Avoid probing hosts on non-existent or disabled ports
- All ports that has a subnet configured in netcfg will be used for probing
- A port may not exist on the device even if it's configured in interfces
- A port will never be added to the edge port list if it is never enabled
If a port meets both conditions above, it will fail the isEdgePort check and produce repeating warning messages.
This patch explicitly avoid probing on non-existent or disabled ports
Change-Id: I5cc5f32d4b2ff9fc00729e0adddbede29fb49ca0
(cherry picked from commit a618d74a7596633d666679f709a853d374fe2cb9)
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
index a02159c..adeda77 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
@@ -193,7 +193,7 @@
eventDispatcher.addSink(HostEvent.class, listenerRegistry);
cfgService.registerProperties(getClass());
networkConfigService.addListener(networkConfigListener);
- monitor = new HostMonitor(packetService, this, interfaceService, edgePortService);
+ monitor = new HostMonitor(packetService, this, interfaceService, edgePortService, deviceService);
monitor.setProbeRate(probeRate);
monitor.start();
cfgService.registerProperties(getClass());
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
index ef1c796..8252213 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
@@ -25,6 +25,8 @@
import org.onlab.packet.VlanId;
import org.onlab.packet.ndp.NeighborSolicitation;
import org.onlab.util.SharedScheduledExecutors;
+import org.onosproject.net.Port;
+import org.onosproject.net.device.DeviceService;
import org.onosproject.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Host;
@@ -63,6 +65,7 @@
private HostManager hostManager;
private InterfaceService interfaceService;
private EdgePortService edgePortService;
+ private DeviceService deviceService;
private final Set<IpAddress> monitoredAddresses;
@@ -78,19 +81,21 @@
* Creates a new host monitor.
*
* @param packetService packet service used to send packets on the data plane
- * @param hostManager host manager used to look up host information and
- * probe existing hosts
+ * @param hostManager host manager used to look up host information and probe existing hosts
* @param interfaceService interface service for interface information
* @param edgePortService edge port service
+ * @param deviceService device service
*/
public HostMonitor(PacketService packetService, HostManager hostManager,
InterfaceService interfaceService,
- EdgePortService edgePortService) {
+ EdgePortService edgePortService,
+ DeviceService deviceService) {
this.packetService = packetService;
this.hostManager = hostManager;
this.interfaceService = interfaceService;
this.edgePortService = edgePortService;
+ this.deviceService = deviceService;
monitoredAddresses = Collections.newSetFromMap(new ConcurrentHashMap<>());
hostProviders = new ConcurrentHashMap<>();
@@ -188,8 +193,17 @@
*/
private void sendRequest(IpAddress targetIp) {
interfaceService.getMatchingInterfaces(targetIp).forEach(intf -> {
+ Port port = deviceService.getPort(intf.connectPoint());
+ if (port == null) {
+ log.debug("Aborting probing non-existent port: {}", intf);
+ return;
+ }
+ if (!port.isEnabled()) {
+ log.debug("Aborting probing disabled port: {}", intf);
+ return;
+ }
if (!edgePortService.isEdgePoint(intf.connectPoint())) {
- log.warn("Aborting attempt to send probe out non-edge port: {}", intf);
+ log.warn("Aborting probing non-edge port: {}", intf);
return;
}
diff --git a/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java b/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
index 37ae0d3..d492e39 100644
--- a/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
@@ -126,7 +126,7 @@
expectLastCall().times(2);
replay(hostProvider);
- hostMonitor = new HostMonitor(null, hostManager, null, edgePortService);
+ hostMonitor = new HostMonitor(null, hostManager, null, edgePortService, null);
hostMonitor.registerHostProvider(hostProvider);
hostMonitor.addMonitoringFor(hostIp);
@@ -151,6 +151,7 @@
Port port = createMock(Port.class);
expect(port.number()).andReturn(portNum).anyTimes();
+ expect(port.isEnabled()).andReturn(true).anyTimes();
replay(port);
TestDeviceService deviceService = new TestDeviceService();
@@ -173,7 +174,7 @@
// Run the test
- hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
+ hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR);
hostMonitor.run();
@@ -220,6 +221,7 @@
Port port = createMock(Port.class);
expect(port.number()).andReturn(portNum).anyTimes();
+ expect(port.isEnabled()).andReturn(true).anyTimes();
replay(port);
TestDeviceService deviceService = new TestDeviceService();
@@ -242,7 +244,7 @@
// Run the test
- hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
+ hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR);
hostMonitor.run();
@@ -291,6 +293,7 @@
Port port = createMock(Port.class);
expect(port.number()).andReturn(portNum).anyTimes();
+ expect(port.isEnabled()).andReturn(true).anyTimes();
replay(port);
TestDeviceService deviceService = new TestDeviceService();
@@ -313,7 +316,7 @@
// Run the test
- hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
+ hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR);
hostMonitor.run();
@@ -361,6 +364,7 @@
Port port = createMock(Port.class);
expect(port.number()).andReturn(portNum).anyTimes();
+ expect(port.isEnabled()).andReturn(true).anyTimes();
replay(port);
TestDeviceService deviceService = new TestDeviceService();
@@ -383,7 +387,7 @@
// Run the test
- hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
+ hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR);
hostMonitor.run();
@@ -451,5 +455,12 @@
}
return ports;
}
+
+ @Override
+ public Port getPort(ConnectPoint cp) {
+ return devicePorts.get(cp.deviceId()).stream()
+ .filter(p -> p.number().equals(cp.port()))
+ .findAny().orElse(null);
+ }
}
}