Search in sources :

Example 16 with HostDescription

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)));
}
Also used : InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 17 with HostDescription

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)));
}
Also used : HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 18 with HostDescription

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)));
}
Also used : HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 19 with HostDescription

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);
}
Also used : IpAddress(org.onlab.packet.IpAddress) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostDescription(org.onosproject.net.host.HostDescription) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with HostDescription

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));
}
Also used : DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Aggregations

HostDescription (org.onosproject.net.host.HostDescription)29 Test (org.junit.Test)19 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)16 HostId (org.onosproject.net.HostId)12 IpAddress (org.onlab.packet.IpAddress)8 HostLocation (org.onosproject.net.HostLocation)8 Host (org.onosproject.net.Host)7 MacAddress (org.onlab.packet.MacAddress)4 VlanId (org.onlab.packet.VlanId)4 DeviceEvent (org.onosproject.net.device.DeviceEvent)4 HashSet (java.util.HashSet)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DefaultHost (org.onosproject.net.DefaultHost)3 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)3 Strings (com.google.common.base.Strings)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 Collectors (java.util.stream.Collectors)2 Tools (org.onlab.util.Tools)2