Search in sources :

Example 1 with BUS

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

the class Aadl2CsvTranslator method buildScnBusBindingsTable.

/**
 * Build the scenario bus bindings table
 */
Table buildScnBusBindingsTable() {
    Table scnBusBindingsTable = new Table("Scenario", "Comp", "Impl", "ActualConnectionBindingSrcComp", "ActualConnectionBindingSrcImpl", "ActualConnectionBindingSrcCompInst", "ActualConnectionBindingSrcBusInst", "ActualConnectionBindingDestConnComp", "ActualConnectionBindingDestConnImpl", "ActualConnectionBindingDestConnCompInst", "ActualConnectionBindingDestConn");
    for (ComponentImplementation sysImpl : compImpls) {
        for (PropertyAssociation propAssoc : sysImpl.getOwnedPropertyAssociations()) {
            if (propAssoc.getOwnedValues().size() != 1) {
                throw new RuntimeException("Unexpected number of property owned values: " + propAssoc.getOwnedValues().size());
            }
            PropertyExpression expr = propAssoc.getOwnedValues().get(0).getOwnedValue();
            // Obtain the bus reference values
            String[] compImplInstBusNames = getStrRepofExpr(expr);
            // We only consider the case where the length of compImplInstBusNames is 4
            if (compImplInstBusNames.length != 4) {
                throw new RuntimeException("Unexpected number of values in property expression: " + compImplInstBusNames.length);
            }
            // property: bus connection binding applies to connections
            for (ContainedNamedElement appliesToImpl : propAssoc.getAppliesTos()) {
                PortConnection appliesToConn = null;
                SystemSubcomponent appliesToSubcomp = null;
                scnBusBindingsTable.addValue(scenario);
                scnBusBindingsTable.addValue(sysImpl.getTypeName());
                scnBusBindingsTable.addValue(sysImpl.getName());
                scnBusBindingsTable.addValue(compImplInstBusNames[0]);
                scnBusBindingsTable.addValue(compImplInstBusNames[1]);
                scnBusBindingsTable.addValue(compImplInstBusNames[2]);
                scnBusBindingsTable.addValue(compImplInstBusNames[3]);
                if (appliesToImpl.getContainmentPathElements().size() > 2) {
                    throw new RuntimeException("Unexpected number of values in ContainedNamedElement: " + appliesToImpl.getContainmentPathElements().size());
                }
                for (ContainmentPathElement element : appliesToImpl.getContainmentPathElements()) {
                    NamedElement namedElement = element.getNamedElement();
                    if (namedElement instanceof SystemSubcomponent) {
                        appliesToSubcomp = (SystemSubcomponent) namedElement;
                    } else if (namedElement instanceof PortConnection) {
                        appliesToConn = (PortConnection) namedElement;
                    } else {
                        throw new RuntimeException("Unexpected value: " + namedElement);
                    }
                }
                if (appliesToSubcomp != null) {
                    ComponentImplementation compImpl = appliesToSubcomp.getComponentImplementation();
                    scnBusBindingsTable.addValue(compImpl.getTypeName());
                    scnBusBindingsTable.addValue(compImpl.getName());
                    scnBusBindingsTable.addValue(appliesToSubcomp.getName());
                } else {
                    scnBusBindingsTable.addValue(sysImpl.getTypeName());
                    scnBusBindingsTable.addValue(sysImpl.getName());
                    scnBusBindingsTable.addValue("");
                }
                scnBusBindingsTable.addValue(appliesToConn.getName());
                scnBusBindingsTable.capRow();
            }
        }
    }
    return scnBusBindingsTable;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) PropertyExpression(org.osate.aadl2.PropertyExpression) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) PortConnection(org.osate.aadl2.PortConnection)

Example 2 with BUS

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

the class Aadl2CsvTranslator method populateDataFromAadlObjects.

/**
 * Assume the input model is correct without any syntax errors
 * Populate mission req, cyber and safety reqs and rels from AADL objects
 */
