Search in sources :

Example 16 with HostService

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

the class VirtualNetworkHostManagerTest method testGetHostsOnNonEmptyVnet.

/**
 * Tests the getHosts(), getHost(), getHostsByXX(), getConnectedHosts() methods
 * on a non-empty virtual network.
 */
@Test
public void testGetHostsOnNonEmptyVnet() {
    VirtualNetwork virtualNetwork = setupEmptyVnet();
    VirtualHost vhost1 = manager.createVirtualHost(virtualNetwork.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
    VirtualHost vhost2 = manager.createVirtualHost(virtualNetwork.id(), HID2, MAC2, VLAN2, LOC2, IPSET2);
    HostService hostService = manager.get(virtualNetwork.id(), HostService.class);
    // test the getHosts() and getHostCount() methods
    Iterator<Host> itHosts = hostService.getHosts().iterator();
    assertEquals("The host set size did not match.", 2, Iterators.size(itHosts));
    assertEquals("The host count did not match.", 2, hostService.getHostCount());
    // test the getHost() method
    Host testHost = hostService.getHost(HID2);
    assertEquals("The expected host did not match.", vhost2, testHost);
    // test the getHostsByVlan(...) method
    Collection<Host> collHost = hostService.getHostsByVlan(VLAN1);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost1));
    // test the getHostsByMac(...) method
    collHost = hostService.getHostsByMac(MAC2);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost2));
    // test the getHostsByIp(...) method
    collHost = hostService.getHostsByIp(IP1);
    assertEquals("The host set size did not match.", 2, collHost.size());
    collHost = hostService.getHostsByIp(IP2);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost1));
    // test the getConnectedHosts(ConnectPoint) method
    collHost = hostService.getConnectedHosts(LOC1);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost1));
    // test the getConnectedHosts(DeviceId) method
    collHost = hostService.getConnectedHosts(DID2);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost2));
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) HostService(org.onosproject.net.host.HostService) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) Host(org.onosproject.net.Host) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) Test(org.junit.Test)

Aggregations

HostService (org.onosproject.net.host.HostService)16 Test (org.junit.Test)8 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)8 Host (org.onosproject.net.Host)8 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)3 IpAddress (org.onlab.packet.IpAddress)3 Set (java.util.Set)2 VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1