BUG-1234 nodeType/ID in adaptors 54/8354/1
authorMichal Rehak <mirehak@cisco.com>
Wed, 25 Jun 2014 15:06:21 +0000 (17:06 +0200)
committerMichal Rehak <mirehak@cisco.com>
Wed, 25 Jun 2014 19:56:40 +0000 (21:56 +0200)
- node change: type MD_SAL -> OF, nodeId String->Long (=dpid)
- nodeConnector change: type MD_SAL -> OF, nodeConnectorId String->Short (=dpid)
- additional changes to statistic table conversions, topology - regarding type+id
- added unit tests

Change-Id: If7e2d6f49e558b9fe95d0a07cf86ed10eb28ff5a
Signed-off-by: Michal Rehak <mirehak@cisco.com>
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FlowProgrammerAdapter.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ToSalConversionsUtils.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyMapping.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/MDFlowMappingTest.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/NodeMappingTest.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/topology/test/TopologyMappingTest.java [new file with mode: 0644]

index ba68d52..d71858e 100644 (file)
@@ -83,6 +83,7 @@ public class ComponentActivator extends ComponentActivatorAbstractBase {
 
     @Override
     protected void init() {
+        // TODO: deprecated, should be removed soon
         NodeIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class);
         NodeConnectorIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class, NodeMapping.MD_SAL_TYPE);
     }
@@ -232,8 +233,8 @@ public class ComponentActivator extends ComponentActivatorAbstractBase {
 
     private Dictionary<String,Object> properties() {
         final Hashtable<String,Object> props = new Hashtable<String, Object>();
-        props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), NodeMapping.MD_SAL_TYPE);
-        props.put("protocolName", NodeMapping.MD_SAL_TYPE);
+        props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), NodeIDType.OPENFLOW);
+        props.put("protocolName", NodeIDType.OPENFLOW);
         return props;
     }
 }
index ba7377e..acb54ba 100644 (file)
@@ -247,7 +247,8 @@ public class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, Sa
 
         flowId = UUID.randomUUID();
         cache.put(flow, flowId);
-        return this.writeFlowAsync(MDFlowMapping.toMDFlow(flow, flowId.toString()), new NodeKey(new NodeId(node.getNodeIDString())));
+        return this.writeFlowAsync(MDFlowMapping.toMDFlow(flow, flowId.toString()), new NodeKey(
+                new NodeId(NodeMapping.OPENFLOW_ID_PREFIX + node.getID())));
     }
 
     private Future<RpcResult<TransactionStatus>> internalModifyFlowAsync(final Node node, final Flow oldFlow, final Flow newFlow, final long rid) {
@@ -261,7 +262,8 @@ public class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, Sa
         }
 
         cache.put(newFlow, flowId);
-        return this.writeFlowAsync(MDFlowMapping.toMDFlow(newFlow, flowId.toString()), new NodeKey(new NodeId(node.getNodeIDString())));
+        return this.writeFlowAsync(MDFlowMapping.toMDFlow(newFlow, flowId.toString()), new NodeKey(
+                new NodeId(NodeMapping.OPENFLOW_ID_PREFIX + node.getID())));
     }
 
     private Future<RpcResult<TransactionStatus>> internalRemoveFlowAsync(final Node node, final Flow adflow, final long rid) {
@@ -275,7 +277,8 @@ public class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, Sa
 
         final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow flow = MDFlowMapping.toMDFlow(adflow, flowId.toString());
         final DataModificationTransaction modification = this.dataBrokerService.beginTransaction();
-        modification.removeConfigurationData(flowPath(flow, new NodeKey(new NodeId(node.getNodeIDString()))));
+        modification.removeConfigurationData(flowPath(flow, new NodeKey(
+                new NodeId(NodeMapping.OPENFLOW_ID_PREFIX + node.getID()))));
         return modification.commit();
     }
 
index 2830165..5959d23 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.controller.sal.core.Edge;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.NodeTable;
+import org.opendaylight.controller.sal.core.NodeTable.NodeTableIDType;
 import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.core.UpdateType;
 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
