Committed by
Gerrit Code Review
[ONOS-641] Update unit tests to include IPv6 as well
- HostMonitorTest
Add more IPv6 related test cases
- HostLocationProviderTest
Add more test cases, including:
NS/NA
RS/RA
DAD
IPv6 unicast
IPv6 multicast
IPv4
- HostLocationProvider
Minor indent fix
Change-Id: Id4c3af430862c61872ccaa98beac3a47313206ac
Showing
3 changed files
with
896 additions
and
50 deletions
| ... | @@ -23,10 +23,12 @@ import org.junit.Before; | ... | @@ -23,10 +23,12 @@ import org.junit.Before; |
| 23 | import org.junit.Test; | 23 | import org.junit.Test; |
| 24 | import org.onlab.packet.ARP; | 24 | import org.onlab.packet.ARP; |
| 25 | import org.onlab.packet.Ethernet; | 25 | import org.onlab.packet.Ethernet; |
| 26 | +import org.onlab.packet.IPv6; | ||
| 26 | import org.onlab.packet.IpAddress; | 27 | import org.onlab.packet.IpAddress; |
| 27 | import org.onlab.packet.IpPrefix; | 28 | import org.onlab.packet.IpPrefix; |
| 28 | import org.onlab.packet.MacAddress; | 29 | import org.onlab.packet.MacAddress; |
| 29 | import org.onlab.packet.VlanId; | 30 | import org.onlab.packet.VlanId; |
| 31 | +import org.onlab.packet.ndp.NeighborSolicitation; | ||
| 30 | import org.onosproject.incubator.net.intf.Interface; | 32 | import org.onosproject.incubator.net.intf.Interface; |
| 31 | import org.onosproject.incubator.net.intf.InterfaceService; | 33 | import org.onosproject.incubator.net.intf.InterfaceService; |
| 32 | import org.onosproject.net.ConnectPoint; | 34 | import org.onosproject.net.ConnectPoint; |
| ... | @@ -64,14 +66,22 @@ import static org.junit.Assert.assertTrue; | ... | @@ -64,14 +66,22 @@ import static org.junit.Assert.assertTrue; |
| 64 | 66 | ||
| 65 | public class HostMonitorTest { | 67 | public class HostMonitorTest { |
| 66 | 68 | ||
| 67 | - private static final IpAddress TARGET_IP_ADDR = | 69 | + private static final IpAddress TARGET_IPV4_ADDR = |
| 68 | IpAddress.valueOf("10.0.0.1"); | 70 | IpAddress.valueOf("10.0.0.1"); |
| 69 | - private static final IpAddress SOURCE_ADDR = | 71 | + private static final IpAddress SOURCE_IPV4_ADDR = |
| 70 | IpAddress.valueOf("10.0.0.99"); | 72 | IpAddress.valueOf("10.0.0.99"); |
| 71 | private static final InterfaceIpAddress IA1 = | 73 | private static final InterfaceIpAddress IA1 = |
| 72 | - new InterfaceIpAddress(SOURCE_ADDR, IpPrefix.valueOf("10.0.0.0/24")); | 74 | + new InterfaceIpAddress(SOURCE_IPV4_ADDR, IpPrefix.valueOf("10.0.0.0/24")); |
| 73 | private MacAddress sourceMac = MacAddress.valueOf(1L); | 75 | private MacAddress sourceMac = MacAddress.valueOf(1L); |
| 74 | 76 | ||
| 77 | + private static final IpAddress TARGET_IPV6_ADDR = | ||
| 78 | + IpAddress.valueOf("1000::1"); | ||
| 79 | + private static final IpAddress SOURCE_IPV6_ADDR = | ||
| 80 | + IpAddress.valueOf("1000::f"); | ||
| 81 | + private static final InterfaceIpAddress IA2 = | ||
| 82 | + new InterfaceIpAddress(SOURCE_IPV6_ADDR, IpPrefix.valueOf("1000::/64")); | ||
| 83 | + private MacAddress sourceMac2 = MacAddress.valueOf(2L); | ||
| 84 | + | ||
| 75 | private EdgePortService edgePortService; | 85 | private EdgePortService edgePortService; |
| 76 | 86 | ||
| 77 | private HostMonitor hostMonitor; | 87 | private HostMonitor hostMonitor; |
| ... | @@ -90,7 +100,36 @@ public class HostMonitorTest { | ... | @@ -90,7 +100,36 @@ public class HostMonitorTest { |
| 90 | } | 100 | } |
| 91 | 101 | ||
| 92 | @Test | 102 | @Test |
| 93 | - public void testMonitorHostExists() throws Exception { | 103 | + public void testMonitorIpv4HostExists() throws Exception { |
| 104 | + ProviderId id = new ProviderId("fake://", "id"); | ||
| 105 | + | ||
| 106 | + Host host = createMock(Host.class); | ||
| 107 | + expect(host.providerId()).andReturn(id); | ||
| 108 | + replay(host); | ||
| 109 | + | ||
| 110 | + HostManager hostManager = createMock(HostManager.class); | ||
| 111 | + expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR)) | ||
| 112 | + .andReturn(Collections.singleton(host)); | ||
| 113 | + replay(hostManager); | ||
| 114 | + | ||
| 115 | + HostProvider hostProvider = createMock(HostProvider.class); | ||
| 116 | + expect(hostProvider.id()).andReturn(id).anyTimes(); | ||
| 117 | + hostProvider.triggerProbe(host); | ||
| 118 | + expectLastCall().once(); | ||
| 119 | + replay(hostProvider); | ||
| 120 | + | ||
| 121 | + hostMonitor = new HostMonitor(null, hostManager, null, edgePortService); | ||
| 122 | + | ||
| 123 | + hostMonitor.registerHostProvider(hostProvider); | ||
| 124 | + hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR); | ||
| 125 | + | ||
| 126 | + hostMonitor.run(null); | ||
| 127 | + | ||
| 128 | + verify(hostProvider); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Test | ||
| 132 | + public void testMonitorIpv6HostExists() throws Exception { | ||
| 94 | ProviderId id = new ProviderId("fake://", "id"); | 133 | ProviderId id = new ProviderId("fake://", "id"); |
| 95 | 134 | ||
| 96 | Host host = createMock(Host.class); | 135 | Host host = createMock(Host.class); |
| ... | @@ -98,7 +137,7 @@ public class HostMonitorTest { | ... | @@ -98,7 +137,7 @@ public class HostMonitorTest { |
| 98 | replay(host); | 137 | replay(host); |
| 99 | 138 | ||
| 100 | HostManager hostManager = createMock(HostManager.class); | 139 | HostManager hostManager = createMock(HostManager.class); |
| 101 | - expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) | 140 | + expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR)) |
| 102 | .andReturn(Collections.singleton(host)); | 141 | .andReturn(Collections.singleton(host)); |
| 103 | replay(hostManager); | 142 | replay(hostManager); |
| 104 | 143 | ||
| ... | @@ -111,7 +150,7 @@ public class HostMonitorTest { | ... | @@ -111,7 +150,7 @@ public class HostMonitorTest { |
| 111 | hostMonitor = new HostMonitor(null, hostManager, null, edgePortService); | 150 | hostMonitor = new HostMonitor(null, hostManager, null, edgePortService); |
| 112 | 151 | ||
| 113 | hostMonitor.registerHostProvider(hostProvider); | 152 | hostMonitor.registerHostProvider(hostProvider); |
| 114 | - hostMonitor.addMonitoringFor(TARGET_IP_ADDR); | 153 | + hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR); |
| 115 | 154 | ||
| 116 | hostMonitor.run(null); | 155 | hostMonitor.run(null); |
| 117 | 156 | ||
| ... | @@ -119,7 +158,7 @@ public class HostMonitorTest { | ... | @@ -119,7 +158,7 @@ public class HostMonitorTest { |
| 119 | } | 158 | } |
| 120 | 159 | ||
| 121 | @Test | 160 | @Test |
| 122 | - public void testMonitorHostDoesNotExist() throws Exception { | 161 | + public void testMonitorIpv4HostDoesNotExist() throws Exception { |
| 123 | 162 | ||
| 124 | HostManager hostManager = createMock(HostManager.class); | 163 | HostManager hostManager = createMock(HostManager.class); |
| 125 | 164 | ||
| ... | @@ -140,12 +179,12 @@ public class HostMonitorTest { | ... | @@ -140,12 +179,12 @@ public class HostMonitorTest { |
| 140 | 179 | ||
| 141 | ConnectPoint cp = new ConnectPoint(devId, portNum); | 180 | ConnectPoint cp = new ConnectPoint(devId, portNum); |
| 142 | 181 | ||
| 143 | - expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) | 182 | + expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR)) |
| 144 | .andReturn(Collections.emptySet()).anyTimes(); | 183 | .andReturn(Collections.emptySet()).anyTimes(); |
| 145 | replay(hostManager); | 184 | replay(hostManager); |
| 146 | 185 | ||
| 147 | InterfaceService interfaceService = createMock(InterfaceService.class); | 186 | InterfaceService interfaceService = createMock(InterfaceService.class); |
| 148 | - expect(interfaceService.getMatchingInterface(TARGET_IP_ADDR)) | 187 | + expect(interfaceService.getMatchingInterface(TARGET_IPV4_ADDR)) |
| 149 | .andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE)) | 188 | .andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE)) |
| 150 | .anyTimes(); | 189 | .anyTimes(); |
| 151 | replay(interfaceService); | 190 | replay(interfaceService); |
| ... | @@ -156,7 +195,7 @@ public class HostMonitorTest { | ... | @@ -156,7 +195,7 @@ public class HostMonitorTest { |
| 156 | // Run the test | 195 | // Run the test |
| 157 | hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService); | 196 | hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService); |
| 158 | 197 | ||
| 159 | - hostMonitor.addMonitoringFor(TARGET_IP_ADDR); | 198 | + hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR); |
| 160 | hostMonitor.run(null); | 199 | hostMonitor.run(null); |
| 161 | 200 | ||
| 162 | 201 | ||
| ... | @@ -178,16 +217,85 @@ public class HostMonitorTest { | ... | @@ -178,16 +217,85 @@ public class HostMonitorTest { |
| 178 | Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length); | 217 | Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length); |
| 179 | assertEquals(Ethernet.VLAN_UNTAGGED, eth.getVlanID()); | 218 | assertEquals(Ethernet.VLAN_UNTAGGED, eth.getVlanID()); |
| 180 | ARP arp = (ARP) eth.getPayload(); | 219 | ARP arp = (ARP) eth.getPayload(); |
| 181 | - assertArrayEquals(SOURCE_ADDR.toOctets(), | 220 | + assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(), |
| 182 | arp.getSenderProtocolAddress()); | 221 | arp.getSenderProtocolAddress()); |
| 183 | assertArrayEquals(sourceMac.toBytes(), | 222 | assertArrayEquals(sourceMac.toBytes(), |
| 184 | arp.getSenderHardwareAddress()); | 223 | arp.getSenderHardwareAddress()); |
| 185 | - assertArrayEquals(TARGET_IP_ADDR.toOctets(), | 224 | + assertArrayEquals(TARGET_IPV4_ADDR.toOctets(), |
| 186 | arp.getTargetProtocolAddress()); | 225 | arp.getTargetProtocolAddress()); |
| 187 | } | 226 | } |
| 188 | 227 | ||
| 189 | @Test | 228 | @Test |
| 190 | - public void testMonitorHostDoesNotExistWithVlan() throws Exception { | 229 | + public void testMonitorIpv6HostDoesNotExist() throws Exception { |
| 230 | + | ||
| 231 | + HostManager hostManager = createMock(HostManager.class); | ||
| 232 | + | ||
| 233 | + DeviceId devId = DeviceId.deviceId("fake"); | ||
| 234 | + | ||
| 235 | + Device device = createMock(Device.class); | ||
| 236 | + expect(device.id()).andReturn(devId).anyTimes(); | ||
| 237 | + replay(device); | ||
| 238 | + | ||
| 239 | + PortNumber portNum = PortNumber.portNumber(2L); | ||
| 240 | + | ||
| 241 | + Port port = createMock(Port.class); | ||
| 242 | + expect(port.number()).andReturn(portNum).anyTimes(); | ||
| 243 | + replay(port); | ||
| 244 | + | ||
| 245 | + TestDeviceService deviceService = new TestDeviceService(); | ||
| 246 | + deviceService.addDevice(device, Collections.singleton(port)); | ||
| 247 | + | ||
| 248 | + ConnectPoint cp = new ConnectPoint(devId, portNum); | ||
| 249 | + | ||
| 250 | + expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR)) | ||
| 251 | + .andReturn(Collections.emptySet()).anyTimes(); | ||
| 252 | + replay(hostManager); | ||
| 253 | + | ||
| 254 | + InterfaceService interfaceService = createMock(InterfaceService.class); | ||
| 255 | + expect(interfaceService.getMatchingInterface(TARGET_IPV6_ADDR)) | ||
| 256 | + .andReturn(new Interface(cp, Collections.singleton(IA2), sourceMac2, VlanId.NONE)) | ||
| 257 | + .anyTimes(); | ||
| 258 | + replay(interfaceService); | ||
| 259 | + | ||
| 260 | + TestPacketService packetService = new TestPacketService(); | ||
| 261 | + | ||
| 262 | + | ||
| 263 | + // Run the test | ||
| 264 | + hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService); | ||
| 265 | + | ||
| 266 | + hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR); | ||
| 267 | + hostMonitor.run(null); | ||
| 268 | + | ||
| 269 | + | ||
| 270 | + // Check that a packet was sent to our PacketService and that it has | ||
| 271 | + // the properties we expect | ||
| 272 | + assertEquals(1, packetService.packets.size()); | ||
| 273 | + OutboundPacket packet = packetService.packets.get(0); | ||
| 274 | + | ||
| 275 | + // Check the output port is correct | ||
| 276 | + assertEquals(1, packet.treatment().immediate().size()); | ||
| 277 | + Instruction instruction = packet.treatment().immediate().get(0); | ||
| 278 | + assertTrue(instruction instanceof OutputInstruction); | ||
| 279 | + OutputInstruction oi = (OutputInstruction) instruction; | ||
| 280 | + assertEquals(portNum, oi.port()); | ||
| 281 | + | ||
| 282 | + // Check the output packet is correct (well the important bits anyway) | ||
| 283 | + final byte[] pktData = new byte[packet.data().remaining()]; | ||
| 284 | + packet.data().get(pktData); | ||
| 285 | + Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length); | ||
| 286 | + assertEquals(Ethernet.VLAN_UNTAGGED, eth.getVlanID()); | ||
| 287 | + IPv6 ipv6 = (IPv6) eth.getPayload(); | ||
| 288 | + assertArrayEquals(SOURCE_IPV6_ADDR.toOctets(), ipv6.getSourceAddress()); | ||
| 289 | + | ||
| 290 | + NeighborSolicitation ns = | ||
| 291 | + (NeighborSolicitation) ipv6.getPayload().getPayload(); | ||
| 292 | + assertArrayEquals(sourceMac2.toBytes(), ns.getOptions().get(0).data()); | ||
| 293 | + | ||
| 294 | + assertArrayEquals(TARGET_IPV6_ADDR.toOctets(), ns.getTargetAddress()); | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + @Test | ||
| 298 | + public void testMonitorIpv4HostDoesNotExistWithVlan() throws Exception { | ||
| 191 | 299 | ||
| 192 | HostManager hostManager = createMock(HostManager.class); | 300 | HostManager hostManager = createMock(HostManager.class); |
| 193 | 301 | ||
| ... | @@ -209,12 +317,12 @@ public class HostMonitorTest { | ... | @@ -209,12 +317,12 @@ public class HostMonitorTest { |
| 209 | 317 | ||
| 210 | ConnectPoint cp = new ConnectPoint(devId, portNum); | 318 | ConnectPoint cp = new ConnectPoint(devId, portNum); |
| 211 | 319 | ||
| 212 | - expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) | 320 | + expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR)) |
| 213 | .andReturn(Collections.emptySet()).anyTimes(); | 321 | .andReturn(Collections.emptySet()).anyTimes(); |
| 214 | replay(hostManager); | 322 | replay(hostManager); |
| 215 | 323 | ||
| 216 | InterfaceService interfaceService = createMock(InterfaceService.class); | 324 | InterfaceService interfaceService = createMock(InterfaceService.class); |
| 217 | - expect(interfaceService.getMatchingInterface(TARGET_IP_ADDR)) | 325 | + expect(interfaceService.getMatchingInterface(TARGET_IPV4_ADDR)) |
| 218 | .andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.vlanId(vlan))) | 326 | .andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.vlanId(vlan))) |
| 219 | .anyTimes(); | 327 | .anyTimes(); |
| 220 | replay(interfaceService); | 328 | replay(interfaceService); |
| ... | @@ -225,7 +333,7 @@ public class HostMonitorTest { | ... | @@ -225,7 +333,7 @@ public class HostMonitorTest { |
| 225 | // Run the test | 333 | // Run the test |
| 226 | hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService); | 334 | hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService); |
| 227 | 335 | ||
| 228 | - hostMonitor.addMonitoringFor(TARGET_IP_ADDR); | 336 | + hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR); |
| 229 | hostMonitor.run(null); | 337 | hostMonitor.run(null); |
| 230 | 338 | ||
| 231 | 339 | ||
| ... | @@ -247,14 +355,84 @@ public class HostMonitorTest { | ... | @@ -247,14 +355,84 @@ public class HostMonitorTest { |
| 247 | Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length); | 355 | Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length); |
| 248 | assertEquals(vlan, eth.getVlanID()); | 356 | assertEquals(vlan, eth.getVlanID()); |
| 249 | ARP arp = (ARP) eth.getPayload(); | 357 | ARP arp = (ARP) eth.getPayload(); |
| 250 | - assertArrayEquals(SOURCE_ADDR.toOctets(), | 358 | + assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(), |
| 251 | arp.getSenderProtocolAddress()); | 359 | arp.getSenderProtocolAddress()); |
| 252 | assertArrayEquals(sourceMac.toBytes(), | 360 | assertArrayEquals(sourceMac.toBytes(), |
| 253 | arp.getSenderHardwareAddress()); | 361 | arp.getSenderHardwareAddress()); |
| 254 | - assertArrayEquals(TARGET_IP_ADDR.toOctets(), | 362 | + assertArrayEquals(TARGET_IPV4_ADDR.toOctets(), |
| 255 | arp.getTargetProtocolAddress()); | 363 | arp.getTargetProtocolAddress()); |
| 256 | } | 364 | } |
| 257 | 365 | ||
| 366 | + @Test | ||
| 367 | + public void testMonitorIpv6HostDoesNotExistWithVlan() throws Exception { | ||
| 368 | + | ||
| 369 | + HostManager hostManager = createMock(HostManager.class); | ||
| 370 | + | ||
| 371 | + DeviceId devId = DeviceId.deviceId("fake"); | ||
| 372 | + short vlan = 5; | ||
| 373 | + | ||
| 374 | + Device device = createMock(Device.class); | ||
| 375 | + expect(device.id()).andReturn(devId).anyTimes(); | ||
| 376 | + replay(device); | ||
| 377 | + | ||
| 378 | + PortNumber portNum = PortNumber.portNumber(1L); | ||
| 379 | + | ||
| 380 | + Port port = createMock(Port.class); | ||
| 381 | + expect(port.number()).andReturn(portNum).anyTimes(); | ||
| 382 | + replay(port); | ||
| 383 | + | ||
| 384 | + TestDeviceService deviceService = new TestDeviceService(); | ||
| 385 | + deviceService.addDevice(device, Collections.singleton(port)); | ||
| 386 | + | ||
| 387 | + ConnectPoint cp = new ConnectPoint(devId, portNum); | ||
| 388 | + | ||
| 389 | + expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR)) | ||
| 390 | + .andReturn(Collections.emptySet()).anyTimes(); | ||
| 391 | + replay(hostManager); | ||
| 392 | + | ||
| 393 | + InterfaceService interfaceService = createMock(InterfaceService.class); | ||
| 394 | + expect(interfaceService.getMatchingInterface(TARGET_IPV6_ADDR)) | ||
| 395 | + .andReturn(new Interface(cp, Collections.singleton(IA2), sourceMac2, VlanId.vlanId(vlan))) | ||
| 396 | + .anyTimes(); | ||
| 397 | + replay(interfaceService); | ||
| 398 | + | ||
| 399 | + TestPacketService packetService = new TestPacketService(); | ||
| 400 | + | ||
| 401 | + | ||
| 402 | + // Run the test | ||
| 403 | + hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService); | ||
| 404 | + | ||
| 405 | + hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR); | ||
| 406 | + hostMonitor.run(null); | ||
| 407 | + | ||
| 408 | + | ||
| 409 | + // Check that a packet was sent to our PacketService and that it has | ||
| 410 | + // the properties we expect | ||
| 411 | + assertEquals(1, packetService.packets.size()); | ||
| 412 | + OutboundPacket packet = packetService.packets.get(0); | ||
| 413 | + | ||
| 414 | + // Check the output port is correct | ||
| 415 | + assertEquals(1, packet.treatment().immediate().size()); | ||
| 416 | + Instruction instruction = packet.treatment().immediate().get(0); | ||
| 417 | + assertTrue(instruction instanceof OutputInstruction); | ||
| 418 | + OutputInstruction oi = (OutputInstruction) instruction; | ||
| 419 | + assertEquals(portNum, oi.port()); | ||
| 420 | + | ||
| 421 | + // Check the output packet is correct (well the important bits anyway) | ||
| 422 | + final byte[] pktData = new byte[packet.data().remaining()]; | ||
| 423 | + packet.data().get(pktData); | ||
| 424 | + Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length); | ||
| 425 | + assertEquals(vlan, eth.getVlanID()); | ||
| 426 | + IPv6 ipv6 = (IPv6) eth.getPayload(); | ||
| 427 | + assertArrayEquals(SOURCE_IPV6_ADDR.toOctets(), ipv6.getSourceAddress()); | ||
| 428 | + | ||
| 429 | + NeighborSolicitation ns = | ||
| 430 | + (NeighborSolicitation) ipv6.getPayload().getPayload(); | ||
| 431 | + assertArrayEquals(sourceMac2.toBytes(), ns.getOptions().get(0).data()); | ||
| 432 | + | ||
| 433 | + assertArrayEquals(TARGET_IPV6_ADDR.toOctets(), ns.getTargetAddress()); | ||
| 434 | + } | ||
| 435 | + | ||
| 258 | class TestPacketService extends PacketServiceAdapter { | 436 | class TestPacketService extends PacketServiceAdapter { |
| 259 | 437 | ||
| 260 | List<OutboundPacket> packets = new ArrayList<>(); | 438 | List<OutboundPacket> packets = new ArrayList<>(); | ... | ... |
| ... | @@ -335,15 +335,15 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -335,15 +335,15 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
| 335 | arp.getSenderProtocolAddress()); | 335 | arp.getSenderProtocolAddress()); |
| 336 | updateLocationIP(hid, srcMac, vlan, hloc, ip); | 336 | updateLocationIP(hid, srcMac, vlan, hloc, ip); |
| 337 | 337 | ||
| 338 | - // IPv4: update location only | 338 | + // IPv4: update location only |
| 339 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { | 339 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { |
| 340 | updateLocation(hid, srcMac, vlan, hloc); | 340 | updateLocation(hid, srcMac, vlan, hloc); |
| 341 | 341 | ||
| 342 | - // | 342 | + // |
| 343 | - // NeighborAdvertisement and NeighborSolicitation: possible | 343 | + // NeighborAdvertisement and NeighborSolicitation: possible |
| 344 | - // new hosts, update both location and IP. | 344 | + // new hosts, update both location and IP. |
| 345 | - // | 345 | + // |
| 346 | - // IPv6: update location only | 346 | + // IPv6: update location only |
| 347 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) { | 347 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) { |
| 348 | IPv6 ipv6 = (IPv6) eth.getPayload(); | 348 | IPv6 ipv6 = (IPv6) eth.getPayload(); |
| 349 | IpAddress ip = IpAddress.valueOf(IpAddress.Version.INET6, | 349 | IpAddress ip = IpAddress.valueOf(IpAddress.Version.INET6, | ... | ... |
| ... | @@ -23,9 +23,17 @@ import org.onlab.osgi.ComponentContextAdapter; | ... | @@ -23,9 +23,17 @@ import org.onlab.osgi.ComponentContextAdapter; |
| 23 | import org.onlab.packet.ARP; | 23 | import org.onlab.packet.ARP; |
| 24 | import org.onlab.packet.ChassisId; | 24 | import org.onlab.packet.ChassisId; |
| 25 | import org.onlab.packet.Ethernet; | 25 | import org.onlab.packet.Ethernet; |
| 26 | +import org.onlab.packet.ICMP6; | ||
| 27 | +import org.onlab.packet.IPv4; | ||
| 28 | +import org.onlab.packet.IPv6; | ||
| 29 | +import org.onlab.packet.Ip6Address; | ||
| 26 | import org.onlab.packet.IpAddress; | 30 | import org.onlab.packet.IpAddress; |
| 27 | import org.onlab.packet.MacAddress; | 31 | import org.onlab.packet.MacAddress; |
| 28 | import org.onlab.packet.VlanId; | 32 | import org.onlab.packet.VlanId; |
| 33 | +import org.onlab.packet.ndp.NeighborAdvertisement; | ||
| 34 | +import org.onlab.packet.ndp.NeighborSolicitation; | ||
| 35 | +import org.onlab.packet.ndp.RouterAdvertisement; | ||
| 36 | +import org.onlab.packet.ndp.RouterSolicitation; | ||
| 29 | import org.onosproject.cfg.ComponentConfigAdapter; | 37 | import org.onosproject.cfg.ComponentConfigAdapter; |
| 30 | import org.onosproject.core.ApplicationId; | 38 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; | 39 | import org.onosproject.core.CoreService; |
| ... | @@ -66,6 +74,7 @@ import java.util.Hashtable; | ... | @@ -66,6 +74,7 @@ import java.util.Hashtable; |
| 66 | import java.util.Set; | 74 | import java.util.Set; |
| 67 | 75 | ||
| 68 | import static org.easymock.EasyMock.*; | 76 | import static org.easymock.EasyMock.*; |
| 77 | +import static org.hamcrest.Matchers.is; | ||
| 69 | import static org.junit.Assert.*; | 78 | import static org.junit.Assert.*; |
| 70 | import static org.onlab.packet.VlanId.vlanId; | 79 | import static org.onlab.packet.VlanId.vlanId; |
| 71 | import static org.onosproject.net.Device.Type.SWITCH; | 80 | import static org.onosproject.net.Device.Type.SWITCH; |
| ... | @@ -75,27 +84,42 @@ import static org.onosproject.net.PortNumber.portNumber; | ... | @@ -75,27 +84,42 @@ import static org.onosproject.net.PortNumber.portNumber; |
| 75 | import static org.onosproject.net.device.DeviceEvent.Type.*; | 84 | import static org.onosproject.net.device.DeviceEvent.Type.*; |
| 76 | 85 | ||
| 77 | public class HostLocationProviderTest { | 86 | public class HostLocationProviderTest { |
| 78 | - | ||
| 79 | private static final Integer INPORT = 10; | 87 | private static final Integer INPORT = 10; |
| 80 | private static final String DEV1 = "of:1"; | 88 | private static final String DEV1 = "of:1"; |
| 81 | private static final String DEV2 = "of:2"; | 89 | private static final String DEV2 = "of:2"; |
| 82 | private static final String DEV3 = "of:3"; | 90 | private static final String DEV3 = "of:3"; |
| 91 | + private static final String DEV4 = "of:4"; | ||
| 92 | + private static final String DEV5 = "of:5"; | ||
| 93 | + private static final String DEV6 = "of:6"; | ||
| 83 | 94 | ||
| 84 | private static final VlanId VLAN = vlanId(); | 95 | private static final VlanId VLAN = vlanId(); |
| 96 | + | ||
| 97 | + // IPv4 Host | ||
| 85 | private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01"); | 98 | private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01"); |
| 86 | private static final MacAddress BCMAC = MacAddress.valueOf("ff:ff:ff:ff:ff:ff"); | 99 | private static final MacAddress BCMAC = MacAddress.valueOf("ff:ff:ff:ff:ff:ff"); |
| 87 | private static final byte[] IP = new byte[]{10, 0, 0, 1}; | 100 | private static final byte[] IP = new byte[]{10, 0, 0, 1}; |
| 88 | - | ||
| 89 | private static final IpAddress IP_ADDRESS = | 101 | private static final IpAddress IP_ADDRESS = |
| 90 | IpAddress.valueOf(IpAddress.Version.INET, IP); | 102 | IpAddress.valueOf(IpAddress.Version.INET, IP); |
| 91 | private static final HostLocation LOCATION = | 103 | private static final HostLocation LOCATION = |
| 92 | new HostLocation(deviceId(DEV1), portNumber(INPORT), 0L); | 104 | new HostLocation(deviceId(DEV1), portNumber(INPORT), 0L); |
| 93 | - | ||
| 94 | private static final DefaultHost HOST = | 105 | private static final DefaultHost HOST = |
| 95 | new DefaultHost(ProviderId.NONE, hostId(MAC), MAC, | 106 | new DefaultHost(ProviderId.NONE, hostId(MAC), MAC, |
| 96 | vlanId(VlanId.UNTAGGED), LOCATION, | 107 | vlanId(VlanId.UNTAGGED), LOCATION, |
| 97 | ImmutableSet.of(IP_ADDRESS)); | 108 | ImmutableSet.of(IP_ADDRESS)); |
| 98 | 109 | ||
| 110 | + // IPv6 Host | ||
| 111 | + private static final MacAddress MAC2 = MacAddress.valueOf("00:00:22:00:00:02"); | ||
| 112 | + private static final MacAddress BCMAC2 = MacAddress.valueOf("33:33:00:00:00:01"); | ||
| 113 | + private static final byte[] IP2 = Ip6Address.valueOf("1000::1").toOctets(); | ||
| 114 | + private static final IpAddress IP_ADDRESS2 = | ||
| 115 | + IpAddress.valueOf(IpAddress.Version.INET6, IP2); | ||
| 116 | + private static final HostLocation LOCATION2 = | ||
| 117 | + new HostLocation(deviceId(DEV4), portNumber(INPORT), 0L); | ||
| 118 | + private static final DefaultHost HOST2 = | ||
| 119 | + new DefaultHost(ProviderId.NONE, hostId(MAC2), MAC2, | ||
| 120 | + vlanId(VlanId.UNTAGGED), LOCATION2, | ||
| 121 | + ImmutableSet.of(IP_ADDRESS2)); | ||
| 122 | + | ||
| 99 | private static final ComponentContextAdapter CTX_FOR_REMOVE = | 123 | private static final ComponentContextAdapter CTX_FOR_REMOVE = |
| 100 | new ComponentContextAdapter() { | 124 | new ComponentContextAdapter() { |
| 101 | @Override | 125 | @Override |
| ... | @@ -157,51 +181,189 @@ public class HostLocationProviderTest { | ... | @@ -157,51 +181,189 @@ public class HostLocationProviderTest { |
| 157 | @Test | 181 | @Test |
| 158 | public void events() { | 182 | public void events() { |
| 159 | // new host | 183 | // new host |
| 160 | - testProcessor.process(new TestPacketContext(DEV1)); | 184 | + testProcessor.process(new TestArpPacketContext(DEV1)); |
| 161 | assertNotNull("new host expected", providerService.added); | 185 | assertNotNull("new host expected", providerService.added); |
| 162 | assertNull("host motion unexpected", providerService.moved); | 186 | assertNull("host motion unexpected", providerService.moved); |
| 163 | 187 | ||
| 164 | // the host moved to new switch | 188 | // the host moved to new switch |
| 165 | - testProcessor.process(new TestPacketContext(DEV2)); | 189 | + testProcessor.process(new TestArpPacketContext(DEV2)); |
| 166 | assertNotNull("host motion expected", providerService.moved); | 190 | assertNotNull("host motion expected", providerService.moved); |
| 167 | 191 | ||
| 168 | // the host was misheard on a spine | 192 | // the host was misheard on a spine |
| 169 | - testProcessor.process(new TestPacketContext(DEV3)); | 193 | + testProcessor.process(new TestArpPacketContext(DEV3)); |
| 194 | + assertNull("host misheard on spine switch", providerService.spine); | ||
| 195 | + | ||
| 196 | + providerService.clear(); | ||
| 197 | + | ||
| 198 | + // new host | ||
| 199 | + testProcessor.process(new TestNAPacketContext(DEV4)); | ||
| 200 | + assertNotNull("new host expected", providerService.added); | ||
| 201 | + assertNull("host motion unexpected", providerService.moved); | ||
| 202 | + | ||
| 203 | + // the host moved to new switch | ||
| 204 | + testProcessor.process(new TestNAPacketContext(DEV5)); | ||
| 205 | + assertNotNull("host motion expected", providerService.moved); | ||
| 206 | + | ||
| 207 | + // the host was misheard on a spine | ||
| 208 | + testProcessor.process(new TestNAPacketContext(DEV6)); | ||
| 170 | assertNull("host misheard on spine switch", providerService.spine); | 209 | assertNull("host misheard on spine switch", providerService.spine); |
| 171 | } | 210 | } |
| 172 | 211 | ||
| 173 | @Test | 212 | @Test |
| 174 | public void removeHostByDeviceRemove() { | 213 | public void removeHostByDeviceRemove() { |
| 175 | provider.modified(CTX_FOR_REMOVE); | 214 | provider.modified(CTX_FOR_REMOVE); |
| 176 | - testProcessor.process(new TestPacketContext(DEV1)); | 215 | + testProcessor.process(new TestArpPacketContext(DEV1)); |
| 216 | + testProcessor.process(new TestNAPacketContext(DEV4)); | ||
| 217 | + | ||
| 177 | Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, | 218 | Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, |
| 178 | "m", "h", "s", "n", new ChassisId(0L)); | 219 | "m", "h", "s", "n", new ChassisId(0L)); |
| 179 | deviceService.listener.event(new DeviceEvent(DEVICE_REMOVED, device)); | 220 | deviceService.listener.event(new DeviceEvent(DEVICE_REMOVED, device)); |
| 180 | assertEquals("incorrect remove count", 1, providerService.removeCount); | 221 | assertEquals("incorrect remove count", 1, providerService.removeCount); |
| 222 | + | ||
| 223 | + device = new DefaultDevice(ProviderId.NONE, deviceId(DEV4), SWITCH, | ||
| 224 | + "m", "h", "s", "n", new ChassisId(0L)); | ||
| 225 | + deviceService.listener.event(new DeviceEvent(DEVICE_REMOVED, device)); | ||
| 226 | + assertEquals("incorrect remove count", 2, providerService.removeCount); | ||
| 181 | } | 227 | } |
| 182 | 228 | ||
| 183 | @Test | 229 | @Test |
| 184 | public void removeHostByDeviceOffline() { | 230 | public void removeHostByDeviceOffline() { |
| 185 | provider.modified(CTX_FOR_REMOVE); | 231 | provider.modified(CTX_FOR_REMOVE); |
| 186 | - testProcessor.process(new TestPacketContext(DEV1)); | 232 | + testProcessor.process(new TestArpPacketContext(DEV1)); |
| 233 | + testProcessor.process(new TestArpPacketContext(DEV4)); | ||
| 234 | + | ||
| 187 | Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, | 235 | Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, |
| 188 | "m", "h", "s", "n", new ChassisId(0L)); | 236 | "m", "h", "s", "n", new ChassisId(0L)); |
| 189 | deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device)); | 237 | deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device)); |
| 190 | assertEquals("incorrect remove count", 1, providerService.removeCount); | 238 | assertEquals("incorrect remove count", 1, providerService.removeCount); |
| 239 | + | ||
| 240 | + device = new DefaultDevice(ProviderId.NONE, deviceId(DEV4), SWITCH, | ||
| 241 | + "m", "h", "s", "n", new ChassisId(0L)); | ||
| 242 | + deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device)); | ||
| 243 | + assertEquals("incorrect remove count", 2, providerService.removeCount); | ||
| 191 | } | 244 | } |
| 192 | 245 | ||
| 193 | @Test | 246 | @Test |
| 194 | public void removeHostByDevicePortDown() { | 247 | public void removeHostByDevicePortDown() { |
| 195 | provider.modified(CTX_FOR_REMOVE); | 248 | provider.modified(CTX_FOR_REMOVE); |
| 196 | - testProcessor.process(new TestPacketContext(DEV1)); | 249 | + testProcessor.process(new TestArpPacketContext(DEV1)); |
| 250 | + testProcessor.process(new TestArpPacketContext(DEV4)); | ||
| 251 | + | ||
| 197 | Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, | 252 | Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, |
| 198 | "m", "h", "s", "n", new ChassisId(0L)); | 253 | "m", "h", "s", "n", new ChassisId(0L)); |
| 199 | deviceService.listener.event(new DeviceEvent(PORT_UPDATED, device, | 254 | deviceService.listener.event(new DeviceEvent(PORT_UPDATED, device, |
| 200 | - new DefaultPort(device, portNumber(INPORT), | 255 | + new DefaultPort(device, portNumber(INPORT), false))); |
| 201 | - false))); | ||
| 202 | assertEquals("incorrect remove count", 1, providerService.removeCount); | 256 | assertEquals("incorrect remove count", 1, providerService.removeCount); |
| 257 | + | ||
| 258 | + device = new DefaultDevice(ProviderId.NONE, deviceId(DEV4), SWITCH, | ||
| 259 | + "m", "h", "s", "n", new ChassisId(0L)); | ||
| 260 | + deviceService.listener.event(new DeviceEvent(PORT_UPDATED, device, | ||
| 261 | + new DefaultPort(device, portNumber(INPORT), false))); | ||
| 262 | + assertEquals("incorrect remove count", 2, providerService.removeCount); | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + /** | ||
| 266 | + * When receiving ARP, updates location and IP. | ||
| 267 | + */ | ||
| 268 | + @Test | ||
| 269 | + public void testReceiveArp() { | ||
| 270 | + testProcessor.process(new TestArpPacketContext(DEV1)); | ||
| 271 | + HostDescription descr = providerService.added; | ||
| 272 | + assertThat(descr.location(), is(LOCATION)); | ||
| 273 | + assertThat(descr.hwAddress(), is(MAC)); | ||
| 274 | + assertThat(descr.ipAddress().toArray()[0], is(IP_ADDRESS)); | ||
| 275 | + assertThat(descr.vlan(), is(VLAN)); | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + /** | ||
| 279 | + * When receiving IPv4, updates location only. | ||
| 280 | + */ | ||
| 281 | + @Test | ||
| 282 | + public void testReceiveIpv4() { | ||
| 283 | + testProcessor.process(new TestIpv4PacketContext(DEV1)); | ||
| 284 | + HostDescription descr = providerService.added; | ||
| 285 | + assertThat(descr.location(), is(LOCATION)); | ||
| 286 | + assertThat(descr.hwAddress(), is(MAC)); | ||
| 287 | + assertThat(descr.ipAddress().size(), is(0)); | ||
| 288 | + assertThat(descr.vlan(), is(VLAN)); | ||
| 203 | } | 289 | } |
| 204 | 290 | ||
| 291 | + /** | ||
| 292 | + * When receiving NeighborAdvertisement, updates location and IP. | ||
| 293 | + */ | ||
| 294 | + @Test | ||
| 295 | + public void testReceiveNA() { | ||
| 296 | + testProcessor.process(new TestNAPacketContext(DEV4)); | ||
| 297 | + assertNotNull(providerService.added); | ||
| 298 | + HostDescription descr = providerService.added; | ||
| 299 | + assertThat(descr.location(), is(LOCATION2)); | ||
| 300 | + assertThat(descr.hwAddress(), is(MAC2)); | ||
| 301 | + assertThat(descr.ipAddress().toArray()[0], is(IP_ADDRESS2)); | ||
| 302 | + assertThat(descr.vlan(), is(VLAN)); | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + /** | ||
| 306 | + * When receiving NeighborSolicitation, updates location and IP. | ||
| 307 | + */ | ||
| 308 | + @Test | ||
| 309 | + public void testReceiveNS() { | ||
| 310 | + testProcessor.process(new TestNSPacketContext(DEV4)); | ||
| 311 | + HostDescription descr = providerService.added; | ||
| 312 | + assertThat(descr.location(), is(LOCATION2)); | ||
| 313 | + assertThat(descr.hwAddress(), is(MAC2)); | ||
| 314 | + assertThat(descr.ipAddress().toArray()[0], is(IP_ADDRESS2)); | ||
| 315 | + assertThat(descr.vlan(), is(VLAN)); | ||
| 316 | + } | ||
| 317 | + | ||
| 318 | + /** | ||
| 319 | + * When receiving RouterAdvertisement, ignores it. | ||
| 320 | + */ | ||
| 321 | + @Test | ||
| 322 | + public void testReceivesRA() { | ||
| 323 | + testProcessor.process(new TestRAPacketContext(DEV4)); | ||
| 324 | + assertNull(providerService.added); | ||
| 325 | + } | ||
| 326 | + | ||
| 327 | + /** | ||
| 328 | + * When receiving RouterSolicitation, ignores it. | ||
| 329 | + */ | ||
| 330 | + @Test | ||
| 331 | + public void testReceiveRS() { | ||
| 332 | + testProcessor.process(new TestRSPacketContext(DEV4)); | ||
| 333 | + assertNull(providerService.added); | ||
| 334 | + } | ||
| 335 | + | ||
| 336 | + /** | ||
| 337 | + * When receiving Duplicate Address Detection (DAD), ignores it. | ||
| 338 | + */ | ||
| 339 | + @Test | ||
| 340 | + public void testReceiveDAD() { | ||
| 341 | + testProcessor.process(new TestDADPacketContext(DEV4)); | ||
| 342 | + assertNull(providerService.added); | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + /** | ||
| 346 | + * When receiving IPv6 multicast packet, ignores it. | ||
| 347 | + */ | ||
| 348 | + @Test | ||
| 349 | + public void testReceiveIpv6Multicast() { | ||
| 350 | + testProcessor.process(new TestIpv6McastPacketContext(DEV4)); | ||
| 351 | + assertNull(providerService.added); | ||
| 352 | + } | ||
| 353 | + | ||
| 354 | + /** | ||
| 355 | + * When receiving IPv6 unicast packet, updates location only. | ||
| 356 | + */ | ||
| 357 | + @Test | ||
| 358 | + public void testReceiveIpv6Unicast() { | ||
| 359 | + testProcessor.process(new TestIpv6PacketContext(DEV4)); | ||
| 360 | + assertNotNull(providerService.added); | ||
| 361 | + HostDescription descr = providerService.added; | ||
| 362 | + assertThat(descr.location(), is(LOCATION2)); | ||
| 363 | + assertThat(descr.hwAddress(), is(MAC2)); | ||
| 364 | + assertThat(descr.ipAddress().size(), is(0)); | ||
| 365 | + assertThat(descr.vlan(), is(VLAN)); | ||
| 366 | + } | ||
| 205 | 367 | ||
| 206 | @After | 368 | @After |
| 207 | public void tearDown() { | 369 | public void tearDown() { |
| ... | @@ -233,24 +395,30 @@ public class HostLocationProviderTest { | ... | @@ -233,24 +395,30 @@ public class HostLocationProviderTest { |
| 233 | extends AbstractProviderService<HostProvider> | 395 | extends AbstractProviderService<HostProvider> |
| 234 | implements HostProviderService { | 396 | implements HostProviderService { |
| 235 | 397 | ||
| 236 | - DeviceId added = null; | 398 | + HostDescription added = null; |
| 237 | - DeviceId moved = null; | 399 | + HostDescription moved = null; |
| 238 | - DeviceId spine = null; | 400 | + HostDescription spine = null; |
| 239 | public int removeCount; | 401 | public int removeCount; |
| 240 | 402 | ||
| 403 | + public void clear() { | ||
| 404 | + added = null; | ||
| 405 | + moved = null; | ||
| 406 | + spine = null; | ||
| 407 | + removeCount = 0; | ||
| 408 | + } | ||
| 409 | + | ||
| 241 | protected TestHostProviderService(HostProvider provider) { | 410 | protected TestHostProviderService(HostProvider provider) { |
| 242 | super(provider); | 411 | super(provider); |
| 243 | } | 412 | } |
| 244 | 413 | ||
| 245 | @Override | 414 | @Override |
| 246 | public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) { | 415 | public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) { |
| 247 | - DeviceId descr = hostDescription.location().deviceId(); | ||
| 248 | if (added == null) { | 416 | if (added == null) { |
| 249 | - added = descr; | 417 | + added = hostDescription; |
| 250 | - } else if ((moved == null) && !descr.equals(added)) { | 418 | + } else if ((moved == null) && !hostDescription.equals(added)) { |
| 251 | - moved = descr; | 419 | + moved = hostDescription; |
| 252 | } else { | 420 | } else { |
| 253 | - spine = descr; | 421 | + spine = hostDescription; |
| 254 | } | 422 | } |
| 255 | } | 423 | } |
| 256 | 424 | ||
| ... | @@ -272,24 +440,26 @@ public class HostLocationProviderTest { | ... | @@ -272,24 +440,26 @@ public class HostLocationProviderTest { |
| 272 | } | 440 | } |
| 273 | } | 441 | } |
| 274 | 442 | ||
| 275 | - | ||
| 276 | private class TestTopologyService extends TopologyServiceAdapter { | 443 | private class TestTopologyService extends TopologyServiceAdapter { |
| 277 | @Override | 444 | @Override |
| 278 | public boolean isInfrastructure(Topology topology, | 445 | public boolean isInfrastructure(Topology topology, |
| 279 | ConnectPoint connectPoint) { | 446 | ConnectPoint connectPoint) { |
| 280 | //simulate DPID3 as an infrastructure switch | 447 | //simulate DPID3 as an infrastructure switch |
| 281 | - if ((connectPoint.deviceId()).equals(deviceId(DEV3))) { | 448 | + if ((connectPoint.deviceId()).equals(deviceId(DEV3)) || |
| 449 | + connectPoint.deviceId().equals(deviceId(DEV6))) { | ||
| 282 | return true; | 450 | return true; |
| 283 | } | 451 | } |
| 284 | return false; | 452 | return false; |
| 285 | } | 453 | } |
| 286 | } | 454 | } |
| 287 | 455 | ||
| 288 | - private class TestPacketContext implements PacketContext { | 456 | + /** |
| 289 | - | 457 | + * Generates ARP packet. |
| 458 | + */ | ||
| 459 | + private class TestArpPacketContext implements PacketContext { | ||
| 290 | private final String deviceId; | 460 | private final String deviceId; |
| 291 | 461 | ||
| 292 | - public TestPacketContext(String deviceId) { | 462 | + public TestArpPacketContext(String deviceId) { |
| 293 | this.deviceId = deviceId; | 463 | this.deviceId = deviceId; |
| 294 | } | 464 | } |
| 295 | 465 | ||
| ... | @@ -344,6 +514,490 @@ public class HostLocationProviderTest { | ... | @@ -344,6 +514,490 @@ public class HostLocationProviderTest { |
| 344 | } | 514 | } |
| 345 | } | 515 | } |
| 346 | 516 | ||
| 517 | + /** | ||
| 518 | + * Generates IPv6 Unicast packet. | ||
| 519 | + */ | ||
| 520 | + private class TestIpv4PacketContext implements PacketContext { | ||
| 521 | + private final String deviceId; | ||
| 522 | + | ||
| 523 | + public TestIpv4PacketContext(String deviceId) { | ||
| 524 | + this.deviceId = deviceId; | ||
| 525 | + } | ||
| 526 | + | ||
| 527 | + @Override | ||
| 528 | + public long time() { | ||
| 529 | + return 0; | ||
| 530 | + } | ||
| 531 | + | ||
| 532 | + @Override | ||
| 533 | + public InboundPacket inPacket() { | ||
| 534 | + IPv4 ipv4 = new IPv4(); | ||
| 535 | + ipv4.setDestinationAddress("10.0.0.1"); | ||
| 536 | + ipv4.setSourceAddress(IP_ADDRESS.toString()); | ||
| 537 | + Ethernet eth = new Ethernet(); | ||
| 538 | + eth.setEtherType(Ethernet.TYPE_IPV4) | ||
| 539 | + .setVlanID(VLAN.toShort()) | ||
| 540 | + .setSourceMACAddress(MAC) | ||
| 541 | + .setDestinationMACAddress(MacAddress.valueOf("00:00:00:00:00:01")) | ||
| 542 | + .setPayload(ipv4); | ||
| 543 | + ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), | ||
| 544 | + portNumber(INPORT)); | ||
| 545 | + return new DefaultInboundPacket(receivedFrom, eth, | ||
| 546 | + ByteBuffer.wrap(eth.serialize())); | ||
| 547 | + } | ||
| 548 | + | ||
| 549 | + @Override | ||
| 550 | + public OutboundPacket outPacket() { | ||
| 551 | + return null; | ||
| 552 | + } | ||
| 553 | + | ||
| 554 | + @Override | ||
| 555 | + public TrafficTreatment.Builder treatmentBuilder() { | ||
| 556 | + return null; | ||
| 557 | + } | ||
| 558 | + | ||
| 559 | + @Override | ||
| 560 | + public void send() { | ||
| 561 | + | ||
| 562 | + } | ||
| 563 | + | ||
| 564 | + @Override | ||
| 565 | + public boolean block() { | ||
| 566 | + return false; | ||
| 567 | + } | ||
| 568 | + | ||
| 569 | + @Override | ||
| 570 | + public boolean isHandled() { | ||
| 571 | + return false; | ||
| 572 | + } | ||
| 573 | + } | ||
| 574 | + | ||
| 575 | + /** | ||
| 576 | + * Generates NeighborAdvertisement packet. | ||
| 577 | + */ | ||
| 578 | + private class TestNAPacketContext implements PacketContext { | ||
| 579 | + private final String deviceId; | ||
| 580 | + | ||
| 581 | + public TestNAPacketContext(String deviceId) { | ||
| 582 | + this.deviceId = deviceId; | ||
| 583 | + } | ||
| 584 | + | ||
| 585 | + @Override | ||
| 586 | + public long time() { | ||
| 587 | + return 0; | ||
| 588 | + } | ||
| 589 | + | ||
| 590 | + @Override | ||
| 591 | + public InboundPacket inPacket() { | ||
| 592 | + NeighborAdvertisement na = new NeighborAdvertisement(); | ||
| 593 | + ICMP6 icmp6 = new ICMP6(); | ||
| 594 | + icmp6.setPayload(na); | ||
| 595 | + IPv6 ipv6 = new IPv6(); | ||
| 596 | + ipv6.setPayload(icmp6); | ||
| 597 | + ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets()); | ||
| 598 | + ipv6.setSourceAddress(IP2); | ||
| 599 | + Ethernet eth = new Ethernet(); | ||
| 600 | + eth.setEtherType(Ethernet.TYPE_IPV6) | ||
| 601 | + .setVlanID(VLAN.toShort()) | ||
| 602 | + .setSourceMACAddress(MAC2.toBytes()) | ||
| 603 | + .setDestinationMACAddress(BCMAC2) | ||
| 604 | + .setPayload(ipv6); | ||
| 605 | + ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), | ||
| 606 | + portNumber(INPORT)); | ||
| 607 | + return new DefaultInboundPacket(receivedFrom, eth, | ||
| 608 | + ByteBuffer.wrap(eth.serialize())); | ||
| 609 | + } | ||
| 610 | + | ||
| 611 | + @Override | ||
| 612 | + public OutboundPacket outPacket() { | ||
| 613 | + return null; | ||
| 614 | + } | ||
| 615 | + | ||
| 616 | + @Override | ||
| 617 | + public TrafficTreatment.Builder treatmentBuilder() { | ||
| 618 | + return null; | ||
| 619 | + } | ||
| 620 | + | ||
| 621 | + @Override | ||
| 622 | + public void send() { | ||
| 623 | + | ||
| 624 | + } | ||
| 625 | + | ||
| 626 | + @Override | ||
| 627 | + public boolean block() { | ||
| 628 | + return false; | ||
| 629 | + } | ||
| 630 | + | ||
| 631 | + @Override | ||
| 632 | + public boolean isHandled() { | ||
| 633 | + return false; | ||
| 634 | + } | ||
| 635 | + } | ||
| 636 | + | ||
| 637 | + /** | ||
| 638 | + * Generates NeighborSolicitation packet. | ||
| 639 | + */ | ||
| 640 | + private class TestNSPacketContext implements PacketContext { | ||
| 641 | + private final String deviceId; | ||
| 642 | + | ||
| 643 | + public TestNSPacketContext(String deviceId) { | ||
| 644 | + this.deviceId = deviceId; | ||
| 645 | + } | ||
| 646 | + | ||
| 647 | + @Override | ||
| 648 | + public long time() { | ||
| 649 | + return 0; | ||
| 650 | + } | ||
| 651 | + | ||
| 652 | + @Override | ||
| 653 | + public InboundPacket inPacket() { | ||
| 654 | + NeighborSolicitation ns = new NeighborSolicitation(); | ||
| 655 | + ICMP6 icmp6 = new ICMP6(); | ||
| 656 | + icmp6.setPayload(ns); | ||
| 657 | + IPv6 ipv6 = new IPv6(); | ||
| 658 | + ipv6.setPayload(icmp6); | ||
| 659 | + ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1:ff00:0000").toOctets()); | ||
| 660 | + ipv6.setSourceAddress(IP2); | ||
| 661 | + Ethernet eth = new Ethernet(); | ||
| 662 | + eth.setEtherType(Ethernet.TYPE_IPV6) | ||
| 663 | + .setVlanID(VLAN.toShort()) | ||
| 664 | + .setSourceMACAddress(MAC2.toBytes()) | ||
| 665 | + .setDestinationMACAddress(BCMAC2) | ||
| 666 | + .setPayload(ipv6); | ||
| 667 | + ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), | ||
| 668 | + portNumber(INPORT)); | ||
| 669 | + return new DefaultInboundPacket(receivedFrom, eth, | ||
| 670 | + ByteBuffer.wrap(eth.serialize())); | ||
| 671 | + } | ||
| 672 | + | ||
| 673 | + @Override | ||
| 674 | + public OutboundPacket outPacket() { | ||
| 675 | + return null; | ||
| 676 | + } | ||
| 677 | + | ||
| 678 | + @Override | ||
| 679 | + public TrafficTreatment.Builder treatmentBuilder() { | ||
| 680 | + return null; | ||
| 681 | + } | ||
| 682 | + | ||
| 683 | + @Override | ||
| 684 | + public void send() { | ||
| 685 | + | ||
| 686 | + } | ||
| 687 | + | ||
| 688 | + @Override | ||
| 689 | + public boolean block() { | ||
| 690 | + return false; | ||
| 691 | + } | ||
| 692 | + | ||
| 693 | + @Override | ||
| 694 | + public boolean isHandled() { | ||
| 695 | + return false; | ||
| 696 | + } | ||
| 697 | + } | ||
| 698 | + | ||
| 699 | + /** | ||
| 700 | + * Generates Duplicate Address Detection packet. | ||
| 701 | + */ | ||
| 702 | + private class TestDADPacketContext implements PacketContext { | ||
| 703 | + private final String deviceId; | ||
| 704 | + | ||
| 705 | + public TestDADPacketContext(String deviceId) { | ||
| 706 | + this.deviceId = deviceId; | ||
| 707 | + } | ||
| 708 | + | ||
| 709 | + @Override | ||
| 710 | + public long time() { | ||
| 711 | + return 0; | ||
| 712 | + } | ||
| 713 | + | ||
| 714 | + @Override | ||
| 715 | + public InboundPacket inPacket() { | ||
| 716 | + NeighborSolicitation ns = new NeighborSolicitation(); | ||
| 717 | + ICMP6 icmp6 = new ICMP6(); | ||
| 718 | + icmp6.setPayload(ns); | ||
| 719 | + IPv6 ipv6 = new IPv6(); | ||
| 720 | + ipv6.setPayload(icmp6); | ||
| 721 | + ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets()); | ||
| 722 | + ipv6.setSourceAddress(Ip6Address.valueOf("::").toOctets()); | ||
| 723 | + Ethernet eth = new Ethernet(); | ||
| 724 | + eth.setEtherType(Ethernet.TYPE_IPV6) | ||
| 725 | + .setVlanID(VLAN.toShort()) | ||
| 726 | + .setSourceMACAddress(MAC2.toBytes()) | ||
| 727 | + .setDestinationMACAddress(BCMAC2) | ||
| 728 | + .setPayload(ipv6); | ||
| 729 | + ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), | ||
| 730 | + portNumber(INPORT)); | ||
| 731 | + return new DefaultInboundPacket(receivedFrom, eth, | ||
| 732 | + ByteBuffer.wrap(eth.serialize())); | ||
| 733 | + } | ||
| 734 | + | ||
| 735 | + @Override | ||
| 736 | + public OutboundPacket outPacket() { | ||
| 737 | + return null; | ||
| 738 | + } | ||
| 739 | + | ||
| 740 | + @Override | ||
| 741 | + public TrafficTreatment.Builder treatmentBuilder() { | ||
| 742 | + return null; | ||
| 743 | + } | ||
| 744 | + | ||
| 745 | + @Override | ||
| 746 | + public void send() { | ||
| 747 | + | ||
| 748 | + } | ||
| 749 | + | ||
| 750 | + @Override | ||
| 751 | + public boolean block() { | ||
| 752 | + return false; | ||
| 753 | + } | ||
| 754 | + | ||
| 755 | + @Override | ||
| 756 | + public boolean isHandled() { | ||
| 757 | + return false; | ||
| 758 | + } | ||
| 759 | + } | ||
| 760 | + | ||
| 761 | + /** | ||
| 762 | + * Generates Router Solicitation packet. | ||
| 763 | + */ | ||
| 764 | + private class TestRSPacketContext implements PacketContext { | ||
| 765 | + private final String deviceId; | ||
| 766 | + | ||
| 767 | + public TestRSPacketContext(String deviceId) { | ||
| 768 | + this.deviceId = deviceId; | ||
| 769 | + } | ||
| 770 | + | ||
| 771 | + @Override | ||
| 772 | + public long time() { | ||
| 773 | + return 0; | ||
| 774 | + } | ||
| 775 | + | ||
| 776 | + @Override | ||
| 777 | + public InboundPacket inPacket() { | ||
| 778 | + RouterSolicitation ns = new RouterSolicitation(); | ||
| 779 | + ICMP6 icmp6 = new ICMP6(); | ||
| 780 | + icmp6.setPayload(ns); | ||
| 781 | + IPv6 ipv6 = new IPv6(); | ||
| 782 | + ipv6.setPayload(icmp6); | ||
| 783 | + ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::2").toOctets()); | ||
| 784 | + ipv6.setSourceAddress(Ip6Address.valueOf("::").toOctets()); | ||
| 785 | + Ethernet eth = new Ethernet(); | ||
| 786 | + eth.setEtherType(Ethernet.TYPE_IPV6) | ||
| 787 | + .setVlanID(VLAN.toShort()) | ||
| 788 | + .setSourceMACAddress(MAC2.toBytes()) | ||
| 789 | + .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:02")) | ||
| 790 | + .setPayload(ipv6); | ||
| 791 | + ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), | ||
| 792 | + portNumber(INPORT)); | ||
| 793 | + return new DefaultInboundPacket(receivedFrom, eth, | ||
| 794 | + ByteBuffer.wrap(eth.serialize())); | ||
| 795 | + } | ||
| 796 | + | ||
| 797 | + @Override | ||
| 798 | + public OutboundPacket outPacket() { | ||
| 799 | + return null; | ||
| 800 | + } | ||
| 801 | + | ||
| 802 | + @Override | ||
| 803 | + public TrafficTreatment.Builder treatmentBuilder() { | ||
| 804 | + return null; | ||
| 805 | + } | ||
| 806 | + | ||
| 807 | + @Override | ||
| 808 | + public void send() { | ||
| 809 | + | ||
| 810 | + } | ||
| 811 | + | ||
| 812 | + @Override | ||
| 813 | + public boolean block() { | ||
| 814 | + return false; | ||
| 815 | + } | ||
| 816 | + | ||
| 817 | + @Override | ||
| 818 | + public boolean isHandled() { | ||
| 819 | + return false; | ||
| 820 | + } | ||
| 821 | + } | ||
| 822 | + | ||
| 823 | + /** | ||
| 824 | + * Generates Router Advertisement packet. | ||
| 825 | + */ | ||
| 826 | + private class TestRAPacketContext implements PacketContext { | ||
| 827 | + private final String deviceId; | ||
| 828 | + | ||
| 829 | + public TestRAPacketContext(String deviceId) { | ||
| 830 | + this.deviceId = deviceId; | ||
| 831 | + } | ||
| 832 | + | ||
| 833 | + @Override | ||
| 834 | + public long time() { | ||
| 835 | + return 0; | ||
| 836 | + } | ||
| 837 | + | ||
| 838 | + @Override | ||
| 839 | + public InboundPacket inPacket() { | ||
| 840 | + RouterAdvertisement ns = new RouterAdvertisement(); | ||
| 841 | + ICMP6 icmp6 = new ICMP6(); | ||
| 842 | + icmp6.setPayload(ns); | ||
| 843 | + IPv6 ipv6 = new IPv6(); | ||
| 844 | + ipv6.setPayload(icmp6); | ||
| 845 | + ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets()); | ||
| 846 | + ipv6.setSourceAddress(IP2); | ||
| 847 | + Ethernet eth = new Ethernet(); | ||
| 848 | + eth.setEtherType(Ethernet.TYPE_IPV6) | ||
| 849 | + .setVlanID(VLAN.toShort()) | ||
| 850 | + .setSourceMACAddress(MAC2.toBytes()) | ||
| 851 | + .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:01")) | ||
| 852 | + .setPayload(ipv6); | ||
| 853 | + ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), | ||
| 854 | + portNumber(INPORT)); | ||
| 855 | + return new DefaultInboundPacket(receivedFrom, eth, | ||
| 856 | + ByteBuffer.wrap(eth.serialize())); | ||
| 857 | + } | ||
| 858 | + | ||
| 859 | + @Override | ||
| 860 | + public OutboundPacket outPacket() { | ||
| 861 | + return null; | ||
| 862 | + } | ||
| 863 | + | ||
| 864 | + @Override | ||
| 865 | + public TrafficTreatment.Builder treatmentBuilder() { | ||
| 866 | + return null; | ||
| 867 | + } | ||
| 868 | + | ||
| 869 | + @Override | ||
| 870 | + public void send() { | ||
| 871 | + | ||
| 872 | + } | ||
| 873 | + | ||
| 874 | + @Override | ||
| 875 | + public boolean block() { | ||
| 876 | + return false; | ||
| 877 | + } | ||
| 878 | + | ||
| 879 | + @Override | ||
| 880 | + public boolean isHandled() { | ||
| 881 | + return false; | ||
| 882 | + } | ||
| 883 | + } | ||
| 884 | + | ||
| 885 | + /** | ||
| 886 | + * Generates IPv6 Multicast packet. | ||
| 887 | + */ | ||
| 888 | + private class TestIpv6McastPacketContext implements PacketContext { | ||
| 889 | + private final String deviceId; | ||
| 890 | + | ||
| 891 | + public TestIpv6McastPacketContext(String deviceId) { | ||
| 892 | + this.deviceId = deviceId; | ||
| 893 | + } | ||
| 894 | + | ||
| 895 | + @Override | ||
| 896 | + public long time() { | ||
| 897 | + return 0; | ||
| 898 | + } | ||
| 899 | + | ||
| 900 | + @Override | ||
| 901 | + public InboundPacket inPacket() { | ||
| 902 | + IPv6 ipv6 = new IPv6(); | ||
| 903 | + ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets()); | ||
| 904 | + ipv6.setSourceAddress(IP2); | ||
| 905 | + Ethernet eth = new Ethernet(); | ||
| 906 | + eth.setEtherType(Ethernet.TYPE_IPV6) | ||
| 907 | + .setVlanID(VLAN.toShort()) | ||
| 908 | + .setSourceMACAddress(MAC2.toBytes()) | ||
| 909 | + .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:01")) | ||
| 910 | + .setPayload(ipv6); | ||
| 911 | + ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), | ||
| 912 | + portNumber(INPORT)); | ||
| 913 | + return new DefaultInboundPacket(receivedFrom, eth, | ||
| 914 | + ByteBuffer.wrap(eth.serialize())); | ||
| 915 | + } | ||
| 916 | + | ||
| 917 | + @Override | ||
| 918 | + public OutboundPacket outPacket() { | ||
| 919 | + return null; | ||
| 920 | + } | ||
| 921 | + | ||
| 922 | + @Override | ||
| 923 | + public TrafficTreatment.Builder treatmentBuilder() { | ||
| 924 | + return null; | ||
| 925 | + } | ||
| 926 | + | ||
| 927 | + @Override | ||
| 928 | + public void send() { | ||
| 929 | + | ||
| 930 | + } | ||
| 931 | + | ||
| 932 | + @Override | ||
| 933 | + public boolean block() { | ||
| 934 | + return false; | ||
| 935 | + } | ||
| 936 | + | ||
| 937 | + @Override | ||
| 938 | + public boolean isHandled() { | ||
| 939 | + return false; | ||
| 940 | + } | ||
| 941 | + } | ||
| 942 | + | ||
| 943 | + /** | ||
| 944 | + * Generates IPv6 Unicast packet. | ||
| 945 | + */ | ||
| 946 | + private class TestIpv6PacketContext implements PacketContext { | ||
| 947 | + private final String deviceId; | ||
| 948 | + | ||
| 949 | + public TestIpv6PacketContext(String deviceId) { | ||
| 950 | + this.deviceId = deviceId; | ||
| 951 | + } | ||
| 952 | + | ||
| 953 | + @Override | ||
| 954 | + public long time() { | ||
| 955 | + return 0; | ||
| 956 | + } | ||
| 957 | + | ||
| 958 | + @Override | ||
| 959 | + public InboundPacket inPacket() { | ||
| 960 | + IPv6 ipv6 = new IPv6(); | ||
| 961 | + ipv6.setDestinationAddress(Ip6Address.valueOf("1000::1").toOctets()); | ||
| 962 | + ipv6.setSourceAddress(IP2); | ||
| 963 | + Ethernet eth = new Ethernet(); | ||
| 964 | + eth.setEtherType(Ethernet.TYPE_IPV6) | ||
| 965 | + .setVlanID(VLAN.toShort()) | ||
| 966 | + .setSourceMACAddress(MAC2) | ||
| 967 | + .setDestinationMACAddress(MacAddress.valueOf("00:00:00:00:00:01")) | ||
| 968 | + .setPayload(ipv6); | ||
| 969 | + ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), | ||
| 970 | + portNumber(INPORT)); | ||
| 971 | + return new DefaultInboundPacket(receivedFrom, eth, | ||
| 972 | + ByteBuffer.wrap(eth.serialize())); | ||
| 973 | + } | ||
| 974 | + | ||
| 975 | + @Override | ||
| 976 | + public OutboundPacket outPacket() { | ||
| 977 | + return null; | ||
| 978 | + } | ||
| 979 | + | ||
| 980 | + @Override | ||
| 981 | + public TrafficTreatment.Builder treatmentBuilder() { | ||
| 982 | + return null; | ||
| 983 | + } | ||
| 984 | + | ||
| 985 | + @Override | ||
| 986 | + public void send() { | ||
| 987 | + | ||
| 988 | + } | ||
| 989 | + | ||
| 990 | + @Override | ||
| 991 | + public boolean block() { | ||
| 992 | + return false; | ||
| 993 | + } | ||
| 994 | + | ||
| 995 | + @Override | ||
| 996 | + public boolean isHandled() { | ||
| 997 | + return false; | ||
| 998 | + } | ||
| 999 | + } | ||
| 1000 | + | ||
| 347 | private class TestDeviceService extends DeviceServiceAdapter { | 1001 | private class TestDeviceService extends DeviceServiceAdapter { |
| 348 | private DeviceListener listener; | 1002 | private DeviceListener listener; |
| 349 | 1003 | ||
| ... | @@ -361,12 +1015,26 @@ public class HostLocationProviderTest { | ... | @@ -361,12 +1015,26 @@ public class HostLocationProviderTest { |
| 361 | private class TestHostService extends HostServiceAdapter { | 1015 | private class TestHostService extends HostServiceAdapter { |
| 362 | @Override | 1016 | @Override |
| 363 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { | 1017 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { |
| 364 | - return ImmutableSet.of(HOST); | 1018 | + ConnectPoint cp1 = new ConnectPoint(deviceId(DEV1), portNumber(INPORT)); |
| 1019 | + ConnectPoint cp2 = new ConnectPoint(deviceId(DEV4), portNumber(INPORT)); | ||
| 1020 | + if (connectPoint.equals(cp1)) { | ||
| 1021 | + return ImmutableSet.of(HOST); | ||
| 1022 | + } else if (connectPoint.equals(cp2)) { | ||
| 1023 | + return ImmutableSet.of(HOST2); | ||
| 1024 | + } else { | ||
| 1025 | + return ImmutableSet.of(); | ||
| 1026 | + } | ||
| 365 | } | 1027 | } |
| 366 | 1028 | ||
| 367 | @Override | 1029 | @Override |
| 368 | public Set<Host> getConnectedHosts(DeviceId deviceId) { | 1030 | public Set<Host> getConnectedHosts(DeviceId deviceId) { |
| 369 | - return ImmutableSet.of(HOST); | 1031 | + if (deviceId.equals(deviceId(DEV1))) { |
| 1032 | + return ImmutableSet.of(HOST); | ||
| 1033 | + } else if (deviceId.equals(deviceId(DEV4))) { | ||
| 1034 | + return ImmutableSet.of(HOST2); | ||
| 1035 | + } else { | ||
| 1036 | + return ImmutableSet.of(); | ||
| 1037 | + } | ||
| 370 | } | 1038 | } |
| 371 | 1039 | ||
| 372 | } | 1040 | } | ... | ... |
-
Please register or login to post a comment