X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fimplementation%2Finternal%2FFlowProgrammerService.java;h=6bea30666925ddaf4991f819597fde625766026f;hb=refs%2Fchanges%2F49%2F449%2F1;hp=0cc2a1943d3bd027b8426298ff588b30a21e6d89;hpb=a1f02e35be4dff06e523d3aeb05a7b9e1ca91a07;p=controller.git 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 0cc2a1943d..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() { @@ -248,13 +299,13 @@ public class FlowProgrammerService implements IFlowProgrammerService, try { node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId)); } catch (NumberFormatException e) { - e.printStackTrace(); + logger.error("",e); } catch (ConstructionException e) { - e.printStackTrace(); + logger.error("",e); } ci.println(this.addFlow(node, getSampleFlow(node))); } - + public void _modifyflow(CommandInterpreter ci) throws UnknownHostException { Node node = null; String nodeId = ci.nextArgument(); @@ -265,9 +316,9 @@ public class FlowProgrammerService implements IFlowProgrammerService, try { node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId)); } catch (NumberFormatException e) { - e.printStackTrace(); + logger.error("",e); } catch (ConstructionException e) { - e.printStackTrace(); + logger.error("",e); } Flow flowA = getSampleFlow(node); Flow flowB = getSampleFlow(node); @@ -288,9 +339,9 @@ public class FlowProgrammerService implements IFlowProgrammerService, try { node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId)); } catch (NumberFormatException e) { - e.printStackTrace(); + logger.error("",e); } catch (ConstructionException e) { - e.printStackTrace(); + logger.error("",e); } ci.println(this.removeFlow(node, getSampleFlow(node))); } @@ -305,9 +356,9 @@ public class FlowProgrammerService implements IFlowProgrammerService, try { node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId)); } catch (NumberFormatException e) { - e.printStackTrace(); + logger.error("",e); } catch (ConstructionException e) { - e.printStackTrace(); + logger.error("",e); } ci.println(this.addFlow(node, getSampleFlowV6(node))); } @@ -323,9 +374,9 @@ public class FlowProgrammerService implements IFlowProgrammerService, try { node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId)); } catch (NumberFormatException e) { - e.printStackTrace(); + logger.error("",e); } catch (ConstructionException e) { - e.printStackTrace(); + logger.error("",e); } ci.println(this.removeFlow(node, getSampleFlowV6(node))); } @@ -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"); + } }