@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);
 }
  /**
   * 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;
  }
    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");
      }
    }
  /** Tests sending packet from node to nonexistent node */
  @Test(expected = UnsupportedOperationException.class)
  public void testNodeToVoidRouting() {
    SimpleInfrastructureDevice loop = new SimpleInfrastructureDevice();

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

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

    // Exception should be thrown as destination node is not present
  }
Example #7
0
  /* (non-Javadoc)
   * @see cz.cuni.mff.d3s.deeco.runtime.DEECoPlugin#init(cz.cuni.mff.d3s.deeco.runtime.DEECoContainer)
   */
  @Override
  public void init(DEECoContainer container) throws PluginInitFailedException {
    try {
      adaptationManager = new AdaptationManager();
      container.deployComponent(adaptationManager);

      for (ComponentInstance c : container.getRuntimeMetadata().getComponentInstances()) {
        if (c.getName().equals(AdaptationManager.class.getName())) {
          // Adjust non-deterministic mode switching manager periods
          for (ComponentProcess p : c.getComponentProcesses()) {
            if (p.getName().equals("reason")) {
              for (Trigger t : p.getTriggers()) {
                if (t instanceof TimeTrigger) {
                  ((TimeTrigger) t).setPeriod(period);
                }
              }
            }
          }
        }
      }
    } catch (AnnotationProcessorException e) {
      Log.e("Error while trying to deploy AdaptationManager", e);
    }
  }
 @Override
 public String getId() {
   return String.valueOf(container.getId());
 }
Example #9
0
 @Override
 public void init(DEECoContainer container) {
   super.init(container);
   host.setBroadcastDevice(this);
   positionPlugin = container.getPluginInstance(PositionPlugin.class);
 }