public NetworkInterface unmarshall(JsonUnmarshallerContext context) throws Exception {
    NetworkInterface networkInterface = new NetworkInterface();

    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.currentToken;
    if (token == null) token = context.nextToken();

    while (true) {
      if (token == null) break;

      if (token == FIELD_NAME || token == START_OBJECT) {
        if (context.testExpression("Ipv4Address", targetDepth)) {
          context.nextToken();
          networkInterface.setIpv4Address(StringJsonUnmarshaller.getInstance().unmarshall(context));
        }
        if (context.testExpression("MacAddress", targetDepth)) {
          context.nextToken();
          networkInterface.setMacAddress(StringJsonUnmarshaller.getInstance().unmarshall(context));
        }
        if (context.testExpression("Ipv6Address", targetDepth)) {
          context.nextToken();
          networkInterface.setIpv6Address(StringJsonUnmarshaller.getInstance().unmarshall(context));
        }
      } else if (token == END_ARRAY || token == END_OBJECT) {
        if (context.getCurrentDepth() <= originalDepth) break;
      }

      token = context.nextToken();
    }

    return networkInterface;
  }
  @Test
  public void canCreateBatchOfNetworkInterfaces() throws Exception {
    ResourceGroups resourceGroups = resourceManager.resourceGroups();
    Networks networks = networkManager.networks();
    NetworkInterfaces networkInterfaces = networkManager.networkInterfaces();

    Creatable<ResourceGroup> resourceGroupCreatable =
        resourceGroups.define(RG_NAME).withRegion(Region.US_EAST);

    final String vnetName = "vnet1212";
    Creatable<Network> networkCreatable =
        networks
            .define(vnetName)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup(resourceGroupCreatable)
            .withAddressSpace("10.0.0.0/28");

    // Prepare a batch of nics
    //
    final String nic1Name = "nic1";
    Creatable<NetworkInterface> networkInterface1Creatable =
        networkInterfaces
            .define(nic1Name)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup(resourceGroupCreatable)
            .withNewPrimaryNetwork(networkCreatable)
            .withPrimaryPrivateIpAddressStatic("10.0.0.5");

    final String nic2Name = "nic2";
    Creatable<NetworkInterface> networkInterface2Creatable =
        networkInterfaces
            .define(nic2Name)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup(resourceGroupCreatable)
            .withNewPrimaryNetwork(networkCreatable)
            .withPrimaryPrivateIpAddressStatic("10.0.0.6");

    final String nic3Name = "nic3";
    Creatable<NetworkInterface> networkInterface3Creatable =
        networkInterfaces
            .define(nic3Name)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup(resourceGroupCreatable)
            .withNewPrimaryNetwork(networkCreatable)
            .withPrimaryPrivateIpAddressStatic("10.0.0.7");

    final String nic4Name = "nic4";
    Creatable<NetworkInterface> networkInterface4Creatable =
        networkInterfaces
            .define(nic4Name)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup(resourceGroupCreatable)
            .withNewPrimaryNetwork(networkCreatable)
            .withPrimaryPrivateIpAddressStatic("10.0.0.8");

    CreatedResources<NetworkInterface> batchNics =
        networkInterfaces.create(
            networkInterface1Creatable,
            networkInterface2Creatable,
            networkInterface3Creatable,
            networkInterface4Creatable);

    Assert.assertTrue(batchNics.size() == 4);
    HashMap<String, Boolean> found = new LinkedHashMap<>();
    for (NetworkInterface nic : batchNics) {
      if (nic.name().equalsIgnoreCase(nic1Name)) {
        found.put(nic1Name, true);
      }
      if (nic.name().equalsIgnoreCase(nic2Name)) {
        found.put(nic2Name, true);
      }
      if (nic.name().equalsIgnoreCase(nic3Name)) {
        found.put(nic3Name, true);
      }
      if (nic.name().equalsIgnoreCase(nic4Name)) {
        found.put(nic4Name, true);
      }
    }
    Assert.assertTrue(found.size() == 4);
  }
  /** Creates hosts for the scenario */
  protected void createHosts() {
    this.hosts = new ArrayList<DTNHost>();
    int lastGroupWithFiles = -1;
    this.nrofGroupsWithFiles = 0;
    this.groupSizes = new int[nrofGroups];

    for (int i = 1; i <= nrofGroups; i++) {
      List<NetworkInterface> mmNetInterfaces = new ArrayList<NetworkInterface>();
      Settings s = new Settings(GROUP_NS + i);
      s.setSecondaryNamespace(GROUP_NS);
      String gid = s.getSetting(GROUP_ID_S);
      int nrofHosts = s.getInt(NROF_HOSTS_S);
      int nrofInterfaces = s.getInt(NROF_INTERF_S);
      int appCount;
      boolean hasFileCapability;
      if (s.contains(FILE_CAPABILITY_S)) {
        hasFileCapability = s.getBoolean(FILE_CAPABILITY_S);
      } else {
        hasFileCapability = false;
      }

      if (hasFileCapability && i != lastGroupWithFiles) {
        lastGroupWithFiles = i;
        this.nrofGroupsWithFiles++;
      }

      // creates prototypes of MessageRouter and MovementModel
      MovementModel mmProto =
          (MovementModel) s.createIntializedObject(MM_PACKAGE + s.getSetting(MOVEMENT_MODEL_S));
      MessageRouter mRouterProto =
          (MessageRouter) s.createIntializedObject(ROUTING_PACKAGE + s.getSetting(ROUTER_S));

      // checks that these values are positive (throws Error if not)
      ensurePositiveValue(nrofHosts, NROF_HOSTS_S);
      ensurePositiveValue(nrofInterfaces, NROF_INTERF_S);
      this.groupSizes[i - 1] = nrofHosts;

      // setup interfaces
      for (int j = 1; j <= nrofInterfaces; j++) {
        String Intname = s.getSetting(INTERFACENAME_S + j);
        Settings t = new Settings(Intname);
        NetworkInterface mmInterface =
            (NetworkInterface) t.createIntializedObject(INTTYPE_PACKAGE + t.getSetting(INTTYPE_S));
        mmInterface.setClisteners(connectionListeners);
        mmNetInterfaces.add(mmInterface);
      }

      // setup applications
      if (s.contains(APPCOUNT_S)) {
        appCount = s.getInt(APPCOUNT_S);
      } else {
        appCount = 0;
      }
      for (int j = 1; j <= appCount; j++) {
        String appname = null;
        Application protoApp = null;
        try {
          // Get name of the application for this group
          appname = s.getSetting(GAPPNAME_S + j);
          // Get settings for the given application
          Settings t = new Settings(appname);
          // Load an instance of the application
          protoApp = (Application) t.createIntializedObject(APP_PACKAGE + t.getSetting(APPTYPE_S));
          // Set application listeners
          protoApp.setAppListeners(this.appListeners);
          // Set the proto application in proto router
          // mRouterProto.setApplication(protoApp);
          mRouterProto.addApplication(protoApp);
        } catch (SettingsError se) {
          // Failed to create an application for this group
          System.err.println("Failed to setup an application: " + se);
          System.err.println("Caught at " + se.getStackTrace()[0]);
          System.exit(-1);
        }
      }

      if (mmProto instanceof MapBasedMovement) {
        this.simMap = ((MapBasedMovement) mmProto).getMap();
      }

      // creates hosts of ith group
      for (int j = 0; j < nrofHosts; j++) {
        ModuleCommunicationBus comBus = new ModuleCommunicationBus();

        // prototypes are given to new DTNHost which replicates
        // new instances of movement model and message router
        DTNHost host =
            new DTNHost(
                this.messageListeners,
                this.movementListeners,
                this.queryListeners,
                gid,
                mmNetInterfaces,
                comBus,
                mmProto,
                mRouterProto,
                hasFileCapability);
        hosts.add(host);
      }
    }
  }
 public Builder fromNetworkInterface(NetworkInterface in) {
   return this.network(in.getNetwork())
       .networkIP(in.getNetworkIP().orNull())
       .accessConfigs(in.getAccessConfigs());
 }
