Search in sources :

Example 1 with BlockImpl

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

the class VDMInstrumentor method retrieve_block.

protected BlockImpl retrieve_block(ComponentType compType) {
    BlockImpl blockImpl = null;
    for (ComponentImpl cmpImpl : vdm_model.getComponentImpl()) {
        if (cmpImpl.getBlockImpl() != null) {
            blockImpl = cmpImpl.getBlockImpl();
            for (ComponentInstance cmpInstance : blockImpl.getSubcomponent()) {
                ComponentImpl impl = cmpInstance.getImplementation();
                ComponentType enumType = null;
                if (impl != null) {
                    enumType = impl.getType();
                } else {
                    enumType = cmpInstance.getSpecification();
                }
                if (compType.getId().equals(enumType.getId())) {
                    return blockImpl;
                }
            }
        }
    }
    return blockImpl;
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Example 2 with BlockImpl

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

the class VDMInstrumentor method retrieve_cmp_impl.

protected ComponentImpl retrieve_cmp_impl(ComponentType componentType) {
    ComponentImpl componentImpl = null;
    BlockImpl blockImpl = null;
    for (ComponentImpl cImpl : vdm_model.getComponentImpl()) {
        if (cImpl.getBlockImpl() != null) {
            blockImpl = cImpl.getBlockImpl();
            for (ComponentInstance cmpInstance : blockImpl.getSubcomponent()) {
                ComponentImpl impl = cmpInstance.getImplementation();
                ComponentType enumType = null;
                if (impl != null) {
                    enumType = impl.getType();
                } else {
                    enumType = cmpInstance.getSpecification();
                }
                if (componentType.getId().equals(enumType.getId())) {
                    componentImpl = cImpl;
                    return cImpl;
                }
            }
        }
    }
    return componentImpl;
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Example 3 with BlockImpl

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

the class VDMInstrumentor method retrieve_block.

protected BlockImpl retrieve_block(ComponentImpl compImpl) {
    BlockImpl blockImpl = null;
    String cmpID = compImpl.getType().getId();
    for (ComponentImpl cmpImpl : vdm_model.getComponentImpl()) {
        if (cmpImpl.getBlockImpl() != null) {
            blockImpl = cmpImpl.getBlockImpl();
            for (ComponentInstance cmpInstance : blockImpl.getSubcomponent()) {
                ComponentImpl impl = cmpInstance.getImplementation();
                ComponentType enumType = null;
                if (impl != null) {
                    enumType = impl.getType();
                } else {
                    enumType = cmpInstance.getSpecification();
                }
                if (cmpID.equals(enumType.getId())) {
                    return blockImpl;
                }
            }
        }
    }
    return blockImpl;
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Example 4 with BlockImpl

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

the class VDMInstrumentor method retrieve_component_and_channels.

protected void retrieve_component_and_channels(Model vdm_model, List<String> threats, boolean blame_assignment, boolean component_level) {
    HashSet<ComponentType> vdm_components = new HashSet<ComponentType>();
    HashSet<Connection> vdm_links = new HashSet<Connection>();
    // Initialize Components with Empty Ports and Ignore
    identifyEmptyOutputComponents();
    // Initialize DataFlow for empty Implementations.
    LustreProgram lt = vdm_model.getDataflowCode();
    if (lt == null) {
        lt = new LustreProgram();
        vdm_model.setDataflowCode(lt);
    }
    if (threats.contains("LS")) {
        System.out.println("Location Spoofing Instrumentation");
        locationSpoofing(vdm_components);
    }
    if (threats.contains("LB")) {
        System.out.println("Logic Bomb Instrumentation");
        logicBomb(vdm_components);
    }
    if (threats.contains("SV")) {
        System.out.println("Software Virus/malware/worm/trojan");
        softwareVirus(vdm_components);
    }
    if (threats.contains("RI")) {
        System.out.println("Remote Code Injection");
        remoteCodeInjection(vdm_components);
    }
    if (threats.contains("OT")) {
        System.out.println("Outsider Threat");
        outsiderThreat(vdm_components);
    }
    if (threats.contains("IT")) {
        System.out.println("Insider Threat");
        insiderThreat(vdm_components);
    }
    if (threats.contains("HT")) {
        System.out.println("Hardware Trojans");
        hardwareTrojan(vdm_components);
    }
    if (threats.contains("NI")) {
        System.out.println("Network Injection Instrumentation");
        // Snooze links for component level blame assignment.
        if (!component_level) {
            networkInjection(vdm_links);
        }
    }
    if (threats.contains("BN")) {
        System.out.println("Benign");
        vdm_components.clear();
        vdm_links.clear();
    }
    // int component_index = 1;
    // Removed Once component Implemtation assumption.
    ComponentImpl componentImpl = retrieve_main_cmp_impl();
    BlockImpl blockImpl = null;
    if (componentImpl != null) {
        blockImpl = componentImpl.getBlockImpl();
    }
    Map<String, HashSet<Connection>> components_map = new HashMap<String, HashSet<Connection>>();
    if (vdm_components.size() > 0) {
        for (ComponentType component : vdm_components) {
            blockImpl = retrieve_block(component);
            HashSet<Connection> vdm_cmp_links = instrument_component(component, blockImpl);
            for (Connection link_con : vdm_cmp_links) {
                // Check if connection contains Empty Component on Port Ends.
                if (!ignoreMarkedLink(link_con)) {
                    // Check if Port is Probe Port
                    if (!isProbePort(link_con)) {
                        vdm_links.add(link_con);
                    }
                }
            }
            components_map.put(component.getId(), vdm_cmp_links);
        }
    }
    // Snoorzing probe ports and Empty output components
    if (vdm_links.size() > 0) {
        Iterator<Connection> it = vdm_links.iterator();
        while (it.hasNext()) {
            Connection con = it.next();
            if (isProbePort(con)) {
                it.remove();
            } else if (ignoreMarkedLink(con)) {
                it.remove();
            }
        }
    }
    HashSet<String> global_constants = new HashSet<String>();
    Map<Connection, String> connections_map = new HashMap<Connection, String>();
    if (vdm_links.size() > 0) {
        for (Connection connection : vdm_links) {
            // System.out.println("(" + connection_index++ + ") " +
            // connection.getName());
            // instrument_link(connection, blockImpl);
            String cmpID = getComponentID(components_map, connection);
            if (cmpID != null) {
                // Find Block based on Connection
                blockImpl = getBlockID(cmpID);
                String constant = instrument_link(cmpID, connection, blockImpl);
                global_constants.add(constant);
                connections_map.put(connection, constant);
            } else {
                // Handle 'NI' as Special Case.
                ConnectionEnd conDest = connection.getSource();
                Port dest_port = conDest.getComponentPort();
                if (dest_port != null) {
                    cmpID = dest_port.getId();
                } else {
                    CompInstancePort compInstance = conDest.getSubcomponentPort();
                    ComponentInstance compInst = compInstance.getSubcomponent();
                    cmpID = compInst.getId();
                }
                blockImpl = retrieve_block(connection);
                String constant = instrument_link(cmpID, connection, blockImpl);
                global_constants.add(constant);
                connections_map.put(connection, constant);
            }
        }
    } else {
        emptySelection = true;
    }
    // Declare Global Constants
    for (String comp_id : global_constants) {
        ConstantDeclaration global_comp_const = new ConstantDeclaration();
        DataType global_comp_dataType = new DataType();
        global_comp_dataType.setPlainType(PlainType.BOOL);
        global_comp_const.setName(comp_id);
        global_comp_const.setDataType(global_comp_dataType);
        // Expression global_expr = new Expression();
        // global_expr.setBoolLiteral(true);
        // global_comp_const.setDefinition(global_expr);
        vdm_model.getDataflowCode().getConstantDeclaration().add(global_comp_const);
    // g_constants.add(global_comp_const);
    }
    Map<String, List<String>> connection_gps_comp_map = connection_gps_mapper(connections_map, components_map);
    // Choosing Blame options
    if (threats.contains("LS") && component_level) {
        // Link Level Instrumentation varibales
        dec_var_asmp_const(connection_gps_comp_map, blame_assignment, false);
    } else if (threats.contains("LS") && !component_level) {
        dec_var_asmp_const(connection_gps_comp_map, blame_assignment, true);
    }
    if (blame_assignment && component_level) {
        Map<String, List<String>> connection_comp_map = connection_mapper(connections_map, components_map);
        ComponentImpl compImpl = retrieve_main_cmp_impl();
        // if (compImpl.getBlockImpl() == null) {
        // compImpl = retrieve_block(compImpl);
        // }
        ContractSpec contractSpec = compImpl.getType().getContract();
        for (String key : components_map.keySet()) {
            String id = key.replace("::", "_double_colon_");
            Expression wk_expr = new Expression();
            wk_expr.setIdentifier(id);
            Expression not_wkexpr = new Expression();
            not_wkexpr.setNot(wk_expr);
            // Adding weakly assume variables
            ContractItem weakly_assume_item = new ContractItem();
            weakly_assume_item.setName(id + " is not instrumented");
            weakly_assume_item.setExpression(not_wkexpr);
            // Checking connection before adding assumption
            HashSet<Connection> empty_connection_check = components_map.get(key);
            if (empty_connection_check.size() > 0) {
                contractSpec.getWeaklyassume().add(weakly_assume_item);
            }
        }
        dec_var_const(connection_comp_map);
    } else if (blame_assignment && !component_level) {
        ComponentImpl compImpl = retrieve_main_cmp_impl();
        if (compImpl != null) {
            // if (compImpl.getBlockImpl() == null) {
            // compImpl = retrieve_block_impl(compImpl);
            // }
            ContractSpec contractSpec = compImpl.getType().getContract();
            for (String key : global_constants) {
                Expression wk_expr = new Expression();
                wk_expr.setIdentifier(key);
                Expression not_wkexpr = new Expression();
                not_wkexpr.setNot(wk_expr);
                // Adding weakly assume variables
                ContractItem weakly_assume_item = new ContractItem();
                weakly_assume_item.setName(link_name(key) + " is not instrumented");
                weakly_assume_item.setExpression(not_wkexpr);
                contractSpec.getWeaklyassume().add(weakly_assume_item);
            }
        }
    }
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) HashMap(java.util.HashMap) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ConstantDeclaration(verdict.vdm.vdm_lustre.ConstantDeclaration) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) ContractItem(verdict.vdm.vdm_lustre.ContractItem) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) DataType(verdict.vdm.vdm_data.DataType) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) ComponentType(verdict.vdm.vdm_model.ComponentType) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Connection(verdict.vdm.vdm_model.Connection) Expression(verdict.vdm.vdm_lustre.Expression) LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd)

