From 779fa90cecfb41f64fa4edda9f3a631aca43c0c1 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Thu, 2 Jan 2014 22:32:21 -0800 Subject: [PATCH] Fixed implementation of getNodeConnectorProps and getNodeProps Change-Id: If05e04129cf002ead7f07eafba66d07c1d66c4c5 Signed-off-by: Ed Warnicke --- .../InventoryAndReadAdapter.xtend | 64 ++++- .../sal/compatibility/NodeMapping.xtend | 218 ++++++++++-------- 2 files changed, 180 insertions(+), 102 deletions(-) diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend index 746d32ff16..56ca1b609c 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend @@ -64,6 +64,9 @@ import org.slf4j.LoggerFactory import static extension org.opendaylight.controller.sal.common.util.Arguments.* import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.* +import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader +import java.util.concurrent.ConcurrentHashMap +import java.util.Map class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventoryService, @@ -360,15 +363,64 @@ class InventoryAndReadAdapter implements IPluginInReadService, } override getNodeProps() { - - // FIXME: Read from MD-SAL inventory service - return null; + val props = new ConcurrentHashMap>() + + val nodes = readAllMDNodes() + for (node : nodes.node ) { + val fcn = node.getAugmentation(FlowCapableNode) + if(fcn != null) { + val perNodeProps = fcn.toADNodeProperties(node.id) + val perNodePropMap = new ConcurrentHashMap + if(perNodeProps != null ) { + for(perNodeProp : perNodeProps) { + perNodePropMap.put(perNodeProp.name,perNodeProp) + } + } + props.put(new Node(MD_SAL_TYPE, node.id.toADNodeId),perNodePropMap) + } + } + return props; + } + + private def readAllMDNodes() { + val nodesRef = InstanceIdentifier.builder(Nodes) + .toInstance + val reader = TypeSafeDataReader.forReader(dataService) + return reader.readOperationalData(nodesRef) + } + + private def readAllMDNodeConnectors(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node) { + val nodeRef = InstanceIdentifier.builder(Nodes) + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(node.id)) + .toInstance + val reader = TypeSafeDataReader.forReader(dataService) + return reader.readOperationalData(nodeRef).nodeConnector } override getNodeConnectorProps(Boolean refresh) { - - // FIXME: Read from MD-SAL Invcentory Service - return null; + // Note, because the MD-SAL has a unified data store, we can ignore the Boolean refresh, as we have no secondary + // data store to refresh from + val props = new ConcurrentHashMap>() + val nodes = readAllMDNodes() + for (node : nodes.node) { + val ncs = node.readAllMDNodeConnectors + if(ncs != null) { + for( nc : ncs ) { + val fcnc = nc.getAugmentation(FlowCapableNodeConnector) + if(fcnc != null) { + val ncps = fcnc.toADNodeConnectorProperties + val ncpsm = new ConcurrentHashMap + if(ncps != null) { + for(p : ncps) { + ncpsm.put(p.name,p) + } + } + props.put(nc.id.toADNodeConnector(node.id),ncpsm) + } + } + } + } + return props } private def FlowCapableNode readFlowCapableNode(NodeRef ref) { diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.xtend index f77cfcd67d..4ad91c2677 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.xtend +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.xtend @@ -46,22 +46,28 @@ import org.opendaylight.controller.sal.core.Capabilities import org.opendaylight.controller.sal.core.MacAddress import java.util.Date import org.opendaylight.controller.sal.core.TimeStamp +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowNodeConnector +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowNode public class NodeMapping { public static val MD_SAL_TYPE = "MD_SAL"; private static val NODE_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; - private static val NODECONNECTOR_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; - + private static val NODECONNECTOR_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node. + NodeConnector; private new() { throw new UnsupportedOperationException("Utility class. Instantiation is not allowed."); } public static def toADNode(InstanceIdentifier node) throws ConstructionException { - return new Node(MD_SAL_TYPE, node.toNodeId.toADNodeId); + return node.toNodeId.toADNode } - + + public static def toADNode(NodeId id) { + return new Node(MD_SAL_TYPE, id.toADNodeId); + } + public static def toNodeId(InstanceIdentifier node) { checkNotNull(node); checkNotNull(node.getPath()); @@ -71,55 +77,60 @@ public class NodeMapping { val nodeKey = item.getKey().checkInstanceOf(NodeKey); return nodeKey.id } - + public static def toADNodeId(NodeId nodeId) { checkNotNull(nodeId); return nodeId.value } - public static def toADNodeConnector(NodeConnectorRef source) throws ConstructionException { checkNotNull(source); val InstanceIdentifier path = checkNotNull(source.getValue()); - val node = path.toADNode(); checkArgument(path.path.size() >= 3); val arg = path.getPath().get(2); val item = arg.checkInstanceOf(IdentifiableItem); val connectorKey = item.getKey().checkInstanceOf(NodeConnectorKey); - return new NodeConnector(connectorKey.id.toNodeConnectorType(path.toNodeId), connectorKey.id.toADNodeConnectorId(path.toNodeId), node); + return connectorKey.id.toADNodeConnector(path.toNodeId) } - public static def toNodeConnectorType(NodeConnectorId ncId,NodeId nodeId) { + public static def toADNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId ncid, + org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nid) { + return new NodeConnector(ncid.toNodeConnectorType(nid), + ncid.toADNodeConnectorId(nid), nid.toADNode); + } + + public static def toNodeConnectorType(NodeConnectorId ncId, NodeId nodeId) { if (ncId.equals(nodeId.toLocalNodeConnectorId)) { return NodeConnector.NodeConnectorIDType.SWSTACK } else if (ncId.equals(nodeId.toNormalNodeConnectorId)) { return NodeConnector.NodeConnectorIDType.HWPATH - } else if (ncId.equals(nodeId.toControllerNodeConnectorId)){ + } else if (ncId.equals(nodeId.toControllerNodeConnectorId)) { return NodeConnector.NodeConnectorIDType.CONTROLLER } return MD_SAL_TYPE } - - public static def toADNodeConnectorId(NodeConnectorId nodeConnectorId,NodeId nodeId) { - if(nodeConnectorId.equals(nodeId.toLocalNodeConnectorId) || - nodeConnectorId.equals(nodeId.toNormalNodeConnectorId) || - nodeConnectorId.equals(nodeId.toControllerNodeConnectorId) - ) { + + public static def toADNodeConnectorId(NodeConnectorId nodeConnectorId, NodeId nodeId) { + if (nodeConnectorId.equals(nodeId.toLocalNodeConnectorId) || + nodeConnectorId.equals(nodeId.toNormalNodeConnectorId) || + nodeConnectorId.equals(nodeId.toControllerNodeConnectorId)) { return NodeConnector.SPECIALNODECONNECTORID } return nodeConnectorId.value } - - public static def toControllerNodeConnectorId(NodeId node) { + + public static def toControllerNodeConnectorId(NodeId node) { return new NodeConnectorId(node.value + ":" + 4294967293L) } - public static def toLocalNodeConnectorId(NodeId node) { + + public static def toLocalNodeConnectorId(NodeId node) { return new NodeConnectorId(node.value + ":" + 4294967294L) } - public static def toNormalNodeConnectorId(NodeId node) { + + public static def toNormalNodeConnectorId(NodeId node) { return new NodeConnectorId(node.value + ":" + 4294967290L) } - + public static def toNodeRef(Node node) { checkArgument(MD_SAL_TYPE.equals(node.getType())); var nodeId = node.ID.checkInstanceOf(String) @@ -127,21 +138,21 @@ public class NodeMapping { val nodePath = InstanceIdentifier.builder().node(Nodes).child(NODE_CLASS, nodeKey).toInstance(); return new NodeRef(nodePath); } - + public static def toNodeConnectorRef(NodeConnector nodeConnector) { val node = nodeConnector.node.toNodeRef(); val nodePath = node.getValue() as InstanceIdentifier var NodeConnectorId nodeConnectorId - if(nodeConnector.ID.equals(NodeConnector.SPECIALNODECONNECTORID)){ - if(nodeConnector.type.equals(NodeConnector.NodeConnectorIDType.SWSTACK)) { + if (nodeConnector.ID.equals(NodeConnector.SPECIALNODECONNECTORID)) { + if (nodeConnector.type.equals(NodeConnector.NodeConnectorIDType.SWSTACK)) { nodeConnectorId = nodePath.toNodeId.toLocalNodeConnectorId } else if (nodeConnector.type.equals(NodeConnector.NodeConnectorIDType.HWPATH)) { nodeConnectorId = nodePath.toNodeId.toNormalNodeConnectorId } else if (nodeConnector.type.equals(NodeConnector.NodeConnectorIDType.CONTROLLER)) { nodeConnectorId = nodePath.toNodeId.toControllerNodeConnectorId - } + } } else { - nodeConnectorId = new NodeConnectorId(nodeConnector.ID.checkInstanceOf(String)) + nodeConnectorId = new NodeConnectorId(nodeConnector.ID.checkInstanceOf(String)) } val connectorKey = new NodeConnectorKey(nodeConnectorId); val path = InstanceIdentifier.builder(nodePath).child(NODECONNECTOR_CLASS, connectorKey).toInstance(); @@ -151,152 +162,167 @@ public class NodeMapping { public static def toADNode(NodeRef node) throws ConstructionException { return toADNode(node.getValue()); } - + public static def toADNodeConnectorProperties(NodeConnectorUpdated nc) { - val props = new HashSet(); val fcncu = nc.getAugmentation(FlowCapableNodeConnectorUpdated) - if(fcncu != null) { - if(fcncu.currentFeature != null && fcncu.currentFeature.toAdBandwidth != null) { + if (fcncu != null) { + return fcncu.toADNodeConnectorProperties + } + return new HashSet(); + } + + public static def toADNodeConnectorProperties(FlowNodeConnector fcncu) { + val props = new HashSet(); + if (fcncu != null) { + if (fcncu.currentFeature != null && fcncu.currentFeature.toAdBandwidth != null) { props.add(fcncu.currentFeature.toAdBandwidth) } - if(fcncu.advertisedFeatures != null && fcncu.advertisedFeatures.toAdAdvertizedBandwidth != null) { + if (fcncu.advertisedFeatures != null && fcncu.advertisedFeatures.toAdAdvertizedBandwidth != null) { props.add(fcncu.advertisedFeatures.toAdAdvertizedBandwidth) } - if(fcncu.supported != null && fcncu.supported.toAdSupportedBandwidth != null) { + if (fcncu.supported != null && fcncu.supported.toAdSupportedBandwidth != null) { props.add(fcncu.supported.toAdSupportedBandwidth) } - if(fcncu.peerFeatures != null && fcncu.peerFeatures.toAdPeerBandwidth != null) { + if (fcncu.peerFeatures != null && fcncu.peerFeatures.toAdPeerBandwidth != null) { props.add(fcncu.peerFeatures.toAdPeerBandwidth) } - if(fcncu.name != null && fcncu.name.toAdName != null) { + if (fcncu.name != null && fcncu.name.toAdName != null) { props.add(fcncu.name.toAdName) } - if(fcncu.configuration != null && fcncu.configuration.toAdConfig != null) { + if (fcncu.configuration != null && fcncu.configuration.toAdConfig != null) { props.add(fcncu.configuration.toAdConfig) } - if(fcncu.state != null && fcncu.state.toAdState != null) { + if (fcncu.state != null && fcncu.state.toAdState != null) { props.add(fcncu.state.toAdState) } } return props } - + public static def toAdName(String name) { return new Name(name) - } - + } + public static def toAdConfig(PortConfig pc) { var Config config; - if(pc.PORTDOWN){ + if (pc.PORTDOWN) { config = new Config(Config.ADMIN_DOWN) } else { config = new Config(Config.ADMIN_UP) } return config } - + public static def toAdState(State s) { var org.opendaylight.controller.sal.core.State state - if(s.linkDown) { + if (s.linkDown) { state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_DOWN) } else { state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_UP) } return state } - + public static def toAdBandwidth(PortFeatures pf) { var Bandwidth bw = null - if (pf.is_10mbHd || pf.is_10mbFd ) { - bw= new Bandwidth(Bandwidth.BW10Mbps) - } else if (pf.is_100mbHd || pf.is_100mbFd ) { - bw= new Bandwidth(Bandwidth.BW100Mbps) - } else if (pf.is_1gbHd || pf.is_1gbFd ) { - bw= new Bandwidth(Bandwidth.BW1Gbps) - } else if (pf.is_1gbFd ) { - bw= new Bandwidth(Bandwidth.BW10Gbps) - } else if ( pf.is_10gbFd ) { - bw= new Bandwidth(Bandwidth.BW10Gbps) - } else if ( pf.is_40gbFd ) { - bw= new Bandwidth(Bandwidth.BW40Gbps) - } else if ( pf.is_100gbFd ) { - bw= new Bandwidth(Bandwidth.BW100Gbps) - } else if ( pf.is_1tbFd ) { - bw= new Bandwidth(Bandwidth.BW1Tbps) - } + if (pf.is_10mbHd || pf.is_10mbFd) { + bw = new Bandwidth(Bandwidth.BW10Mbps) + } else if (pf.is_100mbHd || pf.is_100mbFd) { + bw = new Bandwidth(Bandwidth.BW100Mbps) + } else if (pf.is_1gbHd || pf.is_1gbFd) { + bw = new Bandwidth(Bandwidth.BW1Gbps) + } else if (pf.is_1gbFd) { + bw = new Bandwidth(Bandwidth.BW10Gbps) + } else if (pf.is_10gbFd) { + bw = new Bandwidth(Bandwidth.BW10Gbps) + } else if (pf.is_40gbFd) { + bw = new Bandwidth(Bandwidth.BW40Gbps) + } else if (pf.is_100gbFd) { + bw = new Bandwidth(Bandwidth.BW100Gbps) + } else if (pf.is_1tbFd) { + bw = new Bandwidth(Bandwidth.BW1Tbps) + } return bw; } - + public static def toAdAdvertizedBandwidth(PortFeatures pf) { var AdvertisedBandwidth abw val bw = pf.toAdBandwidth - if(bw != null) { + if (bw != null) { abw = new AdvertisedBandwidth(bw.value) } return abw } - + public static def toAdSupportedBandwidth(PortFeatures pf) { var SupportedBandwidth sbw val bw = pf.toAdBandwidth - if(bw != null ) { + if (bw != null) { sbw = new SupportedBandwidth(bw.value) } return sbw } - + public static def toAdPeerBandwidth(PortFeatures pf) { var PeerBandwidth pbw val bw = pf.toAdBandwidth - if(bw != null) { + if (bw != null) { pbw = new PeerBandwidth(bw.value) } return pbw } - + public static def toADNodeProperties(NodeUpdated nu) { + val fcnu = nu.getAugmentation(FlowCapableNodeUpdated) + if (fcnu != null) { + return fcnu.toADNodeProperties(nu.id) + } + return new HashSet(); + + } + + public static def toADNodeProperties(FlowNode fcnu, NodeId id) { val props = new HashSet(); - val fcnu = nu.getAugmentation(FlowCapableNodeUpdated) - if(fcnu != null) { - props.add(toADTimestamp) - // props.add(fcnu.supportedActions.toADActions) - TODO - if(nu.id != null) { - props.add(nu.id.toADMacAddress) - } - if(fcnu.switchFeatures != null) { - if(fcnu.switchFeatures.maxTables != null) { - props.add(fcnu.switchFeatures.maxTables.toADTables) - } - if(fcnu.switchFeatures.capabilities != null) { + if (fcnu != null) { + props.add(toADTimestamp) + + // props.add(fcnu.supportedActions.toADActions) - TODO + if (id != null) { + props.add(id.toADMacAddress) + } + if (fcnu.switchFeatures != null) { + if (fcnu.switchFeatures.maxTables != null) { + props.add(fcnu.switchFeatures.maxTables.toADTables) + } + if (fcnu.switchFeatures.capabilities != null) { props.add(fcnu.switchFeatures.capabilities.toADCapabiliities) - } - if(fcnu.switchFeatures.maxBuffers != null) { + } + if (fcnu.switchFeatures.maxBuffers != null) { props.add(fcnu.switchFeatures.maxBuffers.toADBuffers) - } - } - } - return props; - + } + } + } + return props; } - + public static def toADTimestamp() { val date = new Date(); - val timestamp = new TimeStamp(date.time,"connectedSince") + val timestamp = new TimeStamp(date.time, "connectedSince") return timestamp; } - + public static def toADMacAddress(NodeId id) { - return new MacAddress(Long.parseLong(id.value.replaceAll("openflow:","")).longValue.bytesFromDpid) + return new MacAddress(Long.parseLong(id.value.replaceAll("openflow:", "")).longValue.bytesFromDpid) } - + public static def toADTables(Short tables) { return new Tables(tables.byteValue) } - + public static def toADCapabiliities(List> capabilities) { var int b - for(capability : capabilities) { - if(capability.equals(FlowFeatureCapabilityFlowStats)) { + for (capability : capabilities) { + if (capability.equals(FlowFeatureCapabilityFlowStats)) { b = Capabilities.CapabilitiesType.FLOW_STATS_CAPABILITY.value.bitwiseOr(b) } else if (capability.equals(FlowFeatureCapabilityTableStats)) { b = Capabilities.CapabilitiesType.TABLE_STATS_CAPABILITY.value.bitwiseOr(b) @@ -314,9 +340,9 @@ public class NodeMapping { } return new Capabilities(b) } - + public static def toADBuffers(Long buffers) { return new Buffers(buffers.intValue) } - + } -- 2.36.6