Merge "Bug 499: Added support for old DOM Broker APIs."
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / utils / NodeConnectorCreator.java
index cbf3f95b2a776dc616ebd8606697b7b46aa06f2d..9cd551664cb945bb4a0c7ed279507a9870fe9b1e 100644 (file)
@@ -40,7 +40,7 @@ public abstract class NodeConnectorCreator {
         if (node.getType().equals(NodeIDType.OPENFLOW)) {
             try {
                 return new NodeConnector(NodeConnectorIDType.OPENFLOW,
-                        (Short) portId, node);
+                        portId, node);
             } catch (ConstructionException e1) {
                 logger.error("",e1);
                 return null;
@@ -49,6 +49,18 @@ public abstract class NodeConnectorCreator {
         return null;
     }
 
+    /**
+     * Generic NodeConnector creator
+     * The nodeConnector type is inferred from the node type
+     *
+     * @param portId The string representing the port id
+     * @param node The network node as {@link org.opendaylight.controller.sal.core.Node Node} object
+     * @return The corresponding {@link org.opendaylight.controller.sal.core.NodeConnector NodeConnector} object
+     */
+    public static NodeConnector createNodeConnector(String portId, Node node) {
+        return NodeConnector.fromString(String.format("%s|%s@%s", node.getType(), portId, node.toString()));
+    }
+
     /**
      * NodeConnector creator where NodeConnector type can be specified
      * Needed to create special internal node connectors (like software stack)
@@ -61,7 +73,11 @@ public abstract class NodeConnectorCreator {
     public static NodeConnector createNodeConnector(
             String nodeConnectorType, Object portId, Node node) {
         try {
-            return new NodeConnector(nodeConnectorType, portId, node);
+            if (nodeConnectorType.equals(Node.NodeIDType.OPENFLOW) && (portId.getClass() == String.class)) {
+                return new NodeConnector(nodeConnectorType, Short.parseShort((String) portId), node);
+            } else {
+                return new NodeConnector(nodeConnectorType, portId, node);
+            }
         } catch (ConstructionException e1) {
             logger.error("",e1);
             return null;