External api proposal
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / translator / MultipartReplyTranslator.java
index 77e4cf837fc2e108402e65bba015c488f6ebfd19..56f2ebec56c37c3aa8f893869959975d8fa12202 100644 (file)
@@ -12,12 +12,13 @@ import java.util.ArrayList;
 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;
+import org.opendaylight.openflowplugin.api.openflow.md.core.IMDMessageTranslator;
+import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupStatsResponseConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterStatsResponseConvertor;
-import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
@@ -26,7 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.F
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdatedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdatedBuilder;
@@ -66,11 +67,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDesc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeatures;
@@ -116,6 +117,8 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
         
         List<DataObject> listDataObject = new CopyOnWriteArrayList<DataObject>();
 
+        OpenflowVersion ofVersion = OpenflowVersion.get(sc.getPrimaryConductor().getVersion());
+
         if(msg instanceof MultipartReplyMessage){
             MultipartReplyMessage mpReply = (MultipartReplyMessage)msg;
             NodeId node = this.nodeIdFromDatapathId(sc.getFeatures().getDatapathId());
@@ -128,7 +131,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                 message.setTransactionId(generateTransactionId(mpReply.getXid()));
                 MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase)mpReply.getMultipartReplyBody();
                 MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
-                message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(),sc.getFeatures().getDatapathId()));
+                message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(),sc.getFeatures().getDatapathId(), ofVersion));
                 
                 logger.debug("Converted flow statistics : {}",message.build().toString());
                 listDataObject.add(message.build());
@@ -171,7 +174,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                             new NodeConnectorStatisticsAndPortNumberMapBuilder();
                     statsBuilder.setNodeConnectorId(
                             InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(sc.getFeatures().getDatapathId(),
-                                    portStats.getPortNo()));
+                                    portStats.getPortNo(), ofVersion));
                     
                     BytesBuilder bytesBuilder = new BytesBuilder();
                     bytesBuilder.setReceived(portStats.getRxBytes());
@@ -184,10 +187,11 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                     statsBuilder.setPackets(packetsBuilder.build());
                     
                     DurationBuilder durationBuilder = new DurationBuilder();
-                    durationBuilder.setSecond(new Counter32(portStats.getDurationSec()));
-                    durationBuilder.setNanosecond(new Counter32(portStats.getDurationNsec()));
+                    if (portStats.getDurationSec() != null)
+                        durationBuilder.setSecond(new Counter32(portStats.getDurationSec()));
+                    if (portStats.getDurationNsec() != null)
+                        durationBuilder.setNanosecond(new Counter32(portStats.getDurationNsec()));
                     statsBuilder.setDuration(durationBuilder.build());
-                    
                     statsBuilder.setCollisionCount(portStats.getCollisions());
                     statsBuilder.setKey(new NodeConnectorStatisticsAndPortNumberMapKey(statsBuilder.getNodeConnectorId()));
                     statsBuilder.setReceiveCrcError(portStats.getRxCrcErr());
@@ -197,6 +201,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                     statsBuilder.setReceiveOverRunError(portStats.getRxOverErr());
                     statsBuilder.setTransmitDrops(portStats.getTxDropped());
                     statsBuilder.setTransmitErrors(portStats.getTxErrors());
+                    
                     statsMap.add(statsBuilder.build());
                 }
                 message.setNodeConnectorStatisticsAndPortNumberMap(statsMap);
@@ -230,7 +235,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                 MultipartReplyGroupDescCase caseBody = (MultipartReplyGroupDescCase)mpReply.getMultipartReplyBody();
                 MultipartReplyGroupDesc replyBody = caseBody.getMultipartReplyGroupDesc();
 
-                message.setGroupDescStats(groupStatsConvertor.toSALGroupDescStatsList(replyBody.getGroupDesc()));
+                message.setGroupDescStats(groupStatsConvertor.toSALGroupDescStatsList(replyBody.getGroupDesc(), ofVersion));
                 
                 logger.debug("Converted group statistics : {}",message.toString());
                 listDataObject.add(message.build());
@@ -409,7 +414,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                             new QueueIdAndStatisticsMapBuilder();
                     statsBuilder.setNodeConnectorId(
                             InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(sc.getFeatures().getDatapathId(),
-                                    queueStats.getPortNo()));
+                                    queueStats.getPortNo(), ofVersion));
                     statsBuilder.setTransmissionErrors(new Counter64(queueStats.getTxErrors()));
                     statsBuilder.setTransmittedBytes(new Counter64(queueStats.getTxBytes()));
                     statsBuilder.setTransmittedPackets(new Counter64(queueStats.getTxPackets()));
