Committed by
Gerrit Code Review
Probe immediately when IPs are added to host monitor
rather than waiting for the next polling cycle. Change-Id: Iffaf50f7a589b52be659b82b8a289e04a5de4ca6
Showing
2 changed files
with
34 additions
and
85 deletions
| ... | @@ -107,6 +107,7 @@ public class HostMonitor implements TimerTask { | ... | @@ -107,6 +107,7 @@ public class HostMonitor implements TimerTask { |
| 107 | */ | 107 | */ |
| 108 | void addMonitoringFor(IpAddress ip) { | 108 | void addMonitoringFor(IpAddress ip) { |
| 109 | monitoredAddresses.add(ip); | 109 | monitoredAddresses.add(ip); |
| 110 | + probe(ip); | ||
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | /** | 113 | /** |
| ... | @@ -151,28 +152,30 @@ public class HostMonitor implements TimerTask { | ... | @@ -151,28 +152,30 @@ public class HostMonitor implements TimerTask { |
| 151 | 152 | ||
| 152 | @Override | 153 | @Override |
| 153 | public void run(Timeout timeout) throws Exception { | 154 | public void run(Timeout timeout) throws Exception { |
| 154 | - for (IpAddress ip : monitoredAddresses) { | 155 | + monitoredAddresses.forEach(this::probe); |
| 155 | - Set<Host> hosts = hostManager.getHostsByIp(ip); | ||
| 156 | - | ||
| 157 | - if (hosts.isEmpty()) { | ||
| 158 | - sendRequest(ip); | ||
| 159 | - } else { | ||
| 160 | - for (Host host : hosts) { | ||
| 161 | - HostProvider provider = hostProviders.get(host.providerId()); | ||
| 162 | - if (provider == null) { | ||
| 163 | - hostProviders.remove(host.providerId(), null); | ||
| 164 | - } else { | ||
| 165 | - provider.triggerProbe(host); | ||
| 166 | - } | ||
| 167 | - } | ||
| 168 | - } | ||
| 169 | - } | ||
| 170 | 156 | ||
| 171 | synchronized (this) { | 157 | synchronized (this) { |
| 172 | this.timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); | 158 | this.timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); |
| 173 | } | 159 | } |
| 174 | } | 160 | } |
| 175 | 161 | ||
| 162 | + private void probe(IpAddress ip) { | ||
| 163 | + Set<Host> hosts = hostManager.getHostsByIp(ip); | ||
| 164 | + | ||
| 165 | + if (hosts.isEmpty()) { | ||
| 166 | + sendRequest(ip); | ||
| 167 | + } else { | ||
| 168 | + for (Host host : hosts) { | ||
| 169 | + HostProvider provider = hostProviders.get(host.providerId()); | ||
| 170 | + if (provider == null) { | ||
| 171 | + hostProviders.remove(host.providerId(), null); | ||
| 172 | + } else { | ||
| 173 | + provider.triggerProbe(host); | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + } | ||
| 177 | + } | ||
| 178 | + | ||
| 176 | /** | 179 | /** |
| 177 | * Sends an ARP or NDP request for the given IP address. | 180 | * Sends an ARP or NDP request for the given IP address. |
| 178 | * | 181 | * | ... | ... |
| ... | @@ -35,10 +35,8 @@ import org.onosproject.net.ConnectPoint; | ... | @@ -35,10 +35,8 @@ import org.onosproject.net.ConnectPoint; |
| 35 | import org.onosproject.net.Device; | 35 | import org.onosproject.net.Device; |
| 36 | import org.onosproject.net.DeviceId; | 36 | import org.onosproject.net.DeviceId; |
| 37 | import org.onosproject.net.Host; | 37 | import org.onosproject.net.Host; |
| 38 | -import org.onosproject.net.MastershipRole; | ||
| 39 | import org.onosproject.net.Port; | 38 | import org.onosproject.net.Port; |
| 40 | import org.onosproject.net.PortNumber; | 39 | import org.onosproject.net.PortNumber; |
| 41 | -import org.onosproject.net.device.DeviceListener; | ||
| 42 | import org.onosproject.net.device.DeviceServiceAdapter; | 40 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 43 | import org.onosproject.net.edge.EdgePortService; | 41 | import org.onosproject.net.edge.EdgePortService; |
| 44 | import org.onosproject.net.flow.instructions.Instruction; | 42 | import org.onosproject.net.flow.instructions.Instruction; |
| ... | @@ -101,56 +99,37 @@ public class HostMonitorTest { | ... | @@ -101,56 +99,37 @@ public class HostMonitorTest { |
| 101 | 99 | ||
| 102 | @Test | 100 | @Test |
| 103 | public void testMonitorIpv4HostExists() throws Exception { | 101 | public void testMonitorIpv4HostExists() throws Exception { |
| 104 | - ProviderId id = new ProviderId("fake://", "id"); | 102 | + testMonitorHostExists(TARGET_IPV4_ADDR); |
| 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 | } | 103 | } |
| 130 | 104 | ||
| 131 | @Test | 105 | @Test |
| 132 | public void testMonitorIpv6HostExists() throws Exception { | 106 | public void testMonitorIpv6HostExists() throws Exception { |
| 107 | + testMonitorHostExists(TARGET_IPV6_ADDR); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + private void testMonitorHostExists(IpAddress hostIp) throws Exception { | ||
| 133 | ProviderId id = new ProviderId("fake://", "id"); | 111 | ProviderId id = new ProviderId("fake://", "id"); |
| 134 | 112 | ||
| 135 | Host host = createMock(Host.class); | 113 | Host host = createMock(Host.class); |
| 136 | - expect(host.providerId()).andReturn(id); | 114 | + expect(host.providerId()).andReturn(id).anyTimes(); |
| 137 | replay(host); | 115 | replay(host); |
| 138 | 116 | ||
| 139 | HostManager hostManager = createMock(HostManager.class); | 117 | HostManager hostManager = createMock(HostManager.class); |
| 140 | - expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR)) | 118 | + expect(hostManager.getHostsByIp(hostIp)) |
| 141 | - .andReturn(Collections.singleton(host)); | 119 | + .andReturn(Collections.singleton(host)) |
| 120 | + .anyTimes(); | ||
| 142 | replay(hostManager); | 121 | replay(hostManager); |
| 143 | 122 | ||
| 144 | HostProvider hostProvider = createMock(HostProvider.class); | 123 | HostProvider hostProvider = createMock(HostProvider.class); |
| 145 | expect(hostProvider.id()).andReturn(id).anyTimes(); | 124 | expect(hostProvider.id()).andReturn(id).anyTimes(); |
| 146 | hostProvider.triggerProbe(host); | 125 | hostProvider.triggerProbe(host); |
| 147 | - expectLastCall().once(); | 126 | + expectLastCall().times(2); |
| 148 | replay(hostProvider); | 127 | replay(hostProvider); |
| 149 | 128 | ||
| 150 | hostMonitor = new HostMonitor(null, hostManager, null, edgePortService); | 129 | hostMonitor = new HostMonitor(null, hostManager, null, edgePortService); |
| 151 | 130 | ||
| 152 | hostMonitor.registerHostProvider(hostProvider); | 131 | hostMonitor.registerHostProvider(hostProvider); |
| 153 | - hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR); | 132 | + hostMonitor.addMonitoringFor(hostIp); |
| 154 | 133 | ||
| 155 | hostMonitor.run(null); | 134 | hostMonitor.run(null); |
| 156 | 135 | ||
| ... | @@ -202,7 +181,7 @@ public class HostMonitorTest { | ... | @@ -202,7 +181,7 @@ public class HostMonitorTest { |
| 202 | 181 | ||
| 203 | // Check that a packet was sent to our PacketService and that it has | 182 | // Check that a packet was sent to our PacketService and that it has |
| 204 | // the properties we expect | 183 | // the properties we expect |
| 205 | - assertEquals(1, packetService.packets.size()); | 184 | + assertEquals(2, packetService.packets.size()); |
| 206 | OutboundPacket packet = packetService.packets.get(0); | 185 | OutboundPacket packet = packetService.packets.get(0); |
| 207 | 186 | ||
| 208 | // Check the output port is correct | 187 | // Check the output port is correct |
| ... | @@ -271,7 +250,7 @@ public class HostMonitorTest { | ... | @@ -271,7 +250,7 @@ public class HostMonitorTest { |
| 271 | 250 | ||
| 272 | // Check that a packet was sent to our PacketService and that it has | 251 | // Check that a packet was sent to our PacketService and that it has |
| 273 | // the properties we expect | 252 | // the properties we expect |
| 274 | - assertEquals(1, packetService.packets.size()); | 253 | + assertEquals(2, packetService.packets.size()); |
| 275 | OutboundPacket packet = packetService.packets.get(0); | 254 | OutboundPacket packet = packetService.packets.get(0); |
| 276 | 255 | ||
| 277 | // Check the output port is correct | 256 | // Check the output port is correct |
| ... | @@ -342,7 +321,7 @@ public class HostMonitorTest { | ... | @@ -342,7 +321,7 @@ public class HostMonitorTest { |
| 342 | 321 | ||
| 343 | // Check that a packet was sent to our PacketService and that it has | 322 | // Check that a packet was sent to our PacketService and that it has |
| 344 | // the properties we expect | 323 | // the properties we expect |
| 345 | - assertEquals(1, packetService.packets.size()); | 324 | + assertEquals(2, packetService.packets.size()); |
| 346 | OutboundPacket packet = packetService.packets.get(0); | 325 | OutboundPacket packet = packetService.packets.get(0); |
| 347 | 326 | ||
| 348 | // Check the output port is correct | 327 | // Check the output port is correct |
| ... | @@ -412,7 +391,7 @@ public class HostMonitorTest { | ... | @@ -412,7 +391,7 @@ public class HostMonitorTest { |
| 412 | 391 | ||
| 413 | // Check that a packet was sent to our PacketService and that it has | 392 | // Check that a packet was sent to our PacketService and that it has |
| 414 | // the properties we expect | 393 | // the properties we expect |
| 415 | - assertEquals(1, packetService.packets.size()); | 394 | + assertEquals(2, packetService.packets.size()); |
| 416 | OutboundPacket packet = packetService.packets.get(0); | 395 | OutboundPacket packet = packetService.packets.get(0); |
| 417 | 396 | ||
| 418 | // Check the output port is correct | 397 | // Check the output port is correct |
| ... | @@ -460,26 +439,11 @@ public class HostMonitorTest { | ... | @@ -460,26 +439,11 @@ public class HostMonitorTest { |
| 460 | } | 439 | } |
| 461 | 440 | ||
| 462 | @Override | 441 | @Override |
| 463 | - public int getDeviceCount() { | ||
| 464 | - return 0; | ||
| 465 | - } | ||
| 466 | - | ||
| 467 | - @Override | ||
| 468 | public Iterable<Device> getDevices() { | 442 | public Iterable<Device> getDevices() { |
| 469 | return devices; | 443 | return devices; |
| 470 | } | 444 | } |
| 471 | 445 | ||
| 472 | @Override | 446 | @Override |
| 473 | - public Device getDevice(DeviceId deviceId) { | ||
| 474 | - return null; | ||
| 475 | - } | ||
| 476 | - | ||
| 477 | - @Override | ||
| 478 | - public MastershipRole getRole(DeviceId deviceId) { | ||
| 479 | - return null; | ||
| 480 | - } | ||
| 481 | - | ||
| 482 | - @Override | ||
| 483 | public List<Port> getPorts(DeviceId deviceId) { | 447 | public List<Port> getPorts(DeviceId deviceId) { |
| 484 | List<Port> ports = Lists.newArrayList(); | 448 | List<Port> ports = Lists.newArrayList(); |
| 485 | for (Port p : devicePorts.get(deviceId)) { | 449 | for (Port p : devicePorts.get(deviceId)) { |
| ... | @@ -487,23 +451,5 @@ public class HostMonitorTest { | ... | @@ -487,23 +451,5 @@ public class HostMonitorTest { |
| 487 | } | 451 | } |
| 488 | return ports; | 452 | return ports; |
| 489 | } | 453 | } |
| 490 | - | ||
| 491 | - @Override | ||
| 492 | - public Port getPort(DeviceId deviceId, PortNumber portNumber) { | ||
| 493 | - return null; | ||
| 494 | - } | ||
| 495 | - | ||
| 496 | - @Override | ||
| 497 | - public boolean isAvailable(DeviceId deviceId) { | ||
| 498 | - return false; | ||
| 499 | - } | ||
| 500 | - | ||
| 501 | - @Override | ||
| 502 | - public void addListener(DeviceListener listener) { | ||
| 503 | - } | ||
| 504 | - | ||
| 505 | - @Override | ||
| 506 | - public void removeListener(DeviceListener listener) { | ||
| 507 | - } | ||
| 508 | } | 454 | } |
| 509 | } | 455 | } | ... | ... |
-
Please register or login to post a comment