Search in sources :

Example 11 with HostService

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

the class VirtualNetworkHostManagerTest method testGetHostsByNullIp.

/**
 * Tests querying for hosts with null ip.
 */
@Test(expected = NullPointerException.class)
public void testGetHostsByNullIp() {
    VirtualNetwork vnet = setupVnet();
    HostService hostService = manager.get(vnet.id(), HostService.class);
    hostService.getHostsByIp(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) HostService(org.onosproject.net.host.HostService) Test(org.junit.Test)

Example 12 with HostService

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

the class VirtualNetworkHostManagerTest method testGetConnectedHostsByNullLoc.

/**
 * Tests querying for connected hosts with null host location (connect point).
 */
@Test(expected = NullPointerException.class)
public void testGetConnectedHostsByNullLoc() {
    VirtualNetwork vnet = setupEmptyVnet();
    HostService hostService = manager.get(vnet.id(), HostService.class);
    hostService.getConnectedHosts((ConnectPoint) null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) HostService(org.onosproject.net.host.HostService) Test(org.junit.Test)

Example 13 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)

Example 14 with HostService

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

the class VirtualNetworkHostManagerTest method testGetHostsOnEmptyVnet.

/**
 * Tests the getHosts(), getHost(), getHostsByXX(), getConnectedHosts() methods
 * on an empty virtual network.
 */
@Test
public void testGetHostsOnEmptyVnet() {
    VirtualNetwork virtualNetwork = setupEmptyVnet();
    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.", 0, Iterators.size(itHosts));
    assertEquals("The host count did not match.", 0, hostService.getHostCount());
    // test the getHost() method
    Host testHost = hostService.getHost(HID2);
    assertNull("The host should be null.", testHost);
    // test the getHostsByVlan(...) method
    Collection<Host> collHost = hostService.getHostsByVlan(VLAN1);
    assertEquals("The host set size did not match.", 0, collHost.size());
    // test the getHostsByMac(...) method
    collHost = hostService.getHostsByMac(MAC2);
    assertEquals("The host set size did not match.", 0, collHost.size());
    // test the getHostsByIp(...) method
    collHost = hostService.getHostsByIp(IP1);
    assertEquals("The host set size did not match.", 0, collHost.size());
    // test the getConnectedHosts(ConnectPoint) method
    collHost = hostService.getConnectedHosts(LOC1);
    assertEquals("The host set size did not match.", 0, collHost.size());
    // test the getConnectedHosts(DeviceId) method
    collHost = hostService.getConnectedHosts(DID2);
    assertEquals("The host set size did not match.", 0, collHost.size());
}
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) Test(org.junit.Test)

Example 15 with HostService

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

the class VmIpCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    HostService service = AbstractShellCommand.get(HostService.class);
    Iterator<Host> it = service.getHosts().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        for (IpAddress ip : it.next().ipAddresses()) {
            strings.add(ip.toString() + CIDR);
        }
    }
    return delegate.complete(session, commandLine, candidates);
}
Also used : HostService(org.onosproject.net.host.HostService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) Host(org.onosproject.net.Host) IpAddress(org.onlab.packet.IpAddress)

Aggregations

HostService (org.onosproject.net.host.HostService)19 Test (org.junit.Test)9 Host (org.onosproject.net.Host)9 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)8 IpAddress (org.onlab.packet.IpAddress)4 Set (java.util.Set)3 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)3 Before (org.junit.Before)3 CoreService (org.onosproject.core.CoreService)3 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)3 FlowRuleService (org.onosproject.net.flow.FlowRuleService)3 List (java.util.List)2 Map (java.util.Map)2 IpPrefix (org.onlab.packet.IpPrefix)2 MacAddress (org.onlab.packet.MacAddress)2 VlanId (org.onlab.packet.VlanId)2 VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)2 DefaultHost (org.onosproject.net.DefaultHost)2 GroupService (org.onosproject.net.group.GroupService)2 Logger (org.slf4j.Logger)2