@@ -420,7 +425,8 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                     statsBuilder.setDuration(durationBuilder.build());
                     
                     statsBuilder.setQueueId(new QueueId(queueStats.getQueueId()));
-                    statsBuilder.setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(sc.getFeatures().getDatapathId(), queueStats.getPortNo()));
+                    statsBuilder.setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(sc.getFeatures().getDatapathId(),
+                            queueStats.getPortNo(), ofVersion));
                     
                     statsMap.add(statsBuilder.build());
                 }
@@ -464,24 +470,23 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
         List<Long> supportActionByGroups = new ArrayList<Long>();
         for(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType supportedActions : actionsSupported){
             long supportActionBitmap = 0;
-            supportActionBitmap |= supportedActions.isOFPATOUTPUT()?(1 << 0): ~(1 << 0);
-            supportActionBitmap |= supportedActions.isOFPATCOPYTTLOUT()?(1 << 11): ~(1 << 11);
-            supportActionBitmap |= supportedActions.isOFPATCOPYTTLIN()?(1 << 12): ~(1 << 12);
-            supportActionBitmap |= supportedActions.isOFPATSETMPLSTTL()?(1 << 15): ~(1 << 15);
-            supportActionBitmap |= supportedActions.isOFPATDECMPLSTTL()?(1 << 16): ~(1 << 16);
-            supportActionBitmap |= supportedActions.isOFPATPUSHVLAN()?(1 << 16): ~(1 << 16);
-            supportActionBitmap |= supportedActions.isOFPATPOPVLAN()?(1 << 17): ~(1 << 17);
-            supportActionBitmap |= supportedActions.isOFPATPUSHMPLS()?(1 << 18): ~(1 << 18);
-            supportActionBitmap |= supportedActions.isOFPATPOPMPLS()?(1 << 19): ~(1 << 19);
-            supportActionBitmap |= supportedActions.isOFPATSETQUEUE()?(1 << 20): ~(1 << 20);
-            supportActionBitmap |= supportedActions.isOFPATGROUP()?(1 << 21): ~(1 << 21);
-            supportActionBitmap |= supportedActions.isOFPATSETNWTTL()?(1 << 22): ~(1 << 22);
-            supportActionBitmap |= supportedActions.isOFPATDECNWTTL()?(1 << 23): ~(1 << 23);
-            supportActionBitmap |= supportedActions.isOFPATSETFIELD()?(1 << 24): ~(1 << 24);
-            supportActionBitmap |= supportedActions.isOFPATPUSHPBB()?(1 << 25): ~(1 << 25);
-            supportActionBitmap |= supportedActions.isOFPATPOPPBB()?(1 << 26): ~(1 << 26);
-            supportActionBitmap |= supportedActions.isOFPATEXPERIMENTER()?(1 << 27): ~(1 << 27);
-            supportActionByGroups.add(new Long(supportActionBitmap));
+            supportActionBitmap |= supportedActions.isOFPATOUTPUT()?(1 << 0): 0;
+            supportActionBitmap |= supportedActions.isOFPATCOPYTTLOUT()?(1 << 11): 0;
+            supportActionBitmap |= supportedActions.isOFPATCOPYTTLIN()?(1 << 12): 0;
+            supportActionBitmap |= supportedActions.isOFPATSETMPLSTTL()?(1 << 15): 0;
+            supportActionBitmap |= supportedActions.isOFPATDECMPLSTTL()?(1 << 16): 0;
+            supportActionBitmap |= supportedActions.isOFPATPUSHVLAN()?(1 << 17): 0;
+            supportActionBitmap |= supportedActions.isOFPATPOPVLAN()?(1 << 18): 0;
+            supportActionBitmap |= supportedActions.isOFPATPUSHMPLS()?(1 << 19): 0;
+            supportActionBitmap |= supportedActions.isOFPATPOPMPLS()?(1 << 20): 0;
+            supportActionBitmap |= supportedActions.isOFPATSETQUEUE()?(1 << 21): 0;
+            supportActionBitmap |= supportedActions.isOFPATGROUP()?(1 << 22): 0;
+            supportActionBitmap |= supportedActions.isOFPATSETNWTTL()?(1 << 23): 0;
+            supportActionBitmap |= supportedActions.isOFPATDECNWTTL()?(1 << 24): 0;
+            supportActionBitmap |= supportedActions.isOFPATSETFIELD()?(1 << 25): 0;
+            supportActionBitmap |= supportedActions.isOFPATPUSHPBB()?(1 << 26): 0;
+            supportActionBitmap |= supportedActions.isOFPATPOPPBB()?(1 << 27): 0;
+            supportActionByGroups.add(Long.valueOf(supportActionBitmap));
         }
         return supportActionByGroups;
     }