Search in sources :

Example 21 with HostDescription

use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.

the class NetworkConfigHostProvider method addHost.

/**
 * Adds host information.
 * IP information will be appended if host exists.
 *
 * @param mac MAC address of the host
 * @param vlan VLAN ID of the host
 * @param locations Location of the host
 * @param ips Set of IP addresses of the host
 */
protected void addHost(MacAddress mac, VlanId vlan, Set<HostLocation> locations, Set<IpAddress> ips) {
    HostId hid = HostId.hostId(mac, vlan);
    HostDescription desc = (ips != null) ? new DefaultHostDescription(mac, vlan, locations, ips, true) : new DefaultHostDescription(mac, vlan, locations, Collections.emptySet(), true);
    providerService.hostDetected(hid, desc, true);
}
Also used : DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostId(org.onosproject.net.HostId) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostDescription(org.onosproject.net.host.HostDescription)

Example 22 with HostDescription

use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.

the class HostLocationProviderTest method receiveArp.

/**
 * When receiving ARP, updates location and IP.
 */
@Test
public void receiveArp() {
    testProcessor.process(new TestArpPacketContext(DEV1));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat("receiveArp. 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().toArray()[0], is(IP_ADDRESS)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.vlan(), is(VLAN)));
}
Also used : HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 23 with HostDescription

use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.

the class HostLocationProviderTest method receiveDhcp6.

/**
 * When receiving DHCPv6 REQUEST, update MAC, location of client.
 * When receiving DHCPv6 ACK, update MAC, location of server and IP of client.
 */
@Test
public void receiveDhcp6() {
    TestUtils.setField(provider, "useDhcp6", true);
    // DHCP Request
    testProcessor.process(new TestDhcp6RequestPacketContext(DEV4, 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(LOCATION2)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.hwAddress(), is(MAC2)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.ipAddress().size(), is(0)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.vlan(), is(VLAN)));
    // DHCP Ack
    testProcessor.process(new TestDhcp6AckPacketContext(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(DHCP6_SERVER_MAC)));
    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 DHCP client.
    HostDescription descr3 = providerService.descriptions.get(2);
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr3.location(), is(LOCATION2)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr3.hwAddress(), is(MAC2)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr3.ipAddress().size(), is(1)));
    IpAddress ip = descr3.ipAddress().iterator().next();
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(ip, is(IP_ADDRESS2.getIp6Address())));
    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 24 with HostDescription

use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.

the class HostLocationProviderTest method receivesRa.

/**
 * When receiving RouterAdvertisement, update location and IP.
 */
@Test
public void receivesRa() {
    testProcessor.process(new TestRAPacketContext(DEV4));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat("receivesRa. No host description expected", providerService.descriptions.size(), is(1)));
    final HostDescription desc = providerService.descriptions.get(0);
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(desc.location(), is(LOCATION2)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(desc.hwAddress(), is(MAC2)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(desc.ipAddress().toArray()[0], is(IP_ADDRESS2)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(desc.vlan(), is(VLAN)));
}
Also used : HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 25 with HostDescription

use of org.onosproject.net.host.HostDescription in project onos by opennetworkinglab.

the class HostLocationProviderTest method receiveIpv6Unicast.

/**
 * When receiving IPv6 unicast packet, updates location only.
 */
@Test
public void receiveIpv6Unicast() {
    testProcessor.process(new TestIpv6PacketContext(DEV4));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat("receiveIpv6Unicast. One host description expected", providerService.descriptions.size(), is(1)));
    HostDescription descr = providerService.descriptions.get(0);
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.location(), is(LOCATION2)));
    TestTools.assertAfter(ASSERTION_DELAY, () -> assertThat(descr.hwAddress(), is(MAC2)));
    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)

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