Java Code Examples for org.onosproject.net.host.HostService#getHostsByIp()
The following examples show how to use
org.onosproject.net.host.HostService#getHostsByIp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VirtualNetworkHostManagerTest.java From onos with Apache License 2.0 | 5 votes |
/** * 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()); }
Example 2
Source File: VirtualNetworkHostManagerTest.java From onos with Apache License 2.0 | 5 votes |
/** * 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); }
Example 3
Source File: VirtualNetworkHostManagerTest.java From onos with Apache License 2.0 | 4 votes |
/** * 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)); }
Example 4
Source File: DefaultNeighbourMessageHandler.java From onos with Apache License 2.0 | 4 votes |
@Override public void handleMessage(NeighbourMessageContext context, HostService hostService) { switch (context.type()) { case REPLY: Host h = hostService.getHost(hostId(context.packet().getDestinationMAC(), vlanId(context.packet().getVlanID()))); if (h == null) { context.flood(); } else { context.forward(h.location()); } break; case REQUEST: // See if we have the target host in the host store Set<Host> hosts = hostService.getHostsByIp(context.target()); Host dst = null; Host src = hostService.getHost(hostId(context.srcMac(), context.vlan())); for (Host host : hosts) { if (host.vlan().equals(context.vlan())) { dst = host; break; } } if (src != null && dst != null) { // We know the target host so we can respond context.reply(dst.mac()); return; } // The request couldn't be resolved. // Flood the request on all ports except the incoming port. context.flood(); break; default: break; } }