X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotruntime%2Fmaster%2FIoTMaster.java;h=70ae6b876c9e8cd849b266a2a5032cf6dd2753ae;hb=7e8c0cabb7057ad561adbb8b6cc2a0fd5c41bbf4;hp=454ca306e2cfd6aa4ea03f886a23cc2a1525b81b;hpb=aaa765a192fdcd2aaa05fb6b276424652578d0e8;p=iot2.git diff --git a/iotjava/iotruntime/master/IoTMaster.java b/iotjava/iotruntime/master/IoTMaster.java index 454ca30..70ae6b8 100644 --- a/iotjava/iotruntime/master/IoTMaster.java +++ b/iotjava/iotruntime/master/IoTMaster.java @@ -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,9 +221,14 @@ 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); objAddInitHand = new ObjectAddressInitHandler(BOOL_VERBOSE); mapClassNameToCrim = new HashMap(); @@ -281,6 +292,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 +319,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); } @@ -330,9 +345,9 @@ public final class IoTMaster { System.out.println("IoTMaster: Error reading config file: " + strCfgFileName); ex.printStackTrace(); } - System.out.println("IoTMaster: Reading " + strCfgField + + RuntimeOutput.print("IoTMaster: Reading " + strCfgField + " from config file: " + strCfgFileName + " with value: " + - prop.getProperty(strCfgField, null)); + prop.getProperty(strCfgField, null), BOOL_VERBOSE); // NULL is returned if the property isn't found return prop.getProperty(strCfgField, null); } @@ -407,7 +422,7 @@ public final class IoTMaster { * @params strFieldName String field name * @params strIoTSlaveObjectHostAdd String slave host address * @params inStream ObjectInputStream communication - * @params inStream ObjectOutputStream communication + * @params outStream ObjectOutputStream communication * @params strLanguage String language * @return void */ @@ -452,12 +467,6 @@ public final class IoTMaster { if (commHan.getComPort(strDeviceAddressKey) == null) { commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddressKey); } - - // TODO: DEBUG!!! - System.out.println("\n\n DEBUG: InstrumentSetDevice: Object Name: " + strObjName); - System.out.println("DEBUG: InstrumentSetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey)); - System.out.println("DEBUG: InstrumentSetDevice: Device address: " + strDeviceAddressKey + "\n\n"); - // Send address one by one if(strLanguage.equals(STR_JAVA)) { Message msgGetIoTSetObj = null; @@ -518,12 +527,6 @@ public final class IoTMaster { } int iRows = setInstrumenter.numberOfRows(); RuntimeOutput.print("IoTMaster: Number of rows for IoTZigbeeAddress: " + iRows, BOOL_VERBOSE); - - // TODO: DEBUG!!! - System.out.println("\n\nDEBUG: InstrumentZigbeeDevice: Object Name: " + strObjName); - System.out.println("DEBUG: InstrumentZigbeeDevice: Port number: " + commHan.getComPort(strZigbeeGWAddressKey)); - System.out.println("DEBUG: InstrumentZigbeeDevice: Device address: " + strZigbeeGWAddress + "\n\n"); - // Transfer the address for(int iRow=0; iRow " + STR_LOG_FILE_PATH + strObjName + ".log &"; @@ -947,7 +941,7 @@ public final class IoTMaster { // Send the file to the compute node String strCmdSend = "scp " + shellFile + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + ":" + STR_RUNTIME_DIR; runCommand(strCmdSend); - System.out.println("IoTMaster: Sending shell file: " + strCmdSend); + RuntimeOutput.print("IoTMaster: Sending shell file: " + strCmdSend, BOOL_VERBOSE); return STR_SSH + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + " cd " + STR_RUNTIME_DIR + " " + shellFile; } @@ -1004,12 +998,6 @@ public final class IoTMaster { strLanguageDriver = parseConfigFile(sCfgFile, STR_LANGUAGE); if(strLanguageDriver == null) // Check nullness for the second time - report if it is still null throw new Error("IoTMaster: Language specification missing in config file: " + sCfgFile); - // PROFILING - long start = 0; - long result = 0; - // PROFILING - start = System.currentTimeMillis(); - // Construct ssh command line // e.g. ssh rtrimana@dw-2.eecs.uci.edu cd ; // java -cp $CLASSPATH:./*.jar @@ -1024,7 +1012,6 @@ public final class IoTMaster { else throw new Error("IoTMaster: Language specification not recognized: " + strLanguageDriver); RuntimeOutput.print("IoTMaster: Language for " + strObjName + " is " + strLanguageDriver, BOOL_VERBOSE); - RuntimeOutput.print(strSSHCommand, BOOL_VERBOSE); // Start a new thread to start a new JVM createThread(strSSHCommand); @@ -1042,14 +1029,6 @@ public final class IoTMaster { outStream = new BufferedOutputStream(socket.getOutputStream()); recvAck(inStream); } - - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> Time needed to start JVM for " + strObjName + ": " + result + "\n\n"); - - // PROFILING - start = System.currentTimeMillis(); - if(strLanguageDriver.equals(STR_JAVA)) { sendFileToJavaSlaveDriver(serverSocket, inStream, outStream, strObjName, strObjClassName, strObjClassInterfaceName, strObjStubClsIntfaceName, @@ -1060,14 +1039,6 @@ public final class IoTMaster { commHan.getRMIRegPort(strObjName), commHan.getRMIStubPort(strObjName), arrFieldValues, arrFieldClasses, outStream, inStream); } - - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> Time needed to send JAR file for " + strObjName + ": " + result + "\n\n"); - - // PROFILING - start = System.currentTimeMillis(); - // Instrument the class source code and look for IoTSet for device addresses // e.g. @config private IoTSet lb_addresses; RuntimeOutput.print("IoTMaster: Instantiating for " + strObjClassName + " with objectID " + strFieldObjectID, BOOL_VERBOSE); @@ -1125,11 +1096,6 @@ public final class IoTMaster { createDriverObjectCpp(outStream, inStream); //endSessionCpp(outStream); } - - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> Time needed to create object " + strObjName + " and instrument IoTDeviceAddress: " + result + "\n\n"); - // Closing streams outStream.close(); inStream.close(); @@ -1353,7 +1319,6 @@ public final class IoTMaster { reinitializeIoTSetFieldCpp(outStream, inStream); } else if (iotcommMsg == IoTCommCode.CREATE_NEW_IOTRELATION) { // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO CREATE IOTRELATION - // TODO: createNewIoTRelation needs to be created here! createNewIoTRelationCpp(str, outStream, inStream); List listObject = objInitHand.getListObjectInitInfo(str); List listSecondObject = objInitHand.getSecondObjectInitInfo(str); @@ -2059,13 +2024,6 @@ public final class IoTMaster { recvAck(inStream); } RuntimeOutput.print("IoTMaster: Communication established!", BOOL_VERBOSE); - - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> From start until after SSH for main controller: " + result); - // PROFILING - start = System.currentTimeMillis(); - // Send files for every controller class // e.g. AcmeProximity.jar and AcmeProximity.zip String strControllerClassName = strObjControllerName + STR_CLS_FILE_EXT; @@ -2096,13 +2054,6 @@ public final class IoTMaster { processJailConfig.combineAdditionalMACPolicy(strContMACCfg, strObjControllerName, strObjControllerName); } } - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> From IoTSlave start until main controller object is created: " + result); - System.out.println(" ==> Including file transfer times!\n\n"); - // PROFILING - start = System.currentTimeMillis(); - // == END INITIALIZING CONTROLLER/DEVICE IOTSLAVE == // Instrumenting one file RuntimeOutput.print("IoTMaster: Opening class file: " + strControllerClassName, BOOL_VERBOSE); @@ -2130,11 +2081,6 @@ public final class IoTMaster { // SetInstrumenter vs. RelationInstrumenter String strFieldName = map.getKey(); String strClassName = map.getValue().getClass().getName(); - - System.out.println("\n\nDEBUG: Instrumenting IoTSet and IoTRelation objects!!!"); - System.out.println("DEBUG: Field name: " + strFieldName); - System.out.println("DEBUG: Class name: " + strFieldName + "\n\n"); - if(strClassName.equals(STR_SET_INSTRUMENTER_CLS)) { SetInstrumenter setInstrumenter = (SetInstrumenter) map.getValue(); if(setInstrumenter.getObjTableName().equals(STR_IOT_DEV_ADD_CLS)) { @@ -2161,15 +2107,6 @@ public final class IoTMaster { String strTempFileName = "./" + strObjControllerName + STR_MAC_POLICY_EXT; processJailConfig.combineControllerMACPolicies(strIoTSlaveControllerHostAdd, strObjControllerName, strTempFileName); processJailConfig.flush(); - - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> Time needed to instrument device driver objects: " + result + "\n\n"); - System.out.println(" ==> #Objects: " + commHan.getActiveControllerObjectList().size() + "\n\n"); - - // PROFILING - start = System.currentTimeMillis(); - // ROUTING POLICY: implement basic policies to reject all other irrelevant traffics for(String s: commHan.getHosts()) { setHostBasicPolicies(s); @@ -2181,34 +2118,16 @@ public final class IoTMaster { // Deploy the policy setAddresses = new HashSet(commHan.getHosts()); setAddresses.add(strIoTMasterHostAdd); - createPolicyThreads(STR_ROUTER_ADD, setAddresses); - - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> Time needed to send policy files and deploy them : " + result + "\n\n"); - - // PROFILING - start = System.currentTimeMillis(); - + // See if firewall policy is configured to be "on" or "off" + if (STR_POLICY_ON.equals(STR_YES)) + createPolicyThreads(STR_ROUTER_ADD, setAddresses); // Separating object creations and Set/Relation initializations createDriverObjects(); - - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> Time needed to instantiate objects: " + result + "\n\n"); - // PROFILING - start = System.currentTimeMillis(); - // Sets and relations initializations if(STR_LANGUAGE_CONTROLLER.equals(STR_JAVA)) initializeSetsAndRelationsJava(inStream, outStream); else initializeSetsAndRelationsCpp(inStream, outStream);; - - // PROFILING - result = System.currentTimeMillis()-start; - System.out.println("\n\n ==> Time needed to initialize sets and relations: " + result + "\n\n"); - if(STR_LANGUAGE_CONTROLLER.equals(STR_JAVA)) // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO EXECUTE INIT METHOD commMasterToSlave(new MessageSimple(IoTCommCode.INVOKE_INIT_METHOD), "Invoke init() method!", inStream, outStream);