BUG 2280 - mac address mask translation.
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchConvertorImpl.java
index 0f44849ddd32001d0f58af31f1e42a297bd3949e..dba2e92a3f420dc54e1cd79cf5da33610e6e13e7 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2013 Ericsson. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Ericsson. and others.  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,
@@ -8,12 +8,25 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
 
+import static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Splitter;
 import java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
-
+import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
+import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
+import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionResolvers;
+import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
+import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil;
 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
+import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
 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;
@@ -52,6 +65,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 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.TcpFlagMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatchBuilder;
 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;
@@ -61,6 +76,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 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._3.match.TunnelIpv4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
 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;
@@ -105,6 +122,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
@@ -115,10 +133,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcpFlagMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
 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.action.rev130731.actions.grouping.Action;
 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.Ipv6ExthdrFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
@@ -158,15 +178,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbI
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpFlag;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Dst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Src;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
 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.oxm.fields.MatchEntries;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -176,20 +202,27 @@ import org.slf4j.LoggerFactory;
 public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
     private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
     static final String PREFIX_SEPARATOR = "/";
-    private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 };
+    static final Splitter PREFIX_SPLITTER = Splitter.on('/');
+    private static final byte[] VLAN_VID_MASK = new byte[]{16, 0};
     private static final short PROTO_TCP = 6;
     private static final short PROTO_UDP = 17;
+    private static final String noIp = "0.0.0.0/0";
 
     @Override
-    public List<MatchEntries> convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match) {
+    public List<MatchEntries> convert(
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) {
         List<MatchEntries> matchEntriesList = new ArrayList<>();
-
+        if (match == null) return matchEntriesList;
         if (match.getInPort() != null) {
-            matchEntriesList.add(toOfPort(InPort.class, match.getInPort()));
+            //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
+            matchEntriesList.add(toOfPort(InPort.class,
+                    InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPort())));
         }
 
         if (match.getInPhyPort() != null) {
-            matchEntriesList.add(toOfPort(InPhyPort.class, match.getInPhyPort()));
+            //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
+            matchEntriesList.add(toOfPort(InPhyPort.class,
+                    InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPhyPort())));
         }
 
         org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
@@ -308,6 +341,15 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                 if (ipv4Match.getIpv4Destination() != null) {
                     matchEntriesList.add(toOfIpv4Prefix(Ipv4Dst.class, ipv4Match.getIpv4Destination()));
                 }
+            }
+            if (layer3Match instanceof TunnelIpv4Match) {
+                TunnelIpv4Match tunnelIpv4Src = (TunnelIpv4Match) layer3Match;
+                if (tunnelIpv4Src.getTunnelIpv4Source() != null) {
+                    matchEntriesList.add(NxmExtensionsConvertor.toNxmIpv4Tunnel(TunnelIpv4Src.class, tunnelIpv4Src.getTunnelIpv4Source()));
+                }
+                if (tunnelIpv4Src.getTunnelIpv4Destination() != null) {
+                    matchEntriesList.add(NxmExtensionsConvertor.toNxmIpv4Tunnel(TunnelIpv4Dst.class, tunnelIpv4Src.getTunnelIpv4Destination()));
+                }
             } else if (layer3Match instanceof ArpMatch) {
                 ArpMatch arpMatch = (ArpMatch) layer3Match;
                 if (arpMatch.getArpOp() != null) {
@@ -333,9 +375,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                     matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
                             arpTargetHardwareAddress.getMask()));
                 }
-            }
-
-            else if (layer3Match instanceof Ipv6Match) {
+            } else if (layer3Match instanceof Ipv6Match) {
                 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
                 if (ipv6Match.getIpv6Source() != null) {
                     matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
@@ -386,116 +426,194 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
             }
         }
 
+        //FIXME: move to extensible support
+        // TODO: Move to seperate bundle as soon as OF extensibility is supported by ofplugin/java
+        TcpFlagMatch tcpFlagMatch = match.getTcpFlagMatch();
+        if (tcpFlagMatch != null) {
+            if (tcpFlagMatch.getTcpFlag() != null) {
+                matchEntriesList.add(NxmExtensionsConvertor.toNxmTcpFlag(tcpFlagMatch.getTcpFlag()));
+            }
+        }
+
         org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
                 .getTunnel();
         if (tunnel != null) {
             matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
         }
 
-        
+
+        /**
+         * TODO: EXTENSION PROPOSAL (match, MD-SAL to OFJava)
+         * - we might need version for conversion and for key
+         * - sanitize NPE
+         */
+        Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(match);
+        if (extensionListOpt.isPresent()) {
+            for (ExtensionList extensionItem : extensionListOpt.get().getExtensionList()) {
+                // TODO: get real version
+                ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
+                ConvertorToOFJava<MatchEntries> convertor =
+                        OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
+                MatchEntries ofMatch = convertor.convert(extensionItem.getExtension());
+                matchEntriesList.add(ofMatch);
+            }
+        }
+
         return matchEntriesList;
     }
