Kunihiro Ishiguro
Committed by Jonathan Hart

Add IPv6 HostManager test.

Change-Id: I84a54b3635fd5b7a2a591f9bcf54cb3f7bceaddb
......@@ -70,11 +70,17 @@ public class HostManagerTest {
private static final VlanId VLAN2 = VlanId.vlanId((short) 2);
private static final MacAddress MAC1 = MacAddress.valueOf("00:00:11:00:00:01");
private static final MacAddress MAC2 = MacAddress.valueOf("00:00:22:00:00:02");
private static final MacAddress MAC3 = MacAddress.valueOf("00:00:33:00:00:03");
private static final MacAddress MAC4 = MacAddress.valueOf("00:00:44:00:00:04");
private static final HostId HID1 = HostId.hostId(MAC1, VLAN1);
private static final HostId HID2 = HostId.hostId(MAC2, VLAN1);
private static final HostId HID3 = HostId.hostId(MAC3, VLAN1);
private static final HostId HID4 = HostId.hostId(MAC4, VLAN1);
private static final IpAddress IP1 = IpAddress.valueOf("10.0.0.1");
private static final IpAddress IP2 = IpAddress.valueOf("10.0.0.2");
private static final IpAddress IP3 = IpAddress.valueOf("2001::1");
private static final IpAddress IP4 = IpAddress.valueOf("2001::2");
private static final DeviceId DID1 = DeviceId.deviceId("of:001");
private static final DeviceId DID2 = DeviceId.deviceId("of:002");
......@@ -94,6 +100,15 @@ public class HostManagerTest {
private static final InterfaceIpAddress IA3 =
new InterfaceIpAddress(IpAddress.valueOf("10.3.3.3"),
IpPrefix.valueOf("10.3.3.0/24"));
private static final InterfaceIpAddress IA4 =
new InterfaceIpAddress(IpAddress.valueOf("2001:100::1"),
IpPrefix.valueOf("2001:100::/56"));
private static final InterfaceIpAddress IA5 =
new InterfaceIpAddress(IpAddress.valueOf("2001:200::1"),
IpPrefix.valueOf("2001:200::/48"));
private static final InterfaceIpAddress IA6 =
new InterfaceIpAddress(IpAddress.valueOf("2001:300::1"),
IpPrefix.valueOf("2001:300::/56"));
private HostManager mgr;
......@@ -169,6 +184,28 @@ public class HostManagerTest {
}
@Test
public void hostDetectedIPv6() {
assertNull("host shouldn't be found", mgr.getHost(HID3));
// host addition
detect(HID3, MAC3, VLAN1, LOC1, IP3);
assertEquals("exactly one should be found", 1, mgr.getHostCount());
detect(HID4, MAC4, VLAN2, LOC2, IP3);
assertEquals("two hosts should be found", 2, mgr.getHostCount());
validateEvents(HOST_ADDED, HOST_ADDED);
// host motion
detect(HID3, MAC3, VLAN1, LOC2, IP3);
validateEvents(HOST_MOVED);
assertEquals("only two hosts should be found", 2, mgr.getHostCount());
// host update
detect(HID3, MAC3, VLAN1, LOC2, IP4);
validateEvents(HOST_UPDATED);
assertEquals("only two hosts should be found", 2, mgr.getHostCount());
}
@Test
public void hostVanished() {
detect(HID1, MAC1, VLAN1, LOC1, IP1);
providerService.hostVanished(HID1);
......@@ -177,6 +214,15 @@ public class HostManagerTest {
assertNull("host should have been removed", mgr.getHost(HID1));
}
@Test
public void hostVanishedIPv6() {
detect(HID3, MAC3, VLAN1, LOC1, IP3);
providerService.hostVanished(HID3);
validateEvents(HOST_ADDED, HOST_REMOVED);
assertNull("host should have been removed", mgr.getHost(HID3));
}
private void validateHosts(
String msg, Iterable<Host> hosts, HostId... ids) {
Set<HostId> hids = Sets.newHashSet(ids);
......@@ -199,6 +245,19 @@ public class HostManagerTest {
assertTrue("incorrect host location", mgr.getConnectedHosts(DID2).isEmpty());
}
@Test
public void getHostsIPv6() {
detect(HID3, MAC3, VLAN1, LOC1, IP3);
detect(HID4, MAC4, VLAN1, LOC2, IP4);
validateHosts("host not properly stored", mgr.getHosts(), HID3, HID4);
validateHosts("can't get hosts by VLAN", mgr.getHostsByVlan(VLAN1), HID3, HID4);
validateHosts("can't get hosts by MAC", mgr.getHostsByMac(MAC3), HID3);
validateHosts("can't get hosts by IP", mgr.getHostsByIp(IP3), HID3);
validateHosts("can't get hosts by location", mgr.getConnectedHosts(LOC1), HID3);
assertTrue("incorrect host location", mgr.getConnectedHosts(DID2).isEmpty());
}
private static class TestHostProvider extends AbstractProvider
implements HostProvider {
......@@ -263,6 +322,40 @@ public class HostManagerTest {
}
@Test
public void bindAddressesToPortIPv6() {
PortAddresses add1 =
new PortAddresses(CP1, Sets.newHashSet(IA4, IA5), MAC3, VlanId.NONE);
mgr.bindAddressesToPort(add1);
Set<PortAddresses> storedAddresses = mgr.getAddressBindingsForPort(CP1);
assertEquals(1, storedAddresses.size());
assertTrue(storedAddresses.contains(add1));
// Add some more addresses and check that they're added correctly
PortAddresses add2 =
new PortAddresses(CP1, Sets.newHashSet(IA6), null,
VlanId.vlanId((short) 2));
mgr.bindAddressesToPort(add2);
storedAddresses = mgr.getAddressBindingsForPort(CP1);
assertEquals(2, storedAddresses.size());
assertTrue(storedAddresses.contains(add1));
assertTrue(storedAddresses.contains(add2));
PortAddresses add3 = new PortAddresses(CP1, null, MAC4, VlanId.NONE);
mgr.bindAddressesToPort(add3);
storedAddresses = mgr.getAddressBindingsForPort(CP1);
assertEquals(3, storedAddresses.size());
assertTrue(storedAddresses.contains(add1));
assertTrue(storedAddresses.contains(add2));
assertTrue(storedAddresses.contains(add3));
}
@Test
public void unbindAddressesFromPort() {
PortAddresses add1 =
new PortAddresses(CP1, Sets.newHashSet(IA1, IA2), MAC1, VlanId.NONE);
......@@ -291,6 +384,34 @@ public class HostManagerTest {
}
@Test
public void unbindAddressesFromPortIPv6() {
PortAddresses add1 =
new PortAddresses(CP1, Sets.newHashSet(IA4, IA5), MAC3, VlanId.NONE);
mgr.bindAddressesToPort(add1);
Set<PortAddresses> storedAddresses = mgr.getAddressBindingsForPort(CP1);
assertEquals(1, storedAddresses.size());
assertTrue(storedAddresses.contains(add1));
PortAddresses rem1 =
new PortAddresses(CP1, Sets.newHashSet(IA4), null, VlanId.NONE);
mgr.unbindAddressesFromPort(rem1);
storedAddresses = mgr.getAddressBindingsForPort(CP1);
// It shouldn't have been removed because it didn't match the originally
// submitted address object
assertEquals(1, storedAddresses.size());
assertTrue(storedAddresses.contains(add1));
mgr.unbindAddressesFromPort(add1);
storedAddresses = mgr.getAddressBindingsForPort(CP1);
assertTrue(storedAddresses.isEmpty());
}
@Test
public void clearAddresses() {
PortAddresses add1 =
new PortAddresses(CP1, Sets.newHashSet(IA1, IA2), MAC1, VlanId.NONE);
......@@ -308,6 +429,23 @@ public class HostManagerTest {
}
@Test
public void clearAddressesIPv6() {
PortAddresses add1 =
new PortAddresses(CP1, Sets.newHashSet(IA4, IA5), MAC3, VlanId.NONE);
mgr.bindAddressesToPort(add1);
Set<PortAddresses> storedAddresses = mgr.getAddressBindingsForPort(CP1);
assertEquals(1, storedAddresses.size());
assertTrue(storedAddresses.contains(add1));
mgr.clearAddresses(CP1);
storedAddresses = mgr.getAddressBindingsForPort(CP1);
assertTrue(storedAddresses.isEmpty());
}
@Test
public void getAddressBindingsForPort() {
PortAddresses add1 =
new PortAddresses(CP1, Sets.newHashSet(IA1, IA2), MAC1, VlanId.NONE);
......@@ -320,6 +458,18 @@ public class HostManagerTest {
}
@Test
public void getAddressBindingsForPortIPv6() {
PortAddresses add1 =
new PortAddresses(CP1, Sets.newHashSet(IA4, IA5), MAC3, VlanId.NONE);
mgr.bindAddressesToPort(add1);
Set<PortAddresses> storedAddresses = mgr.getAddressBindingsForPort(CP1);
assertEquals(1, storedAddresses.size());
assertTrue(storedAddresses.contains(add1));
}
@Test
public void getAddressBindings() {
Set<PortAddresses> storedAddresses = mgr.getAddressBindings();
......@@ -344,4 +494,30 @@ public class HostManagerTest {
assertTrue(storedAddresses.size() == 2);
assertTrue(storedAddresses.equals(Sets.newHashSet(add1, add2)));
}
@Test
public void getAddressBindingsIPv6() {
Set<PortAddresses> storedAddresses = mgr.getAddressBindings();
assertTrue(storedAddresses.isEmpty());
PortAddresses add1 =
new PortAddresses(CP1, Sets.newHashSet(IA4, IA5), MAC3, VlanId.NONE);
mgr.bindAddressesToPort(add1);
storedAddresses = mgr.getAddressBindings();
assertTrue(storedAddresses.size() == 1);
PortAddresses add2 =
new PortAddresses(CP2, Sets.newHashSet(IA5), MAC4, VlanId.NONE);
mgr.bindAddressesToPort(add2);
storedAddresses = mgr.getAddressBindings();
assertTrue(storedAddresses.size() == 2);
assertTrue(storedAddresses.equals(Sets.newHashSet(add1, add2)));
}
}
......