Fix to Topology Adapter to properly handle links coming and going
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / topology / TopologyMapping.xtend
1 package org.opendaylight.controller.sal.compatibility.topology
2
3 import com.google.common.collect.FluentIterable
4 import java.util.Collections
5 import java.util.List
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.rev130712.NodeId
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.TpId
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.Topology
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.topology.Link
17
18 import static com.google.common.base.Preconditions.*
19 import static org.opendaylight.controller.sal.compatibility.NodeMapping.*
20
21 class TopologyMapping {
22     
23     private new() {
24         throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
25     }
26     
27     public static def toADEdgeUpdates(Topology topology) {
28         val List<TopoEdgeUpdate> result = new CopyOnWriteArrayList<TopoEdgeUpdate>()
29         return FluentIterable.from(topology.link).transform[toAdEdge(topology).toTopoEdgeUpdate].copyInto(result)
30     }
31     
32     public static def toAdEdge(Link link,Topology topology) {
33         val adSrc = link.source.sourceTp.toADNodeConnector(link.source.sourceNode)
34         val adDst = link.destination.destTp.toADNodeConnector(link.destination.destNode)
35         return new Edge(adSrc,adDst); 
36     }
37     
38     public static def toTopoEdgeUpdate(Edge e) {
39         return toTopoEdgeUpdate(e,UpdateType.ADDED)
40     }
41     
42     public static def toTopoEdgeUpdate(Edge e,UpdateType type) {
43         return new TopoEdgeUpdate(e,Collections.emptySet,type)
44     }
45     
46     public static def toADNodeId(NodeId nodeId) {
47         checkNotNull(nodeId);
48         return nodeId.value
49     }
50     public static def toADNodeConnector(TpId source,NodeId nodeId) throws ConstructionException {
51         checkNotNull(source);
52         return new NodeConnector(MD_SAL_TYPE,source.toADNodeConnectorId,nodeId.toADNode)
53     }
54     
55     public static def toADNodeConnectorId(TpId nodeConnectorId) {
56         return nodeConnectorId.value
57     }
58     
59     public static def toADNode(NodeId nodeId) {
60         checkNotNull(nodeId);
61         return new Node(MD_SAL_TYPE,nodeId.toADNodeId);       
62     }
63 }