@Test public void testOfLinkAdded() throws Exception { Class<PhysicalNetworkAdapter> class1 = PhysicalNetworkAdapter.class; Field field = class1.getDeclaredField("running"); field.setAccessible(true); Assert.assertTrue((Boolean) field.get(physicalNetworkAdapter) == false); Link link = mock(Link.class); LinkKey linkKey = mock(LinkKey.class); LinkId linkId = mock(LinkId.class); Source source = mock(Source.class); Destination destination = mock(Destination.class); org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId nodeId = mock(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId.class); TpId tpId = mock(TpId.class); PhysicalLink physicalLink = mock(PhysicalLink.class); when(link.getKey()).thenReturn(linkKey); when(link.getLinkId()).thenReturn(linkId); when(linkId.getValue()).thenReturn(new String("test")); when(link.getSource()).thenReturn(source); when(link.getDestination()).thenReturn(destination); when(source.getSourceNode()).thenReturn(nodeId); when(source.getSourceTp()).thenReturn(tpId); when(destination.getDestNode()).thenReturn(nodeId); when(destination.getDestTp()).thenReturn(tpId); when(nodeId.getValue()) .thenReturn(new String("srcNode")) .thenReturn(new String("dstNode")); when(tpId.getValue()) .thenReturn(new String("srcTp")) .thenReturn(new String("dstTp")); when(phyConfigLoader.getPhysicalLink(any(PhysicalLinkId.class))) .thenReturn(null) .thenReturn(physicalLink); when(physicalLink.getMetric()).thenReturn(1L); physicalNetworkAdapter.ofLinkAdded(link); Assert.assertTrue((Boolean)field.get(physicalNetworkAdapter) == true); physicalNetworkAdapter.ofLinkAdded(link); verify(physicalLink).getMetric(); physicalNetworkAdapter.close(); }
protected void ofLinkAdded(Link link) { log.debug("OF link added:{}.", link.getKey()); String srcNode = link.getSource().getSourceNode().getValue(); String srcTp = link.getSource().getSourceTp().getValue(); String dstNode = link.getDestination().getDestNode().getValue(); String dstTp = link.getDestination().getDestTp().getValue(); String strLinkId = link.getLinkId().getValue(); PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setSrcNodeId(new PhysicalNodeId(srcNode)); linkBuilder.setSrcPortId(new PhysicalPortId(srcTp)); linkBuilder.setDestNodeId(new PhysicalNodeId(dstNode)); linkBuilder.setDestPortId(new PhysicalPortId(dstTp)); linkBuilder.setBandwidth(PhyConfigLoader.DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(PhyConfigLoader.DEFAULT_LINK_DELAY); linkBuilder.setLossRate(PhyConfigLoader.DEFAULT_LINK_LOSS_RATE); PhysicalLinkId physicalLinkId = new PhysicalLinkId(strLinkId); PhysicalLink physicalLink = phyConfigLoader.getPhysicalLink(physicalLinkId); if (physicalLink != null) { linkBuilder.setMetric(physicalLink.getMetric()); } else { log.warn("Can not find conf info of {}.", link.getKey()); } synchronized (mutex) { physicalLinkSet.add(linkBuilder.build()); if (!running) { phyTimer.schedule(new PhyTransmit(), 10, 500); running = true; } } }
PhysicalNetworkAdapter { protected void ofLinkAdded(Link link) { log.debug("OF link added:{}.", link.getKey()); String srcNode = link.getSource().getSourceNode().getValue(); String srcTp = link.getSource().getSourceTp().getValue(); String dstNode = link.getDestination().getDestNode().getValue(); String dstTp = link.getDestination().getDestTp().getValue(); String strLinkId = link.getLinkId().getValue(); PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setSrcNodeId(new PhysicalNodeId(srcNode)); linkBuilder.setSrcPortId(new PhysicalPortId(srcTp)); linkBuilder.setDestNodeId(new PhysicalNodeId(dstNode)); linkBuilder.setDestPortId(new PhysicalPortId(dstTp)); linkBuilder.setBandwidth(PhyConfigLoader.DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(PhyConfigLoader.DEFAULT_LINK_DELAY); linkBuilder.setLossRate(PhyConfigLoader.DEFAULT_LINK_LOSS_RATE); PhysicalLinkId physicalLinkId = new PhysicalLinkId(strLinkId); PhysicalLink physicalLink = phyConfigLoader.getPhysicalLink(physicalLinkId); if (physicalLink != null) { linkBuilder.setMetric(physicalLink.getMetric()); } else { log.warn("Can not find conf info of {}.", link.getKey()); } synchronized (mutex) { physicalLinkSet.add(linkBuilder.build()); if (!running) { phyTimer.schedule(new PhyTransmit(), 10, 500); running = true; } } } }
PhysicalNetworkAdapter { protected void ofLinkAdded(Link link) { log.debug("OF link added:{}.", link.getKey()); String srcNode = link.getSource().getSourceNode().getValue(); String srcTp = link.getSource().getSourceTp().getValue(); String dstNode = link.getDestination().getDestNode().getValue(); String dstTp = link.getDestination().getDestTp().getValue(); String strLinkId = link.getLinkId().getValue(); PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setSrcNodeId(new PhysicalNodeId(srcNode)); linkBuilder.setSrcPortId(new PhysicalPortId(srcTp)); linkBuilder.setDestNodeId(new PhysicalNodeId(dstNode)); linkBuilder.setDestPortId(new PhysicalPortId(dstTp)); linkBuilder.setBandwidth(PhyConfigLoader.DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(PhyConfigLoader.DEFAULT_LINK_DELAY); linkBuilder.setLossRate(PhyConfigLoader.DEFAULT_LINK_LOSS_RATE); PhysicalLinkId physicalLinkId = new PhysicalLinkId(strLinkId); PhysicalLink physicalLink = phyConfigLoader.getPhysicalLink(physicalLinkId); if (physicalLink != null) { linkBuilder.setMetric(physicalLink.getMetric()); } else { log.warn("Can not find conf info of {}.", link.getKey()); } synchronized (mutex) { physicalLinkSet.add(linkBuilder.build()); if (!running) { phyTimer.schedule(new PhyTransmit(), 10, 500); running = true; } } } PhysicalNetworkAdapter(DataBroker dataBroker
            , NotificationProviderService notificationProviderService
            , PhyConfigLoader phyConfigLoader
            , FlowUtils ofFlowUtils); }
PhysicalNetworkAdapter { protected void ofLinkAdded(Link link) { log.debug("OF link added:{}.", link.getKey()); String srcNode = link.getSource().getSourceNode().getValue(); String srcTp = link.getSource().getSourceTp().getValue(); String dstNode = link.getDestination().getDestNode().getValue(); String dstTp = link.getDestination().getDestTp().getValue(); String strLinkId = link.getLinkId().getValue(); PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setSrcNodeId(new PhysicalNodeId(srcNode)); linkBuilder.setSrcPortId(new PhysicalPortId(srcTp)); linkBuilder.setDestNodeId(new PhysicalNodeId(dstNode)); linkBuilder.setDestPortId(new PhysicalPortId(dstTp)); linkBuilder.setBandwidth(PhyConfigLoader.DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(PhyConfigLoader.DEFAULT_LINK_DELAY); linkBuilder.setLossRate(PhyConfigLoader.DEFAULT_LINK_LOSS_RATE); PhysicalLinkId physicalLinkId = new PhysicalLinkId(strLinkId); PhysicalLink physicalLink = phyConfigLoader.getPhysicalLink(physicalLinkId); if (physicalLink != null) { linkBuilder.setMetric(physicalLink.getMetric()); } else { log.warn("Can not find conf info of {}.", link.getKey()); } synchronized (mutex) { physicalLinkSet.add(linkBuilder.build()); if (!running) { phyTimer.schedule(new PhyTransmit(), 10, 500); running = true; } } } PhysicalNetworkAdapter(DataBroker dataBroker
            , NotificationProviderService notificationProviderService
            , PhyConfigLoader phyConfigLoader
            , FlowUtils ofFlowUtils); void close(); PhyConfigLoader getPhyConfigLoader(); }
PhysicalNetworkAdapter { protected void ofLinkAdded(Link link) { log.debug("OF link added:{}.", link.getKey()); String srcNode = link.getSource().getSourceNode().getValue(); String srcTp = link.getSource().getSourceTp().getValue(); String dstNode = link.getDestination().getDestNode().getValue(); String dstTp = link.getDestination().getDestTp().getValue(); String strLinkId = link.getLinkId().getValue(); PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setSrcNodeId(new PhysicalNodeId(srcNode)); linkBuilder.setSrcPortId(new PhysicalPortId(srcTp)); linkBuilder.setDestNodeId(new PhysicalNodeId(dstNode)); linkBuilder.setDestPortId(new PhysicalPortId(dstTp)); linkBuilder.setBandwidth(PhyConfigLoader.DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(PhyConfigLoader.DEFAULT_LINK_DELAY); linkBuilder.setLossRate(PhyConfigLoader.DEFAULT_LINK_LOSS_RATE); PhysicalLinkId physicalLinkId = new PhysicalLinkId(strLinkId); PhysicalLink physicalLink = phyConfigLoader.getPhysicalLink(physicalLinkId); if (physicalLink != null) { linkBuilder.setMetric(physicalLink.getMetric()); } else { log.warn("Can not find conf info of {}.", link.getKey()); } synchronized (mutex) { physicalLinkSet.add(linkBuilder.build()); if (!running) { phyTimer.schedule(new PhyTransmit(), 10, 500); running = true; } } } PhysicalNetworkAdapter(DataBroker dataBroker
            , NotificationProviderService notificationProviderService
            , PhyConfigLoader phyConfigLoader
            , FlowUtils ofFlowUtils); void close(); PhyConfigLoader getPhyConfigLoader();  }