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.topology;
10 import java.util.Iterator;
12 import org.opendaylight.controller.sal.compatibility.InventoryMapping;
13 import org.opendaylight.controller.sal.core.ConstructionException;
14 import org.opendaylight.controller.sal.core.Edge;
15 import org.opendaylight.controller.sal.core.NodeConnector;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
30 import com.google.common.base.Splitter;
32 public class TopologyMapping {
33 private static final Splitter QUAD_COLON_SPLITTER = Splitter.on("::::");
35 public TopologyMapping(final TopologyKey path, final InstanceIdentifier<Topology> key) {
36 // No-op for now. Multi-instance will require fixing InventoryMapping first.
39 public Edge toAdTopologyEdge(final InstanceIdentifier<Link> identifier) throws ConstructionException {
40 @SuppressWarnings("unchecked")
41 final LinkKey linkKey = ((KeyedInstanceIdentifier<Link, LinkKey>)identifier).getKey();
43 final Iterator<String> it = QUAD_COLON_SPLITTER.split(linkKey.getLinkId().getValue()).iterator();
44 final NodeConnector tail = InventoryMapping.nodeConnectorFromId(it.next());
45 final NodeConnector head = InventoryMapping.nodeConnectorFromId(it.next());
46 return new Edge(tail, head);
49 public NodeConnector toAdTopologyNodeConnector(final InstanceIdentifier<TerminationPoint> identifier) {
50 @SuppressWarnings("unchecked")
51 final TerminationPointKey tpKey = ((KeyedInstanceIdentifier<TerminationPoint, TerminationPointKey>)identifier).getKey();
53 return InventoryMapping.nodeConnectorFromId(tpKey.getTpId().getValue());
56 public org.opendaylight.controller.sal.core.Node toAdTopologyNode(final InstanceIdentifier<Node> identifier) {
57 @SuppressWarnings("unchecked")
58 final NodeKey nodeKey = ((KeyedInstanceIdentifier<Node, NodeKey>)identifier).getKey();
60 return InventoryMapping.nodeFromNodeId(nodeKey.getNodeId().getValue());
63 public NodeKey toTopologyNodeKey(final org.opendaylight.controller.sal.core.Node node) {
64 return new NodeKey(new NodeId(InventoryMapping.toNodeId(node)));
67 public TerminationPointKey toTopologyTerminationPointKey(final NodeConnector nc) {
68 return new TerminationPointKey(new TpId(InventoryMapping.toNodeConnectorId(nc)));
71 public LinkKey toTopologyLinkKey(final Edge edge) {
72 final TerminationPointKey sourceTp = toTopologyTerminationPointKey(edge.getTailNodeConnector());
73 final TerminationPointKey destTp = toTopologyTerminationPointKey(edge.getHeadNodeConnector());
75 final StringBuilder sb = new StringBuilder();
76 sb.append(sourceTp.getTpId().toString());
78 sb.append(destTp.getTpId().toString());
79 return new LinkKey(new LinkId(sb.toString()));