Search in sources :

Example 11 with CompInstancePort

use of verdict.vdm.vdm_model.CompInstancePort in project VERDICT by ge-high-assurance.

the class Vdm2Csv method updateConnectionTable.

private void updateConnectionTable(String connName, String connQualName, verdict.vdm.vdm_model.ConnectionEnd source, verdict.vdm.vdm_model.ConnectionEnd destination, Table scnConnTable, Map<String, HashMap<String, String>> connectionAttributesMap, String scenario, ComponentImpl compImpl, Map<String, String> compToCompImpl, Map<String, HashSet<String>> propToConnections) {
    scnConnTable.addValue(scenario);
    String compQualName = compImpl.getType().getId();
    scnConnTable.addValue(compQualName);
    scnConnTable.addValue(replaceColonsWithUnderscore(compQualName));
    scnConnTable.addValue(compQualName.substring(0, compQualName.indexOf(':')));
    // component
    scnConnTable.addValue(compImpl.getType().getName());
    // component implementation
    scnConnTable.addValue(compImpl.getName());
    // connection qualified name
    scnConnTable.addValue(connQualName);
    // connection sanitized qualified name
    scnConnTable.addValue(replaceColonsWithUnderscore(connQualName));
    // connection name
    scnConnTable.addValue(connName);
    if (source.getComponentPort() != null) {
        Port srcCompPort = source.getComponentPort();
        String fullQualNameSrcCompPort = srcCompPort.getId();
        // get the component name
        // remove port name from fullQualNameSrcCompPort and text before "::" and after "." to get the source component name
        String compName = fullQualNameSrcCompPort.substring(fullQualNameSrcCompPort.indexOf(':') + 2, fullQualNameSrcCompPort.indexOf('.'));
        if (!compToCompImpl.containsKey(compName)) {
            throw new RuntimeException("Unable to find Component Implementation corresponding to " + compName);
        }
        // SrcCompInstQualifiedName
        scnConnTable.addValue("");
        // SanitizedSrcCompInstQualifiedName
        scnConnTable.addValue("");
        // SrcCompInstPackage
        scnConnTable.addValue("");
        // SrcComp
        scnConnTable.addValue(compName);
        // SrcImpl
        scnConnTable.addValue(compToCompImpl.get(compName));
        // SrcCompInstance
        scnConnTable.addValue("");
        // SrcCompCategory
        scnConnTable.addValue(compImpl.getType().getCompCateg().toString());
        // SrcPortName
        scnConnTable.addValue(srcCompPort.getName());
        // SrcPortType
        scnConnTable.addValue(srcCompPort.getMode().value());
    } else if (source.getSubcomponentPort() != null) {
        String sourceInstQualName = source.getSubcomponentPort().getSubcomponent().getId();
        // SrcCompInstQualifiedName
        scnConnTable.addValue(sourceInstQualName);
        // SanitizedSrcCompInstQualifiedName
        scnConnTable.addValue(replaceColonsWithUnderscore(sourceInstQualName));
        // SrcCompInstPackage
        scnConnTable.addValue(sourceInstQualName.substring(0, compQualName.indexOf(':')));
        CompInstancePort srcCompPort = source.getSubcomponentPort();
        // get the component name
        // SrcComp
        scnConnTable.addValue(srcCompPort.getSubcomponent().getSpecification().getName());
        // SrcImpl
        scnConnTable.addValue("");
        // SrcCompInstance
        scnConnTable.addValue(srcCompPort.getSubcomponent().getName());
        // SrcCompCategory
        scnConnTable.addValue(srcCompPort.getSubcomponent().getSpecification().getCompCateg());
        // SrcPortName
        scnConnTable.addValue(srcCompPort.getPort().getName());
        // SrcPortType
        scnConnTable.addValue(srcCompPort.getPort().getMode().value());
    } else {
        throw new RuntimeException("Connection source has null values foe component port and subcomponent port");
    }
    if (destination.getComponentPort() != null) {
        Port destCompPort = destination.getComponentPort();
        String fullQualNameDestCompPort = destCompPort.getId();
        // get the component name
        // remove port name from fullQualNameDestCompPort and text before "::" and after "." to get the destination component name
        String compName = fullQualNameDestCompPort.substring(fullQualNameDestCompPort.indexOf(':') + 2, fullQualNameDestCompPort.indexOf('.'));
        if (!compToCompImpl.containsKey(compName)) {
            throw new RuntimeException("Unable to find Component Implementation corresponding to " + compName);
        }
        // DestCompInstQualifiedName
        scnConnTable.addValue("");
        // SanitizedDestCompInstQualifiedName
        scnConnTable.addValue("");
        // DestCompInstPackage
        scnConnTable.addValue("");
        // DestComp
        scnConnTable.addValue(compName);
        scnConnTable.addValue(compToCompImpl.get(compName));
        // DestCompInstance
        scnConnTable.addValue("");
        // DestCompCategory
        scnConnTable.addValue(compImpl.getType().getCompCateg().toString());
        // DestPortName
        scnConnTable.addValue(destCompPort.getName());
        // DestPortType
        scnConnTable.addValue(destCompPort.getMode().value());
    } else if (destination.getSubcomponentPort() != null) {
        String destInstQualName = destination.getSubcomponentPort().getSubcomponent().getId();
        // DestCompInstQualifiedName
        scnConnTable.addValue(destInstQualName);
        // SanitizedDestCompInstQualifiedName
        scnConnTable.addValue(replaceColonsWithUnderscore(destInstQualName));
        // DestCompInstPackage
        scnConnTable.addValue(destInstQualName.substring(0, compQualName.indexOf(':')));
        CompInstancePort destCompPort = destination.getSubcomponentPort();
        // get the component name
        // DestComp
        scnConnTable.addValue(destination.getSubcomponentPort().getSubcomponent().getSpecification().getName());
        scnConnTable.addValue("");
        // DestCompInstance
        scnConnTable.addValue(destCompPort.getSubcomponent().getName());
        // DestCompCategory
        scnConnTable.addValue(destCompPort.getSubcomponent().getSpecification().getCompCateg());
        // DestPortName
        scnConnTable.addValue(destCompPort.getPort().getName());
        // DestPortType
        scnConnTable.addValue(destCompPort.getPort().getMode().value());
    } else {
        throw new RuntimeException("Connection destination has null values foe component port and subcomponent port");
    }
    // add connection attributes/properties
    HashMap<String, String> connAttrMap = connectionAttributesMap.get(connName);
    for (String propName : propToConnections.keySet()) {
        if (synthesis && DefenseProperties.MBAA_CONN_DEFENSE_PROPERTIES_SET.contains(propName)) {
            // this fools stem - --code synonymous to code by William in the previous aadl2csvtranslator
            scnConnTable.addValue("9");
        } else if (connAttrMap.containsKey(propName)) {
            // check if the connection has that property - add it to csv if it does
            // connection property
            scnConnTable.addValue(connAttrMap.get(propName));
        } else {
            scnConnTable.addValue("");
        }
    }
    scnConnTable.capRow();
}
Also used : CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) CIAPort(verdict.vdm.vdm_model.CIAPort) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) IAPort(verdict.vdm.vdm_model.IAPort)

