From: rtrimana <rtrimana@uci.edu>
Date: Wed, 4 Jan 2017 19:32:40 +0000 (-0800)
Subject: Applying changes for 3rd benchmark (wildcard addresses) in IoTMaster
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e1efcd1397214872d9215fc63eb5d4ccaed5ab50;p=iot2.git

Applying changes for 3rd benchmark (wildcard addresses) in IoTMaster
---

diff --git a/iotjava/iotruntime/master/CommunicationHandler.java b/iotjava/iotruntime/master/CommunicationHandler.java
index 6f9c67a..def3e77 100644
--- a/iotjava/iotruntime/master/CommunicationHandler.java
+++ b/iotjava/iotruntime/master/CommunicationHandler.java
@@ -69,6 +69,7 @@ public final class CommunicationHandler {
 	private Set<Integer> hsDevicePort;
 	private Set<Integer> hsCallbackPort;
 	private Map<Integer, Integer[]> hmCallbackPort;
+	private Map<Integer, Integer> hmAdditionalPort;
 	private int iNumOfObjects;
 	private int iNumOfHosts;
 	private boolean bVerbose;
@@ -99,6 +100,7 @@ public final class CommunicationHandler {
 		hsDevicePort = new HashSet<Integer>();
 		hsCallbackPort = new HashSet<Integer>();
 		hmCallbackPort = new HashMap<Integer, Integer[]>();
+		hmAdditionalPort = new HashMap<Integer, Integer>();
 		iNumOfObjects = 0;
 		iNumOfHosts = 0;
 		bVerbose = _bVerbose;
@@ -254,6 +256,30 @@ public final class CommunicationHandler {
 
 	}
 
+	/**
+	 * Method addAdditionalPort()
+	 * <p>
+	 * Add a new port for new connections for any objects in the program.
+	 * This newly generated port number will be recorded.
+	 *
+	 * @return  int		One new port
+	 */
+	public int addAdditionalPort(String sAObject) {
+
+		hmActiveObj.put(sAObject, iNumOfObjects);
+
+		int iAdditionalPort = 0;
+		do {
+			iAdditionalPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
+			// Check port existence in HashMap
+		} while (portIsAvailable(iAdditionalPort) == false);
+		hmAdditionalPort.put(iNumOfObjects, iAdditionalPort);
+
+		iNumOfObjects++;
+
+		return iAdditionalPort;
+	}
+
 	/**
 	 * Method portIsAvailable()
 	 * <p>
@@ -272,6 +298,8 @@ public final class CommunicationHandler {
 			return false;
 		} else if (hmRMIStubPort.containsValue(iPortNumber) == true) {
 			return false;
+		} else if (hmAdditionalPort.containsValue(iPortNumber) == true) {
+			return false;
 		} else if (hsDevicePort.contains(iPortNumber) == true) {
 			return false;
 		} else if (hsCallbackPort.contains(iPortNumber) == true) {
@@ -367,6 +395,19 @@ public final class CommunicationHandler {
 		return hmComPort.get(hmActiveObj.get(sAObject));
 	}
 
+	/**
+	 * Method getAdditionalPort()
+	 * <p>
+	 * User finds a port number using Object name
+	 *
+	 * @param   sAObject  String active object name
+	 * @return  Integer
+	 */
+	public Integer getAdditionalPort(String sAObject) {
+
+		return hmAdditionalPort.get(hmActiveObj.get(sAObject));
+	}
+
 	/**
 	 * Method getRMIRegPort()
 	 * <p>
diff --git a/iotjava/iotruntime/master/IoTMaster.java b/iotjava/iotruntime/master/IoTMaster.java
index 34f181a..e35d775 100644
--- a/iotjava/iotruntime/master/IoTMaster.java
+++ b/iotjava/iotruntime/master/IoTMaster.java
@@ -368,9 +368,14 @@ public class IoTMaster {
 				commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
 			}
 			// Send address one by one
-			Message msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
-				strDeviceAddress, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort,
-				bSrcPortWildCard, bDstPortWildCard);
+			Message msgGetIoTSetObj = null;
+			if (bDstPortWildCard) {
+				String strUniqueDev = strDeviceAddress + ":" + iRow;
+				msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
+					strDeviceAddress, commHan.getAdditionalPort(strUniqueDev), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
+			} else
+				msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
+					strDeviceAddress, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
 			commMasterToSlave(msgGetIoTSetObj, "Get IoTSet objects!", inStream, outStream);
 		}
 		// Reinitialize IoTSet on device object
@@ -597,6 +602,15 @@ public class IoTMaster {
 			if (commHan.getComPort(strDeviceAddress) == null) {
 				commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
 			}
+			boolean bDstPortWildCard = false;
+			// Recognize this and allocate different ports for it
+			if (arrFieldValues.length > 3) {
+				bDstPortWildCard = (boolean) arrFieldValues[4];
+				if (bDstPortWildCard) {	// This needs a unique source port
+					String strUniqueDev = strDeviceAddress + ":" + iRow;
+					commHan.addAdditionalPort(strUniqueDev);
+				}
+			}
 			// Send routing policy to router for device drivers and devices
 			// ROUTING POLICY: RMI communication - RMI registry and stub ports
 			if((iDestDeviceDriverPort == -1) && (!strProtocol.equals(STR_NO_PROTOCOL))) {