use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.
the class HostLocationProviderTest method receiveDhcp.
/**
* When receiving DHCP REQUEST, update MAC, location of client.
* When receiving DHCP ACK, update MAC, location of server and IP of client.
*/
@Test
public void receiveDhcp() {
TestUtils.setField(provider, "useDhcp", true);
// DHCP Request
testProcessor.process(new TestDhcpRequestPacketContext(DEV1, VLAN));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat("receiveDhcpRequest. One host description expected", providerService.descriptions.size(), is(1)));
// Should learn the MAC and location of DHCP client
HostDescription descr = providerService.descriptions.get(0);
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.location(), is(LOCATION)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.hwAddress(), is(MAC)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.ipAddress().size(), is(0)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.vlan(), is(VLAN)));
// DHCP Ack
testProcessor.process(new TestDhcpAckPacketContext(DEV1));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat("receiveDhcpAck. Two additional host descriptions expected", providerService.descriptions.size(), is(3)));
// Should also learn the MAC, location of DHCP server
HostDescription descr2 = providerService.descriptions.get(1);
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr2.location(), is(LOCATION3)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr2.hwAddress(), is(MAC3)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr2.ipAddress().size(), is(0)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr2.vlan(), is(VLAN)));
// Should update the IP address of the client.
HostDescription descr3 = providerService.descriptions.get(2);
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr3.location(), is(LOCATION)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr3.hwAddress(), is(MAC)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr3.ipAddress().size(), is(1)));
IpAddress ip = descr3.ipAddress().iterator().next();
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(ip, is(IP_ADDRESS.getIp4Address())));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr3.vlan(), is(VLAN)));
}
use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.
the class HostLocationProviderTest method receiveNa.
/**
* When receiving NeighborAdvertisement, updates location and IP.
* We should also expect that target IP is learnt.
*/
@Test
public void receiveNa() {
testProcessor.process(new TestNaPacketContext(DEV4));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat("receiveNa. One host description expected", providerService.descriptions.size(), is(2)));
final HostDescription descr0 = providerService.descriptions.get(0);
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr0.location(), is(LOCATION2)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr0.hwAddress(), is(MAC2)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertTrue(descr0.ipAddress().contains(LLIP_ADDRESS2)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr0.vlan(), is(VLAN)));
final HostDescription descr1 = providerService.descriptions.get(1);
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr1.location(), is(LOCATION2)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr1.hwAddress(), is(MAC2)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertTrue(descr1.ipAddress().contains(IP_ADDRESS2)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr1.vlan(), is(VLAN)));
}
use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.
the class HostLocationProviderTest method receiveIpv4.
/**
* When receiving IPv4, updates location only.
*/
@Test
public void receiveIpv4() {
testProcessor.process(new TestIpv4PacketContext(DEV1));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat("receiveIpv4. One host description expected", providerService.descriptions.size(), is(1)));
HostDescription descr = providerService.descriptions.get(0);
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.location(), is(LOCATION)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.hwAddress(), is(MAC)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.ipAddress().size(), is(0)));
TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.vlan(), is(VLAN)));
}
use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.
the class DistributedHostStoreTest method testRemoveHostByIp.
@Test
public void testRemoveHostByIp() {
Set<IpAddress> ips = new HashSet<>();
ips.add(IP1);
ips.add(IP2);
HostDescription description = createHostDesc(HOSTID, ips);
ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false);
ecXHostStore.removeIp(HOSTID, IP1);
Set<Host> hosts = ecXHostStore.getHosts(IP1);
assertTrue(hosts.size() == 0);
}
use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.
the class BasicHostOperatorTest method testDescOps.
@Test
public void testDescOps() {
HostDescription desc = BasicHostOperator.combine(BHC, HOST);
assertEquals(NAME, desc.annotations().value(AnnotationKeys.NAME));
assertEquals(String.valueOf(LON), desc.annotations().value(AnnotationKeys.LONGITUDE));
assertEquals(String.valueOf(LAT), desc.annotations().value(AnnotationKeys.LATITUDE));
}
Aggregations