Merge "Removed useless method"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchConvertorImpl.java
index a7e72725796dfccd234f6ba9d65dd671db7158f0..352aa6cc0c94a805de2cf338feac7dc6442f943f 100644 (file)
@@ -10,12 +10,13 @@ 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 java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-
+import javax.annotation.Nonnull;
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
@@ -36,7 +37,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
@@ -65,7 +65,6 @@ 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.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;
@@ -265,8 +264,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Tunne
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-
 /**
  * Utility class for converting a MD-SAL Flow into the OF flow mod
  */
@@ -276,7 +273,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
     private static final short PROTO_TCP = 6;
     private static final short PROTO_UDP = 17;
     private static final short PROTO_ICMPV4 = 1;
-    private static final String noIp = "0.0.0.0/0";
+    private static final String NO_IP = "0.0.0.0/0";
 
     @Override
     public List<MatchEntry> convert(
@@ -303,222 +300,81 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
             matchEntryList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
         }
 
-        EthernetMatch ethernetMatch = match.getEthernetMatch();
-        if (ethernetMatch != null) {
-            EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
-            if (ethernetDestination != null) {
-                MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                matchEntryBuilder.setOxmMatchField(EthDst.class);
-                EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder();
-                EthDstBuilder ethDstBuilder = new EthDstBuilder();
-                ethDstBuilder.setMacAddress(ethernetDestination.getAddress());
-                boolean hasMask = false;
-                if (null != ethernetDestination.getMask()) {
-                    ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetDestination.getMask().getValue()));
-                    hasMask = true;
-                }
-                ethDstCaseBuilder.setEthDst(ethDstBuilder.build());
-                matchEntryBuilder.setMatchEntryValue(ethDstCaseBuilder.build());
-                matchEntryBuilder.setHasMask(hasMask);
-                matchEntryList.add(matchEntryBuilder.build());
-            }
-
-            EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
-            if (ethernetSource != null) {
-                MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                matchEntryBuilder.setOxmMatchField(EthSrc.class);
-
-                EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder();
-                EthSrcBuilder ethDstBuilder = new EthSrcBuilder();
-                ethDstBuilder.setMacAddress(ethernetSource.getAddress());
-                boolean hasMask = false;
-                if (null != ethernetSource.getMask()) {
-                    ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetSource.getMask().getValue()));
-                    hasMask = true;
-                }
-                ethSrcCaseBuilder.setEthSrc(ethDstBuilder.build());
-                matchEntryBuilder.setMatchEntryValue(ethSrcCaseBuilder.build());
-                matchEntryBuilder.setHasMask(hasMask);
-                matchEntryList.add(matchEntryBuilder.build());
-            }
+        ethernetMatch(matchEntryList, match.getEthernetMatch());
+        vlanMatch(matchEntryList, match.getVlanMatch());
+        ipMatch(matchEntryList, match.getIpMatch());
+        layer4Match(matchEntryList, match.getLayer4Match());
+        icmpv4Match(matchEntryList, match.getIcmpv4Match());
+        icmpv6Match(matchEntryList, match.getIcmpv6Match());
+        layer3Match(matchEntryList, match.getLayer3Match());
+        protocolMatchFields(matchEntryList, match.getProtocolMatchFields());
 
-            if (ethernetMatch.getEthernetType() != null) {
-                matchEntryList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
+        org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
+                .getTunnel();
+        if (tunnel != null) {
+            MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+            TunnelIdCaseBuilder tunnelIdCaseBuilder = new TunnelIdCaseBuilder();
+            TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder();
+            boolean hasMask = false;
+            if (null != tunnel.getTunnelMask()) {
+                hasMask = true;
+                tunnelIdBuilder.setMask(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelMask(), OFConstants.SIZE_OF_LONG_IN_BYTES));
             }
+            tunnelIdBuilder.setTunnelId(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelId(), OFConstants.SIZE_OF_LONG_IN_BYTES));
+            tunnelIdCaseBuilder.setTunnelId(tunnelIdBuilder.build());
+            matchEntryBuilder.setMatchEntryValue(tunnelIdCaseBuilder.build());
+            matchEntryBuilder.setHasMask(hasMask);
+            matchEntryBuilder.setOxmMatchField(TunnelId.class);
+            matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+            matchEntryList.add(matchEntryBuilder.build());
         }
 
