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);
}
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)));
}
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)));
}
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)));
}
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)));
}
Aggregations