Use singleton list for simple packetIn 32/7632/1
authorRobert Varga <robert.varga@pantheon.sk>
Mon, 2 Jun 2014 17:19:26 +0000 (19:19 +0200)
committerRobert Varga <robert.varga@pantheon.sk>
Tue, 3 Jun 2014 08:52:29 +0000 (10:52 +0200)
Tracing has shown we are spending quite some time constructing
CopyOnWriteArrayList -- just to throw it away. Let's use a singleton
list, which is way faster.

Change-Id: Id2bb5c7d548d5d4257170828667a66543099fa38
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/PacketInTranslator.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/PacketInV10Translator.java

index f547040998b87950fb809de56d444f49734374a2..5b921cd0c484780f2b58cf6843099e9178dd7faa 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.translator;
 import java.math.BigInteger;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
@@ -40,15 +39,15 @@ public class PacketInTranslator implements IMDMessageTranslator<OfHeader, List<D
     protected static final Logger LOG = LoggerFactory
             .getLogger(PacketInTranslator.class);
     @Override
-    public List<DataObject> translate(SwitchConnectionDistinguisher cookie,
-            SessionContext sc, OfHeader msg) {
-        
+    public List<DataObject> translate(final SwitchConnectionDistinguisher cookie,
+            final SessionContext sc, final OfHeader msg) {
+
         List<DataObject> salPacketIn = Collections.emptyList();
-        
+
         if (sc != null && msg instanceof PacketInMessage) {
             PacketInMessage message = (PacketInMessage)msg;
             LOG.trace("PacketIn[v{}]: Cookie: {} Match.type: {}",
-                    message.getVersion(), message.getCookie(), 
+                    message.getVersion(), message.getCookie(),
                     message.getMatch() != null ? message.getMatch().getType() : message.getMatch());
 
            // create a packet received event builder
@@ -64,14 +63,14 @@ public class PacketInTranslator implements IMDMessageTranslator<OfHeader, List<D
                LOG.warn("Received packet_in, but there is no device datapathId received yet");
            } else {
                BigInteger dpid = features.getDatapathId();
-    
+
                // get the Cookie if it exists
                if(message.getCookie() != null) {
                    pktInBuilder.setFlowCookie(new FlowCookie(message.getCookie()));
                }
                //TODO: use either canonical mapping or suitable hash -> 32b
                //pktInBuilder.setConnectionCookie(cookie);
-    
+
                // extract the port number
                Long port = null;
                if (message.getMatch() != null && message.getMatch().getMatchEntries() != null) {
@@ -88,26 +87,25 @@ public class PacketInTranslator implements IMDMessageTranslator<OfHeader, List<D
                        }
                    }
                }
-    
+
                if (port == null) {
                    // no incoming port, so drop the event
                    LOG.warn("Received packet_in, but couldn't find an input port");
                } else {
                    LOG.trace("Received packet_in from {} on port {}", dpid, port);
-                   
+
                    Match match = MatchConvertorImpl.fromOFMatchToSALMatch(message.getMatch(),dpid);
                    MatchBuilder matchBuilder = new MatchBuilder(match);
                    pktInBuilder.setMatch(matchBuilder.build());
-                   
+
                    pktInBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(message.getReason()));
                    pktInBuilder.setTableId(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId(message.getTableId().getValue().shortValue()));
                    pktInBuilder.setIngress(InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(dpid,port));
                    PacketReceived pktInEvent = pktInBuilder.build();
-                   salPacketIn = new CopyOnWriteArrayList<DataObject>();
-                   salPacketIn.add(pktInEvent);
+                   salPacketIn = Collections.<DataObject>singletonList(pktInEvent);
                }
-           } 
-        } 
+           }
+        }
         return salPacketIn;
     }
 }
index 30b4b1ec5d50e427368c6d4354396eae086ffcb4..5b328526b7682582bc9f552872ddea2b5a56643f 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.translator;
 import java.math.BigInteger;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
@@ -34,11 +33,11 @@ public class PacketInV10Translator implements IMDMessageTranslator<OfHeader, Lis
     protected static final Logger LOG = LoggerFactory
             .getLogger(PacketInV10Translator.class);
     @Override
-    public List<DataObject> translate(SwitchConnectionDistinguisher cookie,
-            SessionContext sc, OfHeader msg) {
-        
+    public List<DataObject> translate(final SwitchConnectionDistinguisher cookie,
+            final SessionContext sc, final OfHeader msg) {
+
         List<DataObject> salPacketIn = Collections.emptyList();
-        
+
         if (sc != null && msg instanceof PacketInMessage) {
             PacketInMessage message = (PacketInMessage)msg;
             LOG.trace("PacketIn[v{}]: InPort: {}",
@@ -70,11 +69,10 @@ public class PacketInV10Translator implements IMDMessageTranslator<OfHeader, Lis
                     pktInBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(message.getReason()));
                     pktInBuilder.setIngress(InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(dpid, port));
                     PacketReceived pktInEvent = pktInBuilder.build();
-                    salPacketIn = new CopyOnWriteArrayList<DataObject>();
-                    salPacketIn.add(pktInEvent);
+                    salPacketIn = Collections.<DataObject>singletonList(pktInEvent);
                 }
-            } 
-        } 
+            }
+        }
         return salPacketIn;
     }
 }