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.md.compatibility.topologymanager
10 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
13 import org.opendaylight.controller.sal.core.NodeConnector
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
17 import org.opendaylight.controller.sal.core.Edge
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
20 import java.util.HashSet
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId
22 import org.opendaylight.controller.sal.compatibility.NodeMapping
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Source
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Destination
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey
30 import java.util.HashMap
32 class AdSalTopologyMapping {
34 val TopologyKey topologyMapping;
36 val InstanceIdentifier<Topology> topologyPath;
38 new(TopologyKey topology) {
39 topologyMapping = topology;
40 _topologyPath = InstanceIdentifier.builder(NetworkTopology).child(Topology, topology).toInstance;
43 def InstanceIdentifier<TerminationPoint> toTerminationPoint(NodeConnector connector) {
44 InstanceIdentifier.builder(topologyPath).child(Node).child(TerminationPoint, connector.toTerminationPointKey()).toInstance;
47 def Map<Edge, Set<org.opendaylight.controller.sal.core.Property>> toEdgePropertiesMap(Iterable<Link> links) {
48 val ret = new HashMap<Edge, Set<org.opendaylight.controller.sal.core.Property>>
50 ret.put(link.toEdge(), link.toProperties())
55 def Set<Edge> toEdges(Iterable<Link> links) {
56 val ret = new HashSet<Edge>
63 def Edge toEdge(Link link) {
64 val tail = link.source.toNodeConnector();
65 val head = link.destination.toNodeConnector();
66 return new Edge(tail, head);
69 def org.opendaylight.controller.sal.core.Node toAdNode(Node node) {
70 return node.nodeId.toAdNode;
73 def org.opendaylight.controller.sal.core.Node toAdNode(
74 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId node) {
75 val key = new NodeKey(new NodeId(node))
76 return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, key);
79 def NodeConnector toNodeConnector(Source ref) {
80 val adNode = ref.sourceNode.toAdNode();
81 val key = new NodeConnectorKey(new NodeConnectorId(ref.sourceTp))
82 return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
85 def NodeConnector toNodeConnector(Destination ref) {
86 val adNode = ref.destNode.toAdNode();
87 val key = new NodeConnectorKey(new NodeConnectorId(ref.destTp))
88 return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
91 def TerminationPointKey toTerminationPointKey(NodeConnector connector) {
94 def Set<org.opendaylight.controller.sal.core.Property> toProperties(Link link) {