use of verdict.vdm.vdm_data.DataType 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_data.DataType in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitBoolType.
/**
* Extract a plain bool type.
*/
@Override
public void exitBoolType(LustreParser.BoolTypeContext ctx) {
ctx.dataType = new DataType();
ctx.dataType.setPlainType(PlainType.BOOL);
}
use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitEnumType.
/**
* Extract an enum type.
*/
@Override
public void exitEnumType(LustreParser.EnumTypeContext ctx) {
EnumType enumType = new EnumType();
ctx.ID().forEach(id -> enumType.getEnumValue().add(id.getText()));
ctx.dataType = new DataType();
ctx.dataType.setEnumType(enumType);
}
use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.
the class VDM2Lustre method visit.
public void visit(NodeParameter node_param) {
DataType data_type = node_param.getDataType();
String user_defined_type = null;
if (data_type != null) {
user_defined_type = data_type.getUserDefinedType();
}
if (user_defined_type != null) {
user_defined_type = user_defined_type.replace(".", "_dot_");
user_defined_type = user_defined_type.replace("::", "_double_colon_");
boolean implemented_type = typeDeclarations.containsKey(user_defined_type);
if (implemented_type) {
data_type.setUserDefinedType(user_defined_type);
}
}
}
use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitIntType.
/**
* Extract a plain int type.
*/
@Override
public void exitIntType(LustreParser.IntTypeContext ctx) {
ctx.dataType = new DataType();
ctx.dataType.setPlainType(PlainType.INT);
}
Aggregations