Post "Clustering optimization" updates
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / SinglePurposeMultipartReplyTranslator.java
index 6ad269a2f7c999a8d91f94a3664cf3155ac01e67..ad111387be91dcc2e326b044ec456ff8557af0bd 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.openflowplugin.impl.statistics;
 
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
@@ -89,10 +92,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Table
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * Class converts multipart reply messages to the notification objects defined
@@ -112,19 +111,18 @@ public class SinglePurposeMultipartReplyTranslator {
     private static MeterStatsResponseConvertor meterStatsConvertor = new MeterStatsResponseConvertor();
 
 
-    public List<DataObject> translate(DeviceContext deviceContext, OfHeader msg) {
+    public List<DataObject> translate(final DeviceContext deviceContext, final OfHeader msg) {
 
-        List<DataObject> listDataObject = new CopyOnWriteArrayList<DataObject>();
+        List<DataObject> listDataObject = new ArrayList<>();
 
         OpenflowVersion ofVersion = OpenflowVersion.get(deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
 
         final FeaturesReply features = deviceContext.getPrimaryConnectionContext().getFeatures();
         if (msg instanceof MultipartReplyMessage) {
             MultipartReplyMessage mpReply = (MultipartReplyMessage) msg;
-            NodeId node = this.nodeIdFromDatapathId(features.getDatapathId());
+            NodeId node = SinglePurposeMultipartReplyTranslator.nodeIdFromDatapathId(features.getDatapathId());
             switch (mpReply.getType()) {
                 case OFPMPFLOW: {
-                    logger.debug("Received flow statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+");
                     FlowsStatisticsUpdateBuilder message = new FlowsStatisticsUpdateBuilder();
                     message.setId(node);
                     message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
@@ -133,12 +131,10 @@ public class SinglePurposeMultipartReplyTranslator {
                     MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
                     message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), features.getDatapathId(), ofVersion));
 
-                    logger.debug("Converted flow statistics : {}", message.build().toString());
                     listDataObject.add(message.build());
                     return listDataObject;
                 }
                 case OFPMPAGGREGATE: {
-                    logger.debug("Received aggregate flow statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+");
                     AggregateFlowStatisticsUpdateBuilder message = new AggregateFlowStatisticsUpdateBuilder();
                     message.setId(node);
                     message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
@@ -150,13 +146,11 @@ public class SinglePurposeMultipartReplyTranslator {
                     message.setPacketCount(new Counter64(replyBody.getPacketCount()));
                     message.setFlowCount(new Counter32(replyBody.getFlowCount()));
 
-                    logger.debug("Converted aggregate flow statistics : {}", message.build().toString());
                     listDataObject.add(message.build());
                     return listDataObject;
                 }
                 case OFPMPPORTSTATS: {
 
-                    logger.debug("Received port statistics multipart response");
 
                     NodeConnectorStatisticsUpdateBuilder message = new NodeConnectorStatisticsUpdateBuilder();
                     message.setId(node);
@@ -187,10 +181,12 @@ public class SinglePurposeMultipartReplyTranslator {
                         statsBuilder.setPackets(packetsBuilder.build());
 
                         DurationBuilder durationBuilder = new DurationBuilder();
-                        if (portStats.getDurationSec() != null)
+                        if (portStats.getDurationSec() != null) {
                             durationBuilder.setSecond(new Counter32(portStats.getDurationSec()));
-                        if (portStats.getDurationNsec() != null)
+                        }
+                        if (portStats.getDurationNsec() != null) {
                             durationBuilder.setNanosecond(new Counter32(portStats.getDurationNsec()));
+                        }
                         statsBuilder.setDuration(durationBuilder.build());
                         statsBuilder.setCollisionCount(portStats.getCollisions());
                         statsBuilder.setKey(new NodeConnectorStatisticsAndPortNumberMapKey(statsBuilder.getNodeConnectorId()));
@@ -206,13 +202,11 @@ public class SinglePurposeMultipartReplyTranslator {
                     }
                     message.setNodeConnectorStatisticsAndPortNumberMap(statsMap);
 
-                    logger.debug("Converted ports statistics : {}", message.build().toString());
 
                     listDataObject.add(message.build());
                     return listDataObject;
                 }
                 case OFPMPGROUP: {
-                    logger.debug("Received group statistics multipart reponse");
                     GroupStatisticsUpdatedBuilder message = new GroupStatisticsUpdatedBuilder();
                     message.setId(node);
                     message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
@@ -221,12 +215,10 @@ public class SinglePurposeMultipartReplyTranslator {
                     MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
                     message.setGroupStats(groupStatsConvertor.toSALGroupStatsList(replyBody.getGroupStats()));
 
-                    logger.debug("Converted group statistics : {}", message.toString());
                     listDataObject.add(message.build());
                     return listDataObject;
                 }
                 case OFPMPGROUPDESC: {
-                    logger.debug("Received group description statistics multipart reponse");
 
                     GroupDescStatsUpdatedBuilder message = new GroupDescStatsUpdatedBuilder();
                     message.setId(node);
@@ -237,12 +229,10 @@ public class SinglePurposeMultipartReplyTranslator {
 
                     message.setGroupDescStats(groupStatsConvertor.toSALGroupDescStatsList(replyBody.getGroupDesc(), ofVersion));
 
-                    logger.debug("Converted group statistics : {}", message.toString());
                     listDataObject.add(message.build());
                     return listDataObject;
                 }
                 case OFPMPGROUPFEATURES: {
-                    logger.debug("Received group features multipart reponse");
                     GroupFeaturesUpdatedBuilder message = new GroupFeaturesUpdatedBuilder();
                     message.setId(node);
                     message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
@@ -291,7 +281,6 @@ public class SinglePurposeMultipartReplyTranslator {
                     return listDataObject;
                 }
                 case OFPMPMETER: {
-                    logger.debug("Received meter statistics multipart reponse");
                     MeterStatisticsUpdatedBuilder message = new MeterStatisticsUpdatedBuilder();
                     message.setId(node);
                     message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
@@ -305,7 +294,6 @@ public class SinglePurposeMultipartReplyTranslator {
                     return listDataObject;
                 }
                 case OFPMPMETERCONFIG: {
-                    logger.debug("Received meter config statistics multipart reponse");
 
                     MeterConfigStatsUpdatedBuilder message = new MeterConfigStatsUpdatedBuilder();
                     message.setId(node);
@@ -320,7 +308,6 @@ public class SinglePurposeMultipartReplyTranslator {
                     return listDataObject;
                 }
                 case OFPMPMETERFEATURES: {
-                    logger.debug("Received meter features multipart reponse");
                     //Convert OF message and send it to SAL listener
                     MeterFeaturesUpdatedBuilder message = new MeterFeaturesUpdatedBuilder();
                     message.setId(node);
@@ -366,7 +353,6 @@ public class SinglePurposeMultipartReplyTranslator {
                     return listDataObject;
                 }
                 case OFPMPTABLE: {
-                    logger.debug("Received flow table statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+");
 
                     FlowTableStatisticsUpdateBuilder message = new FlowTableStatisticsUpdateBuilder();
                     message.setId(node);
@@ -389,13 +375,10 @@ public class SinglePurposeMultipartReplyTranslator {
                     }
 
                     message.setFlowTableAndStatisticsMap(salFlowStats);
-
-                    logger.debug("Converted flow table statistics : {}", message.build().toString());
                     listDataObject.add(message.build());
                     return listDataObject;
                 }
                 case OFPMPQUEUE: {
-                    logger.debug("Received queue statistics multipart response");
 
                     QueueStatisticsUpdateBuilder message = new QueueStatisticsUpdateBuilder();
                     message.setId(node);
@@ -432,7 +415,6 @@ public class SinglePurposeMultipartReplyTranslator {
                     }
                     message.setQueueIdAndStatisticsMap(statsMap);
 
-                    logger.debug("Converted queue statistics : {}", message.build().toString());
                     listDataObject.add(message.build());
                     return listDataObject;
                 }
@@ -445,28 +427,23 @@ public class SinglePurposeMultipartReplyTranslator {
         return listDataObject;
     }
 
-    private NodeId nodeIdFromDatapathId(BigInteger datapathId) {
+    private static NodeId nodeIdFromDatapathId(final BigInteger datapathId) {
         String current = datapathId.toString();
         return new NodeId("openflow:" + current);
     }
 
-    private TransactionId generateTransactionId(Long xid) {
-        String stringXid = xid.toString();
-        BigInteger bigIntXid = new BigInteger(stringXid);
+    private static TransactionId generateTransactionId(final Long xid) {
+        BigInteger bigIntXid = BigInteger.valueOf(xid);
         return new TransactionId(bigIntXid);
-
     }
 
-    /* 
+    /*
      * Method returns the bitmap of actions supported by each group.
-     * TODO: My recommendation would be, its good to have a respective model of 
-     * 'type bits', which will generate a class where all these flags will eventually
-     * be stored as boolean. It will be convenient for application to check the
-     * supported action, rather then doing bitmap operation.
+     *
      * @param actionsSupported
      * @return
      */
-    private List<Long> getGroupActionsSupportBitmap(List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType> actionsSupported) {
+    static List<Long> getGroupActionsSupportBitmap(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType> actionsSupported) {
         List<Long> supportActionByGroups = new ArrayList<Long>();
         for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType supportedActions : actionsSupported) {
             long supportActionBitmap = 0;