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 java.util.HashMap;
11 import java.util.HashSet;
15 import org.opendaylight.controller.sal.compatibility.NodeMapping;
16 import org.opendaylight.controller.sal.core.ConstructionException;
17 import org.opendaylight.controller.sal.core.Edge;
18 import org.opendaylight.controller.sal.core.NodeConnector;
19 import org.opendaylight.controller.sal.core.Property;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Destination;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Source;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 public class AdSalTopologyMapping {
36 private final InstanceIdentifier<Topology> topologyPath;
38 public AdSalTopologyMapping(final TopologyKey topology) {
39 this.topologyPath = InstanceIdentifier.builder(NetworkTopology.class)
40 .child(Topology.class, topology).toInstance();
43 public InstanceIdentifier<Topology> getTopologyPath() {
47 public InstanceIdentifier<TerminationPoint> toTerminationPoint(final NodeConnector connector) {
48 return getTopologyPath().builder()
50 .child(TerminationPoint.class, toTerminationPointKey(connector))
54 public Map<Edge,Set<Property>> toEdgePropertiesMap(final Iterable<Link> links) {
55 final HashMap<Edge,Set<Property>> ret = new HashMap<>();
56 for (final Link link : links) {
58 ret.put(toEdge(link), toProperties(link));
59 } catch (ConstructionException e) {
60 throw new IllegalStateException(String.format("Failed to create edge properties for {}", link), e);
66 public static Set<Edge> toEdges(final Iterable<Link> links) throws ConstructionException {
67 final HashSet<Edge> ret = new HashSet<Edge>();
68 for (final Link link : links) {
69 ret.add(toEdge(link));
74 public static Edge toEdge(final Link link) throws ConstructionException {
75 final NodeConnector tail = toNodeConnector(link.getSource());
76 final NodeConnector head = toNodeConnector(link.getDestination());
77 return new Edge(tail, head);
80 public static org.opendaylight.controller.sal.core.Node toAdNode(final Node node) throws ConstructionException {
81 return toAdNode(node.getNodeId());
84 public static org.opendaylight.controller.sal.core.Node toAdNode(final NodeId node) throws ConstructionException {
85 final NodeKey key = new NodeKey(
86 new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId(node));
87 return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, key);
90 public static NodeConnector toNodeConnector(final Source ref) throws ConstructionException {
91 final org.opendaylight.controller.sal.core.Node adNode = toAdNode(ref.getSourceNode());
92 final NodeConnectorKey key = new NodeConnectorKey(new NodeConnectorId(ref.getSourceTp()));
93 return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
96 public static NodeConnector toNodeConnector(final Destination ref) throws ConstructionException {
97 final org.opendaylight.controller.sal.core.Node adNode = toAdNode(ref.getDestNode());
98 final NodeConnectorKey key = new NodeConnectorKey(new NodeConnectorId(ref.getDestTp()));
99 return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
102 public TerminationPointKey toTerminationPointKey(final NodeConnector connector) {
106 public Set<Property> toProperties(final Link link) {