@Test public void testHostFind() throws UnknownHostException { assertNotNull(this.invtoryListener); // create one node and two node connectors Node node1 = NodeCreator.createOFNode(1L); NodeConnector nc1_1 = NodeConnectorCreator.createOFNodeConnector((short) 1, node1); NodeConnector nc1_2 = NodeConnectorCreator.createOFNodeConnector((short) 2, node1); // test addStaticHost(), put into inactive host DB if not verifiable Status st = this.hosttracker.addStaticHost("192.168.0.8", "11:22:33:44:55:66", nc1_1, "0"); st = this.hosttracker.addStaticHost("192.168.0.13", "11:22:33:44:55:77", nc1_2, "0"); HostNodeConnector hnc_1 = this.hosttracker.hostFind(InetAddress.getByName("192.168.0.8")); assertNull(hnc_1); this.invtoryListener.notifyNodeConnector(nc1_1, UpdateType.ADDED, null); hnc_1 = this.hosttracker.hostFind(InetAddress.getByName("192.168.0.8")); assertNotNull(hnc_1); }
@Test public void testNotifyNodeConnector() throws UnknownHostException { String ip; assertNotNull(this.invtoryListener); // create one node and two node connectors Node node1 = NodeCreator.createOFNode(1L); NodeConnector nc1_1 = NodeConnectorCreator.createOFNodeConnector((short) 1, node1); NodeConnector nc1_2 = NodeConnectorCreator.createOFNodeConnector((short) 2, node1); // test addStaticHost(), put into inactive host DB if not verifiable Status st = this.hosttracker.addStaticHost("192.168.0.8", "11:22:33:44:55:66", nc1_1, "0"); st = this.hosttracker.addStaticHost("192.168.0.13", "11:22:33:44:55:77", nc1_2, "0"); this.invtoryListener.notifyNodeConnector(nc1_1, UpdateType.ADDED, null); // check all host list Iterator<HostNodeConnector> hnci = this.hosttracker.getAllHosts().iterator(); while (hnci.hasNext()) { ip = hnci.next().getNetworkAddressAsString(); Assert.assertTrue(ip.equals("192.168.0.8")); } // check active host DB hnci = this.hosttracker.getActiveStaticHosts().iterator(); while (hnci.hasNext()) { ip = hnci.next().getNetworkAddressAsString(); Assert.assertTrue(ip.equals("192.168.0.8")); } // check inactive host DB hnci = this.hosttracker.getInactiveStaticHosts().iterator(); while (hnci.hasNext()) { ip = hnci.next().getNetworkAddressAsString(); Assert.assertTrue(ip.equals("192.168.0.13")); } }
@Test public void testStaticHost() throws UnknownHostException { String ip; assertNotNull(this.hosttracker); // create one node and two node connectors Node node1 = NodeCreator.createOFNode(1L); NodeConnector nc1_1 = NodeConnectorCreator.createOFNodeConnector((short) 1, node1); NodeConnector nc1_2 = NodeConnectorCreator.createOFNodeConnector((short) 2, node1); // test addStaticHost(), store into inactive host DB Status st = this.hosttracker.addStaticHost("192.168.0.8", "11:22:33:44:55:66", nc1_1, "0"); Assert.assertTrue(st.isSuccess()); st = this.hosttracker.addStaticHost("192.168.0.13", "11:22:33:44:55:77", nc1_2, "0"); Assert.assertTrue(st.isSuccess()); // check inactive DB Iterator<HostNodeConnector> hnci = this.hosttracker.getInactiveStaticHosts().iterator(); while (hnci.hasNext()) { ip = hnci.next().getNetworkAddressAsString(); Assert.assertTrue(ip.equals("192.168.0.8") || ip.equals("192.168.0.13")); } // check active host DB hnci = this.hosttracker.getActiveStaticHosts().iterator(); Assert.assertFalse(hnci.hasNext()); // test removeStaticHost() st = this.hosttracker.removeStaticHost("192.168.0.8"); Assert.assertTrue(st.isSuccess()); hnci = this.hosttracker.getInactiveStaticHosts().iterator(); while (hnci.hasNext()) { ip = hnci.next().getNetworkAddressAsString(); Assert.assertTrue(ip.equals("192.168.0.13")); } }