-        VlanMatch vlanMatch = match.getVlanMatch();
-        if (vlanMatch != null) {
-            if (vlanMatch.getVlanId() != null) {
-                VlanId vlanId = vlanMatch.getVlanId();
-                MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                matchEntryBuilder.setOxmMatchField(VlanVid.class);
 
-                VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
-                VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
-                boolean setCfiBit = false;
-                Integer vidEntryValue = 0;
-                boolean hasmask = false;
-                if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
-                    setCfiBit = true;
-                    if (vlanId.getVlanId() != null) {
-                        vidEntryValue = vlanId.getVlanId().getValue();
-                    }
-                    hasmask = (vidEntryValue == 0);
-                    if (hasmask) {
-                        vlanVidBuilder.setMask(VLAN_VID_MASK);
-                    }
-                }
-
-                vlanVidBuilder.setCfiBit(setCfiBit);
-                vlanVidBuilder.setVlanVid(vidEntryValue);
-                vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
-                matchEntryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
-                matchEntryBuilder.setHasMask(hasmask);
-                matchEntryList.add(matchEntryBuilder.build());
-            }
-
-            if (vlanMatch.getVlanPcp() != null) {
-                matchEntryList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
+        /**
+         * 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<MatchEntry> convertor =
+                        OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
+                MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
+                matchEntryList.add(ofMatch);
             }
         }
 
-        IpMatch ipMatch = match.getIpMatch();
-        if (ipMatch != null) {
-            if (ipMatch.getIpDscp() != null) {
-                matchEntryList.add(toOfIpDscp(ipMatch.getIpDscp()));
-            }
+        return matchEntryList;
+    }
 
-            if (ipMatch.getIpEcn() != null) {
-                matchEntryList.add(toOfIpEcn(ipMatch.getIpEcn()));
-            }
 
-            if (ipMatch.getIpProtocol() != null) {
-                matchEntryList.add(toOfIpProto(ipMatch.getIpProtocol()));
+    private void protocolMatchFields(List<MatchEntry> matchEntryList,
+            ProtocolMatchFields protocolMatchFields) {
+        if (protocolMatchFields != null) {
+            if (protocolMatchFields.getMplsLabel() != null) {
+                matchEntryList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
             }
 
-        }
-
-        Layer4Match layer4Match = match.getLayer4Match();
-        if (layer4Match != null) {
-            if (layer4Match instanceof TcpMatch) {
-                TcpMatch tcpMatch = (TcpMatch) layer4Match;
-
-                if (tcpMatch.getTcpSourcePort() != null) {
-                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                    matchEntryBuilder.setOxmMatchField(TcpSrc.class);
-
-                    TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
-                    TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
-                    tcpSrcBuilder.setPort(tcpMatch.getTcpSourcePort());
-                    tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
-
-                    matchEntryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
-                    matchEntryBuilder.setHasMask(false);
-                    matchEntryList.add(matchEntryBuilder.build());
-                }
-                if (tcpMatch.getTcpDestinationPort() != null) {
-                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                    matchEntryBuilder.setOxmMatchField(TcpDst.class);
-
-                    TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder();
-                    TcpDstBuilder tcpDstBuilder = new TcpDstBuilder();
-                    tcpDstBuilder.setPort(tcpMatch.getTcpDestinationPort());
-                    tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build());
-                    matchEntryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build());
-                    matchEntryBuilder.setHasMask(false);
-                    matchEntryList.add(matchEntryBuilder.build());
-                }
-            } else if (layer4Match instanceof UdpMatch) {
-                UdpMatch udpMatch = (UdpMatch) layer4Match;
-                if (udpMatch.getUdpSourcePort() != null) {
-                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                    matchEntryBuilder.setOxmMatchField(UdpSrc.class);
-
-                    UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder();
-                    UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder();
-                    boolean hasMask = false;
-                    udpSrcBuilder.setPort(udpMatch.getUdpSourcePort());
-                    udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build());
-                    matchEntryBuilder.setMatchEntryValue(udpSrcCaseBuilder.build());
-                    matchEntryBuilder.setHasMask(hasMask);
-                    matchEntryList.add(matchEntryBuilder.build());
-                }
-
-                if (udpMatch.getUdpDestinationPort() != null) {
-                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                    matchEntryBuilder.setOxmMatchField(UdpDst.class);
-
-                    UdpDstCaseBuilder udpDstCaseBuilder = new UdpDstCaseBuilder();
-                    UdpDstBuilder udpDstBuilder = new UdpDstBuilder();
-                    udpDstBuilder.setPort(udpMatch.getUdpDestinationPort());
-                    udpDstCaseBuilder.setUdpDst(udpDstBuilder.build());
-                    matchEntryBuilder.setMatchEntryValue(udpDstCaseBuilder.build());
-                    matchEntryBuilder.setHasMask(false);
-                    matchEntryList.add(matchEntryBuilder.build());
-                }
-            } else if (layer4Match instanceof SctpMatch) {
-                SctpMatch sctpMatch = (SctpMatch) layer4Match;
-                if (sctpMatch.getSctpSourcePort() != null) {
-                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                    matchEntryBuilder.setOxmMatchField(SctpSrc.class);
-
-                    SctpSrcCaseBuilder sctpSrcCaseBuilder = new SctpSrcCaseBuilder();
-                    SctpSrcBuilder sctpSrcBuilder = new SctpSrcBuilder();
-                    sctpSrcBuilder.setPort(sctpMatch.getSctpSourcePort());
-                    sctpSrcCaseBuilder.setSctpSrc(sctpSrcBuilder.build());
-                    matchEntryBuilder.setMatchEntryValue(sctpSrcCaseBuilder.build());
-                    matchEntryBuilder.setHasMask(false);
-                    matchEntryList.add(matchEntryBuilder.build());
-                }
-
-                if (sctpMatch.getSctpDestinationPort() != null) {
-                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-                    matchEntryBuilder.setOxmMatchField(SctpDst.class);
-
-                    SctpDstCaseBuilder sctpDstCaseBuilder = new SctpDstCaseBuilder();
-                    SctpDstBuilder sctpDstBuilder = new SctpDstBuilder();
-                    sctpDstBuilder.setPort(sctpMatch.getSctpDestinationPort());
-                    sctpDstCaseBuilder.setSctpDst(sctpDstBuilder.build());
-                    matchEntryBuilder.setMatchEntryValue(sctpDstCaseBuilder.build());
-                    matchEntryBuilder.setHasMask(false);
-                    matchEntryList.add(matchEntryBuilder.build());
-                }
+            if (protocolMatchFields.getMplsBos() != null) {
+                matchEntryList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
             }
-        }
 
-        Icmpv4Match icmpv4Match = match.getIcmpv4Match();
-        if (icmpv4Match != null) {
-            if (icmpv4Match.getIcmpv4Type() != null) {
-                matchEntryList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
+            if (protocolMatchFields.getMplsTc() != null) {
+                matchEntryList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
             }
 
-            if (icmpv4Match.getIcmpv4Code() != null) {
-                matchEntryList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
+            if (protocolMatchFields.getPbb() != null) {
+                matchEntryList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
             }
         }
+    }
 
-        Icmpv6Match icmpv6Match = match.getIcmpv6Match();
-        if (icmpv6Match != null) {
-            if (icmpv6Match.getIcmpv6Type() != null) {
-                matchEntryList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
-            }
-
-            if (icmpv6Match.getIcmpv6Code() != null) {
-                matchEntryList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
-            }
-        }
 
-        Layer3Match layer3Match = match.getLayer3Match();
+    private void layer3Match(List<MatchEntry> matchEntryList,
+            Layer3Match layer3Match) {
         if (layer3Match != null) {
             if (layer3Match instanceof Ipv4Match) {
                 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
@@ -798,67 +654,238 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
                 }
             }
         }
+    }
 
-        ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
-        if (protocolMatchFields != null) {
-            if (protocolMatchFields.getMplsLabel() != null) {
-                matchEntryList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
+
+    private void icmpv6Match(List<MatchEntry> matchEntryList,
+            Icmpv6Match icmpv6Match) {
+        if (icmpv6Match != null) {
+            if (icmpv6Match.getIcmpv6Type() != null) {
+                matchEntryList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
             }
 
-            if (protocolMatchFields.getMplsBos() != null) {
-                matchEntryList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
+            if (icmpv6Match.getIcmpv6Code() != null) {
+                matchEntryList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
             }
+        }
+    }
 
-            if (protocolMatchFields.getMplsTc() != null) {
-                matchEntryList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
+
+    private void icmpv4Match(List<MatchEntry> matchEntryList,
+            Icmpv4Match icmpv4Match) {
+        if (icmpv4Match != null) {
+            if (icmpv4Match.getIcmpv4Type() != null) {
+                matchEntryList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
             }
 
-            if (protocolMatchFields.getPbb() != null) {
-                matchEntryList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
+            if (icmpv4Match.getIcmpv4Code() != null) {
+                matchEntryList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
             }
         }
+    }
 
-        org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
-                .getTunnel();
-        if (tunnel != null) {
 
+    private void layer4Match(List<MatchEntry> matchEntryList,
+            Layer4Match layer4Match) {
+        if (layer4Match != null) {
+            if (layer4Match instanceof TcpMatch) {
+                TcpMatch tcpMatch = (TcpMatch) layer4Match;
 
-            MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-            TunnelIdCaseBuilder tunnelIdCaseBuilder = new TunnelIdCaseBuilder();
-            TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder();
-            boolean hasMask = false;
-            if (null != tunnel.getTunnelMask()) {
-                hasMask = true;
-                tunnelIdBuilder.setMask(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelMask(), OFConstants.SIZE_OF_LONG_IN_BYTES));
+                if (tcpMatch.getTcpSourcePort() != null) {
+                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                    matchEntryBuilder.setOxmMatchField(TcpSrc.class);
+
+                    TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
+                    TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
+                    tcpSrcBuilder.setPort(tcpMatch.getTcpSourcePort());
+                    tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
+
+                    matchEntryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
+                    matchEntryBuilder.setHasMask(false);
+                    matchEntryList.add(matchEntryBuilder.build());
+                }
+                if (tcpMatch.getTcpDestinationPort() != null) {
+                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                    matchEntryBuilder.setOxmMatchField(TcpDst.class);
+
+                    TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder();
+                    TcpDstBuilder tcpDstBuilder = new TcpDstBuilder();
+                    tcpDstBuilder.setPort(tcpMatch.getTcpDestinationPort());
+                    tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build());
+                    matchEntryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build());
+                    matchEntryBuilder.setHasMask(false);
+                    matchEntryList.add(matchEntryBuilder.build());
+                }
+            } else if (layer4Match instanceof UdpMatch) {
+                UdpMatch udpMatch = (UdpMatch) layer4Match;
+                if (udpMatch.getUdpSourcePort() != null) {
+                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                    matchEntryBuilder.setOxmMatchField(UdpSrc.class);
+
+                    UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder();
+                    UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder();
+                    boolean hasMask = false;
+                    udpSrcBuilder.setPort(udpMatch.getUdpSourcePort());
+                    udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build());
+                    matchEntryBuilder.setMatchEntryValue(udpSrcCaseBuilder.build());
+                    matchEntryBuilder.setHasMask(hasMask);
+                    matchEntryList.add(matchEntryBuilder.build());
+                }
+
+                if (udpMatch.getUdpDestinationPort() != null) {
+                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                    matchEntryBuilder.setOxmMatchField(UdpDst.class);
+
+                    UdpDstCaseBuilder udpDstCaseBuilder = new UdpDstCaseBuilder();
+                    UdpDstBuilder udpDstBuilder = new UdpDstBuilder();
+                    udpDstBuilder.setPort(udpMatch.getUdpDestinationPort());
+                    udpDstCaseBuilder.setUdpDst(udpDstBuilder.build());
+                    matchEntryBuilder.setMatchEntryValue(udpDstCaseBuilder.build());
+                    matchEntryBuilder.setHasMask(false);
+                    matchEntryList.add(matchEntryBuilder.build());
+                }
+            } else if (layer4Match instanceof SctpMatch) {
+                SctpMatch sctpMatch = (SctpMatch) layer4Match;
+                if (sctpMatch.getSctpSourcePort() != null) {
+                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                    matchEntryBuilder.setOxmMatchField(SctpSrc.class);
+
+                    SctpSrcCaseBuilder sctpSrcCaseBuilder = new SctpSrcCaseBuilder();
+                    SctpSrcBuilder sctpSrcBuilder = new SctpSrcBuilder();
+                    sctpSrcBuilder.setPort(sctpMatch.getSctpSourcePort());
+                    sctpSrcCaseBuilder.setSctpSrc(sctpSrcBuilder.build());
+                    matchEntryBuilder.setMatchEntryValue(sctpSrcCaseBuilder.build());
+                    matchEntryBuilder.setHasMask(false);
+                    matchEntryList.add(matchEntryBuilder.build());
+                }
+
+                if (sctpMatch.getSctpDestinationPort() != null) {
+                    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                    matchEntryBuilder.setOxmMatchField(SctpDst.class);
+
+                    SctpDstCaseBuilder sctpDstCaseBuilder = new SctpDstCaseBuilder();
+                    SctpDstBuilder sctpDstBuilder = new SctpDstBuilder();
+                    sctpDstBuilder.setPort(sctpMatch.getSctpDestinationPort());
+                    sctpDstCaseBuilder.setSctpDst(sctpDstBuilder.build());
+                    matchEntryBuilder.setMatchEntryValue(sctpDstCaseBuilder.build());
+                    matchEntryBuilder.setHasMask(false);
+                    matchEntryList.add(matchEntryBuilder.build());
+                }
             }
-            tunnelIdBuilder.setTunnelId(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelId(), OFConstants.SIZE_OF_LONG_IN_BYTES));
-            tunnelIdCaseBuilder.setTunnelId(tunnelIdBuilder.build());
-            matchEntryBuilder.setMatchEntryValue(tunnelIdCaseBuilder.build());
-            matchEntryBuilder.setHasMask(hasMask);
-            matchEntryBuilder.setOxmMatchField(TunnelId.class);
-            matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-            matchEntryList.add(matchEntryBuilder.build());
         }
+    }
 
 
-        /**
-         * 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<MatchEntry> convertor =
-                        OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
-                MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
-                matchEntryList.add(ofMatch);
+    private void ipMatch(List<MatchEntry> matchEntryList, IpMatch ipMatch) {
+        if (ipMatch != null) {
+            if (ipMatch.getIpDscp() != null) {
+                matchEntryList.add(toOfIpDscp(ipMatch.getIpDscp()));
+            }
+
+            if (ipMatch.getIpEcn() != null) {
+                matchEntryList.add(toOfIpEcn(ipMatch.getIpEcn()));
             }
+
+            if (ipMatch.getIpProtocol() != null) {
+                matchEntryList.add(toOfIpProto(ipMatch.getIpProtocol()));
+            }
+
         }
+    }
 
-        return matchEntryList;
+
+    private void vlanMatch(List<MatchEntry> matchEntryList,
+            VlanMatch vlanMatch) {
+        if (vlanMatch != null) {
+            if (vlanMatch.getVlanId() != null) {
+                VlanId vlanId = vlanMatch.getVlanId();
+                MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                matchEntryBuilder.setOxmMatchField(VlanVid.class);
+
+                VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
+                VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
+                boolean setCfiBit = false;
+                Integer vidEntryValue = 0;
+                boolean hasmask = false;
+                if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
+                    setCfiBit = true;
+                    if (vlanId.getVlanId() != null) {
+                        vidEntryValue = vlanId.getVlanId().getValue();
+                    }
+                    hasmask = (vidEntryValue == 0);
+                    if (hasmask) {
+                        vlanVidBuilder.setMask(VLAN_VID_MASK);
+                    }
+                }
+
+                vlanVidBuilder.setCfiBit(setCfiBit);
+                vlanVidBuilder.setVlanVid(vidEntryValue);
+                vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
+                matchEntryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
+                matchEntryBuilder.setHasMask(hasmask);
+                matchEntryList.add(matchEntryBuilder.build());
+            }
+
+            if (vlanMatch.getVlanPcp() != null) {
+                matchEntryList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
+            }
+        }
+    }
+
+
+    private void ethernetMatch(List<MatchEntry> matchEntryList,
+            EthernetMatch ethernetMatch) {
+        if (ethernetMatch != null) {
+            EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
+            if (ethernetDestination != null) {
+                MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                matchEntryBuilder.setOxmMatchField(EthDst.class);
+                EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder();
+                EthDstBuilder ethDstBuilder = new EthDstBuilder();
+                ethDstBuilder.setMacAddress(ethernetDestination.getAddress());
+                boolean hasMask = false;
+                if (null != ethernetDestination.getMask()) {
+                    ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetDestination.getMask().getValue()));
+                    hasMask = true;
+                }
+                ethDstCaseBuilder.setEthDst(ethDstBuilder.build());
+                matchEntryBuilder.setMatchEntryValue(ethDstCaseBuilder.build());
+                matchEntryBuilder.setHasMask(hasMask);
+                matchEntryList.add(matchEntryBuilder.build());
+            }
+
+            EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
+            if (ethernetSource != null) {
+                MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
+                matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
+                matchEntryBuilder.setOxmMatchField(EthSrc.class);
+
+                EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder();
+                EthSrcBuilder ethDstBuilder = new EthSrcBuilder();
+                ethDstBuilder.setMacAddress(ethernetSource.getAddress());
+                boolean hasMask = false;
+                if (null != ethernetSource.getMask()) {
+                    ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetSource.getMask().getValue()));
+                    hasMask = true;
+                }
+                ethSrcCaseBuilder.setEthSrc(ethDstBuilder.build());
+                matchEntryBuilder.setMatchEntryValue(ethSrcCaseBuilder.build());
+                matchEntryBuilder.setHasMask(hasMask);
+                matchEntryList.add(matchEntryBuilder.build());
+            }
+
+            if (ethernetMatch.getEthernetType() != null) {
+                matchEntryList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
+            }
+        }
     }
 
 
@@ -889,7 +916,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
      * @return
      * @author avishnoi@in.ibm.com
      */
-    public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
+    public static MatchBuilder fromOFMatchV10ToSALMatch(@Nonnull final MatchV10 swMatch, @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
         MatchBuilder matchBuilder = new MatchBuilder();
         EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
         VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
@@ -944,7 +971,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
 
                 ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + "32";
             }
-            if (!noIp.equals(ipv4PrefixStr)) {
+            if (!NO_IP.equals(ipv4PrefixStr)) {
                 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
                 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
             }
@@ -961,7 +988,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
 
                 ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + "32";
             }
-            if (!noIp.equals(ipv4PrefixStr)) {
+            if (!NO_IP.equals(ipv4PrefixStr)) {
                 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
                 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
             }
@@ -1039,7 +1066,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
             matchBuilder.setIpMatch(ipMatchBuilder.build());
         }
 
-        return matchBuilder.build();
+        return matchBuilder;
     }
 
     /**
@@ -1054,8 +1081,8 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
      * @author avishnoi@in.ibm.com
      */
     public static MatchBuilder fromOFMatchToSALMatch(
-            final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match swMatch,
-            final BigInteger datapathid, final OpenflowVersion ofVersion) {
+            @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match swMatch,
+            @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
         return OfMatchToSALMatchConvertor(swMatch.getMatchEntry(), datapathid, ofVersion);
     }
 