Example 12 with CompInstancePort

use of verdict.vdm.vdm_model.CompInstancePort in project VERDICT by ge-high-assurance.

the class Vdm2Csv method updateCyberMissionsTable.

private void updateCyberMissionsTable(Table missionTable, String scenario, String missionReqId, String cyberReqId, verdict.vdm.vdm_model.CIA cyberCIA, verdict.vdm.vdm_model.Severity cyberSeverity, CyberExpr cyberReqCondition, Map<String, List<ConnectionEnd>> connectionDestToSourceMap) {
    // get port's linked source instance
    if (connectionDestToSourceMap.containsKey(cyberReqCondition.getPort().getName())) {
        List<ConnectionEnd> linkedSourcePorts = connectionDestToSourceMap.get(cyberReqCondition.getPort().getName());
        for (ConnectionEnd linkedSourcePort : linkedSourcePorts) {
            if (linkedSourcePort.getSubcomponentPort() != null) {
                missionTable.addValue(scenario);
                missionTable.addValue(sanitizeValue(missionReqId));
                // MissionReq
                missionTable.addValue("");
                missionTable.addValue(cyberReqId);
                // Req
                missionTable.addValue("");
                // get cia and add as MissionImpactCIA
                missionTable.addValue(formatToSmall(cyberCIA.toString()));
                // Effect
                missionTable.addValue("");
                // get and add severity
                missionTable.addValue(formatToSmall(cyberSeverity.name()));
                CompInstancePort destCompPort = linkedSourcePort.getSubcomponentPort();
                missionTable.addValue(destCompPort.getSubcomponent().getName());
                missionTable.addValue(destCompPort.getPort().getName());
                // get CIA and add it to table
                missionTable.addValue(formatToSmall(cyberReqCondition.getPort().getCia().name()));
                missionTable.addValue("Cyber");
                missionTable.capRow();
            } else {
                throw new RuntimeException("Linked Source Port has no instance information");
            }
        }
    } else {
        throw new RuntimeException("Missing component instance dependency. " + cyberReqCondition.getPort().getName() + " is not linked to a source port");
    }
}
Also used : CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd)