@@ -489,7 +490,7 @@ public class InventoryAndReadAdapter implements IPluginInReadService, IPluginInI
                 }
 
                 try {
-                    final Node adNode = new Node(NodeMapping.MD_SAL_TYPE, NodeMapping.toADNodeId(node.getId()));
+                    final Node adNode = NodeMapping.toADNode(node.getId());
                     props.put(adNode, perNodePropMap);
                 } catch (ConstructionException e) {
                     LOG.warn("Failed to construct node for {}, skipping it", node, e);
@@ -572,7 +573,7 @@ public class InventoryAndReadAdapter implements IPluginInReadService, IPluginInI
         it.setLookupCount(tableStats.getPacketsLookedUp().getValue().longValue());
         it.setMatchedCount(tableStats.getPacketsMatched().getValue().longValue());
         it.setName(tableId.toString());
-        it.setNodeTable(new NodeTable(NodeMapping.MD_SAL_TYPE, tableId, node));
+        it.setNodeTable(new NodeTable(NodeTableIDType.OPENFLOW, tableId.byteValue(), node));
         return it;
     }
 
index 67af3e4..9b5d0e8 100644 (file)
@@ -357,7 +357,7 @@ public final class MDFlowMapping {
     }
 
     public static Uri toUri(final NodeConnector connector) {
-        return new NodeConnectorId(((String) connector.getID()));
+        return new NodeConnectorId(NodeMapping.OPENFLOW_ID_PREFIX + connector.getNode().getID() + ":" + (connector.getID()));
     }
 
     public static MacAddress toMacAddress(final byte[] bytes) {
index f5701bf..90134e6 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.controller.sal.core.Config;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.MacAddress;
 import org.opendaylight.controller.sal.core.Name;
+import org.opendaylight.controller.sal.core.Node.NodeIDType;
 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
 import org.opendaylight.controller.sal.core.PeerBandwidth;
 import org.opendaylight.controller.sal.core.Property;
@@ -61,7 +62,11 @@ import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 
 public final class NodeMapping {
-    public final static String MD_SAL_TYPE = "MD_SAL";
+
+    /** openflow id prefix */
+    public static final String OPENFLOW_ID_PREFIX = "openflow:";
+
+    public final static String MD_SAL_TYPE = "MD_SAL_DEPRECATED";
 
     private final static Class<Node> NODE_CLASS = Node.class;
 
@@ -77,8 +82,19 @@ public final class NodeMapping {
     }
 
     public static org.opendaylight.controller.sal.core.Node toADNode(final NodeId id) throws ConstructionException {
-        String aDNodeId = NodeMapping.toADNodeId(id);
-        return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, aDNodeId);
+        Long aDNodeId = openflowFullNodeIdToLong(NodeMapping.toADNodeId(id));
+        return new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, aDNodeId);
+    }
+
+    /**
+     * @param adNodeId
+     * @return
+     */
+    private static Long openflowFullNodeIdToLong(String adNodeId) {
+        if (adNodeId == null) {
+            return null;
+        }
+        return Long.valueOf(adNodeId.replaceFirst("^.*:", ""));
     }
 
     public static NodeId toNodeId(final InstanceIdentifier<?> id) {
@@ -88,6 +104,9 @@ public final class NodeMapping {
     }
 
     public static String toADNodeId(final NodeId nodeId) {
+        if (nodeId == null) {
+            return null;
+        }
         return nodeId.getValue();
     }
 
@@ -112,7 +131,7 @@ public final class NodeMapping {
         } else if (ncId.equals(toControllerNodeConnectorId(nodeId))) {
             return NodeConnectorIDType.CONTROLLER;
         }
-        return MD_SAL_TYPE;
+        return NodeConnectorIDType.OPENFLOW;
     }
 
     public static Object toADNodeConnectorId(final NodeConnectorId nodeConnectorId, final NodeId nodeId) {
@@ -121,7 +140,8 @@ public final class NodeMapping {
                 nodeConnectorId.equals(toControllerNodeConnectorId(nodeId))) {
             return org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID;
         }
-        return nodeConnectorId.getValue();
+
+        return (short) Long.valueOf(nodeConnectorId.getValue().replaceFirst("^.*:", "")).longValue();
     }
 
     public static NodeId toAdNodeId(final NodeConnectorId nodeConnectorId) {
@@ -145,9 +165,9 @@ public final class NodeMapping {
     }
 
     public static NodeRef toNodeRef(final org.opendaylight.controller.sal.core.Node node) {
-        Preconditions.checkArgument(MD_SAL_TYPE.equals(node.getType()));
-        final String nodeId = Arguments.<String>checkInstanceOf(node.getID(), String.class);
-        final NodeKey nodeKey = new NodeKey(new NodeId(nodeId));
+        Preconditions.checkArgument(NodeIDType.OPENFLOW.equals(node.getType()));
+        final Long nodeId = Arguments.<Long>checkInstanceOf(node.getID(), Long.class);
+        final NodeKey nodeKey = new NodeKey(new NodeId(OPENFLOW_ID_PREFIX+nodeId));
         final InstanceIdentifier<Node> nodePath = InstanceIdentifier.builder(Nodes.class).child(NODE_CLASS, nodeKey).toInstance();
         return new NodeRef(nodePath);
     }
@@ -170,7 +190,8 @@ public final class NodeMapping {
                 nodeConnectorId = toControllerNodeConnectorId(nodeId);
             }
         } else {
-            nodeConnectorId = new NodeConnectorId(Arguments.<String>checkInstanceOf(nodeConnector.getID(), String.class));
+            nodeConnectorId = new NodeConnectorId(OPENFLOW_ID_PREFIX
+                    + Arguments.<Short>checkInstanceOf(nodeConnector.getID(), Short.class));
         }
         final NodeConnectorKey connectorKey = new NodeConnectorKey(nodeConnectorId);
         final InstanceIdentifier<NodeConnector> path = nodePath.child(NODECONNECTOR_CLASS, connectorKey);
