NodeConnector custom type 03/403/1
authorKalvin Hom <kahom@cisco.com>
Wed, 29 May 2013 19:18:06 +0000 (12:18 -0700)
committerKalvin Hom <kahom@cisco.com>
Wed, 29 May 2013 19:25:33 +0000 (12:25 -0700)
Changes for NodeConnector to create
new NodeConnector of custom type;

Created STUB implementation for
protocol plugin;

Reordered NodeFactory's arguments
to be consistent with other methods;

Change-Id: I7608005985f6f61f54d4339290191574ea6450c6
Signed-off-by: Kalvin Hom <kahom@cisco.com>
opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java
opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeConnectorFactory.java [new file with mode: 0644]
opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeFactory.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeConnectorFactory.java [new file with mode: 0644]
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeFactory.java

index 9c47b3b9839dec497ff8dc0d6a23d3e896aad35d..8e4c985c06b76ea6055717ae7a5d46370335673e 100644 (file)
@@ -7,6 +7,7 @@ import org.apache.felix.dm.Component;
 
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.opendaylight.controller.sal.core.IContainerListener;
+import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
 import org.opendaylight.controller.sal.utils.INodeFactory;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -104,7 +105,7 @@ public class Activator extends ComponentActivatorAbstractBase {
     }
     
     public Object[] getGlobalImplementations() {
-        Object[] res = { FlowProgrammerService.class, StubNodeFactory.class };
+        Object[] res = { FlowProgrammerService.class, StubNodeFactory.class, StubNodeConnectorFactory.class };
         return res;
     }
     
@@ -126,5 +127,15 @@ public class Activator extends ComponentActivatorAbstractBase {
             props.put("protocolName", "STUB");
             c.setInterface(INodeFactory.class.getName(), props);
         }
+        if (imp.equals(StubNodeConnectorFactory.class)) {
+            // export the service to be used by SAL
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            // Set the protocolPluginType property which will be used
+            // by SAL
+            props.put("protocolPluginType", "STUB");
+            props.put("protocolName", "STUB");
+            c.setInterface(INodeConnectorFactory.class.getName(), props);
+        }
+        
     }
 }
diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeConnectorFactory.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeConnectorFactory.java
new file mode 100644 (file)
index 0000000..0c1963d
--- /dev/null
@@ -0,0 +1,49 @@
+package org.opendaylight.controller.protocol_plugins.stub.internal;
+
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
+import org.opendaylight.controller.sal.core.Node;
+
+public class StubNodeConnectorFactory implements INodeConnectorFactory
+    {
+      void init() {
+      }
+
+      /**
+       * Function called by the dependency manager when at least one dependency
+       * become unsatisfied or when the component is shutting down because for
+       * example bundle is being stopped.
+       * 
+       */
+      void destroy() {
+      }
+
+      /**
+       * Function called by dependency manager after "init ()" is called and after
+       * the services provided by the class are registered in the service registry
+       * 
+       */
+      void start() {
+      }
+
+      /**
+       * Function called by the dependency manager before the services exported by
+       * the component are unregistered, this will be followed by a "destroy ()"
+       * calls
+       * 
+       */
+      void stop() {
+      }
+      
+      public NodeConnector fromStringNoNode(String typeStr, String IDStr,
+              Node n){
+          if(typeStr.equals("STUB")){
+              try {
+                  return new NodeConnector(typeStr, Integer.parseInt(IDStr), n);
+              } catch (Exception ex) {
+                  return null;
+              }
+          }
+          return null;
+      }
+}
index c2ce473303632b90602986b806690a5f225146e4..5b8ee12e567791f963caee163415f1db41616edf 100644 (file)
@@ -35,7 +35,7 @@ public class StubNodeFactory implements INodeFactory
       void stop() {
       }
       
-      public Node fromString(String nodeId, String nodeType){
+      public Node fromString(String nodeType, String nodeId){
           if(nodeType.equals("STUB"))
               try{
                   return new Node("STUB", Integer.parseInt(nodeId));
index 4c7f278209096e16c857f57c6f49d9da7ea94c9f..ef0c0667aa22eeff199ea83ad3769adfaba7cfb9 100644 (file)
@@ -445,7 +445,7 @@ public class Node implements Serializable {
                     .getGlobalInstance(INodeFactory.class, new Node(), "(protocolName="+typeStr+")");
             if(f==null)
                 return null;
-            return f.fromString(IDStr, typeStr);
+            return f.fromString(typeStr, IDStr);
         }
     }
 }
index 495af7970c7f0597ad50fc1e39863aafd3753fd6..9c49a315082d5af561fb5c1b6cf6e7ff94eabf87 100644 (file)
@@ -28,6 +28,9 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
+import org.opendaylight.controller.sal.utils.INodeFactory;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
 
 /**
  * Describe a generic network element attachment points,
@@ -602,8 +605,13 @@ public class NodeConnector implements Serializable {
                 return null;
             }
         } else {
-            // Lookup via OSGi service registry
+            //Use INodeConnectorFactory to create a NodeConnector of registered type.
+            //The protocol plugin being used depends on typeStr.
+            INodeConnectorFactory f = (INodeConnectorFactory) ServiceHelper
+                    .getGlobalInstance(INodeConnectorFactory.class, new NodeConnector(), "(protocolName="+typeStr+")");
+            if(f==null)
+                return null;
+            return f.fromStringNoNode(typeStr, IDStr, n);
         }
-        return null;
     }
 }
diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeConnectorFactory.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeConnectorFactory.java
new file mode 100644 (file)
index 0000000..317976d
--- /dev/null
@@ -0,0 +1,29 @@
+
+/*
+ * Copyright (c) 2013 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.utils;
+
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+
+/**
+ * @file   INodeFactory.java
+ *
+ * @brief  Define the interface to be called when looking up custom node types
+ *
+ */
+
+public interface INodeConnectorFactory {
+    /**
+     * Method to get custom NodeConnector types from protocol plugins
+     *
+     */
+    public NodeConnector fromStringNoNode(String typeStr, String IDStr,
+            Node n);
+}
index 29ba7d6222537cf24f2c4c922aefdfbdeeb79609..dce6eb03f6885329cfd910ade984366ff7a8e5c8 100644 (file)
@@ -23,5 +23,5 @@ public interface INodeFactory {
      * Method to get custom node types from protocol plugins
      *
      */
-    public Node fromString(String nodeId, String nodeType);
+    public Node fromString(String nodeType, String nodeId);
 }