Bug 3328: Set icmpv4-match into OF10 match.
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchConvertorImplV10Test.java
index 389fdbb6f58e423963be8537fadd341e065e239e..a453ad08f278aed420816bbfc9d3c1f80872b635 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ * Copyright (c) 2014-2015 Pantheon Technologies s.r.o. and others. All rights reserved.\r
  *\r
  * This program and the accompanying materials are made available under the\r
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
@@ -18,6 +18,9 @@ import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;\r
@@ -83,6 +86,7 @@ public class MatchConvertorImplV10Test {
         TcpMatch tcpMatch = (TcpMatch) salMatch.getLayer4Match();\r
         Assert.assertEquals("Wrong tp dst", 4096, tcpMatch.getTcpDestinationPort().getValue().intValue());\r
         Assert.assertEquals("Wrong tp src", 2048, tcpMatch.getTcpSourcePort().getValue().intValue());\r
+        Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());\r
     }\r
 \r
     /**\r
@@ -117,6 +121,7 @@ public class MatchConvertorImplV10Test {
         Assert.assertEquals("Wrong layer 3 match", null, salMatch.getLayer3Match());\r
         Assert.assertEquals("Wrong layer 4 match", null, salMatch.getLayer4Match());\r
         Assert.assertEquals("Wrong ip match", null, salMatch.getIpMatch());\r
+        Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());\r
     }\r
 \r
     /**\r
@@ -137,6 +142,7 @@ public class MatchConvertorImplV10Test {
         Assert.assertEquals("Wrong layer 3 match", null, salMatch.getLayer3Match());\r
         Assert.assertEquals("Wrong layer 4 match", null, salMatch.getLayer4Match());\r
         Assert.assertEquals("Wrong ip match", null, salMatch.getIpMatch());\r
+        Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());\r
     }\r
 \r
     /**\r
@@ -161,6 +167,7 @@ public class MatchConvertorImplV10Test {
         UdpMatch udpMatch = (UdpMatch) salMatch.getLayer4Match();\r
         Assert.assertEquals("Wrong udp dst", 4096, udpMatch.getUdpDestinationPort().getValue().intValue());\r
         Assert.assertEquals("Wrong udp src", 2048, udpMatch.getUdpSourcePort().getValue().intValue());\r
+        Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());\r
     }\r
 \r
     /**\r
@@ -173,4 +180,633 @@ public class MatchConvertorImplV10Test {
 \r
         MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10);\r
     }\r
-}
\ No newline at end of file
+\r
+    /**\r
+     * ICMPv4 match test for\r
+     * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
+     */\r
+    @Test\r
+    public void testIcmpv4Match() {\r
+        // NW_PROTO, TP_SRC, TP_DST are wildcarded.\r
+        Long dlType = 0x800L;\r
+        FlowWildcardsV10 wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, true, true, true, true);\r
+        MatchV10Builder builder = new MatchV10Builder().\r
+            setWildcards(wc).\r
+            setDlType(dlType.intValue());\r
+        MatchV10 match = builder.build();\r
+\r
+        BigInteger dpid = BigInteger.valueOf(12345L);\r
+        Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // NW_PROTO is not wildcarded but null.\r
+        wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, true, true);\r
+        match = builder.setWildcards(wc).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify ICMPv4 protocol.\r
+        Short ipProto = 1;\r
+        match = builder.setNwProto(ipProto).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        IpMatch ipMatch = salMatch.getIpMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // TP_SRC is not wildcarded but null.\r
+        wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, true, false);\r
+        match = builder.setWildcards(wc).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify ICMPv4 type.\r
+        Short icmpType = 10;\r
+        match = builder.setTpSrc(icmpType.intValue()).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        Icmpv4Match icmpv4Match = salMatch.getIcmpv4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 type",\r
+                            icmpType, icmpv4Match.getIcmpv4Type());\r
+        Assert.assertEquals("Wrong ICMPv4 code",\r
+                            null, icmpv4Match.getIcmpv4Code());\r
+\r
+        // TP_DST is not wildcarded but null.\r
+        wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, false, false);\r
+        match = builder.setWildcards(wc).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        icmpv4Match = salMatch.getIcmpv4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 type",\r
+                            icmpType, icmpv4Match.getIcmpv4Type());\r
+        Assert.assertEquals("Wrong ICMPv4 code",\r
+                            null, icmpv4Match.getIcmpv4Code());\r
+\r
+        // Specify ICMPv4 code only.\r
+        Short icmpCode = 33;\r
+        match = builder.setTpSrc(null).setTpDst(icmpCode.intValue()).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        icmpv4Match = salMatch.getIcmpv4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 type",\r
+                            null, icmpv4Match.getIcmpv4Type());\r
+        Assert.assertEquals("Wrong ICMPv4 code",\r
+                            icmpCode, icmpv4Match.getIcmpv4Code());\r
+\r
+        // Specify both ICMPv4 type and code.\r
+        icmpType = 0;\r
+        icmpCode = 8;\r
+        match = builder.setTpSrc(icmpType.intValue()).\r
+            setTpDst(icmpCode.intValue()).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        icmpv4Match = salMatch.getIcmpv4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 type",\r
+                            icmpType, icmpv4Match.getIcmpv4Type());\r
+        Assert.assertEquals("Wrong ICMPv4 code",\r
+                            icmpCode, icmpv4Match.getIcmpv4Code());\r
+    }\r
+\r
+    /**\r
+     * TCP match test for\r
+     * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
+     */\r
+    @Test\r
+    public void testTcpMatch() {\r
+        // TP_SRC, TP_DST are wildcarded.\r
+        // NW_PROTO is not wildcarded but null.\r
+        Long dlType = 0x800L;\r
+        FlowWildcardsV10 wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, true, true);\r
+        MatchV10Builder builder = new MatchV10Builder().\r
+            setWildcards(wc).\r
+            setDlType(dlType.intValue());\r
+        MatchV10 match = builder.build();\r
+\r
+        BigInteger dpid = BigInteger.valueOf(12345L);\r
+        Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify TCP protocol.\r
+        Short ipProto = 6;\r
+        match = builder.setNwProto(ipProto).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        IpMatch ipMatch = salMatch.getIpMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // TP_SRC is not wildcarded but null.\r
+        wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, true, false);\r
+        match = builder.setWildcards(wc).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify TCP source port.\r
+        Integer srcPort = 60000;\r
+        match = builder.setTpSrc(srcPort).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        TcpMatch tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong TCP src", srcPort,\r
+                            tcpMatch.getTcpSourcePort().getValue());\r
+        Assert.assertEquals("Wrong TCP dst", null,\r
+                            tcpMatch.getTcpDestinationPort());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // TP_DST is not wildcarded but null.\r
+        wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, false, false);\r
+        match = builder.setWildcards(wc).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong TCP src", srcPort,\r
+                            tcpMatch.getTcpSourcePort().getValue());\r
+        Assert.assertEquals("Wrong TCP dst", null,\r
+                            tcpMatch.getTcpDestinationPort());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify TCP destination port only.\r
+        Integer dstPort = 6653;\r
+        match = builder.setTpSrc(null).setTpDst(dstPort).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong TCP src", null,\r
+                            tcpMatch.getTcpSourcePort());\r
+        Assert.assertEquals("Wrong TCP dst", dstPort,\r
+                            tcpMatch.getTcpDestinationPort().getValue());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify both source and destination port.\r
+        srcPort = 32767;\r
+        dstPort = 9999;\r
+        match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong TCP src", srcPort,\r
+                            tcpMatch.getTcpSourcePort().getValue());\r
+        Assert.assertEquals("Wrong TCP dst", dstPort,\r
+                            tcpMatch.getTcpDestinationPort().getValue());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+    }\r
+\r
+    /**\r
+     * UDP match test for\r
+     * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
+     */\r
+    @Test\r
+    public void testUdpMatch() {\r
+        // TP_SRC, TP_DST are wildcarded.\r
+        // NW_PROTO is not wildcarded but null.\r
+        Long dlType = 0x800L;\r
+        FlowWildcardsV10 wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, true, true);\r
+        MatchV10Builder builder = new MatchV10Builder().\r
+            setWildcards(wc).\r
+            setDlType(dlType.intValue());\r
+        MatchV10 match = builder.build();\r
+\r
+        BigInteger dpid = BigInteger.valueOf(12345L);\r
+        Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify UDP protocol.\r
+        Short ipProto = 17;\r
+        match = builder.setNwProto(ipProto).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        IpMatch ipMatch = salMatch.getIpMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // TP_SRC is not wildcarded but null.\r
+        wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, true, false);\r
+        match = builder.setWildcards(wc).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify UDP source port.\r
+        Integer srcPort = 60000;\r
+        match = builder.setTpSrc(srcPort).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        UdpMatch udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong UDP src", srcPort,\r
+                            udpMatch.getUdpSourcePort().getValue());\r
+        Assert.assertEquals("Wrong UDP dst", null,\r
+                            udpMatch.getUdpDestinationPort());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // TP_DST is not wildcarded but null.\r
+        wc = new FlowWildcardsV10(\r
+            true, true, false, true, true, true, false, true, false, false);\r
+        match = builder.setWildcards(wc).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong UDP src", srcPort,\r
+                            udpMatch.getUdpSourcePort().getValue());\r
+        Assert.assertEquals("Wrong UDP dst", null,\r
+                            udpMatch.getUdpDestinationPort());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify UDP destination port only.\r
+        Integer dstPort = 6653;\r
+        match = builder.setTpSrc(null).setTpDst(dstPort).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong UDP src", null,\r
+                            udpMatch.getUdpSourcePort());\r
+        Assert.assertEquals("Wrong UDP dst", dstPort,\r
+                            udpMatch.getUdpDestinationPort().getValue());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+\r
+        // Specify both source and destination port.\r
+        srcPort = 32767;\r
+        dstPort = 9999;\r
+        match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();\r
+        salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
+            match, dpid, OpenflowVersion.OF10);\r
+        etherMatch = salMatch.getEthernetMatch();\r
+        ipMatch = salMatch.getIpMatch();\r
+        udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
+        Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
+        Assert.assertEquals("Wrong dl src",\r
+                            null, etherMatch.getEthernetSource());\r
+        Assert.assertEquals("Wrong dl dst",\r
+                            null, etherMatch.getEthernetDestination());\r
+        Assert.assertEquals("Wrong dl type", dlType,\r
+                            etherMatch.getEthernetType().getType().getValue());\r
+        Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
+        Assert.assertEquals("Wrong ip protocol",\r
+                            ipProto, ipMatch.getIpProtocol());\r
+        Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
+        Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
+        Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
+        Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
+        Assert.assertEquals("Wrong UDP src", srcPort,\r
+                            udpMatch.getUdpSourcePort().getValue());\r
+        Assert.assertEquals("Wrong UDP dst", dstPort,\r
+                            udpMatch.getUdpDestinationPort().getValue());\r
+        Assert.assertEquals("Wrong ICMPv4 match",\r
+                            null, salMatch.getIcmpv4Match());\r
+    }\r
+}\r