Ejemplo n.º 1
0
 @Override
 public void init(DEECoContainer container) {
   random = new Random(container.getId());
   LoopDevice loop = new LoopDevice(container);
   Layer1 l1 = container.getPluginInstance(Network.class).getL1();
   l1.registerDevice(loop);
   loops.add(loop);
 }
Ejemplo n.º 2
0
    public LoopDevice(DEECoContainer container) {
      this.container = container;
      address = new MANETBroadcastAddress(getId());
      positionProvider = container.getPluginInstance(PositionPlugin.class);
      scheduler = container.getRuntimeFramework().getScheduler();

      if (positionProvider != null) {
        Log.i(
            container.getId()
                + ": "
                + LoopDevice.class.getSimpleName()
                + " using node position information provided by "
                + positionProvider.getClass().getSimpleName());
      } else {
        Log.i(
            container.getId()
                + ": "
                + LoopDevice.class.getSimpleName()
                + " not using node position information");
      }
    }
  /**
   * Configures source node
   *
   * <p>Has working layer1, used to send packets
   */
  private DEECoContainer setupSourceNode(int id) {
    DEECoContainer node = Mockito.mock(DEECoContainer.class);

    // Configure id for mocked container
    Mockito.when(node.getId()).thenReturn(id);

    // Configure runtime
    Mockito.when(node.getRuntimeFramework()).thenReturn(runtime);

    // Configure Network for mocked container
    Layer1 layer1 = new Layer1((byte) id, DefaultDataIDSource.getInstance(), scheduler);
    Network network = Mockito.mock(Network.class);
    Mockito.when(network.getL1()).thenReturn(layer1);
    Mockito.when(node.getPluginInstance(Network.class)).thenReturn(network);

    return node;
  }
  /** Tests sending packet from one node to another one */
  @Test
  public void testNodeToNodeRouting() {
    SimpleInfrastructureDevice loop = new SimpleInfrastructureDevice();

    // Register nodes 0 and 1 with Infrastructure loop-back
    loop.init(node0);
    loop.init(node1);

    // Send packet from node 0 to node 1
    Layer1 node0layer1 = node0.getPluginInstance(Network.class).getL1();
    node0layer1.sendL1Packet(TEST_PACKET, new IPAddress(String.valueOf(node1.getId())));

    // Test packet was received on node 1
    Layer1 node1layer1 = node1.getPluginInstance(Network.class).getL1();
    Mockito.verify(node1layer1, Mockito.atLeastOnce())
        .processL0Packet(Mockito.any(), Mockito.any(), Mockito.any());
  }
  /**
   * Configures destination node
   *
   * <p>Has mocked layer1, used to confirm packet reception
   */
  private DEECoContainer setupDestinationNode(int id) {
    DEECoContainer node = Mockito.mock(DEECoContainer.class);

    // Configure id for mocked container
    Mockito.when(node.getId()).thenReturn(id);

    // Configure runtime
    Mockito.when(node.getRuntimeFramework()).thenReturn(runtime);

    // Configure Network for mocked container
    Layer1 layer1 =
        Mockito.spy(new Layer1((byte) id, DefaultDataIDSource.getInstance(), scheduler));
    Mockito.doNothing().when(layer1).processL0Packet(Mockito.any(), Mockito.any(), Mockito.any());
    Network network = Mockito.mock(Network.class);
    Mockito.when(network.getL1()).thenReturn(layer1);
    Mockito.when(node.getPluginInstance(Network.class)).thenReturn(network);

    return node;
  }
Ejemplo n.º 6
0
 @Override
 public String getId() {
   return String.valueOf(container.getId());
 }