public void populateDataFromAadlObjects(List<EObject> objects) {
    List<ComponentType> componentTypes = new ArrayList<>();
    for (EObject obj : objects) {
        if (obj instanceof SystemType) {
            componentTypes.add((SystemType) obj);
        } else if (obj instanceof BusType) {
            componentTypes.add((BusType) obj);
        } else if (obj instanceof SubprogramType) {
            componentTypes.add((SubprogramType) obj);
        } else if (obj instanceof ThreadType) {
            componentTypes.add((ThreadType) obj);
        } else if (obj instanceof MemoryType) {
            componentTypes.add((MemoryType) obj);
        } else if (obj instanceof DeviceType) {
            componentTypes.add((DeviceType) obj);
        } else if (obj instanceof AbstractType) {
            componentTypes.add((AbstractType) obj);
        } else if (obj instanceof ProcessType) {
            componentTypes.add((ProcessType) obj);
        } else if (obj instanceof ThreadGroupType) {
            componentTypes.add((ThreadGroupType) obj);
        } else if (obj instanceof VirtualProcessorType) {
            componentTypes.add((VirtualProcessorType) obj);
        } else if (obj instanceof ProcessorType) {
            componentTypes.add((ProcessorType) obj);
        } else if (obj instanceof SystemImplementation) {
            compImpls.add((SystemImplementation) obj);
        } else if (obj instanceof SubprogramImplementation) {
            compImpls.add((SubprogramImplementation) obj);
        } else if (obj instanceof ThreadImplementation) {
            compImpls.add((ThreadImplementation) obj);
        } else if (obj instanceof MemoryImplementation) {
            compImpls.add((MemoryImplementation) obj);
        } else if (obj instanceof BusImplementation) {
            compImpls.add((BusImplementation) obj);
        } else if (obj instanceof AbstractImplementation) {
            compImpls.add((AbstractImplementation) obj);
        } else if (obj instanceof DeviceImplementation) {
            compImpls.add((DeviceImplementation) obj);
        } else if (obj instanceof ProcessImplementation) {
            compImpls.add((ProcessImplementation) obj);
        } else if (obj instanceof ThreadGroupImplementation) {
            compImpls.add((ThreadGroupImplementation) obj);
        } else if (obj instanceof VirtualProcessorImplementation) {
            compImpls.add((VirtualProcessorImplementation) obj);
        } else if (obj instanceof ProcessorImplementation) {
            compImpls.add((ProcessorImplementation) obj);
        } else if (obj instanceof PropertySetImpl) {
            // String propertySetName = ((PropertySetImpl)obj).getName();
            // List<Property> compProps = new ArrayList<Property>();
            Set<Property> compPropSet = new HashSet<Property>();
            // List<Property> connProps = new ArrayList<Property>();
            Set<Property> connPropSet = new HashSet<Property>();
            for (Property prop : ((PropertySetImpl) obj).getOwnedProperties()) {
                // Save property owner to be used later
                for (PropertyOwner po : prop.getAppliesTos()) {
                    String propCat = ((MetaclassReferenceImpl) po).getMetaclass().getName().toLowerCase();
                    String propName = prop.getName();
                    switch(propCat) {
                        case "system":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "thread":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "processor":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "memory":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "connection":
                            {
                                connPropertyToName.put(prop, propName);
                                connPropSet.add(prop);
                                break;
                            }
                        case "process":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "abstract":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "device":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "threadgroup":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "virtualprocessor":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        case "bus":
                            {
                                componentPropertyToName.put(prop, propName);
                                compPropSet.add(prop);
                                break;
                            }
                        default:
                            {
                                System.out.println("Warning: unsupported property applies to: " + propCat);
                                break;
                            }
                    }
                }
            }
        // compProps.addAll(compPropSet);
        // connProps.addAll(connPropSet);
        // propSetNameToCompProps.put(propertySetName, compProps);
        // propSetNameToConnProps.put(propertySetName, connProps);
        }
    }
    for (ComponentType compType : componentTypes) {
        String compTypeName = compType.getName();
        List<Event> events = new ArrayList<>();
        List<CyberMission> missionReqs = new ArrayList<>();
        List<CyberRel> cyberRels = new ArrayList<>();
        List<SafetyRel> safetyRels = new ArrayList<>();
        List<CyberReq> cyberReqs = new ArrayList<>();
        List<SafetyReq> safetyReqs = new ArrayList<>();
        for (AnnexSubclause annex : compType.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("verdict")) {
                Verdict verdictAnnex = VerdictUtil.getVerdict(annex);
                for (Statement statement : verdictAnnex.getElements()) {
                    if (statement instanceof Event) {
                        events.add((Event) statement);
                    } else if (statement instanceof CyberMission) {
                        missionReqs.add((CyberMission) statement);
                    } else if (statement instanceof CyberReq) {
                        cyberReqs.add((CyberReq) statement);
                    } else if (statement instanceof CyberRel) {
                        cyberRels.add((CyberRel) statement);
                    } else if (statement instanceof SafetyReq) {
                        safetyReqs.add((SafetyReq) statement);
                    } else if (statement instanceof SafetyRel) {
                        safetyRels.add((SafetyRel) statement);
                    }
                }
            }
        }
        if (!events.isEmpty()) {
            compTypeNameToEvents.put(compTypeName, events);
        }
        if (!missionReqs.isEmpty()) {
            compTypeNameToMissions.put(compTypeName, missionReqs);
        }
        if (!cyberRels.isEmpty()) {
            compTypeNameToCyberRels.put(compTypeName, cyberRels);
        }
        if (!safetyRels.isEmpty()) {
            compTypeNameToSafetyRels.put(compTypeName, safetyRels);
        }
        if (!cyberReqs.isEmpty()) {
            compTypeNameToCyberReqs.put(compTypeName, cyberReqs);
        }
        if (!safetyReqs.isEmpty()) {
            compTypeNameToSafetyReqs.put(compTypeName, safetyReqs);
        }
    }
    for (ComponentImplementation impl : compImpls) {
        compTypeNameToImpl.put(impl.getType().getName(), impl);
        if (!impl.getAllConnections().isEmpty()) {
            sysImplToConns.put(impl, impl.getAllConnections());
        }
    }
}
Also used : ProcessImplementation(org.osate.aadl2.ProcessImplementation) ArrayList(java.util.ArrayList) SystemType(org.osate.aadl2.SystemType) VirtualProcessorImplementation(org.osate.aadl2.VirtualProcessorImplementation) BusImplementation(org.osate.aadl2.BusImplementation) EObject(org.eclipse.emf.ecore.EObject) ThreadImplementation(org.osate.aadl2.ThreadImplementation) HashSet(java.util.HashSet) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) ThreadGroupType(org.osate.aadl2.ThreadGroupType) ThreadGroupImplementation(org.osate.aadl2.ThreadGroupImplementation) PropertySetImpl(org.osate.aadl2.impl.PropertySetImpl) DeviceType(org.osate.aadl2.DeviceType) ThreadType(org.osate.aadl2.ThreadType) AbstractType(org.osate.aadl2.AbstractType) SubprogramType(org.osate.aadl2.SubprogramType) AbstractImplementation(org.osate.aadl2.AbstractImplementation) AnnexSubclause(org.osate.aadl2.AnnexSubclause) ComponentImplementation(org.osate.aadl2.ComponentImplementation) MemoryImplementation(org.osate.aadl2.MemoryImplementation) PropertyOwner(org.osate.aadl2.PropertyOwner) BusType(org.osate.aadl2.BusType) VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) ProcessorType(org.osate.aadl2.ProcessorType) MetaclassReferenceImpl(org.osate.aadl2.impl.MetaclassReferenceImpl) ProcessType(org.osate.aadl2.ProcessType) ProcessorImplementation(org.osate.aadl2.ProcessorImplementation) VirtualProcessorImplementation(org.osate.aadl2.VirtualProcessorImplementation) VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) Property(org.osate.aadl2.Property) MemoryType(org.osate.aadl2.MemoryType) CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) ComponentType(org.osate.aadl2.ComponentType) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SubprogramImplementation(org.osate.aadl2.SubprogramImplementation) SystemImplementation(org.osate.aadl2.SystemImplementation) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) Event(com.ge.research.osate.verdict.dsl.verdict.Event) DeviceImplementation(org.osate.aadl2.DeviceImplementation) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq)