@@ -1075,7 +1102,6 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
         ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
         Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
         ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
-        TcpFlagMatchBuilder tcpFlagMatchBuilder = new TcpFlagMatchBuilder();
         TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
 
         for (MatchEntry ofMatch : swMatchList) {
@@ -1527,7 +1553,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
         if (mplsBos.shortValue() != 0) {
             isBos = true;
         }
-        mplsBosBuilder.setBos(new Boolean(isBos));
+        mplsBosBuilder.setBos(isBos);
         mplsBosCaseBuilder.setMplsBos(mplsBosBuilder.build());
 
         matchEntryBuilder.setMatchEntryValue(mplsBosCaseBuilder.build());
@@ -1738,33 +1764,6 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
         return matchEntryBuilder.build();
     }
 
-    private static MatchEntry toOfVlanVid(final VlanId vlanId) {
-        // TODO: verify
-        boolean hasmask = false;
-        boolean setCfiBit = false;
-        Integer vidEntryValue = 0;
-        MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
-        matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
-        matchEntryBuilder.setOxmMatchField(VlanVid.class);
-        VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
-        VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
-        if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
-            setCfiBit = true;
-            if (vlanId.getVlanId() != null) {
-                vidEntryValue = vlanId.getVlanId().getValue();
-            }
-            hasmask = (vidEntryValue == 0);
-        }
-        vlanVidBuilder.setCfiBit(setCfiBit);
-        vlanVidBuilder.setVlanVid(vidEntryValue);
-        if (hasmask) {
-            vlanVidBuilder.setMask(VLAN_VID_MASK);
-        }
-        vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
-        matchEntryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
-        matchEntryBuilder.setHasMask(hasmask);
-        return matchEntryBuilder.build();
-    }
 
     private static MatchEntry toOfIpProto(final Short ipProtocol) {
         MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();