MD-SAL Statistics Manager - Implemented rpc/notifications for individual flow statistics 28/3728/1
authorAnilkumar Vishnoi <avishnoi@in.ibm.com>
Wed, 11 Dec 2013 14:02:56 +0000 (19:32 +0530)
committerAnilkumar Vishnoi <avishnoi@in.ibm.com>
Sat, 14 Dec 2013 02:23:10 +0000 (07:53 +0530)
and aggregate flow statistics collection
This gerrit is dependent on another gerrit pushed to controller project
http://git.opendaylight.org/gerrit/3708

Change-Id: Ic0dd18aabb74faa2d1b9fcf9b596a1f363c971e4
Signed-off-by: Anilkumar Vishnoi <avishnoi@in.ibm.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/ModelDrivenSwitch.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/AbstractModelDrivenSwitch.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowStatsResponseConvertor.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MatchConvertor.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OpenflowEnumConstant.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java

index b8b302a6e1bf9eb10e720de93526716999926335..aa5e2b7543187b3894d1578176ecc043874cab5a 100644 (file)
@@ -10,6 +10,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.Remo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
@@ -51,6 +52,7 @@ public interface ModelDrivenSwitch extends //
         PacketProcessingService, //
         OpendaylightGroupStatisticsService, //
         OpendaylightMeterStatisticsService, //
+        OpendaylightFlowStatisticsService, //
         Identifiable<InstanceIdentifier<Node>> {
 
     CompositeObjectRegistration<ModelDrivenSwitch> register(ProviderContext ctx);
index 0b7c52fa9558307137a3e330a51159cce422a954..8ad873d8eb323ce62c2187ebac9ba1b8ce6ef2b8 100644 (file)
@@ -36,6 +36,8 @@ import org.opendaylight.openflowplugin.openflow.md.queue.PopListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
@@ -101,6 +103,7 @@ public class MDController implements IMDController {
         addMessageTranslator(MultipartReplyMessage.class,OF13,new MultiPartReplyPortToNodeConnectorUpdatedTranslator());
         addMessageTranslator(MultipartReplyMessage.class,OF13, new MultiPartMessageDescToNodeUpdatedTranslator());
         addMessageTranslator(ExperimenterMessage.class, OF10, new ExperimenterTranslator());
+        addMessageTranslator(MultipartReplyMessage.class,OF10, new MultipartReplyTranslator());
         addMessageTranslator(MultipartReplyMessage.class,OF13, new MultipartReplyTranslator());
         addMessageTranslator(MultipartReplyMessage.class,OF13,new MultipartReplyTableFeaturesToTableUpdatedTranslator());
 
@@ -114,6 +117,9 @@ public class MDController implements IMDController {
 
         addMessagePopListener(SwitchFlowRemoved.class, notificationPopListener);
         addMessagePopListener(TableUpdated.class, notificationPopListener);
+        //Notification registration for flow statistics
+        addMessagePopListener(FlowsStatisticsUpdate.class, notificationPopListener);
+        addMessagePopListener(AggregateFlowStatisticsUpdate.class, notificationPopListener);
         //Notification registrations for group-statistics
         addMessagePopListener(GroupStatisticsUpdated.class, notificationPopListener);
         addMessagePopListener(GroupFeaturesUpdated.class, notificationPopListener);
index ffaddf73168034c46fd4f54bcc2d66e803d45aa3..fbe73c9ea9a771344a25df8678f51b2ea81b85d3 100644 (file)
@@ -12,6 +12,7 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcR
 import org.opendaylight.openflowplugin.openflow.md.ModelDrivenSwitch;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
@@ -37,6 +38,8 @@ public abstract class AbstractModelDrivenSwitch implements ModelDrivenSwitch {
     private RoutedRpcRegistration<SalMeterService> meterRegistration;
 
     private RoutedRpcRegistration<PacketProcessingService> packetRegistration;
+    
+    private RoutedRpcRegistration<OpendaylightFlowStatisticsService> flowStatisticsRegistration;
 
     private RoutedRpcRegistration<OpendaylightGroupStatisticsService> groupStatisticsRegistration;
 
@@ -74,7 +77,11 @@ public abstract class AbstractModelDrivenSwitch implements ModelDrivenSwitch {
         packetRegistration = ctx.addRoutedRpcImplementation(PacketProcessingService.class, this);
         packetRegistration.registerPath(NodeContext.class, getIdentifier());
         builder.add(packetRegistration);
-        
+
+        flowStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightFlowStatisticsService.class, this);
+        flowStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
+        builder.add(flowStatisticsRegistration);
+
         groupStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightGroupStatisticsService.class, this);
         groupStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
         builder.add(groupStatisticsRegistration);
index 746f1fdd5e9570a043fd27071c8b7a7b16d17851..2d8e3cae20db2ef8c16e55ac44708a2b7ded7ef5 100644 (file)
@@ -19,7 +19,9 @@ import org.opendaylight.openflowjava.protocol.api.util.BinContent;
 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MatchConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.OpenflowEnumConstant;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
@@ -33,11 +35,36 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.Remo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
@@ -80,12 +107,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
@@ -96,6 +126,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
@@ -103,11 +135,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;
+//import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features.TableFeatures;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.GetPortOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
@@ -812,82 +847,83 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
 
     }
 
-       @Override
-       public Future<RpcResult<GetPortOutput>> getPort() {
-               // TODO Auto-generated method stub
-               return null;
-       }
+    @Override
+    public Future<RpcResult<GetPortOutput>> getPort() {
+       // TODO Auto-generated method stub
+       return null;
+    }
+    
 
-       @Override
-       public Future<RpcResult<UpdatePortOutput>> updatePort(UpdatePortInput input) {
-               PortModInput ofPortModInput = null ;
-               RpcResult<UpdatePortOutput> rpcResultFromOFLib = null ;
+    @Override
+    public Future<RpcResult<UpdatePortOutput>> updatePort(UpdatePortInput input) {
+       PortModInput ofPortModInput = null ;
+       RpcResult<UpdatePortOutput> rpcResultFromOFLib = null ;
                
                                
-               // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so  
+       // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so  
        // the request can be routed through any connection to the switch
        
        SwitchConnectionDistinguisher cookie = null ;
        
-               // NSF sends a list of port and the ModelDrivenSwitch will 
+       // NSF sends a list of port and the ModelDrivenSwitch will 
        // send one port at a time towards the switch ( mutiple RPCs calls)
-               List<Port> inputPorts = input.getUpdatedPort().getPort().getPort() ;
+       List<Port> inputPorts = input.getUpdatedPort().getPort().getPort() ;
                
-               // Get the Xid. The same Xid has to be sent in all the RPCs
-               Long Xid = sessionContext.getNextXid();
+       // Get the Xid. The same Xid has to be sent in all the RPCs
+       Long Xid = sessionContext.getNextXid();
                
-               for( Port inputPort : inputPorts) {
+       for( Port inputPort : inputPorts) {
                   
-                       // Convert the UpdateGroupInput to GroupModInput 
-                               ofPortModInput = PortConvertor.toPortModInput(inputPort, version) ;
+           // Convert the UpdateGroupInput to GroupModInput 
+           ofPortModInput = PortConvertor.toPortModInput(inputPort, version) ;
                                                        
-                               // Insert the Xid ( transaction Id) before calling the RPC on the OFLibrary
-                       
-                       PortModInputBuilder mdInput = new PortModInputBuilder();
-                       mdInput.setXid(Xid);
-                       mdInput.setVersion(ofPortModInput.getVersion()) ;
-                       mdInput.setPortNo(ofPortModInput.getPortNo()) ;
-                       mdInput.setMaskV10(ofPortModInput.getMaskV10()) ;
-                       mdInput.setMask(ofPortModInput.getMask()) ;
-                       mdInput.setHwAddress(ofPortModInput.getHwAddress());
-                       mdInput.setConfigV10(ofPortModInput.getConfigV10()) ;
-                       mdInput.setConfig(ofPortModInput.getConfig()) ;
-                       mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10()) ;
-                       mdInput.setAdvertise(ofPortModInput.getAdvertise()) ;
-                       
-                       LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
-                       Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(ofPortModInput, cookie) ;
-                                       
-                       try { 
-                               rpcResultFromOFLib = resultFromOFLib.get();
-                       } catch( Exception ex ) {
-                               LOG.error( " Error while getting result for updatePort RPC" + ex.getMessage());
-                       }
+           // Insert the Xid ( transaction Id) before calling the RPC on the OFLibrary
                        
-                       // The Future response value for all the RPCs except the last one is ignored
-                       
-               }
-                       
-                               //Extract the Xid only from the Future for the last RPC and
-                               // send it back to the NSF
-                       UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult() ;
-                       
-                       UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder() ;
-                       updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId()) ;
-                       UpdatePortOutput result = updatePortOutput.build();
-                       
-                       Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
-                       RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors); 
-                       
-                       LOG.debug("Returning the Update Group RPC result to MD-SAL");
-                       return Futures.immediateFuture(rpcResult);
-       
+           PortModInputBuilder mdInput = new PortModInputBuilder();
+           mdInput.setXid(Xid);
+           mdInput.setVersion(ofPortModInput.getVersion()) ;
+           mdInput.setPortNo(ofPortModInput.getPortNo()) ;
+           mdInput.setMaskV10(ofPortModInput.getMaskV10()) ;
+           mdInput.setMask(ofPortModInput.getMask()) ;
+           mdInput.setHwAddress(ofPortModInput.getHwAddress());
+           mdInput.setConfigV10(ofPortModInput.getConfigV10()) ;
+           mdInput.setConfig(ofPortModInput.getConfig()) ;
+           mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10()) ;
+           mdInput.setAdvertise(ofPortModInput.getAdvertise()) ;
+
+           LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
+           Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(ofPortModInput, cookie) ;
+
+           try { 
+               rpcResultFromOFLib = resultFromOFLib.get();
+           } catch( Exception ex ) {
+               LOG.error( " Error while getting result for updatePort RPC" + ex.getMessage());
+           }
+
+           // The Future response value for all the RPCs except the last one is ignored
+
        }
