Cleaning up code for runtime, installer, RMI, compiler for the Java side
[iot2.git] / iotjava / iotruntime / master / ProcessJailConfig.java
index 7b080fdec1bf4ff680967fd83467816377f6d31b..8b64837159e15ce9b84ddeb0332758b33f7c68ee 100644 (file)
@@ -31,11 +31,12 @@ public final class ProcessJailConfig {
         */
        private static final String STR_SSH_USERNAME_ROUTER = "root";
        private static final String STR_SSH_USERNAME_HOST   = "iotuser";
-       private static final String STR_TCP_PROTOCOL = "tcp";
-       private static final String STR_UDP_PROTOCOL = "udp";
-       private static final String STR_TCPGW_PROTOCOL = "tcpgw";
-       private static final String STR_NO_PROTOCOL = "nopro";
+       private static final String STR_TCP_PROTOCOL        = "tcp";
+       private static final String STR_UDP_PROTOCOL        = "udp";
+       private static final String STR_TCPGW_PROTOCOL      = "tcpgw";
+       private static final String STR_NO_PROTOCOL         = "nopro";
 
+       private static final String STR_ADD_MAC_EXT             = ".tomoyo";
        private static final String STR_MAC_POLICY_EXT          = ".tomoyo.pol";
        private static final String STR_OBJECT_NAME             = "<object-name>";
        private static final String STR_OBJECT_CLASS_NAME       = "<object-class-name>";
@@ -46,6 +47,9 @@ public final class ProcessJailConfig {
        private static final String STR_DEV_IP_ADDRESS          = "<dev-ip-address>";
        private static final String STR_DEV_COM_PORT            = "<dev-com-port>";
        private static final String STR_DEV_PORT                        = "<dev-port>";
+       
+    private static final int INT_HTTP_PORT = 80;
+    private static final int INT_DNS_PORT  = 53;
 
 
        /**
@@ -101,6 +105,19 @@ public final class ProcessJailConfig {
                }
        }
        
+       
+       /**
+        * flush() flushes all PrintWriter objects
+        *
+        * @return  void
+        */
+       public void flush() {
+
+               for(PrintWriter pwConfig: mapHostToFile.values()) {
+                       pwConfig.flush();
+               }
+       }
+       
 
        /**
         * close() closes all PrintWriter objects
@@ -201,7 +218,6 @@ public final class ProcessJailConfig {
         */
        public void getAddressList(String strRouterAddress) {
 
-               //HashMap<String,String> hmMACToIPAdd = new HashMap<String,String>();
                try {
                        // We can replace "cat /tmp/dhcp.leases" with "cat /proc/net/arp"
                        String cmd = "ssh " + STR_SSH_USERNAME_ROUTER + "@" + strRouterAddress +
@@ -282,8 +298,6 @@ public final class ProcessJailConfig {
                        replace(STR_OBJECT_CLASS_NAME, strObjectClassName).
                        replace(STR_MASTER_IP_ADDRESS, strMasterIPAddress).
                        replace(STR_MASTER_COM_PORT, String.valueOf(iComPort));
-                       //replace(STR_RMI_REG_PORT, String.valueOf(iRMIRegPort)).
-                       //replace(STR_RMI_STUB_PORT, String.valueOf(iRMIStubPort));
                pwConfig.println("\n");
                pwConfig.print(strNewPolicyList);
                pwConfig.println("network inet stream bind/listen :: " + iRMIRegPort);
@@ -316,6 +330,46 @@ public final class ProcessJailConfig {
        }
 
 
+       /**
+        * configureProcessJailDevicePolicies() method configures the device MAC policies
+        * <p>
+        * 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, String strDeviceIPAddress, 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 stream connect ::ffff:" + strDeviceIPAddress + " " + String.valueOf(INT_HTTP_PORT));     // HTTP access for this address
+               pwConfig.println("network inet dgram send " + strRouterAddress + " " + String.valueOf(iPort));
+       }
+
+
+       /**
+        * configureProcessJailDeviceDriverInetAddressPolicies() method configures the device MAC policies
+        * <p>
+        *
+        * @param   strConfigHost       String hostname to be configured
+        * @param   strAddress          String device IP address
+        * @return  void
+        */
+       public void configureProcessJailInetAddressPolicies(String strConfigHost, String strRouterAddress, String strAddress) {
+
+               PrintWriter pwConfig = getPrintWriter(strConfigHost);
+               pwConfig.println("file read /etc/resolv.conf");
+               pwConfig.println("file read /etc/hosts");
+               pwConfig.println("file read /etc/host.conf");
+               pwConfig.println("network inet dgram send " + strRouterAddress + " " + String.valueOf(INT_DNS_PORT));   // TCP/UDP access through router
+               pwConfig.println("network inet stream connect ::ffff:" + strAddress + " " + String.valueOf(INT_HTTP_PORT));     // HTTP access for this address
+       }
+
+
        /**
         * configureProcessJailControllerPolicies() method configures the main MAC policies for controller
         *
@@ -359,6 +413,21 @@ public final class ProcessJailConfig {
        }
 
 
+       /**
+        * combineAdditionalMACPolicy() method combines the additional MAC policies into the right host policy file
+        *
+        * @param   strConfigHost                       String hostname to be configured
+        * @param   strFileName                         String policy file path and name
+        * @return  void
+        */
+       public void combineAdditionalMACPolicy(String strMACCfgPath, String strObjectName, String strConfigHost) {
+
+               PrintWriter pwConfig = getPrintWriter(strConfigHost);
+               String strPolicyList = readFile(strMACCfgPath + strObjectName + STR_ADD_MAC_EXT);
+               pwConfig.println(strPolicyList);
+       }
+
+
        /**
         * combineControllerMACPolicies() method combines the controller MAC policies into the right host policy file
         *