- Respond to switch Echo Request immediately. It bypasses transmit queue and sends...
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / DataPacketMuxDemux.java
index 93e7840b01c203a741b3610e0e30f5d86236580e..dc84304a047573307e62fa0205fc2ff6dce16a71 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
@@ -44,6 +43,7 @@ import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
 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;
 
 public class DataPacketMuxDemux implements IContainerListener,
         IMessageListener, IDataPacketMux, IInventoryShimExternalListener {
@@ -53,7 +53,8 @@ public class DataPacketMuxDemux implements IContainerListener,
     private ConcurrentMap<Long, ISwitch> swID2ISwitch = new ConcurrentHashMap<Long, ISwitch>();
     // Gives a map between a Container and all the DataPacket listeners on SAL
     private ConcurrentMap<String, IPluginOutDataPacketService> pluginOutDataPacketServices = new ConcurrentHashMap<String, IPluginOutDataPacketService>();
-    // Gives a map between a NodeConnector and the containers to which it belongs
+    // Gives a map between a NodeConnector and the containers to which it
+    // belongs
     private ConcurrentMap<NodeConnector, List<String>> nc2Container = new ConcurrentHashMap<NodeConnector, List<String>>();
     // Gives a map between a Container and the FlowSpecs on it
     private ConcurrentMap<String, List<ContainerFlow>> container2FlowSpecs = new ConcurrentHashMap<String, List<ContainerFlow>>();
@@ -94,7 +95,7 @@ public class DataPacketMuxDemux implements IContainerListener,
             // replication is done in the SAL implementation toward
             // the different APPS
             this.pluginOutDataPacketServices.put(containerName, s);
-            logger.debug("New outService for container:" + containerName);
+            logger.debug("New outService for container: {}", containerName);
         }
     }
 
@@ -111,7 +112,7 @@ public class DataPacketMuxDemux implements IContainerListener,
         }
         if (this.pluginOutDataPacketServices != null) {
             this.pluginOutDataPacketServices.remove(containerName);
-            logger.debug("Removed outService for container:" + containerName);
+            logger.debug("Removed outService for container: {}", containerName);
         }
     }
 
