ea2ee8baf9ec5db22ffbe73a9df15f3da34d76b6
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchConvertorImplV10Test.java
1 /*\r
2  * Copyright (c) 2014-2015 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;\r
10 \r
11 import java.math.BigInteger;\r
12 import org.junit.Assert;\r
13 import org.junit.Before;\r
14 import org.junit.Test;\r
15 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;\r
16 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;\r
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;\r
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;\r
29 \r
30 /**\r
31  * @author michal.polkorab\r
32  *\r
33  */\r
34 public class MatchConvertorImplV10Test {\r
35 \r
36     /**\r
37      * Initializes OpenflowPortsUtil\r
38      */\r
39     @Before\r
40     public void startUp() {\r
41         OpenflowPortsUtil.init();\r
42     }\r
43 \r
44     /**\r
45      * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
46      */\r
47     @Test\r
48     public void test() {\r
49         MatchV10Builder builder = new MatchV10Builder();\r
50         builder.setWildcards(new FlowWildcardsV10(false, false, false, false,\r
51                 false, false, false, false, false, false));\r
52         builder.setNwSrcMask((short) 24);\r
53         builder.setNwDstMask((short) 16);\r
54         builder.setInPort(6653);\r
55         builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));\r
56         builder.setDlDst(new MacAddress("02:02:02:02:02:02"));\r
57         builder.setDlVlan(128);\r
58         builder.setDlVlanPcp((short) 2);\r
59         builder.setDlType(15);\r
60         builder.setNwTos((short) 16);\r
61         builder.setNwProto((short) 6);\r
62         builder.setNwSrc(new Ipv4Address("1.1.1.2"));\r
63         builder.setNwDst(new Ipv4Address("32.16.8.1"));\r
64         builder.setTpSrc(2048);\r
65         builder.setTpDst(4096);\r
66         MatchV10 match = builder.build();\r
67 \r
68         Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
69 \r
70         Assert.assertEquals("Wrong in port", "openflow:42:6653", salMatch.getInPort().getValue());\r
71         Assert.assertEquals("Wrong dl src", new MacAddress("01:01:01:01:01:01"), salMatch.getEthernetMatch()\r
72                 .getEthernetSource().getAddress());\r
73         Assert.assertEquals("Wrong dl dst", new MacAddress("02:02:02:02:02:02"), salMatch.getEthernetMatch()\r
74                 .getEthernetDestination().getAddress());\r
75         Assert.assertEquals("Wrong dl type", 15, salMatch.getEthernetMatch().getEthernetType().getType().getValue().intValue());\r
76         Assert.assertEquals("Wrong dl vlan", 128, salMatch.getVlanMatch().getVlanId().getVlanId().getValue().intValue());\r
77         Assert.assertEquals("Wrong dl vlan pcp", 2, salMatch.getVlanMatch().getVlanPcp().getValue().intValue());\r
78         Ipv4Match ipv4Match = (Ipv4Match) salMatch.getLayer3Match();\r
79         Assert.assertEquals("Wrong nw src address", "1.1.1.2/24", ipv4Match.getIpv4Source().getValue());\r
80         Assert.assertEquals("Wrong nw dst address", "32.16.8.1/16", ipv4Match.getIpv4Destination().getValue());\r
81         Assert.assertEquals("Wrong ip protocol", 6, salMatch.getIpMatch().getIpProtocol().intValue());\r
82         Assert.assertEquals("Wrong ip proto", null, salMatch.getIpMatch().getIpProto());\r
83         Assert.assertEquals("Wrong ip ecn", null, salMatch.getIpMatch().getIpEcn());\r
84         Assert.assertEquals("Wrong ip dscp", 4, salMatch.getIpMatch().getIpDscp().getValue().intValue());\r
85         TcpMatch tcpMatch = (TcpMatch) salMatch.getLayer4Match();\r
86         Assert.assertEquals("Wrong tp dst", 4096, tcpMatch.getTcpDestinationPort().getValue().intValue());\r
87         Assert.assertEquals("Wrong tp src", 2048, tcpMatch.getTcpSourcePort().getValue().intValue());\r
88         Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());\r
89     }\r
90 \r
91     /**\r
92      * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
93      */\r
94     @Test\r
95     public void testWildcardedMatch() {\r
96         MatchV10Builder builder = new MatchV10Builder();\r
97         builder.setWildcards(new FlowWildcardsV10(true, true, true, true,\r
98                 true, true, true, true, true, true));\r
99         builder.setNwSrcMask((short) 24);\r
100         builder.setNwDstMask((short) 16);\r
101         builder.setInPort(6653);\r
102         builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));\r
103         builder.setDlDst(new MacAddress("02:02:02:02:02:02"));\r
104         builder.setDlVlan(128);\r
105         builder.setDlVlanPcp((short) 2);\r
106         builder.setDlType(15);\r
107         builder.setNwTos((short) 14);\r
108         builder.setNwProto((short) 6);\r
109         builder.setNwSrc(new Ipv4Address("1.1.1.2"));\r
110         builder.setNwDst(new Ipv4Address("32.16.8.1"));\r
111         builder.setTpSrc(2048);\r
112         builder.setTpDst(4096);\r
113         MatchV10 match = builder.build();\r
114 \r
115         Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
116 \r
117         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
118         Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
119         Assert.assertEquals("Wrong dl vlan match", null, salMatch.getVlanMatch());\r
120         Assert.assertEquals("Wrong layer 3 match", null, salMatch.getLayer3Match());\r
121         Assert.assertEquals("Wrong layer 4 match", null, salMatch.getLayer4Match());\r
122         Assert.assertEquals("Wrong ip match", null, salMatch.getIpMatch());\r
123         Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());\r
124     }\r
125 \r
126     /**\r
127      * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
128      */\r
129     @Test\r
130     public void testWildcardedMatchWithNoValuesSet() {\r
131         MatchV10Builder builder = new MatchV10Builder();\r
132         builder.setWildcards(new FlowWildcardsV10(true, true, true, true,\r
133                 true, true, true, true, true, true));\r
134         MatchV10 match = builder.build();\r
135 \r
136         Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
137 \r
138         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
139         Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
140         Assert.assertEquals("Wrong dl vlan match", null, salMatch.getVlanMatch());\r
141         Assert.assertEquals("Wrong layer 3 match", null, salMatch.getLayer3Match());\r
142         Assert.assertEquals("Wrong layer 4 match", null, salMatch.getLayer4Match());\r
143         Assert.assertEquals("Wrong ip match", null, salMatch.getIpMatch());\r
144         Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());\r
145     }\r
146 \r
147     /**\r
148      * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
149      */\r
150     @Test\r
151     public void testMatchWithValuesUnset() {\r
152         MatchV10Builder builder = new MatchV10Builder();\r
153         builder.setWildcards(new FlowWildcardsV10(false, false, false, false,\r
154                 false, false, false, false, false, false));\r
155         builder.setNwProto((short) 17);\r
156         builder.setTpSrc(2048);\r
157         builder.setTpDst(4096);\r
158         MatchV10 match = builder.build();\r
159 \r
160         Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
161 \r
162         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
163         Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
164         Assert.assertEquals("Wrong dl vlan match", null, salMatch.getVlanMatch());\r
165         Assert.assertEquals("Wrong layer 3 match", null, salMatch.getLayer3Match());\r
166         UdpMatch udpMatch = (UdpMatch) salMatch.getLayer4Match();\r
167         Assert.assertEquals("Wrong udp dst", 4096, udpMatch.getUdpDestinationPort().getValue().intValue());\r
168         Assert.assertEquals("Wrong udp src", 2048, udpMatch.getUdpSourcePort().getValue().intValue());\r
169         Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());\r
170     }\r
171 \r
172     /**\r
173      * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
174      */\r
175     @Test(expected=NullPointerException.class)\r
176     public void testEmptyMatch() {\r
177         MatchV10Builder builder = new MatchV10Builder();\r
178         MatchV10 match = builder.build();\r
179 \r
180         MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10);\r
181     }\r
182 \r
183     /**\r
184      * ICMPv4 match test for\r
185      * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
186      */\r
187     @Test\r
188     public void testIcmpv4Match() {\r
189         // NW_PROTO, TP_SRC, TP_DST are wildcarded.\r
190         Long dlType = 0x800L;\r
191         FlowWildcardsV10 wc = new FlowWildcardsV10(\r
192             true, true, false, true, true, true, true, true, true, true);\r
193         MatchV10Builder builder = new MatchV10Builder().\r
194             setWildcards(wc).\r
195             setDlType(dlType.intValue());\r
196         MatchV10 match = builder.build();\r
197 \r
198         BigInteger dpid = BigInteger.valueOf(12345L);\r
199         Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
200                 match, dpid, OpenflowVersion.OF10).build();\r
201         EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
202         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
203         Assert.assertEquals("Wrong dl src",\r
204                             null, etherMatch.getEthernetSource());\r
205         Assert.assertEquals("Wrong dl dst",\r
206                             null, etherMatch.getEthernetDestination());\r
207         Assert.assertEquals("Wrong dl type", dlType,\r
208                             etherMatch.getEthernetType().getType().getValue());\r
209         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
210         Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());\r
211         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
212         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
213         Assert.assertEquals("Wrong ICMPv4 match",\r
214                             null, salMatch.getIcmpv4Match());\r
215 \r
216         // NW_PROTO is not wildcarded but null.\r
217         wc = new FlowWildcardsV10(\r
218             true, true, false, true, true, true, false, true, true, true);\r
219         match = builder.setWildcards(wc).build();\r
220         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
221                 match, dpid, OpenflowVersion.OF10).build();\r
222         etherMatch = salMatch.getEthernetMatch();\r
223         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
224         Assert.assertEquals("Wrong dl src",\r
225                             null, etherMatch.getEthernetSource());\r
226         Assert.assertEquals("Wrong dl dst",\r
227                             null, etherMatch.getEthernetDestination());\r
228         Assert.assertEquals("Wrong dl type", dlType,\r
229                             etherMatch.getEthernetType().getType().getValue());\r
230         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
231         Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());\r
232         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
233         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
234         Assert.assertEquals("Wrong ICMPv4 match",\r
235                             null, salMatch.getIcmpv4Match());\r
236 \r
237         // Specify ICMPv4 protocol.\r
238         Short ipProto = 1;\r
239         match = builder.setNwProto(ipProto).build();\r
240         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
241                 match, dpid, OpenflowVersion.OF10).build();\r
242         etherMatch = salMatch.getEthernetMatch();\r
243         IpMatch ipMatch = salMatch.getIpMatch();\r
244         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
245         Assert.assertEquals("Wrong dl src",\r
246                             null, etherMatch.getEthernetSource());\r
247         Assert.assertEquals("Wrong dl dst",\r
248                             null, etherMatch.getEthernetDestination());\r
249         Assert.assertEquals("Wrong dl type", dlType,\r
250                             etherMatch.getEthernetType().getType().getValue());\r
251         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
252         Assert.assertEquals("Wrong ip protocol",\r
253                             ipProto, ipMatch.getIpProtocol());\r
254         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
255         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
256         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
257         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
258         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
259         Assert.assertEquals("Wrong ICMPv4 match",\r
260                             null, salMatch.getIcmpv4Match());\r
261 \r
262         // TP_SRC is not wildcarded but null.\r
263         wc = new FlowWildcardsV10(\r
264             true, true, false, true, true, true, false, true, true, false);\r
265         match = builder.setWildcards(wc).build();\r
266         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
267                 match, dpid, OpenflowVersion.OF10).build();\r
268         etherMatch = salMatch.getEthernetMatch();\r
269         ipMatch = salMatch.getIpMatch();\r
270         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
271         Assert.assertEquals("Wrong dl src",\r
272                             null, etherMatch.getEthernetSource());\r
273         Assert.assertEquals("Wrong dl dst",\r
274                             null, etherMatch.getEthernetDestination());\r
275         Assert.assertEquals("Wrong dl type", dlType,\r
276                             etherMatch.getEthernetType().getType().getValue());\r
277         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
278         Assert.assertEquals("Wrong ip protocol",\r
279                             ipProto, ipMatch.getIpProtocol());\r
280         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
281         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
282         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
283         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
284         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
285         Assert.assertEquals("Wrong ICMPv4 match",\r
286                             null, salMatch.getIcmpv4Match());\r
287 \r
288         // Specify ICMPv4 type.\r
289         Short icmpType = 10;\r
290         match = builder.setTpSrc(icmpType.intValue()).build();\r
291         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
292                 match, dpid, OpenflowVersion.OF10).build();\r
293         etherMatch = salMatch.getEthernetMatch();\r
294         ipMatch = salMatch.getIpMatch();\r
295         Icmpv4Match icmpv4Match = salMatch.getIcmpv4Match();\r
296         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
297         Assert.assertEquals("Wrong dl src",\r
298                             null, etherMatch.getEthernetSource());\r
299         Assert.assertEquals("Wrong dl dst",\r
300                             null, etherMatch.getEthernetDestination());\r
301         Assert.assertEquals("Wrong dl type", dlType,\r
302                             etherMatch.getEthernetType().getType().getValue());\r
303         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
304         Assert.assertEquals("Wrong ip protocol",\r
305                             ipProto, ipMatch.getIpProtocol());\r
306         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
307         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
308         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
309         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
310         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
311         Assert.assertEquals("Wrong ICMPv4 type",\r
312                             icmpType, icmpv4Match.getIcmpv4Type());\r
313         Assert.assertEquals("Wrong ICMPv4 code",\r
314                             null, icmpv4Match.getIcmpv4Code());\r
315 \r
316         // TP_DST is not wildcarded but null.\r
317         wc = new FlowWildcardsV10(\r
318             true, true, false, true, true, true, false, true, false, false);\r
319         match = builder.setWildcards(wc).build();\r
320         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
321                 match, dpid, OpenflowVersion.OF10).build();\r
322         etherMatch = salMatch.getEthernetMatch();\r
323         ipMatch = salMatch.getIpMatch();\r
324         icmpv4Match = salMatch.getIcmpv4Match();\r
325         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
326         Assert.assertEquals("Wrong dl src",\r
327                             null, etherMatch.getEthernetSource());\r
328         Assert.assertEquals("Wrong dl dst",\r
329                             null, etherMatch.getEthernetDestination());\r
330         Assert.assertEquals("Wrong dl type", dlType,\r
331                             etherMatch.getEthernetType().getType().getValue());\r
332         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
333         Assert.assertEquals("Wrong ip protocol",\r
334                             ipProto, ipMatch.getIpProtocol());\r
335         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
336         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
337         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
338         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
339         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
340         Assert.assertEquals("Wrong ICMPv4 type",\r
341                             icmpType, icmpv4Match.getIcmpv4Type());\r
342         Assert.assertEquals("Wrong ICMPv4 code",\r
343                             null, icmpv4Match.getIcmpv4Code());\r
344 \r
345         // Specify ICMPv4 code only.\r
346         Short icmpCode = 33;\r
347         match = builder.setTpSrc(null).setTpDst(icmpCode.intValue()).build();\r
348         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
349                 match, dpid, OpenflowVersion.OF10).build();\r
350         etherMatch = salMatch.getEthernetMatch();\r
351         ipMatch = salMatch.getIpMatch();\r
352         icmpv4Match = salMatch.getIcmpv4Match();\r
353         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
354         Assert.assertEquals("Wrong dl src",\r
355                             null, etherMatch.getEthernetSource());\r
356         Assert.assertEquals("Wrong dl dst",\r
357                             null, etherMatch.getEthernetDestination());\r
358         Assert.assertEquals("Wrong dl type", dlType,\r
359                             etherMatch.getEthernetType().getType().getValue());\r
360         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
361         Assert.assertEquals("Wrong ip protocol",\r
362                             ipProto, ipMatch.getIpProtocol());\r
363         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
364         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
365         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
366         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
367         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
368         Assert.assertEquals("Wrong ICMPv4 type",\r
369                             null, icmpv4Match.getIcmpv4Type());\r
370         Assert.assertEquals("Wrong ICMPv4 code",\r
371                             icmpCode, icmpv4Match.getIcmpv4Code());\r
372 \r
373         // Specify both ICMPv4 type and code.\r
374         icmpType = 0;\r
375         icmpCode = 8;\r
376         match = builder.setTpSrc(icmpType.intValue()).\r
377             setTpDst(icmpCode.intValue()).build();\r
378         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
379                 match, dpid, OpenflowVersion.OF10).build();\r
380         etherMatch = salMatch.getEthernetMatch();\r
381         ipMatch = salMatch.getIpMatch();\r
382         icmpv4Match = salMatch.getIcmpv4Match();\r
383         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
384         Assert.assertEquals("Wrong dl src",\r
385                             null, etherMatch.getEthernetSource());\r
386         Assert.assertEquals("Wrong dl dst",\r
387                             null, etherMatch.getEthernetDestination());\r
388         Assert.assertEquals("Wrong dl type", dlType,\r
389                             etherMatch.getEthernetType().getType().getValue());\r
390         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
391         Assert.assertEquals("Wrong ip protocol",\r
392                             ipProto, ipMatch.getIpProtocol());\r
393         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
394         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
395         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
396         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
397         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
398         Assert.assertEquals("Wrong ICMPv4 type",\r
399                             icmpType, icmpv4Match.getIcmpv4Type());\r
400         Assert.assertEquals("Wrong ICMPv4 code",\r
401                             icmpCode, icmpv4Match.getIcmpv4Code());\r
402     }\r
403 \r
404     /**\r
405      * TCP match test for\r
406      * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
407      */\r
408     @Test\r
409     public void testTcpMatch() {\r
410         // TP_SRC, TP_DST are wildcarded.\r
411         // NW_PROTO is not wildcarded but null.\r
412         Long dlType = 0x800L;\r
413         FlowWildcardsV10 wc = new FlowWildcardsV10(\r
414             true, true, false, true, true, true, false, true, true, true);\r
415         MatchV10Builder builder = new MatchV10Builder().\r
416             setWildcards(wc).\r
417             setDlType(dlType.intValue());\r
418         MatchV10 match = builder.build();\r
419 \r
420         BigInteger dpid = BigInteger.valueOf(12345L);\r
421         Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
422                 match, dpid, OpenflowVersion.OF10).build();\r
423         EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
424         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
425         Assert.assertEquals("Wrong dl src",\r
426                             null, etherMatch.getEthernetSource());\r
427         Assert.assertEquals("Wrong dl dst",\r
428                             null, etherMatch.getEthernetDestination());\r
429         Assert.assertEquals("Wrong dl type", dlType,\r
430                             etherMatch.getEthernetType().getType().getValue());\r
431         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
432         Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());\r
433         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
434         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
435         Assert.assertEquals("Wrong ICMPv4 match",\r
436                             null, salMatch.getIcmpv4Match());\r
437 \r
438         // Specify TCP protocol.\r
439         Short ipProto = 6;\r
440         match = builder.setNwProto(ipProto).build();\r
441         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
442                 match, dpid, OpenflowVersion.OF10).build();\r
443         etherMatch = salMatch.getEthernetMatch();\r
444         IpMatch ipMatch = salMatch.getIpMatch();\r
445         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
446         Assert.assertEquals("Wrong dl src",\r
447                             null, etherMatch.getEthernetSource());\r
448         Assert.assertEquals("Wrong dl dst",\r
449                             null, etherMatch.getEthernetDestination());\r
450         Assert.assertEquals("Wrong dl type", dlType,\r
451                             etherMatch.getEthernetType().getType().getValue());\r
452         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
453         Assert.assertEquals("Wrong ip protocol",\r
454                             ipProto, ipMatch.getIpProtocol());\r
455         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
456         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
457         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
458         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
459         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
460         Assert.assertEquals("Wrong ICMPv4 match",\r
461                             null, salMatch.getIcmpv4Match());\r
462 \r
463         // TP_SRC is not wildcarded but null.\r
464         wc = new FlowWildcardsV10(\r
465             true, true, false, true, true, true, false, true, true, false);\r
466         match = builder.setWildcards(wc).build();\r
467         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
468                 match, dpid, OpenflowVersion.OF10).build();\r
469         etherMatch = salMatch.getEthernetMatch();\r
470         ipMatch = salMatch.getIpMatch();\r
471         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
472         Assert.assertEquals("Wrong dl src",\r
473                             null, etherMatch.getEthernetSource());\r
474         Assert.assertEquals("Wrong dl dst",\r
475                             null, etherMatch.getEthernetDestination());\r
476         Assert.assertEquals("Wrong dl type", dlType,\r
477                             etherMatch.getEthernetType().getType().getValue());\r
478         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
479         Assert.assertEquals("Wrong ip protocol",\r
480                             ipProto, ipMatch.getIpProtocol());\r
481         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
482         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
483         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
484         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
485         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
486         Assert.assertEquals("Wrong ICMPv4 match",\r
487                             null, salMatch.getIcmpv4Match());\r
488 \r
489         // Specify TCP source port.\r
490         Integer srcPort = 60000;\r
491         match = builder.setTpSrc(srcPort).build();\r
492         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
493                 match, dpid, OpenflowVersion.OF10).build();\r
494         etherMatch = salMatch.getEthernetMatch();\r
495         ipMatch = salMatch.getIpMatch();\r
496         TcpMatch tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
497         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
498         Assert.assertEquals("Wrong dl src",\r
499                             null, etherMatch.getEthernetSource());\r
500         Assert.assertEquals("Wrong dl dst",\r
501                             null, etherMatch.getEthernetDestination());\r
502         Assert.assertEquals("Wrong dl type", dlType,\r
503                             etherMatch.getEthernetType().getType().getValue());\r
504         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
505         Assert.assertEquals("Wrong ip protocol",\r
506                             ipProto, ipMatch.getIpProtocol());\r
507         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
508         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
509         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
510         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
511         Assert.assertEquals("Wrong TCP src", srcPort,\r
512                             tcpMatch.getTcpSourcePort().getValue());\r
513         Assert.assertEquals("Wrong TCP dst", null,\r
514                             tcpMatch.getTcpDestinationPort());\r
515         Assert.assertEquals("Wrong ICMPv4 match",\r
516                             null, salMatch.getIcmpv4Match());\r
517 \r
518         // TP_DST is not wildcarded but null.\r
519         wc = new FlowWildcardsV10(\r
520             true, true, false, true, true, true, false, true, false, false);\r
521         match = builder.setWildcards(wc).build();\r
522         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
523                 match, dpid, OpenflowVersion.OF10).build();\r
524         etherMatch = salMatch.getEthernetMatch();\r
525         ipMatch = salMatch.getIpMatch();\r
526         tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
527         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
528         Assert.assertEquals("Wrong dl src",\r
529                             null, etherMatch.getEthernetSource());\r
530         Assert.assertEquals("Wrong dl dst",\r
531                             null, etherMatch.getEthernetDestination());\r
532         Assert.assertEquals("Wrong dl type", dlType,\r
533                             etherMatch.getEthernetType().getType().getValue());\r
534         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
535         Assert.assertEquals("Wrong ip protocol",\r
536                             ipProto, ipMatch.getIpProtocol());\r
537         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
538         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
539         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
540         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
541         Assert.assertEquals("Wrong TCP src", srcPort,\r
542                             tcpMatch.getTcpSourcePort().getValue());\r
543         Assert.assertEquals("Wrong TCP dst", null,\r
544                             tcpMatch.getTcpDestinationPort());\r
545         Assert.assertEquals("Wrong ICMPv4 match",\r
546                             null, salMatch.getIcmpv4Match());\r
547 \r
548         // Specify TCP destination port only.\r
549         Integer dstPort = 6653;\r
550         match = builder.setTpSrc(null).setTpDst(dstPort).build();\r
551         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
552                 match, dpid, OpenflowVersion.OF10).build();\r
553         etherMatch = salMatch.getEthernetMatch();\r
554         ipMatch = salMatch.getIpMatch();\r
555         tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
556         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
557         Assert.assertEquals("Wrong dl src",\r
558                             null, etherMatch.getEthernetSource());\r
559         Assert.assertEquals("Wrong dl dst",\r
560                             null, etherMatch.getEthernetDestination());\r
561         Assert.assertEquals("Wrong dl type", dlType,\r
562                             etherMatch.getEthernetType().getType().getValue());\r
563         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
564         Assert.assertEquals("Wrong ip protocol",\r
565                             ipProto, ipMatch.getIpProtocol());\r
566         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
567         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
568         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
569         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
570         Assert.assertEquals("Wrong TCP src", null,\r
571                             tcpMatch.getTcpSourcePort());\r
572         Assert.assertEquals("Wrong TCP dst", dstPort,\r
573                             tcpMatch.getTcpDestinationPort().getValue());\r
574         Assert.assertEquals("Wrong ICMPv4 match",\r
575                             null, salMatch.getIcmpv4Match());\r
576 \r
577         // Specify both source and destination port.\r
578         srcPort = 32767;\r
579         dstPort = 9999;\r
580         match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();\r
581         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
582                 match, dpid, OpenflowVersion.OF10).build();\r
583         etherMatch = salMatch.getEthernetMatch();\r
584         ipMatch = salMatch.getIpMatch();\r
585         tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
586         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
587         Assert.assertEquals("Wrong dl src",\r
588                             null, etherMatch.getEthernetSource());\r
589         Assert.assertEquals("Wrong dl dst",\r
590                             null, etherMatch.getEthernetDestination());\r
591         Assert.assertEquals("Wrong dl type", dlType,\r
592                             etherMatch.getEthernetType().getType().getValue());\r
593         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
594         Assert.assertEquals("Wrong ip protocol",\r
595                             ipProto, ipMatch.getIpProtocol());\r
596         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
597         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
598         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
599         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
600         Assert.assertEquals("Wrong TCP src", srcPort,\r
601                             tcpMatch.getTcpSourcePort().getValue());\r
602         Assert.assertEquals("Wrong TCP dst", dstPort,\r
603                             tcpMatch.getTcpDestinationPort().getValue());\r
604         Assert.assertEquals("Wrong ICMPv4 match",\r
605                             null, salMatch.getIcmpv4Match());\r
606     }\r
607 \r
608     /**\r
609      * UDP match test for\r
610      * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
611      */\r
612     @Test\r
613     public void testUdpMatch() {\r
614         // TP_SRC, TP_DST are wildcarded.\r
615         // NW_PROTO is not wildcarded but null.\r
616         Long dlType = 0x800L;\r
617         FlowWildcardsV10 wc = new FlowWildcardsV10(\r
618             true, true, false, true, true, true, false, true, true, true);\r
619         MatchV10Builder builder = new MatchV10Builder().\r
620             setWildcards(wc).\r
621             setDlType(dlType.intValue());\r
622         MatchV10 match = builder.build();\r
623 \r
624         BigInteger dpid = BigInteger.valueOf(12345L);\r
625         Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
626                 match, dpid, OpenflowVersion.OF10).build();\r
627         EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
628         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
629         Assert.assertEquals("Wrong dl src",\r
630                             null, etherMatch.getEthernetSource());\r
631         Assert.assertEquals("Wrong dl dst",\r
632                             null, etherMatch.getEthernetDestination());\r
633         Assert.assertEquals("Wrong dl type", dlType,\r
634                             etherMatch.getEthernetType().getType().getValue());\r
635         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
636         Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());\r
637         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
638         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
639         Assert.assertEquals("Wrong ICMPv4 match",\r
640                             null, salMatch.getIcmpv4Match());\r
641 \r
642         // Specify UDP protocol.\r
643         Short ipProto = 17;\r
644         match = builder.setNwProto(ipProto).build();\r
645         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
646                 match, dpid, OpenflowVersion.OF10).build();\r
647         etherMatch = salMatch.getEthernetMatch();\r
648         IpMatch ipMatch = salMatch.getIpMatch();\r
649         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
650         Assert.assertEquals("Wrong dl src",\r
651                             null, etherMatch.getEthernetSource());\r
652         Assert.assertEquals("Wrong dl dst",\r
653                             null, etherMatch.getEthernetDestination());\r
654         Assert.assertEquals("Wrong dl type", dlType,\r
655                             etherMatch.getEthernetType().getType().getValue());\r
656         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
657         Assert.assertEquals("Wrong ip protocol",\r
658                             ipProto, ipMatch.getIpProtocol());\r
659         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
660         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
661         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
662         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
663         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
664         Assert.assertEquals("Wrong ICMPv4 match",\r
665                             null, salMatch.getIcmpv4Match());\r
666 \r
667         // TP_SRC is not wildcarded but null.\r
668         wc = new FlowWildcardsV10(\r
669             true, true, false, true, true, true, false, true, true, false);\r
670         match = builder.setWildcards(wc).build();\r
671         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
672                 match, dpid, OpenflowVersion.OF10).build();\r
673         etherMatch = salMatch.getEthernetMatch();\r
674         ipMatch = salMatch.getIpMatch();\r
675         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
676         Assert.assertEquals("Wrong dl src",\r
677                             null, etherMatch.getEthernetSource());\r
678         Assert.assertEquals("Wrong dl dst",\r
679                             null, etherMatch.getEthernetDestination());\r
680         Assert.assertEquals("Wrong dl type", dlType,\r
681                             etherMatch.getEthernetType().getType().getValue());\r
682         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
683         Assert.assertEquals("Wrong ip protocol",\r
684                             ipProto, ipMatch.getIpProtocol());\r
685         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
686         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
687         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
688         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
689         Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());\r
690         Assert.assertEquals("Wrong ICMPv4 match",\r
691                             null, salMatch.getIcmpv4Match());\r
692 \r
693         // Specify UDP source port.\r
694         Integer srcPort = 60000;\r
695         match = builder.setTpSrc(srcPort).build();\r
696         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
697                 match, dpid, OpenflowVersion.OF10).build();\r
698         etherMatch = salMatch.getEthernetMatch();\r
699         ipMatch = salMatch.getIpMatch();\r
700         UdpMatch udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
701         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
702         Assert.assertEquals("Wrong dl src",\r
703                             null, etherMatch.getEthernetSource());\r
704         Assert.assertEquals("Wrong dl dst",\r
705                             null, etherMatch.getEthernetDestination());\r
706         Assert.assertEquals("Wrong dl type", dlType,\r
707                             etherMatch.getEthernetType().getType().getValue());\r
708         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
709         Assert.assertEquals("Wrong ip protocol",\r
710                             ipProto, ipMatch.getIpProtocol());\r
711         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
712         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
713         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
714         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
715         Assert.assertEquals("Wrong UDP src", srcPort,\r
716                             udpMatch.getUdpSourcePort().getValue());\r
717         Assert.assertEquals("Wrong UDP dst", null,\r
718                             udpMatch.getUdpDestinationPort());\r
719         Assert.assertEquals("Wrong ICMPv4 match",\r
720                             null, salMatch.getIcmpv4Match());\r
721 \r
722         // TP_DST is not wildcarded but null.\r
723         wc = new FlowWildcardsV10(\r
724             true, true, false, true, true, true, false, true, false, false);\r
725         match = builder.setWildcards(wc).build();\r
726         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
727                 match, dpid, OpenflowVersion.OF10).build();\r
728         etherMatch = salMatch.getEthernetMatch();\r
729         ipMatch = salMatch.getIpMatch();\r
730         udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
731         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
732         Assert.assertEquals("Wrong dl src",\r
733                             null, etherMatch.getEthernetSource());\r
734         Assert.assertEquals("Wrong dl dst",\r
735                             null, etherMatch.getEthernetDestination());\r
736         Assert.assertEquals("Wrong dl type", dlType,\r
737                             etherMatch.getEthernetType().getType().getValue());\r
738         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
739         Assert.assertEquals("Wrong ip protocol",\r
740                             ipProto, ipMatch.getIpProtocol());\r
741         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
742         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
743         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
744         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
745         Assert.assertEquals("Wrong UDP src", srcPort,\r
746                             udpMatch.getUdpSourcePort().getValue());\r
747         Assert.assertEquals("Wrong UDP dst", null,\r
748                             udpMatch.getUdpDestinationPort());\r
749         Assert.assertEquals("Wrong ICMPv4 match",\r
750                             null, salMatch.getIcmpv4Match());\r
751 \r
752         // Specify UDP destination port only.\r
753         Integer dstPort = 6653;\r
754         match = builder.setTpSrc(null).setTpDst(dstPort).build();\r
755         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
756                 match, dpid, OpenflowVersion.OF10).build();\r
757         etherMatch = salMatch.getEthernetMatch();\r
758         ipMatch = salMatch.getIpMatch();\r
759         udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
760         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
761         Assert.assertEquals("Wrong dl src",\r
762                             null, etherMatch.getEthernetSource());\r
763         Assert.assertEquals("Wrong dl dst",\r
764                             null, etherMatch.getEthernetDestination());\r
765         Assert.assertEquals("Wrong dl type", dlType,\r
766                             etherMatch.getEthernetType().getType().getValue());\r
767         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
768         Assert.assertEquals("Wrong ip protocol",\r
769                             ipProto, ipMatch.getIpProtocol());\r
770         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
771         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
772         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
773         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
774         Assert.assertEquals("Wrong UDP src", null,\r
775                             udpMatch.getUdpSourcePort());\r
776         Assert.assertEquals("Wrong UDP dst", dstPort,\r
777                             udpMatch.getUdpDestinationPort().getValue());\r
778         Assert.assertEquals("Wrong ICMPv4 match",\r
779                             null, salMatch.getIcmpv4Match());\r
780 \r
781         // Specify both source and destination port.\r
782         srcPort = 32767;\r
783         dstPort = 9999;\r
784         match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();\r
785         salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
786                 match, dpid, OpenflowVersion.OF10).build();\r
787         etherMatch = salMatch.getEthernetMatch();\r
788         ipMatch = salMatch.getIpMatch();\r
789         udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
790         Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
791         Assert.assertEquals("Wrong dl src",\r
792                             null, etherMatch.getEthernetSource());\r
793         Assert.assertEquals("Wrong dl dst",\r
794                             null, etherMatch.getEthernetDestination());\r
795         Assert.assertEquals("Wrong dl type", dlType,\r
796                             etherMatch.getEthernetType().getType().getValue());\r
797         Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());\r
798         Assert.assertEquals("Wrong ip protocol",\r
799                             ipProto, ipMatch.getIpProtocol());\r
800         Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());\r
801         Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());\r
802         Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());\r
803         Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());\r
804         Assert.assertEquals("Wrong UDP src", srcPort,\r
805                             udpMatch.getUdpSourcePort().getValue());\r
806         Assert.assertEquals("Wrong UDP dst", dstPort,\r
807                             udpMatch.getUdpDestinationPort().getValue());\r
808         Assert.assertEquals("Wrong ICMPv4 match",\r
809                             null, salMatch.getIcmpv4Match());\r
810     }\r
811 }\r