Example 5 with BlockImpl

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

the class VDMInstrumentor method retrieve_block_impl.

protected ComponentImpl retrieve_block_impl(ComponentImpl compImpl) {
    BlockImpl blockImpl = null;
    String cmpID = compImpl.getType().getId();
    for (ComponentImpl cImpl : vdm_model.getComponentImpl()) {
        if (cImpl.getBlockImpl() != null) {
            blockImpl = cImpl.getBlockImpl();
            for (ComponentInstance cmpInstance : blockImpl.getSubcomponent()) {
                ComponentImpl impl = cmpInstance.getImplementation();
                ComponentType enumType = null;
                if (impl != null) {
                    enumType = impl.getType();
                } else {
                    enumType = cmpInstance.getSpecification();
                }
                if (cmpID.equals(enumType.getId())) {
                    // compImpl.getId());
                    return cImpl;
                }
            }
        }
    }
    return compImpl;
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Aggregations

BlockImpl (verdict.vdm.vdm_model.BlockImpl)17 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)17 ComponentInstance (verdict.vdm.vdm_model.ComponentInstance)17 ComponentType (verdict.vdm.vdm_model.ComponentType)16 HashSet (java.util.HashSet)9 GenericAttribute (verdict.vdm.vdm_data.GenericAttribute)8 Connection (verdict.vdm.vdm_model.Connection)5 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)3 Port (verdict.vdm.vdm_model.Port)3 PortMode (verdict.vdm.vdm_model.PortMode)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DataType (verdict.vdm.vdm_data.DataType)1 ConstantDeclaration (verdict.vdm.vdm_lustre.ConstantDeclaration)1 ContractItem (verdict.vdm.vdm_lustre.ContractItem)1 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)1 Expression (verdict.vdm.vdm_lustre.Expression)1 LustreProgram (verdict.vdm.vdm_lustre.LustreProgram)1 NodeBody (verdict.vdm.vdm_lustre.NodeBody)1