Search in sources :

Example 21 with Model

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

the class CRVHandler method runAadl2Vdm.

/**
 * Calls Aadl2Vdm translator and writes model to vdmFile
 * @param dir
 * @param vdmFile
 */
public static void runAadl2Vdm(File dir, File vdmFile) {
    Agree2Vdm agree2vdm = new Agree2Vdm();
    Model model = agree2vdm.execute(dir);
    VdmTranslator.marshalToXml(model, vdmFile);
}
Also used : Model(verdict.vdm.vdm_model.Model) Agree2Vdm(com.ge.research.osate.verdict.aadl2vdm.Agree2Vdm)

Example 22 with Model

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

the class MBASHandler method runAadl2Csv.

public static void runAadl2Csv(File dir, String stemOutputDir, String soteriaOutputDir) {
    Agree2Vdm agree2vdm = new Agree2Vdm();
    Model model = agree2vdm.execute(dir);
    Vdm2Csv vdm2csv = new Vdm2Csv();
    vdm2csv.execute(model, stemOutputDir, soteriaOutputDir, dir.getName());
}
Also used : Vdm2Csv(com.ge.research.osate.verdict.vdm2csv.Vdm2Csv) Model(verdict.vdm.vdm_model.Model) Agree2Vdm(com.ge.research.osate.verdict.aadl2vdm.Agree2Vdm)

Example 23 with Model

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

the class App method runGsn.

/**
 * call the GSN creation interface from verdict-assurance-case Behavior: 1. If security cases
 * have not been enabled - Creates normal GSN for every requirement specified 2. If security
 * cases have been enabled - creates a security GSN for every cyber requirement that is
 * specified - creates a normal GSN for all other requirements
 *
 * @param rootGoalId
 * @param gsnOutputDir
 * @param soteriaOutputDir
 * @param caseAadlPath
 */
private static void runGsn(String inputLine, String gsnOutputDir, String soteriaOutputDir, String modelAadlPath, boolean generateXml, boolean securityCases, String modelName, String hostSTEMDir) throws VerdictRunException {
    logHeader("GSN");
    // The prefix for SOteria++ text outputs that are linked from solution nodes
    String soteriaOutputLinkPathPrefix = hostSTEMDir + "/Output/Soteria_Output/" + modelName;
    // Fetch the model first
    File modelXml = new File(gsnOutputDir, "modelXML.xml");
    // Fetch the DeliveryDrone model from the XML
    Model model = VdmTranslator.unmarshalFromXml(modelXml);
    // get all cyber Ids
    List<String> cyberIds = new ArrayList<>();
    for (verdict.vdm.vdm_model.CyberReq aCyberReq : model.getCyberReq()) {
        cyberIds.add(aCyberReq.getId());
    }
    // splitting the input by ';'
    String[] inputIds = inputLine.split(";");
    List<String> allIds = new ArrayList<>();
    for (String inputId : inputIds) {
        allIds.add(inputId);
    }
    // remove duplicates
    List<String> duplicateFreeIds = new ArrayList<>(new HashSet<>(allIds));
    for (String id : duplicateFreeIds) {
        // if cyberId
        if (cyberIds.contains(id)) {
            if (securityCases) {
                // if security is enabled
                // calling the function to create security GSN artefacts
                SecurityGSNInterface createGsnObj = new SecurityGSNInterface();
                try {
                    createGsnObj.runGsnArtifactsGenerator(id, gsnOutputDir, soteriaOutputDir, modelAadlPath, securityCases, generateXml, soteriaOutputLinkPathPrefix, hostSTEMDir);
                } catch (IOException | ParserConfigurationException | SAXException e) {
                    // TODO Auto-generated catch block
                    throw new VerdictRunException("Failed to create GSN fragments", e);
                }
            } else {
                // calling the function to create normal GSN artefacts
                GSNInterface createGsnObj = new GSNInterface();
                try {
                    createGsnObj.runGsnArtifactsGenerator(id, gsnOutputDir, soteriaOutputDir, modelAadlPath, generateXml, soteriaOutputLinkPathPrefix, hostSTEMDir);
                } catch (IOException | ParserConfigurationException | SAXException e) {
                    // TODO Auto-generated catch block
                    throw new VerdictRunException("Failed to create GSN fragments", e);
                }
            }
        } else {
            // if not cyberId
            // calling the function to create normal GSN artefacts
            GSNInterface createGsnObj = new GSNInterface();
            try {
                createGsnObj.runGsnArtifactsGenerator(id, gsnOutputDir, soteriaOutputDir, modelAadlPath, generateXml, soteriaOutputLinkPathPrefix, hostSTEMDir);
            } catch (IOException | ParserConfigurationException | SAXException e) {
                // TODO Auto-generated catch block
                throw new VerdictRunException("Failed to create GSN fragments", e);
            }
        }
    }
    // if running inside docker
    if (isRunningInsideDocker()) {
        // sleep for three seconds to allow docker to exit gracefully
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            throw new VerdictRunException("Failed to create GSN fragments. Thread.sleep exception.", e);
        }
    }
    logHeader("Finished");
}
Also used : GSNInterface(com.ge.verdict.gsn.GSNInterface) SecurityGSNInterface(com.ge.verdict.gsn.SecurityGSNInterface) SecurityGSNInterface(com.ge.verdict.gsn.SecurityGSNInterface) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Model(verdict.vdm.vdm_model.Model) CostModel(com.ge.verdict.synthesis.CostModel) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 24 with Model

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