@@ -342,7 +363,7 @@ public final class NodeMapping {
     }
 
     public static MacAddress toADMacAddress(final NodeId id) {
-        final String nodeId = id.getValue().replaceAll("openflow:", "");
+        final String nodeId = id.getValue().replaceAll(OPENFLOW_ID_PREFIX, "");
         BigInteger nodeIdRaw = new BigInteger(nodeId);
         long lNodeId = nodeIdRaw.longValue();
         byte[] bytesFromDpid = ToSalConversionsUtils.bytesFromDpid(lNodeId);
index 97a25bf..d2243a4 100644 (file)
@@ -53,6 +53,7 @@ import org.opendaylight.controller.sal.action.SwPath;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
 import org.opendaylight.controller.sal.flowprogrammer.Flow;
 import org.opendaylight.controller.sal.match.Match;
 import org.opendaylight.controller.sal.match.MatchType;
@@ -376,10 +377,16 @@ public class ToSalConversionsUtils {
         return null;
     }
 
-    private static NodeConnector fromNodeConnectorRef(Uri uri, Node node) {
+    /**
+     * @param openflow nodeConnector uri
+     * @param node
+     * @return assembled nodeConnector
+     */
+    public static NodeConnector fromNodeConnectorRef(Uri uri, Node node) {
         NodeConnector nodeConnector = null;
         try {
-            nodeConnector = new NodeConnector(NodeMapping.MD_SAL_TYPE,node.getNodeIDString()+":"+uri.getValue(),node);
+            nodeConnector = new NodeConnector(NodeConnectorIDType.OPENFLOW,
+                    Short.valueOf(uri.getValue()), node);
         } catch (ConstructionException e) {
             e.printStackTrace();
         }
index 476a71a..6bc669f 100644 (file)
@@ -18,7 +18,9 @@ import org.opendaylight.controller.sal.compatibility.NodeMapping;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Edge;
 import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.Node.NodeIDType;
 import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
 import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.core.UpdateType;
 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
@@ -93,20 +95,20 @@ public final class TopologyMapping {
     }
 
     public static String toADNodeId(final NodeId nodeId) {
-        return nodeId.getValue();
+        return nodeId.getValue().replaceFirst("^.*:", "");
     }
 
     public static NodeConnector toADNodeConnector(final TpId source, final NodeId nodeId) throws ConstructionException {
         checkNotNull(source);
-        return new NodeConnector(NodeMapping.MD_SAL_TYPE, toADNodeConnectorId(source), toADNode(nodeId));
+        return new NodeConnector(NodeConnectorIDType.OPENFLOW, Short.valueOf(toADNodeConnectorId(source)), toADNode(nodeId));
     }
 
     public static String toADNodeConnectorId(final TpId nodeConnectorId) {
-        return nodeConnectorId.getValue();
+        return nodeConnectorId.getValue().replaceFirst("^.*:", "");
     }
 
     public static Node toADNode(final NodeId nodeId) throws ConstructionException {
         checkNotNull(nodeId);
-        return new Node(NodeMapping.MD_SAL_TYPE, toADNodeId(nodeId));
+        return new Node(NodeIDType.OPENFLOW, Long.valueOf(toADNodeId(nodeId)));
     }
 }
diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/MDFlowMappingTest.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/MDFlowMappingTest.java
new file mode 100644 (file)
index 0000000..4e5f318
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * 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.sal.compatibility.test;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.compatibility.MDFlowMapping;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.Node.NodeIDType;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+
+/**
+ * test for {@link MDFlowMapping}
+ */
+public class MDFlowMappingTest {
+
+    /**
+     * Test method for {@link org.opendaylight.controller.sal.compatibility.MDFlowMapping#toUri(org.opendaylight.controller.sal.core.NodeConnector)}.
+     * @throws ConstructionException
+     */
+    @Test
+    public void testToUri() throws ConstructionException {
+        Node node = new Node(NodeIDType.OPENFLOW, 41L);
+        NodeConnector connector = new NodeConnector(NodeConnectorIDType.OPENFLOW, (short) 42, node);
+        Uri observed = MDFlowMapping.toUri(connector );
+
+        Assert.assertEquals("openflow:41:42", observed.getValue());
+    }
+
+}
index b418e6d..f986310 100644 (file)
@@ -10,9 +10,17 @@ package org.opendaylight.controller.sal.compatibility.test;
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.sal.compatibility.NodeMapping;
+import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.MacAddress;
+import org.opendaylight.controller.sal.core.Node.NodeIDType;
+import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 /**
  * test of {@link NodeMapping} utility class
@@ -67,8 +75,118 @@ public class NodeMappingTest {
         observed = NodeMapping.toAdNodeId(null);
         Assert.assertNull(observed);
 
-        observed = NodeMapping.toAdNodeId(new NodeConnectorId("MD_SAL|openflow:5:2"));
-        Assert.assertEquals("MD_SAL|openflow:5", observed.getValue());
+        observed = NodeMapping.toAdNodeId(new NodeConnectorId("openflow:5:2"));
+        Assert.assertEquals("openflow:5", observed.getValue());
     }
 
+    /**
+     * Test method for
+     * {@link org.opendaylight.controller.sal.compatibility.NodeMapping#toADNode(NodeId)}
+     * .
+     */
+    @Test
+    public void testToAdNode1() {
+        org.opendaylight.controller.sal.core.Node observed;
+        try {
+            observed = NodeMapping.toADNode((NodeId) null);
+        } catch (NullPointerException | ConstructionException e) {
+            //expected
+        }
+
+        NodeId nodeId = new NodeId("openflow:1");
+        try {
+            observed = NodeMapping.toADNode(nodeId);
+            Assert.assertEquals("OF|00:00:00:00:00:00:00:01", observed.toString());
+        } catch (ConstructionException e) {
+            Assert.fail("should succeed to construct Node: "+e.getMessage());
+        }
+    }
+
+    /**
+     * Test method for
+     * {@link org.opendaylight.controller.sal.compatibility.NodeMapping#toNodeConnectorType(NodeConnectorId, NodeId)}
+     * .
+     */
+    @Test
+    public void testToNodeConnectorType() {
+        NodeConnectorId ncId;
+        NodeId nodeId = buildNodeId("1");
+
+        ncId = buildNodeConnectorId("1", "42");
+        Assert.assertEquals(NodeConnectorIDType.OPENFLOW, NodeMapping.toNodeConnectorType(ncId, nodeId ));
+
+        ncId = buildNodeConnectorId("1", "4294967293");
+        Assert.assertEquals(NodeConnectorIDType.CONTROLLER, NodeMapping.toNodeConnectorType(ncId, nodeId ));
+
+        ncId = buildNodeConnectorId("1", "4294967290");
+        Assert.assertEquals(NodeConnectorIDType.HWPATH, NodeMapping.toNodeConnectorType(ncId, nodeId ));
+
+        ncId = buildNodeConnectorId("1", "4294967294");
+        Assert.assertEquals(NodeConnectorIDType.SWSTACK, NodeMapping.toNodeConnectorType(ncId, nodeId ));
+    }
+
+    /**
+     * Test method for
+     * {@link org.opendaylight.controller.sal.compatibility.NodeMapping#toADNodeConnectorId(NodeConnectorId, NodeId)}
+     * .
+     */
+    @Test
+    public void testToAdNodeConnectorId() {
+        NodeConnectorId nodeConnectorId = buildNodeConnectorId("1", "2");
+        NodeId nodeId = buildNodeId("1");
+        Assert.assertEquals(Short.valueOf((short) 2), NodeMapping.toADNodeConnectorId(nodeConnectorId , nodeId));
+    }
+
+    /**
+     * Test method for
+     * {@link org.opendaylight.controller.sal.compatibility.NodeMapping#toNodeRef(Node)}
+     * .
+     * @throws ConstructionException
+     */
+    @Test
+    public void testToNodeRef() throws ConstructionException {
+        org.opendaylight.controller.sal.core.Node node = new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, 42L);
+        InstanceIdentifier<?> nodePath = NodeMapping.toNodeRef(node).getValue();
+
+        String observedId = nodePath.firstKeyOf(Node.class, NodeKey.class).getId().getValue();
+        Assert.assertEquals("openflow:42", observedId);
+    }
+
+    /**
+     * Test method for
+     * {@link org.opendaylight.controller.sal.compatibility.NodeMapping#toNodeConnectorRef(org.opendaylight.controller.sal.core.NodeConnector)}
+     * .
+     * @throws ConstructionException
+     */
+    @Test
+    public void testToNodeConnectorRef() throws ConstructionException {
+        org.opendaylight.controller.sal.core.Node node = new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, 42L);
+        org.opendaylight.controller.sal.core.NodeConnector nodeConnector =
+                new org.opendaylight.controller.sal.core.NodeConnector(
+                        NodeConnectorIDType.OPENFLOW, (short) 1, node);
+
+        InstanceIdentifier<?> nodeConnectorPath = NodeMapping.toNodeConnectorRef(nodeConnector ).getValue();
+        String observedNodeId = nodeConnectorPath.firstKeyOf(Node.class, NodeKey.class).getId().getValue();
+        Assert.assertEquals("openflow:42", observedNodeId);
+
+        String observedNodeConnectorId = nodeConnectorPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue();
+        Assert.assertEquals("openflow:1", observedNodeConnectorId);
+    }
+
+    /**
+     * @param nodeId
+     * @param portId
+     * @return nodeConnectorId
+     */
+    public static NodeConnectorId buildNodeConnectorId(String nodeId, String portId) {
+        return new NodeConnectorId(NodeConnectorIDType.OPENFLOW+"|" + nodeId + ":" + portId);
+    }
+
+    /**
+     * @param id
+     * @return nodeId
+     */
+    public static NodeId buildNodeId(String id) {
+        return new NodeId(NodeConnectorIDType.OPENFLOW+"|" + id);
+    }
 }
