Bug 3328: Set icmpv4-match into OF10 match. 12/20912/1
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Thu, 21 May 2015 17:20:13 +0000 (02:20 +0900)
committerShigeru Yasuda <s-yasuda@da.jp.nec.com>
Thu, 21 May 2015 17:20:13 +0000 (02:20 +0900)
Change-Id: Id636a75ebff08fd3899081d3f1efe98dacb15970
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImplV10Test.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10ImplTest.java

index 67e031d54162fad33fc760852acaa7568e74e817..442e94910a40d816c9d74cd31ec2f85f01122b12 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2013-2014 Ericsson. and others.  All rights reserved.
+ * Copyright (c) 2013-2015 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,
@@ -273,6 +273,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
     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 short PROTO_ICMPV4 = 1;
     private static final String noIp = "0.0.0.0/0";
 
     @Override
@@ -962,41 +963,70 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
             }
         }
         if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() != null) {
-            ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
+            Short nwProto = swMatch.getNwProto();
+            ipMatchBuilder.setIpProtocol(nwProto);
             matchBuilder.setIpMatch(ipMatchBuilder.build());
-        }
-        if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_TCP) {
-            TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
-            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.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_UDP) {
-            UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
-            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()));
-            }
+            int proto = nwProto.intValue();
+            if (proto == PROTO_TCP) {
+                TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
+                boolean hasTcp = false;
+                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()));
+                    hasTcp = true;
+                }
+                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()));
+                    hasTcp = true;
+                }
 
-            if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
-                matchBuilder.setLayer4Match(udpMatchBuilder.build());
+                if (hasTcp) {
+                    matchBuilder.setLayer4Match(tcpMatchBuilder.build());
+                }
+            } else if (proto == PROTO_UDP) {
+                UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
+                boolean hasUdp = false;
+                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()));
+                    hasUdp = true;
+                }
+                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()));
+                    hasUdp = true;
+                }
+
+                if (hasUdp) {
+                    matchBuilder.setLayer4Match(udpMatchBuilder.build());
+                }
+            } else if (proto == PROTO_ICMPV4) {
+                Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
+                boolean hasIcmpv4 = false;
+                if (!swMatch.getWildcards().isTPSRC().booleanValue()) {
+                    Integer type = swMatch.getTpSrc();
+                    if (type != null) {
+                        icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
+                        hasIcmpv4 = true;
+                    }
+                }
+                if (!swMatch.getWildcards().isTPDST().booleanValue()) {
+                    Integer code = swMatch.getTpDst();
+                    if (code != null) {
+                        icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
+                        hasIcmpv4 = true;
+                    }
+                }
+
+                if (hasIcmpv4) {
+                    matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
+                }
             }
         }
         if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
index 659bbab6efa1870d7eb72f764c5847b5736b7a7e..d3b65d7d0f78e902e03ca5b54d3f85506758ef92 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2015 Cisco Systems, Inc. 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,
@@ -20,6 +20,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
@@ -122,6 +123,20 @@ public class MatchConvertorV10Impl implements MatchConvertor<MatchV10> {
                     _tPSRC = convertL4UdpSrcMatch(matchBuilder, udpMatch);
                     _tPDST = convertL4UdpDstMatch(matchBuilder, udpMatch);
                 }
+            } else {
+                Icmpv4Match icmpv4Match = match.getIcmpv4Match();
+                if (icmpv4Match != null) {
+                    Short type = icmpv4Match.getIcmpv4Type();
+                    if (type != null) {
+                        matchBuilder.setTpSrc(type.intValue());
+                        _tPSRC = false;
+                    }
+                    Short code = icmpv4Match.getIcmpv4Code();
+                    if (code != null) {
+                        matchBuilder.setTpDst(code.intValue());
+                        _tPDST = false;
+                    }
+                }
             }
         }
 
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
index 9e0ede5340f09d4e936a55634323d973cb0855a8..dd88245e7e7d57cd17b498fe49f8ebc5807d4c64 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014-2015 Cisco Systems, Inc. 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,
@@ -20,6 +20,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
 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.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.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