the class App method runCRV.

public static void runCRV(String[] args) throws IOException {
    final String vdmTmpDumpFile = "tmp.xml";
    final String kind2TmpDumpFile = "tmp-kind2-result-dump.xml";
    CommandLine cmdLine = cmdLineOptions(args);
    // File eg_file = new File("hawkUAV/model_A.xml");
    File vdmFile = null;
    if (cmdLine.hasOption("o")) {
        String inputPath = cmdLine.getOptionValue("i");
        LOGGY.info(inputPath);
        vdmFile = new File(inputPath);
    }
    boolean component_level = false;
    // Setting Blame assingment Level (Component Level & Link Level)
    if (cmdLine.hasOption("C")) {
        component_level = true;
    }
    boolean meritAssignment = false;
    if (cmdLine.hasOption("M")) {
        meritAssignment = true;
    }
    File lustreFile = null;
    File kind2_resultFile = null;
    File bm_outputFile = null;
    LOGGY.info("************************(VERDICT CRV)******************************");
    if (vdmFile.canRead()) {
        String InputFile = vdmFile.getAbsolutePath();
        String fileExt = InputFile.substring(InputFile.lastIndexOf(".") + 1);
        Model vdm_model = null;
        if (fileExt.equals("iml")) {
            // Cannot use IML model
            LOGGY.warn("IML model has been disabled");
            System.exit(-1);
        } else if (fileExt.equals("xml")) {
            // Use VDM model
            vdm_model = VerdictLustreTranslator.unmarshalFromXml(vdmFile);
        } else {
            LOGGY.warn("Invalid Model Input File: " + fileExt);
            System.exit(-1);
        }
        LOGGY.info("**********Instrumentation Invoked****************");
        Instrumentor instrumentor = new Instrumentor(vdm_model);
        vdm_model = instrumentor.instrument(vdm_model, cmdLine);
        {
            VdmTranslator.marshalToXml(vdm_model, new File(vdmTmpDumpFile));
            vdm_model = VerdictLustreTranslator.unmarshalFromXml(new File(vdmTmpDumpFile));
        }
        LOGGY.info("********Dataflow to Lustre code Printing*********");
        VDM2Lustre vdm2lus = new VDM2Lustre(vdm_model);
        Model lustreModel = vdm2lus.translate();
        if (cmdLine.hasOption("o")) {
            String outputPath = cmdLine.getOptionValue("o");
            lustreFile = new File(outputPath);
            LOGGY.info(lustreFile.getAbsolutePath());
        }
        if (cmdLine.hasOption("r")) {
            String outputFile = cmdLine.getOptionValue("r");
            // LOGGY.info(outputFile);
            bm_outputFile = new File(outputFile);
        }
        if (cmdLine.hasOption("k")) {
            String outputFile = cmdLine.getOptionValue("k");
            // LOGGY.info(outputFile);
            kind2_resultFile = new File(outputFile);
        // if (kind2_resultFile.exists()) {
        // kind2_resultFile.createNewFile();
        // }
        }
        {
            kind2_resultFile = new File(kind2TmpDumpFile);
        }
        // VerdictLustreTranslator.marshalToLustre(lustreModel, lustreFile);
        VDMLustreTranslator.dumpLustre(lustreModel, lustreFile);
        // VerdictLustreTranslator.marshalToLustre(vdm_model, lustreFile);
        LOGGY.info("******************Executor***********************");
        int exitCode = Exec.run_kind2(lustreFile, kind2_resultFile, instrumentor.emptyIntrumentation(), meritAssignment);
        if (exitCode == 20) {
            LOGGY.info("No Invalid Property Found.");
        } else if (exitCode == 10) {
            LOGGY.info("Found Invalid Properties.");
        } else if (exitCode == 0) {
            LOGGY.warn("Kind2 TIMED OUT!!!");
        } else if (exitCode == 2) {
            LOGGY.warn("Kind2 Failure, Log messages:");
            XMLProcessor.parseLog(kind2_resultFile);
        }
        if (meritAssignment) {
            LOGGY.info("*************Merit Assignment***********");
            MeritAssignmentResult.readAndPrintInfo(kind2_resultFile);
        } else {
            LOGGY.info("*************Blame Assignment***********");
            BlameAssignment bm = new BlameAssignment();
            bm = bm.compute_blame_assignment(kind2_resultFile, instrumentor.getAttackMap(), component_level);
            XMLProcessor.dumpXML(bm, bm_outputFile);
        }
    } else {
        LOGGY.warn("ERROR Unable to read VDM Model File");
    }
    LOGGY.info("************************(VERDICT CRV)********************************");
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) VDM2Lustre(edu.uiowa.clc.verdict.lustre.VDM2Lustre) Model(verdict.vdm.vdm_model.Model) File(java.io.File) BlameAssignment(edu.uiowa.clc.verdict.blm.BlameAssignment)

