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;
}
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;
}
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;
}
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);
}
}
}
}
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;
}
Aggregations