import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import org.opendaylight.controller.sal.action.SetNwDst;
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.Node.NodeIDType;
+import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.flowprogrammer.Flow;
import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
import org.opendaylight.controller.sal.match.Match;
import org.opendaylight.controller.sal.match.MatchType;
-import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.sal.utils.EtherTypes;
+import org.opendaylight.controller.sal.utils.GlobalConstants;
import org.opendaylight.controller.sal.utils.IPProtocols;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
.getLogger(FlowProgrammerService.class);
private ConcurrentHashMap<String, IPluginInFlowProgrammerService> pluginFlowProgrammer;
private Set<IFlowProgrammerListener> listener;
+ private AtomicLong seq;
public FlowProgrammerService() {
pluginFlowProgrammer = new ConcurrentHashMap<String, IPluginInFlowProgrammerService>();
listener = new HashSet<IFlowProgrammerListener>();
+ seq = new AtomicLong();
+ /*
+ * This Request ID generator starts with 1. Each aysnc message is
+ * associated with an unique Request ID (!= 0).
+ */
+ seq.lazySet(1);
}
/**
* Function called by the dependency manager when all the required
* dependencies are satisfied
- *
+ *
*/
void init() {
logger.debug("INIT called!");
* 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() {
// Clear previous registration to avoid they are left hanging
/**
* 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() {
logger.debug("START called!");
* 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() {
logger.debug("STOP called!");
}
// Set the reference to the plugin flow programmer
- public void setService(Map props, IPluginInFlowProgrammerService s) {
+ public void setService(Map<String, Object> props, IPluginInFlowProgrammerService s) {
if (this.pluginFlowProgrammer == null) {
logger.error("pluginFlowProgrammer store null");
return;
}
- logger.trace("Got a service set request {}", s);
- String type = null;
- for (Object e : props.entrySet()) {
- Map.Entry entry = (Map.Entry) e;
- logger.trace("Prop key:({}) value:({})", entry.getKey(),
- entry.getValue());
+ if (logger.isTraceEnabled()) {
+ logger.trace("Got a service set request {}", s);
+ for (Map.Entry<String, Object> entry : props.entrySet()) {
+ logger.trace("Prop key:({}) value:({})", entry.getKey(), entry.getValue());
+ }
}
- Object value = props.get("protocolPluginType");
+ String type = null;
+ Object value = props.get(GlobalConstants.PROTOCOLPLUGINTYPE.toString());
if (value instanceof String) {
type = (String) value;
}
}
}
- public void unsetService(Map props, IPluginInFlowProgrammerService s) {
+ public void unsetService(Map<String, Object> props, IPluginInFlowProgrammerService s) {
if (this.pluginFlowProgrammer == null) {
logger.error("pluginFlowProgrammer store null");
return;
}
- String type = null;
logger.debug("Received unsetpluginFlowProgrammer request");
- for (Object e : props.entrySet()) {
- Map.Entry entry = (Map.Entry) e;
- logger.trace("Prop key:({}) value:({})", entry.getKey(),
- entry.getValue());
+ if (logger.isTraceEnabled()) {
+ logger.trace("Got a service set request {}", s);
+ for (Map.Entry<String, Object> entry : props.entrySet()) {
+ logger.trace("Prop key:({}) value:({})", entry.getKey(), entry.getValue());
+ }
}
- Object value = props.get("protocoloPluginType");
+ String type = null;
+ Object value = props.get(GlobalConstants.PROTOCOLPLUGINTYPE.toString());
if (value instanceof String) {
type = (String) value;
}
return new Status(StatusCode.NOSERVICE, "Plugin unuvailable");
}
+ @Override
+ public Status addFlowAsync(Node node, Flow flow) {
+ if (pluginFlowProgrammer != null) {
+ if (this.pluginFlowProgrammer.get(node.getType()) != null) {
+ return this.pluginFlowProgrammer.get(node.getType()).addFlowAsync(
+ node, flow, getNextRid());
+ }
+ }
+ return new Status(StatusCode.NOSERVICE, "Plugin unuvailable");
+ }
+
+ @Override
+ public Status removeFlowAsync(Node node, Flow flow) {
+ if (pluginFlowProgrammer != null) {
+ if (this.pluginFlowProgrammer.get(node.getType()) != null) {
+ return this.pluginFlowProgrammer.get(node.getType())
+ .removeFlowAsync(node, flow, getNextRid());
+ }
+ }
+ return new Status(StatusCode.NOSERVICE, "Plugin unuvailable");
+ }
+
+ @Override
+ public Status modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow) {
+ if (pluginFlowProgrammer != null) {
+ if (this.pluginFlowProgrammer.get(node.getType()) != null) {
+ return this.pluginFlowProgrammer.get(node.getType())
+ .modifyFlowAsync(node, oldFlow, newFlow, getNextRid());
+ }
+ }
+ return new Status(StatusCode.NOSERVICE, "Plugin unuvailable");
+ }
+
@Override
public void flowRemoved(Node node, Flow flow) {
for (IFlowProgrammerListener l : listener) {
}
}
+ @Override
+ public void flowErrorReported(Node node, long rid, Object err) {
+ logger.error("Got error {} for message rid {} from node {}",
+ new Object[] { err, rid, node });
+
+ for (IFlowProgrammerListener l : listener) {
+ l.flowErrorReported(node, rid, err);
+ }
+ }
+
// ---------------- OSGI TEST CODE ------------------------------//
private void registerWithOSGIConsole() {
return flow;
}
+ /**
+ * This Request ID generator starts with 1. Each aysnc message is
+ * associated with an unique Request ID (!= 0).
+ *
+ * @return Request ID
+ */
+ private long getNextRid() {
+ return seq.getAndIncrement();
+ }
+
+ @Override
+ public Status syncSendBarrierMessage(Node node) {
+ if (this.pluginFlowProgrammer != null) {
+ if (this.pluginFlowProgrammer.get(node.getType()) != null) {
+ return this.pluginFlowProgrammer.get(node.getType())
+ .syncSendBarrierMessage(node);
+ }
+ }
+ return new Status(StatusCode.NOSERVICE, "Plugin unuvailable");
+ }
+
+ @Override
+ public Status asyncSendBarrierMessage(Node node) {
+ if (this.pluginFlowProgrammer != null) {
+ if (this.pluginFlowProgrammer.get(node.getType()) != null) {
+ return this.pluginFlowProgrammer.get(node.getType())
+ .asyncSendBarrierMessage(node);
+ }
+ }
+ return new Status(StatusCode.NOSERVICE, "Plugin unuvailable");
+ }
}