Search in sources :

Example 1 with AnnexLibrary

use of org.osate.aadl2.AnnexLibrary in project VERDICT by ge-high-assurance.

the class VerdictJavaValidator method checkThreatModel.

/**
 * Check that IDS are unique and non-empty and that top-level intro is a system.
 * Check that assumptions are unique.
 *
 * @param threatModel
 */
@Check(CheckType.FAST)
public void checkThreatModel(ThreatModel threatModel) {
    if (threatModel.getIntro().getType() != null && !threatModel.getIntro().getType().equals("system") && !threatModel.getIntro().getType().equals("connection")) {
        error("Top-level quantified variable must be a system or connection", VerdictPackage.Literals.THREAT_MODEL__INTRO);
    }
    if (threatModel.getId().length() == 0) {
        error("Threat model must specify an ID", VerdictPackage.Literals.THREAT_MODEL__ID);
    } else {
        // Check IDs unique
        Set<String> otherIds = new HashSet<>();
        // Find AADL package
        EObject container = threatModel;
        while (container != null && !(container instanceof PublicPackageSection)) {
            container = container.eContainer();
        }
        if (container instanceof PublicPackageSection) {
            // Find all verdict annex libraries
            for (AnnexLibrary library : ((PublicPackageSection) container).getOwnedAnnexLibraries()) {
                if ("verdict".equals(library.getName())) {
                    // Find all other threat model declarations
                    for (ThreatStatement other : ThreatModelUtil.getVerdictThreatModels(library).getStatements()) {
                        if (other instanceof ThreatModel && !threatModel.equals(other)) {
                            otherIds.add(((ThreatModel) other).getId());
                        }
                    }
                }
            }
        }
        if (otherIds.contains(threatModel.getId())) {
            error("Duplicate ID " + threatModel.getId(), VerdictPackage.Literals.THREAT_MODEL__ID);
        }
    }
    // Check for duplicate assumptions
    Map<CRVAssumption, Integer> assumptionCounts = new HashMap<>();
    for (CRVAssumption assumption : threatModel.getAssumptions()) {
        if (assumptionCounts.containsKey(assumption)) {
            assumptionCounts.put(assumption, assumptionCounts.get(assumption) + 1);
        } else {
            assumptionCounts.put(assumption, 1);
        }
    }
    int pos = 0;
    for (CRVAssumption assumption : threatModel.getAssumptions()) {
        if (assumptionCounts.get(assumption) > 1) {
            warning("Duplicate assumption: " + assumption.getLiteral(), VerdictPackage.Literals.THREAT_MODEL__ASSUMPTIONS, pos);
        }
        pos++;
    }
    if (threatModel.getReference() != null) {
        // We say that a reference string is valid if there is a valid database ID
        // that is a prefix string of that reference string
        Set<String> definedDatabases = ThreatModelUtil.getDefinedThreatDatabases(threatModel);
        if (!definedDatabases.stream().anyMatch(database -> threatModel.getReference().startsWith(database))) {
            error("Undefined threat database: " + threatModel.getReference(), VerdictPackage.Literals.THREAT_MODEL__REFERENCE);
        }
    }
}
Also used : SubcomponentType(org.osate.aadl2.SubcomponentType) Inject(com.google.inject.Inject) Event(com.ge.research.osate.verdict.dsl.verdict.Event) ThreatEqualContains(com.ge.research.osate.verdict.dsl.verdict.ThreatEqualContains) ThreatStatement(com.ge.research.osate.verdict.dsl.verdict.ThreatStatement) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) FExpr(com.ge.research.osate.verdict.dsl.verdict.FExpr) Classifier(org.osate.aadl2.Classifier) TargetLikelihood(com.ge.research.osate.verdict.dsl.verdict.TargetLikelihood) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Map(java.util.Map) ComponentType(org.osate.aadl2.ComponentType) Check(org.eclipse.xtext.validation.Check) Var(com.ge.research.osate.verdict.dsl.verdict.Var) ThreatDefense(com.ge.research.osate.verdict.dsl.verdict.ThreatDefense) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) EPackage(org.eclipse.emf.ecore.EPackage) List(java.util.List) ResourceDescriptionsProvider(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider) PublicPackageSection(org.osate.aadl2.PublicPackageSection) Optional(java.util.Optional) VerdictUtil(com.ge.research.osate.verdict.dsl.VerdictUtil) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) AnnexLibrary(org.osate.aadl2.AnnexLibrary) ThreatModel(com.ge.research.osate.verdict.dsl.verdict.ThreatModel) CRVAssumption(com.ge.research.osate.verdict.dsl.verdict.CRVAssumption) SystemType(org.osate.aadl2.SystemType) HashMap(java.util.HashMap) SystemImplementation(org.osate.aadl2.SystemImplementation) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CheckType(org.eclipse.xtext.validation.CheckType) ThreatDatabase(com.ge.research.osate.verdict.dsl.verdict.ThreatDatabase) FieldTypeResult(com.ge.research.osate.verdict.dsl.ThreatModelUtil.FieldTypeResult) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort) Subcomponent(org.osate.aadl2.Subcomponent) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) VerdictVariable(com.ge.research.osate.verdict.dsl.type.VerdictVariable) Intro(com.ge.research.osate.verdict.dsl.verdict.Intro) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) VerdictThreatModels(com.ge.research.osate.verdict.dsl.verdict.VerdictThreatModels) VerdictType(com.ge.research.osate.verdict.dsl.type.VerdictType) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) ThreatModelUtil(com.ge.research.osate.verdict.dsl.ThreatModelUtil) AnnexSubclause(org.osate.aadl2.AnnexSubclause) PropertiesJavaValidator(org.osate.xtext.aadl2.properties.validation.PropertiesJavaValidator) VerdictPackage(com.ge.research.osate.verdict.dsl.verdict.VerdictPackage) HashMap(java.util.HashMap) PublicPackageSection(org.osate.aadl2.PublicPackageSection) ThreatStatement(com.ge.research.osate.verdict.dsl.verdict.ThreatStatement) EObject(org.eclipse.emf.ecore.EObject) CRVAssumption(com.ge.research.osate.verdict.dsl.verdict.CRVAssumption) AnnexLibrary(org.osate.aadl2.AnnexLibrary) HashSet(java.util.HashSet) ThreatModel(com.ge.research.osate.verdict.dsl.verdict.ThreatModel) Check(org.eclipse.xtext.validation.Check)

