Example #1
0
  @SuppressWarnings("empty-statement")
  public GenericTest() {
    try {
      // setup environment
      simLogger = SimLogger.getInstance(SimLogger.INFO);
      Topology topology = new Topology();
      SimulationEngine simEngine = new SimulationEngine(topology);
      simEngine.setInstance(simEngine);

      // specify Topology matrices for test nodes to send and receive
      // WAN: three subnets interconnected by network #1 router
      topology.setNumberOfSubnets(3);
      topology.setDiameter(2);
      int links[][] = {{0}, {0, 0, 1544, 384}, {0, 1544, 0, 0}, {0, 384, 0, 0}};
      topology.setLinksMatrix(links);
      byte exitInterfaces[][] = {{0}, {0, 0, 1, 2}, {0, 3, 0, 0}, {0, 4, 0, 0}};
      topology.setExitInterfacesMatrix(1, exitInterfaces);
      int[][] routingMatrix = {{0}, {0, 1, 2, 3}, {0, 1, 2, 1}, {0, 1, 1, 3}};
      topology.setStaticRoutingMatrix(routingMatrix);

      // setup LAN:
      // subnet 1 has two hosts; subnets 2 and 3 have one host
      // all subnets are 100 MB/s contention LANs
      int[] lanTypes = {0, 1, 1, 1};
      topology.setLanTypes(lanTypes);
      int[] subnetHostCount = {0, 2, 1, 1};
      topology.setSubnetHostCount(subnetHostCount);
      int[] subnetDataRate = {0, 100, 100, 100};
      topology.setSubnetDataRate(subnetDataRate);
      byte[][] lanInterfaces = {{0}, {0, 51, 52, 53}, {0, 54, 55}, {0, 56, 57}};
      topology.setLanInterfacesMatrix(lanInterfaces);
      topology.findTotalNumberOfHosts();

      // setup print layers
      topology.setPrintAtLayer(2);
      topology.setPrintAtLayer(3);
      topology.setPrintAtLayer(5);

      // print out the new topology and load it into simulator
      topology.printTopology();

      // load the configuration into simulator
      if (!simEngine.loadConfiguration()) {
        simLogger.logWarn("Configuration Error");
        return;
      }
      ConnectivityMatrix cm = simEngine.getConnectivityMatrix();
      simLogger.setPrintAtLayers(topology.getPrintAtLayers());

      // set hostnames for printout
      Router router1 = (Router) cm.getHost(1, 1);
      router1.setName("router-1.1");
      Host host1_2 = (Host) cm.getHost(1, 2);
      host1_2.setName("host-1.2");
      Host host1_3 = (Host) cm.getHost(1, 3);
      host1_3.setName("host-1.3");
      Router router2 = (Router) cm.getHost(2, 1);
      router2.setName("router-2.1");
      Host host2_2 = (Host) cm.getHost(2, 2);
      host2_2.setName("host-2.2");
      Router router3 = (Router) cm.getHost(3, 1);
      router3.setName("router-3.1");
      Host host3_2 = (Host) cm.getHost(3, 2);
      host3_2.setName("host-3.2");

      // send 10 messages over unreliable transport from host 1.2 to host 1.3, via LAN
      for (int i = 1; i <= 10; i++) {
        host1_2.sendMessage(i + " 1.2 Watson are you there?", 1, 3, Message.UNRELIABLE);
      }

      // send 10 messages over unreliable transport from host 1.3 to host 1.2, via LAN
      for (int i = 1; i <= 10; i++) {
        host1_3.sendMessage(i + " 1.3 Yep I'm here.", 1, 2, Message.UNRELIABLE);
      }

      // send 10 messages over unreliable transport from host 1.2 to host 2.2, via WAN (1 hop)
      for (int i = 1; i <= 10; i++) {
        host1_2.sendMessage(i + " 1.2 Watson are you there?", 2, 2, Message.UNRELIABLE);
      }

      // send 10 messages over unreliable transport from host 2.2 to host 1.2, via WAN (1 hop)
      for (int i = 1; i <= 10; i++) {
        host2_2.sendMessage(i + " 2.2 Yep I'm here.", 1, 2, Message.UNRELIABLE);
      }

      // send 10 messages over unreliable transport from host 2.2 to host 3.2, via WAN (2 hops)
      for (int i = 1; i <= 10; i++) {
        host2_2.sendMessage(i + " 2.2 Watson are you there?", 3, 2, Message.UNRELIABLE);
      }

      // send 10 messages over unreliable transport from host 3.2 to host 2.2, via WAN (2 hops)
      for (int i = 1; i <= 10; i++) {
        host3_2.sendMessage(i + " 3.2 Yep I'm here.", 2, 2, Message.UNRELIABLE);
      }

      // send 10 messages over unreliable transport from host 1.1 to host 2.1, via WAN (1 hop)
      for (int i = 1; i <= 10; i++) {
        router1.sendMessage(i + " 1.1 Watson are you there?", 2, 1, Message.UNRELIABLE);
      }

      // execute the simulation
      DiscreteEventSimulator des = simEngine.getDes();
      while (des.nextEvent()) ;

      // print out connectivity matrix
      System.out.println("\nConfiguration:\n" + cm.toString());

      // print out host statistics
      System.out.println("\nStatistics for Simulation:");
      System.out.println("Router node 1.1 LAN:");
      System.out.println(router1.getLanInterface().getStatistics().toString());
      System.out.println("Router node 1.1 link to 2.1:");
      System.out.println(router1.getLinkInterfaceById(1).getStatistics().toString());
      System.out.println("Router node 1.1 link to 3.1:");
      System.out.println(router1.getLinkInterfaceById(2).getStatistics().toString());
      System.out.println("Host node 1.2:");
      System.out.println(host1_2.getLanInterface().getStatistics().toString());
      System.out.println("Host node 1.3:");
      System.out.println(host1_3.getLanInterface().getStatistics().toString());
      System.out.println("Router node 2.1 LAN:");
      System.out.println(router2.getLanInterface().getStatistics().toString());
      System.out.println("Router node 2.1 link to 1.1:");
      System.out.println(router2.getLinkInterfaceById(3).getStatistics().toString());
      System.out.println("Host node 2.2:");
      System.out.println(host2_2.getLanInterface().getStatistics().toString());
      System.out.println("Router node 3.1 LAN:");
      System.out.println(router3.getLinkInterfaceById(4).getStatistics().toString());
      System.out.println("Router node 3.1 link to 1.1):");
      System.out.println(router3.getLanInterface().getStatistics().toString());
      System.out.println("Host node 3.2:");
      System.out.println(host3_2.getLanInterface().getStatistics().toString());

      simLogger.logStats("Configuration:\n" + cm.toString());
      simLogger.logInfo("Simulation Finished");
      simLogger.close();
    } catch (Exception e) {
      System.err.println("Exception in GenericTest:" + e.getMessage());
      simLogger.logException(e);
    }
  } // end GenericTest constructor