Adjusting runtime system back after paper evaluation - putting back RMI port and...
[iot2.git] / iotjava / iotruntime / master / CommunicationHandler.java
index 15db69022eeaf98d0c04adcac6f2d1c8847ea8c0..5d257722772b03d9480bb67df92e36967755b6b0 100644 (file)
@@ -67,11 +67,19 @@ public final class CommunicationHandler {
        private Map<Integer, Integer> hmRMIRegPort;
        private Map<Integer, Integer> hmRMIStubPort;
        private Set<Integer> hsDevicePort;
+       private Set<Integer> hsAllPorts;
        private Map<Integer, Integer> hmAdditionalPort;
        private int iNumOfObjects;
        private int iNumOfHosts;
        private boolean bVerbose;
 
+       // TODO: THIS IS HACKING FOR IOTSEC
+       // Replace random
+       private int comPortCount = 10000;
+       private int rmiRegCount = 20000;
+       private int rmiStubCount = 30000;
+       private int additionalCount = 40000;
+
        /**
         * CommunicationHandler class constants
         */
@@ -96,12 +104,40 @@ public final class CommunicationHandler {
                hmRMIRegPort = new HashMap<Integer, Integer>();
                hmRMIStubPort = new HashMap<Integer, Integer>();
                hsDevicePort = new HashSet<Integer>();
+               hsAllPorts = new HashSet<Integer>();
                hmAdditionalPort = new HashMap<Integer, Integer>();
                iNumOfObjects = 0;
                iNumOfHosts = 0;
                bVerbose = _bVerbose;
                RuntimeOutput.print("CommunicationHandler: Creating a new CommunicationHandler object!", bVerbose);
        }
+       
+       /**
+        * Method clearCommunicationHandler()
+        * <p>
+        * Clear the data structure
+        *
+        * @return  void
+        */
+       public void clearCommunicationHandler() {
+
+               listActiveControllerObj.clear();
+               listFieldObjectID.clear();
+               listObjCrtInfo.clear();
+               listArrFieldValues.clear();
+               listArrFieldClasses.clear();
+               hmActiveObj.clear();
+               hmHostAdd.clear();
+               hmHostList.clear();
+               hmComPort.clear();
+               hmRMIRegPort.clear();
+               hmRMIStubPort.clear();
+               hsDevicePort.clear();
+               hmAdditionalPort.clear();
+               iNumOfObjects = 0;
+               iNumOfHosts = 0;
+               RuntimeOutput.print("CommunicationHandler: Clearing CommunicationHandler object's data structure!", bVerbose);
+    }
 
        /**
         * Method addPortConnection()
@@ -136,23 +172,33 @@ public final class CommunicationHandler {
                int iComPort = 0;
                do {
                        iComPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
+                       //System.out.println("DEBUG: Assigning comPort: " + comPortCount);
+                       //iComPort = comPortCount++;
                        // Check port existence in HashMap
                } while (portIsAvailable(iComPort) == false);
                hmComPort.put(iNumOfObjects, iComPort);
+               // hsAllPorts tracks all the existing and used port numbers
+               hsAllPorts.add(iComPort);
 
                int iRMIRegPort = 0;
                do {
                        iRMIRegPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
+                       //System.out.println("DEBUG: Assigning regPort: " + rmiRegCount);
+                       //iRMIRegPort = rmiRegCount++;
                        // Check port existence in HashMap
                } while (portIsAvailable(iRMIRegPort) == false);
                hmRMIRegPort.put(iNumOfObjects, iRMIRegPort);
+               hsAllPorts.add(iRMIRegPort);
 
                int iRMIStubPort = 0;
                do {
                        iRMIStubPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
+                       //System.out.println("DEBUG: Assigning stubPort: " + rmiStubCount);
+                       //iRMIStubPort = rmiStubCount++;
                        // Check port existence in HashMap
                } while (portIsAvailable(iRMIStubPort) == false);
                hmRMIStubPort.put(iNumOfObjects, iRMIStubPort);
+               hsAllPorts.add(iRMIStubPort);
 
                iNumOfObjects++;
        }
@@ -194,7 +240,8 @@ public final class CommunicationHandler {
        public void addDevicePort(int iDevPort) {
 
                hsDevicePort.add(iDevPort);
-
+               // Track this port number
+        hsAllPorts.add(iDevPort);
        }
 
        /**
@@ -212,9 +259,13 @@ public final class CommunicationHandler {
                int iAdditionalPort = 0;
                do {
                        iAdditionalPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
+                       //System.out.println("DEBUG: Assigning additionalPort: " + additionalCount);
+                       //iAdditionalPort = additionalCount++;
                        // Check port existence in HashMap
                } while (portIsAvailable(iAdditionalPort) == false);
                hmAdditionalPort.put(iNumOfObjects, iAdditionalPort);
+               // Track this port number
+               hsAllPorts.add(iAdditionalPort);
 
                iNumOfObjects++;
 
@@ -246,6 +297,11 @@ public final class CommunicationHandler {
                } else {
                        return true;
                }
+               //if (hsAllPorts.contains(iPortNumber)) {
+               //    return false;
+               //} else {
+               //    return true;
+               //}
        }
 
        /**