Example 25 with Model

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

the class GSNInterface method runGsnArtifactsGenerator.

/**
 * The interface for creating GSN artefacts
 *
 * @param userInput -- the GUI user input with Ids
 * @param gsnOutputDir -- the directory where outputs will be stored
 * @param soteriaOutputDir -- the directory containing Soteria outputs
 * @param caseAadlPath -- the directory containing the AADL files
 * @param xmlFlag -- determines if xml should be created
 * @param soteriaOutputLinkPathPrefix -- a prefix for creating the clickable urls
 * @throws IOException
 * @throws ParserConfigurationException
 * @throws SAXException
 */
public void runGsnArtifactsGenerator(String userInput, String gsnOutputDir, String soteriaOutputDir, String modelAadlPath, boolean xmlFlag, String soteriaOutputLinkPathPrefix, String hostSTEMDir) throws IOException, ParserConfigurationException, SAXException {
    File modelXml = new File(gsnOutputDir, "modelXML.xml");
    File cyberOutput = new File(soteriaOutputDir, "ImplProperties.xml");
    File safetyOutput = new File(soteriaOutputDir, "ImplProperties-safety.xml");
    // Fetch the DeliveryDrone model from the XML
    Model xmlModel = VdmTranslator.unmarshalFromXml(modelXml);
    // List of all mission ids
    List<String> missionIds = new ArrayList<>();
    for (Mission aMission : xmlModel.getMission()) {
        missionIds.add(aMission.getId());
    }
    // List of ids to create fragments for
    List<String> forIds = new ArrayList<>();
    if (userInput.equals("ALLMREQKEY")) {
        forIds.addAll(missionIds);
    } else {
        // get individual IDs from the user input
        String[] inputs = userInput.split(";");
        // adding each Id to the list
        for (String id : inputs) {
            forIds.add(id);
        }
    }
    // creating fragments
    for (String rootGoalId : forIds) {
        // create the GSN fragment
        CreateGSN objCreateGSN = new CreateGSN();
        GsnNode gsnFragment = objCreateGSN.gsnCreator(xmlModel, cyberOutput, safetyOutput, modelAadlPath, rootGoalId, soteriaOutputLinkPathPrefix, hostSTEMDir);
        System.out.println("Info: Created GSN fragment for " + rootGoalId);
        // Filenames
        String xmlFilename = rootGoalId + "_GsnFragment.xml";
        String dotFilename = rootGoalId + "_GsnFragment.dot";
        String svgFilename = rootGoalId + "_GsnFragment.svg";
        if (xmlFlag) {
            // Create a file and print the GSN XML
            File gsnXmlFile = new File(gsnOutputDir, xmlFilename);
            Gsn2Xml objGsn2Xml = new Gsn2Xml();
            objGsn2Xml.convertGsnToXML(gsnFragment, gsnXmlFile);
            System.out.println("Info: Written GSN to xml for " + rootGoalId + ": " + gsnXmlFile.getAbsolutePath());
        }
        // Create a file and print the dot
        File gsnDotFile = new File(gsnOutputDir, dotFilename);
        Gsn2Dot objGsn2Dot = new Gsn2Dot();
        objGsn2Dot.createDot(gsnFragment, gsnDotFile);
        // System.out.println(
        // "Info: Written GSN to dot for "
        // + rootGoalId
        // + ": "
        // + gsnDotFile.getAbsolutePath());
        // generate the svg file using graphviz
        String graphDestination = gsnOutputDir + SEP + svgFilename;
        String dotFileSource = gsnDotFile.getAbsolutePath();
        Dot2GraphViz objDot2GraphViz = new Dot2GraphViz();
        objDot2GraphViz.generateGraph(dotFileSource, graphDestination);
        System.out.println("Info: Written GSN to svg for " + rootGoalId + ": " + graphDestination);
    }
}
Also used : Model(verdict.vdm.vdm_model.Model) ArrayList(java.util.ArrayList) Mission(verdict.vdm.vdm_model.Mission) File(java.io.File)

