From 8ebde8f123de0b852b91c62ee764b3ae0fb666cc Mon Sep 17 00:00:00 2001 From: rtrimana Date: Mon, 24 Apr 2017 13:54:56 -0700 Subject: [PATCH] Completing Tomoyo policies for irrigation benchmark --- iotjava/iotruntime/master/IoTMaster.java | 15 ++++++-- .../iotruntime/master/ProcessJailConfig.java | 36 +++++++++++++++++++ localconfig/tomoyo/Java.tomoyo.pol | 2 ++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/iotjava/iotruntime/master/IoTMaster.java b/iotjava/iotruntime/master/IoTMaster.java index ed199d0..568c939 100644 --- a/iotjava/iotruntime/master/IoTMaster.java +++ b/iotjava/iotruntime/master/IoTMaster.java @@ -138,6 +138,7 @@ public class IoTMaster { private static final String STR_MAC_POL_PATH = "tomoyo/"; private static int INT_SIZE = 4; // send length in the size of integer (4 bytes) + private static final int INT_DNS_PORT = 53; /** * Runtime class name constants - not to be configured by users @@ -730,6 +731,8 @@ public class IoTMaster { routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, STR_TCP_PROTOCOL, iDestDeviceDriverPort); routerConfig.configureRouterHTTPPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress); routerConfig.configureHostHTTPPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress); + // Configure MAC policies + processJailConfig.configureProcessJailGWDevicePolicies(strIoTSlaveObjectHostAdd, STR_ROUTER_ADD, INT_DNS_PORT); } else { // Other port numbers... commHan.addDevicePort(iDestDeviceDriverPort); @@ -753,7 +756,7 @@ public class IoTMaster { * @return void */ private void setRouterPolicyIoTSetAddress(String strFieldIdentifier, Map.Entry map, - String strHostAddress) { + String strHostAddress, String strControllerName) { // Get information from the set SetInstrumenter setInstrumenter = (SetInstrumenter) map.getValue(); @@ -766,6 +769,11 @@ public class IoTMaster { // Get device address String strAddress = (String) arrFieldValues[0]; // Setting up router policies for HTTP/HTTPs + if (strControllerName != null) { + processJailConfig.configureProcessJailInetAddressPolicies(strControllerName, strAddress); + } else { + processJailConfig.configureProcessJailInetAddressPolicies(strHostAddress, strAddress); + } routerConfig.configureRouterHTTPPolicies(STR_ROUTER_ADD, strHostAddress, strAddress); routerConfig.configureHostHTTPPolicies(strHostAddress, strHostAddress, strAddress); } @@ -820,7 +828,7 @@ public class IoTMaster { setRouterPolicyIoTSetDevice(strFieldIdentifier, map, strIoTSlaveObjectHostAdd); } else if(setInstrumenter.getObjTableName().equals(STR_IOT_ADD_CLS)) { // Instrument the IoTAddress - setRouterPolicyIoTSetAddress(strFieldIdentifier, map, strIoTSlaveObjectHostAdd); + setRouterPolicyIoTSetAddress(strFieldIdentifier, map, strIoTSlaveObjectHostAdd, null); } else if(setInstrumenter.getObjTableName().equals(STR_IOT_ZB_ADD_CLS)) { // Instrument the IoTZigbeeAddress - special feature for Zigbee device support RuntimeOutput.print("IoTMaster: IoTZigbeeAddress found! No router policy is set here..", @@ -2101,7 +2109,7 @@ public class IoTMaster { throw new Error(strErrMsg); } else if(setInstrumenter.getObjTableName().equals(STR_IOT_ADD_CLS)) { // Instrument the IoTAddress - setRouterPolicyIoTSetAddress(strFieldName, map, strIoTSlaveControllerHostAdd); + setRouterPolicyIoTSetAddress(strFieldName, map, strIoTSlaveControllerHostAdd, strObjControllerName); instrumentIoTSetAddress(strFieldName, strFieldName, inStream, outStream, STR_LANGUAGE_CONTROLLER); } else { // Any other cases @@ -2184,6 +2192,7 @@ public class IoTMaster { serverSocket.close(); commHan.printLists(); lbIoT.printHostInfo(); + // TODO: Uncomment this - just for experiments! createMACPolicyThreads(setAddresses); } diff --git a/iotjava/iotruntime/master/ProcessJailConfig.java b/iotjava/iotruntime/master/ProcessJailConfig.java index 7b080fd..4781fbd 100644 --- a/iotjava/iotruntime/master/ProcessJailConfig.java +++ b/iotjava/iotruntime/master/ProcessJailConfig.java @@ -316,6 +316,42 @@ public final class ProcessJailConfig { } + /** + * configureProcessJailDevicePolicies() method configures the device MAC policies + *

+ * This method configures the device policies between device driver and device + * + * @param strConfigHost String hostname to be configured + * @param strRouterAddress String router address + * @param iPort Integer port + * @return void + */ + public void configureProcessJailGWDevicePolicies(String strConfigHost, String strRouterAddress, int iPort) { + + PrintWriter pwConfig = getPrintWriter(strConfigHost); + pwConfig.println("file read /home/iotuser/iot2/iotjava/iotruntime/\\*.jks"); + pwConfig.println("file read /etc/resolv.conf"); + pwConfig.println("file read /etc/hosts"); + pwConfig.println("network inet dgram send " + strRouterAddress + " " + String.valueOf(iPort)); + } + + + /** + * configureProcessJailDeviceDriverInetAddressPolicies() method configures the device MAC policies + *

+ * + * @param strConfigHost String hostname to be configured + * @param strAddress String device IP address + * @return void + */ + public void configureProcessJailInetAddressPolicies(String strConfigHost, String strAddress) { + + PrintWriter pwConfig = getPrintWriter(strConfigHost); + //System.out.println("\n\nDEBUG: Writing the config host address setup!!!\n\n"); + pwConfig.println("network inet stream connect ::ffff:" + strAddress + " " + String.valueOf(80)); // HTTP access for this address + } + + /** * configureProcessJailControllerPolicies() method configures the main MAC policies for controller * diff --git a/localconfig/tomoyo/Java.tomoyo.pol b/localconfig/tomoyo/Java.tomoyo.pol index 083348b..efcc432 100644 --- a/localconfig/tomoyo/Java.tomoyo.pol +++ b/localconfig/tomoyo/Java.tomoyo.pol @@ -43,6 +43,8 @@ file read /home/iotuser/iot2/iotjava/iotruntime/\*.config network inet stream connect ::ffff: file read /home/iotuser/iot2/iotjava/iotruntime/master/\*.class file read /home/iotuser/iot2/iotjava/iotruntime/messages/\*.class +file read /home/iotuser/iot2/iotjava/iotruntime/zigbee/\*.class +file read /home/iotuser/iot2/iotjava/iotruntime/resources/\*.csv file read /dev/random file read /dev/urandom file create /home/iotuser/iot2/iotjava/iotruntime/.jar 0666 -- 2.34.1