-       @Override
-       public Future<RpcResult<UpdateTableOutput>> updateTable(
+       //Extract the Xid only from the Future for the last RPC and
+       // send it back to the NSF
+       UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult() ;
+       
+       UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder() ;
+       updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId()) ;
+       UpdatePortOutput result = updatePortOutput.build();
+       
+       Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
+       RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors); 
+       
+       LOG.debug("Returning the Update Group RPC result to MD-SAL");
+       return Futures.immediateFuture(rpcResult);
+
+    }
+    
+    @Override
+    public Future<RpcResult<UpdateTableOutput>> updateTable(
                        UpdateTableInput input) {
 
-               // Get the Xid. The same Xid has to be sent in all the Multipart requests
+        // Get the Xid. The same Xid has to be sent in all the Multipart requests
         Long xid = this.getSessionContext().getNextXid();
 
         LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ",xid);
@@ -905,7 +941,7 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
         MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
         MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
 
-         // Slice the multipart request based on the configuration parameter, which is the no. of TableFeatureList element
+        // Slice the multipart request based on the configuration parameter, which is the no. of TableFeatureList element
         // to be put in one multipart message. Default is 5
         // This parameter must be set based on switch's Buffer capacity
 
@@ -936,8 +972,9 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
         index += noOfEntriesInMPR ;
                tmpOfTableFeatureList = null ; // To avoid any corrupt data
         }
-      //Extract the Xid only from the Future for the last RPC and
-               // send it back to the NSF
+        
+        //Extract the Xid only from the Future for the last RPC and
+       // send it back to the NSF
         LOG.debug("Returning the result and transaction id to NSF");
         LOG.debug("Return results and transaction id back to caller");
         UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
@@ -947,5 +984,317 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
         RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
         return Futures.immediateFuture(rpcResult);
 
