Search in sources :

Example 96 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project VERDICT by ge-high-assurance.

the class VerdictJavaValidator method checkStatement.

/**
 * Check that cyber relations/requirements have unique, non-empty IDs
 * and they are only located in subsystems/top-level systems, respectively.
 *
 * @param statement
 */
@Check(CheckType.FAST)
public void checkStatement(Statement statement) {
    String statementType;
    boolean shouldBeSubcomponent;
    if (statement instanceof CyberRel) {
        statementType = "Cyber relation";
        shouldBeSubcomponent = true;
    } else if (statement instanceof CyberReq) {
        statementType = "Cyber requirement";
        shouldBeSubcomponent = false;
    } else if (statement instanceof CyberMission) {
        statementType = "Mission";
        shouldBeSubcomponent = false;
    } else if (statement instanceof SafetyReq) {
        statementType = "Safety requirement";
        shouldBeSubcomponent = false;
    } else if (statement instanceof SafetyRel) {
        statementType = "Safety relation";
        shouldBeSubcomponent = true;
    } else if (statement instanceof Event) {
        statementType = "Event";
        shouldBeSubcomponent = true;
    } else {
        throw new RuntimeException("statement is not CyberRel, or CyberReq, or Mission, or SafetyReq, or SafetyRel, or Event!?");
    }
    if (statement.getId().length() == 0) {
        error(statementType + " must specify an ID", VerdictPackage.Literals.STATEMENT__ID);
        return;
    }
    // Find enclosing system
    EObject container = statement;
    while (container != null && !(container instanceof SystemType || container instanceof PublicPackageSection)) {
        container = container.eContainer();
    }
    /*
		 * Within the same component, we need to make sure that cyber relations, cyber requirements,
		 * safety relations, safety missions, events do not have naming conflicts respectively.
		 */
    Set<String> otherIds = new HashSet<>();
    if (container instanceof SystemType) {
        SystemType currentSystem = (SystemType) container;
        // Get enclosing file
        while (!(container instanceof PublicPackageSection)) {
            container = container.eContainer();
        }
        // Get all verdict annexes for this system
        for (AnnexSubclause annex : currentSystem.getOwnedAnnexSubclauses()) {
            if ("verdict".equals(annex.getName())) {
                Verdict subclause = VerdictUtil.getVerdict(annex);
                // We only check that within the same statement category, there should not be naming conflicts.
                for (Statement other : subclause.getElements()) {
                    // Don't double-count self
                    if (!statement.equals(other)) {
                        if ((statement instanceof CyberRel) && (other instanceof CyberRel)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof CyberReq) && (other instanceof CyberReq)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof CyberMission) && (other instanceof CyberMission)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof SafetyReq) && (other instanceof SafetyReq)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof SafetyRel) && (other instanceof SafetyRel)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof Event) && (other instanceof Event)) {
                            otherIds.add(other.getId());
                        }
                    }
                }
            }
        }
        /*
			 * A system is a top-level system if it is not a subcomponent
			 * of any other system (cyber/safety requirements are valid).
			 *
			 * If it is a subcomponent of another system, then it is a
			 * subcomponent (cyber/safety relations are valid).
			 */
        PublicPackageSection pack = (PublicPackageSection) container;
        // Find all system impls
        for (Classifier cls : pack.getOwnedClassifiers()) {
            if (cls instanceof SystemImplementation) {
                // Grab the dependency/subcomponent tree
                SystemImplementation systemImpl = (SystemImplementation) cls;
                for (Subcomponent sub : systemImpl.getAllSubcomponents()) {
                    if (sub.getComponentImplementation() != null) {
                        subcomponents.add(sub.getComponentImplementation().getType());
                    }
                    subcomponents.add(sub.getSubcomponentType());
                }
            }
        }
        boolean isSubcomponent = subcomponents.contains(currentSystem);
        if (isSubcomponent && !shouldBeSubcomponent) {
            warning(statementType + " not allowed in subcomponent system");
        } else if (!isSubcomponent && shouldBeSubcomponent) {
            warning(statementType + " not allowed in top-level system");
        }
        if (otherIds.contains(statement.getId())) {
            error("Duplicate ID " + statement.getId(), VerdictPackage.Literals.STATEMENT__ID);
        }
    }
    // Perform extra checks for missions
    if (statement instanceof CyberMission) {
        checkMission((CyberMission) statement);
    }
    // And cyber reqs
    if (statement instanceof CyberReq) {
        checkCyberReq((CyberReq) statement);
    }
}
Also used : CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) ThreatStatement(com.ge.research.osate.verdict.dsl.verdict.ThreatStatement) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SystemType(org.osate.aadl2.SystemType) Classifier(org.osate.aadl2.Classifier) PublicPackageSection(org.osate.aadl2.PublicPackageSection) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) SystemImplementation(org.osate.aadl2.SystemImplementation) EObject(org.eclipse.emf.ecore.EObject) Subcomponent(org.osate.aadl2.Subcomponent) Event(com.ge.research.osate.verdict.dsl.verdict.Event) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) AnnexSubclause(org.osate.aadl2.AnnexSubclause) HashSet(java.util.HashSet) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) Check(org.eclipse.xtext.validation.Check)

