Committed by
Gerrit Code Review
ONOS-2309: Add check in HostMonitor to make sure we only send out edge ports
Change-Id: Id128319163786487c5b545fbc51e47097edfe0ab
Showing
3 changed files
with
36 additions
and
5 deletions
... | @@ -25,6 +25,7 @@ import org.onlab.packet.IpAddress; | ... | @@ -25,6 +25,7 @@ import org.onlab.packet.IpAddress; |
25 | import org.onlab.packet.MacAddress; | 25 | import org.onlab.packet.MacAddress; |
26 | import org.onlab.packet.VlanId; | 26 | import org.onlab.packet.VlanId; |
27 | import org.onosproject.incubator.net.intf.InterfaceService; | 27 | import org.onosproject.incubator.net.intf.InterfaceService; |
28 | +import org.onosproject.net.edge.EdgePortService; | ||
28 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; | 29 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
29 | import org.onosproject.net.config.NetworkConfigEvent; | 30 | import org.onosproject.net.config.NetworkConfigEvent; |
30 | import org.onosproject.net.config.NetworkConfigListener; | 31 | import org.onosproject.net.config.NetworkConfigListener; |
... | @@ -90,6 +91,9 @@ public class HostManager | ... | @@ -90,6 +91,9 @@ public class HostManager |
90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
91 | protected InterfaceService interfaceService; | 92 | protected InterfaceService interfaceService; |
92 | 93 | ||
94 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
95 | + protected EdgePortService edgePortService; | ||
96 | + | ||
93 | private HostMonitor monitor; | 97 | private HostMonitor monitor; |
94 | 98 | ||
95 | @Activate | 99 | @Activate |
... | @@ -97,7 +101,7 @@ public class HostManager | ... | @@ -97,7 +101,7 @@ public class HostManager |
97 | store.setDelegate(delegate); | 101 | store.setDelegate(delegate); |
98 | eventDispatcher.addSink(HostEvent.class, listenerRegistry); | 102 | eventDispatcher.addSink(HostEvent.class, listenerRegistry); |
99 | networkConfigService.addListener(networkConfigListener); | 103 | networkConfigService.addListener(networkConfigListener); |
100 | - monitor = new HostMonitor(packetService, this, interfaceService); | 104 | + monitor = new HostMonitor(packetService, this, interfaceService, edgePortService); |
101 | monitor.start(); | 105 | monitor.start(); |
102 | log.info("Started"); | 106 | log.info("Started"); |
103 | } | 107 | } | ... | ... |
... | @@ -31,6 +31,7 @@ import org.onosproject.incubator.net.intf.Interface; | ... | @@ -31,6 +31,7 @@ import org.onosproject.incubator.net.intf.Interface; |
31 | import org.onosproject.incubator.net.intf.InterfaceService; | 31 | import org.onosproject.incubator.net.intf.InterfaceService; |
32 | import org.onosproject.net.ConnectPoint; | 32 | import org.onosproject.net.ConnectPoint; |
33 | import org.onosproject.net.Host; | 33 | import org.onosproject.net.Host; |
34 | +import org.onosproject.net.edge.EdgePortService; | ||
34 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
35 | import org.onosproject.net.flow.TrafficTreatment; | 36 | import org.onosproject.net.flow.TrafficTreatment; |
36 | import org.onosproject.net.host.HostProvider; | 37 | import org.onosproject.net.host.HostProvider; |
... | @@ -39,6 +40,8 @@ import org.onosproject.net.packet.DefaultOutboundPacket; | ... | @@ -39,6 +40,8 @@ import org.onosproject.net.packet.DefaultOutboundPacket; |
39 | import org.onosproject.net.packet.OutboundPacket; | 40 | import org.onosproject.net.packet.OutboundPacket; |
40 | import org.onosproject.net.packet.PacketService; | 41 | import org.onosproject.net.packet.PacketService; |
41 | import org.onosproject.net.provider.ProviderId; | 42 | import org.onosproject.net.provider.ProviderId; |
43 | +import org.slf4j.Logger; | ||
44 | +import org.slf4j.LoggerFactory; | ||
42 | 45 | ||
43 | import java.nio.ByteBuffer; | 46 | import java.nio.ByteBuffer; |
44 | import java.util.Collections; | 47 | import java.util.Collections; |
... | @@ -56,9 +59,13 @@ import java.util.concurrent.TimeUnit; | ... | @@ -56,9 +59,13 @@ import java.util.concurrent.TimeUnit; |
56 | * </p> | 59 | * </p> |
57 | */ | 60 | */ |
58 | public class HostMonitor implements TimerTask { | 61 | public class HostMonitor implements TimerTask { |
62 | + | ||
63 | + private Logger log = LoggerFactory.getLogger(getClass()); | ||
64 | + | ||
59 | private PacketService packetService; | 65 | private PacketService packetService; |
60 | private HostManager hostManager; | 66 | private HostManager hostManager; |
61 | private InterfaceService interfaceService; | 67 | private InterfaceService interfaceService; |
68 | + private EdgePortService edgePortService; | ||
62 | 69 | ||
63 | private final Set<IpAddress> monitoredAddresses; | 70 | private final Set<IpAddress> monitoredAddresses; |
64 | 71 | ||
... | @@ -79,11 +86,13 @@ public class HostMonitor implements TimerTask { | ... | @@ -79,11 +86,13 @@ public class HostMonitor implements TimerTask { |
79 | * @param interfaceService interface service for interface information | 86 | * @param interfaceService interface service for interface information |
80 | */ | 87 | */ |
81 | public HostMonitor(PacketService packetService, HostManager hostManager, | 88 | public HostMonitor(PacketService packetService, HostManager hostManager, |
82 | - InterfaceService interfaceService) { | 89 | + InterfaceService interfaceService, |
90 | + EdgePortService edgePortService) { | ||
83 | 91 | ||
84 | this.packetService = packetService; | 92 | this.packetService = packetService; |
85 | this.hostManager = hostManager; | 93 | this.hostManager = hostManager; |
86 | this.interfaceService = interfaceService; | 94 | this.interfaceService = interfaceService; |
95 | + this.edgePortService = edgePortService; | ||
87 | 96 | ||
88 | monitoredAddresses = Collections.newSetFromMap(new ConcurrentHashMap<>()); | 97 | monitoredAddresses = Collections.newSetFromMap(new ConcurrentHashMap<>()); |
89 | hostProviders = new ConcurrentHashMap<>(); | 98 | hostProviders = new ConcurrentHashMap<>(); |
... | @@ -173,6 +182,11 @@ public class HostMonitor implements TimerTask { | ... | @@ -173,6 +182,11 @@ public class HostMonitor implements TimerTask { |
173 | return; | 182 | return; |
174 | } | 183 | } |
175 | 184 | ||
185 | + if (!edgePortService.isEdgePoint(intf.connectPoint())) { | ||
186 | + log.warn("Attempt to send probe out non-edge port: {}", intf); | ||
187 | + return; | ||
188 | + } | ||
189 | + | ||
176 | for (InterfaceIpAddress ia : intf.ipAddresses()) { | 190 | for (InterfaceIpAddress ia : intf.ipAddresses()) { |
177 | if (ia.subnetAddress().contains(targetIp)) { | 191 | if (ia.subnetAddress().contains(targetIp)) { |
178 | sendProbe(intf.connectPoint(), targetIp, ia.ipAddress(), | 192 | sendProbe(intf.connectPoint(), targetIp, ia.ipAddress(), | ... | ... |
... | @@ -19,6 +19,7 @@ import com.google.common.collect.HashMultimap; | ... | @@ -19,6 +19,7 @@ import com.google.common.collect.HashMultimap; |
19 | import com.google.common.collect.Lists; | 19 | import com.google.common.collect.Lists; |
20 | import com.google.common.collect.Multimap; | 20 | import com.google.common.collect.Multimap; |
21 | import org.junit.After; | 21 | import org.junit.After; |
22 | +import org.junit.Before; | ||
22 | import org.junit.Test; | 23 | import org.junit.Test; |
23 | import org.onlab.packet.ARP; | 24 | import org.onlab.packet.ARP; |
24 | import org.onlab.packet.Ethernet; | 25 | import org.onlab.packet.Ethernet; |
... | @@ -37,6 +38,7 @@ import org.onosproject.net.Port; | ... | @@ -37,6 +38,7 @@ import org.onosproject.net.Port; |
37 | import org.onosproject.net.PortNumber; | 38 | import org.onosproject.net.PortNumber; |
38 | import org.onosproject.net.device.DeviceListener; | 39 | import org.onosproject.net.device.DeviceListener; |
39 | import org.onosproject.net.device.DeviceServiceAdapter; | 40 | import org.onosproject.net.device.DeviceServiceAdapter; |
41 | +import org.onosproject.net.edge.EdgePortService; | ||
40 | import org.onosproject.net.flow.instructions.Instruction; | 42 | import org.onosproject.net.flow.instructions.Instruction; |
41 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | 43 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
42 | import org.onosproject.net.host.HostProvider; | 44 | import org.onosproject.net.host.HostProvider; |
... | @@ -51,6 +53,7 @@ import java.util.Collections; | ... | @@ -51,6 +53,7 @@ import java.util.Collections; |
51 | import java.util.List; | 53 | import java.util.List; |
52 | import java.util.Set; | 54 | import java.util.Set; |
53 | 55 | ||
56 | +import static org.easymock.EasyMock.anyObject; | ||
54 | import static org.easymock.EasyMock.createMock; | 57 | import static org.easymock.EasyMock.createMock; |
55 | import static org.easymock.EasyMock.expect; | 58 | import static org.easymock.EasyMock.expect; |
56 | import static org.easymock.EasyMock.expectLastCall; | 59 | import static org.easymock.EasyMock.expectLastCall; |
... | @@ -70,8 +73,18 @@ public class HostMonitorTest { | ... | @@ -70,8 +73,18 @@ public class HostMonitorTest { |
70 | new InterfaceIpAddress(SOURCE_ADDR, IpPrefix.valueOf("10.0.0.0/24")); | 73 | new InterfaceIpAddress(SOURCE_ADDR, IpPrefix.valueOf("10.0.0.0/24")); |
71 | private MacAddress sourceMac = MacAddress.valueOf(1L); | 74 | private MacAddress sourceMac = MacAddress.valueOf(1L); |
72 | 75 | ||
76 | + private EdgePortService edgePortService; | ||
77 | + | ||
73 | private HostMonitor hostMonitor; | 78 | private HostMonitor hostMonitor; |
74 | 79 | ||
80 | + @Before | ||
81 | + public void setUp() { | ||
82 | + edgePortService = createMock(EdgePortService.class); | ||
83 | + expect(edgePortService.isEdgePoint(anyObject(ConnectPoint.class))) | ||
84 | + .andReturn(true).anyTimes(); | ||
85 | + replay(edgePortService); | ||
86 | + } | ||
87 | + | ||
75 | @After | 88 | @After |
76 | public void shutdown() { | 89 | public void shutdown() { |
77 | hostMonitor.shutdown(); | 90 | hostMonitor.shutdown(); |
... | @@ -96,7 +109,7 @@ public class HostMonitorTest { | ... | @@ -96,7 +109,7 @@ public class HostMonitorTest { |
96 | expectLastCall().once(); | 109 | expectLastCall().once(); |
97 | replay(hostProvider); | 110 | replay(hostProvider); |
98 | 111 | ||
99 | - hostMonitor = new HostMonitor(null, hostManager, null); | 112 | + hostMonitor = new HostMonitor(null, hostManager, null, edgePortService); |
100 | 113 | ||
101 | hostMonitor.registerHostProvider(hostProvider); | 114 | hostMonitor.registerHostProvider(hostProvider); |
102 | hostMonitor.addMonitoringFor(TARGET_IP_ADDR); | 115 | hostMonitor.addMonitoringFor(TARGET_IP_ADDR); |
... | @@ -144,7 +157,7 @@ public class HostMonitorTest { | ... | @@ -144,7 +157,7 @@ public class HostMonitorTest { |
144 | 157 | ||
145 | 158 | ||
146 | // Run the test | 159 | // Run the test |
147 | - hostMonitor = new HostMonitor(packetService, hostManager, interfaceService); | 160 | + hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService); |
148 | 161 | ||
149 | hostMonitor.addMonitoringFor(TARGET_IP_ADDR); | 162 | hostMonitor.addMonitoringFor(TARGET_IP_ADDR); |
150 | hostMonitor.run(null); | 163 | hostMonitor.run(null); |
... | @@ -216,7 +229,7 @@ public class HostMonitorTest { | ... | @@ -216,7 +229,7 @@ public class HostMonitorTest { |
216 | 229 | ||
217 | 230 | ||
218 | // Run the test | 231 | // Run the test |
219 | - hostMonitor = new HostMonitor(packetService, hostManager, interfaceService); | 232 | + hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService); |
220 | 233 | ||
221 | hostMonitor.addMonitoringFor(TARGET_IP_ADDR); | 234 | hostMonitor.addMonitoringFor(TARGET_IP_ADDR); |
222 | hostMonitor.run(null); | 235 | hostMonitor.run(null); | ... | ... |
-
Please register or login to post a comment