-       }
+    }
+
+    @Override
+    public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
+            GetAllFlowStatisticsFromFlowTableInput arg0) {
+
+        //Generate xid to associate it with the request
+        Long xid = this.getSessionContext().getNextXid();
+
+        LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}"
+                ,arg0.getTableId().getValue(),xid);
+
+        // Create multipart request header
+        MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
+        mprInput.setType(MultipartType.OFPMPFLOW);
+        mprInput.setVersion(version);
+        mprInput.setXid(xid);
+        mprInput.setFlags(new MultipartRequestFlags(false));
+
+        // Create multipart request body for fetch all the group stats
+        MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder  = new MultipartRequestFlowCaseBuilder (); 
+        MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
+        mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
+        mprFlowRequestBuilder.setOutPort(OpenflowEnumConstant.OFPP_ANY);
+        mprFlowRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY);
+        mprFlowRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE);
+        mprFlowRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK);
+        if(version == OpenflowEnumConstant.OPENFLOW_V10){
+            LOG.info("Target node is running openflow version 1.0");
+            FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,false,false,false,false,false,false,false,false,false,false);
+            mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
+        }
+        if(version == OpenflowEnumConstant.OPENFLOW_V13){
+            LOG.info("Target node is running openflow version 1.3+");
+            mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
+        }
+
+
+        //Set request body to main multipart request
+        multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
+        mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+
+        //Send the request, no cookies associated, use any connection
+        LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
+        this.messageService.multipartRequest(mprInput.build(), null);
+
+        // Prepare rpc return output. Set xid and send it back.
+        LOG.debug("Return results and transaction id back to caller");
+        GetAllFlowStatisticsFromFlowTableOutputBuilder output = 
+                new GetAllFlowStatisticsFromFlowTableOutputBuilder();
+        output.setTransactionId(generateTransactionId(xid));
+        output.setFlowAndStatisticsMapList(null);
+
+        Collection<RpcError> errors = Collections.emptyList();
+        RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
+        return Futures.immediateFuture(rpcResult);
+    }
+
+    @Override
+    public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
+            GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
+        
+        //Generate xid to associate it with the request
+        Long xid = this.getSessionContext().getNextXid();
+
+        LOG.info("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}",xid);
+
+        // Create multipart request header
+        MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
+        mprInput.setType(MultipartType.OFPMPFLOW);
+        mprInput.setVersion(version);
+        mprInput.setXid(xid);
+        mprInput.setFlags(new MultipartRequestFlags(false));
+
+        // Create multipart request body for fetch all the group stats
+        MultipartRequestFlowCaseBuilder  multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
+        MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
+        mprFlowRequestBuilder.setTableId(OpenflowEnumConstant.OFPTT_ALL);
+        mprFlowRequestBuilder.setOutPort(OpenflowEnumConstant.OFPP_ANY);
+        mprFlowRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY);
+        mprFlowRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE);
+        mprFlowRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK);
+        mprFlowRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK);
+        
+        if(version == OpenflowEnumConstant.OPENFLOW_V10){
+            FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,false,false,false,false,false,false,false,false,false,false);
+            mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
+        }
+        if(version == OpenflowEnumConstant.OPENFLOW_V13){
+            mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
+        }
+        //Set request body to main multipart request
+        multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
+        mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+
+        //Send the request, no cookies associated, use any connection
+        LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
+        this.messageService.multipartRequest(mprInput.build(), null);
+
+        // Prepare rpc return output. Set xid and send it back.
+        GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output = 
+                new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
+        output.setTransactionId(generateTransactionId(xid));
+        output.setFlowAndStatisticsMapList(null);
+
+        Collection<RpcError> errors = Collections.emptyList();
+        RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
+        return Futures.immediateFuture(rpcResult);
+
+    }
+
+    @Override
+    public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
+            GetFlowStatisticsFromFlowTableInput arg0) {
+        //Generate xid to associate it with the request
+        Long xid = this.getSessionContext().getNextXid();
+
+        LOG.debug("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}"
+                ,arg0.getMatch().toString(),arg0.getTableId(),xid);
+
+        // Create multipart request header
+        MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
+        mprInput.setType(MultipartType.OFPMPFLOW);
+        mprInput.setVersion(version);
+        mprInput.setXid(xid);
+        mprInput.setFlags(new MultipartRequestFlags(false));
+
+        // Create multipart request body for fetch all the group stats
+        MultipartRequestFlowCaseBuilder  multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
+        MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
+        mprFlowRequestBuilder.setTableId(arg0.getTableId());
+        mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
+        mprFlowRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY);
+        mprFlowRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE);
+        mprFlowRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK);
+
+
+        if(version == OpenflowEnumConstant.OPENFLOW_V10){
+            mprFlowRequestBuilder.setMatchV10(MatchConvertor.toMatchV10(arg0.getMatch()));
+        }
+        if(version == OpenflowEnumConstant.OPENFLOW_V13){
+            MatchBuilder matchBuilder = new MatchBuilder();
+            matchBuilder.setMatchEntries(MatchConvertor.toMatch(arg0.getMatch()));
+            matchBuilder.setType(OxmMatchType.class);
+            mprFlowRequestBuilder.setMatch(matchBuilder.build());
+        
+            mprFlowRequestBuilder.setCookie(arg0.getCookie());
+            mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask());
+            mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
+        }
+
+        //Set request body to main multipart request
+        multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
+        mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+
+        //Send the request, no cookies associated, use any connection
+        LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
+        this.messageService.multipartRequest(mprInput.build(), null);
+
+        // Prepare rpc return output. Set xid and send it back.
+        GetFlowStatisticsFromFlowTableOutputBuilder output = 
+                new GetFlowStatisticsFromFlowTableOutputBuilder();
+        output.setTransactionId(generateTransactionId(xid));
+        output.setFlowAndStatisticsMapList(null);
+
+        Collection<RpcError> errors = Collections.emptyList();
+        RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
+        return Futures.immediateFuture(rpcResult);
+    }
+
+    @Override
+    public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
+            GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
+        //Generate xid to associate it with the request
+        Long xid = this.getSessionContext().getNextXid();
+
+        LOG.debug("Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}"
+                ,arg0.getTableId().getValue(),xid);
+
+        // Create multipart request header
+        MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
+        mprInput.setType(MultipartType.OFPMPAGGREGATE);
+        mprInput.setVersion(version);
+        mprInput.setXid(xid);
+        mprInput.setFlags(new MultipartRequestFlags(false));
+
+        // Create multipart request body for fetch all the group stats
+        MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder  = new MultipartRequestAggregateCaseBuilder (); 
+        MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
+        mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
+        mprAggregateRequestBuilder.setOutPort(OpenflowEnumConstant.OFPP_ANY);
+        mprAggregateRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY);
+        mprAggregateRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE);
+        mprAggregateRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK);
+        if(version == OpenflowEnumConstant.OPENFLOW_V10){
+            FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,false,false,false,false,false,false,false,false,false,false);
+            mprAggregateRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
+        }
+        if(version == OpenflowEnumConstant.OPENFLOW_V13){
+            mprAggregateRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
+        }
+
+
+        //Set request body to main multipart request
+        multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
+        mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
+
+        //Send the request, no cookies associated, use any connection
+        LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
+        this.messageService.multipartRequest(mprInput.build(), null);
+
+        // Prepare rpc return output. Set xid and send it back.
+        GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output = 
+                new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
+        output.setTransactionId(generateTransactionId(xid));
+
+        Collection<RpcError> errors = Collections.emptyList();
+        RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
+        return Futures.immediateFuture(rpcResult);
+    }
+
+    @Override
+    public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
+            GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
+
+        //Generate xid to associate it with the request
+        Long xid = this.getSessionContext().getNextXid();
+
+        LOG.debug("Prepare agregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}"
+                ,arg0.getMatch().toString(),arg0.getTableId(),xid);
+
+        // Create multipart request header
+        MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
+        mprInput.setType(MultipartType.OFPMPAGGREGATE);
+        mprInput.setVersion(version);
+        mprInput.setXid(xid);
+        mprInput.setFlags(new MultipartRequestFlags(false));
+
+        // Create multipart request body for fetch all the group stats
+        MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder  = new MultipartRequestAggregateCaseBuilder (); 
+        MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
+        mprAggregateRequestBuilder.setTableId(arg0.getTableId());
+        mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
+        mprAggregateRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY);
+        mprAggregateRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE);
+        mprAggregateRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK);
+
+
+        if(version == OpenflowEnumConstant.OPENFLOW_V10){
+            mprAggregateRequestBuilder.setMatchV10(MatchConvertor.toMatchV10(arg0.getMatch()));
+        }
+        if(version == OpenflowEnumConstant.OPENFLOW_V13){
+            MatchBuilder matchBuilder = new MatchBuilder();
+            matchBuilder.setMatchEntries(MatchConvertor.toMatch(arg0.getMatch()));
+            matchBuilder.setType(OxmMatchType.class);
+            mprAggregateRequestBuilder.setMatch(matchBuilder.build());
+        
+            mprAggregateRequestBuilder.setCookie(arg0.getCookie());
+            mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask());
+            mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
+        }
+
+        //Set request body to main multipart request
+        multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
+        mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
+
+        //Send the request, no cookies associated, use any connection
+        LOG.debug("Send request for to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
+        this.messageService.multipartRequest(mprInput.build(), null);
+
+        // Prepare rpc return output. Set xid and send it back.
+        GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output = 
+                new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
+        output.setTransactionId(generateTransactionId(xid));
+
+        Collection<RpcError> errors = Collections.emptyList();
+        RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
+        return Futures.immediateFuture(rpcResult);
+    }
+
+    @Override
+    public Future<RpcResult<GetAllFlowStatisticsOutput>> getAllFlowStatistics(GetAllFlowStatisticsInput arg0) {
+        //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it.
+        // Once sal-compatibility layer is fixed this rpc call can be removed from yang file 
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetAllNodeConnectorStatisticsOutput>> getAllNodeConnectorStatistics(
+            GetAllNodeConnectorStatisticsInput arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetFlowStatisticsOutput>> getFlowStatistics(GetFlowStatisticsInput arg0) {
+        //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it.
+        // Once sal-compatibility layer is fixed this rpc call can be removed from yang file 
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetFlowTableStatisticsOutput>> getFlowTableStatistics(GetFlowTableStatisticsInput arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
+            GetNodeConnectorStatisticsInput arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowStatsResponseConvertor.java
new file mode 100644 (file)
index 0000000..8743ba5
--- /dev/null
@@ -0,0 +1,132 @@
+package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.generic.statistics.DurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
+
+/**
+ * Class is an utility class for converting flow related statistics messages coming from openflow 
+ * switch to MD-SAL messages.
+ * @author avishnoi@in.ibm.com
+ *
+ */
+public class FlowStatsResponseConvertor {
+    
+    /**
+     * Method returns the list of MD-SAL format flow statistics, converted flow Openflow
+     * specific flow statistics. 
+     * @param allFlowStats
+     * @return
+     */
+    public List<FlowAndStatisticsMapList> toSALFlowStatsList(List<FlowStats> allFlowStats){
+        
+        List<FlowAndStatisticsMapList> convertedSALFlowStats = new ArrayList<FlowAndStatisticsMapList>();
+        
+        for(FlowStats flowStats : allFlowStats){
+            convertedSALFlowStats.add(toSALFlowStats(flowStats));
+        }
+        
+        return convertedSALFlowStats;
+    }
+
+    /**
+     * Method convert Openflow switch specific flow statistics to the MD-SAL format 
+     * flow statistics.
+     * @param flowStats
+     * @return
+     */
+    public FlowAndStatisticsMapList toSALFlowStats(FlowStats flowStats){
+        FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
+        salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
+        salFlowStatsBuilder.setCookie(flowStats.getCookie());
+
+        DurationBuilder time = new DurationBuilder();
+        time.setSecond(new Counter64(new BigInteger(flowStats.getDurationSec().toString())));
+        time.setNanosecond(new Counter64(new BigInteger(flowStats.getDurationNsec().toString())));
+        salFlowStatsBuilder.setDuration(time.build());
+        
+        salFlowStatsBuilder.setFlags(
+                new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(),
+                        flowStats.getFlags().isOFPFFRESETCOUNTS(),
+                        flowStats.getFlags().isOFPFFNOPKTCOUNTS(),
+                        flowStats.getFlags().isOFPFFNOBYTCOUNTS(),
+                        flowStats.getFlags().isOFPFFSENDFLOWREM()));
+        
+        salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
+        salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
+        salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
+        salFlowStatsBuilder.setPriority(flowStats.getPriority());
+        salFlowStatsBuilder.setTableId(flowStats.getTableId());
+        if(flowStats.getMatchV10() != null){
+            salFlowStatsBuilder.setMatch(MatchConvertor.fromOFMatchV10ToSALMatch(flowStats.getMatchV10()));
+        }
+        if(flowStats.getMatch() != null){
+            salFlowStatsBuilder.setMatch(MatchConvertor.fromOFMatchToSALMatch(flowStats.getMatch()));
+        }
+        if(flowStats.getInstructions()!= null){
+            salFlowStatsBuilder.setInstructions(toSALInstruction(flowStats.getInstructions()));
+        }
+        
+        return salFlowStatsBuilder.build();
+        
+    }
+    
+    /**
+     * Method convert Openflow 1.3+ specific instructions to MD-SAL format
+     * flow instruction
+     * Note: MD-SAL won't augment this data directly to the data store, 
+     * so key setting is not required. If user wants to augment this data
+     * directly to the data store, key setting is required for each instructions. 
+     * @param instructions
+     * @return
+     */
+    public Instructions toSALInstruction(
+            List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions> instructions) {
+        
+        InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
+        
+        List<Instruction> salInstructionList = new ArrayList<Instruction>();
+        
+        for(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions switchInst : instructions){
+            if(switchInst instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions){
+                InstructionBuilder instBuilder = new InstructionBuilder();
+                instBuilder.setInstruction(new ApplyActionsCaseBuilder().build());
+                salInstructionList.add(instBuilder.build());
+            }else if(switchInst instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions){
+                InstructionBuilder instBuilder = new InstructionBuilder();
+                instBuilder.setInstruction(new ClearActionsCaseBuilder().build());
+                salInstructionList.add(instBuilder.build());
+            }else if(switchInst instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable){
+                InstructionBuilder instBuilder = new InstructionBuilder();
+                instBuilder.setInstruction(new GoToTableCaseBuilder().build());
+                salInstructionList.add(instBuilder.build());
+            }else if(switchInst instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions){
+                InstructionBuilder instBuilder = new InstructionBuilder();
+                instBuilder.setInstruction(new WriteActionsCaseBuilder().build());
+                salInstructionList.add(instBuilder.build());
+            }else if(switchInst instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata){
+                InstructionBuilder instBuilder = new InstructionBuilder();
+                instBuilder.setInstruction(new WriteMetadataCaseBuilder().build());
+                salInstructionList.add(instBuilder.build());
+            }
+        }
+        instructionsBuilder.setInstruction(salInstructionList);
+        return instructionsBuilder.build();
+    }
+}
index 0a06b54d5e75d8ffd66765f5f0ddba88e86ee446..11cab51653c75d556b451a95f1dd98cb75332b93 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
 
 import java.math.BigInteger;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -17,33 +18,59 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
@@ -94,6 +121,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
@@ -137,6 +165,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpD
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
 import org.slf4j.Logger;
@@ -148,6 +178,9 @@ import org.slf4j.LoggerFactory;
 public class MatchConvertor {
     private static final Logger logger = LoggerFactory.getLogger(MatchConvertor.class);
     private static final String PREFIX_SEPARATOR = "/";
+    
+    private static final short PROTO_TCP = 6;
+    private static final short PROTO_UDP = 17;
 
     public static List<MatchEntries> toMatch(
             org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match) {
@@ -364,7 +397,547 @@ public class MatchConvertor {
 
         return matchEntriesList;
     }
+    
+    /**
+     * Method builds openflow 1.0 specific match (MatchV10) from MD-SAL match.
+     * @param match MD-SAL match
+     * @return
+     * @author avishnoi@in.ibm.com
+     */
+    public static MatchV10 toMatchV10(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match) {
+        
+        MatchV10Builder matchv10Builder = new MatchV10Builder();
+        if(match.getEthernetMatch()!= null){
+            matchv10Builder.setDlDst(match.getEthernetMatch().getEthernetDestination().getAddress());
+            matchv10Builder.setDlSrc(match.getEthernetMatch().getEthernetSource().getAddress());
+            matchv10Builder.setDlType(match.getEthernetMatch().getEthernetType().getType().getValue().intValue());
+        }
+        if(match.getVlanMatch()!= null){
+            matchv10Builder.setDlVlan(match.getVlanMatch().getVlanId().getVlanId().getValue());
+            matchv10Builder.setDlVlanPcp(match.getVlanMatch().getVlanPcp().getValue());
+        }
+        if(match.getInPort()!=null){
+            matchv10Builder.setInPort(match.getInPort().intValue());
+        }
+        Layer3Match l3Match = match.getLayer3Match();
+        if(l3Match != null){
+            if(l3Match instanceof Ipv4Match){
+                Ipv4Match ipv4 = (Ipv4Match)l3Match;
+                Ipv4Address ipv4Address = null;
+                String[] addressParts;
+                Integer prefix;
+                if(ipv4.getIpv4Source()!=null){
+                    addressParts = ipv4.getIpv4Source().getValue().split(PREFIX_SEPARATOR);
+                    prefix = null;
+                    if (addressParts.length < 2) {
+                        prefix = 0;
+                    } else {
+                        prefix = Integer.parseInt(addressParts[1]);
+                    }
+    
+                    ipv4Address = new Ipv4Address(addressParts[0]);
+                    matchv10Builder.setNwSrc(ipv4Address);
+                    matchv10Builder.setNwSrcMask(prefix.shortValue());
+                }
+
+                if(ipv4.getIpv4Destination()!=null){
+                    addressParts = ipv4.getIpv4Destination().getValue().split("/");
+                    prefix = null;
+                    if (addressParts.length < 2) {
+                        prefix = 0;
+                    } else {
+                        prefix = Integer.parseInt(addressParts[1]);
+                    }
+    
+                    ipv4Address = new Ipv4Address(addressParts[0]);
+                    matchv10Builder.setNwDst(ipv4Address);
+                    matchv10Builder.setNwDstMask(prefix.shortValue());
+                }
+            }
+        }
+        IpMatch ipMatch = match.getIpMatch();
+        if(ipMatch!=null){
+            matchv10Builder.setNwProto(ipMatch.getIpProtocol());
+            matchv10Builder.setNwTos(ipMatch.getIpDscp().getValue());
+        }
+        
+        Layer4Match layer4Match = match.getLayer4Match();
+        if (layer4Match != null) {
+            if (layer4Match instanceof TcpMatch) {
+                TcpMatch tcpMatch = (TcpMatch) layer4Match;
+                if (tcpMatch.getTcpSourcePort() != null) {
+                    matchv10Builder.setTpSrc(tcpMatch.getTcpSourcePort().getValue());                        
+                }
+
+                if (tcpMatch.getTcpDestinationPort() != null) {
+                    matchv10Builder.setTpDst(tcpMatch.getTcpDestinationPort().getValue());
+                }
+            } else if (layer4Match instanceof UdpMatch) {
+                UdpMatch udpMatch = (UdpMatch) layer4Match;
+                if (udpMatch.getUdpSourcePort() != null) {
+                    matchv10Builder.setTpSrc(udpMatch.getUdpSourcePort().getValue());                        
+                }
+
+                if (udpMatch.getUdpDestinationPort() != null) {
+                    matchv10Builder.setTpDst(udpMatch.getUdpDestinationPort().getValue());
+                }
+            }
+        }
+        matchv10Builder.setWildcards(new FlowWildcardsV10(true,
+                        matchv10Builder.getDlDst()!=null?true:false,
+                        matchv10Builder.getDlSrc()!=null?true:false,
+                        matchv10Builder.getDlType()!=null?true:false,
+                        matchv10Builder.getDlVlan()!=null?true:false,
+                        matchv10Builder.getDlVlanPcp()!=null?true:false,
+                        matchv10Builder.getInPort()!=null?true:false,
+                        matchv10Builder.getNwProto()!=null?true:false,
+                        matchv10Builder.getNwTos()!=null?true:false,
+                        matchv10Builder.getTpDst()!=null?true:false,
+                        matchv10Builder.getTpSrc()!=null?true:false));
+        
+        return matchv10Builder.build();
+    }
+
+    /**
+     * Method convert Openflow 1.0 specific flow match to MD-SAL format 
+     * flow match
+     * @param match
+     * @return
+     * @author avishnoi@in.ibm.com
+     */
+    public static Match fromOFMatchV10ToSALMatch(MatchV10 swMatch){
+        MatchBuilder matchBuilder = new MatchBuilder();
+        EthernetMatchBuilder ethMatchBuilder =  new EthernetMatchBuilder();
+        VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
+        Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
+        IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
+       
+        if(swMatch.getInPort() != null){
+            matchBuilder.setInPort((long)swMatch.getInPort());
+        }
+        
+        if(swMatch.getDlSrc()!= null){
+            EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
+            ethSrcBuilder.setAddress(swMatch.getDlSrc());
+            ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
+            matchBuilder.setEthernetMatch(ethMatchBuilder.build());
+        }
+        if(swMatch.getDlDst()!= null){
+            EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
+            ethDstBuilder.setAddress(swMatch.getDlDst());
+            ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
+            matchBuilder.setEthernetMatch(ethMatchBuilder.build());
+        }
+        if(swMatch.getDlType()!= null){
+            EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
+            ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long)swMatch.getDlType()));
+            ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
+            matchBuilder.setEthernetMatch(ethMatchBuilder.build());
+        }
+        if(swMatch.getDlVlan()!=null){
+            VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
+            vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(swMatch.getDlVlan()));
+            vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
+            matchBuilder.setVlanMatch(vlanMatchBuilder.build());
+        }
+        if(swMatch.getDlVlanPcp()!= null){
+            vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(swMatch.getDlVlanPcp()));
+            matchBuilder.setVlanMatch(vlanMatchBuilder.build());
+        }
+        if(swMatch.getNwSrc() !=null){
+            String ipv4PrefixStr = swMatch.getNwSrc().getValue();
+            if(swMatch.getNwSrcMask()!= null){
+                ipv4PrefixStr +=PREFIX_SEPARATOR+swMatch.getNwSrcMask();
+            }
+            ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
+            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
+        }
+        if(swMatch.getNwDst() !=null){
+            String ipv4PrefixStr = swMatch.getNwDst().getValue();
+            if(swMatch.getNwDstMask()!= null){
+                ipv4PrefixStr +=PREFIX_SEPARATOR+swMatch.getNwDstMask();
+            }
+            ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
+            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
+        }
+        if(swMatch.getNwProto()!= null ){
+            ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
+            matchBuilder.setIpMatch(ipMatchBuilder.build());
+        }
+        if(swMatch.getNwProto() == PROTO_TCP){
+            TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
+            if(swMatch.getTpSrc()!= null)
+                tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpSrc()));
+            if(swMatch.getTpDst()!= null)
+                tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpDst()));
+            matchBuilder.setLayer4Match(tcpMatchBuilder.build());
+        }
+        if(swMatch.getNwProto() == PROTO_UDP){
+            UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
+            if(swMatch.getTpSrc()!= null)
+                udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpSrc()));
+            if(swMatch.getTpDst()!= null)
+                udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpDst()));
+            matchBuilder.setLayer4Match(udpMatchBuilder.build());
+        }
+        if(swMatch.getNwTos()!=null){
+            ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
+            matchBuilder.setIpMatch(ipMatchBuilder.build());
+        }
+        
+        return matchBuilder.build();
+    }
+
+    /**
+     * Method converts Openflow 1.3+ specific flow match to MD-SAL format
+     * flow match
+     * @param match
+     * @return
+     * @author avishnoi@in.ibm.com
+     */
+    public static Match fromOFMatchToSALMatch(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match swMatch) {
+        
+        MatchBuilder matchBuilder = new MatchBuilder();
+        EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
+        VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
+        IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
+        TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
+        UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
+        SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
+        Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
+        Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
+        Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
+        ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
+        Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
+        ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
+
+        List<MatchEntries> swMatchList = swMatch.getMatchEntries();
+        
+        for(MatchEntries ofMatch : swMatchList){
+            
+            if(ofMatch.getOxmMatchField().equals(InPort.class)){
+                PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
+                matchBuilder.setInPort(portNumber.getPortNumber().getValue());
+            }else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)){
+                PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
+                matchBuilder.setInPhyPort(portNumber.getPortNumber().getValue());
+            }else if(ofMatch.getOxmMatchField().equals(Metadata.class)){
+                MetadataBuilder metadataBuilder = new MetadataBuilder();
+                MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
+                if(metadataMatchEntry != null){
+                    metadataBuilder.setMetadata(new BigInteger(metadataMatchEntry.getMetadata()));
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        metadataBuilder.setMetadataMask(maskMatchEntry.getMask());
+                    }
+                    matchBuilder.setMetadata(metadataBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(EthSrc.class)){
+                MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
+                if(macAddressMatchEntry != null){
+                    EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
+                    ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
+                    ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
+                    matchBuilder.setEthernetMatch(ethMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(EthDst.class)){
+                MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
+                if(macAddressMatchEntry != null){
+                    EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
+                    ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
+                    ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
+                    matchBuilder.setEthernetMatch(ethMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(EthType.class)){
+                EthTypeMatchEntry ethTypeMatchEntry = ofMatch.getAugmentation(EthTypeMatchEntry.class);
+                if(ethTypeMatchEntry != null){
+                    EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
+                    ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long)ethTypeMatchEntry.getEthType().getValue()));
+                    ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
+                    matchBuilder.setEthernetMatch(ethMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(VlanVid.class)){
+                VlanVidMatchEntry vlanVidMatchEntry = ofMatch.getAugmentation(VlanVidMatchEntry.class);
+                if(vlanVidMatchEntry != null){
+                    VlanIdBuilder vlanBuilder = new VlanIdBuilder();
+                    vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanVidMatchEntry.getVlanVid()));
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        vlanBuilder.setMask(maskMatchEntry.getMask());
+                    }
+                    vlanMatchBuilder.setVlanId(vlanBuilder.build());
+                    matchBuilder.setVlanMatch(vlanMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(VlanPcp.class)){
+                VlanPcpMatchEntry vlanPcpMatchEntry = ofMatch.getAugmentation(VlanPcpMatchEntry.class);
+                if(vlanPcpMatchEntry != null){
+                    vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(vlanPcpMatchEntry.getVlanPcp()));
+                    matchBuilder.setVlanMatch(vlanMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(IpDscp.class)){
+                DscpMatchEntry dscpMatchEntry = ofMatch.getAugmentation(DscpMatchEntry.class);
+                if(dscpMatchEntry != null){
+                    ipMatchBuilder.setIpDscp(new Dscp(dscpMatchEntry.getDscp().getValue()));
+                    matchBuilder.setIpMatch(ipMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(IpEcn.class)){
+                EcnMatchEntry ecnMatchEntry = ofMatch.getAugmentation(EcnMatchEntry.class);
+                if(ecnMatchEntry != null){
+                    ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
+                    matchBuilder.setIpMatch(ipMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(IpProto.class)){
+                ProtocolNumberMatchEntry protocolNumberMatchEntry = ofMatch.getAugmentation(ProtocolNumberMatchEntry.class);
+                if(protocolNumberMatchEntry != null){
+                    ipMatchBuilder.setIpProtocol(protocolNumberMatchEntry.getProtocolNumber());
+                    matchBuilder.setIpMatch(ipMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(TcpSrc.class)){
+                PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
+                if(portMatchEntry != null){
+                    tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
+                    matchBuilder.setLayer4Match(tcpMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(TcpDst.class)){
+                PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
+                if(portMatchEntry != null){
+                    tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
+                    matchBuilder.setLayer4Match(tcpMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(UdpSrc.class)){
+                PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
+                if(portMatchEntry != null){
+                    udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
+                    matchBuilder.setLayer4Match(udpMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(UdpDst.class)){
+                PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
+                if(portMatchEntry != null){
+                    udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
+                    matchBuilder.setLayer4Match(udpMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(SctpSrc.class)){
+                PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
+                if(portMatchEntry != null){
+                    sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
+                    matchBuilder.setLayer4Match(sctpMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(SctpDst.class)){
+                PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
+                if(portMatchEntry != null){
+                    sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
+                    matchBuilder.setLayer4Match(sctpMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Icmpv4Type.class)){
+                Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = ofMatch.getAugmentation(Icmpv4TypeMatchEntry.class);
+                if(icmpv4TypeMatchEntry != null){
+                    icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
+                    matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Icmpv4Code.class)){
+                Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = ofMatch.getAugmentation(Icmpv4CodeMatchEntry.class);
+                if(icmpv4CodeMatchEntry != null){
+                    icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
+                    matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Icmpv6Type.class)){
+                Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = ofMatch.getAugmentation(Icmpv6TypeMatchEntry.class);
+                if(icmpv6TypeMatchEntry != null){
+                    icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
+                    matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Icmpv6Code.class)){
+                Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = ofMatch.getAugmentation(Icmpv6CodeMatchEntry.class);
+                if(icmpv6CodeMatchEntry != null){
+                    icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
+                    matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Ipv4Src.class) ||
+                    ofMatch.getOxmMatchField().equals(Ipv4Dst.class)){
+                Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
+                if(ipv4AddressMatchEntry != null){
+                    String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        ipv4PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
+                    }
+                    if(ofMatch.getOxmMatchField().equals(Ipv4Src.class)){
+                        ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
+                    }
+                    if(ofMatch.getOxmMatchField().equals(Ipv4Dst.class)){
+                        ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
+                    }
+                    matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(ArpOp.class)){
+                OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
+                if(opCodeMatchEntry != null){
+                    arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
+                    matchBuilder.setLayer3Match(arpMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(ArpSpa.class) ||
+                    ofMatch.getOxmMatchField().equals(ArpTpa.class)){
+                Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
+                if(ipv4AddressMatchEntry != null){
+                    String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        ipv4PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
+                    }
+                    if(ofMatch.getOxmMatchField().equals(ArpSpa.class)){
+                        arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
+                    }
+                    if(ofMatch.getOxmMatchField().equals(ArpTpa.class)){
+                        arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
+                    }
+                    matchBuilder.setLayer3Match(arpMatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(ArpSha.class) ||
+                    ofMatch.getOxmMatchField().equals(ArpTha.class)){
+                MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
+                if(macAddressMatchEntry !=null){
+                    if(ofMatch.getOxmMatchField().equals(ArpSha.class)){
+                        ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
+                        arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
+                        MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                        if(maskMatchEntry != null){
+                            arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
+                        }
+                        arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
+                        matchBuilder.setLayer3Match(arpMatchBuilder.build());
+                    }
+                    if(ofMatch.getOxmMatchField().equals(ArpTha.class)){
+                        ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
+                        arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
+                        MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                        if(maskMatchEntry != null){
+                            arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
+                        }
+                        arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
+                        matchBuilder.setLayer3Match(arpMatchBuilder.build());
+                    }
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Ipv6Src.class) ||
+                    ofMatch.getOxmMatchField().equals(Ipv6Dst.class)){
+                Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
+                if(ipv6AddressMatchEntry != null){
+                    String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        ipv6PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
+                    }
+                    if(ofMatch.getOxmMatchField().equals(Ipv6Src.class)){
+                        ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
+                    }
+                    if(ofMatch.getOxmMatchField().equals(Ipv6Dst.class)){
+                        ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
+                    }
+                    matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)){
+                Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = ofMatch.getAugmentation(Ipv6FlabelMatchEntry.class);
+                if(ipv6FlabelMatchEntry != null){
+                    Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
+                    ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6FlabelMatchEntry.getIpv6Flabel()));
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
+                    }
+                    ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
+                    matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)){
+                Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
+                if(ipv6AddressMatchEntry != null){
+                    ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
+                    matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)){
+                MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
+                if(macAddressMatchEntry != null){
+                    ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
+                    matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)){
+                MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
+                if(macAddressMatchEntry != null){
+                    ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
+                    matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)){
+                PseudoFieldMatchEntry pseudoFieldMatchEntry = ofMatch.getAugmentation(PseudoFieldMatchEntry.class);
+                if(pseudoFieldMatchEntry != null){
+                    Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
+                        
+                    PseudoField pField = pseudoFieldMatchEntry.getPseudoField();
+                    Integer bitmap = 0;
+                    bitmap |= pField.isNonext()?(1 << 0): ~(1 << 0);
+                    bitmap |= pField.isEsp()?(1 << 1): ~(1 << 1);
+                    bitmap |= pField.isAuth()?(1 << 2): ~(1 << 2);
+                    bitmap |= pField.isDest()?(1 << 3): ~(1 << 3);
+                    bitmap |= pField.isFrag()?(1 << 4): ~(1 << 4);
+                    bitmap |= pField.isRouter()?(1 << 5): ~(1 << 5);
+                    bitmap |= pField.isHop()?(1 << 6): ~(1 << 6);
+                    bitmap |= pField.isUnrep()?(1 << 7): ~(1 << 7);
+                    bitmap |= pField.isUnseq()?(1 << 8): ~(1 << 8);
+
+                    ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        ipv6ExtHeaderBuilder.setIpv6ExthdrMask(maskMatchEntry.getMask());
+                    }
+                    ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
+                    matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(MplsLabel.class)){
+                MplsLabelMatchEntry mplsLabelMatchEntry = ofMatch.getAugmentation(MplsLabelMatchEntry.class);
+                if(mplsLabelMatchEntry != null){
+                    protocolMatchFieldsBuilder.setMplsLabel(mplsLabelMatchEntry.getMplsLabel());
+                    matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(MplsBos.class)){
+                BosMatchEntry bosMatchEntry = ofMatch.getAugmentation(BosMatchEntry.class);
+                if(bosMatchEntry != null){
+                    protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
+                    matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(MplsTc.class)){
+                TcMatchEntry tcMatchEntry = ofMatch.getAugmentation(TcMatchEntry.class);
+                if(tcMatchEntry != null){
+                    protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
+                    matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(PbbIsid.class)){
+                IsidMatchEntry isidMatchEntry = ofMatch.getAugmentation(IsidMatchEntry.class);
+                if(isidMatchEntry != null){
+                    PbbBuilder pbbBuilder = new PbbBuilder();
+                    pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        pbbBuilder.setPbbMask(maskMatchEntry.getMask());
+                    }
+                    protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
+                    matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
+                }
+            }else if(ofMatch.getOxmMatchField().equals(TunnelId.class)){
+                TunnelBuilder tunnelBuilder = new TunnelBuilder();
+                MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
+                if(metadataMatchEntry != null){
+                    tunnelBuilder.setTunnelId(new BigInteger(metadataMatchEntry.getMetadata()));
+                    MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
+                    if(maskMatchEntry != null){
+                        tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
+                    }
+                    matchBuilder.setTunnel(tunnelBuilder.build());
+                }
+            }
+        }
+        return matchBuilder.build();
+    }
 
+    
     private static MatchEntries toOfMplsPbb(Pbb pbb) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         boolean hasmask = false;
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OpenflowEnumConstant.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OpenflowEnumConstant.java
new file mode 100644 (file)
index 0000000..05ba02e
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright IBM Corporation, 2013.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
+
+import java.math.BigInteger;
+
+
+/**
+ * Class holds Openflow enum contant.
+ * @author avishnoi@in.ibm.com
+ *
+ */
+public class OpenflowEnumConstant {
+    
+    public static final Short OFPTT_ALL = 0xff;
+    public static final Long ANY = Long.parseLong("ffffffff", 16);
+    public static final Long OFPP_ANY = ANY;
+    public static final Long OFPG_ANY = ANY;
+    public static final BigInteger DEFAULT_COOKIE = BigInteger.ZERO;
+    public static final BigInteger DEFAULT_COOKIE_MASK = BigInteger.ZERO;
+    public static short OPENFLOW_V10 = 0x01;
+    public static short OPENFLOW_V13 = 0x04;
+
+
+}
index 625e2c13c10fa4f8076131b57ca43f9401654adf..bed00bf975d99dd1dfdae6d917be13d9e17225c9 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright IBM Corporation, 2013.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.openflowplugin.openflow.md.core.translator;
 
 import java.math.BigInteger;
@@ -7,10 +14,14 @@ 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.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.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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdatedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdatedBuilder;
@@ -39,12 +50,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCase;
 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.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.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;
@@ -67,6 +82,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
     protected static final Logger logger = LoggerFactory
             .getLogger(MultipartReplyTranslator.class);
     
+    private static FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor();
     private static GroupStatsResponseConvertor groupStatsConvertor = new GroupStatsResponseConvertor();
     private static MeterStatsResponseConvertor meterStatsConvertor = new MeterStatsResponseConvertor();
 
@@ -79,6 +95,38 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
             MultipartReplyMessage mpReply = (MultipartReplyMessage)msg;
             NodeId node = this.nodeIdFromDatapathId(sc.getFeatures().getDatapathId());
             switch (mpReply.getType()){
+            case OFPMPFLOW: {
+                logger.info("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());
+                message.setTransactionId(generateTransactionId(mpReply.getXid()));
+                MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase)mpReply.getMultipartReplyBody();
+                MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
+                message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats()));
+                
+                logger.info("Converted flow statistics : {}",message.build().toString());
+                listDataObject.add(message.build());
+                return listDataObject;
+            }
+            case OFPMPAGGREGATE: {
+                logger.info("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());
+                message.setTransactionId(generateTransactionId(mpReply.getXid()));
+                
+                MultipartReplyAggregateCase caseBody = (MultipartReplyAggregateCase)mpReply.getMultipartReplyBody();
+                MultipartReplyAggregate replyBody = caseBody.getMultipartReplyAggregate();
+                message.setByteCount(new Counter64(replyBody.getByteCount()));
+                message.setPacketCount(new Counter64(replyBody.getPacketCount()));
+                message.setFlowCount(new Counter32(replyBody.getFlowCount()));
+                
+                logger.info("Converted aggregate flow statistics : {}",message.build().toString());
+                listDataObject.add(message.build());
+                return listDataObject;
+                
+            }
             case OFPMPGROUP:{
                 logger.info("Received group statistics multipart reponse");
                 GroupStatisticsUpdatedBuilder message = new GroupStatisticsUpdatedBuilder();
@@ -88,6 +136,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                 MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase)mpReply.getMultipartReplyBody();
                 MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
                 message.setGroupStats(groupStatsConvertor.toSALGroupStatsList(replyBody.getGroupStats()));
+                
                 logger.debug("Converted group statistics : {}",message.toString());
                 listDataObject.add(message.build());
                 return listDataObject;
@@ -101,7 +150,9 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                 message.setTransactionId(generateTransactionId(mpReply.getXid()));
                 MultipartReplyGroupDescCase caseBody = (MultipartReplyGroupDescCase)mpReply.getMultipartReplyBody();
                 MultipartReplyGroupDesc replyBody = caseBody.getMultipartReplyGroupDesc();
+
                 message.setGroupDescStats(groupStatsConvertor.toSALGroupDescStatsList(replyBody.getGroupDesc()));
+                
                 logger.debug("Converted group statistics : {}",message.toString());
                 listDataObject.add(message.build());
                 return listDataObject;
@@ -183,6 +234,7 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                 MultipartReplyMeterConfigCase caseBody = (MultipartReplyMeterConfigCase)mpReply.getMultipartReplyBody();
                 MultipartReplyMeterConfig replyBody = caseBody.getMultipartReplyMeterConfig();
                 message.setMeterConfigStats(meterStatsConvertor.toSALMeterConfigList(replyBody.getMeterConfig()));
+                
                 listDataObject.add(message.build());
                 return listDataObject;
             }
@@ -236,7 +288,6 @@ public class MultipartReplyTranslator implements IMDMessageTranslator<OfHeader,
                 return listDataObject;
             }
             default:
-                logger.info(" Type : {}, not handled yet",mpReply.getType().name() );
                 return listDataObject;
             }
         }