X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fimplementation%2Finternal%2FFlowProgrammerService.java;h=6bea30666925ddaf4991f819597fde625766026f;hp=dd1277311e6a7bb93e9dcbf81ad62e97f25488b8;hb=e2f7aaa41e482815ca1d4495eb85c8653cd903ab;hpb=11837100975c9ad113e12668c09ecd78f9433f73 diff --git a/opendaylight/sal/implementation/src/main/java/org/opendaylight/controller/sal/implementation/internal/FlowProgrammerService.java b/opendaylight/sal/implementation/src/main/java/org/opendaylight/controller/sal/implementation/internal/FlowProgrammerService.java index dd1277311e..6bea306669 100644 --- a/opendaylight/sal/implementation/src/main/java/org/opendaylight/controller/sal/implementation/internal/FlowProgrammerService.java +++ b/opendaylight/sal/implementation/src/main/java/org/opendaylight/controller/sal/implementation/internal/FlowProgrammerService.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.sal.implementation.internal; 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; @@ -27,8 +28,8 @@ import org.opendaylight.controller.sal.action.PopVlan; 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; @@ -36,11 +37,11 @@ import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerSer 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.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; @@ -58,10 +59,17 @@ public class FlowProgrammerService implements IFlowProgrammerService, .getLogger(FlowProgrammerService.class); private ConcurrentHashMap pluginFlowProgrammer; private Set listener; + private AtomicLong seq; public FlowProgrammerService() { pluginFlowProgrammer = new ConcurrentHashMap(); listener = new HashSet(); + seq = new AtomicLong(); + /* + * This Request ID generator starts with 1. Each aysnc message is + * associated with an unique Request ID (!= 0). + */ + seq.lazySet(1); } /** @@ -213,6 +221,39 @@ public class FlowProgrammerService implements IFlowProgrammerService, 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) { @@ -220,6 +261,16 @@ public class FlowProgrammerService implements IFlowProgrammerService, } } + @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() { @@ -254,7 +305,7 @@ public class FlowProgrammerService implements IFlowProgrammerService, } ci.println(this.addFlow(node, getSampleFlow(node))); } - + public void _modifyflow(CommandInterpreter ci) throws UnknownHostException { Node node = null; String nodeId = ci.nextArgument(); @@ -440,4 +491,35 @@ public class FlowProgrammerService implements IFlowProgrammerService, 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"); + } }