Beispiel #5
0
  public GUI(String Profile, NetworkInterface NetObj) {

    MainDisplay = new Display();
    MainShell = new Shell(MainDisplay);
    Updater = new GUIUpdaterThread(NetObj, this);
    Updater.setDaemon(true);

    // restartOpt=false;
    if (Profile.equals("SERVER") == true) {
      // FIX THIS ASAP
      UserProfile = "SERVER";
      MainServer = (JTServer) NetObj;
      MainServer.test();
      System.out.println(
          "GUI invoked with " + MainServer.getLocalUserIP() + ":" + MainServer.getLocalUserPort());
      MainClient = null;
    } else if (Profile.equals("CLIENT") == true) {
      // FIX THIS ASAP
      UserProfile = "CLIENT";
      MainClient = (JTClient) NetObj;
      MainClient.test();
      MainServer = null;
      System.out.println(
          "GUI invoked with target " + MainClient.getTargetIP() + ":" + MainClient.getTargetPort());
      System.out.println(
          "and client "
              + MainClient.getLocalUserName()
              + "@"
              + MainClient.getLocalUserIP()
              + ":"
              + MainClient.getLocalUserPort());
    } else {
      confirmWin(
          MainShell,
          "Internal Error! No extension of JTNetworkInterface active!",
          jeremeTalk.JTC.OK);
      destroy();
    }

    Calibri = new Font(MainDisplay, "Calibri", 12, SWT.NORMAL);

    Red = new Color(MainDisplay, 0x80, 0, 0);
    Green = new Color(MainDisplay, 0, 0x80, 0);
    Blue = new Color(MainDisplay, 0, 0, 0x80);
    White = new Color(MainDisplay, 0xFF, 0xFF, 0xFF);
    Black = new Color(MainDisplay, 0, 0, 0);
    Gray = new Color(MainDisplay, 0xCC, 0xCC, 0xCC);

    GridLayout GlobalWinGL = new GridLayout();
    GlobalWinGL.numColumns = 3;
    GlobalWinGL.marginHeight = 10;
    GlobalWinGL.marginWidth = 10;
    GlobalWinGL.verticalSpacing = 5;
    GlobalWinGL.horizontalSpacing = 5;

    MainShell.setLayout(GlobalWinGL);

    initWidgets();

    addWidgetListeners();

    MainShell.setMenuBar(GlobalMainMenu);
    MainShell.pack();

    MainShell.setLocation(centralize(MainDisplay.getPrimaryMonitor().getBounds(), MainShell));

    MainShell.setText(
        "JeremeTalk v1.0 : Welcome " + NetObj.getLocalUserName() + " | You are " + UserProfile);

    MainShell.open();
    Updater.start();
    while (!MainShell.isDisposed()) {
      if (!MainDisplay.readAndDispatch()) MainDisplay.sleep();
    }
    if (MainServer == null) MainClient.freePort();
    else MainServer.freePort();
    Updater.kill();
    System.out.println("GUI Destroyed!");
  }
  /** Creates hosts for the scenario */
  protected void createHosts() {
    this.hosts = new ArrayList<DTNHost>();

    for (int i = 1; i <= nrofGroups; i++) {
      List<NetworkInterface> interfaces = new ArrayList<NetworkInterface>();
      Settings s = new Settings(GROUP_NS + i);
      s.setSecondaryNamespace(GROUP_NS);
      String gid = s.getSetting(GROUP_ID_S);
      int nrofHosts = s.getInt(NROF_HOSTS_S);
      int nrofInterfaces = s.getInt(NROF_INTERF_S);
      int appCount;

      // creates prototypes of MessageRouter and MovementModel
      MovementModel mmProto =
          (MovementModel) s.createIntializedObject(MM_PACKAGE + s.getSetting(MOVEMENT_MODEL_S));
      MessageRouter mRouterProto =
          (MessageRouter) s.createIntializedObject(ROUTING_PACKAGE + s.getSetting(ROUTER_S));

      /* checks that these values are positive (throws Error if not) */
      s.ensurePositiveValue(nrofHosts, NROF_HOSTS_S);
      s.ensurePositiveValue(nrofInterfaces, NROF_INTERF_S);

      // setup interfaces
      for (int j = 1; j <= nrofInterfaces; j++) {
        String intName = s.getSetting(INTERFACENAME_S + j);
        Settings intSettings = new Settings(intName);
        NetworkInterface iface =
            (NetworkInterface)
                intSettings.createIntializedObject(
                    INTTYPE_PACKAGE + intSettings.getSetting(INTTYPE_S));
        iface.setClisteners(connectionListeners);
        iface.setGroupSettings(s);
        interfaces.add(iface);
      }

      // setup applications
      if (s.contains(APPCOUNT_S)) {
        appCount = s.getInt(APPCOUNT_S);
      } else {
        appCount = 0;
      }
      for (int j = 1; j <= appCount; j++) {
        String appname = null;
        Application protoApp = null;
        try {
          // Get name of the application for this group
          appname = s.getSetting(GAPPNAME_S + j);
          // Get settings for the given application
          Settings t = new Settings(appname);
          // Load an instance of the application
          protoApp = (Application) t.createIntializedObject(APP_PACKAGE + t.getSetting(APPTYPE_S));

          // Set application listeners
          protoApp.setAppListeners(this.appListeners);
          // Set the proto application in proto router
          // mRouterProto.setApplication(protoApp);
          mRouterProto.addApplication(protoApp);
        } catch (SettingsError se) {
          // Failed to create an application for this group
          System.err.println("Failed to setup an application: " + se);
          System.err.println("Caught at " + se.getStackTrace()[0]);
          System.exit(-1);
        }
      }

      if (mmProto instanceof MapBasedMovement) {
        this.simMap = ((MapBasedMovement) mmProto).getMap();
      }

      // creates hosts of ith group
      // smcho added
      // database =
      // end added

      for (int j = 0; j < nrofHosts; j++) {
        ModuleCommunicationBus comBus = new ModuleCommunicationBus();

        // prototypes are given to new DTNHost which replicates
        // new instances of movement model and message router
        DTNHost host =
            new DTNHost(
                this.messageListeners,
                this.movementListeners,
                gid,
                interfaces,
                comBus,
                mmProto,
                mRouterProto);

        // smcho added
        // todo:: no error checking when there are no files or directories exist
        //                String initialContext = s.getSetting("host" + Integer.toString(j));
        //                List<String> contexts = Arrays.asList(initialContext);
        //                ContextMessage c =
        // ContextMessage.load(JavaConversions.asScalaBuffer(Arrays.asList(initialContext)));
        //                host.setContextMessage(c);
        // end added

        hosts.add(host);
      }
    }
  }