Example 3 with BUS

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

the class Aadl2Vdm method translateProcessorTypeObjects.

// End of translateVirtualProcessorTypeObjects
/**
 * Analyzing each processorType:
 * 1. Determine if it is a lower-level system or higher-level system
 * 2. If lower-level, add to componentType list attribute of Model
 * 	2.1 Populate the port, contract, cyberRel, safetyRel, event, id, compCategory
 *      fields of componentType of the Model object
 * 3. If higher-level, assign to Model
 * 	3.1 Populate the safetyReq
 *      cyberReq, mission fields of Model object
 * @param processorTypes
 * @param m1
 * @return
 */
public Model translateProcessorTypeObjects(List<ProcessorType> processorTypes, Model m1, HashSet<String> dataTypeDecl) {
    for (ProcessorType proType : processorTypes) {
        // variables for unpacking proType
        List<Event> events = new ArrayList<>();
        List<CyberMission> missionReqs = new ArrayList<>();
        List<CyberRel> cyberRels = new ArrayList<>();
        List<SafetyRel> safetyRels = new ArrayList<>();
        List<CyberReq> cyberReqs = new ArrayList<>();
        List<SafetyReq> safetyReqs = new ArrayList<>();
        // a flag to check if a higher -level component has already been found
        boolean higher_flag = false;
        // unpacking proType
        for (AnnexSubclause annex : proType.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("verdict")) {
                Verdict verdictAnnex = VerdictUtil.getVerdict(annex);
                for (Statement statement : verdictAnnex.getElements()) {
                    if (statement instanceof Event) {
                        events.add((Event) statement);
                    } else if (statement instanceof CyberMission) {
                        missionReqs.add((CyberMission) statement);
                    } else if (statement instanceof CyberReq) {
                        cyberReqs.add((CyberReq) statement);
                    } else if (statement instanceof CyberRel) {
                        cyberRels.add((CyberRel) statement);
                    } else if (statement instanceof SafetyReq) {
                        safetyReqs.add((SafetyReq) statement);
                    } else if (statement instanceof SafetyRel) {
                        safetyRels.add((SafetyRel) statement);
                    }
                }
            }
        }
        /**
         *  For every ProcessorType,
         *  populate the id, name, compCateg, port, event,
         *  cyberRel, and safetyRel fields of componentType
         *  and add it to the list of componentType
         *  of the Model object
         */
        if (true) {
            // No Filter-- do for all System Types
            // to pack the memType as a VDM component
            verdict.vdm.vdm_model.ComponentType packComponent = new verdict.vdm.vdm_model.ComponentType();
            // Note: Not populating "contract" for now
            // ISSUE: There is no getId() function for memoryType
            packComponent.setId(proType.getQualifiedName());
            // populating "name"
            packComponent.setName(proType.getName());
            // populating "compCateg"
            packComponent.setCompCateg(proType.getCategory().getName());
            // get all bus accesses and store them as ports
            List<BusAccess> busAccesses = proType.getOwnedBusAccesses();
            // checking each busAccess's details and adding it to the port list
            for (BusAccess busAccess : busAccesses) {
                String portName = busAccess.getName();
                String modeString = "in";
                if (busAccess.getKind() == AccessType.PROVIDES) {
                    modeString = "providesBusAccess";
                } else if (busAccess.getKind() == AccessType.REQUIRES) {
                    modeString = "requiresBusAccess";
                }
                verdict.vdm.vdm_model.Port newPort = createVdmPort(portName, modeString, busAccess.getQualifiedName());
                // Note: Not populating "type" for now
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each busAccess
            // ISSUE: no getOwnedDataAccess for processorType
            // get all ports
            List<DataPort> dataPorts = proType.getOwnedDataPorts();
            // checking each port's mode and name and adding it to the port list
            for (DataPort dataPort : dataPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmPort(dataPort, m1, dataTypeDecl);
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each port
            // get all event data ports
            List<EventDataPort> eventDataPorts = proType.getOwnedEventDataPorts();
            for (EventDataPort eventDataPort : eventDataPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmPort(eventDataPort, m1, dataTypeDecl);
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // get all event ports
            List<EventPort> eventPorts = proType.getOwnedEventPorts();
            for (EventPort eventPort : eventPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmEventPort(eventPort);
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // packing all events and adding to component
            for (Event anEvent : events) {
                // To pack the event as a VDM event
                verdict.vdm.vdm_model.Event packEvent = createVdmEvent(anEvent);
                // adding to the list of component's events
                packComponent.getEvent().add(packEvent);
            }
            // packing all cyberRels and adding to component
            for (CyberRel aCyberRel : cyberRels) {
                // To pack the cyberRel as a VDM event
                verdict.vdm.vdm_model.CyberRel packCyberRel = createVdmCyberRel(aCyberRel);
                // adding to the list of component's Cyber relations
                packComponent.getCyberRel().add(packCyberRel);
            }
            // packing all safetyRels and adding to component
            for (SafetyRel aSafetyRel : safetyRels) {
                // To pack the safetyRel as a VDM event
                verdict.vdm.vdm_model.SafetyRel packSafetyRel = createVdmSafetyRel(aSafetyRel);
                // adding to the list of component's Safety relations
                packComponent.getSafetyRel().add(packSafetyRel);
            }
            // End of packing all safetyRels
            // adding to the list of componenmemTypes of the Model object
            m1.getComponentType().add(packComponent);
        }
        /**
         * If a high-level system
         *  populate the name, safetyReq, cyberReq, and mission
         *  for the model object
         */
        if (!cyberReqs.isEmpty() || !safetyReqs.isEmpty() || !missionReqs.isEmpty()) {
            // checking if a high-level system has already been found
            if (higher_flag == false) {
                higher_flag = true;
            } else {
                System.out.println("Warning: Multiple high-level systems detected!");
            }
            // populating name
            m1.setName(proType.getName());
            // packing all safetyReqs and adding to model
            for (SafetyReq aSafetyReq : safetyReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.SafetyReq packSafetyReq = createVdmSafetyReq(aSafetyReq, proType.getFullName());
                // adding to the list of model's Safety requirements
                m1.getSafetyReq().add(packSafetyReq);
            }
            // packing all cyberReqs and adding to model
            for (CyberReq aCyberReq : cyberReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.CyberReq packCyberReq = createVdmCyberReq(aCyberReq, proType.getFullName());
                // adding to the list of model's Cyber requirements
                m1.getCyberReq().add(packCyberReq);
            }
            // packing all missionReqs and adding to model
            for (CyberMission aMission : missionReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.Mission packMission = createVdmMission(aMission);
                // adding to the list of model's Mission
                m1.getMission().add(packMission);
            }
        // End of packing all missionReqs
        }
    // End of if a higher-level system
    }
    // returning the populated Model
    return m1;
}
Also used : VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) ProcessorType(org.osate.aadl2.ProcessorType) ArrayList(java.util.ArrayList) Port(verdict.vdm.vdm_model.Port) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EventPort(org.osate.aadl2.EventPort) EventDataPort(org.osate.aadl2.EventDataPort) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) BusAccess(org.osate.aadl2.BusAccess) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) Event(com.ge.research.osate.verdict.dsl.verdict.Event) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 4 with BUS

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

