1 package org.opendaylight.controller.sal.compatibility.topology
3 import com.google.common.collect.FluentIterable
4 import java.util.Collections
6 import java.util.concurrent.CopyOnWriteArrayList
7 import org.opendaylight.controller.sal.core.ConstructionException
8 import org.opendaylight.controller.sal.core.Edge
9 import org.opendaylight.controller.sal.core.Node
10 import org.opendaylight.controller.sal.core.NodeConnector
11 import org.opendaylight.controller.sal.core.UpdateType
12 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
18 import static com.google.common.base.Preconditions.*
19 import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.*
20 import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector
23 import org.slf4j.LoggerFactory
25 class TopologyMapping {
26 private static val LOG = LoggerFactory.getLogger(TopologyMapping);
28 throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
31 public static def toADEdgeUpdates(Topology topology,TypeSafeDataReader reader) {
32 val List<TopoEdgeUpdate> result = new CopyOnWriteArrayList<TopoEdgeUpdate>()
33 return FluentIterable.from(topology.link).transform[toAdEdge(topology).toTopoEdgeUpdate(reader)].copyInto(result)
36 public static def toAdEdge(Link link,Topology topology) {
37 val adSrc = link.source.sourceTp.toADNodeConnector(link.source.sourceNode)
38 val adDst = link.destination.destTp.toADNodeConnector(link.destination.destNode)
39 return new Edge(adSrc,adDst);
42 public static def toTopoEdgeUpdate(Edge e,TypeSafeDataReader reader) {
43 return toTopoEdgeUpdate(e,UpdateType.ADDED,reader)
46 public static def toTopoEdgeUpdate(Edge e,UpdateType type,TypeSafeDataReader reader) {
47 return new TopoEdgeUpdate(e,e.toAdEdgeProperties(reader),type)
50 public static def toAdEdgeProperties(Edge e,TypeSafeDataReader reader) {
51 val ncref = e.tailNodeConnector.toNodeConnectorRef
53 LOG.debug("Edge {} ncref {}",e,ncref)
56 val ncInstanceId = (ncref.value as InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>)
57 if(ncInstanceId == null) {
58 LOG.debug("Edge {} ncref {}",e,ncref)
61 val nc = reader.readOperationalData(ncInstanceId)
65 return nc.toADNodeConnectorProperties
68 public static def toADNodeId(NodeId nodeId) {
72 public static def toADNodeConnector(TpId source,NodeId nodeId) throws ConstructionException {
74 return new NodeConnector(MD_SAL_TYPE,source.toADNodeConnectorId,nodeId.toADNode)
77 public static def toADNodeConnectorId(TpId nodeConnectorId) {
78 return nodeConnectorId.value
81 public static def toADNode(NodeId nodeId) {
83 return new Node(MD_SAL_TYPE,nodeId.toADNodeId);