Adding options to disable/enable firewall policy and choose MAC/IP translation methods
[iot2.git] / iotjava / iotruntime / master / IoTMaster.java
index 454ca306e2cfd6aa4ea03f886a23cc2a1525b81b..15948bf633de21d17394055eccc2dcbf9bfc6953 100644 (file)
@@ -103,6 +103,8 @@ public final class IoTMaster {
        private static String STR_SKEL_CLASS_SUFFIX;
        private static String STR_STUB_CLASS_SUFFIX;
        private static String STR_ACTIVATE_SANDBOXING;
+       private static String STR_POLICY_ON;
+       private static String STR_MAC_TO_IP_TRANSLATION;
        private static boolean BOOL_VERBOSE;
 
        /**
@@ -138,6 +140,8 @@ public final class IoTMaster {
        private static final String STR_SHELL_HEADER = "#!/bin/sh";
        private static final String STR_JAVA_PATH = "/usr/bin/java";
        private static final String STR_MAC_POL_PATH = "tomoyo/";
+        private static final String STR_TMP = "tmp";
+        private static final String STR_ARP = "arp";
 
        private static int INT_SIZE = 4;        // send length in the size of integer (4 bytes)
        private static final int INT_DNS_PORT = 53;
@@ -201,6 +205,8 @@ public final class IoTMaster {
                STR_JVM_MAX_HEAP_SIZE = null;
                STR_LANGUAGE_CONTROLLER = null;
                STR_ACTIVATE_SANDBOXING = null;
+               STR_POLICY_ON = null;
+               STR_MAC_TO_IP_TRANSLATION = null;
                BOOL_VERBOSE = false;
        }
 
@@ -215,7 +221,13 @@ public final class IoTMaster {
                lbIoT = new LoadBalancer(BOOL_VERBOSE);
                lbIoT.setupLoadBalancer();
                routerConfig = new RouterConfig();
-               routerConfig.getAddressList(STR_ROUTER_ADD);
+               // Get MAC to IP translation either from /tmp/dhcp.leases or arp command
+               if (STR_MAC_TO_IP_TRANSLATION.equals(STR_TMP))
+                       routerConfig.getAddressListTmp(STR_ROUTER_ADD);
+               else if (STR_MAC_TO_IP_TRANSLATION.equals(STR_ARP))
+                       routerConfig.getAddressListArp(STR_ROUTER_ADD);
+               else
+                       throw new Error("IoTMaster: Unknown value for STR_MAC_TO_IP_TRANSLATION: " + STR_MAC_TO_IP_TRANSLATION);
                processJailConfig = new ProcessJailConfig();
                //processJailConfig.setAddressListObject(routerConfig.getAddressListObject());
                objInitHand = new ObjectInitHandler(BOOL_VERBOSE);
@@ -281,6 +293,8 @@ public final class IoTMaster {
                STR_SKEL_CLASS_SUFFIX = prop.getProperty("SKEL_CLASS_SUFFIX");
                STR_STUB_CLASS_SUFFIX = prop.getProperty("STUB_CLASS_SUFFIX");
                STR_ACTIVATE_SANDBOXING = prop.getProperty("ACTIVATE_SANDBOXING");
+               STR_POLICY_ON = prop.getProperty("POLICY_ON");
+               STR_MAC_TO_IP_TRANSLATION = prop.getProperty("MAC_TO_IP_TRANSLATION");
                if(prop.getProperty("VERBOSE").equals(STR_YES)) {
                        BOOL_VERBOSE = true;
                }
@@ -306,6 +320,8 @@ public final class IoTMaster {
                RuntimeOutput.print("STR_SKEL_CLASS_SUFFIX=" + STR_SKEL_CLASS_SUFFIX, BOOL_VERBOSE);
                RuntimeOutput.print("STR_STUB_CLASS_SUFFIX=" + STR_STUB_CLASS_SUFFIX, BOOL_VERBOSE);
                RuntimeOutput.print("STR_ACTIVATE_SANDBOXING=" + STR_ACTIVATE_SANDBOXING, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_POLICY_ON=" + STR_POLICY_ON, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_MAC_TO_IP_TRANSLATION=" + STR_MAC_TO_IP_TRANSLATION, BOOL_VERBOSE);
                RuntimeOutput.print("BOOL_VERBOSE=" + BOOL_VERBOSE, BOOL_VERBOSE);
                RuntimeOutput.print("IoTMaster: Information extracted successfully!", BOOL_VERBOSE);
        }
@@ -2181,7 +2197,9 @@ public final class IoTMaster {
                                // Deploy the policy
                                setAddresses = new HashSet<String>(commHan.getHosts());
                                setAddresses.add(strIoTMasterHostAdd);
-                               createPolicyThreads(STR_ROUTER_ADD, setAddresses);
+                               // See if firewall policy is configured to be "on" or "off"
+                               if (STR_POLICY_ON.equals(STR_YES))
+                                       createPolicyThreads(STR_ROUTER_ADD, setAddresses);
 
                                // PROFILING
                                result = System.currentTimeMillis()-start;