the class Aadl2Vdm method translateVirtualProcessorTypeObjects.

// End of translateThreadGroupTypeObjects
/**
 * Analyzing each virtualProcessorType:
 * 1. Determine if it is a lower-level system or higher-level system
 * 2. If lower-level, add to componentType list attribute of Model
 * 	2.1 Populate the port, contract, cyberRel, safetyRel, event, id, compCategory
 *      fields of componentType of the Model object
 * 3. If higher-level, assign to Model
 * 	3.1 Populate the safetyReq
 *      cyberReq, mission fields of Model object
 * @param virtualProcessorTypes
 * @param m1
 * @return
 */
public Model translateVirtualProcessorTypeObjects(List<VirtualProcessorType> virtualProcessorTypes, Model m1, HashSet<String> dataTypeDecl) {
    for (VirtualProcessorType vprocType : virtualProcessorTypes) {
        // variables for unpacking vprocType
        List<Event> events = new ArrayList<>();
        List<CyberMission> missionReqs = new ArrayList<>();
        List<CyberRel> cyberRels = new ArrayList<>();
        List<SafetyRel> safetyRels = new ArrayList<>();
        List<CyberReq> cyberReqs = new ArrayList<>();
        List<SafetyReq> safetyReqs = new ArrayList<>();
        // a flag to check if a higher -level component has already been found
        boolean higher_flag = false;
        // unpacking vprocType
        for (AnnexSubclause annex : vprocType.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("verdict")) {
                Verdict verdictAnnex = VerdictUtil.getVerdict(annex);
                for (Statement statement : verdictAnnex.getElements()) {
                    if (statement instanceof Event) {
                        events.add((Event) statement);
                    } else if (statement instanceof CyberMission) {
                        missionReqs.add((CyberMission) statement);
                    } else if (statement instanceof CyberReq) {
                        cyberReqs.add((CyberReq) statement);
                    } else if (statement instanceof CyberRel) {
                        cyberRels.add((CyberRel) statement);
                    } else if (statement instanceof SafetyReq) {
                        safetyReqs.add((SafetyReq) statement);
                    } else if (statement instanceof SafetyRel) {
                        safetyRels.add((SafetyRel) statement);
                    }
                }
            }
        }
        /**
         *  For every VirtualProcessorType,
         *  populate the id, name, compCateg, port, event,
         *  cyberRel, and safetyRel fields of componentType
         *  and add it to the list of componentType
         *  of the Model object
         */
        if (true) {
            // No Filter-- do for all System Types
            // to pack the memType as a VDM component
            verdict.vdm.vdm_model.ComponentType packComponent = new verdict.vdm.vdm_model.ComponentType();
            // Note: Not populating "contract" for now
            // ISSUE: There is no getId() function for memoryType
            packComponent.setId(vprocType.getQualifiedName());
            // populating "name"
            packComponent.setName(vprocType.getName());
            // populating "compCateg"
            packComponent.setCompCateg(vprocType.getCategory().getName());
            // get all bus accesses and store them as ports
            List<BusAccess> busAccesses = vprocType.getOwnedBusAccesses();
            // checking each busAccess's details and adding it to the port list
            for (BusAccess busAccess : busAccesses) {
                String portName = busAccess.getName();
                String modeString = "in";
                if (busAccess.getKind() == AccessType.PROVIDES) {
                    modeString = "providesBusAccess";
                } else if (busAccess.getKind() == AccessType.REQUIRES) {
                    modeString = "requiresBusAccess";
                }
                verdict.vdm.vdm_model.Port newPort = createVdmPort(portName, modeString, busAccess.getQualifiedName());
                // Note: Not populating "type" for now
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each busAccess
            // ISSUE: no getOwnedDataAccesses for virtualProcessorType
            // get all ports
            List<DataPort> dataPorts = vprocType.getOwnedDataPorts();
            // checking each port's mode and name and adding it to the port list
            for (DataPort dataPort : dataPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmPort(dataPort, m1, dataTypeDecl);
                // Note: Not populating "type" for now
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each port
            // get all event data ports
            List<EventDataPort> eventDataPorts = vprocType.getOwnedEventDataPorts();
            for (EventDataPort eventDataPort : eventDataPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmPort(eventDataPort, m1, dataTypeDecl);
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // get all event ports
            List<EventPort> eventPorts = vprocType.getOwnedEventPorts();
            for (EventPort eventPort : eventPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmEventPort(eventPort);
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // packing all events and adding to component
            for (Event anEvent : events) {
                // To pack the event as a VDM event
                verdict.vdm.vdm_model.Event packEvent = createVdmEvent(anEvent);
                // adding to the list of component's events
                packComponent.getEvent().add(packEvent);
            }
            // packing all cyberRels and adding to component
            for (CyberRel aCyberRel : cyberRels) {
                // To pack the cyberRel as a VDM event
                verdict.vdm.vdm_model.CyberRel packCyberRel = createVdmCyberRel(aCyberRel);
                // adding to the list of component's Cyber relations
                packComponent.getCyberRel().add(packCyberRel);
            }
            // packing all safetyRels and adding to component
            for (SafetyRel aSafetyRel : safetyRels) {
                // To pack the safetyRel as a VDM event
                verdict.vdm.vdm_model.SafetyRel packSafetyRel = createVdmSafetyRel(aSafetyRel);
                // adding to the list of component's Safety relations
                packComponent.getSafetyRel().add(packSafetyRel);
            }
            // End of packing all safetyRels
            // adding to the list of componenmemTypes of the Model object
            m1.getComponentType().add(packComponent);
        }
        /**
         * If a high-level system
         *  populate the name, safetyReq, cyberReq, and mission
         *  for the model object
         */
        if (!cyberReqs.isEmpty() || !safetyReqs.isEmpty() || !missionReqs.isEmpty()) {
            // checking if a high-level system has already been found
            if (higher_flag == false) {
                higher_flag = true;
            } else {
                System.out.println("Warning: Multiple high-level systems detected!");
            }
            // populating name
            m1.setName(vprocType.getName());
            // packing all safetyReqs and adding to model
            for (SafetyReq aSafetyReq : safetyReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.SafetyReq packSafetyReq = createVdmSafetyReq(aSafetyReq, vprocType.getFullName());
                // adding to the list of model's Safety requirements
                m1.getSafetyReq().add(packSafetyReq);
            }
            // packing all cyberReqs and adding to model
            for (CyberReq aCyberReq : cyberReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.CyberReq packCyberReq = createVdmCyberReq(aCyberReq, vprocType.getFullName());
                // adding to the list of model's Cyber requirements
                m1.getCyberReq().add(packCyberReq);
            }
            // packing all missionReqs and adding to model
            for (CyberMission aMission : missionReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.Mission packMission = createVdmMission(aMission);
                // adding to the list of model's Mission
                m1.getMission().add(packMission);
            }
        // End of packing all missionReqs
        }
    // End of if a higher-level system
    }
    // returning the populated Model
    return m1;
}
Also used : ArrayList(java.util.ArrayList) Port(verdict.vdm.vdm_model.Port) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EventPort(org.osate.aadl2.EventPort) VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) EventDataPort(org.osate.aadl2.EventDataPort) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) BusAccess(org.osate.aadl2.BusAccess) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) Event(com.ge.research.osate.verdict.dsl.verdict.Event) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 5 with BUS

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

