--- /dev/null
+/**
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.compatibility.topology;
+
+import java.util.Iterator;
+
+import org.opendaylight.controller.sal.compatibility.InventoryMapping;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+import com.google.common.base.Splitter;
+
+public class TopologyMapping {
+ private static final Splitter QUAD_COLON_SPLITTER = Splitter.on("::::");
+
+ public TopologyMapping(final TopologyKey path, final InstanceIdentifier<Topology> key) {
+ // No-op for now. Multi-instance will require fixing InventoryMapping first.
+ }
+
+ public Edge toAdTopologyEdge(final InstanceIdentifier<Link> identifier) throws ConstructionException {
+ @SuppressWarnings("unchecked")
+ final LinkKey linkKey = ((KeyedInstanceIdentifier<Link, LinkKey>)identifier).getKey();
+
+ final Iterator<String> it = QUAD_COLON_SPLITTER.split(linkKey.getLinkId().getValue()).iterator();
+ final NodeConnector tail = InventoryMapping.nodeConnectorFromId(it.next());
+ final NodeConnector head = InventoryMapping.nodeConnectorFromId(it.next());
+ return new Edge(tail, head);
+ }
+
+ public NodeConnector toAdTopologyNodeConnector(final InstanceIdentifier<TerminationPoint> identifier) {
+ @SuppressWarnings("unchecked")
+ final TerminationPointKey tpKey = ((KeyedInstanceIdentifier<TerminationPoint, TerminationPointKey>)identifier).getKey();
+
+ return InventoryMapping.nodeConnectorFromId(tpKey.getTpId().getValue());
+ }
+
+ public org.opendaylight.controller.sal.core.Node toAdTopologyNode(final InstanceIdentifier<Node> identifier) {
+ @SuppressWarnings("unchecked")
+ final NodeKey nodeKey = ((KeyedInstanceIdentifier<Node, NodeKey>)identifier).getKey();
+
+ return InventoryMapping.nodeFromNodeId(nodeKey.getNodeId().getValue());
+ }
+
+ public NodeKey toTopologyNodeKey(final org.opendaylight.controller.sal.core.Node node) {
+ return new NodeKey(new NodeId(InventoryMapping.toNodeId(node)));
+ }
+
+ public TerminationPointKey toTopologyTerminationPointKey(final NodeConnector nc) {
+ return new TerminationPointKey(new TpId(InventoryMapping.toNodeConnectorId(nc)));
+ }
+
+ public LinkKey toTopologyLinkKey(final Edge edge) {
+ final TerminationPointKey sourceTp = toTopologyTerminationPointKey(edge.getTailNodeConnector());
+ final TerminationPointKey destTp = toTopologyTerminationPointKey(edge.getHeadNodeConnector());
+
+ final StringBuilder sb = new StringBuilder();
+ sb.append(sourceTp.getTpId().toString());
+ sb.append("::::");
+ sb.append(destTp.getTpId().toString());
+ return new LinkKey(new LinkId(sb.toString()));
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.md.compatibility.topology
-
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
-import org.opendaylight.controller.sal.core.Edge
-import java.util.Set
-import org.opendaylight.controller.sal.core.Property
-import org.opendaylight.controller.sal.core.NodeConnector
-
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
-import org.opendaylight.controller.sal.compatibility.InventoryMapping
-class TopologyMapping {
-
- new(TopologyKey path, InstanceIdentifier<Topology> key) {
- // NOOP
- }
-
- def Edge toAdTopologyEdge(InstanceIdentifier<Link> identifier) {
- val linkKey = (identifier.path.last as IdentifiableItem<Link,LinkKey>).key;
- val components = linkKey.linkId.value.split("::::");
- val tail = InventoryMapping.nodeConnectorFromId(components.get(0));
- val head = InventoryMapping.nodeConnectorFromId(components.get(1));
- return new Edge(tail, head);
- }
-
- def NodeConnector toAdTopologyNodeConnector(InstanceIdentifier<TerminationPoint> identifier) {
- val tpKey = (identifier.path.last as IdentifiableItem<TerminationPoint,TerminationPointKey>).key;
- return InventoryMapping.nodeConnectorFromId(tpKey.tpId.value);
- }
-
- def org.opendaylight.controller.sal.core.Node toAdTopologyNode(
- InstanceIdentifier<Node> identifier) {
- val tpKey = (identifier.path.last as IdentifiableItem<Node,NodeKey>).key;
- return InventoryMapping.nodeFromNodeId(tpKey.nodeId.value);
- }
-
-
-
- def NodeKey toTopologyNodeKey(org.opendaylight.controller.sal.core.Node node) {
- val nodeId = new NodeId(InventoryMapping.toNodeId(node));
- return new NodeKey(nodeId);
- }
-
- def TerminationPointKey toTopologyTerminationPointKey(NodeConnector nc) {
- val node = nc.node;
- val nodeId = new TpId(InventoryMapping.toNodeConnectorId(nc))
- return new TerminationPointKey(nodeId);
- }
-
- def LinkKey toTopologyLinkKey(Edge edge) {
- val sourceTp = edge.tailNodeConnector.toTopologyTerminationPointKey;
- val destTp = edge.headNodeConnector.toTopologyTerminationPointKey;
- val linkId = new LinkId('''«sourceTp.tpId»::::«destTp.tpId»''')
- return new LinkKey(linkId);
- }
-}