@Test public void testAddPathToDestination() { SourceRoutingSwitch device = new SourceRoutingSwitch(1, null, 5, new IdentityFlowletIntermediary()); device.addConnection(topology.getPort(1, 0)); device.addConnection(topology.getPort(1, 2)); device.addConnection(topology.getPort(1, 3)); device.addPathToDestination(4, makePath(new Integer[]{1, 2, 4})); boolean thrown = false; try { device.addPathToDestination(4, makePath(new Integer[]{1, 2, 4})); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); thrown = false; try { device.addPathToDestination(4, makePath(new Integer[]{})); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); thrown = false; try { device.addPathToDestination(4, makePath(new Integer[]{1, 4, 4})); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); thrown = false; try { device.addPathToDestination(4, makePath(new Integer[]{4, 2, 4})); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); thrown = false; try { device.addPathToDestination(4, makePath(new Integer[]{1, 2, 1})); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); thrown = false; try { device.addPathToDestination(1, makePath(new Integer[]{1, 2, 1})); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); thrown = false; try { device.addPathToDestination(1, makePath(new Integer[]{1, 2, 1})); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); }
void addPathToDestination(int destinationId, SourceRoutingPath path) { if (path.size() < 2) { throw new IllegalArgumentException("Cannot add a path of zero or one length (must have source and destination included)."); } if (!connectedTo.contains(path.get(1))) { throw new IllegalArgumentException("Cannot add path with source hop to a network device to which it is not connected (" + path.get(1) + ")"); } if (path.get(0) != this.getIdentifier()) { throw new IllegalArgumentException("First node on path should be this identifier (expected " + this.getIdentifier() + ", received " + path.get(0) + ")"); } if (path.get(path.size() - 1) != destinationId) { throw new IllegalArgumentException("Last node on path should be destination (expected " + destinationId + ", received " + path.get(path.size() - 1) + ")"); } if (this.getIdentifier() == destinationId) { throw new IllegalArgumentException("Cannot add a path going to itself (" + this.getIdentifier() + ")"); } List<SourceRoutingPath> current = this.destinationToPaths.get(destinationId); if (current.contains(path)) { if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_skip_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") skipped duplicate path : " + path); return; } else if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_add_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") added duplicate path : " + path); } else { throw new IllegalArgumentException("Cannot add a duplicate path (" + path + ")"); } } current.add(path); }
SourceRoutingSwitch extends NetworkDevice { void addPathToDestination(int destinationId, SourceRoutingPath path) { if (path.size() < 2) { throw new IllegalArgumentException("Cannot add a path of zero or one length (must have source and destination included)."); } if (!connectedTo.contains(path.get(1))) { throw new IllegalArgumentException("Cannot add path with source hop to a network device to which it is not connected (" + path.get(1) + ")"); } if (path.get(0) != this.getIdentifier()) { throw new IllegalArgumentException("First node on path should be this identifier (expected " + this.getIdentifier() + ", received " + path.get(0) + ")"); } if (path.get(path.size() - 1) != destinationId) { throw new IllegalArgumentException("Last node on path should be destination (expected " + destinationId + ", received " + path.get(path.size() - 1) + ")"); } if (this.getIdentifier() == destinationId) { throw new IllegalArgumentException("Cannot add a path going to itself (" + this.getIdentifier() + ")"); } List<SourceRoutingPath> current = this.destinationToPaths.get(destinationId); if (current.contains(path)) { if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_skip_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") skipped duplicate path : " + path); return; } else if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_add_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") added duplicate path : " + path); } else { throw new IllegalArgumentException("Cannot add a duplicate path (" + path + ")"); } } current.add(path); } }
SourceRoutingSwitch extends NetworkDevice { void addPathToDestination(int destinationId, SourceRoutingPath path) { if (path.size() < 2) { throw new IllegalArgumentException("Cannot add a path of zero or one length (must have source and destination included)."); } if (!connectedTo.contains(path.get(1))) { throw new IllegalArgumentException("Cannot add path with source hop to a network device to which it is not connected (" + path.get(1) + ")"); } if (path.get(0) != this.getIdentifier()) { throw new IllegalArgumentException("First node on path should be this identifier (expected " + this.getIdentifier() + ", received " + path.get(0) + ")"); } if (path.get(path.size() - 1) != destinationId) { throw new IllegalArgumentException("Last node on path should be destination (expected " + destinationId + ", received " + path.get(path.size() - 1) + ")"); } if (this.getIdentifier() == destinationId) { throw new IllegalArgumentException("Cannot add a path going to itself (" + this.getIdentifier() + ")"); } List<SourceRoutingPath> current = this.destinationToPaths.get(destinationId); if (current.contains(path)) { if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_skip_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") skipped duplicate path : " + path); return; } else if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_add_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") added duplicate path : " + path); } else { throw new IllegalArgumentException("Cannot add a duplicate path (" + path + ")"); } } current.add(path); } SourceRoutingSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary); }
SourceRoutingSwitch extends NetworkDevice { void addPathToDestination(int destinationId, SourceRoutingPath path) { if (path.size() < 2) { throw new IllegalArgumentException("Cannot add a path of zero or one length (must have source and destination included)."); } if (!connectedTo.contains(path.get(1))) { throw new IllegalArgumentException("Cannot add path with source hop to a network device to which it is not connected (" + path.get(1) + ")"); } if (path.get(0) != this.getIdentifier()) { throw new IllegalArgumentException("First node on path should be this identifier (expected " + this.getIdentifier() + ", received " + path.get(0) + ")"); } if (path.get(path.size() - 1) != destinationId) { throw new IllegalArgumentException("Last node on path should be destination (expected " + destinationId + ", received " + path.get(path.size() - 1) + ")"); } if (this.getIdentifier() == destinationId) { throw new IllegalArgumentException("Cannot add a path going to itself (" + this.getIdentifier() + ")"); } List<SourceRoutingPath> current = this.destinationToPaths.get(destinationId); if (current.contains(path)) { if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_skip_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") skipped duplicate path : " + path); return; } else if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_add_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") added duplicate path : " + path); } else { throw new IllegalArgumentException("Cannot add a duplicate path (" + path + ")"); } } current.add(path); } SourceRoutingSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary); @Override void receive(Packet genericPacket); List<List<SourceRoutingPath>> getPathsList(); @Override void receiveFromIntermediary(Packet genericPacket); @Override String toString(); }
SourceRoutingSwitch extends NetworkDevice { void addPathToDestination(int destinationId, SourceRoutingPath path) { if (path.size() < 2) { throw new IllegalArgumentException("Cannot add a path of zero or one length (must have source and destination included)."); } if (!connectedTo.contains(path.get(1))) { throw new IllegalArgumentException("Cannot add path with source hop to a network device to which it is not connected (" + path.get(1) + ")"); } if (path.get(0) != this.getIdentifier()) { throw new IllegalArgumentException("First node on path should be this identifier (expected " + this.getIdentifier() + ", received " + path.get(0) + ")"); } if (path.get(path.size() - 1) != destinationId) { throw new IllegalArgumentException("Last node on path should be destination (expected " + destinationId + ", received " + path.get(path.size() - 1) + ")"); } if (this.getIdentifier() == destinationId) { throw new IllegalArgumentException("Cannot add a path going to itself (" + this.getIdentifier() + ")"); } List<SourceRoutingPath> current = this.destinationToPaths.get(destinationId); if (current.contains(path)) { if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_skip_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") skipped duplicate path : " + path); return; } else if (Simulator.getConfiguration().getBooleanPropertyWithDefault("allow_source_routing_add_duplicate_paths", false)) { System.out.println("For (" + this.getIdentifier() + "->" + destinationId + ") added duplicate path : " + path); } else { throw new IllegalArgumentException("Cannot add a duplicate path (" + path + ")"); } } current.add(path); } SourceRoutingSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary); @Override void receive(Packet genericPacket); List<List<SourceRoutingPath>> getPathsList(); @Override void receiveFromIntermediary(Packet genericPacket); @Override String toString();  }