From 27152eea5daa9611915b162425970d67594a1bc1 Mon Sep 17 00:00:00 2001 From: Kalvin Hom Date: Tue, 28 May 2013 16:41:12 -0700 Subject: [PATCH 1/1] NodeFactory service Added INodeFactory interface in SAL to handle creation of different Node types; Node will use INodeFactory to create Nodes that are not one of the preset types; StubNodeFactory for plugin stub creates Nodes of STUB type; Change-Id: I727eb7e4eae8daacf732b0856f6d0cc1d55ba749 Signed-off-by: Kalvin Hom --- .../stub/internal/Activator.java | 12 ++++- .../stub/internal/StubNodeFactory.java | 48 +++++++++++++++++++ .../controller/sal/core/Node.java | 12 +++-- .../controller/sal/utils/INodeFactory.java | 27 +++++++++++ 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeFactory.java create mode 100644 opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeFactory.java diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java index ff44fd4467..9c47b3b983 100644 --- a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java +++ b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java @@ -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.INodeFactory; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.discovery.IDiscoveryService; @@ -103,7 +104,7 @@ public class Activator extends ComponentActivatorAbstractBase { } public Object[] getGlobalImplementations() { - Object[] res = { FlowProgrammerService.class }; + Object[] res = { FlowProgrammerService.class, StubNodeFactory.class }; return res; } @@ -116,5 +117,14 @@ public class Activator extends ComponentActivatorAbstractBase { props.put("protocolPluginType", "STUB"); c.setInterface(IPluginInFlowProgrammerService.class.getName(), props); } + if (imp.equals(StubNodeFactory.class)) { + // export the service to be used by SAL + Dictionary props = new Hashtable(); + // Set the protocolPluginType property which will be used + // by SAL + props.put("protocolPluginType", "STUB"); + props.put("protocolName", "STUB"); + c.setInterface(INodeFactory.class.getName(), props); + } } } diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeFactory.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeFactory.java new file mode 100644 index 0000000000..c2ce473303 --- /dev/null +++ b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeFactory.java @@ -0,0 +1,48 @@ +package org.opendaylight.controller.protocol_plugins.stub.internal; + +import org.opendaylight.controller.sal.core.ConstructionException; +import org.opendaylight.controller.sal.utils.INodeFactory; +import org.opendaylight.controller.sal.core.Node; + +public class StubNodeFactory implements INodeFactory + { + 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 Node fromString(String nodeId, String nodeType){ + if(nodeType.equals("STUB")) + try{ + return new Node("STUB", Integer.parseInt(nodeId)); + } catch(ConstructionException e) + { + return null; + } + return null; + } +} diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java index ea9d93bdb6..4c7f278209 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java @@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import org.opendaylight.controller.sal.utils.HexEncode; +import org.opendaylight.controller.sal.utils.INodeFactory; +import org.opendaylight.controller.sal.utils.ServiceHelper; /** * Describe a generic network element in multiple SDNs technologies. A @@ -437,9 +439,13 @@ public class Node implements Serializable { return null; } } else { - // We need to lookup via OSGi service registry for an - // handler for this + //Use INodeFactory to create a Node of registered Node type. + //The protocol plugin being used depends on typeStr. + INodeFactory f = (INodeFactory) ServiceHelper + .getGlobalInstance(INodeFactory.class, new Node(), "(protocolName="+typeStr+")"); + if(f==null) + return null; + return f.fromString(IDStr, typeStr); } - return null; } } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeFactory.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeFactory.java new file mode 100644 index 0000000000..29ba7d6222 --- /dev/null +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeFactory.java @@ -0,0 +1,27 @@ + +/* + * 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; + +/** + * @file INodeFactory.java + * + * @brief Define the interface to be called when looking up custom node types + * + */ + +public interface INodeFactory { + /** + * Method to get custom node types from protocol plugins + * + */ + public Node fromString(String nodeId, String nodeType); +} -- 2.36.6