public BandwidthTopology(Topology topology, NetworkTrackerService networkTrackerService) { nodeNum = topology.getNode().toArray().length; // Map<NodeId, Integer> tpIdMap = new HashMap<>(); int switchIndex = 0; for (int i = 0; i < nodeNum; i++) { NodeId nodeId = topology.getNode().get(i).getNodeId(); if (!(nodeId.getValue().contains("host"))) { tpIdMap.put(nodeId, switchIndex); ++switchNum; ++switchIndex; } } this.BandwidthMap = new long[switchNum][switchNum]; for (int i = 0; i < switchNum; i++) { for (int j = 0; j < switchNum; j++) { this.BandwidthMap[i][j] = 0; } } for (Link link : topology.getLink()) { TpId tpId = link.getSource().getSourceTp(); Integer src = tpIdMap.get(link.getSource().getSourceNode()); Integer dst = tpIdMap.get(link.getDestination().getDestNode()); if (null != src && null != dst) this.BandwidthMap[src][dst] = getBandwidthByTp(link.getSource().getSourceTp(), networkTrackerService); } }
public String getTpIdMap() { StringBuffer result = new StringBuffer("{"); for (NodeId key : tpIdMap.keySet()) { LOG.info(key.getValue() + ":" + tpIdMap.get(key)); result.append('\"' + key.getValue() + '\"' + ':' + tpIdMap.get(key).toString() + ','); } result.deleteCharAt(result.lastIndexOf(",")); result.append('}'); return result.toString(); }
/** * Test method for {@link org.opendaylight.unimgr.command.uniAddCommandTest#execute()}. * * @throws Exception */ @SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testExecute() throws Exception { final Optional<Node> optionalOvsdbNode = mock(Optional.class); final UniAugmentation uniAugmentation = mock(UniAugmentation.class); final OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class); final ConnectionInfo connectionInfo = mock(ConnectionInfo.class); final IpAddress ipAddress = mock(IpAddress.class); final Ipv4Address ipv4Address = mock(Ipv4Address.class); final OvsdbNodeRef ovsNodedRef = mock(OvsdbNodeRef.class); final Node node = mock(Node.class); final NodeId nodeId = mock(NodeId.class); final List<Node> nodes = new ArrayList<Node>(); final InstanceIdentifier uniKey = InstanceIdentifier.create(NetworkTopology.class) .child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID)) .child(Node.class, new NodeKey(OVSDB_NODE_ID)); nodes.add(node); // Case UNI1 : uni.getOvsdbNodeRef() != null, !optionalNode.isPresent() when(uniNode.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation); when(optUniNode.isPresent()).thenReturn(false); when(MdsalUtils.readNode( any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))) .thenReturn(optUniNode) .thenReturn(optionalOvsdbNode); when(optionalOvsdbNode.isPresent()).thenReturn(false).thenReturn(true); when(optionalOvsdbNode.get()).thenReturn(node); when(uniAugmentation.getIpAddress()).thenReturn(ipAddress); when(uniAugmentation.getSpeed()).thenReturn(mock(Speed.class)); when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef); when(ovsdbNodeAugmentation.getConnectionInfo()).thenReturn(connectionInfo); when(connectionInfo.getRemoteIp()).thenReturn(ipAddress); when(ipAddress.getIpv4Address()).thenReturn(ipv4Address); when(ipv4Address.toString()).thenReturn("ipv4Address_test"); when(ipv4Address.getValue()).thenReturn("ipv4AddressValue_test"); when(ovsNodedRef.getValue()).thenReturn(uniKey); when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation); when(node.getNodeId()).thenReturn(nodeId); when(nodeId.toString()).thenReturn("ovsdbNodeId_test"); when(OvsdbUtils.findOvsdbNode(any(DataBroker.class), any(UniAugmentation.class))) .thenReturn(optionalOvsdbNode); when(OvsdbUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class))) .thenReturn(null); when(UniUtils.updateUniNode( any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(UniAugmentation.class), any(Node.class), any(DataBroker.class))) .thenReturn(true); when(UniUtils.updateUniNode( any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(UniAugmentation.class), any(InstanceIdentifier.class), any(DataBroker.class))) .thenReturn(true); when(OvsdbUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class))) .thenReturn(node); PowerMockito.doNothing() .when( OvsdbUtils.class, "createBridgeNode", dataBroker, uniKey, uniAugmentation, UnimgrConstants.DEFAULT_BRIDGE_NAME); when(UniUtils.getUniNodes(any(DataBroker.class))).thenReturn(nodes); when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(uniKey); when(UnimgrMapper.getUniIid( any(DataBroker.class), any(IpAddress.class), any(LogicalDatastoreType.class))) .thenReturn(uniKey); verifyExecute(1, 0, 1, 0); // Case UNI2 : optionalNode.isPresent() when(MdsalUtils.readNode( any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))) .thenReturn(optionalOvsdbNode); verifyExecute(1, 0, 1, 0); // Case UNI3 : uni.getOvsdbNodeRef() == null, optionalNode.isPresent() when(uniAugmentation.getOvsdbNodeRef()).thenReturn(null); when(optionalOvsdbNode.isPresent()).thenReturn(true); when(MdsalUtils.readNode( any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))) .thenReturn(optUniNode) .thenReturn(optionalOvsdbNode); verifyExecute(2, 1, 3, 0); // Case UNI4 : uni.getOvsdbNodeRef() == null, !optionalNode.isPresent() when(optionalOvsdbNode.isPresent()).thenReturn(false); verifyExecute(2, 1, 4, 0); }
/* * (non-Javadoc) * * @see org.opendaylight.controller.md.sal.binding.api.DataChangeListener#onDataChanged(org. * opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) */ @Override public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) { LOG.info("OnDataChange, change: {}", change); try { // create for (Entry<InstanceIdentifier<?>, DataObject> entry : change.getCreatedData().entrySet()) { if (entry.getKey().getTargetType() == NetconfNode.class) { NodeId nodeId = helper.getNodeId(entry.getKey()); // To determine whether the equipment is support ofconfig helper.createOfconfigNode(nodeId); } } // update for (Entry<InstanceIdentifier<?>, DataObject> entry : change.getUpdatedData().entrySet()) { if (entry.getKey().getTargetType() == NetconfNode.class) { NodeId nodeId = helper.getNodeId(entry.getKey()); // To determine whether it is device ofconfig Optional<OfconfigTopoHandler> handlerOptional = helper.getOfconfigInventoryTopoHandler(nodeId); if (handlerOptional.isPresent()) { // We have a ofconfig device NetconfNode nnode = (NetconfNode) entry.getValue(); ConnectionStatus csts = nnode.getConnectionStatus(); switch (csts) { case Connected: { if (helper.isOfconfigDeviceNode(nnode)) { LOG.info("ofconfig device: {} is fully connected", nodeId.getValue()); } break; } case Connecting: { if (helper.isOfconfigDeviceNode(nnode)) { LOG.info("ofconfig device: {} was disconnected", nodeId.getValue()); } break; } case UnableToConnect: { if (helper.isOfconfigDeviceNode(nnode)) { LOG.info("ofconfig device: {} connection failed", nodeId.getValue()); helper.destroyOfconfigNode(nodeId); } break; } default: break; } } } } } catch (Exception e) { LOG.error("OnDataChange, change: {} fail", change, e); } }