@Test public void testSingleForward() { EcmpThenSourceRoutingSwitch device = new EcmpThenSourceRoutingSwitch(1, null, 5, new IdentityFlowletIntermediary(), 5000); device.addConnection(topology.getPort(1, 0)); device.addConnection(topology.getPort(1, 4)); SourceRoutingPath path = new SourceRoutingPath(); path.add(1); path.add(4); path.add(2); path.add(0); path.add(3); device.addPathToDestination(3, path); device.addDestinationToNextSwitch(3, 0); when(packet.getDestinationId()).thenReturn(3); when(packet.getDataSizeByte()).thenReturn(1000L); for (int i = 0; i < 5; i++) { ArgumentCaptor<Packet> captorA = ArgumentCaptor.forClass(Packet.class); device.receiveFromTransportLayer(packet); verify(topology.getPort(1, 0), times(1 + i)).enqueue(captorA.capture()); verify(topology.getPort(1, 4), times(0)).enqueue(captorA.capture()); assert(captorA.getValue() instanceof TcpPacket); assert(!(captorA.getValue() instanceof SourceRoutingEncapsulation)); } ArgumentCaptor<Packet> captorB = ArgumentCaptor.forClass(Packet.class); device.receiveFromTransportLayer(packet); verify(topology.getPort(1, 0), times(5)).enqueue(captorB.capture()); verify(topology.getPort(1, 4), times(1)).enqueue(captorB.capture()); assert(!(captorB.getValue() instanceof TcpPacket)); assert(captorB.getValue() instanceof SourceRoutingEncapsulation); }
@Override public void addDestinationToNextSwitch(int destinationId, int nextHopId) { if (!connectedTo.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add hop to a network device to which it is not connected (" + nextHopId + ")"); } List<Integer> current = this.destinationToNextSwitch.get(destinationId); if (current.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add a duplicate next hop network device identifier (" + nextHopId + ")"); } current.add(nextHopId); }
EcmpThenSourceRoutingSwitch extends SourceRoutingSwitch implements EcmpSwitchRoutingInterface { @Override public void addDestinationToNextSwitch(int destinationId, int nextHopId) { if (!connectedTo.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add hop to a network device to which it is not connected (" + nextHopId + ")"); } List<Integer> current = this.destinationToNextSwitch.get(destinationId); if (current.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add a duplicate next hop network device identifier (" + nextHopId + ")"); } current.add(nextHopId); } }
EcmpThenSourceRoutingSwitch extends SourceRoutingSwitch implements EcmpSwitchRoutingInterface { @Override public void addDestinationToNextSwitch(int destinationId, int nextHopId) { if (!connectedTo.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add hop to a network device to which it is not connected (" + nextHopId + ")"); } List<Integer> current = this.destinationToNextSwitch.get(destinationId); if (current.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add a duplicate next hop network device identifier (" + nextHopId + ")"); } current.add(nextHopId); } EcmpThenSourceRoutingSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary, long switchThresholdBytes); }
EcmpThenSourceRoutingSwitch extends SourceRoutingSwitch implements EcmpSwitchRoutingInterface { @Override public void addDestinationToNextSwitch(int destinationId, int nextHopId) { if (!connectedTo.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add hop to a network device to which it is not connected (" + nextHopId + ")"); } List<Integer> current = this.destinationToNextSwitch.get(destinationId); if (current.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add a duplicate next hop network device identifier (" + nextHopId + ")"); } current.add(nextHopId); } EcmpThenSourceRoutingSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary, long switchThresholdBytes); @Override void receive(Packet genericPacket); @Override void receiveFromIntermediary(Packet genericPacket); @Override void addDestinationToNextSwitch(int destinationId, int nextHopId); }
EcmpThenSourceRoutingSwitch extends SourceRoutingSwitch implements EcmpSwitchRoutingInterface { @Override public void addDestinationToNextSwitch(int destinationId, int nextHopId) { if (!connectedTo.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add hop to a network device to which it is not connected (" + nextHopId + ")"); } List<Integer> current = this.destinationToNextSwitch.get(destinationId); if (current.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add a duplicate next hop network device identifier (" + nextHopId + ")"); } current.add(nextHopId); } EcmpThenSourceRoutingSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary, long switchThresholdBytes); @Override void receive(Packet genericPacket); @Override void receiveFromIntermediary(Packet genericPacket); @Override void addDestinationToNextSwitch(int destinationId, int nextHopId);  }