2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.compatibility.topology
10 import com.google.common.collect.FluentIterable
11 import java.util.Collections
13 import java.util.concurrent.CopyOnWriteArrayList
14 import org.opendaylight.controller.sal.core.ConstructionException
15 import org.opendaylight.controller.sal.core.Edge
16 import org.opendaylight.controller.sal.core.Node
17 import org.opendaylight.controller.sal.core.NodeConnector
18 import org.opendaylight.controller.sal.core.UpdateType
19 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
25 import static com.google.common.base.Preconditions.*
26 import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.*
27 import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector
30 import org.slf4j.LoggerFactory
32 class TopologyMapping {
33 private static val LOG = LoggerFactory.getLogger(TopologyMapping);
35 throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
38 public static def toADEdgeUpdates(Topology topology,TypeSafeDataReader reader) {
39 val List<TopoEdgeUpdate> result = new CopyOnWriteArrayList<TopoEdgeUpdate>()
40 return FluentIterable.from(topology.link).transform[toAdEdge(topology).toTopoEdgeUpdate(reader)].copyInto(result)
43 public static def toAdEdge(Link link,Topology topology) {
44 val adSrc = link.source.sourceTp.toADNodeConnector(link.source.sourceNode)
45 val adDst = link.destination.destTp.toADNodeConnector(link.destination.destNode)
46 return new Edge(adSrc,adDst);
49 public static def toTopoEdgeUpdate(Edge e,TypeSafeDataReader reader) {
50 return toTopoEdgeUpdate(e,UpdateType.ADDED,reader)
53 public static def toTopoEdgeUpdate(Edge e,UpdateType type,TypeSafeDataReader reader) {
54 return new TopoEdgeUpdate(e,e.toAdEdgeProperties(reader),type)
57 public static def toAdEdgeProperties(Edge e,TypeSafeDataReader reader) {
58 val ncref = e.tailNodeConnector.toNodeConnectorRef
60 LOG.debug("Edge {} ncref {}",e,ncref)
63 val ncInstanceId = (ncref.value as InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>)
64 if(ncInstanceId == null) {
65 LOG.debug("Edge {} ncref {}",e,ncref)
68 val nc = reader.readOperationalData(ncInstanceId)
72 return nc.toADNodeConnectorProperties
75 public static def toADNodeId(NodeId nodeId) {
79 public static def toADNodeConnector(TpId source,NodeId nodeId) throws ConstructionException {
81 return new NodeConnector(MD_SAL_TYPE,source.toADNodeConnectorId,nodeId.toADNode)
84 public static def toADNodeConnectorId(TpId nodeConnectorId) {
85 return nodeConnectorId.value
88 public static def toADNode(NodeId nodeId) {
90 return new Node(MD_SAL_TYPE,nodeId.toADNodeId);