Example 97 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project VERDICT by ge-high-assurance.

the class VerdictUtil method getEvents.

/**
 * Get the (linked) set of all cyber requirements in the AADL AST of which obj is part.
 *
 * @param obj
 * @return
 */
public static Set<String> getEvents(EObject obj) {
    Set<String> cyberReqs = new LinkedHashSet<>();
    // Find public package section
    EObject container = obj;
    while (container != null && !(container instanceof PublicPackageSection)) {
        container = container.eContainer();
    }
    PublicPackageSection pack = (PublicPackageSection) container;
    if (pack != null && pack.getOwnedClassifiers() != null) {
        // Find all systems
        for (Classifier cls : pack.getOwnedClassifiers()) {
            if (cls instanceof SystemType) {
                SystemType system = (SystemType) cls;
                // Get all verdict annexes for this system
                for (AnnexSubclause annex : system.getOwnedAnnexSubclauses()) {
                    if ("verdict".equals(annex.getName())) {
                        Verdict subclause = VerdictUtil.getVerdict(annex);
                        // Get all cyber req IDs
                        for (Statement statement : subclause.getElements()) {
                            if (statement instanceof CyberReq) {
                                cyberReqs.add(statement.getId());
                            }
                        }
                    }
                }
            }
        }
    }
    return cyberReqs;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PublicPackageSection(org.osate.aadl2.PublicPackageSection) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) EObject(org.eclipse.emf.ecore.EObject) SystemType(org.osate.aadl2.SystemType) Classifier(org.osate.aadl2.Classifier) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict)

Example 98 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project VERDICT by ge-high-assurance.

the class VerdictUtil method getAllReqs.

/**
 * Get the (linked) set of all cyber requirements in the AADL AST of which obj is part.
 *
 * @param obj
 * @return
 */
public static Set<String> getAllReqs(EObject obj) {
    Set<String> reqs = new LinkedHashSet<>();
    // Find public package section
    EObject container = obj;
    while (container != null && !(container instanceof PublicPackageSection)) {
        container = container.eContainer();
    }
    PublicPackageSection pack = (PublicPackageSection) container;
    if (pack != null && pack.getOwnedClassifiers() != null) {
        // Find all systems
        for (Classifier cls : pack.getOwnedClassifiers()) {
            if (cls instanceof SystemType) {
                SystemType system = (SystemType) cls;
                // Get all verdict annexes for this system
                for (AnnexSubclause annex : system.getOwnedAnnexSubclauses()) {
                    if ("verdict".equals(annex.getName())) {
                        Verdict subclause = VerdictUtil.getVerdict(annex);
                        // Get all cyber req IDs
                        for (Statement statement : subclause.getElements()) {
                            if (statement instanceof CyberReq) {
                                reqs.add(statement.getId());
                            } else if (statement instanceof SafetyReq) {
                                reqs.add(statement.getId());
                            }
                        }
                    }
                }
            }
        }
    }
    return reqs;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PublicPackageSection(org.osate.aadl2.PublicPackageSection) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) EObject(org.eclipse.emf.ecore.EObject) SystemType(org.osate.aadl2.SystemType) Classifier(org.osate.aadl2.Classifier) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict)

