@Test public void testConstructionDuplicate() { device0 = new EcmpSwitch(0, null, 5, new IdentityFlowletIntermediary()); device0.addConnection(topology.getPort(0, 1)); device0.addDestinationToNextSwitch(1, 1); boolean thrown = false; try { device0.addDestinationToNextSwitch(1, 1); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); }
@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); }
EcmpSwitch extends NetworkDevice 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); } }
EcmpSwitch extends NetworkDevice 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); } EcmpSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary); }
EcmpSwitch extends NetworkDevice 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); } 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 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); } 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();  }