Example 13 with CompInstancePort

use of verdict.vdm.vdm_model.CompInstancePort in project VERDICT by ge-high-assurance.

the class Vdm2Csv method getPortsAndCIAsForMission.

private void getPortsAndCIAsForMission(CyberExpr inputCyberExpr, String[] portsCIAs, Map<String, List<ConnectionEnd>> connectionDestToSourceMap) {
    if (inputCyberExpr.getKind() == null) {
        // get port's linked source instance
        if (connectionDestToSourceMap.containsKey(inputCyberExpr.getPort().getName())) {
            List<ConnectionEnd> linkedSourcePorts = connectionDestToSourceMap.get(inputCyberExpr.getPort().getName());
            if (linkedSourcePorts.size() > 1) {
                throw new RuntimeException("Multiple Linked Source Ports is unexpected for ports in cyber expression.");
            }
            if (linkedSourcePorts.get(0).getSubcomponentPort() != null) {
                CompInstancePort depCompPort = linkedSourcePorts.get(0).getSubcomponentPort();
                if (portsCIAs[0].equalsIgnoreCase("")) {
                    portsCIAs[0] = depCompPort.getSubcomponent().getName();
                    portsCIAs[1] = depCompPort.getPort().getName();
                    portsCIAs[2] = formatToSmall(inputCyberExpr.getPort().getCia().name());
                } else {
                    portsCIAs[0] = portsCIAs[0] + ";" + depCompPort.getSubcomponent().getName();
                    portsCIAs[1] = portsCIAs[1] + ";" + depCompPort.getPort().getName();
                    portsCIAs[2] = portsCIAs[2] + ";" + formatToSmall(inputCyberExpr.getPort().getCia().name());
                }
            } else {
                throw new RuntimeException("Linked Source Port has no instance information");
            }
        } else {
            throw new RuntimeException("Missing component instance dependency. " + inputCyberExpr.getPort().getName() + " is not linked to a source port");
        }
    } else if (inputCyberExpr.getKind().toString().equalsIgnoreCase("And")) {
        List<CyberExpr> subInpCyberList = inputCyberExpr.getAnd().getExpr();
        for (CyberExpr subInpCyberExpr : subInpCyberList) {
            getPortsAndCIAsForMission(subInpCyberExpr, portsCIAs, connectionDestToSourceMap);
        }
    } else {
        throw new RuntimeException("VERDICT only supports DNF in cyber requirements.");
    }
}
Also used : CyberExpr(verdict.vdm.vdm_model.CyberExpr) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)13 ConnectionEnd (verdict.vdm.vdm_model.ConnectionEnd)12 Port (verdict.vdm.vdm_model.Port)9 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)6 ComponentInstance (verdict.vdm.vdm_model.ComponentInstance)6 ComponentType (verdict.vdm.vdm_model.ComponentType)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Expression (verdict.vdm.vdm_lustre.Expression)3 HashSet (java.util.HashSet)2 ContractItem (verdict.vdm.vdm_lustre.ContractItem)2 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)2 IfThenElse (verdict.vdm.vdm_lustre.IfThenElse)2 NodeCall (verdict.vdm.vdm_lustre.NodeCall)2 NodeEquation (verdict.vdm.vdm_lustre.NodeEquation)2 NodeEquationLHS (verdict.vdm.vdm_lustre.NodeEquationLHS)2 Connection (verdict.vdm.vdm_model.Connection)2 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1