Commit ec65e538 authored by Paff's avatar Paff
Browse files

transformation for critical port

parent 9eaeef79
......@@ -21,8 +21,8 @@ import secarc.ets.check.MontiSecArcAnalysisCreator;
import secarc.ets.check.MontiSecArcAnalysisVisitor;
import secarc.ets.check.MontiSecArcAnalysisWorkflow;
import secarc.ets.transform.PreCoCoCheckMontiSecArcTransformationWorkflow;
import secarc.ets.transform.criticalport.PreAnalysisCriticalPortTransformationWorkflow;
import secarc.ets.transform.trustlevel.PreAnalysisTrustlevelTransformationWorkflow;
import secarc.ets.transform.criticalport.AnalysisCriticalPortTransformationWorkflow;
import secarc.ets.transform.trustlevel.AnalysisTrustlevelTransformationWorkflow;
/**
* As subclass of {@link ModelingLanguage}, this class configures the technical
......@@ -97,7 +97,41 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
analysisWorkflow.setClient(analysisVisitor);
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED, analysisWorkflow);
PreAnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot> trustlevelTransformationWorkflow = new PreAnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot>(MontiSecArcRoot.class);
this.addTrustlevelWhatIfWorkflow(analysisParameter, analysisConfPath, critical);
this.addCriticalPortWhatIfWorkflow(analysisParameter, analysisConfPath, critical);
}
private void addCriticalPortWhatIfWorkflow(List<String> analysisParameter, String analysisConfPath, boolean critical) {
AnalysisCriticalPortTransformationWorkflow<MontiSecArcRoot> criticalPortTransformationWorkflow = new AnalysisCriticalPortTransformationWorkflow<MontiSecArcRoot>(
MontiSecArcRoot.class);
addExecutionUnit("transformCriticalPort",
criticalPortTransformationWorkflow);
//Workflow for Analysis
MontiSecArcAnalysisWorkflow<MontiSecArcRoot> analysisTransformWorkflow = new MontiSecArcAnalysisWorkflow<MontiSecArcRoot>(LANGUAGE_ROOT);
//AnalysisCreator
analysisTransformWorkflow.setAnalysis(MontiSecArcAnalysisCreator.createAnalysis(analysisConfPath));
//AnalysisConfiguratin
analysisTransformWorkflow.setAnalysisConfiguration(MontiSecArcAnalysisCreator.createConfig());
//Visitor for Analysis
MontiSecArcAnalysisVisitor analysisTransfromVisitor = new MontiSecArcAnalysisVisitor();
analysisTransfromVisitor.setAdvanced(false);
analysisTransfromVisitor.setAnalysisParameter(analysisParameter);
analysisTransfromVisitor.setCiritical(critical);
analysisTransformWorkflow.setClient(analysisTransfromVisitor);
//Add Workflow for Analysis for beginners: what if
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_CRITICAL_PORT, analysisTransformWorkflow);
//Add Workflow for Analysis for advanced users
analysisTransfromVisitor.setAdvanced(true);
analysisTransformWorkflow.setClient(analysisTransfromVisitor);
//Add Workflow for Analysis for advanced users: what if
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED_WHAT_IF_CRITICAL_PORT, analysisTransformWorkflow);
}
private void addTrustlevelWhatIfWorkflow(List<String> analysisParameter, String analysisConfPath, boolean critical) {
AnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot> trustlevelTransformationWorkflow = new AnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot>(MontiSecArcRoot.class);
trustlevelTransformationWorkflow.setAnalysisParameter(analysisParameter);
addExecutionUnit("transformTrustlevel", trustlevelTransformationWorkflow);
......@@ -114,16 +148,13 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
analysisTransfromVisitor.setCiritical(critical);
analysisTransformWorkflow.setClient(analysisTransfromVisitor);
//Add Workflow for Analysis for beginners: what if
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF, analysisTransformWorkflow);
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_TRUSTLEVEL, analysisTransformWorkflow);
//Add Workflow for Analysis for advanced users
analysisTransfromVisitor.setAdvanced(true);
analysisTransformWorkflow.setClient(analysisVisitor);
analysisTransformWorkflow.setClient(analysisTransfromVisitor);
//Add Workflow for Analysis for advanced users: what if
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED_WHAT_IF, analysisTransformWorkflow);
PreAnalysisCriticalPortTransformationWorkflow<MontiSecArcRoot> criticalPortTransformationWorkflow = new PreAnalysisCriticalPortTransformationWorkflow<MontiSecArcRoot>(MontiSecArcRoot.class);
addExecutionUnit("transformCriticalPort", criticalPortTransformationWorkflow);
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED_WHAT_IF_TRUSTLEVEL, analysisTransformWorkflow);
}
/**
......
package secarc.ets.transform.criticalport;
import interfaces2.STEntry;
import interfaces2.namespaces.NameSpace;
import interfaces2.resolvers.AmbigousException;
import interfaces2.resolvers.Resolver;
import java.util.List;
import java.util.Map;
import secarc.MontiSecArcConstants;
import secarc._ast.ASTSecArcCPE;
import secarc._ast.ASTSecArcConfiguration;
import secarc._ast.ASTSecArcIdentity;
import secarc._ast.ASTSecArcPEP;
import secarc._ast.ASTSecArcRefRole;
import secarc._ast.ASTSecArcRole;
import secarc._ast.ASTSecArcTrustLevel;
import secarc._ast.ASTSecArcTrustlevelRelation;
import secarc._tool.MontiSecArcRoot;
import secarc.ets.entries.CPEEntry;
import secarc.ets.entries.ConfigurationEntry;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.PEPEntry;
import secarc.ets.entries.RoleEntry;
import secarc.ets.entries.TrustlevelEntry;
import secarc.ets.entries.TrustlevelRelationEntry;
import mc.MCG;
import mc.ast.ASTNode;
import mc.ast.ConcreteVisitor;
import mc.helper.NameHelper;
import mc.javadsl._ast.ASTQualifiedNameList;
import mc.types._ast.ASTQualifiedName;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd._ast.ASTArcConnector;
import mc.umlp.arcd._ast.ASTArcPort;
import mc.umlp.arcd._ast.ASTArcSimpleConnector;
import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.ConnectorEntry;
import mc.umlp.arcd.ets.entries.PortEntry;
public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
private List<STEntry> entries;
private Resolver resolver;
protected Map<ASTNode, NameSpace> nodesToNameSpaces;
/**
*
* @param dslroot dsl root to use
*/
public AnalysisCriticalPortTransformationVisitor(final MontiSecArcRoot dslroot) {
super();
}
public void setResolver(Resolver resolver) {
this.resolver = resolver;
}
public void setNodesToNameSpaces(Map<ASTNode, NameSpace> nodesToNameSpaces) {
this.nodesToNameSpaces = nodesToNameSpaces;
}
public void setEntries(List<STEntry> entries) {
this.entries = entries;
}
public void visit(ASTSecArcRole node) {
try {
for(String role : node.getRoles()) {
RoleEntry entry = (RoleEntry) resolver.resolve(role, RoleEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTSecArcConfiguration node) {
try {
ConfigurationEntry entry = (ConfigurationEntry) resolver.resolve(node.getName(), ConfigurationEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTSecArcIdentity node) {
try {
for(ASTQualifiedName target : node.getTargets()) {
IdentityEntry entry = (IdentityEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(target.getParts()), IdentityEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTSecArcPEP node) {
try {
PEPEntry entry = (PEPEntry) resolver.resolve(MontiSecArcConstants.PEP_NAME, PEPEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTSecArcTrustLevel node) {
try {
TrustlevelEntry entry = (TrustlevelEntry) resolver.resolve(MontiSecArcConstants.TRUSTLEVEL_NAME, TrustlevelEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTSecArcCPE node) {
try {
CPEEntry entry = (CPEEntry) resolver.resolve(MontiSecArcConstants.CPE_NAME, CPEEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTArcConnector node) {
try {
for(ASTQualifiedName target : node.getTargets()) {
ConnectorEntry entry = (ConnectorEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(target.getParts()), ConnectorEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTArcSimpleConnector node) {
try {
for(ASTQualifiedName target : node.getTargets()) {
ConnectorEntry entry = (ConnectorEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(target.getParts()), ConnectorEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTArcPort node) {
try {
PortEntry entry = (PortEntry) resolver.resolve(node.getName(), PortEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTArcComponent node) {
try {
ComponentEntry entry = (ComponentEntry) resolver.resolve(node.getName(), ComponentEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTSecArcTrustlevelRelation node) {
try {
TrustlevelRelationEntry entry = (TrustlevelRelationEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(node.getServer().getParts()), TrustlevelRelationEntry.KIND, getNameSpaceFor(node.getMainParent()));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
/**
* Analysis which is the namespace a node is in.
*
* @param n Node to be checked.
* @return Namespace the given node is in.
*/
public NameSpace getNameSpaceFor(ASTNode n) {
if (nodesToNameSpaces != null) {
ASTNode curr = n;
while (curr != null) {
NameSpace nsp = nodesToNameSpaces.get(curr);
if (nsp != null) {
return nsp;
}
curr = curr.get_Parent();
}
}
return null;
}
}
......@@ -8,17 +8,16 @@ import interfaces2.resolvers.Resolver;
import java.util.Map;
import secarc._tool.MontiSecArcRoot;
import secarc.ets.transform.trustlevel.PreAnalysisTrustlevelTransformationVisitor;
import mc.DSLWorkflow;
import mc.ast.ASTNode;
import mc.ast.InheritanceVisitor;
public class PreAnalysisCriticalPortTransformationWorkflow<T extends MontiSecArcRoot> extends DSLWorkflow<T> {
public class AnalysisCriticalPortTransformationWorkflow<T extends MontiSecArcRoot> extends DSLWorkflow<T> {
/**
* @param responsibleClass class of the dsl root
*/
public PreAnalysisCriticalPortTransformationWorkflow(final Class<T> responsibleClass) {
public AnalysisCriticalPortTransformationWorkflow(final Class<T> responsibleClass) {
super(responsibleClass);
}
......@@ -49,11 +48,19 @@ public class PreAnalysisCriticalPortTransformationWorkflow<T extends MontiSecArc
}
PreAnalysisCriticalPortTransformationVisitor visitor = new PreAnalysisCriticalPortTransformationVisitor(dslroot);
visitor.setResolver(resolver);
visitor.setNodesToNameSpaces(nodesToNameSpaces);
PreAnalysisCriticalPortTransformationVisitor preVisitor = new PreAnalysisCriticalPortTransformationVisitor(dslroot);
preVisitor.setResolver(resolver);
preVisitor.setNodesToNameSpaces(nodesToNameSpaces);
InheritanceVisitor.run(preVisitor, dslroot.getAst());
AnalysisCriticalPortTransformationVisitor visitorTransform = new AnalysisCriticalPortTransformationVisitor(dslroot);
visitorTransform.setResolver(resolver);
visitorTransform.setNodesToNameSpaces(nodesToNameSpaces);
visitorTransform.setEntries(preVisitor.getEntries());
InheritanceVisitor.run(visitorTransform, dslroot.getAst());
InheritanceVisitor.run(visitor, dslroot.getAst());
}
}
......@@ -12,11 +12,10 @@ import java.util.Map;
import org.jgrapht.traverse.DepthFirstIterator;
import org.jgrapht.traverse.GraphIterator;
import secarc._ast.ASTSecArcPort;
import secarc._tool.MontiSecArcRoot;
import secarc.ets.analysis.checker.AnalysisHelper;
import secarc.ets.analysis.checker.ISecAnalysisParameterChecker;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.entries.SecPortEntry;
import secarc.ets.graph.ArchitectureGraph;
import secarc.ets.graph.ArchitectureGraphBuilder;
import secarc.ets.graph.Edge;
......@@ -24,7 +23,6 @@ import secarc.ets.graph.Vertex;
import mc.MCG;
import mc.ast.ASTNode;
import mc.ast.ConcreteVisitor;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd._ast.ASTArcPort;
import mc.umlp.arcd._ast.ASTMCCompilationUnit;
import mc.umlp.arcd.ets.entries.ComponentEntry;
......@@ -64,6 +62,10 @@ public class PreAnalysisCriticalPortTransformationVisitor extends ConcreteVisito
this.nodesToNameSpaces = nodesToNameSpaces;
}
public List<STEntry> getEntries() {
return this.entries;
}
/**
* Visits compilation unit and builds the architecture graph
*
......@@ -107,15 +109,35 @@ public class PreAnalysisCriticalPortTransformationVisitor extends ConcreteVisito
return;
}
boolean delte = false;
List<STEntry> pathEntries = new ArrayList<STEntry>();
boolean hasCriticalPort = false;
STEntry pathEntry = null;
Vertex<PortEntry> portVertex = Vertex.of(entry);
//Look for paths with port as beginning
GraphIterator<Vertex<? extends STEntry>, Edge> iterator = new DepthFirstIterator<Vertex<? extends STEntry>, Edge>(graphConnectorEdges.getRawGraph(), portVertex);
while(iterator.hasNext()) {
pathEntry = iterator.next().getArchitectureElement();
if(pathEntry.equals(entry)) {
if(hasCriticalPort) {
this.entries.addAll(pathEntries);
}
pathEntries.clear();
hasCriticalPort = false;
}
pathEntries.add(pathEntry);
if(pathEntry instanceof PortEntry && ((SecPortEntry) pathEntry).isCritical()) {
hasCriticalPort = true;
}
}
}
/**
......
......@@ -20,7 +20,7 @@ import mc.ast.ConcreteVisitor;
import mc.literals._ast.ASTIntLiteral;
import mc.umlp.arcd.ets.entries.ComponentEntry;
public class PreAnalysisTrustlevelTransformationVisitor extends ConcreteVisitor {
public class AnalysisTrustlevelTransformationVisitor extends ConcreteVisitor {
private List<String> analysisParameter;
......@@ -32,7 +32,7 @@ public class PreAnalysisTrustlevelTransformationVisitor extends ConcreteVisitor
*
* @param dslroot dsl root to use
*/
public PreAnalysisTrustlevelTransformationVisitor(final MontiSecArcRoot dslroot) {
public AnalysisTrustlevelTransformationVisitor(final MontiSecArcRoot dslroot) {
super();
}
......
......@@ -13,14 +13,14 @@ import mc.ast.ASTNode;
import mc.ast.InheritanceVisitor;
import secarc._tool.MontiSecArcRoot;
public class PreAnalysisTrustlevelTransformationWorkflow<T extends MontiSecArcRoot> extends DSLWorkflow<T> {
public class AnalysisTrustlevelTransformationWorkflow<T extends MontiSecArcRoot> extends DSLWorkflow<T> {
private List<String> analysisParameter;
/**
* @param responsibleClass class of the dsl root
*/
public PreAnalysisTrustlevelTransformationWorkflow(final Class<T> responsibleClass) {
public AnalysisTrustlevelTransformationWorkflow(final Class<T> responsibleClass) {
super(responsibleClass);
}
......@@ -51,7 +51,7 @@ public class PreAnalysisTrustlevelTransformationWorkflow<T extends MontiSecArcRo
}
PreAnalysisTrustlevelTransformationVisitor visitor = new PreAnalysisTrustlevelTransformationVisitor(dslroot);
AnalysisTrustlevelTransformationVisitor visitor = new AnalysisTrustlevelTransformationVisitor(dslroot);
visitor.setAnalysisParameter(analysisParameter);
visitor.setResolver(resolver);
visitor.setNodesToNameSpaces(nodesToNameSpaces);
......
......@@ -102,7 +102,7 @@ public class TestWithSymtabAnalysis<T extends ETSTool> extends
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS, whatIfElement,
MontiSecArcConstants.ARG_ANALYSISCONFPATH, "/home/user/workspace/MA-Paff/03.Implementierung/montiSecArcAnalysis/src/main/conf/Analysis_Conf.txt",
ARG_SYNTHESIS, "secarc", "transformTrustlevel",
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF};
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_TRUSTLEVEL};
List<String> argsAsList = new LinkedList<String>();
argsAsList.addAll(Arrays.asList(args));
for (String mp : additionalModelPath) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment