backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / integrated / test_add_flow_v12_matches.py
1 # Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # vim: tabstop=4 shiftwidth=4 softtabstop=4
17
18 import logging
19
20 from ryu.ofproto import ofproto_v1_2
21 from ryu.ofproto import ether
22 from ryu.ofproto import inet
23 from ryu.tests.integrated import tester
24
25 LOG = logging.getLogger(__name__)
26
27
28 class RunTest(tester.TestFlowBase):
29     """ Test case for add flows of Matches
30     """
31     OFP_VERSIONS = [ofproto_v1_2.OFP_VERSION]
32
33     def __init__(self, *args, **kwargs):
34         super(RunTest, self).__init__(*args, **kwargs)
35
36         self._verify = {}
37
38     def add_matches(self, dp, match):
39         m = dp.ofproto_parser.OFPFlowMod(dp, 0, 0, 0,
40                                          dp.ofproto.OFPFC_ADD,
41                                          0, 0, 0, 0xffffffff,
42                                          dp.ofproto.OFPP_ANY,
43                                          0xffffffff, 0, match, [])
44         dp.send_msg(m)
45
46     def _set_verify(self, headers, value, mask=None,
47                     all_bits_masked=False, type_='int'):
48         self._verify = {}
49         self._verify['headers'] = headers
50         self._verify['value'] = value
51         self._verify['mask'] = mask
52         self._verify['all_bits_masked'] = all_bits_masked
53         self._verify['type'] = type_
54
55     def verify_default(self, dp, stats):
56         type_ = self._verify['type']
57         headers = self._verify['headers']
58         value = self._verify['value']
59         mask = self._verify['mask']
60         value_masked = self._masked(type_, value, mask)
61         all_bits_masked = self._verify['all_bits_masked']
62
63         field = None
64         for s in stats:
65             for f in s.match.fields:
66                 if f.header in headers:
67                     field = f
68                     break
69
70         if field is None:
71             if self._is_all_zero_bit(type_, mask):
72                 return True
73             return 'Field not found.'
74
75         f_value = field.value
76         if hasattr(field, 'mask'):
77             f_mask = field.mask
78         else:
79             f_mask = None
80
81         if (f_value == value) or (f_value == value_masked):
82             if (f_mask == mask) or (all_bits_masked and f_mask is None):
83                 return True
84
85         return "send: %s/%s, reply: %s/%s" \
86             % (self._cnv_to_str(type_, value, mask, f_value, f_mask))
87
88     def _masked(self, type_, value, mask):
89         if mask is None:
90             v = value
91         elif type_ == 'int':
92             v = value & mask
93         elif type_ == 'mac':
94             v = self.haddr_masked(value, mask)
95         elif type_ == 'ipv4':
96             v = self.ipv4_masked(value, mask)
97         elif type_ == 'ipv6':
98             v = self.ipv6_masked(value, mask)
99         else:
100             raise Exception('Unknown type')
101         return v
102
103     def _is_all_zero_bit(self, type_, val):
104         if type_ == 'int' or type_ == 'ipv4':
105             return val == 0
106         elif type_ == 'mac':
107             for v in val:
108                 if v != b'\x00':
109                     return False
110             return True
111         elif type_ == 'ipv6':
112             for v in val:
113                 if v != 0:
114                     return False
115             return True
116         else:
117             raise Exception('Unknown type')
118
119     def _cnv_to_str(self, type_, value, mask, f_value, f_mask):
120         func = None
121         if type_ == 'int':
122             pass
123         elif type_ == 'mac':
124             func = self.haddr_to_str
125         elif type_ == 'ipv4':
126             func = self.ipv4_to_str
127         elif type_ == 'ipv6':
128             func = self.ipv6_to_str
129         else:
130             raise Exception('Unknown type')
131
132         if func:
133             value = func(value)
134             f_value = func(f_value)
135             if mask:
136                 mask = func(mask)
137             if f_mask:
138                 f_mask = func(f_mask)
139
140         return value, mask, f_value, f_mask
141
142     def test_rule_set_dl_dst(self, dp):
143         dl_dst = 'e2:7a:09:79:0b:0f'
144         dl_dst_bin = self.haddr_to_bin(dl_dst)
145
146         headers = [dp.ofproto.OXM_OF_ETH_DST, dp.ofproto.OXM_OF_ETH_DST_W]
147         self._set_verify(headers, dl_dst_bin, type_='mac')
148
149         match = dp.ofproto_parser.OFPMatch()
150         match.set_dl_dst(dl_dst_bin)
151         self.add_matches(dp, match)
152
153     def test_rule_set_dl_dst_masked_ff(self, dp):
154         dl_dst = 'd0:98:79:b4:75:b5'
155         dl_dst_bin = self.haddr_to_bin(dl_dst)
156         mask = 'ff:ff:ff:ff:ff:ff'
157         mask_bin = self.haddr_to_bin(mask)
158
159         headers = [dp.ofproto.OXM_OF_ETH_DST, dp.ofproto.OXM_OF_ETH_DST_W]
160         self._set_verify(headers, dl_dst_bin, mask_bin, True, type_='mac')
161
162         match = dp.ofproto_parser.OFPMatch()
163         match.set_dl_dst_masked(dl_dst_bin, mask_bin)
164         self.add_matches(dp, match)
165
166     def test_rule_set_dl_dst_masked_f0(self, dp):
167         dl_dst = 'e2:7a:09:79:0b:0f'
168         dl_dst_bin = self.haddr_to_bin(dl_dst)
169         mask = 'ff:ff:ff:ff:ff:00'
170         mask_bin = self.haddr_to_bin(mask)
171
172         headers = [dp.ofproto.OXM_OF_ETH_DST, dp.ofproto.OXM_OF_ETH_DST_W]
173         self._set_verify(headers, dl_dst_bin, mask_bin, type_='mac')
174
175         match = dp.ofproto_parser.OFPMatch()
176         match.set_dl_dst_masked(dl_dst_bin, mask_bin)
177         self.add_matches(dp, match)
178
179     def test_rule_set_dl_dst_masked_00(self, dp):
180         dl_dst = 'e2:7a:09:79:0b:0f'
181         dl_dst_bin = self.haddr_to_bin(dl_dst)
182         mask = '00:00:00:00:00:00'
183         mask_bin = self.haddr_to_bin(mask)
184
185         headers = [dp.ofproto.OXM_OF_ETH_DST, dp.ofproto.OXM_OF_ETH_DST_W]
186         self._set_verify(headers, dl_dst_bin, mask_bin, type_='mac')
187
188         match = dp.ofproto_parser.OFPMatch()
189         match.set_dl_dst_masked(dl_dst_bin, mask_bin)
190         self.add_matches(dp, match)
191
192     def test_rule_set_dl_src(self, dp):
193         dl_src = 'e2:7a:09:79:0b:0f'
194         dl_src_bin = self.haddr_to_bin(dl_src)
195
196         headers = [dp.ofproto.OXM_OF_ETH_SRC, dp.ofproto.OXM_OF_ETH_SRC_W]
197         self._set_verify(headers, dl_src_bin, type_='mac')
198
199         match = dp.ofproto_parser.OFPMatch()
200         match.set_dl_src(dl_src_bin)
201         self.add_matches(dp, match)
202
203     def test_rule_set_dl_src_masked_ff(self, dp):
204         dl_src = 'e2:7a:09:79:0b:0f'
205         dl_src_bin = self.haddr_to_bin(dl_src)
206         mask = 'ff:ff:ff:ff:ff:ff'
207         mask_bin = self.haddr_to_bin(mask)
208
209         headers = [dp.ofproto.OXM_OF_ETH_SRC, dp.ofproto.OXM_OF_ETH_SRC_W]
210         self._set_verify(headers, dl_src_bin, mask_bin, True, type_='mac')
211
212         match = dp.ofproto_parser.OFPMatch()
213         match.set_dl_src_masked(dl_src_bin, mask_bin)
214         self.add_matches(dp, match)
215
216     def test_rule_set_dl_src_masked_f0(self, dp):
217         dl_src = 'e2:7a:09:79:0b:0f'
218         dl_src_bin = self.haddr_to_bin(dl_src)
219         mask = 'ff:ff:ff:ff:ff:00'
220         mask_bin = self.haddr_to_bin(mask)
221
222         headers = [dp.ofproto.OXM_OF_ETH_SRC, dp.ofproto.OXM_OF_ETH_SRC_W]
223         self._set_verify(headers, dl_src_bin, mask_bin, type_='mac')
224
225         match = dp.ofproto_parser.OFPMatch()
226         match.set_dl_src_masked(dl_src_bin, mask_bin)
227         self.add_matches(dp, match)
228
229     def test_rule_set_dl_src_masked_00(self, dp):
230         dl_src = 'e2:7a:09:79:0b:0f'
231         dl_src_bin = self.haddr_to_bin(dl_src)
232         mask = '00:00:00:00:00:00'
233         mask_bin = self.haddr_to_bin(mask)
234
235         headers = [dp.ofproto.OXM_OF_ETH_SRC, dp.ofproto.OXM_OF_ETH_SRC_W]
236         self._set_verify(headers, dl_src_bin, mask_bin, type_='mac')
237
238         match = dp.ofproto_parser.OFPMatch()
239         match.set_dl_src_masked(dl_src_bin, mask_bin)
240         self.add_matches(dp, match)
241
242     def test_rule_set_dl_type_ip(self, dp):
243         dl_type = ether.ETH_TYPE_IP
244
245         headers = [dp.ofproto.OXM_OF_ETH_TYPE]
246         self._set_verify(headers, dl_type)
247
248         match = dp.ofproto_parser.OFPMatch()
249         match.set_dl_type(dl_type)
250         self.add_matches(dp, match)
251
252     def test_rule_set_dl_type_arp(self, dp):
253         dl_type = ether.ETH_TYPE_ARP
254
255         headers = [dp.ofproto.OXM_OF_ETH_TYPE]
256         self._set_verify(headers, dl_type)
257
258         match = dp.ofproto_parser.OFPMatch()
259         match.set_dl_type(dl_type)
260         self.add_matches(dp, match)
261
262     def test_rule_set_dl_type_vlan(self, dp):
263         dl_type = ether.ETH_TYPE_8021Q
264
265         headers = [dp.ofproto.OXM_OF_ETH_TYPE]
266         self._set_verify(headers, dl_type)
267
268         match = dp.ofproto_parser.OFPMatch()
269         match.set_dl_type(dl_type)
270         self.add_matches(dp, match)
271
272     def test_rule_set_dl_type_ipv6(self, dp):
273         dl_type = ether.ETH_TYPE_IPV6
274
275         headers = [dp.ofproto.OXM_OF_ETH_TYPE]
276         self._set_verify(headers, dl_type)
277
278         match = dp.ofproto_parser.OFPMatch()
279         match.set_dl_type(dl_type)
280         self.add_matches(dp, match)
281
282     def test_rule_set_dl_type_lacp(self, dp):
283         dl_type = ether.ETH_TYPE_SLOW
284
285         headers = [dp.ofproto.OXM_OF_ETH_TYPE]
286         self._set_verify(headers, dl_type)
287
288         match = dp.ofproto_parser.OFPMatch()
289         match.set_dl_type(dl_type)
290         self.add_matches(dp, match)
291
292     def test_rule_set_ip_dscp(self, dp):
293         ip_dscp = 36
294         dl_type = ether.ETH_TYPE_IP
295
296         headers = [dp.ofproto.OXM_OF_IP_DSCP]
297         self._set_verify(headers, ip_dscp)
298
299         match = dp.ofproto_parser.OFPMatch()
300         match.set_dl_type(dl_type)
301         match.set_ip_dscp(ip_dscp)
302         self.add_matches(dp, match)
303
304     def test_rule_set_vlan_vid(self, dp):
305         vlan_vid = 0x4ef
306
307         headers = [dp.ofproto.OXM_OF_VLAN_VID, dp.ofproto.OXM_OF_VLAN_VID_W]
308         self._set_verify(headers, vlan_vid)
309
310         match = dp.ofproto_parser.OFPMatch()
311         match.set_vlan_vid(vlan_vid)
312         self.add_matches(dp, match)
313
314     def test_rule_set_vlan_vid_masked_ff(self, dp):
315         vlan_vid = 0x4ef
316         mask = 0xfff
317
318         headers = [dp.ofproto.OXM_OF_VLAN_VID, dp.ofproto.OXM_OF_VLAN_VID_W]
319         self._set_verify(headers, vlan_vid, mask, True)
320
321         match = dp.ofproto_parser.OFPMatch()
322         match.set_vlan_vid_masked(vlan_vid, mask)
323         self.add_matches(dp, match)
324
325     def test_rule_set_vlan_vid_masked_f0(self, dp):
326         vlan_vid = 0x4ef
327         mask = 0xff0
328
329         headers = [dp.ofproto.OXM_OF_VLAN_VID, dp.ofproto.OXM_OF_VLAN_VID_W]
330         self._set_verify(headers, vlan_vid, mask)
331
332         match = dp.ofproto_parser.OFPMatch()
333         match.set_vlan_vid_masked(vlan_vid, mask)
334         self.add_matches(dp, match)
335
336     def test_rule_set_vlan_vid_masked_00(self, dp):
337         vlan_vid = 0x4ef
338         mask = 0x000
339
340         headers = [dp.ofproto.OXM_OF_VLAN_VID, dp.ofproto.OXM_OF_VLAN_VID_W]
341         self._set_verify(headers, vlan_vid, mask)
342
343         match = dp.ofproto_parser.OFPMatch()
344         match.set_vlan_vid_masked(vlan_vid, mask)
345         self.add_matches(dp, match)
346
347     def test_rule_set_vlan_pcp(self, dp):
348         vlan_vid = 0x4ef
349         vlan_pcp = 5
350
351         headers = [dp.ofproto.OXM_OF_VLAN_PCP]
352         self._set_verify(headers, vlan_pcp)
353
354         match = dp.ofproto_parser.OFPMatch()
355         match.set_vlan_vid(vlan_vid)
356         match.set_vlan_pcp(vlan_pcp)
357         self.add_matches(dp, match)
358
359     def test_rule_set_ip_ecn(self, dp):
360         dl_type = ether.ETH_TYPE_IP
361         ip_ecn = 3
362
363         headers = [dp.ofproto.OXM_OF_IP_ECN]
364         self._set_verify(headers, ip_ecn)
365
366         match = dp.ofproto_parser.OFPMatch()
367         match.set_dl_type(dl_type)
368         match.set_ip_ecn(ip_ecn)
369         self.add_matches(dp, match)
370
371     def test_rule_set_ip_proto_icmp(self, dp):
372         dl_type = ether.ETH_TYPE_IP
373         ip_proto = inet.IPPROTO_ICMP
374
375         headers = [dp.ofproto.OXM_OF_IP_PROTO]
376         self._set_verify(headers, ip_proto)
377
378         match = dp.ofproto_parser.OFPMatch()
379         match.set_dl_type(dl_type)
380         match.set_ip_proto(ip_proto)
381         self.add_matches(dp, match)
382
383     def test_rule_set_ip_proto_tcp(self, dp):
384         dl_type = ether.ETH_TYPE_IP
385         ip_proto = inet.IPPROTO_TCP
386
387         headers = [dp.ofproto.OXM_OF_IP_PROTO]
388         self._set_verify(headers, ip_proto)
389
390         match = dp.ofproto_parser.OFPMatch()
391         match.set_dl_type(dl_type)
392         match.set_ip_proto(ip_proto)
393         self.add_matches(dp, match)
394
395     def test_rule_set_ip_proto_udp(self, dp):
396         dl_type = ether.ETH_TYPE_IP
397         ip_proto = inet.IPPROTO_UDP
398
399         headers = [dp.ofproto.OXM_OF_IP_PROTO]
400         self._set_verify(headers, ip_proto)
401
402         match = dp.ofproto_parser.OFPMatch()
403         match.set_dl_type(dl_type)
404         match.set_ip_proto(ip_proto)
405         self.add_matches(dp, match)
406
407     def test_rule_set_ip_proto_ipv6_route(self, dp):
408         dl_type = ether.ETH_TYPE_IPV6
409         ip_proto = inet.IPPROTO_ROUTING
410
411         headers = [dp.ofproto.OXM_OF_IP_PROTO]
412         self._set_verify(headers, ip_proto)
413
414         match = dp.ofproto_parser.OFPMatch()
415         match.set_dl_type(dl_type)
416         match.set_ip_proto(ip_proto)
417         self.add_matches(dp, match)
418
419     def test_rule_set_ip_proto_ipv6_frag(self, dp):
420         dl_type = ether.ETH_TYPE_IPV6
421         ip_proto = inet.IPPROTO_FRAGMENT
422
423         headers = [dp.ofproto.OXM_OF_IP_PROTO]
424         self._set_verify(headers, ip_proto)
425
426         match = dp.ofproto_parser.OFPMatch()
427         match.set_dl_type(dl_type)
428         match.set_ip_proto(ip_proto)
429         self.add_matches(dp, match)
430
431     def test_rule_set_ip_proto_ipv6_icmp(self, dp):
432         dl_type = ether.ETH_TYPE_IPV6
433         ip_proto = inet.IPPROTO_ICMPV6
434
435         headers = [dp.ofproto.OXM_OF_IP_PROTO]
436         self._set_verify(headers, ip_proto)
437
438         match = dp.ofproto_parser.OFPMatch()
439         match.set_dl_type(dl_type)
440         match.set_ip_proto(ip_proto)
441         self.add_matches(dp, match)
442
443     def test_rule_set_ip_proto_ipv6_none(self, dp):
444         dl_type = ether.ETH_TYPE_IPV6
445         ip_proto = inet.IPPROTO_NONE
446
447         headers = [dp.ofproto.OXM_OF_IP_PROTO]
448         self._set_verify(headers, ip_proto)
449
450         match = dp.ofproto_parser.OFPMatch()
451         match.set_dl_type(dl_type)
452         match.set_ip_proto(ip_proto)
453         self.add_matches(dp, match)
454
455     def test_rule_set_ip_proto_ipv6_dstopts(self, dp):
456         dl_type = ether.ETH_TYPE_IPV6
457         ip_proto = inet.IPPROTO_DSTOPTS
458
459         headers = [dp.ofproto.OXM_OF_IP_PROTO]
460         self._set_verify(headers, ip_proto)
461
462         match = dp.ofproto_parser.OFPMatch()
463         match.set_dl_type(dl_type)
464         match.set_ip_proto(ip_proto)
465         self.add_matches(dp, match)
466
467     def test_rule_set_ipv4_src(self, dp):
468         dl_type = ether.ETH_TYPE_IP
469         src = '192.168.196.250'
470         src_int = self.ipv4_to_int(src)
471
472         headers = [dp.ofproto.OXM_OF_IPV4_SRC, dp.ofproto.OXM_OF_IPV4_SRC_W]
473         self._set_verify(headers, src_int, type_='ipv4')
474
475         match = dp.ofproto_parser.OFPMatch()
476         match.set_dl_type(dl_type)
477         match.set_ipv4_src(src_int)
478         self.add_matches(dp, match)
479
480     def test_rule_set_ipv4_src_masked_32(self, dp):
481         dl_type = ether.ETH_TYPE_IP
482         src = '192.168.196.250'
483         src_int = self.ipv4_to_int(src)
484         mask = '255.255.255.255'
485         mask_int = self.ipv4_to_int(mask)
486
487         headers = [dp.ofproto.OXM_OF_IPV4_SRC, dp.ofproto.OXM_OF_IPV4_SRC_W]
488         self._set_verify(headers, src_int, mask_int, True, type_='ipv4')
489
490         match = dp.ofproto_parser.OFPMatch()
491         match.set_dl_type(dl_type)
492         match.set_ipv4_src_masked(src_int, mask_int)
493         self.add_matches(dp, match)
494
495     def test_rule_set_ipv4_src_masked_24(self, dp):
496         dl_type = ether.ETH_TYPE_IP
497         src = '192.168.196.250'
498         src_int = self.ipv4_to_int(src)
499         mask = '255.255.255.0'
500         mask_int = self.ipv4_to_int(mask)
501
502         headers = [dp.ofproto.OXM_OF_IPV4_SRC, dp.ofproto.OXM_OF_IPV4_SRC_W]
503         self._set_verify(headers, src_int, mask_int, type_='ipv4')
504
505         match = dp.ofproto_parser.OFPMatch()
506         match.set_dl_type(dl_type)
507         match.set_ipv4_src_masked(src_int, mask_int)
508         self.add_matches(dp, match)
509
510     def test_rule_set_ipv4_src_masked_0(self, dp):
511         dl_type = ether.ETH_TYPE_IP
512         src = '192.168.196.250'
513         src_int = self.ipv4_to_int(src)
514         mask = '0.0.0.0'
515         mask_int = self.ipv4_to_int(mask)
516
517         headers = [dp.ofproto.OXM_OF_IPV4_SRC, dp.ofproto.OXM_OF_IPV4_SRC_W]
518         self._set_verify(headers, src_int, mask_int, type_='ipv4')
519
520         match = dp.ofproto_parser.OFPMatch()
521         match.set_dl_type(dl_type)
522         match.set_ipv4_src_masked(src_int, mask_int)
523         self.add_matches(dp, match)
524
525     def test_rule_set_ipv4_dst(self, dp):
526         dl_type = ether.ETH_TYPE_IP
527         dst = '192.168.54.155'
528         dst_int = self.ipv4_to_int(dst)
529
530         headers = [dp.ofproto.OXM_OF_IPV4_DST, dp.ofproto.OXM_OF_IPV4_DST_W]
531         self._set_verify(headers, dst_int, type_='ipv4')
532
533         match = dp.ofproto_parser.OFPMatch()
534         match.set_dl_type(dl_type)
535         match.set_ipv4_dst(dst_int)
536         self.add_matches(dp, match)
537
538     def test_rule_set_ipv4_dst_masked_32(self, dp):
539         dl_type = ether.ETH_TYPE_IP
540         dst = '192.168.54.155'
541         dst_int = self.ipv4_to_int(dst)
542         mask = '255.255.255.255'
543         mask_int = self.ipv4_to_int(mask)
544
545         headers = [dp.ofproto.OXM_OF_IPV4_DST, dp.ofproto.OXM_OF_IPV4_DST_W]
546         self._set_verify(headers, dst_int, mask_int, True, type_='ipv4')
547
548         match = dp.ofproto_parser.OFPMatch()
549         match.set_dl_type(dl_type)
550         match.set_ipv4_dst_masked(dst_int, mask_int)
551         self.add_matches(dp, match)
552
553     def test_rule_set_ipv4_dst_masked_24(self, dp):
554         dl_type = ether.ETH_TYPE_IP
555         dst = '192.168.54.155'
556         dst_int = self.ipv4_to_int(dst)
557         mask = '255.255.255.0'
558         mask_int = self.ipv4_to_int(mask)
559
560         headers = [dp.ofproto.OXM_OF_IPV4_DST, dp.ofproto.OXM_OF_IPV4_DST_W]
561         self._set_verify(headers, dst_int, mask_int, type_='ipv4')
562
563         match = dp.ofproto_parser.OFPMatch()
564         match.set_dl_type(dl_type)
565         match.set_ipv4_dst_masked(dst_int, mask_int)
566         self.add_matches(dp, match)
567
568     def test_rule_set_ipv4_dst_masked_0(self, dp):
569         dl_type = ether.ETH_TYPE_IP
570         dst = '192.168.54.155'
571         dst_int = self.ipv4_to_int(dst)
572         mask = '0.0.0.0'
573         mask_int = self.ipv4_to_int(mask)
574
575         headers = [dp.ofproto.OXM_OF_IPV4_DST, dp.ofproto.OXM_OF_IPV4_DST_W]
576         self._set_verify(headers, dst_int, mask_int, type_='ipv4')
577
578         match = dp.ofproto_parser.OFPMatch()
579         match.set_dl_type(dl_type)
580         match.set_ipv4_dst_masked(dst_int, mask_int)
581         self.add_matches(dp, match)
582
583     def test_rule_set_tcp_src(self, dp):
584         dl_type = ether.ETH_TYPE_IP
585         ip_proto = inet.IPPROTO_TCP
586         tp_src = 1103
587
588         headers = [dp.ofproto.OXM_OF_TCP_SRC]
589         self._set_verify(headers, tp_src)
590
591         match = dp.ofproto_parser.OFPMatch()
592         match.set_dl_type(dl_type)
593         match.set_ip_proto(ip_proto)
594         match.set_tcp_src(tp_src)
595         self.add_matches(dp, match)
596
597     def test_rule_set_tcp_dst(self, dp):
598         dl_type = ether.ETH_TYPE_IP
599         ip_proto = inet.IPPROTO_TCP
600         tp_dst = 236
601
602         headers = [dp.ofproto.OXM_OF_TCP_DST]
603         self._set_verify(headers, tp_dst)
604
605         match = dp.ofproto_parser.OFPMatch()
606         match.set_dl_type(dl_type)
607         match.set_ip_proto(ip_proto)
608         match.set_tcp_dst(tp_dst)
609         self.add_matches(dp, match)
610
611     def test_rule_set_udp_src(self, dp):
612         dl_type = ether.ETH_TYPE_IP
613         ip_proto = inet.IPPROTO_UDP
614         tp_src = 56617
615
616         headers = [dp.ofproto.OXM_OF_UDP_SRC]
617         self._set_verify(headers, tp_src)
618
619         match = dp.ofproto_parser.OFPMatch()
620         match.set_dl_type(dl_type)
621         match.set_ip_proto(ip_proto)
622         match.set_udp_src(tp_src)
623         self.add_matches(dp, match)
624
625     def test_rule_set_udp_dst(self, dp):
626         dl_type = ether.ETH_TYPE_IP
627         ip_proto = inet.IPPROTO_UDP
628         tp_dst = 61278
629
630         headers = [dp.ofproto.OXM_OF_UDP_DST]
631         self._set_verify(headers, tp_dst)
632
633         match = dp.ofproto_parser.OFPMatch()
634         match.set_dl_type(dl_type)
635         match.set_ip_proto(ip_proto)
636         match.set_udp_dst(tp_dst)
637         self.add_matches(dp, match)
638
639     def test_rule_set_icmpv4_type(self, dp):
640         dl_type = ether.ETH_TYPE_IP
641         ip_proto = inet.IPPROTO_ICMP
642         icmp_type = 8
643
644         headers = [dp.ofproto.OXM_OF_ICMPV4_TYPE]
645         self._set_verify(headers, icmp_type)
646
647         match = dp.ofproto_parser.OFPMatch()
648         match.set_dl_type(dl_type)
649         match.set_ip_proto(ip_proto)
650         match.set_icmpv4_type(icmp_type)
651         self.add_matches(dp, match)
652
653     def test_rule_set_icmpv4_code(self, dp):
654         dl_type = ether.ETH_TYPE_IP
655         ip_proto = inet.IPPROTO_ICMP
656         icmp_type = 9
657         icmp_code = 16
658
659         headers = [dp.ofproto.OXM_OF_ICMPV4_CODE]
660         self._set_verify(headers, icmp_code)
661
662         match = dp.ofproto_parser.OFPMatch()
663         match.set_dl_type(dl_type)
664         match.set_ip_proto(ip_proto)
665         match.set_icmpv4_type(icmp_type)
666         match.set_icmpv4_code(icmp_code)
667         self.add_matches(dp, match)
668
669     def test_rule_set_arp_opcode(self, dp):
670         dl_type = ether.ETH_TYPE_ARP
671         arp_op = 1
672
673         headers = [dp.ofproto.OXM_OF_ARP_OP]
674         self._set_verify(headers, arp_op)
675
676         match = dp.ofproto_parser.OFPMatch()
677         match.set_dl_type(dl_type)
678         match.set_arp_opcode(arp_op)
679         self.add_matches(dp, match)
680
681     def test_rule_set_arp_spa(self, dp):
682         dl_type = ether.ETH_TYPE_ARP
683         nw_src = '192.168.222.57'
684         nw_src_int = self.ipv4_to_int(nw_src)
685
686         headers = [dp.ofproto.OXM_OF_ARP_SPA, dp.ofproto.OXM_OF_ARP_SPA_W]
687         self._set_verify(headers, nw_src_int, type_='ipv4')
688
689         match = dp.ofproto_parser.OFPMatch()
690         match.set_dl_type(dl_type)
691         match.set_arp_spa(nw_src_int)
692         self.add_matches(dp, match)
693
694     def test_rule_set_arp_spa_masked_32(self, dp):
695         dl_type = ether.ETH_TYPE_ARP
696         nw_src = '192.168.222.57'
697         nw_src_int = self.ipv4_to_int(nw_src)
698         mask = '255.255.255.255'
699         mask_int = self.ipv4_to_int(mask)
700
701         headers = [dp.ofproto.OXM_OF_ARP_SPA, dp.ofproto.OXM_OF_ARP_SPA_W]
702         self._set_verify(headers, nw_src_int, mask_int, True, type_='ipv4')
703
704         match = dp.ofproto_parser.OFPMatch()
705         match.set_dl_type(dl_type)
706         match.set_arp_spa_masked(nw_src_int, mask_int)
707         self.add_matches(dp, match)
708
709     def test_rule_set_arp_spa_masked_24(self, dp):
710         dl_type = ether.ETH_TYPE_ARP
711         nw_src = '192.168.222.57'
712         nw_src_int = self.ipv4_to_int(nw_src)
713         mask = '255.255.255.0'
714         mask_int = self.ipv4_to_int(mask)
715
716         headers = [dp.ofproto.OXM_OF_ARP_SPA, dp.ofproto.OXM_OF_ARP_SPA_W]
717         self._set_verify(headers, nw_src_int, mask_int, type_='ipv4')
718
719         match = dp.ofproto_parser.OFPMatch()
720         match.set_dl_type(dl_type)
721         match.set_arp_spa_masked(nw_src_int, mask_int)
722         self.add_matches(dp, match)
723
724     def test_rule_set_arp_spa_masked_00(self, dp):
725         dl_type = ether.ETH_TYPE_ARP
726         nw_src = '192.168.222.57'
727         nw_src_int = self.ipv4_to_int(nw_src)
728         mask = '0.0.0.0'
729         mask_int = self.ipv4_to_int(mask)
730
731         headers = [dp.ofproto.OXM_OF_ARP_SPA, dp.ofproto.OXM_OF_ARP_SPA_W]
732         self._set_verify(headers, nw_src_int, mask_int, type_='ipv4')
733
734         match = dp.ofproto_parser.OFPMatch()
735         match.set_dl_type(dl_type)
736         match.set_arp_spa_masked(nw_src_int, mask_int)
737         self.add_matches(dp, match)
738
739     def test_rule_set_arp_tpa(self, dp):
740         dl_type = ether.ETH_TYPE_ARP
741         nw_dst = '192.168.198.233'
742         nw_dst_int = self.ipv4_to_int(nw_dst)
743
744         headers = [dp.ofproto.OXM_OF_ARP_TPA, dp.ofproto.OXM_OF_ARP_TPA_W]
745         self._set_verify(headers, nw_dst_int, type_='ipv4')
746
747         match = dp.ofproto_parser.OFPMatch()
748         match.set_dl_type(dl_type)
749         match.set_arp_tpa(nw_dst_int)
750         self.add_matches(dp, match)
751
752     def test_rule_set_arp_tpa_masked_32(self, dp):
753         dl_type = ether.ETH_TYPE_ARP
754         nw_dst = '192.168.198.233'
755         nw_dst_int = self.ipv4_to_int(nw_dst)
756         mask = '255.255.255.255'
757         mask_int = self.ipv4_to_int(mask)
758
759         headers = [dp.ofproto.OXM_OF_ARP_TPA, dp.ofproto.OXM_OF_ARP_TPA_W]
760         self._set_verify(headers, nw_dst_int, mask_int, True, type_='ipv4')
761
762         match = dp.ofproto_parser.OFPMatch()
763         match.set_dl_type(dl_type)
764         match.set_arp_tpa_masked(nw_dst_int, mask_int)
765         self.add_matches(dp, match)
766
767     def test_rule_set_arp_tpa_masked_24(self, dp):
768         dl_type = ether.ETH_TYPE_ARP
769         nw_dst = '192.168.198.233'
770         nw_dst_int = self.ipv4_to_int(nw_dst)
771         mask = '255.255.255.0'
772         mask_int = self.ipv4_to_int(mask)
773
774         headers = [dp.ofproto.OXM_OF_ARP_TPA, dp.ofproto.OXM_OF_ARP_TPA_W]
775         self._set_verify(headers, nw_dst_int, mask_int, type_='ipv4')
776
777         match = dp.ofproto_parser.OFPMatch()
778         match.set_dl_type(dl_type)
779         match.set_arp_tpa_masked(nw_dst_int, mask_int)
780         self.add_matches(dp, match)
781
782     def test_rule_set_arp_tpa_masked_00(self, dp):
783         dl_type = ether.ETH_TYPE_ARP
784         nw_dst = '192.168.198.233'
785         nw_dst_int = self.ipv4_to_int(nw_dst)
786         mask = '0.0.0.0'
787         mask_int = self.ipv4_to_int(mask)
788
789         headers = [dp.ofproto.OXM_OF_ARP_TPA, dp.ofproto.OXM_OF_ARP_TPA_W]
790         self._set_verify(headers, nw_dst_int, mask_int, type_='ipv4')
791
792         match = dp.ofproto_parser.OFPMatch()
793         match.set_dl_type(dl_type)
794         match.set_arp_tpa_masked(nw_dst_int, mask_int)
795         self.add_matches(dp, match)
796
797     def test_rule_set_arp_sha(self, dp):
798         dl_type = ether.ETH_TYPE_ARP
799         arp_sha = '3e:ec:13:9b:f3:0b'
800         arp_sha_bin = self.haddr_to_bin(arp_sha)
801
802         headers = [dp.ofproto.OXM_OF_ARP_SHA, dp.ofproto.OXM_OF_ARP_SHA_W]
803         self._set_verify(headers, arp_sha_bin, type_='mac')
804
805         match = dp.ofproto_parser.OFPMatch()
806         match.set_dl_type(dl_type)
807         match.set_arp_sha(arp_sha_bin)
808         self.add_matches(dp, match)
809
810     def test_rule_set_arp_sha_masked_ff(self, dp):
811         dl_type = ether.ETH_TYPE_ARP
812         arp_sha = '3e:ec:13:9b:f3:0b'
813         arp_sha_bin = self.haddr_to_bin(arp_sha)
814         mask = 'ff:ff:ff:ff:ff:ff'
815         mask_bin = self.haddr_to_bin(mask)
816
817         headers = [dp.ofproto.OXM_OF_ARP_SHA, dp.ofproto.OXM_OF_ARP_SHA_W]
818         self._set_verify(headers, arp_sha_bin, mask_bin, True, type_='mac')
819
820         match = dp.ofproto_parser.OFPMatch()
821         match.set_dl_type(dl_type)
822         match.set_arp_sha_masked(arp_sha_bin, mask_bin)
823         self.add_matches(dp, match)
824
825     def test_rule_set_arp_sha_masked_f0(self, dp):
826         dl_type = ether.ETH_TYPE_ARP
827         arp_sha = '3e:ec:13:9b:f3:0b'
828         arp_sha_bin = self.haddr_to_bin(arp_sha)
829         mask = 'ff:ff:ff:ff:ff:00'
830         mask_bin = self.haddr_to_bin(mask)
831
832         headers = [dp.ofproto.OXM_OF_ARP_SHA, dp.ofproto.OXM_OF_ARP_SHA_W]
833         self._set_verify(headers, arp_sha_bin, mask_bin, type_='mac')
834
835         match = dp.ofproto_parser.OFPMatch()
836         match.set_dl_type(dl_type)
837         match.set_arp_sha_masked(arp_sha_bin, mask_bin)
838         self.add_matches(dp, match)
839
840     def test_rule_set_arp_sha_masked_00(self, dp):
841         dl_type = ether.ETH_TYPE_ARP
842         arp_sha = '3e:ec:13:9b:f3:0b'
843         arp_sha_bin = self.haddr_to_bin(arp_sha)
844         mask = '00:00:00:00:00:00'
845         mask_bin = self.haddr_to_bin(mask)
846
847         headers = [dp.ofproto.OXM_OF_ARP_SHA, dp.ofproto.OXM_OF_ARP_SHA_W]
848         self._set_verify(headers, arp_sha_bin, mask_bin, type_='mac')
849
850         match = dp.ofproto_parser.OFPMatch()
851         match.set_dl_type(dl_type)
852         match.set_arp_sha_masked(arp_sha_bin, mask_bin)
853         self.add_matches(dp, match)
854
855     def test_rule_set_arp_tha(self, dp):
856         dl_type = ether.ETH_TYPE_ARP
857         arp_tha = '83:6c:21:52:49:68'
858         arp_tha_bin = self.haddr_to_bin(arp_tha)
859
860         headers = [dp.ofproto.OXM_OF_ARP_THA, dp.ofproto.OXM_OF_ARP_THA_W]
861         self._set_verify(headers, arp_tha_bin, type_='mac')
862
863         match = dp.ofproto_parser.OFPMatch()
864         match.set_dl_type(dl_type)
865         match.set_arp_tha(arp_tha_bin)
866         self.add_matches(dp, match)
867
868     def test_rule_set_arp_tha_masked_ff(self, dp):
869         dl_type = ether.ETH_TYPE_ARP
870         arp_tha = '83:6c:21:52:49:68'
871         arp_tha_bin = self.haddr_to_bin(arp_tha)
872         mask = 'ff:ff:ff:ff:ff:ff'
873         mask_bin = self.haddr_to_bin(mask)
874
875         headers = [dp.ofproto.OXM_OF_ARP_THA, dp.ofproto.OXM_OF_ARP_THA_W]
876         self._set_verify(headers, arp_tha_bin, mask_bin, True, type_='mac')
877
878         match = dp.ofproto_parser.OFPMatch()
879         match.set_dl_type(dl_type)
880         match.set_arp_tha_masked(arp_tha_bin, mask_bin)
881         self.add_matches(dp, match)
882
883     def test_rule_set_arp_tha_masked_f0(self, dp):
884         dl_type = ether.ETH_TYPE_ARP
885         arp_tha = '83:6c:21:52:49:68'
886         arp_tha_bin = self.haddr_to_bin(arp_tha)
887         mask = 'ff:ff:ff:ff:ff:00'
888         mask_bin = self.haddr_to_bin(mask)
889
890         headers = [dp.ofproto.OXM_OF_ARP_THA, dp.ofproto.OXM_OF_ARP_THA_W]
891         self._set_verify(headers, arp_tha_bin, mask_bin, type_='mac')
892
893         match = dp.ofproto_parser.OFPMatch()
894         match.set_dl_type(dl_type)
895         match.set_arp_tha_masked(arp_tha_bin, mask_bin)
896         self.add_matches(dp, match)
897
898     def test_rule_set_arp_tha_masked_00(self, dp):
899         dl_type = ether.ETH_TYPE_ARP
900         arp_tha = '83:6c:21:52:49:68'
901         arp_tha_bin = self.haddr_to_bin(arp_tha)
902         mask = '00:00:00:00:00:00'
903         mask_bin = self.haddr_to_bin(mask)
904
905         headers = [dp.ofproto.OXM_OF_ARP_THA, dp.ofproto.OXM_OF_ARP_THA_W]
906         self._set_verify(headers, arp_tha_bin, mask_bin, type_='mac')
907
908         match = dp.ofproto_parser.OFPMatch()
909         match.set_dl_type(dl_type)
910         match.set_arp_tha_masked(arp_tha_bin, mask_bin)
911         self.add_matches(dp, match)
912
913     def test_rule_set_ipv6_src(self, dp):
914         dl_type = ether.ETH_TYPE_IPV6
915         ipv6_src = '2001:db8:bd05:1d2:288a:1fc0:1:10ee'
916         ipv6_src_int = self.ipv6_to_int(ipv6_src)
917
918         headers = [dp.ofproto.OXM_OF_IPV6_SRC, dp.ofproto.OXM_OF_IPV6_SRC_W]
919         self._set_verify(headers, ipv6_src_int, type_='ipv6')
920
921         match = dp.ofproto_parser.OFPMatch()
922         match.set_dl_type(dl_type)
923         match.set_ipv6_src(ipv6_src_int)
924         self.add_matches(dp, match)
925
926     def test_rule_set_ipv6_src_masked_ff(self, dp):
927         dl_type = ether.ETH_TYPE_IPV6
928         ipv6_src = '2001:db8:bd05:1d2:288a:1fc0:1:10ee'
929         ipv6_src_int = self.ipv6_to_int(ipv6_src)
930         mask = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
931         mask_int = self.ipv6_to_int(mask)
932
933         headers = [dp.ofproto.OXM_OF_IPV6_SRC, dp.ofproto.OXM_OF_IPV6_SRC_W]
934         self._set_verify(headers, ipv6_src_int, mask_int, True, type_='ipv6')
935
936         match = dp.ofproto_parser.OFPMatch()
937         match.set_dl_type(dl_type)
938         match.set_ipv6_src_masked(ipv6_src_int, mask_int)
939         self.add_matches(dp, match)
940
941     def test_rule_set_ipv6_src_masked_f0(self, dp):
942         dl_type = ether.ETH_TYPE_IPV6
943         ipv6_src = '2001:db8:bd05:1d2:288a:1fc0:1:10ee'
944         ipv6_src_int = self.ipv6_to_int(ipv6_src)
945         mask = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0'
946         mask_int = self.ipv6_to_int(mask)
947
948         headers = [dp.ofproto.OXM_OF_IPV6_SRC, dp.ofproto.OXM_OF_IPV6_SRC_W]
949         self._set_verify(headers, ipv6_src_int, mask_int, type_='ipv6')
950
951         match = dp.ofproto_parser.OFPMatch()
952         match.set_dl_type(dl_type)
953         match.set_ipv6_src_masked(ipv6_src_int, mask_int)
954         self.add_matches(dp, match)
955
956     def test_rule_set_ipv6_src_masked_00(self, dp):
957         dl_type = ether.ETH_TYPE_IPV6
958         ipv6_src = '2001:db8:bd05:1d2:288a:1fc0:1:10ee'
959         ipv6_src_int = self.ipv6_to_int(ipv6_src)
960         mask = '0:0:0:0:0:0:0:0'
961         mask_int = self.ipv6_to_int(mask)
962
963         headers = [dp.ofproto.OXM_OF_IPV6_SRC, dp.ofproto.OXM_OF_IPV6_SRC_W]
964         self._set_verify(headers, ipv6_src_int, mask_int, type_='ipv6')
965
966         match = dp.ofproto_parser.OFPMatch()
967         match.set_dl_type(dl_type)
968         match.set_ipv6_src_masked(ipv6_src_int, mask_int)
969         self.add_matches(dp, match)
970
971     def test_rule_set_ipv6_dst(self, dp):
972         dl_type = ether.ETH_TYPE_IPV6
973         ipv6_dst = 'e9e8:9ea5:7d67:82cc:ca54:1fc0:2d24:f038'
974         ipv6_dst_int = self.ipv6_to_int(ipv6_dst)
975
976         headers = [dp.ofproto.OXM_OF_IPV6_DST, dp.ofproto.OXM_OF_IPV6_DST_W]
977         self._set_verify(headers, ipv6_dst_int, type_='ipv6')
978
979         match = dp.ofproto_parser.OFPMatch()
980         match.set_dl_type(dl_type)
981         match.set_ipv6_dst(ipv6_dst_int)
982         self.add_matches(dp, match)
983
984     def test_rule_set_ipv6_dst_masked_ff(self, dp):
985         dl_type = ether.ETH_TYPE_IPV6
986         ipv6_dst = 'e9e8:9ea5:7d67:82cc:ca54:1fc0:2d24:f038'
987         ipv6_dst_int = self.ipv6_to_int(ipv6_dst)
988         mask = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
989         mask_int = self.ipv6_to_int(mask)
990
991         headers = [dp.ofproto.OXM_OF_IPV6_DST, dp.ofproto.OXM_OF_IPV6_DST_W]
992         self._set_verify(headers, ipv6_dst_int, mask_int, True, type_='ipv6')
993
994         match = dp.ofproto_parser.OFPMatch()
995         match.set_dl_type(dl_type)
996         match.set_ipv6_dst_masked(ipv6_dst_int, mask_int)
997         self.add_matches(dp, match)
998
999     def test_rule_set_ipv6_dst_masked_f0(self, dp):
1000         dl_type = ether.ETH_TYPE_IPV6
1001         ipv6_dst = 'e9e8:9ea5:7d67:82cc:ca54:1fc0:2d24:f038'
1002         ipv6_dst_int = self.ipv6_to_int(ipv6_dst)
1003         mask = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0'
1004         mask_int = self.ipv6_to_int(mask)
1005
1006         headers = [dp.ofproto.OXM_OF_IPV6_DST, dp.ofproto.OXM_OF_IPV6_DST_W]
1007         self._set_verify(headers, ipv6_dst_int, mask_int, type_='ipv6')
1008
1009         match = dp.ofproto_parser.OFPMatch()
1010         match.set_dl_type(dl_type)
1011         match.set_ipv6_dst_masked(ipv6_dst_int, mask_int)
1012         self.add_matches(dp, match)
1013
1014     def test_rule_set_ipv6_dst_masked_00(self, dp):
1015         dl_type = ether.ETH_TYPE_IPV6
1016         ipv6_dst = 'e9e8:9ea5:7d67:82cc:ca54:1fc0:2d24:f038'
1017         ipv6_dst_int = self.ipv6_to_int(ipv6_dst)
1018         mask = '0:0:0:0:0:0:0:0'
1019         mask_int = self.ipv6_to_int(mask)
1020
1021         headers = [dp.ofproto.OXM_OF_IPV6_DST, dp.ofproto.OXM_OF_IPV6_DST_W]
1022         self._set_verify(headers, ipv6_dst_int, mask_int, type_='ipv6')
1023
1024         match = dp.ofproto_parser.OFPMatch()
1025         match.set_dl_type(dl_type)
1026         match.set_ipv6_dst_masked(ipv6_dst_int, mask_int)
1027         self.add_matches(dp, match)
1028
1029     def test_rule_set_ipv6_flabel(self, dp):
1030         dl_type = ether.ETH_TYPE_IPV6
1031         ipv6_label = 0xc5384
1032
1033         headers = [dp.ofproto.OXM_OF_IPV6_FLABEL,
1034                    dp.ofproto.OXM_OF_IPV6_FLABEL_W]
1035         self._set_verify(headers, ipv6_label)
1036
1037         match = dp.ofproto_parser.OFPMatch()
1038         match.set_dl_type(dl_type)
1039         match.set_ipv6_flabel(ipv6_label)
1040         self.add_matches(dp, match)
1041
1042     def test_rule_set_ipv6_flabel_masked_ff(self, dp):
1043         dl_type = ether.ETH_TYPE_IPV6
1044         ipv6_label = 0xc5384
1045         mask = 0xfffff
1046
1047         headers = [dp.ofproto.OXM_OF_IPV6_FLABEL,
1048                    dp.ofproto.OXM_OF_IPV6_FLABEL_W]
1049         self._set_verify(headers, ipv6_label, mask, True)
1050
1051         match = dp.ofproto_parser.OFPMatch()
1052         match.set_dl_type(dl_type)
1053         match.set_ipv6_flabel_masked(ipv6_label, mask)
1054         self.add_matches(dp, match)
1055
1056     def test_rule_set_ipv6_flabel_masked_f0(self, dp):
1057         dl_type = ether.ETH_TYPE_IPV6
1058         ipv6_label = 0xc5384
1059         mask = 0xffff0
1060
1061         headers = [dp.ofproto.OXM_OF_IPV6_FLABEL,
1062                    dp.ofproto.OXM_OF_IPV6_FLABEL_W]
1063         self._set_verify(headers, ipv6_label, mask)
1064
1065         match = dp.ofproto_parser.OFPMatch()
1066         match.set_dl_type(dl_type)
1067         match.set_ipv6_flabel_masked(ipv6_label, mask)
1068         self.add_matches(dp, match)
1069
1070     def test_rule_set_ipv6_flabel_masked_00(self, dp):
1071         dl_type = ether.ETH_TYPE_IPV6
1072         ipv6_label = 0xc5384
1073         mask = 0x0
1074
1075         headers = [dp.ofproto.OXM_OF_IPV6_FLABEL,
1076                    dp.ofproto.OXM_OF_IPV6_FLABEL_W]
1077         self._set_verify(headers, ipv6_label, mask)
1078
1079         match = dp.ofproto_parser.OFPMatch()
1080         match.set_dl_type(dl_type)
1081         match.set_ipv6_flabel_masked(ipv6_label, mask)
1082         self.add_matches(dp, match)
1083
1084     def test_rule_set_icmpv6_type(self, dp):
1085         dl_type = ether.ETH_TYPE_IPV6
1086         ip_proto = inet.IPPROTO_ICMPV6
1087         icmp_type = 129
1088
1089         headers = [dp.ofproto.OXM_OF_ICMPV6_TYPE]
1090         self._set_verify(headers, icmp_type)
1091
1092         match = dp.ofproto_parser.OFPMatch()
1093         match.set_dl_type(dl_type)
1094         match.set_ip_proto(ip_proto)
1095         match.set_icmpv6_type(icmp_type)
1096         self.add_matches(dp, match)
1097
1098     def test_rule_set_icmpv6_code(self, dp):
1099         dl_type = ether.ETH_TYPE_IPV6
1100         ip_proto = inet.IPPROTO_ICMPV6
1101         icmp_type = 138
1102         icmp_code = 1
1103
1104         headers = [dp.ofproto.OXM_OF_ICMPV6_CODE]
1105         self._set_verify(headers, icmp_code)
1106
1107         match = dp.ofproto_parser.OFPMatch()
1108         match.set_dl_type(dl_type)
1109         match.set_ip_proto(ip_proto)
1110         match.set_icmpv6_type(icmp_type)
1111         match.set_icmpv6_code(icmp_code)
1112         self.add_matches(dp, match)
1113
1114     def test_rule_set_ipv6_nd_target(self, dp):
1115         dl_type = ether.ETH_TYPE_IPV6
1116         ip_proto = inet.IPPROTO_ICMPV6
1117         icmp_type = 135
1118         target = "5420:db3f:921b:3e33:2791:98f:dd7f:2e19"
1119         target_int = self.ipv6_to_int(target)
1120
1121         headers = [dp.ofproto.OXM_OF_IPV6_ND_TARGET]
1122         self._set_verify(headers, target_int, type_='ipv6')
1123
1124         match = dp.ofproto_parser.OFPMatch()
1125         match.set_dl_type(dl_type)
1126         match.set_ip_proto(ip_proto)
1127         match.set_icmpv6_type(icmp_type)
1128         match.set_ipv6_nd_target(target_int)
1129         self.add_matches(dp, match)
1130
1131     def test_rule_set_ipv6_nd_sll(self, dp):
1132         dl_type = ether.ETH_TYPE_IPV6
1133         ip_proto = inet.IPPROTO_ICMPV6
1134         icmp_type = 135
1135         nd_sll = "93:6d:d0:d4:e8:36"
1136         nd_sll_bin = self.haddr_to_bin(nd_sll)
1137
1138         headers = [dp.ofproto.OXM_OF_IPV6_ND_SLL]
1139         self._set_verify(headers, nd_sll_bin, type_='mac')
1140
1141         match = dp.ofproto_parser.OFPMatch()
1142         match.set_dl_type(dl_type)
1143         match.set_ip_proto(ip_proto)
1144         match.set_icmpv6_type(icmp_type)
1145         match.set_ipv6_nd_sll(nd_sll_bin)
1146         self.add_matches(dp, match)
1147
1148     def test_rule_set_ipv6_nd_tll(self, dp):
1149         dl_type = ether.ETH_TYPE_IPV6
1150         ip_proto = inet.IPPROTO_ICMPV6
1151         icmp_type = 136
1152         nd_tll = "18:f6:66:b6:f1:b3"
1153         nd_tll_bin = self.haddr_to_bin(nd_tll)
1154
1155         headers = [dp.ofproto.OXM_OF_IPV6_ND_TLL]
1156         self._set_verify(headers, nd_tll_bin, type_='mac')
1157
1158         match = dp.ofproto_parser.OFPMatch()
1159         match.set_dl_type(dl_type)
1160         match.set_ip_proto(ip_proto)
1161         match.set_icmpv6_type(icmp_type)
1162         match.set_ipv6_nd_tll(nd_tll_bin)
1163         self.add_matches(dp, match)
1164
1165     def test_rule_set_mpls_label(self, dp):
1166         dl_type = 0x8847
1167         label = 2144
1168
1169         headers = [dp.ofproto.OXM_OF_MPLS_LABEL]
1170         self._set_verify(headers, label)
1171
1172         match = dp.ofproto_parser.OFPMatch()
1173         match.set_dl_type(dl_type)
1174         match.set_mpls_label(label)
1175         self.add_matches(dp, match)
1176
1177     def test_rule_set_mpls_tc(self, dp):
1178         dl_type = 0x8847
1179         tc = 3
1180
1181         headers = [dp.ofproto.OXM_OF_MPLS_TC]
1182         self._set_verify(headers, tc)
1183
1184         match = dp.ofproto_parser.OFPMatch()
1185         match.set_dl_type(dl_type)
1186         match.set_mpls_tc(tc)
1187         self.add_matches(dp, match)
1188
1189     def is_supported(self, t):
1190         # Open vSwitch 1.10 does not support MPLS yet.
1191         unsupported = [
1192             'test_rule_set_mpls_label',
1193             'test_rule_set_mpls_tc',
1194         ]
1195         for u in unsupported:
1196             if t.find(u) != -1:
1197                 return False
1198
1199         return True