aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java')
-rw-r--r--framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java214
1 files changed, 196 insertions, 18 deletions
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
index d167197a..3cd2ca2b 100644
--- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
+++ b/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
@@ -23,10 +23,12 @@ import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
+import org.onlab.packet.IPv6;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
+import org.onlab.packet.ndp.NeighborSolicitation;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
@@ -64,14 +66,22 @@ import static org.junit.Assert.assertTrue;
public class HostMonitorTest {
- private static final IpAddress TARGET_IP_ADDR =
+ private static final IpAddress TARGET_IPV4_ADDR =
IpAddress.valueOf("10.0.0.1");
- private static final IpAddress SOURCE_ADDR =
+ private static final IpAddress SOURCE_IPV4_ADDR =
IpAddress.valueOf("10.0.0.99");
private static final InterfaceIpAddress IA1 =
- new InterfaceIpAddress(SOURCE_ADDR, IpPrefix.valueOf("10.0.0.0/24"));
+ new InterfaceIpAddress(SOURCE_IPV4_ADDR, IpPrefix.valueOf("10.0.0.0/24"));
private MacAddress sourceMac = MacAddress.valueOf(1L);
+ private static final IpAddress TARGET_IPV6_ADDR =
+ IpAddress.valueOf("1000::1");
+ private static final IpAddress SOURCE_IPV6_ADDR =
+ IpAddress.valueOf("1000::f");
+ private static final InterfaceIpAddress IA2 =
+ new InterfaceIpAddress(SOURCE_IPV6_ADDR, IpPrefix.valueOf("1000::/64"));
+ private MacAddress sourceMac2 = MacAddress.valueOf(2L);
+
private EdgePortService edgePortService;
private HostMonitor hostMonitor;
@@ -90,7 +100,36 @@ public class HostMonitorTest {
}
@Test
- public void testMonitorHostExists() throws Exception {
+ public void testMonitorIpv4HostExists() throws Exception {
+ ProviderId id = new ProviderId("fake://", "id");
+
+ Host host = createMock(Host.class);
+ expect(host.providerId()).andReturn(id);
+ replay(host);
+
+ HostManager hostManager = createMock(HostManager.class);
+ expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR))
+ .andReturn(Collections.singleton(host));
+ replay(hostManager);
+
+ HostProvider hostProvider = createMock(HostProvider.class);
+ expect(hostProvider.id()).andReturn(id).anyTimes();
+ hostProvider.triggerProbe(host);
+ expectLastCall().once();
+ replay(hostProvider);
+
+ hostMonitor = new HostMonitor(null, hostManager, null, edgePortService);
+
+ hostMonitor.registerHostProvider(hostProvider);
+ hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR);
+
+ hostMonitor.run(null);
+
+ verify(hostProvider);
+ }
+
+ @Test
+ public void testMonitorIpv6HostExists() throws Exception {
ProviderId id = new ProviderId("fake://", "id");
Host host = createMock(Host.class);
@@ -98,7 +137,7 @@ public class HostMonitorTest {
replay(host);
HostManager hostManager = createMock(HostManager.class);
- expect(hostManager.getHostsByIp(TARGET_IP_ADDR))
+ expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR))
.andReturn(Collections.singleton(host));
replay(hostManager);
@@ -111,7 +150,7 @@ public class HostMonitorTest {
hostMonitor = new HostMonitor(null, hostManager, null, edgePortService);
hostMonitor.registerHostProvider(hostProvider);
- hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
+ hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR);
hostMonitor.run(null);
@@ -119,7 +158,7 @@ public class HostMonitorTest {
}
@Test
- public void testMonitorHostDoesNotExist() throws Exception {
+ public void testMonitorIpv4HostDoesNotExist() throws Exception {
HostManager hostManager = createMock(HostManager.class);
@@ -140,12 +179,12 @@ public class HostMonitorTest {
ConnectPoint cp = new ConnectPoint(devId, portNum);
- expect(hostManager.getHostsByIp(TARGET_IP_ADDR))
+ expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR))
.andReturn(Collections.emptySet()).anyTimes();
replay(hostManager);
InterfaceService interfaceService = createMock(InterfaceService.class);
- expect(interfaceService.getMatchingInterface(TARGET_IP_ADDR))
+ expect(interfaceService.getMatchingInterface(TARGET_IPV4_ADDR))
.andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE))
.anyTimes();
replay(interfaceService);
@@ -156,7 +195,7 @@ public class HostMonitorTest {
// Run the test
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
- hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
+ hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR);
hostMonitor.run(null);
@@ -178,16 +217,85 @@ public class HostMonitorTest {
Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
assertEquals(Ethernet.VLAN_UNTAGGED, eth.getVlanID());
ARP arp = (ARP) eth.getPayload();
- assertArrayEquals(SOURCE_ADDR.toOctets(),
+ assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(),
arp.getSenderProtocolAddress());
assertArrayEquals(sourceMac.toBytes(),
arp.getSenderHardwareAddress());
- assertArrayEquals(TARGET_IP_ADDR.toOctets(),
+ assertArrayEquals(TARGET_IPV4_ADDR.toOctets(),
arp.getTargetProtocolAddress());
}
@Test
- public void testMonitorHostDoesNotExistWithVlan() throws Exception {
+ public void testMonitorIpv6HostDoesNotExist() throws Exception {
+
+ HostManager hostManager = createMock(HostManager.class);
+
+ DeviceId devId = DeviceId.deviceId("fake");
+
+ Device device = createMock(Device.class);
+ expect(device.id()).andReturn(devId).anyTimes();
+ replay(device);
+
+ PortNumber portNum = PortNumber.portNumber(2L);
+
+ Port port = createMock(Port.class);
+ expect(port.number()).andReturn(portNum).anyTimes();
+ replay(port);
+
+ TestDeviceService deviceService = new TestDeviceService();
+ deviceService.addDevice(device, Collections.singleton(port));
+
+ ConnectPoint cp = new ConnectPoint(devId, portNum);
+
+ expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR))
+ .andReturn(Collections.emptySet()).anyTimes();
+ replay(hostManager);
+
+ InterfaceService interfaceService = createMock(InterfaceService.class);
+ expect(interfaceService.getMatchingInterface(TARGET_IPV6_ADDR))
+ .andReturn(new Interface(cp, Collections.singleton(IA2), sourceMac2, VlanId.NONE))
+ .anyTimes();
+ replay(interfaceService);
+
+ TestPacketService packetService = new TestPacketService();
+
+
+ // Run the test
+ hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
+
+ hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR);
+ hostMonitor.run(null);
+
+
+ // Check that a packet was sent to our PacketService and that it has
+ // the properties we expect
+ assertEquals(1, packetService.packets.size());
+ OutboundPacket packet = packetService.packets.get(0);
+
+ // Check the output port is correct
+ assertEquals(1, packet.treatment().immediate().size());
+ Instruction instruction = packet.treatment().immediate().get(0);
+ assertTrue(instruction instanceof OutputInstruction);
+ OutputInstruction oi = (OutputInstruction) instruction;
+ assertEquals(portNum, oi.port());
+
+ // Check the output packet is correct (well the important bits anyway)
+ final byte[] pktData = new byte[packet.data().remaining()];
+ packet.data().get(pktData);
+ Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
+ assertEquals(Ethernet.VLAN_UNTAGGED, eth.getVlanID());
+ IPv6 ipv6 = (IPv6) eth.getPayload();
+ assertArrayEquals(SOURCE_IPV6_ADDR.toOctets(), ipv6.getSourceAddress());
+
+ NeighborSolicitation ns =
+ (NeighborSolicitation) ipv6.getPayload().getPayload();
+ assertArrayEquals(sourceMac2.toBytes(), ns.getOptions().get(0).data());
+
+ assertArrayEquals(TARGET_IPV6_ADDR.toOctets(), ns.getTargetAddress());
+ }
+
+ @Test
+ public void testMonitorIpv4HostDoesNotExistWithVlan() throws Exception {
HostManager hostManager = createMock(HostManager.class);
@@ -209,12 +317,12 @@ public class HostMonitorTest {
ConnectPoint cp = new ConnectPoint(devId, portNum);
- expect(hostManager.getHostsByIp(TARGET_IP_ADDR))
+ expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR))
.andReturn(Collections.emptySet()).anyTimes();
replay(hostManager);
InterfaceService interfaceService = createMock(InterfaceService.class);
- expect(interfaceService.getMatchingInterface(TARGET_IP_ADDR))
+ expect(interfaceService.getMatchingInterface(TARGET_IPV4_ADDR))
.andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.vlanId(vlan)))
.anyTimes();
replay(interfaceService);
@@ -225,7 +333,7 @@ public class HostMonitorTest {
// Run the test
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
- hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
+ hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR);
hostMonitor.run(null);
@@ -247,14 +355,84 @@ public class HostMonitorTest {
Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
assertEquals(vlan, eth.getVlanID());
ARP arp = (ARP) eth.getPayload();
- assertArrayEquals(SOURCE_ADDR.toOctets(),
+ assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(),
arp.getSenderProtocolAddress());
assertArrayEquals(sourceMac.toBytes(),
arp.getSenderHardwareAddress());
- assertArrayEquals(TARGET_IP_ADDR.toOctets(),
+ assertArrayEquals(TARGET_IPV4_ADDR.toOctets(),
arp.getTargetProtocolAddress());
}
+ @Test
+ public void testMonitorIpv6HostDoesNotExistWithVlan() throws Exception {
+
+ HostManager hostManager = createMock(HostManager.class);
+
+ DeviceId devId = DeviceId.deviceId("fake");
+ short vlan = 5;
+
+ Device device = createMock(Device.class);
+ expect(device.id()).andReturn(devId).anyTimes();
+ replay(device);
+
+ PortNumber portNum = PortNumber.portNumber(1L);
+
+ Port port = createMock(Port.class);
+ expect(port.number()).andReturn(portNum).anyTimes();
+ replay(port);
+
+ TestDeviceService deviceService = new TestDeviceService();
+ deviceService.addDevice(device, Collections.singleton(port));
+
+ ConnectPoint cp = new ConnectPoint(devId, portNum);
+
+ expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR))
+ .andReturn(Collections.emptySet()).anyTimes();
+ replay(hostManager);
+
+ InterfaceService interfaceService = createMock(InterfaceService.class);
+ expect(interfaceService.getMatchingInterface(TARGET_IPV6_ADDR))
+ .andReturn(new Interface(cp, Collections.singleton(IA2), sourceMac2, VlanId.vlanId(vlan)))
+ .anyTimes();
+ replay(interfaceService);
+
+ TestPacketService packetService = new TestPacketService();
+
+
+ // Run the test
+ hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService);
+
+ hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR);
+ hostMonitor.run(null);
+
+
+ // Check that a packet was sent to our PacketService and that it has
+ // the properties we expect
+ assertEquals(1, packetService.packets.size());
+ OutboundPacket packet = packetService.packets.get(0);
+
+ // Check the output port is correct
+ assertEquals(1, packet.treatment().immediate().size());
+ Instruction instruction = packet.treatment().immediate().get(0);
+ assertTrue(instruction instanceof OutputInstruction);
+ OutputInstruction oi = (OutputInstruction) instruction;
+ assertEquals(portNum, oi.port());
+
+ // Check the output packet is correct (well the important bits anyway)
+ final byte[] pktData = new byte[packet.data().remaining()];
+ packet.data().get(pktData);
+ Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
+ assertEquals(vlan, eth.getVlanID());
+ IPv6 ipv6 = (IPv6) eth.getPayload();
+ assertArrayEquals(SOURCE_IPV6_ADDR.toOctets(), ipv6.getSourceAddress());
+
+ NeighborSolicitation ns =
+ (NeighborSolicitation) ipv6.getPayload().getPayload();
+ assertArrayEquals(sourceMac2.toBytes(), ns.getOptions().get(0).data());
+
+ assertArrayEquals(TARGET_IPV6_ADDR.toOctets(), ns.getTargetAddress());
+ }
+
class TestPacketService extends PacketServiceAdapter {
List<OutboundPacket> packets = new ArrayList<>();