X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FDataPacketMuxDemux.java;h=a1fcd1ab23b7c5a8836d5ad1200533b5a08a03ec;hb=refs%2Fchanges%2F70%2F1170%2F1;hp=7614a4d128eae867ed4378f78e346da447c4d081;hpb=cf900ecae0a4afada4c675bfadaf78f27eb18857;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java index 7614a4d128..a1fcd1ab23 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.protocol_plugin.openflow.internal; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -22,18 +23,10 @@ import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExtern import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPacketIn; -import org.openflow.protocol.OFPacketOut; -import org.openflow.protocol.OFPort; -import org.openflow.protocol.OFType; -import org.openflow.protocol.action.OFAction; -import org.openflow.protocol.action.OFActionOutput; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import org.opendaylight.controller.sal.connection.IPluginOutConnectionService; import org.opendaylight.controller.sal.core.ConstructionException; import org.opendaylight.controller.sal.core.ContainerFlow; +import org.opendaylight.controller.sal.core.IContainerAware; import org.opendaylight.controller.sal.core.IContainerListener; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; @@ -44,9 +37,18 @@ import org.opendaylight.controller.sal.packet.PacketResult; import org.opendaylight.controller.sal.packet.RawPacket; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.HexEncode; +import org.openflow.protocol.OFMessage; +import org.openflow.protocol.OFPacketIn; +import org.openflow.protocol.OFPacketOut; +import org.openflow.protocol.OFPort; +import org.openflow.protocol.OFType; +import org.openflow.protocol.action.OFAction; +import org.openflow.protocol.action.OFActionOutput; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class DataPacketMuxDemux implements IContainerListener, - IMessageListener, IDataPacketMux, IInventoryShimExternalListener { + IMessageListener, IDataPacketMux, IInventoryShimExternalListener, IContainerAware { protected static final Logger logger = LoggerFactory .getLogger(DataPacketMuxDemux.class); private IController controller = null; @@ -60,6 +62,7 @@ public class DataPacketMuxDemux implements IContainerListener, private ConcurrentMap> container2FlowSpecs = new ConcurrentHashMap>(); // Track local data packet listener private List iDataPacketListen = new CopyOnWriteArrayList(); + private IPluginOutConnectionService connectionOutService; void setIDataPacketListen(IDataPacketListen s) { if (this.iDataPacketListen != null) { @@ -128,10 +131,20 @@ public class DataPacketMuxDemux implements IContainerListener, } } + void setIPluginOutConnectionService(IPluginOutConnectionService s) { + connectionOutService = s; + } + + void unsetIPluginOutConnectionService(IPluginOutConnectionService s) { + if (connectionOutService == s) { + connectionOutService = null; + } + } + /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ void init() { this.controller.addMessageListener(OFType.PACKET_IN, this); @@ -141,7 +154,7 @@ public class DataPacketMuxDemux implements IContainerListener, * 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() { this.controller.removeMessageListener(OFType.PACKET_IN, this); @@ -164,9 +177,21 @@ public class DataPacketMuxDemux implements IContainerListener, new Object[] { sw, msg, this.pluginOutDataPacketServices }); return; } + + Long ofSwitchID = Long.valueOf(sw.getId()); + try { + Node n = new Node(Node.NodeIDType.OPENFLOW, ofSwitchID); + if (!connectionOutService.isLocal(n)) { + logger.debug("Connection service refused DataPacketMuxDemux receive {} {}", sw, msg); + return; + } + } + catch (Exception e) { + return; + } + if (msg instanceof OFPacketIn) { OFPacketIn ofPacket = (OFPacketIn) msg; - Long ofSwitchID = Long.valueOf(sw.getId()); Short ofPortID = Short.valueOf(ofPacket.getInPort()); try { @@ -258,6 +283,12 @@ public class DataPacketMuxDemux implements IContainerListener, return; } + if (!connectionOutService.isLocal(outPort.getNode())) { + logger.debug("data packets will not be sent to {} in a non-master controller", outPort.toString()); + return; + } + + if (!outPort.getType().equals( NodeConnector.NodeConnectorIDType.OPENFLOW)) { // The output Port is not of type OpenFlow @@ -290,7 +321,8 @@ public class DataPacketMuxDemux implements IContainerListener, + data.length); po.setPacketData(data); - sw.asyncSend(po); + // send PACKET_OUT at high priority + sw.asyncFastSend(po); logger.trace("Transmitted a frame of size: {}", data.length); } @@ -344,14 +376,13 @@ public class DataPacketMuxDemux implements IContainerListener, } switch (t) { case ADDED: - if (!fSpecs.contains(previousFlow)) { - fSpecs.add(previousFlow); + if (!fSpecs.contains(currentFlow)) { + fSpecs.add(currentFlow); } + container2FlowSpecs.put(containerName, fSpecs); break; case REMOVED: - if (fSpecs.contains(previousFlow)) { - fSpecs.remove(previousFlow); - } + fSpecs.remove(currentFlow); break; case CHANGED: break; @@ -421,4 +452,29 @@ public class DataPacketMuxDemux implements IContainerListener, UpdateType type, Set props) { // do nothing } + + @Override + public void containerCreate(String containerName) { + // do nothing + } + + @Override + public void containerDestroy(String containerName) { + Set removeNodeConnectorSet = new HashSet(); + for (Map.Entry> entry : nc2Container.entrySet()) { + List ncContainers = entry.getValue(); + if (ncContainers.contains(containerName)) { + NodeConnector nodeConnector = entry.getKey(); + removeNodeConnectorSet.add(nodeConnector); + } + } + for (NodeConnector nodeConnector : removeNodeConnectorSet) { + List ncContainers = nc2Container.get(nodeConnector); + ncContainers.remove(containerName); + if (ncContainers.isEmpty()) { + nc2Container.remove(nodeConnector); + } + } + container2FlowSpecs.remove(containerName); + } }