@@ -28,6 +29,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
@@ -35,6 +37,7 @@ 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._4.match.TcpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
 
 /**
@@ -64,7 +67,7 @@ public class MatchConvertorV10ImplTest {
 
     @Test
     /**
-     * Test method for MatchConvertotV10Impl#convert()
+     * Test method for {@link MatchConvertorV10Impl#convert(Match,BigInteger)}
      */
     public void testConvert() {
         MatchV10 matchV10 = matchConvertorV10.convert(createL4UdpMatch().build(), dataPathId);
@@ -91,6 +94,115 @@ public class MatchConvertorV10ImplTest {
 
     }
 
+    /**
+     * ICMPv4 match test for
+     * {@link MatchConvertorV10Impl#convert(Match,BigInteger)}.
+     */
+    @Test
+    public void testConvertIcmpv4() {
+        MatchBuilder matchBuilder = createMatchBuilderWithDefaults();
+        Match match = matchBuilder.build();
+        MatchV10 matchV10 = matchConvertorV10.convert(match, dataPathId);
+        Integer zero = 0;
+        boolean wcTpSrc = true;
+        boolean wcTpDst = true;
+        FlowWildcardsV10 wc = new FlowWildcardsV10(
+            false, false, false, true, true, false, false, false,
+            wcTpDst, wcTpSrc);
+        assertEquals(ZERO_MAC, matchV10.getDlDst());
+        assertEquals(FF_MAC, matchV10.getDlSrc());
+        assertEquals(0, matchV10.getDlType().intValue());
+        assertEquals(0xffff, matchV10.getDlVlan().intValue());
+        assertEquals(Integer.parseInt(NODE_CONNECTOR_ID),
+                     matchV10.getInPort().intValue());
+        assertEquals(DEFAULT_IPV4_ADDRESS.getValue(),
+                     matchV10.getNwDst().getValue());
+        assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
+        assertEquals(0, matchV10.getNwTos().shortValue());
+        assertEquals(zero, matchV10.getTpSrc());
+        assertEquals(zero, matchV10.getTpDst());
+        assertEquals(wc, matchV10.getWildcards());
+
+        // Specify ICMP type only.
+        Integer icmpType = 55;
+        Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder().
+            setIcmpv4Type(icmpType.shortValue());
+        wcTpSrc = false;
+        wc = new FlowWildcardsV10(
+            false, false, false, true, true, false, false, false,
+            wcTpDst, wcTpSrc);
+        match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()).
+            build();
+        matchV10 = matchConvertorV10.convert(match, dataPathId);
+        assertEquals(ZERO_MAC, matchV10.getDlDst());
+        assertEquals(FF_MAC, matchV10.getDlSrc());
+        assertEquals(0, matchV10.getDlType().intValue());
+        assertEquals(0xffff, matchV10.getDlVlan().intValue());
+        assertEquals(Integer.parseInt(NODE_CONNECTOR_ID),
+                     matchV10.getInPort().intValue());
+        assertEquals(DEFAULT_IPV4_ADDRESS.getValue(),
+                     matchV10.getNwDst().getValue());
+        assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
+        assertEquals(0, matchV10.getNwTos().shortValue());
+        assertEquals(icmpType, matchV10.getTpSrc());
+        assertEquals(zero, matchV10.getTpDst());
+        assertEquals(wc, matchV10.getWildcards());
+
+        // Specify ICMP code only.
+        Integer icmpCode = 31;
+        icmpv4MatchBuilder = new Icmpv4MatchBuilder().
+            setIcmpv4Type(null).setIcmpv4Code(icmpCode.shortValue());
+        wcTpSrc = true;
+        wcTpDst = false;
+        wc = new FlowWildcardsV10(
+            false, false, false, true, true, false, false, false,
+            wcTpDst, wcTpSrc);
+        match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()).
+            build();
+        matchV10 = matchConvertorV10.convert(match, dataPathId);
+        assertEquals(ZERO_MAC, matchV10.getDlDst());
+        assertEquals(FF_MAC, matchV10.getDlSrc());
+        assertEquals(0, matchV10.getDlType().intValue());
+        assertEquals(0xffff, matchV10.getDlVlan().intValue());
+        assertEquals(Integer.parseInt(NODE_CONNECTOR_ID),
+                     matchV10.getInPort().intValue());
+        assertEquals(DEFAULT_IPV4_ADDRESS.getValue(),
+                     matchV10.getNwDst().getValue());
+        assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
+        assertEquals(0, matchV10.getNwTos().shortValue());
+        assertEquals(zero, matchV10.getTpSrc());
+        assertEquals(icmpCode, matchV10.getTpDst());
+        assertEquals(wc, matchV10.getWildcards());
+
+        // Specify both ICMP type and code.
+        icmpType = 11;
+        icmpCode = 22;
+        icmpv4MatchBuilder = new Icmpv4MatchBuilder().
+            setIcmpv4Type(icmpType.shortValue()).
+            setIcmpv4Code(icmpCode.shortValue());
+        wcTpSrc = false;
+        wcTpDst = false;
+        wc = new FlowWildcardsV10(
+            false, false, false, true, true, false, false, false,
+            wcTpDst, wcTpSrc);
+        match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()).
+            build();
+        matchV10 = matchConvertorV10.convert(match, dataPathId);
+        assertEquals(ZERO_MAC, matchV10.getDlDst());
+        assertEquals(FF_MAC, matchV10.getDlSrc());
+        assertEquals(0, matchV10.getDlType().intValue());
+        assertEquals(0xffff, matchV10.getDlVlan().intValue());
+        assertEquals(Integer.parseInt(NODE_CONNECTOR_ID),
+                     matchV10.getInPort().intValue());
+        assertEquals(DEFAULT_IPV4_ADDRESS.getValue(),
+                     matchV10.getNwDst().getValue());
+        assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
+        assertEquals(0, matchV10.getNwTos().shortValue());
+        assertEquals(icmpType, matchV10.getTpSrc());
+        assertEquals(icmpCode, matchV10.getTpDst());
+        assertEquals(wc, matchV10.getWildcards());
+    }
+
     private MatchBuilder createL4UdpMatch() {
         MatchBuilder matchBuilder = createMatchBuilderWithDefaults();
 
@@ -146,11 +258,6 @@ public class MatchConvertorV10ImplTest {
         ethernetMatchBuilder.setEthernetSource(ethernetSourceBuilder.build());
         matchBuilder.setEthernetMatch(ethernetMatchBuilder.build());
 
-        Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
-        icmpv4MatchBuilder.setIcmpv4Code(ZERO);
-        icmpv4MatchBuilder.setIcmpv4Type(ZERO);
-        matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
-
         NodeConnectorId nodeConnectorId = NodeConnectorId.getDefaultInstance(NODE_CONNECTOR_ID);
 
         matchBuilder.setInPhyPort(nodeConnectorId);