Example 99 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class ModelVerifications method sameVoltage.

/**
 * returns true if two incoming (requires) abstract feature instances in component 'ci' have same voltage
 * @param ci
 * @return
 */
public static boolean sameVoltage(ComponentInstance ci) {
    EList<FeatureInstance> inlets = new BasicEList<FeatureInstance>();
    for (FeatureInstance fi : ci.getAllFeatureInstances(FeatureCategory.ABSTRACT_FEATURE)) {
        Classifier cl = fi.getFeature().getAllClassifier();
        if (fi.getFlowDirection().incoming() && cl.getName().equalsIgnoreCase("power")) {
            inlets.add(fi);
        }
    }
    if (inlets.size() == 2) {
        double v1 = getVoltage(inlets.get(0));
        double v2 = getVoltage(inlets.get(1));
        return v1 == v2;
    }
    return false;
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) BasicEList(org.eclipse.emf.common.util.BasicEList) Classifier(org.osate.aadl2.Classifier)

Example 100 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class ModelVerifications method samePowerBudget.

/**
 * returns true if two incoming (requires) abstract feature instances in component 'ci' have same power budget
 * @param ci
 * @return
 */
public static boolean samePowerBudget(ComponentInstance ci) {
    EList<FeatureInstance> inlets = new BasicEList<FeatureInstance>();
    for (FeatureInstance fi : ci.getAllFeatureInstances(FeatureCategory.ABSTRACT_FEATURE)) {
        Classifier cl = fi.getFeature().getAllClassifier();
        if (fi.getFlowDirection().incoming() && cl.getName().equalsIgnoreCase("power")) {
            inlets.add(fi);
        }
    }
    if (inlets.size() == 2) {
        double pb1 = GetProperties.getPowerBudget(inlets.get(0), 0.0);
        double pb2 = GetProperties.getPowerBudget(inlets.get(1), 0.0);
        return pb1 == pb2;
    }
    return false;
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) BasicEList(org.eclipse.emf.common.util.BasicEList) Classifier(org.osate.aadl2.Classifier)

Aggregations

Classifier (org.osate.aadl2.Classifier)203 ComponentClassifier (org.osate.aadl2.ComponentClassifier)90 ComponentImplementation (org.osate.aadl2.ComponentImplementation)49 NamedElement (org.osate.aadl2.NamedElement)40 AadlPackage (org.osate.aadl2.AadlPackage)38 Subcomponent (org.osate.aadl2.Subcomponent)37 ComponentType (org.osate.aadl2.ComponentType)34 EObject (org.eclipse.emf.ecore.EObject)31 ArrayList (java.util.ArrayList)29 BasicEList (org.eclipse.emf.common.util.BasicEList)28 Feature (org.osate.aadl2.Feature)26 DataClassifier (org.osate.aadl2.DataClassifier)22 FeatureGroupType (org.osate.aadl2.FeatureGroupType)21 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)21 AnnexSubclause (org.osate.aadl2.AnnexSubclause)17 Element (org.osate.aadl2.Element)17 EList (org.eclipse.emf.common.util.EList)15 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)15 FeatureGroup (org.osate.aadl2.FeatureGroup)14 PropertyExpression (org.osate.aadl2.PropertyExpression)14