index 4d35097..0157bc0 100644 (file)
@@ -22,6 +22,8 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import junit.framework.Assert;
+
 import org.junit.Test;
 import org.opendaylight.controller.sal.action.Flood;
 import org.opendaylight.controller.sal.action.FloodAll;
@@ -47,6 +49,7 @@ import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.Node.NodeIDType;
+import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.flowprogrammer.Flow;
 import org.opendaylight.controller.sal.match.MatchType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
@@ -182,6 +185,17 @@ public class TestToSalConversionsUtils {
         checkSalFlow(salFlow);
     }
 
+    /**
+     * test of {@link ToSalConversionsUtils#fromNodeConnectorRef(Uri, Node)}
+     * @throws ConstructionException
+     */
+    @Test
+    public void testFromNodeConnectorRef() throws ConstructionException {
+        Node node = new Node(NodeIDType.OPENFLOW, 42L);
+        NodeConnector nodeConnector = ToSalConversionsUtils.fromNodeConnectorRef(new Uri("1"), node);
+        Assert.assertEquals("OF|1@OF|00:00:00:00:00:00:00:2a", nodeConnector.toString());
+    }
+
     private void checkSalMatch(org.opendaylight.controller.sal.match.Match match, MtchType mt) {
         switch (mt) {
         case other:
diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/topology/test/TopologyMappingTest.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/topology/test/TopologyMappingTest.java
new file mode 100644 (file)
index 0000000..b76370a
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * 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.sal.compatibility.topology.test;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.compatibility.topology.TopologyMapping;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+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;
+
+/**
+ * test for {@link TopologyMapping}
+ */
+public class TopologyMappingTest {
+
+    /**
+     * Test method for {@link org.opendaylight.controller.sal.compatibility.topology.TopologyMapping#toADNodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)}.
+     */
+    @Test
+    public void testToADNodeId() {
+        NodeId nodeId = new NodeId("openflow:1");
+        String observedNodeId = TopologyMapping.toADNodeId(nodeId);
+
+        Assert.assertEquals("1", observedNodeId);
+    }
+
+    /**
+     * Test method for {@link org.opendaylight.controller.sal.compatibility.topology.TopologyMapping#toADNodeConnector(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId, org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)}.
+     * @throws ConstructionException
+     */
+    @Test
+    public void testToADNodeConnector() throws ConstructionException {
+        NodeId nodeId = new NodeId("openflow:1");
+        TpId source = new TpId("foo:2");
+        NodeConnector observedNodeConnector = TopologyMapping.toADNodeConnector(source, nodeId);
+
+        Assert.assertEquals("OF|2@OF|00:00:00:00:00:00:00:01", observedNodeConnector.toString());
+    }
+
+    /**
+     * Test method for {@link org.opendaylight.controller.sal.compatibility.topology.TopologyMapping#toADNodeConnectorId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId)}.
+     */
+    @Test
+    public void testToADNodeConnectorId() {
+        TpId source = new TpId("foo:2");
+        String observedNodeConnectorId = TopologyMapping.toADNodeConnectorId(source);
+
+        Assert.assertEquals("2", observedNodeConnectorId);
+    }
+
+    /**
+     * Test method for {@link org.opendaylight.controller.sal.compatibility.topology.TopologyMapping#toADNode(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)}.
+     * @throws ConstructionException
+     */
+    @Test
+    public void testToADNode() throws ConstructionException {
+        NodeId nodeId = new NodeId("openflow:1");
+        Node observedNode = TopologyMapping.toADNode(nodeId);
+
+        Assert.assertEquals("OF|00:00:00:00:00:00:00:01", observedNode.toString());
+    }
+
+}

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.