the class Aadl2Vdm method populateVDMFromAadlObjects.

/**
 * Assume the input is correct without any syntax errors
 * Populate mission req, cyber and safety reqs and rels from AADL objects
 *
 *  @param objects a List of AADL objects,
 * @param objectsFromFilesInProject
 * 	@param model an empty VDM model to populate
 *  @return a populated VDM model
 * Vidhya: modified function to add and process only objects in the aadl files in the project excluding those in imported aadl files
 */
public Model populateVDMFromAadlObjects(List<EObject> objects, List<EObject> objectsFromFilesInProject, Model model) {
    HashSet<String> dataTypeDecl = new HashSet<String>();
    // variables for extracting data from the AADL object
    List<SystemType> systemTypes = new ArrayList<>();
    List<BusType> busTypes = new ArrayList<>();
    List<SubprogramType> subprogramTypes = new ArrayList<>();
    List<ThreadType> threadTypes = new ArrayList<>();
    List<MemoryType> memoryTypes = new ArrayList<>();
    List<DeviceType> deviceTypes = new ArrayList<>();
    List<AbstractType> abstractTypes = new ArrayList<>();
    List<ProcessType> processTypes = new ArrayList<>();
    List<ThreadGroupType> threadGroupTypes = new ArrayList<>();
    List<VirtualProcessorType> virtualProcessorTypes = new ArrayList<>();
    List<ProcessorType> processorTypes = new ArrayList<>();
    List<ComponentImplementation> compImpls = new ArrayList<>();
    Map<Property, String> connPropertyToName = new LinkedHashMap<>();
    Map<Property, String> componentPropertyToName = new LinkedHashMap<>();
    // process only those properties defined in files in the project and not in the imported files
    HashSet<String> objectNamesFromFilesInProject = getObjectNames(objectsFromFilesInProject);
    // extracting data from the AADLObject
    for (EObject obj : objects) {
        if (obj instanceof SystemType) {
            if (objectNamesFromFilesInProject.contains(((SystemType) obj).getName())) {
                systemTypes.add((SystemType) obj);
            }
        } else if (obj instanceof BusType) {
            if (objectNamesFromFilesInProject.contains(((BusType) obj).getName())) {
                busTypes.add((BusType) obj);
            }
        } else if (obj instanceof SubprogramType) {
            if (objectNamesFromFilesInProject.contains(((SubprogramType) obj).getName())) {
                subprogramTypes.add((SubprogramType) obj);
            }
        } else if (obj instanceof ThreadType) {
            if (objectNamesFromFilesInProject.contains(((ThreadType) obj).getName())) {
                threadTypes.add((ThreadType) obj);
            }
        } else if (obj instanceof MemoryType) {
            if (objectNamesFromFilesInProject.contains(((MemoryType) obj).getName())) {
                memoryTypes.add((MemoryType) obj);
            }
        } else if (obj instanceof DeviceType) {
            if (objectNamesFromFilesInProject.contains(((DeviceType) obj).getName())) {
                deviceTypes.add((DeviceType) obj);
            }
        } else if (obj instanceof AbstractType) {
            if (objectNamesFromFilesInProject.contains(((AbstractType) obj).getName())) {
                abstractTypes.add((AbstractType) obj);
            }
        } else if (obj instanceof ProcessType) {
            if (objectNamesFromFilesInProject.contains(((ProcessType) obj).getName())) {
                processTypes.add((ProcessType) obj);
            }
        } else if (obj instanceof ThreadGroupType) {
            if (objectNamesFromFilesInProject.contains(((ThreadGroupType) obj).getName())) {
                threadGroupTypes.add((ThreadGroupType) obj);
            }
        } else if (obj instanceof VirtualProcessorType) {
            if (objectNamesFromFilesInProject.contains(((VirtualProcessorType) obj).getName())) {
                virtualProcessorTypes.add((VirtualProcessorType) obj);
            }
        } else if (obj instanceof ProcessorType) {
            if (objectNamesFromFilesInProject.contains(((ProcessorType) obj).getName())) {
                processorTypes.add((ProcessorType) obj);
            }
        } else if (obj instanceof SystemImplementation) {
            if (objectNamesFromFilesInProject.contains(((SystemImplementation) obj).getName())) {
                compImpls.add((SystemImplementation) obj);
            }
        } else if (obj instanceof SubprogramImplementation) {
            if (objectNamesFromFilesInProject.contains(((SubprogramImplementation) obj).getName())) {
                compImpls.add((SubprogramImplementation) obj);
            }
        } else if (obj instanceof ThreadImplementation) {
            if (objectNamesFromFilesInProject.contains(((ThreadImplementation) obj).getName())) {
                compImpls.add((ThreadImplementation) obj);
            }
        } else if (obj instanceof MemoryImplementation) {
            if (objectNamesFromFilesInProject.contains(((MemoryImplementation) obj).getName())) {
                compImpls.add((MemoryImplementation) obj);
            }
        } else if (obj instanceof BusImplementation) {
            if (objectNamesFromFilesInProject.contains(((BusImplementation) obj).getName())) {
                compImpls.add((BusImplementation) obj);
            }
        } else if (obj instanceof AbstractImplementation) {
            if (objectNamesFromFilesInProject.contains(((AbstractImplementation) obj).getName())) {
                compImpls.add((AbstractImplementation) obj);
            }
        } else if (obj instanceof DeviceImplementation) {
            if (objectNamesFromFilesInProject.contains(((DeviceImplementation) obj).getName())) {
                compImpls.add((DeviceImplementation) obj);
            }
        } else if (obj instanceof ProcessImplementation) {
            if (objectNamesFromFilesInProject.contains(((ProcessImplementation) obj).getName())) {
                compImpls.add((ProcessImplementation) obj);
            }
        } else if (obj instanceof ThreadGroupImplementation) {
            if (objectNamesFromFilesInProject.contains(((ThreadGroupImplementation) obj).getName())) {
                compImpls.add((ThreadGroupImplementation) obj);
            }
        } else if (obj instanceof VirtualProcessorImplementation) {
            if (objectNamesFromFilesInProject.contains(((VirtualProcessorImplementation) obj).getName())) {
                compImpls.add((VirtualProcessorImplementation) obj);
            }
        } else if (obj instanceof ProcessorImplementation) {
            if (objectNamesFromFilesInProject.contains(((ProcessorImplementation) obj).getName())) {
                compImpls.add((ProcessorImplementation) obj);
            }
        } else if (obj instanceof PropertySetImpl) {
            Set<Property> compPropSet = new HashSet<Property>();
            Set<Property> connPropSet = new HashSet<Property>();
            for (Property prop : ((PropertySetImpl) obj).getOwnedProperties()) {
                // Save property owner to be used later
                for (PropertyOwner po : prop.getAppliesTos()) {
                    String propCat = ((MetaclassReferenceImpl) po).getMetaclass().getName().toLowerCase();
                    String propName = prop.getName();
                    switch(propCat) {
                        case "system":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "thread":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "processor":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "memory":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "connection":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    connPropertyToName.put(prop, propName);
                                }
                                connPropSet.add(prop);
                                break;
                            }
                        case "process":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "abstract":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "device":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "threadgroup":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "virtualprocessor":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "bus":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        case "port":
                            {
                                if (objectNamesFromFilesInProject.contains(propName)) {
                                    componentPropertyToName.put(prop, propName);
                                }
                                compPropSet.add(prop);
                                break;
                            }
                        default:
                            {
                                if (objectNamesFromFilesInProject.contains(((PropertySetImpl) obj).getName())) {
                                    System.out.println("Warning: unsupported property: " + propName + ", applies to: " + propCat);
                                }
                                break;
                            }
                    }
                }
            }
        }
    }
    /* Translating all Component Types */
    if (systemTypes.size() > 0) {
        model = translateSystemTypeObjects(systemTypes, model, dataTypeDecl);
    }
    if (busTypes.size() > 0) {
        model = translateBusTypeObjects(busTypes, model, dataTypeDecl);
    }
    if (subprogramTypes.size() > 0) {
        model = translateSubprogramTypeObjects(subprogramTypes, model, dataTypeDecl);
    }
    if (threadTypes.size() > 0) {
        model = translateThreadTypeObjects(threadTypes, model, dataTypeDecl);
    }
    if (memoryTypes.size() > 0) {
        model = translateMemoryTypeObjects(memoryTypes, model, dataTypeDecl);
    }
    if (deviceTypes.size() > 0) {
        model = translateDeviceTypeObjects(deviceTypes, model, dataTypeDecl);
    }
    if (abstractTypes.size() > 0) {
        model = translateAbstractTypeObjects(abstractTypes, model, dataTypeDecl);
    }
    if (processTypes.size() > 0) {
        model = translateProcessTypeObjects(processTypes, model, dataTypeDecl);
    }
    if (processTypes.size() > 0) {
        model = translateProcessorTypeObjects(processorTypes, model, dataTypeDecl);
    }
    if (threadGroupTypes.size() > 0) {
        model = translateThreadGroupTypeObjects(threadGroupTypes, model, dataTypeDecl);
    }
    if (virtualProcessorTypes.size() > 0) {
        model = translateVirtualProcessorTypeObjects(virtualProcessorTypes, model, dataTypeDecl);
    }
    /* Translating all System Implementations */
    // model = translateSystemImplObjects(systemImpls, componentPropertyToName, connPropertyToName,model);
    // model = translateComponentImplObjects(compImpls, componentPropertyToName, connPropertyToName,model);
    /**
     * Translating all component implementations
     */
    model = translateComponentImplObjects(compImpls, componentPropertyToName, connPropertyToName, model, dataTypeDecl);
    // return the final model
    return model;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ProcessImplementation(org.osate.aadl2.ProcessImplementation) MemoryImplementation(org.osate.aadl2.MemoryImplementation) PropertyOwner(org.osate.aadl2.PropertyOwner) BusType(org.osate.aadl2.BusType) VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) ProcessorType(org.osate.aadl2.ProcessorType) ArrayList(java.util.ArrayList) SystemType(org.osate.aadl2.SystemType) VirtualProcessorImplementation(org.osate.aadl2.VirtualProcessorImplementation) LinkedHashMap(java.util.LinkedHashMap) BusImplementation(org.osate.aadl2.BusImplementation) MetaclassReferenceImpl(org.osate.aadl2.impl.MetaclassReferenceImpl) ProcessType(org.osate.aadl2.ProcessType) ProcessorImplementation(org.osate.aadl2.ProcessorImplementation) VirtualProcessorImplementation(org.osate.aadl2.VirtualProcessorImplementation) EObject(org.eclipse.emf.ecore.EObject) ThreadImplementation(org.osate.aadl2.ThreadImplementation) VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) Property(org.osate.aadl2.Property) HashSet(java.util.HashSet) MemoryType(org.osate.aadl2.MemoryType) ThreadGroupType(org.osate.aadl2.ThreadGroupType) ThreadGroupImplementation(org.osate.aadl2.ThreadGroupImplementation) SubprogramImplementation(org.osate.aadl2.SubprogramImplementation) PropertySetImpl(org.osate.aadl2.impl.PropertySetImpl) DeviceType(org.osate.aadl2.DeviceType) ThreadType(org.osate.aadl2.ThreadType) SystemImplementation(org.osate.aadl2.SystemImplementation) AbstractType(org.osate.aadl2.AbstractType) SubprogramType(org.osate.aadl2.SubprogramType) AbstractImplementation(org.osate.aadl2.AbstractImplementation) DeviceImplementation(org.osate.aadl2.DeviceImplementation)

