@Test public void testSingleForwardTwoOptions() { for (int i = 0; i < 2; i++) { when(packet.getHash(any(Integer.class))).thenReturn(i); ArgumentCaptor<Packet> captor = ArgumentCaptor.forClass(Packet.class); when(packet.getDestinationId()).thenReturn(4); device1.receive(packet); verify(topology.getPort(1, 2), atMost((i + 1) % 2)).enqueue(captor.capture()); verify(topology.getPort(1, 3), atMost(i % 2)).enqueue(captor.capture()); reset(topology.getPort(1, 2), topology.getPort(1, 3)); assertEquals(1, captor.getAllValues().size()); } }
@Override public void receive(Packet genericPacket) { TcpHeader tcpHeader = (TcpHeader) genericPacket; if (tcpHeader.getDestinationId() == this.identifier) { this.passToIntermediary(genericPacket); } else { List<Integer> possibilities = destinationToNextSwitch.get(tcpHeader.getDestinationId()); this.targetIdToOutputPort.get(possibilities.get(tcpHeader.getHash(this.identifier) % possibilities.size())).enqueue(genericPacket); } }
EcmpSwitch extends NetworkDevice implements EcmpSwitchRoutingInterface { @Override public void receive(Packet genericPacket) { TcpHeader tcpHeader = (TcpHeader) genericPacket; if (tcpHeader.getDestinationId() == this.identifier) { this.passToIntermediary(genericPacket); } else { List<Integer> possibilities = destinationToNextSwitch.get(tcpHeader.getDestinationId()); this.targetIdToOutputPort.get(possibilities.get(tcpHeader.getHash(this.identifier) % possibilities.size())).enqueue(genericPacket); } } }
EcmpSwitch extends NetworkDevice implements EcmpSwitchRoutingInterface { @Override public void receive(Packet genericPacket) { TcpHeader tcpHeader = (TcpHeader) genericPacket; if (tcpHeader.getDestinationId() == this.identifier) { this.passToIntermediary(genericPacket); } else { List<Integer> possibilities = destinationToNextSwitch.get(tcpHeader.getDestinationId()); this.targetIdToOutputPort.get(possibilities.get(tcpHeader.getHash(this.identifier) % possibilities.size())).enqueue(genericPacket); } } EcmpSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary); }
EcmpSwitch extends NetworkDevice implements EcmpSwitchRoutingInterface { @Override public void receive(Packet genericPacket) { TcpHeader tcpHeader = (TcpHeader) genericPacket; if (tcpHeader.getDestinationId() == this.identifier) { this.passToIntermediary(genericPacket); } else { List<Integer> possibilities = destinationToNextSwitch.get(tcpHeader.getDestinationId()); this.targetIdToOutputPort.get(possibilities.get(tcpHeader.getHash(this.identifier) % possibilities.size())).enqueue(genericPacket); } } EcmpSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary); @Override void receive(Packet genericPacket); @Override void receiveFromIntermediary(Packet genericPacket); @Override void addDestinationToNextSwitch(int destinationId, int nextHopId); @Override String toString(); }
EcmpSwitch extends NetworkDevice implements EcmpSwitchRoutingInterface { @Override public void receive(Packet genericPacket) { TcpHeader tcpHeader = (TcpHeader) genericPacket; if (tcpHeader.getDestinationId() == this.identifier) { this.passToIntermediary(genericPacket); } else { List<Integer> possibilities = destinationToNextSwitch.get(tcpHeader.getDestinationId()); this.targetIdToOutputPort.get(possibilities.get(tcpHeader.getHash(this.identifier) % possibilities.size())).enqueue(genericPacket); } } EcmpSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary); @Override void receive(Packet genericPacket); @Override void receiveFromIntermediary(Packet genericPacket); @Override void addDestinationToNextSwitch(int destinationId, int nextHopId); @Override String toString();  }