Example 2 with AnnexLibrary

use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.

the class AGREESimulationState method buildPackageToConstantsMap.

private static Map<String, Map<String, ConstStatement>> buildPackageToConstantsMap(final IProject[] projects) {
    // Build a mapping between lower case package names and a map between constant names to constant statements
    final Map<String, Map<String, ConstStatement>> packageToConstantsMap = new HashMap<>();
    try {
        final Set<IFile> aadlFiles = new HashSet<>();
        getAadlFiles(projects, aadlFiles);
        for (final IFile aadlFile : aadlFiles) {
            // final Resource aadlRes = OsateResourceUtil.getResource(aadlFile);
            final Resource aadlRes = getResource(URI.createPlatformResourceURI(aadlFile.getFullPath().toString(), false));
            if (aadlRes != null && !aadlRes.getContents().isEmpty()) {
                final EObject content = aadlRes.getContents().get(0);
                if (content instanceof AadlPackage) {
                    // Find all AGREE Libraries
                    final AadlPackage pkg = (AadlPackage) content;
                    if (pkg.getPublicSection() != null && pkg.getName() != null) {
                        final Map<String, ConstStatement> constants = new HashMap<>();
                        packageToConstantsMap.put(pkg.getQualifiedName().toLowerCase(), constants);
                        for (final AnnexLibrary lib : pkg.getPublicSection().getOwnedAnnexLibraries()) {
                            // Look for AGREE annex libraries
                            if (lib instanceof DefaultAnnexLibrary && "agree".equalsIgnoreCase(lib.getName())) {
                                final AnnexLibrary parsedLib = ((DefaultAnnexLibrary) lib).getParsedAnnexLibrary();
                                if (parsedLib instanceof AgreeContractLibrary) {
                                    final AgreeContractLibrary agreeContractLib = (AgreeContractLibrary) parsedLib;
                                    if (agreeContractLib.getContract() instanceof AgreeContract) {
                                        final AgreeContract agreeContract = (AgreeContract) agreeContractLib.getContract();
                                        for (final SpecStatement spec : agreeContract.getSpecs()) {
                                            if (spec instanceof ConstStatement) {
                                                final ConstStatement constStatement = (ConstStatement) spec;
                                                // Check that the statement is of a supported type
                                                if (getType(constStatement) != null) {
                                                    constants.put(constStatement.getName().toLowerCase(), constStatement);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (CoreException e) {
        throw new AGREESimulatorException(null, e, "Unable to build constants map");
    }
    return packageToConstantsMap;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) IFile(org.eclipse.core.resources.IFile) AadlPackage(org.osate.aadl2.AadlPackage) HashMap(java.util.HashMap) AgreeContractLibrary(com.rockwellcollins.atc.agree.agree.AgreeContractLibrary) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) CoreException(org.eclipse.core.runtime.CoreException) EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) Map(java.util.Map) HashMap(java.util.HashMap) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException) HashSet(java.util.HashSet) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 3 with AnnexLibrary

use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.

the class AgreeValidator method checkPropertyStatement.

@Check(CheckType.FAST)
public void checkPropertyStatement(PropertyStatement propStat) {
    AnnexLibrary library = EcoreUtil2.getContainerOfType(propStat, AnnexLibrary.class);
    if (library != null) {
        error(propStat, "Property statments are allowed only in component annexes");
    }
    TypeDef exprType = AgreeTypeSystem.infer(propStat.getExpr());
    if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
        error(propStat, "Property statement '" + propStat.getName() + "' is of type '" + exprType + "' but must be of type 'bool'");
    }
}
Also used : AgreeTypeSystem.nameOfTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef) ArrayTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef) RecordTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef) TypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef) AnnexLibrary(org.osate.aadl2.AnnexLibrary) Check(org.eclipse.xtext.validation.Check)

Example 4 with AnnexLibrary

use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.

the class AgreeLinkingService method getElm.

private Element getElm(EObject context, EReference reference, String name) {
    String[] segments = name.split("::");
    if (segments.length >= 2) {
        String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
        String statementName = segments[segments.length - 1];
        Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
        PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
        if (propSet != null) {
            Element elm = propSet.findNamedElement(statementName);
            return elm;
        }
        AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
        if (aadlPackage == null) {
            for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
                if (rename.getName() != null && pkgName.equals(rename.getName())) {
                    aadlPackage = rename.getRenamedPackage();
                }
            }
        }
        if (aadlPackage != null) {
            for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
                AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
                for (SpecStatement spec : contract.getSpecs()) {
                    if (spec instanceof RecordDef) {
                        if (((RecordDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof FnDef) {
                        if (((FnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LibraryFnDef) {
                        if (((LibraryFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof UninterpretedFnDef) {
                        if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof NodeDef) {
                        if (((NodeDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LinearizationDef) {
                        if (((LinearizationDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof ConstStatement) {
                        if (((ConstStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof EnumStatement) {
                        if (((EnumStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                        EList<NamedID> enums = ((EnumStatement) spec).getEnums();
                        for (NamedID nid : enums) {
                            if (nid.getName().contentEquals(statementName)) {
                                return nid;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) Element(org.osate.aadl2.Element) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) Namespace(org.osate.aadl2.Namespace) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) EList(org.eclipse.emf.common.util.EList) PackageRename(org.osate.aadl2.PackageRename) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 5 with AnnexLibrary

use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.

the class AgreeScopeProvider method getNamedElements.

private Map<String, NamedElement> getNamedElements(EObject ctx) {
    Map<String, NamedElement> components = new HashMap<>();
    if (ctx instanceof AadlPackage) {
        components.put(((AadlPackage) ctx).getName(), (AadlPackage) ctx);
        PublicPackageSection pubSec = ((AadlPackage) ctx).getPublicSection();
        for (Element el : pubSec.getOwnedElements()) {
            if (el instanceof DataImplementation || el instanceof DataType) {
                components.put(((NamedElement) el).getName(), (NamedElement) el);
            }
        }
        for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(((AadlPackage) ctx), AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
            AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
            components.putAll(getNamedElementsFromSpecs(contract.getSpecs()));
        }
    } else {
        components.putAll(getNamedElementsFromClassifier((Classifier) ctx, false));
    }
    return components;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) PublicPackageSection(org.osate.aadl2.PublicPackageSection) HashMap(java.util.HashMap) Element(org.osate.aadl2.Element) NamedElement(org.osate.aadl2.NamedElement) DataImplementation(org.osate.aadl2.DataImplementation) DataType(org.osate.aadl2.DataType) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) AnnexLibrary(org.osate.aadl2.AnnexLibrary) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

AnnexLibrary (org.osate.aadl2.AnnexLibrary)31 DefaultAnnexLibrary (org.osate.aadl2.DefaultAnnexLibrary)16 AadlPackage (org.osate.aadl2.AadlPackage)14 EObject (org.eclipse.emf.ecore.EObject)13 AnnexSubclause (org.osate.aadl2.AnnexSubclause)13 DefaultAnnexSubclause (org.osate.aadl2.DefaultAnnexSubclause)8 NamedElement (org.osate.aadl2.NamedElement)8 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)7 ArrayList (java.util.ArrayList)7 Classifier (org.osate.aadl2.Classifier)6 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5 Check (org.eclipse.xtext.validation.Check)5 Element (org.osate.aadl2.Element)5 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 PropertySet (org.osate.aadl2.PropertySet)4 AgreeContractLibrary (com.rockwellcollins.atc.agree.agree.AgreeContractLibrary)3 HashMap (java.util.HashMap)3 INode (org.eclipse.xtext.nodemodel.INode)3