-    
+
     /**
-     * Method convert Openflow 1.0 specific flow match to MD-SAL format 
-     * flow match
+     * 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){
+    public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
         MatchBuilder matchBuilder = new MatchBuilder();
-        EthernetMatchBuilder ethMatchBuilder =  new EthernetMatchBuilder();
+        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.getWildcards().isINPORT().booleanValue() && swMatch.getInPort() != null) {
+            matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
+                    (long) swMatch.getInPort(), ofVersion));
         }
-        
-        if(swMatch.getDlSrc()!= null){
+
+        if (!swMatch.getWildcards().isDLSRC().booleanValue() && swMatch.getDlSrc() != null) {
             EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
             ethSrcBuilder.setAddress(swMatch.getDlSrc());
             ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
         }
-        if(swMatch.getDlDst()!= null){
+        if (!swMatch.getWildcards().isDLDST().booleanValue() && swMatch.getDlDst() != null) {
             EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
             ethDstBuilder.setAddress(swMatch.getDlDst());
             ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
         }
-        if(swMatch.getDlType()!= null){
+        if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getDlType() != null) {
             EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
-            ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long)swMatch.getDlType()));
+            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){
+        if (!swMatch.getWildcards().isDLVLAN().booleanValue() && swMatch.getDlVlan() != null) {
             VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
-            vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(swMatch.getDlVlan()));
+            int vlanId = (swMatch.getDlVlan() == ((int) 0xffff)) ? 0 : swMatch.getDlVlan();
+            vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
+            vlanIdBuilder.setVlanIdPresent(vlanId == 0 ? false : true);
             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()));
+        if (!swMatch.getWildcards().isDLVLANPCP().booleanValue() && 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){
+        if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwSrc() != null) {
             String ipv4PrefixStr = swMatch.getNwSrc().getValue();
-            if(swMatch.getNwSrcMask()!= null){
-                ipv4PrefixStr +=PREFIX_SEPARATOR+swMatch.getNwSrcMask();
+            if (swMatch.getNwSrcMask() != null) {
+                ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwSrcMask();
+            } else {
+                //Openflow Spec : 1.3.2
+                //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
+                // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
+                // statistics response.
+
+                ipv4PrefixStr += PREFIX_SEPARATOR + "32";
+            }
+            if (!ipv4PrefixStr.equals(noIp)) {
+                ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
+                matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
             }
-            ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
-            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
         }
-        if(swMatch.getNwDst() !=null){
+        if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwDst() != null) {
             String ipv4PrefixStr = swMatch.getNwDst().getValue();
-            if(swMatch.getNwDstMask()!= null){
-                ipv4PrefixStr +=PREFIX_SEPARATOR+swMatch.getNwDstMask();
+            if (swMatch.getNwDstMask() != null) {
+                ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwDstMask();
+            } else {
+                //Openflow Spec : 1.3.2
+                //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
+                // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
+                // statistics response.
+
+                ipv4PrefixStr += PREFIX_SEPARATOR + "32";
+            }
+            if (!ipv4PrefixStr.equals(noIp)) {
+                ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
+                matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
             }
-            ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
-            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
         }
-        if(swMatch.getNwProto()!= null ){
+        if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() != null) {
             ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
             matchBuilder.setIpMatch(ipMatchBuilder.build());
         }
-        if(swMatch.getNwProto() == PROTO_TCP){
+        if (!swMatch.getWildcards().isNWPROTO().booleanValue() && 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.getWildcards().isTPSRC().booleanValue() && 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.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
+                tcpMatchBuilder
+                        .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
+                                swMatch.getTpDst()));
+            }
+
+            if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
+                matchBuilder.setLayer4Match(tcpMatchBuilder.build());
+            }
         }
-        if(swMatch.getNwProto() == PROTO_UDP){
+        if (!swMatch.getWildcards().isNWPROTO().booleanValue() && 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.getWildcards().isTPSRC().booleanValue() && 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.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
+                udpMatchBuilder
+                        .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
+                                swMatch.getTpDst()));
+            }
+
+            if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
+                matchBuilder.setLayer4Match(udpMatchBuilder.build());
+            }
         }
-        if(swMatch.getNwTos()!=null){
-            ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
+        if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
+            Short dscp = ActionUtil.tosToDscp(swMatch.getNwTos().shortValue());
+            ipMatchBuilder.setIpDscp(new Dscp(dscp));
             matchBuilder.setIpMatch(ipMatchBuilder.build());
         }
-        
+
         return matchBuilder.build();
     }
 
     /**
-     * Method converts Openflow 1.3+ specific flow match to MD-SAL format
-     * flow match
+     * Method converts Openflow 1.3+ specific flow match to MD-SAL format flow
+     * match
+     *
      * @param match
-     * @return
+     * @param swMatch
+     * @param datapathid
+     * @param ofVersion
+     * @return md-sal match instance
      * @author avishnoi@in.ibm.com
      */
