Jonathan Hart
Committed by Gerrit Code Review

ONOS-2309: Add check in HostMonitor to make sure we only send out edge ports

Change-Id: Id128319163786487c5b545fbc51e47097edfe0ab
......@@ -25,6 +25,7 @@ import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.edge.EdgePortService;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
......@@ -90,6 +91,9 @@ public class HostManager
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected InterfaceService interfaceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EdgePortService edgePortService;
private HostMonitor monitor;
@Activate
......@@ -97,7 +101,7 @@ public class HostManager
store.setDelegate(delegate);
eventDispatcher.addSink(HostEvent.class, listenerRegistry);
networkConfigService.addListener(networkConfigListener);
monitor = new HostMonitor(packetService, this, interfaceService);
monitor = new HostMonitor(packetService, this, interfaceService, edgePortService);
monitor.start();
log.info("Started");
}
......
......@@ -31,6 +31,7 @@ import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Host;
import org.onosproject.net.edge.EdgePortService;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.host.HostProvider;
......@@ -39,6 +40,8 @@ import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.ProviderId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.util.Collections;
......@@ -56,9 +59,13 @@ import java.util.concurrent.TimeUnit;
* </p>
*/
public class HostMonitor implements TimerTask {
private Logger log = LoggerFactory.getLogger(getClass());
private PacketService packetService;
private HostManager hostManager;
private InterfaceService interfaceService;
private EdgePortService edgePortService;
private final Set<IpAddress> monitoredAddresses;
......@@ -79,11 +86,13 @@ public class HostMonitor implements TimerTask {
* @param interfaceService interface service for interface information
*/
public HostMonitor(PacketService packetService, HostManager hostManager,
InterfaceService interfaceService) {
InterfaceService interfaceService,
EdgePortService edgePortService) {
this.packetService = packetService;
this.hostManager = hostManager;
this.interfaceService = interfaceService;
this.edgePortService = edgePortService;
monitoredAddresses = Collections.newSetFromMap(new ConcurrentHashMap<>());
hostProviders = new ConcurrentHashMap<>();
......@@ -173,6 +182,11 @@ public class HostMonitor implements TimerTask {
return;
}
if (!edgePortService.isEdgePoint(intf.connectPoint())) {
log.warn("Attempt to send probe out non-edge port: {}", intf);
return;
}
for (InterfaceIpAddress ia : intf.ipAddresses()) {
if (ia.subnetAddress().contains(targetIp)) {
sendProbe(intf.connectPoint(), targetIp, ia.ipAddress(),
......
......@@ -19,6 +19,7 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
......@@ -37,6 +38,7 @@ import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.edge.EdgePortService;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
import org.onosproject.net.host.HostProvider;
......@@ -51,6 +53,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
......@@ -70,8 +73,18 @@ public class HostMonitorTest {
new InterfaceIpAddress(SOURCE_ADDR, IpPrefix.valueOf("10.0.0.0/24"));
private MacAddress sourceMac = MacAddress.valueOf(1L);
private EdgePortService edgePortService;
private HostMonitor hostMonitor;
@Before
public void setUp() {
edgePortService = createMock(EdgePortService.class);
expect(edgePortService.isEdgePoint(anyObject(ConnectPoint.class)))
.andReturn(true).anyTimes();
replay(edgePortService);
}
@After
public void shutdown() {
hostMonitor.shutdown();
......@@ -96,7 +109,7 @@ public class HostMonitorTest {
expectLastCall().once();
replay(hostProvider);
hostMonitor = new HostMonitor(null, hostManager, null);
hostMonitor = new HostMonitor(null, hostManager, null, edgePortService);
hostMonitor.registerHostProvider(hostProvider);
hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
......@@ -144,7 +157,7 @@ public class HostMonitorTest {
// Run the test
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService);
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
hostMonitor.run(null);
......@@ -216,7 +229,7 @@ public class HostMonitorTest {
// Run the test
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService);
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
hostMonitor.run(null);
......