Aggregations

ComponentInstance (org.osate.aadl2.instance.ComponentInstance)22 ArrayList (java.util.ArrayList)16 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)14 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)11 ComponentImplementation (org.osate.aadl2.ComponentImplementation)9 NamedElement (org.osate.aadl2.NamedElement)9 CyberMission (com.ge.research.osate.verdict.dsl.verdict.CyberMission)8 CyberRel (com.ge.research.osate.verdict.dsl.verdict.CyberRel)8 CyberReq (com.ge.research.osate.verdict.dsl.verdict.CyberReq)8 Event (com.ge.research.osate.verdict.dsl.verdict.Event)8 SafetyRel (com.ge.research.osate.verdict.dsl.verdict.SafetyRel)8 SafetyReq (com.ge.research.osate.verdict.dsl.verdict.SafetyReq)8 Statement (com.ge.research.osate.verdict.dsl.verdict.Statement)8 Verdict (com.ge.research.osate.verdict.dsl.verdict.Verdict)8 AnnexSubclause (org.osate.aadl2.AnnexSubclause)8 BusAccess (org.osate.aadl2.BusAccess)8 DataPort (org.osate.aadl2.DataPort)8 EventDataPort (org.osate.aadl2.EventDataPort)8 EventPort (org.osate.aadl2.EventPort)8 InstanceObject (org.osate.aadl2.instance.InstanceObject)8