-    public static Match fromOFMatchToSALMatch(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match swMatch) {
-        
+    public static MatchBuilder fromOFMatchToSALMatch(
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match swMatch,
+            final BigInteger datapathid, final OpenflowVersion ofVersion) {
+        return OfMatchToSALMatchConvertor(swMatch.getMatchEntries(), datapathid, ofVersion);
+    }
+
+    private static MatchBuilder OfMatchToSALMatchConvertor(List<MatchEntries> swMatchList, final BigInteger datapathid,
+                                                           OpenflowVersion ofVersion) {
+
         MatchBuilder matchBuilder = new MatchBuilder();
         EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
         VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
@@ -509,329 +627,391 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
         Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
         ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
+        TcpFlagMatchBuilder tcpFlagMatchBuilder = new TcpFlagMatchBuilder();
+        TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
 
-        List<MatchEntries> swMatchList = swMatch.getMatchEntries();
-        
-        for(MatchEntries ofMatch : swMatchList){
-            
-            if(ofMatch.getOxmMatchField().equals(InPort.class)){
+        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)){
+                if (portNumber != null) {
+                    Long portNo = portNumber.getPortNumber().getValue();
+                    matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, portNo, ofVersion));
+                }
+            } 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)){
+                matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
+                        portNumber.getPortNumber().getValue(), ofVersion));
+            } 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()));
+                if (metadataMatchEntry != null) {
+                    metadataBuilder.setMetadata(new BigInteger(1, metadataMatchEntry.getMetadata()));
                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
-                    if(maskMatchEntry != null){
-                        metadataBuilder.setMetadataMask(maskMatchEntry.getMask());
+                    if (maskMatchEntry != null) {
+                        metadataBuilder.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
+                                .getMask()));
                     }
                     matchBuilder.setMetadata(metadataBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(EthSrc.class)){
+            } else if (ofMatch.getOxmMatchField().equals(EthSrc.class)) {
                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
-                if(macAddressMatchEntry != null){
+                final MaskMatchEntry sourceMask = ofMatch.getAugmentation(MaskMatchEntry.class);
+                if (macAddressMatchEntry != null) {
                     EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
                     ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
+                    if (sourceMask != null) {
+                        ethSourceBuilder.setMask(new MacAddress(macAddressToString(sourceMask.getMask())));
+                    }
                     ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
                     matchBuilder.setEthernetMatch(ethMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(EthDst.class)){
+            } else if (ofMatch.getOxmMatchField().equals(EthDst.class)) {
                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
-                if(macAddressMatchEntry != null){
+                final MaskMatchEntry destinationMask = ofMatch.getAugmentation(MaskMatchEntry.class);
+                if (macAddressMatchEntry != null) {
                     EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
                     ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
+                    if (destinationMask != null) {
+                        ethDestinationBuilder.setMask(new MacAddress(macAddressToString(destinationMask.getMask())));
+                    }
                     ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
                     matchBuilder.setEthernetMatch(ethMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(EthType.class)){
+            } else if (ofMatch.getOxmMatchField().equals(EthType.class)) {
                 EthTypeMatchEntry ethTypeMatchEntry = ofMatch.getAugmentation(EthTypeMatchEntry.class);
-                if(ethTypeMatchEntry != null){
+                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()));
+                    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)){
+            } else if (ofMatch.getOxmMatchField().equals(VlanVid.class)) {
                 VlanVidMatchEntry vlanVidMatchEntry = ofMatch.getAugmentation(VlanVidMatchEntry.class);
-                if(vlanVidMatchEntry != null){
+                if (vlanVidMatchEntry != null) {
                     VlanIdBuilder vlanBuilder = new VlanIdBuilder();
-                    vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanVidMatchEntry.getVlanVid()));                   
+                    vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(
+                            vlanVidMatchEntry.getVlanVid()))
+                            .setVlanIdPresent(vlanVidMatchEntry.isCfiBit());
                     vlanMatchBuilder.setVlanId(vlanBuilder.build());
                     matchBuilder.setVlanMatch(vlanMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(VlanPcp.class)){
+            } 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()));
+                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)){
+            } else if (ofMatch.getOxmMatchField().equals(IpDscp.class)) {
                 DscpMatchEntry dscpMatchEntry = ofMatch.getAugmentation(DscpMatchEntry.class);
-                if(dscpMatchEntry != null){
+                if (dscpMatchEntry != null) {
                     ipMatchBuilder.setIpDscp(new Dscp(dscpMatchEntry.getDscp().getValue()));
                     matchBuilder.setIpMatch(ipMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(IpEcn.class)){
+            } else if (ofMatch.getOxmMatchField().equals(IpEcn.class)) {
                 EcnMatchEntry ecnMatchEntry = ofMatch.getAugmentation(EcnMatchEntry.class);
-                if(ecnMatchEntry != null){
+                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){
+            } 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)){
+            } else if (ofMatch.getOxmMatchField().equals(TcpSrc.class)) {
                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
-                if(portMatchEntry != null){
+                if (portMatchEntry != null) {
                     tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
                     matchBuilder.setLayer4Match(tcpMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(TcpDst.class)){
+            } else if (ofMatch.getOxmMatchField().equals(TcpDst.class)) {
                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
-                if(portMatchEntry != null){
+                if (portMatchEntry != null) {
                     tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
                     matchBuilder.setLayer4Match(tcpMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(UdpSrc.class)){
+            } else if (ofMatch.getOxmMatchField().equals(UdpSrc.class)) {
                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
-                if(portMatchEntry != null){
+                if (portMatchEntry != null) {
                     udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
                     matchBuilder.setLayer4Match(udpMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(UdpDst.class)){
+            } else if (ofMatch.getOxmMatchField().equals(UdpDst.class)) {
                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
-                if(portMatchEntry != null){
+                if (portMatchEntry != null) {
                     udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
                     matchBuilder.setLayer4Match(udpMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(SctpSrc.class)){
+            } else if (ofMatch.getOxmMatchField().equals(SctpSrc.class)) {
                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
-                if(portMatchEntry != null){
+                if (portMatchEntry != null) {
                     sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
                     matchBuilder.setLayer4Match(sctpMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(SctpDst.class)){
+            } else if (ofMatch.getOxmMatchField().equals(SctpDst.class)) {
                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
-                if(portMatchEntry != null){
+                if (portMatchEntry != null) {
                     sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
                     matchBuilder.setLayer4Match(sctpMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Icmpv4Type.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Icmpv4Type.class)) {
                 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = ofMatch.getAugmentation(Icmpv4TypeMatchEntry.class);
-                if(icmpv4TypeMatchEntry != null){
+                if (icmpv4TypeMatchEntry != null) {
                     icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
                     matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Icmpv4Code.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Icmpv4Code.class)) {
                 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = ofMatch.getAugmentation(Icmpv4CodeMatchEntry.class);
-                if(icmpv4CodeMatchEntry != null){
+                if (icmpv4CodeMatchEntry != null) {
                     icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
                     matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Icmpv6Type.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Icmpv6Type.class)) {
                 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = ofMatch.getAugmentation(Icmpv6TypeMatchEntry.class);
-                if(icmpv6TypeMatchEntry != null){
+                if (icmpv6TypeMatchEntry != null) {
                     icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
                     matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Icmpv6Code.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Icmpv6Code.class)) {
                 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = ofMatch.getAugmentation(Icmpv6CodeMatchEntry.class);
-                if(icmpv6CodeMatchEntry != null){
+                if (icmpv6CodeMatchEntry != null) {
                     icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
                     matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Ipv4Src.class) ||
-                    ofMatch.getOxmMatchField().equals(Ipv4Dst.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)
+                    || ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
                 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
-                if(ipv4AddressMatchEntry != null){
+                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 (maskMatchEntry != null) {
+                        ipv4PrefixStr += MatchConvertorUtil.getIpv4Mask(maskMatchEntry);
+                    } else {
+                        //Openflow Spec : 1.3.2
+                        //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
+                        // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
+                        // statistics response.
+
+                        ipv4PrefixStr += PREFIX_SEPARATOR + "32";
                     }
-                    if(ofMatch.getOxmMatchField().equals(Ipv4Src.class)){
+                    if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
                         ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
                     }
-                    if(ofMatch.getOxmMatchField().equals(Ipv4Dst.class)){
+                    if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
                         ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
                     }
                     matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(ArpOp.class)){
+            } else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)
+                    || ofMatch.getOxmMatchField().equals(TunnelIpv4Src.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();
+                    } else {
+                        //Openflow Spec : 1.3.2
+                        //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
+                        // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
+                        // statistics response.
+
+                        ipv4PrefixStr += PREFIX_SEPARATOR + "32";
+                    }
+                    if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)) {
+                        tunnelIpv4MatchBuilder.setTunnelIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
+                    }
+                    if (ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
+                        tunnelIpv4MatchBuilder.setTunnelIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
+                    }
+                    matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
+                }
+            } else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
                 OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
-                if(opCodeMatchEntry != null){
+                if (opCodeMatchEntry != null) {
                     arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
                     matchBuilder.setLayer3Match(arpMatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(ArpSpa.class) ||
-                    ofMatch.getOxmMatchField().equals(ArpTpa.class)){
+            } else if (ofMatch.getOxmMatchField().equals(ArpSpa.class)
+                    || ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
                 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
-                if(ipv4AddressMatchEntry != null){
+                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 (maskMatchEntry != null) {
+                        ipv4PrefixStr += MatchConvertorUtil.getIpv4Mask(maskMatchEntry);
+                    } else {
+                        //Openflow Spec : 1.3.2
+                        //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
+                        // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
+                        // statistics response.
+
+                        ipv4PrefixStr += PREFIX_SEPARATOR + "32";
                     }
-                    if(ofMatch.getOxmMatchField().equals(ArpSpa.class)){
+                    if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
                         arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
                     }
-                    if(ofMatch.getOxmMatchField().equals(ArpTpa.class)){
+                    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)){
+            } 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)){
+                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());
+                        if (maskMatchEntry != null) {
+                            arpSourceHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
+                                    .macAddressToString(maskMatchEntry.getMask())));
                         }
                         arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
                         matchBuilder.setLayer3Match(arpMatchBuilder.build());
                     }
-                    if(ofMatch.getOxmMatchField().equals(ArpTha.class)){
+                    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());
+                        if (maskMatchEntry != null) {
+                            arpTargetHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
+                                    .macAddressToString(maskMatchEntry.getMask())));
                         }
                         arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
                         matchBuilder.setLayer3Match(arpMatchBuilder.build());
                     }
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Ipv6Src.class) ||
-                    ofMatch.getOxmMatchField().equals(Ipv6Dst.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)
+                    || ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
                 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
-                if(ipv6AddressMatchEntry != null){
+                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 (maskMatchEntry != null) {
+                        ipv6PrefixStr += PREFIX_SEPARATOR
+                                + MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskMatchEntry.getMask());
                     }
-                    if(ofMatch.getOxmMatchField().equals(Ipv6Src.class)){
+
+                    if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
                         ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
                     }
-                    if(ofMatch.getOxmMatchField().equals(Ipv6Dst.class)){
+                    if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
                         ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
                     }
                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)) {
                 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = ofMatch.getAugmentation(Ipv6FlabelMatchEntry.class);
-                if(ipv6FlabelMatchEntry != null){
+                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());
+                    if (maskMatchEntry != null) {
+                        ipv6LabelBuilder.setFlabelMask(new Ipv6FlowLabel(Long.valueOf(ByteUtil
+                                .bytesToUnsignedInt(maskMatchEntry.getMask()))));
                     }
                     ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)) {
                 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
-                if(ipv6AddressMatchEntry != null){
+                if (ipv6AddressMatchEntry != null) {
                     ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)) {
                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
-                if(macAddressMatchEntry != null){
+                if (macAddressMatchEntry != null) {
                     ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)) {
                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
-                if(macAddressMatchEntry != null){
+                if (macAddressMatchEntry != null) {
                     ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)){
+            } else if (ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)) {
                 PseudoFieldMatchEntry pseudoFieldMatchEntry = ofMatch.getAugmentation(PseudoFieldMatchEntry.class);
-                if(pseudoFieldMatchEntry != null){
+                if (pseudoFieldMatchEntry != null) {
                     Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
-                        
+
                     Ipv6ExthdrFlags 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);
+                    Integer bitmap = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
 
                     ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
-                    if(maskMatchEntry != null){
-                        ipv6ExtHeaderBuilder.setIpv6ExthdrMask(maskMatchEntry.getMask());
+                    if (maskMatchEntry != null) {
+                        ipv6ExtHeaderBuilder.setIpv6ExthdrMask(ByteUtil.bytesToUnsignedShort(maskMatchEntry.getMask()));
                     }
                     ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(MplsLabel.class)){
+            } else if (ofMatch.getOxmMatchField().equals(MplsLabel.class)) {
                 MplsLabelMatchEntry mplsLabelMatchEntry = ofMatch.getAugmentation(MplsLabelMatchEntry.class);
-                if(mplsLabelMatchEntry != null){
+                if (mplsLabelMatchEntry != null) {
                     protocolMatchFieldsBuilder.setMplsLabel(mplsLabelMatchEntry.getMplsLabel());
                     matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(MplsBos.class)){
+            } else if (ofMatch.getOxmMatchField().equals(MplsBos.class)) {
                 BosMatchEntry bosMatchEntry = ofMatch.getAugmentation(BosMatchEntry.class);
-                if(bosMatchEntry != null){
-                    protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
+                if (bosMatchEntry != null) {
+                    protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos() ? (short) 1 : (short) 0);
                     matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(MplsTc.class)){
+            } else if (ofMatch.getOxmMatchField().equals(MplsTc.class)) {
                 TcMatchEntry tcMatchEntry = ofMatch.getAugmentation(TcMatchEntry.class);
-                if(tcMatchEntry != null){
+                if (tcMatchEntry != null) {
                     protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
                     matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(PbbIsid.class)){
+            } else if (ofMatch.getOxmMatchField().equals(PbbIsid.class)) {
                 IsidMatchEntry isidMatchEntry = ofMatch.getAugmentation(IsidMatchEntry.class);
-                if(isidMatchEntry != null){
+                if (isidMatchEntry != null) {
                     PbbBuilder pbbBuilder = new PbbBuilder();
                     pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
-                    if(maskMatchEntry != null){
-                        pbbBuilder.setPbbMask(maskMatchEntry.getMask());
+                    if (maskMatchEntry != null) {
+                        pbbBuilder.setPbbMask(ByteUtil.bytesToUnsignedMedium(maskMatchEntry.getMask()));
                     }
                     protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
                     matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
                 }
-            }else if(ofMatch.getOxmMatchField().equals(TunnelId.class)){
+            } 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()));
+                if (metadataMatchEntry != null) {
+                    tunnelBuilder.setTunnelId(new BigInteger(1, metadataMatchEntry.getMetadata()));
                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
-                    if(maskMatchEntry != null){
-                        tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
+                    if (maskMatchEntry != null) {
+                        tunnelBuilder.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
+                                .getMask()));
                     }
                     matchBuilder.setTunnel(tunnelBuilder.build());
                 }
+            } else if (ofMatch.getOxmMatchField().equals(TcpFlag.class)) {
+                //FIXME: move to extensible support
+                TcpFlagMatchEntry tcpFlagMatch = ofMatch.getAugmentation(TcpFlagMatchEntry.class);
+                if (tcpFlagMatch != null) {
+                    tcpFlagMatchBuilder.setTcpFlag(tcpFlagMatch.getTcpFlag());
+                    matchBuilder.setTcpFlagMatch(tcpFlagMatchBuilder.build());
+                }
             }
         }
-        return matchBuilder.build();
+        return matchBuilder;
     }
 
-    
-    private static MatchEntries toOfMplsPbb(Pbb pbb) {
+
+    private static MatchEntries toOfMplsPbb(final Pbb pbb) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         boolean hasmask = false;
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
@@ -841,13 +1021,13 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
         if (pbb.getPbbMask() != null) {
             hasmask = true;
-            addMaskAugmentation(matchEntriesBuilder, pbb.getPbbMask());
+            addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedMediumToBytes(pbb.getPbbMask()));
         }
         matchEntriesBuilder.setHasMask(hasmask);
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfMplsTc(Short mplsTc) {
+    private static MatchEntries toOfMplsTc(final Short mplsTc) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -858,7 +1038,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfMplsBos(Short mplsBos) {
+    private static MatchEntries toOfMplsBos(final Short mplsBos) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -873,7 +1053,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfMplsLabel(Long mplsLabel) {
+    private static MatchEntries toOfMplsLabel(final Long mplsLabel) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -884,7 +1064,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIpv6ExtHeader(Ipv6ExtHeader ipv6ExtHeader) {
+    private static MatchEntries toOfIpv6ExtHeader(final Ipv6ExtHeader ipv6ExtHeader) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         boolean hasmask = false;
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
@@ -904,13 +1084,13 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
         if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
             hasmask = true;
-            addMaskAugmentation(matchEntriesBuilder, ipv6ExtHeader.getIpv6ExthdrMask());
+            addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedShortToBytes(ipv6ExtHeader.getIpv6ExthdrMask()));
         }
         matchEntriesBuilder.setHasMask(hasmask);
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIpv6FlowLabel(Ipv6Label ipv6Label) {
+    private static MatchEntries toOfIpv6FlowLabel(final Ipv6Label ipv6Label) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         boolean hasmask = false;
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
@@ -920,13 +1100,13 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
         if (ipv6Label.getFlabelMask() != null) {
             hasmask = true;
-            addMaskAugmentation(matchEntriesBuilder, ipv6Label.getFlabelMask());
+            addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(ipv6Label.getFlabelMask().getValue()));
         }
         matchEntriesBuilder.setHasMask(hasmask);
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfPort(Class<? extends MatchField> field, Long portNumber) {
+    private static MatchEntries toOfPort(final Class<? extends MatchField> field, final Long portNumber) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -937,7 +1117,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfMetadata(Class<? extends MatchField> field, BigInteger metadata, byte[] metadataMask) {
+    private static MatchEntries toOfMetadata(final Class<? extends MatchField> field, final BigInteger metadata,
+                                             final BigInteger metadataMask) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         boolean hasmask = false;
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
@@ -945,15 +1126,16 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         addMetadataAugmentation(matchEntriesBuilder, metadata);
         if (metadataMask != null) {
             hasmask = true;
-            addMaskAugmentation(matchEntriesBuilder, metadataMask);
+            addMaskAugmentation(matchEntriesBuilder,
+                    ByteUtil.convertBigIntegerToNBytes(metadataMask, OFConstants.SIZE_OF_LONG_IN_BYTES));
         }
         matchEntriesBuilder.setHasMask(hasmask);
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfMacAddress(Class<? extends MatchField> field,
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
-            byte[] mask) {
+    public static MatchEntries toOfMacAddress(final Class<? extends MatchField> field,
+                                              final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
+                                              final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         boolean hasmask = false;
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
@@ -961,13 +1143,13 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         addMacAddressAugmentation(matchEntriesBuilder, macAddress);
         if (mask != null) {
             hasmask = true;
-            addMaskAugmentation(matchEntriesBuilder, mask);
+            addMaskAugmentation(matchEntriesBuilder, ByteBufUtils.macAddressToBytes(mask.getValue()));
         }
         matchEntriesBuilder.setHasMask(hasmask);
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfEthernetType(EthernetType ethernetType) {
+    private static MatchEntries toOfEthernetType(final EthernetType ethernetType) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -978,8 +1160,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfLayer3Port(Class<? extends MatchField> field,
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
+    private static MatchEntries toOfLayer3Port(final Class<? extends MatchField> field,
+                                               final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -990,7 +1172,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIcmpv4Type(Short icmpv4Type) {
+    private static MatchEntries toOfIcmpv4Type(final Short icmpv4Type) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1001,7 +1183,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIcmpv4Code(Short icmpv4Code) {
+    private static MatchEntries toOfIcmpv4Code(final Short icmpv4Code) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1012,7 +1194,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIcmpv6Type(Short icmpv6Type) {
+    private static MatchEntries toOfIcmpv6Type(final Short icmpv6Type) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1023,7 +1205,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIcmpv6Code(Short icmpv6Code) {
+    private static MatchEntries toOfIcmpv6Code(final Short icmpv6Code) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1034,7 +1216,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIpv4Prefix(Class<? extends MatchField> field, Ipv4Prefix ipv4Prefix) {
+    public static MatchEntries toOfIpv4Prefix(final Class<? extends MatchField> field, final Ipv4Prefix ipv4Prefix) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setOxmMatchField(field);
@@ -1043,7 +1225,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIpv6Prefix(Class<? extends MatchField> field, Ipv6Prefix ipv6Prefix) {
+    private static MatchEntries toOfIpv6Prefix(final Class<? extends MatchField> field, final Ipv6Prefix ipv6Prefix) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setOxmMatchField(field);
@@ -1052,7 +1234,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIpDscp(Dscp ipDscp) {
+    public static MatchEntries toOfIpDscp(final Dscp ipDscp) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1063,8 +1245,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfVlanPcp(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
+    public static MatchEntries toOfVlanPcp(
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1075,7 +1257,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfVlanVid(VlanId vlanId) {
+    private static MatchEntries toOfVlanVid(final VlanId vlanId) {
         // TODO: verify
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         boolean hasmask = false;
@@ -1084,7 +1266,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setOxmMatchField(VlanVid.class);
         VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
-        if (vlanId.isVlanIdPresent() == true) {
+        if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
             setCfiBit = true;
             if (vlanId.getVlanId() != null) {
                 vidEntryValue = vlanId.getVlanId().getValue();
@@ -1101,7 +1283,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIpProto(Short ipProtocol) {
+    private static MatchEntries toOfIpProto(final Short ipProtocol) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1112,7 +1294,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIpEcn(Short ipEcn) {
+    private static MatchEntries toOfIpEcn(final Short ipEcn) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1123,7 +1305,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfArpOpCode(Integer arpOp) {
+    private static MatchEntries toOfArpOpCode(final Integer arpOp) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1134,7 +1316,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static MatchEntries toOfIpv6Address(Ipv6Address address) {
+    private static MatchEntries toOfIpv6Address(final Ipv6Address address) {
         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
         matchEntriesBuilder.setHasMask(false);
@@ -1145,21 +1327,22 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return matchEntriesBuilder.build();
     }
 
-    private static void addMaskAugmentation(MatchEntriesBuilder builder, byte[] mask) {
+    private static void addMaskAugmentation(final MatchEntriesBuilder builder, final byte[] mask) {
         MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
         maskBuilder.setMask(mask);
         builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
     }
 
-    private static boolean addIpv6PrefixAugmentation(MatchEntriesBuilder builder, Ipv6Prefix address) {
+    private static boolean addIpv6PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv6Prefix address) {
         boolean hasMask = false;
-        String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
+        Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
+        Ipv6Address ipv6Address = new Ipv6Address(addressParts.next());
+
         Integer prefix = null;
-        if (addressParts.length == 2) {
-            prefix = Integer.parseInt(addressParts[1]);
+        if (addressParts.hasNext()) {
+            prefix = Integer.parseInt(addressParts.next());
         }
 
-        Ipv6Address ipv6Address = new Ipv6Address(addressParts[0]);
         Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
         ipv6AddressBuilder.setIpv6Address(ipv6Address);
         builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
@@ -1170,7 +1353,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return hasMask;
     }
 
-    private static byte[] convertIpv6PrefixToByteArray(int prefix) {
+    private static byte[] convertIpv6PrefixToByteArray(final int prefix) {
         // TODO: Temporary fix. Has performance impacts.
         byte[] mask = new byte[16];
         int oneCount = prefix;
@@ -1189,466 +1372,62 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
         return mask;
     }
 
-    private static void addMetadataAugmentation(MatchEntriesBuilder builder, BigInteger metadata) {
+    private static void addMetadataAugmentation(final MatchEntriesBuilder builder, final BigInteger metadata) {
         MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
-        metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerTo64Bit(metadata));
+        metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerToNBytes(metadata, OFConstants.SIZE_OF_LONG_IN_BYTES));
         builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
     }
 
     /**
      * @return true if Ipv4Prefix contains prefix (and it is used in mask),
-     *         false otherwise
+     * false otherwise
      */
-    private static boolean addIpv4PrefixAugmentation(MatchEntriesBuilder builder, Ipv4Prefix address) {
+    private static boolean addIpv4PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv4Prefix address) {
         boolean hasMask = false;
-        String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
-        Integer prefix = null;
-        if (addressParts.length < 2) {
-            prefix = 0;
+        Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
+        Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
+
+        final int prefix;
+        if (addressParts.hasNext()) {
+            int potentionalPrefix = Integer.parseInt(addressParts.next());
+            prefix = potentionalPrefix < 32 ? potentionalPrefix : 0;
         } else {
-            prefix = Integer.parseInt(addressParts[1]);
+            prefix = 0;
         }
 
-        Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]);
         Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
         ipv4AddressBuilder.setIpv4Address(ipv4Address);
         builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
         if (prefix != 0) {
             int mask = 0xffffffff << (32 - prefix);
-            byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
-                    (byte) mask };
+            byte[] maskBytes = new byte[]{(byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
+                    (byte) mask};
             addMaskAugmentation(builder, maskBytes);
             hasMask = true;
         }
         return hasMask;
     }
 
-    private static void addMacAddressAugmentation(MatchEntriesBuilder builder, MacAddress address) {
+    private static void addMacAddressAugmentation(final MatchEntriesBuilder builder, final MacAddress address) {
         MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
         macAddress.setMacAddress(address);
         builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
     }
 
     /**
-     * Method converts OF SetField Match to SAL SetFiled matches
-     * TODO: enable or delete
+     * Method converts OF SetField action to SAL SetFiled action.
+     *
      * @param action
+     * @param ofVersion current ofp version
      * @return
      */
-    public static SetField ofToSALSetField(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action) {
-        logger.info("OF SetField match to SAL SetField match converstion begins");
+    public static SetField fromOFSetFieldToSALSetFieldAction(
+            final Action action, OpenflowVersion ofVersion) {
+        logger.debug("Converting OF SetField action to SAL SetField action");
         SetFieldBuilder setField = new SetFieldBuilder();
-        /*
-         * OxmFieldsAction oxmFields =
-         * action.getAugmentation(OxmFieldsAction.class);
-         *
-         * List<MatchEntries> matchEntries = oxmFields.getMatchEntries();
-         * org.opendaylight
-         * .yang.gen.v1.urn.opendaylight.action.types.rev131112.action
-         * .action.set.field.MatchBuilder match =new
-         * org.opendaylight.yang.gen.v1
-         * .urn.opendaylight.action.types.rev131112.action
-         * .action.set.field.MatchBuilder();
-         *
-         * EthernetMatchBuilder ethernetMatchBuilder = null; VlanMatchBuilder
-         * vlanMatchBuilder = null; IpMatchBuilder ipMatchBuilder = null;
-         * TcpMatchBuilder tcpMatchBuilder = null; UdpMatchBuilder
-         * udpMatchBuilder = null; SctpMatchBuilder sctpMatchBuilder = null;
-         * Icmpv4MatchBuilder icmpv4MatchBuilder = null; Icmpv6MatchBuilder
-         * icmpv6MatchBuilder = null; Ipv4MatchBuilder ipv4MatchBuilder = null;
-         * ArpMatchBuilder arpMatchBuilder = null; Ipv6MatchBuilder
-         * ipv6MatchBuilder = null; ProtocolMatchFieldsBuilder
-         * protocolMatchFieldsBuilder = null;
-         *
-         * for(MatchEntries matchEntry : matchEntries){ if(matchEntry instanceof
-         * InPort){ PortNumberMatchEntry inPort =
-         * matchEntry.getAugmentation(PortNumberMatchEntry.class);
-         * match.setInPort(inPort.getPortNumber().getValue()); }else if
-         * (matchEntry instanceof InPhyPort){ PortNumberMatchEntry phyPort =
-         * matchEntry.getAugmentation(PortNumberMatchEntry.class);
-         * match.setInPhyPort(phyPort.getPortNumber().getValue()); }else if
-         * (matchEntry instanceof Metadata){ MetadataMatchEntry metadataMatch =
-         * matchEntry.getAugmentation(MetadataMatchEntry.class); MetadataBuilder
-         * metadataBuilder = new MetadataBuilder();
-         * metadataBuilder.setMetadata(new
-         * BigInteger(metadataMatch.getMetadata())); MaskMatchEntry maskMatch =
-         * matchEntry.getAugmentation(MaskMatchEntry.class); if (maskMatch !=
-         * null){ metadataBuilder.setMetadataMask(maskMatch.getMask()); }
-         * match.setMetadata(metadataBuilder.build()); }else if (matchEntry
-         * instanceof EthDst){
-         *
-         * if(ethernetMatchBuilder == null) ethernetMatchBuilder = new
-         * EthernetMatchBuilder();
-         *
-         * MacAddressMatchEntry macAddressMatch =
-         * matchEntry.getAugmentation(MacAddressMatchEntry.class);
-         * MaskMatchEntry maskMatch =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * EthernetDestinationBuilder ethernetDestination = new
-         * EthernetDestinationBuilder();
-         * ethernetDestination.setAddress(macAddressMatch.getMacAddress());
-         * if(maskMatch != null){
-         * ethernetDestination.setMask(maskMatch.getMask()); }
-         * ethernetMatchBuilder
-         * .setEthernetDestination(ethernetDestination.build()); }else if
-         * (matchEntry instanceof EthSrc){ if(ethernetMatchBuilder == null)
-         * ethernetMatchBuilder = new EthernetMatchBuilder();
-         *
-         * MacAddressMatchEntry macAddressMatch =
-         * matchEntry.getAugmentation(MacAddressMatchEntry.class);
-         * MaskMatchEntry maskMatch =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * EthernetSourceBuilder ethernetSource = new EthernetSourceBuilder();
-         * ethernetSource.setAddress(macAddressMatch.getMacAddress());
-         * if(maskMatch != null){ ethernetSource.setMask(maskMatch.getMask()); }
-         * ethernetMatchBuilder.setEthernetSource(ethernetSource.build()); }else
-         * if (matchEntry instanceof EthType){ if(ethernetMatchBuilder == null)
-         * ethernetMatchBuilder = new EthernetMatchBuilder();
-         *
-         * EthTypeMatchEntry etherTypeMatch =
-         * matchEntry.getAugmentation(EthTypeMatchEntry.class);
-         * EthernetTypeBuilder ethernetType= new EthernetTypeBuilder();
-         * org.opendaylight
-         * .yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType etherType
-         * = new
-         * org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827
-         * .EtherType((long)etherTypeMatch.getEthType().getValue());
-         * ethernetType.setType(etherType);
-         * ethernetMatchBuilder.setEthernetType(ethernetType.build()); }else if
-         * (matchEntry instanceof VlanVid){ if(vlanMatchBuilder == null)
-         * vlanMatchBuilder = new VlanMatchBuilder();
-         *
-         * VlanVidMatchEntry vlanVidMatch =
-         * matchEntry.getAugmentation(VlanVidMatchEntry.class); MaskMatchEntry
-         * maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
-         *
-         * VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
-         * vlanIdBuilder.setVlanId( new
-         * org.opendaylight.yang.gen.v1.urn.opendaylight
-         * .l2.types.rev130827.VlanId(vlanVidMatch.getVlanVid())); if(maskMatch
-         * != null){ vlanIdBuilder.setMask(maskMatch.getMask()); }
-         * vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
-         *
-         * }else if (matchEntry instanceof VlanPcp){ if(vlanMatchBuilder ==
-         * null) vlanMatchBuilder = new VlanMatchBuilder();
-         *
-         * VlanPcpMatchEntry vlanPcpMatch =
-         * matchEntry.getAugmentation(VlanPcpMatchEntry.class);
-         * vlanMatchBuilder.setVlanPcp( new
-         * org.opendaylight.yang.gen.v1.urn.opendaylight
-         * .l2.types.rev130827.VlanPcp(vlanPcpMatch.getVlanPcp())); }else if
-         * (matchEntry instanceof IpDscp){ if(ipMatchBuilder == null)
-         * ipMatchBuilder = new IpMatchBuilder();
-         *
-         * DscpMatchEntry dscpMatchEntry =
-         * matchEntry.getAugmentation(DscpMatchEntry.class);
-         * ipMatchBuilder.setIpDscp(dscpMatchEntry.getDscp());
-         *
-         * }else if (matchEntry instanceof IpEcn){ if(ipMatchBuilder == null)
-         * ipMatchBuilder = new IpMatchBuilder();
-         *
-         * EcnMatchEntry ecnMatchEntry =
-         * matchEntry.getAugmentation(EcnMatchEntry.class);
-         * ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
-         *
-         * }else if (matchEntry instanceof IpProto){ if(ipMatchBuilder == null)
-         * ipMatchBuilder = new IpMatchBuilder();
-         *
-         * ProtocolNumberMatchEntry protocolNumberMatch =
-         * matchEntry.getAugmentation(ProtocolNumberMatchEntry.class);
-         * ipMatchBuilder
-         * .setIpProtocol(protocolNumberMatch.getProtocolNumber()); }else if
-         * (matchEntry instanceof TcpSrc){ if(tcpMatchBuilder == null)
-         * tcpMatchBuilder = new TcpMatchBuilder();
-         *
-         * PortMatchEntry portMatchEntry =
-         * matchEntry.getAugmentation(PortMatchEntry.class);
-         * tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
-         *
-         * }else if (matchEntry instanceof TcpDst){ if(tcpMatchBuilder == null)
-         * tcpMatchBuilder = new TcpMatchBuilder();
-         *
-         * PortMatchEntry portMatchEntry =
-         * matchEntry.getAugmentation(PortMatchEntry.class);
-         * tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
-         *
-         * }else if (matchEntry instanceof UdpSrc){ if(udpMatchBuilder == null)
-         * udpMatchBuilder = new UdpMatchBuilder();
-         *
-         * PortMatchEntry portMatchEntry =
-         * matchEntry.getAugmentation(PortMatchEntry.class);
-         * udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
-         *
-         *
-         * }else if (matchEntry instanceof UdpDst){ if(udpMatchBuilder == null)
-         * udpMatchBuilder = new UdpMatchBuilder();
-         *
-         * PortMatchEntry portMatchEntry =
-         * matchEntry.getAugmentation(PortMatchEntry.class);
-         * udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
-         * }else if (matchEntry instanceof SctpSrc){ if(sctpMatchBuilder ==
-         * null) sctpMatchBuilder = new SctpMatchBuilder();
-         *
-         * PortMatchEntry portMatchEntry =
-         * matchEntry.getAugmentation(PortMatchEntry.class);
-         * sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
-         *
-         * }else if (matchEntry instanceof SctpDst){ if(sctpMatchBuilder ==
-         * null) sctpMatchBuilder = new SctpMatchBuilder();
-         *
-         * PortMatchEntry portMatchEntry =
-         * matchEntry.getAugmentation(PortMatchEntry.class);
-         * sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
-         * }else if (matchEntry instanceof Icmpv4Type){ if(icmpv4MatchBuilder ==
-         * null) icmpv4MatchBuilder = new Icmpv4MatchBuilder();
-         *
-         * Icmpv4TypeMatchEntry icmpv4TypeMatchEntry =
-         * matchEntry.getAugmentation(Icmpv4TypeMatchEntry.class);
-         * icmpv4MatchBuilder
-         * .setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
-         *
-         * }else if (matchEntry instanceof Icmpv4Code){ if(icmpv4MatchBuilder ==
-         * null) icmpv4MatchBuilder = new Icmpv4MatchBuilder();
-         *
-         * Icmpv4CodeMatchEntry icmpv4CodeMatchEntry =
-         * matchEntry.getAugmentation(Icmpv4CodeMatchEntry.class);
-         * icmpv4MatchBuilder
-         * .setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
-         *
-         * }else if (matchEntry instanceof Icmpv6Type){ if(icmpv6MatchBuilder ==
-         * null) icmpv6MatchBuilder = new Icmpv6MatchBuilder();
-         *
-         * Icmpv6TypeMatchEntry icmpv6TypeMatchEntry =
-         * matchEntry.getAugmentation(Icmpv6TypeMatchEntry.class);
-         * icmpv6MatchBuilder
-         * .setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type()); }else if
-         * (matchEntry instanceof Icmpv6Code){ if(icmpv6MatchBuilder == null)
-         * icmpv6MatchBuilder = new Icmpv6MatchBuilder();
-         *
-         * Icmpv6CodeMatchEntry icmpv6CodeMatchEntry =
-         * matchEntry.getAugmentation(Icmpv6CodeMatchEntry.class);
-         * icmpv6MatchBuilder
-         * .setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code()); }else if
-         * (matchEntry instanceof Ipv4Src){ if(ipv4MatchBuilder == null)
-         * ipv4MatchBuilder = new Ipv4MatchBuilder();
-         *
-         * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
-         * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * ipv4MatchBuilder.setIpv4Source( new
-         * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
-         * String(maskMatchEntry.getMask())));
-         *
-         * }else if (matchEntry instanceof Ipv4Dst){ if(ipv4MatchBuilder ==
-         * null) ipv4MatchBuilder = new Ipv4MatchBuilder();
-         *
-         * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
-         * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * ipv4MatchBuilder.setIpv4Destination( new
-         * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
-         * String(maskMatchEntry.getMask()))); }else if (matchEntry instanceof
-         * ArpOp){ if(arpMatchBuilder == null) arpMatchBuilder = new
-         * ArpMatchBuilder();
-         *
-         * OpCodeMatchEntry opCodeMatchEntry =
-         * matchEntry.getAugmentation(OpCodeMatchEntry.class);
-         * arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
-         *
-         * }else if (matchEntry instanceof ArpSpa){ if(arpMatchBuilder == null)
-         * arpMatchBuilder = new ArpMatchBuilder();
-         *
-         * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
-         * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * arpMatchBuilder.setArpSourceTransportAddress( new
-         * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
-         * String(maskMatchEntry.getMask())));
-         *
-         * }else if (matchEntry instanceof ArpTpa){ if(arpMatchBuilder == null)
-         * arpMatchBuilder = new ArpMatchBuilder();
-         *
-         * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
-         * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * arpMatchBuilder.setArpTargetTransportAddress( new
-         * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
-         * String(maskMatchEntry.getMask())));
-         *
-         * }else if (matchEntry instanceof ArpSha){ if(arpMatchBuilder == null)
-         * arpMatchBuilder = new ArpMatchBuilder();
-         *
-         * MacAddressMatchEntry macAddressMatchEntry =
-         * matchEntry.getAugmentation(MacAddressMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new
-         * ArpSourceHardwareAddressBuilder();
-         * arpSourceHardwareAddressBuilder.setAddress
-         * (macAddressMatchEntry.getMacAddress());
-         * arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
-         * arpMatchBuilder
-         * .setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder
-         * .build());
-         *
-         * }else if (matchEntry instanceof ArpTha){ if(arpMatchBuilder == null)
-         * arpMatchBuilder = new ArpMatchBuilder();
-         *
-         * MacAddressMatchEntry macAddressMatchEntry =
-         * matchEntry.getAugmentation(MacAddressMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new
-         * ArpTargetHardwareAddressBuilder();
-         * arpTargetHardwareAddressBuilder.setAddress
-         * (macAddressMatchEntry.getMacAddress());
-         * arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
-         * arpMatchBuilder
-         * .setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder
-         * .build()); }else if (matchEntry instanceof Ipv6Src){
-         * if(ipv6MatchBuilder == null) ipv6MatchBuilder = new
-         * Ipv6MatchBuilder();
-         *
-         * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
-         * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix
-         * (ipv6AddressMatchEntry.getIpv6Address().getValue()+ "/"+new
-         * String(maskMatchEntry.getMask())));
-         *
-         * }else if (matchEntry instanceof Ipv6Dst){ if(ipv6MatchBuilder ==
-         * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
-         *
-         * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
-         * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class);
-         * ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix
-         * (ipv6AddressMatchEntry.getIpv6Address().getValue()+ "/"+new
-         * String(maskMatchEntry.getMask())));
-         *
-         * }else if (matchEntry instanceof Ipv6Flabel){ if(ipv6MatchBuilder ==
-         * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
-         *
-         * Ipv6FlabelMatchEntry ipv6FlabelMatchEntry =
-         * matchEntry.getAugmentation(Ipv6FlabelMatchEntry.class);
-         * MaskMatchEntry maskMatchEntry =
-         * matchEntry.getAugmentation(MaskMatchEntry.class); Ipv6LabelBuilder
-         * ipv6LabelBuilder = new Ipv6LabelBuilder();
-         * ipv6LabelBuilder.setIpv6Flabel(ipv6FlabelMatchEntry.getIpv6Flabel());
-         * ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
-         * ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
-         *
-         * }else if (matchEntry instanceof Ipv6NdTarget){ if(ipv6MatchBuilder ==
-         * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
-         * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
-         * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
-         * ipv6MatchBuilder
-         * .setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
-         *
-         * }else if (matchEntry instanceof Ipv6NdSll){ if(ipv6MatchBuilder ==
-         * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
-         *
-         * MacAddressMatchEntry macAddressMatchEntry =
-         * matchEntry.getAugmentation(MacAddressMatchEntry.class);
-         * ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
-         * }else if (matchEntry instanceof Ipv6NdTll){ if(ipv6MatchBuilder ==
-         * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
-         *
-         * MacAddressMatchEntry macAddressMatchEntry =
-         * matchEntry.getAugmentation(MacAddressMatchEntry.class);
-         * ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
-         *
-         * }else if (matchEntry instanceof Ipv6Exthdr){ if(ipv6MatchBuilder ==
-         * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
-         *
-         * PseudoFieldMatchEntry pseudoFieldMatchEntry =
-         * matchEntry.getAugmentation(PseudoFieldMatchEntry.class); PseudoField
-         * pseudoField = pseudoFieldMatchEntry.getPseudoField(); int
-         * pseudoFieldInt = 0; pseudoFieldInt |= pseudoField.isNonext()?(1 <<
-         * 0):~(1 << 0); pseudoFieldInt |= pseudoField.isEsp()?(1 << 1):~(1 <<
-         * 1); pseudoFieldInt |= pseudoField.isAuth()?(1 << 2):~(1 << 2);
-         * pseudoFieldInt |= pseudoField.isDest()?(1 << 3):~(1 << 3);
-         * pseudoFieldInt |= pseudoField.isFrag()?(1 << 4):~(1 << 4);
-         * pseudoFieldInt |= pseudoField.isRouter()?(1 << 5):~(1 << 5);
-         * pseudoFieldInt |= pseudoField.isHop()?(1 << 6):~(1 << 6);
-         * pseudoFieldInt |= pseudoField.isUnrep()?(1 << 7):~(1 << 7);
-         * pseudoFieldInt |= pseudoField.isUnseq()?(1 << 8):~(1 << 8);
-         *
-         * ipv6MatchBuilder.setIpv6Exthdr(pseudoFieldInt); }else if (matchEntry
-         * instanceof MplsLabel){ if(protocolMatchFieldsBuilder == null)
-         * protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
-         *
-         * MplsLabelMatchEntry MplsLabelMatchEntry =
-         * matchEntry.getAugmentation(MplsLabelMatchEntry.class);
-         * protocolMatchFieldsBuilder
-         * .setMplsLabel(MplsLabelMatchEntry.getMplsLabel());
-         *
-         * }else if (matchEntry instanceof MplsBos){
-         * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
-         * new ProtocolMatchFieldsBuilder();
-         *
-         * BosMatchEntry bosMatchEntry =
-         * matchEntry.getAugmentation(BosMatchEntry.class);
-         * protocolMatchFieldsBuilder
-         * .setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
-         *
-         * }else if (matchEntry instanceof MplsTc) {
-         * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
-         * new ProtocolMatchFieldsBuilder();
-         *
-         * TcMatchEntry tcMatchEntry =
-         * matchEntry.getAugmentation(TcMatchEntry.class);
-         * protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
-         *
-         * }else if (matchEntry instanceof PbbIsid){
-         * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
-         * new ProtocolMatchFieldsBuilder();
-         *
-         * IsidMatchEntry isidMatchEntry =
-         * matchEntry.getAugmentation(IsidMatchEntry.class); PbbBuilder
-         * pbbBuilder = new PbbBuilder();
-         * pbbBuilder.setPbbIsid(isidMatchEntry.getIsid()); MaskMatchEntry
-         * maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
-         * if(maskMatchEntry != null)
-         * pbbBuilder.setPbbMask(maskMatchEntry.getMask());
-         *
-         * protocolMatchFieldsBuilder.setPbb(pbbBuilder.build()); }else if
-         * (matchEntry instanceof TunnelId){ MetadataMatchEntry
-         * metadataMatchEntry =
-         * matchEntry.getAugmentation(MetadataMatchEntry.class); MaskMatchEntry
-         * maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
-         * TunnelBuilder tunnelBuilder = new TunnelBuilder();
-         * tunnelBuilder.setTunnelId(new
-         * BigInteger(metadataMatchEntry.getMetadata()));
-         * tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
-         * match.setTunnel(tunnelBuilder.build()); } } if(ethernetMatchBuilder
-         * != null){ match.setEthernetMatch(ethernetMatchBuilder.build()); } if
-         * (vlanMatchBuilder != null){
-         * match.setVlanMatch(vlanMatchBuilder.build()); } if(ipMatchBuilder !=
-         * null){ match.setIpMatch(ipMatchBuilder.build()); } if(tcpMatchBuilder
-         * != null){ match.setLayer4Match(tcpMatchBuilder.build()); }
-         * if(udpMatchBuilder != null){
-         * match.setLayer4Match(udpMatchBuilder.build()); } if(sctpMatchBuilder
-         * != null){ match.setLayer4Match(sctpMatchBuilder.build()); }
-         * if(icmpv4MatchBuilder != null){
-         * match.setIcmpv4Match(icmpv4MatchBuilder.build()); }
-         * if(icmpv6MatchBuilder != null){
-         * match.setIcmpv6Match(icmpv6MatchBuilder.build()); }
-         * if(ipv4MatchBuilder != null){
-         * match.setLayer3Match(ipv4MatchBuilder.build()); } if(arpMatchBuilder
-         * != null){ match.setLayer3Match(arpMatchBuilder.build()); }
-         * if(ipv6MatchBuilder != null){
-         * match.setLayer3Match(ipv6MatchBuilder.build()); }
-         * if(protocolMatchFieldsBuilder != null){
-         * match.setProtocolMatchFields(protocolMatchFieldsBuilder.build()); }
-         * setField.setMatch(match.build());
-         */return setField.build();
+        OxmFieldsAction oxmFields = action.getAugmentation(OxmFieldsAction.class);
+        MatchBuilder match = OfMatchToSALMatchConvertor(oxmFields.getMatchEntries(), null, ofVersion);
+        setField.fieldsFrom(match.build());
+        return setField.build();
     }
-}
\ No newline at end of file
+}