Aggregations

Model (verdict.vdm.vdm_model.Model)31 File (java.io.File)18 Test (org.junit.Test)7 Agree2Vdm (com.ge.research.osate.verdict.aadl2vdm.Agree2Vdm)4 VdmTest (com.ge.verdict.vdm.VdmTest)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Ignore (org.junit.Ignore)4 Vdm2Csv (com.ge.research.osate.verdict.vdm2csv.Vdm2Csv)3 VDM2Lustre (edu.uiowa.clc.verdict.lustre.VDM2Lustre)3 CommandLine (org.apache.commons.cli.CommandLine)3 CostModel (com.ge.verdict.synthesis.CostModel)2 BlameAssignment (edu.uiowa.clc.verdict.blm.BlameAssignment)2 JAXBContext (jakarta.xml.bind.JAXBContext)2 JAXBException (jakarta.xml.bind.JAXBException)2 Aadl2Vdm (com.ge.research.osate.verdict.aadl2vdm.Aadl2Vdm)1 GSNInterface (com.ge.verdict.gsn.GSNInterface)1 SecurityGSNInterface (com.ge.verdict.gsn.SecurityGSNInterface)1 VerdictTestInstrumentor (com.ge.verdict.test.instrumentor.VerdictTestInstrumentor)1 Instrumentor (edu.uiowa.clc.verdict.crv.Instrumentor)1