@@ -130,17 +131,17 @@ public class DataPacketMuxDemux implements IContainerListener,
     /**
      * Function called by the dependency manager when all the required
      * dependencies are satisfied
-     *
+     * 
      */
     void init() {
         this.controller.addMessageListener(OFType.PACKET_IN, this);
     }
 
     /**
-     * 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.
-     *
+     * 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);
@@ -158,6 +159,9 @@ public class DataPacketMuxDemux implements IContainerListener,
         if (sw == null || msg == null
                 || this.pluginOutDataPacketServices == null) {
             // Something fishy, we cannot do anything
+            logger.debug(
+                    "sw: {} and/or msg: {} and/or pluginOutDataPacketServices: {} is null!",
+                    new Object[] { sw, msg, this.pluginOutDataPacketServices });
             return;
         }
         if (msg instanceof OFPacketIn) {
@@ -191,13 +195,18 @@ public class DataPacketMuxDemux implements IContainerListener,
                         .get(GlobalConstants.DEFAULT.toString());
                 if (defaultOutService != null) {
                     defaultOutService.receiveDataPacket(dataPacket);
-                    logger.trace("Dispatched to apps a frame of size: "
-                            + ofPacket.getPacketData().length
-                            + " on container: "
-                            + GlobalConstants.DEFAULT.toString());
+                    if (logger.isTraceEnabled()) {
+                      logger.trace(
+                              "Dispatched to apps a frame of size: {} on " +
+                              "container: {}: {}", new Object[] {
+                                    ofPacket.getPacketData().length,
+                                    GlobalConstants.DEFAULT.toString(),
+                                    HexEncode.bytesToHexString(dataPacket
+                                            .getPacketData()) });
+                    }
                 }
                 // Now check the mapping between nodeConnector and
-                // Container and later on optinally filter based on
+                // Container and later on optimally filter based on
                 // flowSpec
                 List<String> containersRX = this.nc2Container.get(p);
                 if (containersRX != null) {
@@ -208,10 +217,15 @@ public class DataPacketMuxDemux implements IContainerListener,
                         if (s != null) {
                             // TODO add filtering on a per-flowSpec base
                             s.receiveDataPacket(dataPacket);
-                            logger.trace("Dispatched to apps a frame of size: "
-                                    + ofPacket.getPacketData().length
-                                    + " on container: " + container);
-
+                            if (logger.isTraceEnabled()) {
+                              logger.trace(
+                                      "Dispatched to apps a frame of size: {}" +
+                                      " on container: {}: {}", new Object[] {
+                                            ofPacket.getPacketData().length,
+                                            container,
+                                            HexEncode.bytesToHexString(dataPacket
+                                                    .getPacketData()) });
+                            }
                         }
                     }
                 }
@@ -234,17 +248,20 @@ public class DataPacketMuxDemux implements IContainerListener,
     public void transmitDataPacket(RawPacket outPkt) {
         // Sanity check area
         if (outPkt == null) {
+            logger.debug("outPkt is null!");
             return;
         }
 
         NodeConnector outPort = outPkt.getOutgoingNodeConnector();
         if (outPort == null) {
+            logger.debug("outPort is null! outPkt: {}", outPkt);
             return;
         }
 
         if (!outPort.getType().equals(
                 NodeConnector.NodeConnectorIDType.OPENFLOW)) {
             // The output Port is not of type OpenFlow
+            logger.debug("outPort is not OF Type! outPort: {}", outPort);
             return;
         }
 
@@ -255,6 +272,7 @@ public class DataPacketMuxDemux implements IContainerListener,
         if (sw == null) {
             // If we cannot get the controller descriptor we cannot even
             // send out the frame
+            logger.debug("swID: {} - sw is null!", swID);
             return;
         }
 
@@ -262,8 +280,9 @@ public class DataPacketMuxDemux implements IContainerListener,
         // build action
         OFActionOutput action = new OFActionOutput().setPort(port);
         // build packet out
-        OFPacketOut po = new OFPacketOut().setBufferId(
-                OFPacketOut.BUFFER_ID_NONE).setInPort(OFPort.OFPP_NONE)
+        OFPacketOut po = new OFPacketOut()
+                .setBufferId(OFPacketOut.BUFFER_ID_NONE)
+                .setInPort(OFPort.OFPP_NONE)
                 .setActions(Collections.singletonList((OFAction) action))
                 .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);
 
@@ -271,30 +290,39 @@ public class DataPacketMuxDemux implements IContainerListener,
                 + data.length);
         po.setPacketData(data);
 
-        sw.asyncSend(po);
-        logger.trace("Transmitted a frame of size:" + data.length);
+        // send PACKET_OUT at high priority
+        sw.asyncFastSend(po);
+        logger.trace("Transmitted a frame of size: {}", data.length);
     }
 
     public void addNode(Node node, Set<Property> props) {
-        if (node == null)
+        if (node == null) {
+            logger.debug("node is null!");
             return;
+        }
 
         long sid = (Long) node.getID();
         ISwitch sw = controller.getSwitches().get(sid);
-        if (sw != null) {
-            this.swID2ISwitch.put(sw.getId(), sw);
+        if (sw == null) {
+            logger.debug("sid: {} - sw is null!", sid);
+            return;
         }
+        this.swID2ISwitch.put(sw.getId(), sw);
     }
 
     public void removeNode(Node node) {
-        if (node == null)
+        if (node == null) {
+            logger.debug("node is null!");
             return;
+        }
 
         long sid = (Long) node.getID();
         ISwitch sw = controller.getSwitches().get(sid);
-        if (sw != null) {
-            this.swID2ISwitch.remove(sw.getId());
+        if (sw == null) {
+            logger.debug("sid: {} - sw is null!", sid);
+            return;
         }
+        this.swID2ISwitch.remove(sw.getId());
     }
 
     @Override
@@ -315,7 +343,6 @@ public class DataPacketMuxDemux implements IContainerListener,
         if (fSpecs == null) {
             fSpecs = new CopyOnWriteArrayList<ContainerFlow>();
         }
-        boolean updateMap = false;
         switch (t) {
         case ADDED:
             if (!fSpecs.contains(previousFlow)) {
@@ -330,13 +357,6 @@ public class DataPacketMuxDemux implements IContainerListener,
         case CHANGED:
             break;
         }
-        if (updateMap) {
-            if (fSpecs.isEmpty()) {
-                this.container2FlowSpecs.remove(containerName);
-            } else {
-                this.container2FlowSpecs.put(containerName, fSpecs);
-            }
-        }
     }
 
     @Override