backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / ofproto / test_parser_v10.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 unittest
19 import logging
20 import six
21 from nose.tools import *
22 from ryu.ofproto.ofproto_v1_0_parser import *
23 from ryu.ofproto.nx_actions import *
24 from ryu.ofproto import ofproto_v1_0_parser
25 from ryu.lib import addrconv
26
27
28 LOG = logging.getLogger('test_ofproto_v10')
29
30
31 class TestOFPPhyPort(unittest.TestCase):
32     """ Test case for ofproto_v1_0_parser.OFPPhyPort
33     """
34
35     # OFP_PHY_PORT_PACK_STR
36     # '!H6s16sIIIIII'... port_no, hw_addr, name, config, state
37     #                    curr, advertised, supported, peer
38     port_no = {'buf': b'\xe7\x6b', 'val': 59243}
39     hw_addr = '52:54:54:10:20:99'
40     name = b'name'.ljust(16)
41     config = {'buf': b'\x84\xb6\x8c\x53', 'val': 2226555987}
42     state = {'buf': b'\x64\x07\xfb\xc9', 'val': 1678244809}
43     curr = {'buf': b'\xa9\xe8\x0a\x2b', 'val': 2850556459}
44     advertised = {'buf': b'\x78\xb9\x7b\x72', 'val': 2025421682}
45     supported = {'buf': b'\x7e\x65\x68\xad', 'val': 2120575149}
46     peer = {'buf': b'\xa4\x5b\x8b\xed', 'val': 2757463021}
47
48     buf = port_no['buf'] \
49         + addrconv.mac.text_to_bin(hw_addr) \
50         + name \
51         + config['buf'] \
52         + state['buf'] \
53         + curr['buf'] \
54         + advertised['buf'] \
55         + supported['buf'] \
56         + peer['buf']
57
58     c = OFPPhyPort(port_no['val'],
59                    hw_addr,
60                    name,
61                    config['val'],
62                    state['val'],
63                    curr['val'],
64                    advertised['val'],
65                    supported['val'],
66                    peer['val'])
67
68     def setUp(self):
69         pass
70
71     def tearDown(self):
72         pass
73
74     def test_init(self):
75         eq_(self.port_no['val'], self.c.port_no)
76         eq_(self.hw_addr, self.c.hw_addr)
77         eq_(self.name, self.c.name)
78         eq_(self.config['val'], self.c.config)
79         eq_(self.state['val'], self.c.state)
80         eq_(self.curr['val'], self.c.curr)
81         eq_(self.advertised['val'], self.c.advertised)
82         eq_(self.supported['val'], self.c.supported)
83         eq_(self.peer['val'], self.c.peer)
84
85     def test_parser(self):
86         res = self.c.parser(self.buf, 0)
87
88         eq_(self.port_no['val'], res.port_no)
89         eq_(self.hw_addr, res.hw_addr)
90         eq_(self.name, res.name)
91         eq_(self.config['val'], res.config)
92         eq_(self.state['val'], res.state)
93         eq_(self.curr['val'], res.curr)
94         eq_(self.advertised['val'], res.advertised)
95         eq_(self.supported['val'], res.supported)
96         eq_(self.peer['val'], res.peer)
97
98
99 class TestOFPMatch(unittest.TestCase):
100     """ Test case for ofproto_v1_0_parser.OFPMatch
101     """
102
103     # OFP_MATCH_PACK_STR
104     # '!IH6s6sHBxHBB2xIIHH'...wildcards, in_port, dl_src, dl_dst, dl_vlan,
105     #                         dl_vlan_pcp, dl_type, nw_tos, nw_proto,
106     #                         nw_src, nw_dst, tp_src, tp_dst
107     wildcards = {'buf': b'\x00\x02\x10\x00', 'val': 135168}
108     in_port = {'buf': b'\x37\x8b', 'val': 14219}
109     dl_src = {'buf': b'\x52\x54\x54\x10\x20\x99',
110               'human': '52:54:54:10:20:99'}
111     dl_dst = {'buf': b'\x61\x31\x50\x6d\xc9\xe5',
112               'human': '61:31:50:6d:c9:e5'}
113     dl_vlan = {'buf': b'\xc1\xf9', 'val': 49657}
114     dl_vlan_pcp = {'buf': b'\x79', 'val': 121}
115     zfill0 = b'\x00'
116     dl_type = {'buf': b'\xa6\x9e', 'val': 42654}
117     nw_tos = {'buf': b'\xde', 'val': 222}
118     nw_proto = {'buf': b'\xe5', 'val': 229}
119     zfil11 = b'\x00' * 2
120     nw_src = {'buf': b'\x1b\x6d\x8d\x4b', 'val': 460164427,
121               'human': '27.109.141.75'}
122     nw_dst = {'buf': b'\xab\x25\xe1\x20', 'val': 2871386400,
123               'human': '171.37.225.32'}
124     tp_src = {'buf': b'\xd5\xc3', 'val': 54723}
125     tp_dst = {'buf': b'\x78\xb9', 'val': 30905}
126
127     buf = wildcards['buf'] \
128         + in_port['buf'] \
129         + dl_src['buf'] \
130         + dl_dst['buf'] \
131         + dl_vlan['buf'] \
132         + dl_vlan_pcp['buf'] \
133         + zfill0 \
134         + dl_type['buf'] \
135         + nw_tos['buf'] \
136         + nw_proto['buf'] \
137         + zfil11 \
138         + nw_src['buf'] \
139         + nw_dst['buf'] \
140         + tp_src['buf'] \
141         + tp_dst['buf']
142
143     def _get_obj(self, dl_src, dl_dst):
144         c = OFPMatch(self.wildcards['val'],
145                      self.in_port['val'],
146                      dl_src,
147                      dl_dst,
148                      self.dl_vlan['val'],
149                      self.dl_vlan_pcp['val'],
150                      self.dl_type['val'],
151                      self.nw_tos['val'],
152                      self.nw_proto['val'],
153                      self.nw_src['val'],
154                      self.nw_dst['val'],
155                      self.tp_src['val'],
156                      self.tp_dst['val'])
157         return c
158
159     def setUp(self):
160         pass
161
162     def tearDown(self):
163         pass
164
165     def test_init(self):
166         c = self._get_obj(self.dl_src['buf'], self.dl_dst['buf'])
167
168         eq_(self.wildcards['val'], c.wildcards)
169         eq_(self.in_port['val'], c.in_port)
170         eq_(self.dl_src['buf'], c.dl_src)
171         eq_(self.dl_dst['buf'], c.dl_dst)
172         eq_(self.dl_vlan['val'], c.dl_vlan)
173         eq_(self.dl_vlan_pcp['val'], c.dl_vlan_pcp)
174         eq_(self.dl_type['val'], c.dl_type)
175         eq_(self.nw_tos['val'], c.nw_tos)
176         eq_(self.nw_proto['val'], c.nw_proto)
177         eq_(self.nw_src['val'], c.nw_src)
178         eq_(self.nw_dst['val'], c.nw_dst)
179         eq_(self.tp_src['val'], c.tp_src)
180         eq_(self.tp_dst['val'], c.tp_dst)
181
182     def test_init_zero(self):
183         c = self._get_obj(0, 0)
184         eq_(mac.DONTCARE, c.dl_src)
185         eq_(mac.DONTCARE, c.dl_dst)
186
187     def test_parse(self):
188         c = self._get_obj(self.dl_src['buf'], self.dl_dst['buf'])
189         res = c.parse(self.buf, 0)
190
191         eq_(self.wildcards['val'], res.wildcards)
192         eq_(self.in_port['val'], res.in_port)
193         eq_(self.dl_src['buf'], res.dl_src)
194         eq_(self.dl_dst['buf'], res.dl_dst)
195         eq_(self.dl_vlan['val'], res.dl_vlan)
196         eq_(self.dl_vlan_pcp['val'], res.dl_vlan_pcp)
197         eq_(self.dl_type['val'], res.dl_type)
198         eq_(self.nw_tos['val'], res.nw_tos)
199         eq_(self.nw_proto['val'], res.nw_proto)
200         eq_(self.nw_src['val'], res.nw_src)
201         eq_(self.nw_dst['val'], res.nw_dst)
202         eq_(self.tp_src['val'], res.tp_src)
203         eq_(self.tp_dst['val'], res.tp_dst)
204
205     def test_serialize(self):
206         buf = bytearray()
207         c = self._get_obj(self.dl_src['buf'], self.dl_dst['buf'])
208
209         c.serialize(buf, 0)
210
211         fmt = ofproto.OFP_MATCH_PACK_STR
212         res = struct.unpack_from(fmt, six.binary_type(buf))
213
214         eq_(self.wildcards['val'], res[0])
215         eq_(self.in_port['val'], res[1])
216         eq_(self.dl_src['buf'], res[2])
217         eq_(self.dl_dst['buf'], res[3])
218         eq_(self.dl_vlan['val'], res[4])
219         eq_(self.dl_vlan_pcp['val'], res[5])
220         eq_(self.dl_type['val'], res[6])
221         eq_(self.nw_tos['val'], res[7])
222         eq_(self.nw_proto['val'], res[8])
223         eq_(self.nw_src['val'], res[9])
224         eq_(self.nw_dst['val'], res[10])
225         eq_(self.tp_src['val'], res[11])
226         eq_(self.tp_dst['val'], res[12])
227
228     def test_getitem(self):
229         c = self._get_obj(self.dl_src['buf'], self.dl_dst['buf'])
230
231         eq_(self.wildcards['val'], c["wildcards"])
232         eq_(self.in_port['val'], c["in_port"])
233         eq_(self.dl_src['human'], c["dl_src"])
234         eq_(self.dl_dst['human'], c["dl_dst"])
235         eq_(self.dl_vlan['val'], c["dl_vlan"])
236         eq_(self.dl_vlan_pcp['val'], c["dl_vlan_pcp"])
237         eq_(self.dl_type['val'], c["dl_type"])
238         eq_(self.nw_tos['val'], c["nw_tos"])
239         eq_(self.nw_proto['val'], c["nw_proto"])
240         eq_(self.nw_src['human'], c["nw_src"])
241         eq_(self.nw_dst['human'], c["nw_dst"])
242         eq_(self.tp_src['val'], c["tp_src"])
243         eq_(self.tp_dst['val'], c["tp_dst"])
244
245
246 class TestOFPActionHeader(unittest.TestCase):
247     """ Test case for ofproto_v1_0_parser.OFPActionHeader
248     """
249
250     # OFP_ACTION_HEADER_PACK_STR
251     # '!HH4x'...type, len, zfill
252     type = {'buf': b'\x00\x02', 'val': ofproto.OFPAT_SET_VLAN_PCP}
253     len = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_HEADER_SIZE}
254     zfill = b'\x00' * 4
255
256     buf = type['buf'] \
257         + len['buf'] \
258         + zfill
259
260     c = OFPActionHeader(type['val'], len['val'])
261
262     def setUp(self):
263         pass
264
265     def tearDown(self):
266         pass
267
268     def test_init(self):
269         eq_(self.type['val'], self.c.type)
270         eq_(self.len['val'], self.c.len)
271
272     def test_serialize(self):
273         buf = bytearray()
274         self.c.serialize(buf, 0)
275
276         fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
277         res = struct.unpack(fmt, six.binary_type(buf))
278
279         eq_(self.type['val'], res[0])
280         eq_(self.len['val'], res[1])
281
282
283 class TestOFPActionOutput(unittest.TestCase):
284     """ Test case for ofproto_v1_0_parser.OFPActionOutput
285     """
286
287     # OFP_ACTION_OUTPUT_PACK_STR
288     # '!HHHH'...type, len, port, max_len
289     type_ = {'buf': b'\x00\x00', 'val': ofproto.OFPAT_OUTPUT}
290     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_OUTPUT_SIZE}
291     port = {'buf': b'\x19\xce', 'val': 6606}
292     max_len = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_OUTPUT_SIZE}
293
294     buf = type_['buf'] \
295         + len_['buf'] \
296         + port['buf'] \
297         + max_len['buf']
298
299     c = OFPActionOutput(port['val'], max_len['val'])
300
301     def setUp(self):
302         pass
303
304     def tearDown(self):
305         pass
306
307     def test_init(self):
308         eq_(self.port['val'], self.c.port)
309         eq_(self.max_len['val'], self.c.max_len)
310
311     def test_parser(self):
312         res = self.c.parser(self.buf, 0)
313
314         eq_(self.port['val'], res.port)
315         eq_(self.max_len['val'], res.max_len)
316
317     @raises(AssertionError)
318     def test_parser_check_type(self):
319         type_ = {'buf': b'\x00\x01', 'val': 1}
320
321         buf = type_['buf'] \
322             + self.len_['buf'] \
323             + self.port['buf'] \
324             + self.max_len['buf']
325
326         self.c.parser(buf, 0)
327
328     @raises(AssertionError)
329     def test_parser_check_len(self):
330         len_ = {'buf': b'\x00\x07', 'val': 7}
331
332         buf = self.type_['buf'] \
333             + len_['buf'] \
334             + self.port['buf'] \
335             + self.max_len['buf']
336
337         self.c.parser(buf, 0)
338
339     def test_serialize(self):
340         buf = bytearray()
341         self.c.serialize(buf, 0)
342
343         fmt = ofproto.OFP_ACTION_OUTPUT_PACK_STR
344         res = struct.unpack(fmt, six.binary_type(buf))
345
346         eq_(self.type_['val'], res[0])
347         eq_(self.len_['val'], res[1])
348         eq_(self.port['val'], res[2])
349         eq_(self.max_len['val'], res[3])
350
351
352 class TestOFPActionVlanVid(unittest.TestCase):
353     """ Test case for ofproto_v1_0_parser.OFPActionVlanVid
354     """
355
356     # OFP_ACTION_VLAN_VID_PACK_STR
357     # '!HHH2x'...type, len, vlan_vid, zfill
358     type_ = {'buf': b'\x00\x01', 'val': ofproto.OFPAT_SET_VLAN_VID}
359     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_VLAN_VID_SIZE}
360     vlan_vid = {'buf': b'\x3c\x0e', 'val': 15374}
361     zfill = b'\x00' * 2
362
363     buf = type_['buf'] \
364         + len_['buf'] \
365         + vlan_vid['buf'] \
366         + zfill
367
368     c = OFPActionVlanVid(vlan_vid['val'])
369
370     def setUp(self):
371         pass
372
373     def tearDown(self):
374         pass
375
376     def test_init(self):
377         eq_(self.vlan_vid['val'], self.c.vlan_vid)
378
379     def test_parser(self):
380         res = self.c.parser(self.buf, 0)
381
382         eq_(self.vlan_vid['val'], res.vlan_vid)
383
384     @raises(AssertionError)
385     def test_parser_check_type(self):
386         type_ = {'buf': b'\x00\x02', 'val': 2}
387
388         buf = type_['buf'] \
389             + self.len_['buf'] \
390             + self.vlan_vid['buf'] \
391             + self.zfill
392
393         self.c.parser(buf, 0)
394
395     @raises(AssertionError)
396     def test_parser_check_len(self):
397         len_ = {'buf': b'\x00\x07', 'val': 7}
398
399         buf = self.type_['buf'] \
400             + len_['buf'] \
401             + self.vlan_vid['buf'] \
402             + self.zfill
403
404         self.c.parser(buf, 0)
405
406     def test_serialize(self):
407         buf = bytearray()
408         self.c.serialize(buf, 0)
409
410         fmt = ofproto.OFP_ACTION_VLAN_VID_PACK_STR
411         res = struct.unpack(fmt, six.binary_type(buf))
412
413         eq_(self.type_['val'], res[0])
414         eq_(self.len_['val'], res[1])
415         eq_(self.vlan_vid['val'], res[2])
416
417
418 class TestOFPActionVlanPcp(unittest.TestCase):
419     """ Test case for ofproto_v1_0_parser.OFPActionVlanPcp
420     """
421
422     # OFP_ACTION_VLAN_PCP_PACK_STR
423     # '!HHB3x'...type, len, vlan_pcp, zfill
424     type_ = {'buf': b'\x00\x02', 'val': ofproto.OFPAT_SET_VLAN_PCP}
425     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_VLAN_PCP_SIZE}
426     vlan_pcp = {'buf': b'\x1c', 'val': 28}
427     zfill = b'\x00' * 3
428
429     buf = type_['buf'] \
430         + len_['buf'] \
431         + vlan_pcp['buf'] \
432         + zfill
433
434     c = OFPActionVlanPcp(vlan_pcp['val'])
435
436     def setUp(self):
437         pass
438
439     def tearDown(self):
440         pass
441
442     def test_init(self):
443         eq_(self.vlan_pcp['val'], self.c.vlan_pcp)
444
445     def test_parser(self):
446         res = self.c.parser(self.buf, 0)
447         eq_(self.vlan_pcp['val'], res.vlan_pcp)
448
449     @raises(AssertionError)
450     def test_parser_check_type(self):
451         type_ = {'buf': b'\x00\x01', 'val': 1}
452
453         buf = type_['buf'] \
454             + self.len_['buf'] \
455             + self.vlan_pcp['buf'] \
456             + self.zfill
457
458         self.c.parser(buf, 0)
459
460     @raises(AssertionError)
461     def test_parser_check_len(self):
462         len_ = {'buf': b'\x00\x07', 'val': 7}
463
464         buf = self.type_['buf'] \
465             + len_['buf'] \
466             + self.vlan_pcp['buf'] \
467             + self.zfill
468
469         self.c.parser(buf, 0)
470
471     def test_serialize(self):
472         buf = bytearray()
473         self.c.serialize(buf, 0)
474
475         fmt = ofproto.OFP_ACTION_VLAN_PCP_PACK_STR
476         res = struct.unpack(fmt, six.binary_type(buf))
477
478         eq_(self.type_['val'], res[0])
479         eq_(self.len_['val'], res[1])
480         eq_(self.vlan_pcp['val'], res[2])
481
482
483 class TestOFPActionStripVlan(unittest.TestCase):
484     """ Test case for ofproto_v1_0_parser.OFPActionStripVlan
485     """
486
487     # OFP_ACTION_HEADER_PACK_STR
488     # '!HH4x'...type, len, zfill
489     type_ = {'buf': b'\x00\x03', 'val': ofproto.OFPAT_STRIP_VLAN}
490     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_HEADER_SIZE}
491     zfill = b'\x00' * 4
492
493     buf = type_['buf'] \
494         + len_['buf'] \
495         + zfill
496
497     c = OFPActionStripVlan()
498
499     def setUp(self):
500         pass
501
502     def tearDown(self):
503         pass
504
505     def test_init(self):
506         pass
507
508     def test_parser(self):
509         ok_(self.c.parser(self.buf, 0))
510
511     @raises(AssertionError)
512     def test_parser_check_type(self):
513         type_ = {'buf': b'\x00\x01', 'val': 1}
514
515         buf = type_['buf'] \
516             + self.len_['buf'] \
517             + self.zfill
518
519         self.c.parser(buf, 0)
520
521     @raises(AssertionError)
522     def test_parser_check_len(self):
523         len_ = {'buf': b'\x00\x07', 'val': 7}
524
525         buf = self.type_['buf'] \
526             + len_['buf'] \
527             + self.zfill
528
529         self.c.parser(buf, 0)
530
531
532 class TestOFPActionSetDlSrc(unittest.TestCase):
533     """ Test case for ofproto_v1_0_parser.OFPActionSetDlSrc
534     """
535
536     # OFP_ACTION_DL_ADDR_PACK_STR
537     # '!HH6s6x'...type, len, dl_addr, zfill
538     type_ = {'buf': b'\x00\x04', 'val': ofproto.OFPAT_SET_DL_SRC}
539     len_ = {'buf': b'\x00\x10', 'val': ofproto.OFP_ACTION_DL_ADDR_SIZE}
540     dl_addr = b'\x0e\xde\x27\xce\xc6\xcf'
541     zfill = b'\x00' * 6
542
543     buf = type_['buf'] \
544         + len_['buf'] \
545         + dl_addr \
546         + zfill
547
548     c = OFPActionSetDlSrc(dl_addr)
549
550     def setUp(self):
551         pass
552
553     def tearDown(self):
554         pass
555
556     def test_init(self):
557         eq_(self.dl_addr, self.c.dl_addr)
558
559     def test_parser_type_src(self):
560         res = self.c.parser(self.buf, 0)
561         eq_(self.dl_addr, res.dl_addr)
562
563     def test_parser_type_dst(self):
564         type_ = {'buf': b'\x00\x05', 'val': ofproto.OFPAT_SET_DL_DST}
565         buf = type_['buf'] \
566             + self.len_['buf'] \
567             + self.dl_addr \
568             + self.zfill
569
570         res = self.c.parser(buf, 0)
571
572         eq_(self.dl_addr, res.dl_addr)
573
574     @raises(AssertionError)
575     def test_parser_check_type(self):
576         type_ = {'buf': b'\x00\x06', 'val': 6}
577         buf = type_['buf'] \
578             + self.len_['buf'] \
579             + self.dl_addr \
580             + self.zfill
581
582         res = self.c.parser(buf, 0)
583
584     @raises(AssertionError)
585     def test_parser_check_len(self):
586         len_ = {'buf': b'\x00\x07', 'val': 7}
587         buf = self.type_['buf'] \
588             + len_['buf'] \
589             + self.dl_addr \
590             + self.zfill
591
592         res = self.c.parser(buf, 0)
593
594     def test_serialize(self):
595         buf = bytearray()
596         self.c.serialize(buf, 0)
597
598         fmt = ofproto.OFP_ACTION_DL_ADDR_PACK_STR
599         res = struct.unpack(fmt, six.binary_type(buf))
600
601         eq_(self.type_['val'], res[0])
602         eq_(self.len_['val'], res[1])
603         eq_(self.dl_addr, res[2])
604
605
606 class TestOFPActionSetDlDst(unittest.TestCase):
607     """ Test case for ofproto_v1_0_parser.OFPActionSetDlDst
608     """
609
610     # OFP_ACTION_DL_ADDR_PACK_STR
611     # '!HH6s6x'...type, len, dl_addr, zfill
612     type_ = {'buf': b'\x00\x05', 'val': ofproto.OFPAT_SET_DL_DST}
613     len_ = {'buf': b'\x00\x10', 'val': ofproto.OFP_ACTION_DL_ADDR_SIZE}
614     dl_addr = b'\x37\x48\x38\x9a\xf4\x28'
615     zfill = b'\x00' * 6
616
617     buf = type_['buf'] \
618         + len_['buf'] \
619         + dl_addr \
620         + zfill
621
622     c = OFPActionSetDlDst(dl_addr)
623
624     def setUp(self):
625         pass
626
627     def tearDown(self):
628         pass
629
630     def test_init(self):
631         eq_(self.dl_addr, self.c.dl_addr)
632
633     def test_parser_type_dst(self):
634         res = self.c.parser(self.buf, 0)
635         eq_(self.dl_addr, res.dl_addr)
636
637     def test_parser_type_src(self):
638         type_ = {'buf': b'\x00\x04', 'val': ofproto.OFPAT_SET_DL_SRC}
639         buf = type_['buf'] \
640             + self.len_['buf'] \
641             + self.dl_addr \
642             + self.zfill
643
644         res = self.c.parser(buf, 0)
645
646         eq_(self.dl_addr, res.dl_addr)
647
648     @raises(AssertionError)
649     def test_parser_check_type(self):
650         type_ = {'buf': b'\x00\x06', 'val': 6}
651         buf = type_['buf'] \
652             + self.len_['buf'] \
653             + self.dl_addr \
654             + self.zfill
655
656         res = self.c.parser(buf, 0)
657
658     @raises(AssertionError)
659     def test_parser_check_len(self):
660         len_ = {'buf': b'\x00\x07', 'val': 7}
661         buf = self.type_['buf'] \
662             + len_['buf'] \
663             + self.dl_addr \
664             + self.zfill
665
666         res = self.c.parser(buf, 0)
667
668     def test_serialize(self):
669         buf = bytearray()
670         self.c.serialize(buf, 0)
671
672         fmt = ofproto.OFP_ACTION_DL_ADDR_PACK_STR
673         res = struct.unpack(fmt, six.binary_type(buf))
674
675         eq_(self.type_['val'], res[0])
676         eq_(self.len_['val'], res[1])
677         eq_(self.dl_addr, res[2])
678
679
680 class TestOFPActionSetNwSrc(unittest.TestCase):
681     """ Test case for ofproto_v1_0_parser.OFPActionSetNwSrc
682     """
683
684     # OFP_ACTION_NW_ADDR_PACK_STR
685     # '!HHI'...type, len, nw_addr
686     type_ = {'buf': b'\x00\x06', 'val': ofproto.OFPAT_SET_NW_SRC}
687     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_NW_ADDR_SIZE}
688     nw_addr = {'buf': b'\xc0\xa8\x7a\x0a', 'val': 3232266762}
689
690     buf = type_['buf'] \
691         + len_['buf'] \
692         + nw_addr['buf']
693
694     c = OFPActionSetNwSrc(nw_addr['val'])
695
696     def setUp(self):
697         pass
698
699     def tearDown(self):
700         pass
701
702     def test_init(self):
703         eq_(self.nw_addr['val'], self.c.nw_addr)
704
705     def test_parser_src(self):
706         res = self.c.parser(self.buf, 0)
707         eq_(self.nw_addr['val'], res.nw_addr)
708
709     def test_parser_dst(self):
710         type_ = {'buf': b'\x00\x07', 'val': ofproto.OFPAT_SET_NW_DST}
711
712         buf = type_['buf'] \
713             + self.len_['buf'] \
714             + self.nw_addr['buf']
715
716         res = self.c.parser(buf, 0)
717         eq_(self.nw_addr['val'], res.nw_addr)
718
719     @raises(AssertionError)
720     def test_parser_check_type(self):
721         type_ = {'buf': b'\x00\x05', 'val': 5}
722
723         buf = type_['buf'] \
724             + self.len_['buf'] \
725             + self.nw_addr['buf']
726
727         self.c.parser(buf, 0)
728
729     @raises(AssertionError)
730     def test_parser_check_len(self):
731         len_ = {'buf': b'\x00\x10', 'val': 16}
732
733         buf = self.type_['buf'] \
734             + len_['buf'] \
735             + self.nw_addr['buf']
736
737         self.c.parser(buf, 0)
738
739     def test_serialize(self):
740         buf = bytearray()
741         self.c.serialize(buf, 0)
742
743         fmt = ofproto.OFP_ACTION_NW_ADDR_PACK_STR
744         res = struct.unpack(fmt, six.binary_type(buf))
745
746         eq_(self.type_['val'], res[0])
747         eq_(self.len_['val'], res[1])
748         eq_(self.nw_addr['val'], res[2])
749
750
751 class TestOFPActionSetNwDst(unittest.TestCase):
752     """ Test case for ofproto_v1_0_parser.OFPActionSetNwDst
753     """
754
755     # OFP_ACTION_NW_ADDR_PACK_STR
756     # '!HHI'...type, len, nw_addr
757     type_ = {'buf': b'\x00\x07', 'val': ofproto.OFPAT_SET_NW_DST}
758     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_NW_ADDR_SIZE}
759     nw_addr = {'buf': b'\xc0\xa8\x7a\x0a', 'val': 3232266762}
760
761     buf = type_['buf'] \
762         + len_['buf'] \
763         + nw_addr['buf']
764
765     c = OFPActionSetNwDst(nw_addr['val'])
766
767     def setUp(self):
768         pass
769
770     def tearDown(self):
771         pass
772
773     def test_init(self):
774         eq_(self.nw_addr['val'], self.c.nw_addr)
775
776     def test_parser_dst(self):
777         res = self.c.parser(self.buf, 0)
778         eq_(self.nw_addr['val'], res.nw_addr)
779
780     def test_parser_src(self):
781         type_ = {'buf': b'\x00\x06', 'val': ofproto.OFPAT_SET_NW_SRC}
782
783         buf = type_['buf'] \
784             + self.len_['buf'] \
785             + self.nw_addr['buf']
786
787         res = self.c.parser(buf, 0)
788         eq_(self.nw_addr['val'], res.nw_addr)
789
790     @raises(AssertionError)
791     def test_parser_check_type(self):
792         type_ = {'buf': b'\x00\x05', 'val': 5}
793
794         buf = type_['buf'] \
795             + self.len_['buf'] \
796             + self.nw_addr['buf']
797
798         self.c.parser(buf, 0)
799
800     @raises(AssertionError)
801     def test_parser_check_len(self):
802         len_ = {'buf': b'\x00\x10', 'val': 16}
803
804         buf = self.type_['buf'] \
805             + len_['buf'] \
806             + self.nw_addr['buf']
807
808         self.c.parser(buf, 0)
809
810     def test_serialize(self):
811         buf = bytearray()
812         self.c.serialize(buf, 0)
813
814         fmt = ofproto.OFP_ACTION_NW_ADDR_PACK_STR
815         res = struct.unpack(fmt, six.binary_type(buf))
816
817         eq_(self.type_['val'], res[0])
818         eq_(self.len_['val'], res[1])
819         eq_(self.nw_addr['val'], res[2])
820
821
822 class TestOFPActionSetNwTos(unittest.TestCase):
823     """ Test case for ofproto_v1_0_parser.OFPActionSetNwTos
824     """
825
826     # OFP_ACTION_NW_TOS_PACK_STR
827     # '!HHB3x'...type, len, tos, zfill
828     type_ = {'buf': b'\x00\x08', 'val': ofproto.OFPAT_SET_NW_TOS}
829     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_NW_TOS_SIZE}
830     tos = {'buf': b'\xb6', 'val': 182}
831     zfill = b'\x00' * 3
832
833     buf = type_['buf'] \
834         + len_['buf'] \
835         + tos['buf'] \
836         + zfill
837
838     c = OFPActionSetNwTos(tos['val'])
839
840     def setUp(self):
841         pass
842
843     def tearDown(self):
844         pass
845
846     def test_init(self):
847         eq_(self.tos['val'], self.c.tos)
848
849     def test_parser(self):
850         res = self.c.parser(self.buf, 0)
851         eq_(self.tos['val'], res.tos)
852
853     @raises(AssertionError)
854     def test_parser_check_type(self):
855         type_ = {'buf': b'\x00\x05', 'val': 5}
856
857         buf = type_['buf'] \
858             + self.len_['buf'] \
859             + self.tos['buf'] \
860             + self.zfill
861
862         self.c.parser(buf, 0)
863
864     @raises(AssertionError)
865     def test_parser_check_len(self):
866         len_ = {'buf': b'\x00\x07', 'val': 7}
867
868         buf = self.type_['buf'] \
869             + len_['buf'] \
870             + self.tos['buf'] \
871             + self.zfill
872
873         self.c.parser(buf, 0)
874
875     def test_serialize(self):
876         buf = bytearray()
877         self.c.serialize(buf, 0)
878
879         fmt = ofproto.OFP_ACTION_NW_TOS_PACK_STR
880         res = struct.unpack(fmt, six.binary_type(buf))
881
882         eq_(self.type_['val'], res[0])
883         eq_(self.len_['val'], res[1])
884         eq_(self.tos['val'], res[2])
885
886
887 class TestOFPActionSetTpSrc(unittest.TestCase):
888     """ Test case for ofproto_v1_0_parser.OFPActionSetTpSrc
889     """
890
891     # OFP_ACTION_TP_PORT_PACK_STR
892     # '!HHH2x'...type, len, tp, zfill
893     type_ = {'buf': b'\x00\x09', 'val': ofproto.OFPAT_SET_TP_SRC}
894     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_TP_PORT_SIZE}
895     tp = {'buf': b'\x07\xf1', 'val': 2033}
896     zfill = b'\x00' * 2
897
898     buf = type_['buf'] \
899         + len_['buf'] \
900         + tp['buf'] \
901         + zfill
902
903     c = OFPActionSetTpSrc(tp['val'])
904
905     def setUp(self):
906         pass
907
908     def tearDown(self):
909         pass
910
911     def test_init(self):
912         eq_(self.tp['val'], self.c.tp)
913
914     def test_parser_src(self):
915         res = self.c.parser(self.buf, 0)
916         eq_(self.tp['val'], res.tp)
917
918     def test_parser_dst(self):
919         type_ = {'buf': b'\x00\x0a', 'val': ofproto.OFPAT_SET_TP_DST}
920
921         buf = type_['buf'] \
922             + self.len_['buf'] \
923             + self.tp['buf'] \
924             + self.zfill
925
926         res = self.c.parser(self.buf, 0)
927         eq_(self.tp['val'], res.tp)
928
929     @raises(AssertionError)
930     def test_parser_check_type(self):
931         type_ = {'buf': b'\x00\x07', 'val': 7}
932
933         buf = type_['buf'] \
934             + self.len_['buf'] \
935             + self.tp['buf'] \
936             + self.zfill
937
938         self.c.parser(buf, 0)
939
940     @raises(AssertionError)
941     def test_parser_check_len(self):
942         len_ = {'buf': b'\x00\x07', 'val': 7}
943
944         buf = self.type_['buf'] \
945             + len_['buf'] \
946             + self.tp['buf'] \
947             + self.zfill
948
949         self.c.parser(buf, 0)
950
951     def test_serialize(self):
952         buf = bytearray()
953         self.c.serialize(buf, 0)
954
955         fmt = ofproto.OFP_ACTION_TP_PORT_PACK_STR
956         res = struct.unpack(fmt, six.binary_type(buf))
957
958         eq_(self.type_['val'], res[0])
959         eq_(self.len_['val'], res[1])
960         eq_(self.tp['val'], res[2])
961
962
963 class TestOFPActionSetTpDst(unittest.TestCase):
964     """ Test case for ofproto_v1_0_parser.OFPActionSetTpDst
965     """
966
967     # OFP_ACTION_TP_PORT_PACK_STR
968     # '!HHH2x'...type, len, tp, zfill
969     type_ = {'buf': b'\x00\x0a', 'val': ofproto.OFPAT_SET_TP_DST}
970     len_ = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_TP_PORT_SIZE}
971     tp = {'buf': b'\x06\x6d', 'val': 1645}
972     zfill = b'\x00' * 2
973
974     buf = type_['buf'] \
975         + len_['buf'] \
976         + tp['buf'] \
977         + zfill
978
979     c = OFPActionSetTpDst(tp['val'])
980
981     def setUp(self):
982         pass
983
984     def tearDown(self):
985         pass
986
987     def test_init(self):
988         eq_(self.tp['val'], self.c.tp)
989
990     def test_parser_dst(self):
991         res = self.c.parser(self.buf, 0)
992         eq_(self.tp['val'], res.tp)
993
994     def test_parser_src(self):
995         type_ = {'buf': b'\x00\x09', 'val': ofproto.OFPAT_SET_TP_SRC}
996
997         buf = type_['buf'] \
998             + self.len_['buf'] \
999             + self.tp['buf'] \
1000             + self.zfill
1001
1002         res = self.c.parser(buf, 0)
1003         eq_(self.tp['val'], res.tp)
1004
1005     @raises(AssertionError)
1006     def test_parser_check_type(self):
1007         type_ = {'buf': b'\x00\x10', 'val': 16}
1008
1009         buf = type_['buf'] \
1010             + self.len_['buf'] \
1011             + self.tp['buf'] \
1012             + self.zfill
1013
1014         self.c.parser(buf, 0)
1015
1016     @raises(AssertionError)
1017     def test_parser_check_len(self):
1018         len_ = {'buf': b'\x00\x07', 'val': 7}
1019
1020         buf = self.type_['buf'] \
1021             + len_['buf'] \
1022             + self.tp['buf'] \
1023             + self.zfill
1024
1025         self.c.parser(buf, 0)
1026
1027     def test_serialize(self):
1028         buf = bytearray()
1029         self.c.serialize(buf, 0)
1030
1031         fmt = ofproto.OFP_ACTION_TP_PORT_PACK_STR
1032         res = struct.unpack(fmt, six.binary_type(buf))
1033
1034         eq_(self.type_['val'], res[0])
1035         eq_(self.len_['val'], res[1])
1036         eq_(self.tp['val'], res[2])
1037
1038
1039 class TestOFPActionEnqueue(unittest.TestCase):
1040     """ Test case for ofproto_v1_0_parser.OFPActionEnqueue
1041     """
1042
1043     # OFP_ACTION_ENQUEUE_PACK_STR
1044     # '!HHH6xI'...type_, len_, port, zfill, queue_id
1045     type_ = {'buf': b'\x00\x0b', 'val': ofproto.OFPAT_ENQUEUE}
1046     len_ = {'buf': b'\x00\x10', 'val': ofproto.OFP_ACTION_ENQUEUE_SIZE}
1047     port = {'buf': b'\x04\x55', 'val': 1109}
1048     zfill = b'\x00' * 6
1049     queue_id = {'buf': b'\x0a\x5b\x03\x5e', 'val': 173736798}
1050
1051     buf = type_['buf'] \
1052         + len_['buf'] \
1053         + port['buf'] \
1054         + zfill \
1055         + queue_id['buf']
1056
1057     c = OFPActionEnqueue(port['val'], queue_id['val'])
1058
1059     def setUp(self):
1060         pass
1061
1062     def tearDown(self):
1063         pass
1064
1065     def test_init(self):
1066         eq_(self.port['val'], self.c.port)
1067         eq_(self.queue_id['val'], self.c.queue_id)
1068
1069     def test_parser(self):
1070         res = self.c.parser(self.buf, 0)
1071
1072         eq_(self.port['val'], res.port)
1073         eq_(self.queue_id['val'], res.queue_id)
1074
1075     @raises(AssertionError)
1076     def test_parser_check_type(self):
1077         type_ = {'buf': b'\x00\x0a', 'val': 10}
1078
1079         buf = type_['buf'] \
1080             + self.len_['buf'] \
1081             + self.port['buf'] \
1082             + self.zfill \
1083             + self.queue_id['buf']
1084
1085         self.c.parser(buf, 0)
1086
1087     @raises(AssertionError)
1088     def test_parser_check_len(self):
1089         len_ = {'buf': b'\x00\x05', 'val': 5}
1090
1091         buf = self.type_['buf'] \
1092             + len_['buf'] \
1093             + self.port['buf'] \
1094             + self.zfill \
1095             + self.queue_id['buf']
1096
1097         self.c.parser(buf, 0)
1098
1099     def test_serialize(self):
1100         buf = bytearray()
1101         self.c.serialize(buf, 0)
1102
1103         fmt = ofproto.OFP_ACTION_ENQUEUE_PACK_STR
1104         res = struct.unpack(fmt, six.binary_type(buf))
1105
1106         eq_(self.type_['val'], res[0])
1107         eq_(self.len_['val'], res[1])
1108         eq_(self.port['val'], res[2])
1109         eq_(self.queue_id['val'], res[3])
1110
1111
1112 class TestNXActionResubmit(unittest.TestCase):
1113     """ Test case for ofproto_v1_0_parser.NXActionResubmit
1114     """
1115
1116     # NX_ACTION_RESUBMIT_PACK_STR
1117     # '!HHIHHB3x'...type, len, vendor, subtype, in_port, table, zfill
1118     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1119     len_ = {'buf': b'\x00\x10', 'val': ofproto.NX_ACTION_RESUBMIT_SIZE}
1120     vendor = {'buf': b'\x00\x00\x23\x20', 'val': 8992}
1121     subtype = {'buf': b'\x00\x01', 'val': 1}
1122     in_port = {'buf': b'\x0a\x4c', 'val': 2636}
1123     table = {'buf': b'\x52', 'val': 82}
1124     zfill = b'\x00' * 3
1125
1126     buf = type_['buf'] \
1127         + len_['buf'] \
1128         + vendor['buf'] \
1129         + subtype['buf'] \
1130         + in_port['buf'] \
1131         + table['buf'] \
1132         + zfill
1133
1134     c = NXActionResubmit(in_port['val'])
1135
1136     def setUp(self):
1137         pass
1138
1139     def tearDown(self):
1140         pass
1141
1142     def test_init(self):
1143         eq_(self.subtype['val'], self.c.subtype)
1144         eq_(self.in_port['val'], self.c.in_port)
1145
1146     def test_parser(self):
1147         res = OFPActionVendor.parser(self.buf, 0)
1148         eq_(self.type_['val'], res.type)
1149         eq_(self.len_['val'], res.len)
1150         eq_(self.in_port['val'], res.in_port)
1151
1152     def test_serialize(self):
1153         buf = bytearray()
1154         self.c.serialize(buf, 0)
1155
1156         fmt = ofproto.NX_ACTION_RESUBMIT_PACK_STR
1157         res = struct.unpack(fmt, six.binary_type(buf))
1158
1159         eq_(self.type_['val'], res[0])
1160         eq_(self.len_['val'], res[1])
1161         eq_(self.vendor['val'], res[2])
1162         eq_(self.subtype['val'], res[3])
1163         eq_(self.in_port['val'], res[4])
1164
1165
1166 class TestNXActionResubmitTable(unittest.TestCase):
1167     """ Test case for ofproto_v1_0_parser.NXActionResubmitTable
1168     """
1169
1170     # NX_ACTION_RESUBMIT_PACK_STR
1171     # '!HHIHHB3x'...type, len, vendor, subtype, in_port, table, zfill
1172     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1173     len_ = {'buf': b'\x00\x10', 'val': ofproto.NX_ACTION_RESUBMIT_SIZE}
1174     vendor = {'buf': b'\x00\x00\x23\x20', 'val': 8992}
1175     subtype = {'buf': b'\x00\x0e', 'val': 14}
1176     in_port = {'buf': b'\x0a\x4c', 'val': 2636}
1177     table_id = {'buf': b'\x52', 'val': 82}
1178     zfill = b'\x00' * 3
1179
1180     buf = type_['buf'] \
1181         + len_['buf'] \
1182         + vendor['buf'] \
1183         + subtype['buf'] \
1184         + in_port['buf'] \
1185         + table_id['buf'] \
1186         + zfill
1187
1188     c = NXActionResubmitTable(in_port['val'], table_id['val'])
1189
1190     def setUp(self):
1191         pass
1192
1193     def tearDown(self):
1194         pass
1195
1196     def test_init(self):
1197         eq_(self.subtype['val'], self.c.subtype)
1198         eq_(self.in_port['val'], self.c.in_port)
1199         eq_(self.table_id['val'], self.c.table_id)
1200
1201     def test_parser(self):
1202         res = OFPActionVendor.parser(self.buf, 0)
1203         eq_(self.type_['val'], res.type)
1204         eq_(self.len_['val'], res.len)
1205         eq_(self.in_port['val'], res.in_port)
1206         eq_(self.table_id['val'], res.table_id)
1207
1208     def test_serialize(self):
1209         buf = bytearray()
1210         self.c.serialize(buf, 0)
1211
1212         fmt = ofproto.NX_ACTION_RESUBMIT_PACK_STR
1213         res = struct.unpack(fmt, six.binary_type(buf))
1214
1215         eq_(self.type_['val'], res[0])
1216         eq_(self.len_['val'], res[1])
1217         eq_(self.vendor['val'], res[2])
1218         eq_(self.subtype['val'], res[3])
1219         eq_(self.in_port['val'], res[4])
1220         eq_(self.table_id['val'], res[5])
1221
1222
1223 class TestNXActionSetTunnel(unittest.TestCase):
1224     """ Test case for ofproto_v1_0_parser.NXActionSetTunnel
1225     """
1226
1227     # NX_ACTION_SET_TUNNEL_PACK_STR
1228     # '!HHIH2xI'...type, len, vendor, subtype, zfill, tun_id
1229     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1230     len_ = {'buf': b'\x00\x10', 'val': ofproto.NX_ACTION_SET_TUNNEL_SIZE}
1231     vendor = {'buf': b'\x00\x00\x23\x20', 'val': 8992}
1232     subtype = {'buf': b'\x00\x02', 'val': 2}
1233     zfill = b'\x00' * 2
1234     tun_id = {'buf': b'\x01\x6f\x01\xd0', 'val': 24052176}
1235
1236     buf = type_['buf'] \
1237         + len_['buf'] \
1238         + vendor['buf'] \
1239         + subtype['buf'] \
1240         + zfill \
1241         + tun_id['buf']
1242
1243     c = NXActionSetTunnel(tun_id['val'])
1244
1245     def setUp(self):
1246         pass
1247
1248     def tearDown(self):
1249         pass
1250
1251     def test_init(self):
1252         eq_(self.subtype['val'], self.c.subtype)
1253         eq_(self.tun_id['val'], self.c.tun_id)
1254
1255     def test_parse(self):
1256         res = OFPActionVendor.parser(self.buf, 0)
1257         eq_(self.type_['val'], res.type)
1258         eq_(self.len_['val'], res.len)
1259         eq_(self.tun_id['val'], res.tun_id)
1260
1261     def test_serialize(self):
1262         buf = bytearray()
1263         self.c.serialize(buf, 0)
1264
1265         fmt = ofproto.NX_ACTION_SET_TUNNEL_PACK_STR
1266         res = struct.unpack(fmt, six.binary_type(buf))
1267
1268         eq_(self.type_['val'], res[0])
1269         eq_(self.len_['val'], res[1])
1270         eq_(self.vendor['val'], res[2])
1271         eq_(self.subtype['val'], res[3])
1272         eq_(self.tun_id['val'], res[4])
1273
1274
1275 class TestNXActionSetQueue(unittest.TestCase):
1276     """ Test case for ofproto_v1_0_parser.NXActionSetQueue
1277     """
1278
1279     # NX_ACTION_SET_QUEUE_PACK_STR
1280     # '!HHIH2xI'...type, len, vendor, subtype, zfill, queue_id
1281     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1282     len_ = {'buf': b'\x00\x10', 'val': ofproto.NX_ACTION_SET_TUNNEL_SIZE}
1283     vendor = {'buf': b'\x00\x00\x23\x20',
1284               'val': ofproto_common.NX_EXPERIMENTER_ID}
1285     subtype = {'buf': b'\x00\x04', 'val': ofproto.NXAST_SET_QUEUE}
1286     zfill = b'\x00' * 2
1287     queue_id = {'buf': b'\xde\xbe\xc5\x18', 'val': 3737044248}
1288
1289     buf = type_['buf'] \
1290         + len_['buf'] \
1291         + vendor['buf'] \
1292         + subtype['buf'] \
1293         + zfill \
1294         + queue_id['buf']
1295
1296     c = NXActionSetQueue(queue_id['val'])
1297
1298     def setUp(self):
1299         pass
1300
1301     def tearDown(self):
1302         pass
1303
1304     def test_init(self):
1305         eq_(self.subtype['val'], self.c.subtype)
1306         eq_(self.queue_id['val'], self.c.queue_id)
1307
1308     def test_parser(self):
1309         res = OFPActionVendor.parser(self.buf, 0)
1310         eq_(self.type_['val'], res.type)
1311         eq_(self.len_['val'], res.len)
1312         eq_(self.queue_id['val'], res.queue_id)
1313
1314     def test_serialize(self):
1315         buf = bytearray()
1316         self.c.serialize(buf, 0)
1317
1318         fmt = ofproto.NX_ACTION_SET_QUEUE_PACK_STR
1319         res = struct.unpack(fmt, six.binary_type(buf))
1320
1321         eq_(self.type_['val'], res[0])
1322         eq_(self.len_['val'], res[1])
1323         eq_(self.vendor['val'], res[2])
1324         eq_(self.subtype['val'], res[3])
1325         eq_(self.queue_id['val'], res[4])
1326
1327
1328 class TestNXActionPopQueue(unittest.TestCase):
1329     """ Test case for ofproto_v1_0_parser.NXActionPopQueue
1330     """
1331
1332     # NX_ACTION_POP_QUEUE_PACK_STR
1333     # '!HHIH6x'...type, len, vendor, subtype, zfill
1334     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1335     len_ = {'buf': b'\x00\x10', 'val': ofproto.NX_ACTION_SET_TUNNEL_SIZE}
1336     vendor = {'buf': b'\x00\x00\x23\x20',
1337               'val': ofproto_common.NX_EXPERIMENTER_ID}
1338     subtype = {'buf': b'\x00\x05', 'val': ofproto.NXAST_POP_QUEUE}
1339     zfill = b'\x00' * 6
1340
1341     buf = type_['buf'] \
1342         + len_['buf'] \
1343         + vendor['buf'] \
1344         + subtype['buf'] \
1345         + zfill
1346
1347     c = NXActionPopQueue()
1348
1349     def setUp(self):
1350         pass
1351
1352     def tearDown(self):
1353         pass
1354
1355     def test_init(self):
1356         eq_(self.subtype['val'], self.c.subtype)
1357
1358     def test_parser(self):
1359         res = OFPActionVendor.parser(self.buf, 0)
1360         eq_(self.type_['val'], res.type)
1361         eq_(self.len_['val'], res.len)
1362         eq_(self.subtype['val'], res.subtype)
1363
1364     def test_serialize(self):
1365         buf = bytearray()
1366         self.c.serialize(buf, 0)
1367
1368         fmt = ofproto.NX_ACTION_POP_QUEUE_PACK_STR
1369         res = struct.unpack(fmt, six.binary_type(buf))
1370
1371         eq_(self.type_['val'], res[0])
1372         eq_(self.len_['val'], res[1])
1373         eq_(self.vendor['val'], res[2])
1374         eq_(self.subtype['val'], res[3])
1375
1376
1377 class TestNXActionRegMove(unittest.TestCase):
1378     """ Test case for ofproto_v1_0_parser.NXActionRegMove
1379     """
1380
1381     # NX_ACTION_REG_MOVE_PACK_STR
1382     # '!HHIHHHHII'...type_, len_, vendor, subtype, n_bits,
1383     #                src_ofs, dst_ofs, src, dst
1384     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1385     len_ = {'buf': b'\x00\x18', 'val': ofproto.NX_ACTION_REG_MOVE_SIZE}
1386     vendor = {'buf': b'\x00\x00\x23\x20',
1387               'val': ofproto_common.NX_EXPERIMENTER_ID}
1388     subtype = {'buf': b'\x00\x06', 'val': ofproto.NXAST_REG_MOVE}
1389     n_bits = {'buf': b'\x3d\x98', 'val': 15768}
1390     src_ofs = {'buf': b'\xf3\xa3', 'val': 62371}
1391     dst_ofs = {'buf': b'\xdc\x67', 'val': 56423}
1392     src_field = {'buf': b'\x00\x01\x00\x04', 'val': "reg0", "val2": 65540}
1393     dst_field = {'buf': b'\x00\x01\x02\x04', 'val': "reg1", "val2": 66052}
1394
1395     buf = type_['buf'] \
1396         + len_['buf'] \
1397         + vendor['buf'] \
1398         + subtype['buf'] \
1399         + n_bits['buf'] \
1400         + src_ofs['buf'] \
1401         + dst_ofs['buf'] \
1402         + src_field['buf'] \
1403         + dst_field['buf']
1404
1405     c = NXActionRegMove(src_field['val'],
1406                         dst_field['val'],
1407                         n_bits['val'],
1408                         src_ofs['val'],
1409                         dst_ofs['val'])
1410
1411     def setUp(self):
1412         pass
1413
1414     def tearDown(self):
1415         pass
1416
1417     def test_init(self):
1418         eq_(self.subtype['val'], self.c.subtype)
1419         eq_(self.src_field['val'], self.c.src_field)
1420         eq_(self.dst_field['val'], self.c.dst_field)
1421         eq_(self.n_bits['val'], self.c.n_bits)
1422         eq_(self.src_field['val'], self.c.src_field)
1423         eq_(self.dst_field['val'], self.c.dst_field)
1424
1425     def test_parser(self):
1426         res = OFPActionVendor.parser(self.buf, 0)
1427         eq_(self.type_['val'], res.type)
1428         eq_(self.len_['val'], res.len)
1429         eq_(self.subtype['val'], res.subtype)
1430         eq_(self.src_ofs['val'], res.src_ofs)
1431         eq_(self.dst_ofs['val'], res.dst_ofs)
1432         eq_(self.n_bits['val'], res.n_bits)
1433         eq_(self.src_field['val'], res.src_field)
1434         eq_(self.dst_field['val'], res.dst_field)
1435
1436     def test_serialize(self):
1437         buf = bytearray()
1438         self.c.serialize(buf, 0)
1439
1440         fmt = ofproto.NX_ACTION_REG_MOVE_PACK_STR
1441         res = struct.unpack(fmt, six.binary_type(buf))
1442
1443         eq_(self.type_['val'], res[0])
1444         eq_(self.len_['val'], res[1])
1445         eq_(self.vendor['val'], res[2])
1446         eq_(self.subtype['val'], res[3])
1447         eq_(self.n_bits['val'], res[4])
1448         eq_(self.src_ofs['val'], res[5])
1449         eq_(self.dst_ofs['val'], res[6])
1450         eq_(self.src_field['val2'], res[7])
1451         eq_(self.dst_field['val2'], res[8])
1452
1453
1454 class TestNXActionRegLoad(unittest.TestCase):
1455     """ Test case for ofproto_v1_0_parser.NXActionRegLoad
1456     """
1457
1458     # NX_ACTION_REG_LOAD_PACK_STR
1459     # '!HHIHHIQ'...type_, len_, vendor, subtype,
1460     #              ofs_nbits, dst, value
1461     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1462     len_ = {'buf': b'\x00\x18', 'val': ofproto.NX_ACTION_REG_MOVE_SIZE}
1463     vendor = {'buf': b'\x00\x00\x23\x20',
1464               'val': ofproto_common.NX_EXPERIMENTER_ID}
1465     subtype = {'buf': b'\x00\x07', 'val': ofproto.NXAST_REG_LOAD}
1466     ofs_nbits = {'buf': b'\x3d\x98', 'val': 15768}
1467     dst = {'buf': b'\x00\x01\x00\x04', 'val': "reg0", "val2": 65540}
1468     value = {'buf': b'\x33\x51\xcd\x43\x25\x28\x18\x99',
1469              'val': 3697962457317775513}
1470     start = 246
1471     end = 270
1472
1473     buf = type_['buf'] \
1474         + len_['buf'] \
1475         + vendor['buf'] \
1476         + subtype['buf'] \
1477         + ofs_nbits['buf'] \
1478         + dst['buf'] \
1479         + value['buf']
1480
1481     c = NXActionRegLoad(ofs_nbits['val'],
1482                         dst['val'],
1483                         value['val'])
1484
1485     def setUp(self):
1486         pass
1487
1488     def tearDown(self):
1489         pass
1490
1491     def test_init(self):
1492         eq_(self.subtype['val'], self.c.subtype)
1493         eq_(self.ofs_nbits['val'], self.c.ofs_nbits)
1494         eq_(self.dst['val'], self.c.dst)
1495         eq_(self.value['val'], self.c.value)
1496
1497     def test_parser(self):
1498         res = OFPActionVendor.parser(self.buf, 0)
1499         eq_(self.type_['val'], res.type)
1500         eq_(self.len_['val'], res.len)
1501         eq_(self.ofs_nbits['val'], self.c.ofs_nbits)
1502         eq_(self.dst['val'], res.dst)
1503         eq_(self.value['val'], res.value)
1504
1505     def test_serialize(self):
1506         buf = bytearray()
1507         self.c.serialize(buf, 0)
1508
1509         fmt = ofproto.NX_ACTION_REG_LOAD_PACK_STR
1510         res = struct.unpack(fmt, six.binary_type(buf))
1511
1512         eq_(self.type_['val'], res[0])
1513         eq_(self.len_['val'], res[1])
1514         eq_(self.vendor['val'], res[2])
1515         eq_(self.subtype['val'], res[3])
1516         eq_(self.ofs_nbits['val'], res[4])
1517         eq_(self.dst['val2'], res[5])
1518         eq_(self.value['val'], res[6])
1519
1520
1521 class TestNXActionSetTunnel64(unittest.TestCase):
1522     """ Test case for ofproto_v1_0_parser.NXActionSetTunnel64
1523     """
1524
1525     # NX_ACTION_SET_TUNNEL64_PACK_STR
1526     # '!HHIH6xQ'...type, len, vendor, subtype, zfill, tun_id
1527     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1528     len_ = {'buf': b'\x00\x18', 'val': ofproto.NX_ACTION_SET_TUNNEL64_SIZE}
1529     vendor = {'buf': b'\x00\x00\x23\x20',
1530               'val': ofproto_common.NX_EXPERIMENTER_ID}
1531     subtype = {'buf': b'\x00\x09', 'val': ofproto.NXAST_SET_TUNNEL64}
1532     zfill = b'\x00' * 6
1533     tun_id = {'buf': b'\x6e\x01\xa6\xea\x7e\x36\x1d\xd9',
1534               'val': 7926800345218817497}
1535
1536     buf = type_['buf'] \
1537         + len_['buf'] \
1538         + vendor['buf'] \
1539         + subtype['buf'] \
1540         + zfill \
1541         + tun_id['buf']
1542
1543     c = NXActionSetTunnel64(tun_id['val'])
1544
1545     def setUp(self):
1546         pass
1547
1548     def tearDown(self):
1549         pass
1550
1551     def test_init(self):
1552         eq_(self.subtype['val'], self.c.subtype)
1553         eq_(self.tun_id['val'], self.c.tun_id)
1554
1555     def test_parser(self):
1556         res = OFPActionVendor.parser(self.buf, 0)
1557         eq_(self.type_['val'], res.type)
1558         eq_(self.len_['val'], res.len)
1559         eq_(self.subtype['val'], res.subtype)
1560         eq_(self.tun_id['val'], res.tun_id)
1561
1562     def test_serialize(self):
1563         buf = bytearray()
1564         self.c.serialize(buf, 0)
1565
1566         fmt = ofproto.NX_ACTION_SET_TUNNEL64_PACK_STR
1567         res = struct.unpack(fmt, six.binary_type(buf))
1568
1569         eq_(self.type_['val'], res[0])
1570         eq_(self.len_['val'], res[1])
1571         eq_(self.vendor['val'], res[2])
1572         eq_(self.subtype['val'], res[3])
1573         eq_(self.tun_id['val'], res[4])
1574
1575
1576 class TestNXActionMultipath(unittest.TestCase):
1577     """ Test case for ofproto_v1_0_parser.NXActionMultipath
1578     """
1579
1580     # NX_ACTION_MULTIPATH_PACK_STR
1581     # '!HHIHHH2xHHI2xHI'...type, len, vendor, subtype, fields, basis, zfill
1582     #                      algorithm, max_link, arg, zfill, ofs_nbits, dst
1583     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1584     len_ = {'buf': b'\x00\x20', 'val': ofproto.NX_ACTION_MULTIPATH_SIZE}
1585     vendor = {'buf': b'\x00\x00\x23\x20',
1586               'val': ofproto_common.NX_EXPERIMENTER_ID}
1587     subtype = {'buf': b'\x00\x0a', 'val': ofproto.NXAST_MULTIPATH}
1588     fields = {'buf': b'\x6d\xf5', 'val': 28149}
1589     basis = {'buf': b'\x7c\x0a', 'val': 31754}
1590     zfill0 = b'\x00' * 2
1591     algorithm = {'buf': b'\x82\x1d', 'val': 33309}
1592     max_link = {'buf': b'\x06\x2b', 'val': 1579}
1593     arg = {'buf': b'\x18\x79\x41\xc8', 'val': 410599880}
1594     zfill1 = b'\x00' * 2
1595     ofs_nbits = {'buf': b'\xa9\x9a', 'val': 43418}
1596     dst = {'buf': b'\x00\x01\x00\x04', 'val': "reg0", 'val2': 65540}
1597     start = 678
1598     end = 704
1599
1600     buf = type_['buf'] \
1601         + len_['buf'] \
1602         + vendor['buf'] \
1603         + subtype['buf'] \
1604         + fields['buf'] \
1605         + basis['buf'] \
1606         + zfill0 \
1607         + algorithm['buf'] \
1608         + max_link['buf'] \
1609         + arg['buf'] \
1610         + zfill1 \
1611         + ofs_nbits['buf'] \
1612         + dst['buf']
1613
1614     c = NXActionMultipath(fields['val'],
1615                           basis['val'],
1616                           algorithm['val'],
1617                           max_link['val'],
1618                           arg['val'],
1619                           ofs_nbits['val'],
1620                           dst['val'])
1621
1622     def setUp(self):
1623         pass
1624
1625     def tearDown(self):
1626         pass
1627
1628     def test_init(self):
1629         eq_(self.subtype['val'], self.c.subtype)
1630         eq_(self.fields['val'], self.c.fields)
1631         eq_(self.basis['val'], self.c.basis)
1632         eq_(self.algorithm['val'], self.c.algorithm)
1633         eq_(self.max_link['val'], self.c.max_link)
1634         eq_(self.arg['val'], self.c.arg)
1635         eq_(self.ofs_nbits['val'], self.c.ofs_nbits)
1636         eq_(self.dst['val'], self.c.dst)
1637
1638     def test_parser(self):
1639         res = OFPActionVendor.parser(self.buf, 0)
1640         eq_(self.type_['val'], res.type)
1641         eq_(self.len_['val'], res.len)
1642         eq_(self.subtype['val'], res.subtype)
1643         eq_(self.fields['val'], res.fields)
1644         eq_(self.basis['val'], res.basis)
1645         eq_(self.algorithm['val'], res.algorithm)
1646         eq_(self.max_link['val'], res.max_link)
1647         eq_(self.arg['val'], res.arg)
1648         eq_(self.ofs_nbits['val'], res.ofs_nbits)
1649         eq_(self.dst['val'], res.dst)
1650
1651     def test_serialize(self):
1652         buf = bytearray()
1653         self.c.serialize(buf, 0)
1654
1655         fmt = ofproto.NX_ACTION_MULTIPATH_PACK_STR
1656         res = struct.unpack(fmt, six.binary_type(buf))
1657
1658         eq_(self.type_['val'], res[0])
1659         eq_(self.len_['val'], res[1])
1660         eq_(self.vendor['val'], res[2])
1661         eq_(self.subtype['val'], res[3])
1662         eq_(self.fields['val'], res[4])
1663         eq_(self.basis['val'], res[5])
1664         eq_(self.algorithm['val'], res[6])
1665         eq_(self.max_link['val'], res[7])
1666         eq_(self.arg['val'], res[8])
1667         eq_(self.ofs_nbits['val'], res[9])
1668         eq_(self.dst['val2'], res[10])
1669
1670
1671 class TestNXActionBundle(unittest.TestCase):
1672     """ Test case for ofproto_v1_0_parser.NXActionBundle
1673     """
1674
1675     # NX_ACTION_BUNDLE_PACK_STR
1676     # '!HHIHHHHIHHI4x'...type, len, vendor, subtype, algorithm,
1677     #                    fields, basis, slave_type, n_slaves,
1678     #                    ofs_nbits, dst, zfill
1679     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1680     len_ = {'buf': b'\x00\x28', 'val': (ofproto.NX_ACTION_BUNDLE_SIZE + 8)}
1681     vendor = {'buf': b'\x00\x00\x23\x20',
1682               'val': ofproto_common.NX_EXPERIMENTER_ID}
1683     subtype = {'buf': b'\x00\x0c', 'val': ofproto.NXAST_BUNDLE}
1684     algorithm = {'buf': b'\x51\xa7', 'val': 20903}
1685     fields = {'buf': b'\xf8\xef', 'val': 63727}
1686     basis = {'buf': b'\xfd\x6f', 'val': 64879}
1687     slave_type = {'buf': b'\x7c\x51\x0f\xe0', 'val': 2085687264}
1688     n_slaves = {'buf': b'\x00\x02', 'val': 2}
1689     ofs_nbits = {'buf': b'\x00\x00', 'val': 0}
1690     dst = {'buf': b'\x00\x00\x00\x00', 'val': 0}
1691     zfill = b'\x00' * 4
1692
1693     slaves_buf = (b'\x00\x01', b'\x00\x02')
1694     slaves_val = (1, 2)
1695
1696     _len = len_['val'] + len(slaves_val) * 2
1697     _len += (_len % 8)
1698
1699     buf = type_['buf'] \
1700         + len_['buf'] \
1701         + vendor['buf'] \
1702         + subtype['buf'] \
1703         + algorithm['buf'] \
1704         + fields['buf'] \
1705         + basis['buf'] \
1706         + slave_type['buf'] \
1707         + n_slaves['buf'] \
1708         + ofs_nbits['buf'] \
1709         + dst['buf'] \
1710         + zfill \
1711         + slaves_buf[0] \
1712         + slaves_buf[1]
1713
1714     c = NXActionBundle(algorithm['val'],
1715                        fields['val'],
1716                        basis['val'],
1717                        slave_type['val'],
1718                        n_slaves['val'],
1719                        ofs_nbits['val'],
1720                        dst['val'],
1721                        slaves_val)
1722
1723     def setUp(self):
1724         pass
1725
1726     def tearDown(self):
1727         pass
1728
1729     def test_init(self):
1730         eq_(self.subtype['val'], self.c.subtype)
1731         eq_(self.algorithm['val'], self.c.algorithm)
1732         eq_(self.fields['val'], self.c.fields)
1733         eq_(self.basis['val'], self.c.basis)
1734         eq_(self.slave_type['val'], self.c.slave_type)
1735         eq_(self.n_slaves['val'], self.c.n_slaves)
1736         eq_(self.ofs_nbits['val'], self.c.ofs_nbits)
1737         eq_(self.dst['val'], self.c.dst)
1738
1739         # slaves
1740         slaves = self.c.slaves
1741         eq_(self.slaves_val[0], slaves[0])
1742         eq_(self.slaves_val[1], slaves[1])
1743
1744     def test_parser(self):
1745         res = OFPActionVendor.parser(self.buf, 0)
1746         eq_(self.type_['val'], res.type)
1747         eq_(self.len_['val'], res.len)
1748         eq_(self.subtype['val'], res.subtype)
1749         eq_(self.algorithm['val'], res.algorithm)
1750         eq_(self.fields['val'], res.fields)
1751         eq_(self.basis['val'], res.basis)
1752         eq_(self.slave_type['val'], res.slave_type)
1753         eq_(self.n_slaves['val'], res.n_slaves)
1754         eq_(self.ofs_nbits['val'], res.ofs_nbits)
1755         eq_(self.dst['val'], res.dst)
1756
1757         # slaves
1758         slaves = res.slaves
1759         eq_(self.slaves_val[0], slaves[0])
1760         eq_(self.slaves_val[1], slaves[1])
1761
1762     def test_serialize(self):
1763         buf = bytearray()
1764         self.c.serialize(buf, 0)
1765
1766         fmt = '!' \
1767             + ofproto.NX_ACTION_BUNDLE_PACK_STR.replace('!', '') \
1768             + 'HH4x'
1769
1770         res = struct.unpack(fmt, six.binary_type(buf))
1771
1772         eq_(self.type_['val'], res[0])
1773         eq_(self.len_['val'], res[1])
1774         eq_(self.vendor['val'], res[2])
1775         eq_(self.subtype['val'], res[3])
1776         eq_(self.algorithm['val'], res[4])
1777         eq_(self.fields['val'], res[5])
1778         eq_(self.basis['val'], res[6])
1779         eq_(self.slave_type['val'], res[7])
1780         eq_(self.n_slaves['val'], res[8])
1781         eq_(self.ofs_nbits['val'], res[9])
1782         eq_(self.dst['val'], res[10])
1783
1784
1785 class TestNXActionBundleLoad(unittest.TestCase):
1786     """ Test case for ofproto_v1_0_parser.NXActionBundleLoad
1787     """
1788
1789     # NX_ACTION_BUNDLE_PACK_STR
1790     # '!HHIHHHHIHHI4x'...type, len, vendor, subtype, algorithm,
1791     #                    fields, basis, slave_type, n_slaves,
1792     #                    ofs_nbits, dst, zfill
1793     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1794     len_ = {'buf': b'\x00\x28', 'val': (ofproto.NX_ACTION_BUNDLE_SIZE + 8)}
1795     vendor = {'buf': b'\x00\x00\x23\x20',
1796               'val': ofproto_common.NX_EXPERIMENTER_ID}
1797     subtype = {'buf': b'\x00\x0d', 'val': ofproto.NXAST_BUNDLE_LOAD}
1798     algorithm = {'buf': b'\x83\x15', 'val': 33557}
1799     fields = {'buf': b'\xc2\x7a', 'val': 49786}
1800     basis = {'buf': b'\x86\x18', 'val': 34328}
1801     slave_type = {'buf': b'\x18\x42\x0b\x55', 'val': 406981461}
1802     n_slaves = {'buf': b'\x00\x02', 'val': 2}
1803     ofs_nbits = {'buf': b'\xd2\x9d', 'val': 53917}
1804     dst = {'buf': b'\x00\x01\x00\x04', 'val': "reg0", 'val2': 65540}
1805     zfill = b'\x00' * 4
1806
1807     slaves_buf = (b'\x00\x01', b'\x00\x02')
1808     slaves_val = (1, 2)
1809
1810     _len = len_['val'] + len(slaves_val) * 2
1811     _len += (_len % 8)
1812
1813     buf = type_['buf'] \
1814         + len_['buf'] \
1815         + vendor['buf'] \
1816         + subtype['buf'] \
1817         + algorithm['buf'] \
1818         + fields['buf'] \
1819         + basis['buf'] \
1820         + slave_type['buf'] \
1821         + n_slaves['buf'] \
1822         + ofs_nbits['buf'] \
1823         + dst['buf'] \
1824         + zfill \
1825         + slaves_buf[0] \
1826         + slaves_buf[1]
1827
1828     c = NXActionBundleLoad(algorithm['val'],
1829                            fields['val'],
1830                            basis['val'],
1831                            slave_type['val'],
1832                            n_slaves['val'],
1833                            ofs_nbits['val'],
1834                            dst['val'],
1835                            slaves_val)
1836
1837     def setUp(self):
1838         pass
1839
1840     def tearDown(self):
1841         pass
1842
1843     def test_init(self):
1844         eq_(self.subtype['val'], self.c.subtype)
1845         eq_(self.algorithm['val'], self.c.algorithm)
1846         eq_(self.fields['val'], self.c.fields)
1847         eq_(self.basis['val'], self.c.basis)
1848         eq_(self.slave_type['val'], self.c.slave_type)
1849         eq_(self.n_slaves['val'], self.c.n_slaves)
1850         eq_(self.ofs_nbits['val'], self.c.ofs_nbits)
1851         eq_(self.dst['val'], self.c.dst)
1852
1853         # slaves
1854         slaves = self.c.slaves
1855         eq_(self.slaves_val[0], slaves[0])
1856         eq_(self.slaves_val[1], slaves[1])
1857
1858     def test_parser(self):
1859         res = OFPActionVendor.parser(self.buf, 0)
1860         eq_(self.type_['val'], res.type)
1861         eq_(self.len_['val'], res.len)
1862         eq_(self.subtype['val'], res.subtype)
1863         eq_(self.algorithm['val'], res.algorithm)
1864         eq_(self.fields['val'], res.fields)
1865         eq_(self.basis['val'], res.basis)
1866         eq_(self.slave_type['val'], res.slave_type)
1867         eq_(self.n_slaves['val'], res.n_slaves)
1868         eq_(self.ofs_nbits['val'], res.ofs_nbits)
1869         eq_(self.dst['val'], res.dst)
1870
1871         # slaves
1872         slaves = res.slaves
1873         eq_(self.slaves_val[0], slaves[0])
1874         eq_(self.slaves_val[1], slaves[1])
1875
1876     def test_serialize(self):
1877         buf = bytearray()
1878         self.c.serialize(buf, 0)
1879
1880         fmt = '!' \
1881             + ofproto.NX_ACTION_BUNDLE_PACK_STR.replace('!', '') \
1882             + 'HH4x'
1883
1884         res = struct.unpack(fmt, six.binary_type(buf))
1885
1886         eq_(self.type_['val'], res[0])
1887         eq_(self.len_['val'], res[1])
1888         eq_(self.vendor['val'], res[2])
1889         eq_(self.subtype['val'], res[3])
1890         eq_(self.algorithm['val'], res[4])
1891         eq_(self.fields['val'], res[5])
1892         eq_(self.basis['val'], res[6])
1893         eq_(self.slave_type['val'], res[7])
1894         eq_(self.n_slaves['val'], res[8])
1895         eq_(self.ofs_nbits['val'], res[9])
1896         eq_(self.dst['val2'], res[10])
1897
1898
1899 class TestNXActionOutputReg(unittest.TestCase):
1900     """ Test case for ofproto_v1_0_parser.NXActionOutputReg
1901     """
1902
1903     # NX_ACTION_OUTPUT_REG_PACK_STR
1904     # '!HHIHHIH6x'...type, len, vendor, subtype, ofs_nbits,
1905     #                    src, max_len, zfill
1906     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1907     len_ = {'buf': b'\x00\x18', 'val': ofproto.NX_ACTION_OUTPUT_REG_SIZE}
1908     vendor = {'buf': b'\x00\x00\x23\x20',
1909               'val': ofproto_common.NX_EXPERIMENTER_ID}
1910     subtype = {'buf': b'\x00\x0f', 'val': ofproto.NXAST_OUTPUT_REG}
1911     ofs_nbits = {'buf': b'\xfe\x78', 'val': 65144}
1912     src = {'buf': b'\x00\x01\x00\x04', 'val': "reg0", 'val2': 65540}
1913     max_len = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_OUTPUT_SIZE}
1914     zfill = b'\x00' * 6
1915
1916     buf = type_['buf'] \
1917         + len_['buf'] \
1918         + vendor['buf'] \
1919         + subtype['buf'] \
1920         + ofs_nbits['buf'] \
1921         + src['buf'] \
1922         + max_len['buf'] \
1923         + zfill
1924
1925     c = NXActionOutputReg(ofs_nbits['val'],
1926                           src['val'],
1927                           max_len['val'])
1928
1929     def setUp(self):
1930         pass
1931
1932     def tearDown(self):
1933         pass
1934
1935     def test_init(self):
1936         eq_(self.subtype['val'], self.c.subtype)
1937         eq_(self.ofs_nbits['val'], self.c.ofs_nbits)
1938         eq_(self.src['val'], self.c.src)
1939         eq_(self.max_len['val'], self.c.max_len)
1940
1941     def test_parser(self):
1942         res = OFPActionVendor.parser(self.buf, 0)
1943         eq_(self.type_['val'], res.type)
1944         eq_(self.len_['val'], res.len)
1945         eq_(self.subtype['val'], res.subtype)
1946         eq_(self.ofs_nbits['val'], self.c.ofs_nbits)
1947         eq_(self.src['val'], res.src)
1948         eq_(self.max_len['val'], res.max_len)
1949
1950     def test_serialize(self):
1951         buf = bytearray()
1952         self.c.serialize(buf, 0)
1953
1954         fmt = ofproto.NX_ACTION_OUTPUT_REG_PACK_STR
1955         res = struct.unpack(fmt, six.binary_type(buf))
1956
1957         eq_(self.type_['val'], res[0])
1958         eq_(self.len_['val'], res[1])
1959         eq_(self.vendor['val'], res[2])
1960         eq_(self.subtype['val'], res[3])
1961         eq_(self.ofs_nbits['val'], res[4])
1962         eq_(self.src['val2'], res[5])
1963         eq_(self.max_len['val'], res[6])
1964
1965
1966 class TestNXActionExit(unittest.TestCase):
1967     """ Test case for ofproto_v1_0_parser.NXActionExit
1968     """
1969
1970     # NX_ACTION_HEADER_PACK_STR
1971     # '!HHIH'...type, len, vendor, subtype
1972     type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPAT_VENDOR}
1973     len_ = {'buf': b'\x00\x10', 'val': ofproto.NX_ACTION_HEADER_SIZE}
1974     vendor = {'buf': b'\x00\x00\x23\x20',
1975               'val': ofproto_common.NX_EXPERIMENTER_ID}
1976     subtype = {'buf': b'\x00\x11', 'val': ofproto.NXAST_EXIT}
1977     zfill = b'\x00' * 6
1978
1979     buf = type_['buf'] \
1980         + len_['buf'] \
1981         + vendor['buf'] \
1982         + subtype['buf'] \
1983         + zfill
1984
1985     c = NXActionExit()
1986
1987     def setUp(self):
1988         pass
1989
1990     def tearDown(self):
1991         pass
1992
1993     def test_init(self):
1994         eq_(self.subtype['val'], self.c.subtype)
1995
1996     def test_parser(self):
1997         res = OFPActionVendor.parser(self.buf, 0)
1998         eq_(self.type_['val'], res.type)
1999         eq_(self.len_['val'], res.len)
2000         eq_(self.subtype['val'], res.subtype)
2001
2002     def test_serialize(self):
2003         buf = bytearray()
2004         self.c.serialize(buf, 0)
2005
2006         fmt = ofproto.NX_ACTION_HEADER_PACK_STR
2007         res = struct.unpack(fmt, six.binary_type(buf))
2008
2009         eq_(self.type_['val'], res[0])
2010         eq_(self.len_['val'], res[1])
2011         eq_(self.vendor['val'], res[2])
2012         eq_(self.subtype['val'], res[3])
2013
2014
2015 class TestOFPDescStats(unittest.TestCase):
2016     """ Test case for ofproto_v1_0_parser.OFPDescStats
2017     """
2018
2019     # OFP_DESC_STATS_PACK_STR
2020     # '!256s256s256s32s256s'...mfr_desc, hw_desc, sw_desc, serial_num, dp_desc
2021     mfr_desc = b'mfr_desc'.ljust(256)
2022     hw_desc = b'hw_desc'.ljust(256)
2023     sw_desc = b'sw_desc'.ljust(256)
2024     serial_num = b'serial_num'.ljust(32)
2025     dp_desc = b'dp_desc'.ljust(256)
2026
2027     buf = mfr_desc \
2028         + hw_desc \
2029         + sw_desc \
2030         + serial_num \
2031         + dp_desc
2032
2033     c = OFPDescStats(mfr_desc, hw_desc, sw_desc, serial_num, dp_desc)
2034
2035     def setUp(self):
2036         pass
2037
2038     def tearDown(self):
2039         pass
2040
2041     def test_init(self):
2042         eq_(self.mfr_desc, self.c.mfr_desc)
2043         eq_(self.hw_desc, self.c.hw_desc)
2044         eq_(self.sw_desc, self.c.sw_desc)
2045         eq_(self.serial_num, self.c.serial_num)
2046         eq_(self.dp_desc, self.c.dp_desc)
2047
2048     def test_parser(self):
2049         res = self.c.parser(self.buf, 0)
2050
2051         eq_(self.mfr_desc, self.mfr_desc)
2052         eq_(self.hw_desc, self.hw_desc)
2053         eq_(self.sw_desc, self.sw_desc)
2054         eq_(self.serial_num, self.serial_num)
2055         eq_(self.dp_desc, self.dp_desc)
2056
2057
2058 class TestOFPFlowStats(unittest.TestCase):
2059     """ Test case for ofproto_v1_0_parser.OFPFlowStats
2060     """
2061
2062     # OFP_FLOW_STATS_0_PACK_STR
2063     # '!HBx'...length, table_id, zfill
2064     length = {'buf': b'\x00\x58', 'val': 88}
2065     length_append_action = {'buf': b'\x00\x60', 'val': 96}
2066     table_id = {'buf': b'\x51', 'val': 81}
2067     zfill_0 = b'\x00'
2068
2069     # OFP_MATCH_PACK_STR
2070     # '!IH6s6sHBxHBB2xIIHH'...
2071     match = b'\x97\x7c\xa6\x1e' \
2072         + b'\x5e\xa0' \
2073         + b'\x7a\x3e\xed\x30\x4a\x90' \
2074         + b'\x96\x8e\x67\xbe\x2f\xe2' \
2075         + b'\xb1\x81' \
2076         + b'\xbe' \
2077         + b'\x00' \
2078         + b'\x01\xab' \
2079         + b'\x42' \
2080         + b'\xfe' \
2081         + b'\x00\x00' \
2082         + b'\xa4\x5d\x5c\x42' \
2083         + b'\xa2\x5c\x2e\x05' \
2084         + b'\x5a\x94' \
2085         + b'\x64\xd4'
2086
2087     # OFP_FLOW_STATS_1_PACK_STR
2088     # '!IIHHH6xQQQ'...duration_sec, duration_nsec, priority,
2089     #                 idle_timeout, hard_timeout, zfill,
2090     #                 cookie, packet_count, byte_count
2091     duration_sec = {'buf': b'\x94\x19\xb3\xd2', 'val': 2484712402}
2092     duration_nsec = {'buf': b'\xee\x66\xcf\x7c', 'val': 3999715196}
2093     priority = {'buf': b'\xe1\xc0', 'val': 57792}
2094     idle_timeout = {'buf': b'\x8e\x10', 'val': 36368}
2095     hard_timeout = {'buf': b'\xd4\x99', 'val': 54425}
2096     zfill_1 = b'\x00\x00\x00\x00\x00\x00'
2097     cookie = {'buf': b'\x0b\x01\xe8\xe5\xf0\x84\x8a\xe0',
2098               'val': 793171083674290912}
2099     packet_count = {'buf': b'\x47\x5c\xc6\x05\x28\xff\x7c\xdb',
2100                     'val': 5142202600015232219}
2101     byte_count = {'buf': b'\x24\xe9\x4b\xee\xcb\x57\xd9\xc3',
2102                   'val': 2659740543924820419}
2103
2104     # <action>_PACK_STR...type_, len_ [others...]
2105     type = {'buf': b'\x00\x00', 'val': ofproto.OFPAT_OUTPUT}
2106     len = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_OUTPUT_SIZE}
2107     port = {'buf': b'\x59\x2a', 'val': 22826}
2108     max_len = {'buf': b'\x00\x08', 'val': ofproto.OFP_ACTION_OUTPUT_SIZE}
2109     action = (type, len, port, max_len)
2110
2111     ACTION_TYPE = 0
2112     ACTION_LEN = 1
2113     ACTION_PORT = 2
2114     ACTION_MAX_LEN = 3
2115
2116     c = OFPFlowStats()
2117
2118     def setUp(self):
2119         pass
2120
2121     def tearDown(self):
2122         pass
2123
2124     def test_init(self):
2125         pass
2126
2127     def _parser(self, action=None):
2128         buf = self.table_id['buf'] \
2129             + self.zfill_0 \
2130             + self.match \
2131             + self.duration_sec['buf'] \
2132             + self.duration_nsec['buf'] \
2133             + self.priority['buf'] \
2134             + self.idle_timeout['buf'] \
2135             + self.hard_timeout['buf'] \
2136             + self.zfill_1 \
2137             + self.cookie['buf'] \
2138             + self.packet_count['buf'] \
2139             + self.byte_count['buf']
2140
2141         if not action:
2142             buf = self.length['buf'] + buf
2143         else:
2144             buf = self.length_append_action['buf'] + buf
2145
2146             for a in self.action:
2147                 buf = buf + a['buf']
2148
2149         return self.c.parser(buf, 0)
2150
2151     def test_parser(self):
2152         res = self._parser()
2153
2154         eq_(self.length['val'], res.length)
2155         eq_(self.table_id['val'], res.table_id)
2156         eq_(self.duration_sec['val'], res.duration_sec)
2157         eq_(self.duration_nsec['val'], res.duration_nsec)
2158         eq_(self.priority['val'], res.priority)
2159         eq_(self.idle_timeout['val'], res.idle_timeout)
2160         eq_(self.hard_timeout['val'], res.hard_timeout)
2161         eq_(self.cookie['val'], res.cookie)
2162         eq_(self.packet_count['val'], res.packet_count)
2163         eq_(self.byte_count['val'], res.byte_count)
2164
2165     def test_parser_append_actions(self):
2166         res = self._parser(True).actions[0]
2167
2168         eq_(self.action[self.ACTION_TYPE]['val'], res.type)
2169         eq_(self.action[self.ACTION_LEN]['val'], res.len)
2170         eq_(self.action[self.ACTION_PORT]['val'], res.port)
2171         eq_(self.action[self.ACTION_MAX_LEN]['val'], res.max_len)
2172
2173
2174 class TestOFPAggregateStats(unittest.TestCase):
2175     """ Test case for ofproto_v1_0_parser.OFPAggregateStats
2176     """
2177
2178     # OFP_AGGREGATE_STATS_REPLY_PACK_STR
2179     # '!QQI4x'...packet_count, byte_count, flow_count, zfill
2180     packet_count = {'buf': b'\x43\x95\x1b\xfb\x0f\xf6\xa7\xdd',
2181                     'val': 4869829337189623773}
2182     byte_count = {'buf': b'\x36\xda\x2d\x80\x2a\x95\x35\xdd',
2183                   'val': 3952521651464517085}
2184     flow_count = {'buf': b'\xc3\x0d\xc3\xed', 'val': 3272459245}
2185     zfill = b'\x00' * 4
2186
2187     buf = packet_count['buf'] \
2188         + byte_count['buf'] \
2189         + flow_count['buf'] \
2190         + zfill
2191
2192     c = OFPAggregateStats(packet_count['val'],
2193                           byte_count['val'],
2194                           flow_count['val'])
2195
2196     def setUp(self):
2197         pass
2198
2199     def tearDown(self):
2200         pass
2201
2202     def test_init(self):
2203         eq_(self.packet_count['val'], self.c.packet_count)
2204         eq_(self.byte_count['val'], self.c.byte_count)
2205         eq_(self.flow_count['val'], self.c.flow_count)
2206
2207     def test_parser(self):
2208
2209         res = self.c.parser(self.buf, 0)
2210
2211         eq_(self.packet_count['val'], res.packet_count)
2212         eq_(self.byte_count['val'], res.byte_count)
2213         eq_(self.flow_count['val'], res.flow_count)
2214
2215
2216 class TestOFPTableStats(unittest.TestCase):
2217     """ Test case for ofproto_v1_0_parser.OFPTableStats
2218     """
2219
2220     # OFP_TABLE_STATS_PACK_STR
2221     # '!B3x32sIIIQQ'...table_id, zfill, name, wildcards, max_entries,
2222     #                  active_count, lookup_count, matched_count
2223     table_id = {'buf': b'\x5b', 'val': 91}
2224     zfill = b'\x00' * 3
2225     name = b'name'.ljust(32)
2226     wildcards = {'buf': b'\xc5\xaf\x6e\x12', 'val': 3316608530}
2227     max_entries = {'buf': b'\x95\x6c\x78\x4d', 'val': 2506913869}
2228     active_count = {'buf': b'\x78\xac\xa8\x1e', 'val': 2024581150}
2229     lookup_count = {'buf': b'\x40\x1d\x9c\x39\x19\xec\xd4\x1c',
2230                     'val': 4620020561814017052}
2231     matched_count = {'buf': b'\x27\x35\x02\xb6\xc5\x5e\x17\x65',
2232                      'val': 2825167325263435621}
2233
2234     buf = table_id['buf'] \
2235         + zfill \
2236         + name \
2237         + wildcards['buf'] \
2238         + max_entries['buf'] \
2239         + active_count['buf'] \
2240         + lookup_count['buf'] \
2241         + matched_count['buf']
2242
2243     c = OFPTableStats(table_id['val'],
2244                       name,
2245                       wildcards['val'],
2246                       max_entries['val'],
2247                       active_count['val'],
2248                       lookup_count['val'],
2249                       matched_count['val'])
2250
2251     def setUp(self):
2252         pass
2253
2254     def tearDown(self):
2255         pass
2256
2257     def test_init(self):
2258         eq_(self.table_id['val'], self.c.table_id)
2259         eq_(self.name, self.c.name)
2260         eq_(self.wildcards['val'], self.c.wildcards)
2261         eq_(self.max_entries['val'], self.c.max_entries)
2262         eq_(self.active_count['val'], self.c.active_count)
2263         eq_(self.lookup_count['val'], self.c.lookup_count)
2264         eq_(self.matched_count['val'], self.c.matched_count)
2265
2266     def test_parser(self):
2267         res = self.c.parser(self.buf, 0)
2268
2269         eq_(self.table_id['val'], res.table_id)
2270         eq_(self.name, res.name)
2271         eq_(self.wildcards['val'], res.wildcards)
2272         eq_(self.max_entries['val'], res.max_entries)
2273         eq_(self.active_count['val'], res.active_count)
2274         eq_(self.lookup_count['val'], res.lookup_count)
2275         eq_(self.matched_count['val'], res.matched_count)
2276
2277
2278 class TestOFPPortStats(unittest.TestCase):
2279     """ Test case for ofproto_v1_0_parser.OFPPortStats
2280     """
2281
2282     # OFP_PORT_STATS_PACK_STR
2283     # '!H6xQQQQQQQQQQQQ'... port_no, zfill, rx_packets, tx_packets,
2284     #                       rx_bytes, tx_bytes, rx_dropped, tx_dropped,
2285     #                       rx_errors, tx_errors, rx_frame_err,
2286     #                       rx_over_err, rx_crc_err, collisions
2287     port_no = {'buf': b'\xe7\x6b', 'val': 59243}
2288     zfill = b'\x00' * 6
2289     rx_packets = {'buf': b'\x53\x44\x36\x61\xc4\x86\xc0\x37',
2290                   'val': 5999980397101236279}
2291     tx_packets = {'buf': b'\x27\xa4\x41\xd7\xd4\x53\x9e\x42',
2292                   'val': 2856480458895760962}
2293     rx_bytes = {'buf': b'\x55\xa1\x38\x60\x43\x97\x0d\x89',
2294                 'val': 6170274950576278921}
2295     tx_bytes = {'buf': b'\x77\xe1\xd5\x63\x18\xae\x63\xaa',
2296                 'val': 8638420181865882538}
2297     rx_dropped = {'buf': b'\x60\xe6\x20\x01\x24\xda\x4e\x5a',
2298                   'val': 6982303461569875546}
2299     tx_dropped = {'buf': b'\x09\x2d\x5d\x71\x71\xb6\x8e\xc7',
2300                   'val': 661287462113808071}
2301     rx_errors = {'buf': b'\x2f\x7e\x35\xb3\x66\x3c\x19\x0d',
2302                  'val': 3422231811478788365}
2303     tx_errors = {'buf': b'\x57\x32\x08\x2f\x88\x32\x40\x6b',
2304                  'val': 6283093430376743019}
2305     rx_frame_err = {'buf': b'\x0c\x28\x6f\xad\xce\x66\x6e\x8b',
2306                     'val': 876072919806406283}
2307     rx_over_err = {'buf': b'\x5a\x90\x8f\x9b\xfc\x82\x2e\xa0',
2308                    'val': 6525873760178941600}
2309     rx_crc_err = {'buf': b'\x73\x3a\x71\x17\xd6\x74\x69\x47',
2310                   'val': 8303073210207070535}
2311     collisions = {'buf': b'\x2f\x52\x0c\x79\x96\x03\x6e\x79',
2312                   'val': 3409801584220270201}
2313
2314     buf = port_no['buf'] \
2315         + zfill \
2316         + rx_packets['buf'] \
2317         + tx_packets['buf'] \
2318         + rx_bytes['buf'] \
2319         + tx_bytes['buf'] \
2320         + rx_dropped['buf'] \
2321         + tx_dropped['buf'] \
2322         + rx_errors['buf'] \
2323         + tx_errors['buf'] \
2324         + rx_frame_err['buf'] \
2325         + rx_over_err['buf'] \
2326         + rx_crc_err['buf'] \
2327         + collisions['buf']
2328
2329     c = OFPPortStats(port_no['val'],
2330                      rx_packets['val'],
2331                      tx_packets['val'],
2332                      rx_bytes['val'],
2333                      tx_bytes['val'],
2334                      rx_dropped['val'],
2335                      tx_dropped['val'],
2336                      rx_errors['val'],
2337                      tx_errors['val'],
2338                      rx_frame_err['val'],
2339                      rx_over_err['val'],
2340                      rx_crc_err['val'],
2341                      collisions['val'])
2342
2343     def setUp(self):
2344         pass
2345
2346     def tearDown(self):
2347         pass
2348
2349     def test_init(self):
2350         eq_(self.port_no['val'], self.c.port_no)
2351         eq_(self.rx_packets['val'], self.c.rx_packets)
2352         eq_(self.tx_packets['val'], self.c.tx_packets)
2353         eq_(self.rx_bytes['val'], self.c.rx_bytes)
2354         eq_(self.tx_bytes['val'], self.c.tx_bytes)
2355         eq_(self.rx_dropped['val'], self.c.rx_dropped)
2356         eq_(self.tx_dropped['val'], self.c.tx_dropped)
2357         eq_(self.rx_errors['val'], self.c.rx_errors)
2358         eq_(self.tx_errors['val'], self.c.tx_errors)
2359         eq_(self.rx_frame_err['val'], self.c.rx_frame_err)
2360         eq_(self.rx_over_err['val'], self.c.rx_over_err)
2361         eq_(self.rx_crc_err['val'], self.c.rx_crc_err)
2362         eq_(self.collisions['val'], self.c.collisions)
2363
2364     def test_parser(self):
2365         res = self.c.parser(self.buf, 0)
2366
2367         eq_(self.port_no['val'], res.port_no)
2368         eq_(self.rx_packets['val'], res.rx_packets)
2369         eq_(self.tx_packets['val'], res.tx_packets)
2370         eq_(self.rx_bytes['val'], res.rx_bytes)
2371         eq_(self.tx_bytes['val'], res.tx_bytes)
2372         eq_(self.rx_dropped['val'], res.rx_dropped)
2373         eq_(self.tx_dropped['val'], res.tx_dropped)
2374         eq_(self.rx_errors['val'], res.rx_errors)
2375         eq_(self.tx_errors['val'], res.tx_errors)
2376         eq_(self.rx_frame_err['val'], res.rx_frame_err)
2377         eq_(self.rx_over_err['val'], res.rx_over_err)
2378         eq_(self.rx_crc_err['val'], res.rx_crc_err)
2379         eq_(self.collisions['val'], res.collisions)
2380
2381
2382 class TestOFPQueueStats(unittest.TestCase):
2383     """ Test case for ofproto_v1_0_parser.OFPQueueStats
2384     """
2385
2386     # OFP_QUEUE_STATS_PACK_STR
2387     # '!H2xIQQQ...port_no, queue_id, tx_bytes, tx_packets, tx_errors
2388     port_no = {'buf': b'\xe7\x6b', 'val': 59243}
2389     zfill = b'\x00' * 2
2390     queue_id = {'buf': b'\x2a\xa8\x7f\x32', 'val': 715685682}
2391     tx_bytes = {'buf': b'\x77\xe1\xd5\x63\x18\xae\x63\xaa',
2392                 'val': 8638420181865882538}
2393     tx_packets = {'buf': b'\x27\xa4\x41\xd7\xd4\x53\x9e\x42',
2394                   'val': 2856480458895760962}
2395     tx_errors = {'buf': b'\x57\x32\x08\x2f\x88\x32\x40\x6b',
2396                  'val': 6283093430376743019}
2397
2398     c = OFPQueueStats(port_no['val'],
2399                       queue_id['val'],
2400                       tx_bytes['val'],
2401                       tx_packets['val'],
2402                       tx_errors['val'])
2403
2404     buf = port_no['buf'] \
2405         + zfill \
2406         + queue_id['buf'] \
2407         + tx_bytes['buf'] \
2408         + tx_packets['buf'] \
2409         + tx_errors['buf']
2410
2411     def setUp(self):
2412         pass
2413
2414     def tearDown(self):
2415         pass
2416
2417     def test_init(self):
2418         eq_(self.port_no['val'], self.c.port_no)
2419         eq_(self.queue_id['val'], self.c.queue_id)
2420         eq_(self.tx_bytes['val'], self.c.tx_bytes)
2421         eq_(self.tx_packets['val'], self.c.tx_packets)
2422         eq_(self.tx_errors['val'], self.c.tx_errors)
2423
2424     def test_parser(self):
2425         res = self.c.parser(self.buf, 0)
2426
2427         eq_(self.port_no['val'], res.port_no)
2428         eq_(self.queue_id['val'], res.queue_id)
2429         eq_(self.tx_bytes['val'], res.tx_bytes)
2430         eq_(self.tx_packets['val'], res.tx_packets)
2431         eq_(self.tx_errors['val'], res.tx_errors)
2432
2433
2434 class TestOFPVendorStats(unittest.TestCase):
2435     """ Test case for ofproto_v1_0_parser.OFPVendorStats
2436     """
2437
2438     specific_data = 'specific_data'
2439     specific_data_after = 'data'
2440     offset = specific_data.find(specific_data_after)
2441
2442     c = OFPVendorStats(specific_data)
2443
2444     def setUp(self):
2445         pass
2446
2447     def tearDown(self):
2448         pass
2449
2450     def test_init(self):
2451         eq_(self.specific_data, self.c.specific_data)
2452
2453     def test_parser(self):
2454         res = self.c.parser(self.specific_data, self.offset)
2455         eq_(self.specific_data_after, res.specific_data)
2456
2457
2458 class TestOFPQueuePropNone(unittest.TestCase):
2459     """ Test case for ofproto_v1_0_parser.OFPQueuePropNone
2460     """
2461
2462     # OFP_QUEUE_PROP_HEADER_PACK_STR
2463     # '!HH4x'...property_, len_
2464     property = {'buf': b'\x00\x00', 'val': ofproto.OFPQT_NONE}
2465     len = {'buf': b'\x00\x08', 'val': ofproto.OFP_QUEUE_PROP_HEADER_SIZE}
2466     zfill = b'\x00' * 4
2467
2468     c = OFPQueuePropNone()
2469
2470     def setUp(self):
2471         pass
2472
2473     def tearDown(self):
2474         pass
2475
2476     def test_init(self):
2477         cls = OFPQueuePropHeader._QUEUE_PROPERTIES[self.c.cls_prop_type]
2478
2479         eq_(self.property['val'], self.c.cls_prop_type)
2480         eq_(self.property['val'], self.c.property)
2481         eq_(self.property['val'], cls.cls_prop_type)
2482
2483         eq_(self.len['val'], self.c.cls_prop_len)
2484         eq_(self.len['val'], self.c.len)
2485         eq_(self.len['val'], cls.cls_prop_len)
2486
2487     def test_parser(self):
2488         buf = self.property['buf'] \
2489             + self.len['buf'] \
2490             + self.zfill
2491
2492         ok_(self.c.parser(buf, 0))
2493
2494
2495 class TestOFPQueuePropMinRate(unittest.TestCase):
2496     """ Test case for ofproto_v1_0_parser.OFPQueuePropMinRate
2497     """
2498
2499     # OFP_QUEUE_PROP_MIN_RATE_PACK_STR
2500     # '!H6x'...rate
2501     rate = {'buf': b'\x00\x01', 'val': ofproto.OFPQT_MIN_RATE}
2502     len = {'buf': b'\x00\x10', 'val': ofproto.OFP_QUEUE_PROP_MIN_RATE_SIZE}
2503     zfill = b'\x00' * 6
2504
2505     buf = rate['buf'] \
2506         + zfill
2507
2508     c = OFPQueuePropMinRate(rate['val'])
2509
2510     def setUp(self):
2511         pass
2512
2513     def tearDown(self):
2514         pass
2515
2516     def test_init(self):
2517         cls = OFPQueuePropHeader._QUEUE_PROPERTIES[self.c.cls_prop_type]
2518
2519         eq_(self.rate['val'], self.c.cls_prop_type)
2520         eq_(self.rate['val'], self.c.rate)
2521         eq_(self.rate['val'], cls.cls_prop_type)
2522
2523         eq_(self.len['val'], self.c.cls_prop_len)
2524         eq_(self.len['val'], cls.cls_prop_len)
2525
2526     def test_parser(self):
2527         res = self.c.parser(self.buf, 0)
2528         eq_(self.rate['val'], res.rate)
2529
2530
2531 class TestOFPPacketQueue(unittest.TestCase):
2532     """ Test case for ofproto_v1_0_parser.OFPPacketQueue
2533     """
2534
2535     # OFP_PACKET_QUEUE_PQCK_STR
2536     # '!IH2x'...queue_id, len_, zfill
2537     queue_id = {'buf': b'\x4d\x4b\x3a\xd1', 'val': 1296775889}
2538     len_ = {'buf': b'\x00\x08',
2539             'val': ofproto.OFP_QUEUE_PROP_HEADER_SIZE}
2540     zfill = b'\x00' * 2
2541
2542     buf = queue_id['buf'] \
2543         + len_['buf'] \
2544         + zfill
2545
2546     c = OFPPacketQueue(queue_id['val'],
2547                        len_['val'])
2548
2549     def setUp(self):
2550         pass
2551
2552     def tearDown(self):
2553         pass
2554
2555     def test_init(self):
2556         eq_(self.queue_id['val'], self.c.queue_id)
2557         eq_(self.len_['val'], self.c.len)
2558
2559     def test_parser(self):
2560         res = self.c.parser(self.buf, 0)
2561         eq_(self.queue_id['val'], res.queue_id)
2562         eq_(self.len_['val'], res.len)
2563
2564     def test_parser_append_prop(self):
2565         # OFP_QUEUE_PROP_HEADER_PACK_STR + OFP_QUEUE_PROP_MIN_RATE_PACK_STR
2566         # '!HH4xH6x'...type, len, zfill, rate, zfill
2567         len_ = {'buf': b'\x00\x10',
2568                 'val': ofproto.OFP_QUEUE_PROP_MIN_RATE_SIZE}
2569         a_type = {'buf': b'\x00\x01', 'val': ofproto.OFPQT_MIN_RATE}
2570         a_len = {'buf': b'\x00\x10',
2571                  'val': ofproto.OFP_QUEUE_PROP_MIN_RATE_SIZE}
2572         a_zfill0 = b'\x00' * 4
2573         a_rate = {'buf': b'\x00\x01', 'val': ofproto.OFPQT_MIN_RATE}
2574         a_zfill1 = b'\x00' * 6
2575
2576         buf = self.queue_id['buf'] \
2577             + len_['buf'] \
2578             + self.zfill \
2579             + a_type['buf'] \
2580             + a_len['buf'] \
2581             + a_zfill0 \
2582             + a_rate['buf'] \
2583             + a_zfill1
2584
2585         res = self.c.parser(buf, 0)
2586
2587         eq_(self.queue_id['val'], res.queue_id)
2588         eq_(len_['val'], res.len)
2589
2590         append_cls = res.properties[0]
2591
2592         eq_(a_type['val'], append_cls.property)
2593         eq_(a_len['val'], append_cls.len)
2594         eq_(a_rate['val'], append_cls.rate)
2595
2596
2597 class TestOFPHello(unittest.TestCase):
2598     """ Test case for ofproto_v1_0_parser.OFPHello
2599     """
2600
2601     def setUp(self):
2602         pass
2603
2604     def tearDown(self):
2605         pass
2606
2607     def test_init(self):
2608         pass
2609
2610     def test_parser(self):
2611         version = ofproto.OFP_VERSION
2612         msg_type = ofproto.OFPT_HELLO
2613         msg_len = ofproto.OFP_HEADER_SIZE
2614         xid = 2183948390
2615         data = b'\x00\x01\x02\x03'
2616
2617         fmt = ofproto.OFP_HEADER_PACK_STR
2618         buf = struct.pack(fmt, version, msg_type, msg_len, xid) \
2619             + data
2620
2621         res = OFPHello.parser(object, version, msg_type, msg_len, xid,
2622                               bytearray(buf))
2623
2624         eq_(version, res.version)
2625         eq_(msg_type, res.msg_type)
2626         eq_(msg_len, res.msg_len)
2627         eq_(xid, res.xid)
2628         eq_(six.binary_type(buf), six.binary_type(res.buf))
2629
2630     def test_serialize(self):
2631
2632         class Datapath(object):
2633             ofproto = ofproto  # copy to class attribute
2634             ofproto_parser = ofproto_v1_0_parser
2635
2636         c = OFPHello(Datapath)
2637         c.serialize()
2638         eq_(ofproto.OFP_VERSION, c.version)
2639         eq_(ofproto.OFPT_HELLO, c.msg_type)
2640         eq_(0, c.xid)
2641
2642
2643 class TestOFPErrorMsg(unittest.TestCase):
2644     """ Test case for ofproto_v1_0_parser.OFPErrorMsg
2645     """
2646
2647     def setUp(self):
2648         pass
2649
2650     def tearDown(self):
2651         pass
2652
2653     def test_init(self):
2654         pass
2655
2656     def test_parser(self):
2657         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
2658         msg_type = {'buf': b'\x01', 'val': ofproto.OFPT_ERROR}
2659         msg_len = {'buf': b'\x00\x0c',
2660                    'val': ofproto.OFP_ERROR_MSG_SIZE}
2661         xid = {'buf': b'\x87\x8b\x26\x7c', 'val': 2274043516}
2662         type = {'buf': b'\xab\x3e', 'val': 43838}
2663         code = {'buf': b'\x5d\x3c', 'val': 23868}
2664         data = b'Error Message.'
2665
2666         buf = version['buf'] \
2667             + msg_type['buf'] \
2668             + msg_len['buf'] \
2669             + xid['buf'] \
2670             + type['buf'] \
2671             + code['buf'] \
2672             + data
2673
2674         res = OFPErrorMsg.parser(object,
2675                                  version['val'],
2676                                  msg_type['val'],
2677                                  msg_len['val'],
2678                                  xid['val'],
2679                                  buf)
2680
2681         eq_(version['val'], res.version)
2682         eq_(msg_type['val'], res.msg_type)
2683         eq_(msg_len['val'], res.msg_len)
2684         eq_(xid['val'], res.xid)
2685         eq_(type['val'], res.type)
2686         eq_(code['val'], res.code)
2687         eq_(data, res.data)
2688
2689     def test_serialize(self):
2690         class Datapath(object):
2691             ofproto = ofproto  # copy to class attribute
2692             ofproto_parser = ofproto_v1_0_parser
2693
2694         type = 1306
2695         code = 13774
2696         data = b'Error Message.'
2697
2698         c = OFPErrorMsg(Datapath)
2699         c.type = type
2700         c.code = code
2701         c.data = data
2702
2703         c.serialize()
2704
2705         eq_(ofproto.OFP_VERSION, c.version)
2706         eq_(ofproto.OFPT_ERROR, c.msg_type)
2707         eq_(0, c.xid)
2708
2709         fmt = '!' \
2710             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2711             + ofproto.OFP_ERROR_MSG_PACK_STR.replace('!', '') \
2712             + str(len(data)) + 's'
2713
2714         res = struct.unpack(fmt, six.binary_type(c.buf))
2715         eq_(ofproto.OFP_VERSION, res[0])
2716         eq_(ofproto.OFPT_ERROR, res[1])
2717         eq_(len(c.buf), res[2])
2718         eq_(0, res[3])
2719         eq_(type, res[4])
2720         eq_(code, res[5])
2721         eq_(data, res[6])
2722
2723
2724 class TestOFPEchoRequest(unittest.TestCase):
2725     """ Test case for ofproto_v1_0_parser.OFPEchoRequest
2726     """
2727
2728     def setUp(self):
2729         pass
2730
2731     def tearDown(self):
2732         pass
2733
2734     def test_init(self):
2735         pass
2736
2737     def test_parser(self):
2738         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
2739         msg_type = {'buf': b'\x02', 'val': ofproto.OFPT_ECHO_REQUEST}
2740         msg_len = {'buf': b'\x00\x08',
2741                    'val': ofproto.OFP_HEADER_SIZE}
2742         xid = {'buf': b'\x84\x47\xef\x3f', 'val': 2219306815}
2743         data = b'Request Message.'
2744
2745         buf = version['buf'] \
2746             + msg_type['buf'] \
2747             + msg_len['buf'] \
2748             + xid['buf'] \
2749             + data
2750
2751         res = OFPEchoRequest.parser(object,
2752                                     version['val'],
2753                                     msg_type['val'],
2754                                     msg_len['val'],
2755                                     xid['val'],
2756                                     buf)
2757
2758         eq_(version['val'], res.version)
2759         eq_(msg_type['val'], res.msg_type)
2760         eq_(msg_len['val'], res.msg_len)
2761         eq_(xid['val'], res.xid)
2762         eq_(data, res.data)
2763
2764     def test_serialize(self):
2765         class Datapath(object):
2766             ofproto = ofproto  # copy to class attribute
2767             ofproto_parser = ofproto_v1_0_parser
2768
2769         data = b'Request Message.'
2770
2771         c = OFPEchoRequest(Datapath)
2772         c.data = data
2773
2774         c.serialize()
2775
2776         eq_(ofproto.OFP_VERSION, c.version)
2777         eq_(ofproto.OFPT_ECHO_REQUEST, c.msg_type)
2778         eq_(0, c.xid)
2779
2780         fmt = '!' \
2781             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2782             + str(len(data)) + 's'
2783
2784         res = struct.unpack(fmt, six.binary_type(c.buf))
2785         eq_(ofproto.OFP_VERSION, res[0])
2786         eq_(ofproto.OFPT_ECHO_REQUEST, res[1])
2787         eq_(len(c.buf), res[2])
2788         eq_(0, res[3])
2789         eq_(data, res[4])
2790
2791
2792 class TestOFPEchoReply(unittest.TestCase):
2793     """ Test case for ofproto_v1_0_parser.OFPEchoReply
2794     """
2795
2796     def setUp(self):
2797         pass
2798
2799     def tearDown(self):
2800         pass
2801
2802     def test_init(self):
2803         pass
2804
2805     def test_parser(self):
2806         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
2807         msg_type = {'buf': b'\x03', 'val': ofproto.OFPT_ECHO_REPLY}
2808         msg_len = {'buf': b'\x00\x08',
2809                    'val': ofproto.OFP_HEADER_SIZE}
2810         xid = {'buf': b'\x6e\x21\x3e\x62', 'val': 1847672418}
2811         data = b'Reply Message.'
2812
2813         buf = version['buf'] \
2814             + msg_type['buf'] \
2815             + msg_len['buf'] \
2816             + xid['buf'] \
2817             + data
2818
2819         res = OFPEchoReply.parser(object,
2820                                   version['val'],
2821                                   msg_type['val'],
2822                                   msg_len['val'],
2823                                   xid['val'],
2824                                   buf)
2825
2826         eq_(version['val'], res.version)
2827         eq_(msg_type['val'], res.msg_type)
2828         eq_(msg_len['val'], res.msg_len)
2829         eq_(xid['val'], res.xid)
2830         eq_(data, res.data)
2831
2832     def test_serialize(self):
2833         class Datapath(object):
2834             ofproto = ofproto  # copy to class attribute
2835             ofproto_parser = ofproto_v1_0_parser
2836
2837         data = b'Reply Message.'
2838
2839         c = OFPEchoReply(Datapath)
2840         c.data = data
2841
2842         c.serialize()
2843
2844         eq_(ofproto.OFP_VERSION, c.version)
2845         eq_(ofproto.OFPT_ECHO_REPLY, c.msg_type)
2846         eq_(0, c.xid)
2847
2848         fmt = '!' \
2849             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2850             + str(len(data)) + 's'
2851
2852         res = struct.unpack(fmt, six.binary_type(c.buf))
2853         eq_(ofproto.OFP_VERSION, res[0])
2854         eq_(ofproto.OFPT_ECHO_REPLY, res[1])
2855         eq_(len(c.buf), res[2])
2856         eq_(0, res[3])
2857         eq_(data, res[4])
2858
2859
2860 class TestOFPVendor(unittest.TestCase):
2861     """ Test case for ofproto_v1_0_parser.OFPVendor
2862     """
2863
2864     def setUp(self):
2865         pass
2866
2867     def tearDown(self):
2868         pass
2869
2870     def test_init(self):
2871         pass
2872
2873     def test_parser(self):
2874         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
2875         msg_type = {'buf': b'\x04', 'val': ofproto.OFPT_VENDOR}
2876         msg_len = {'buf': b'\x00\x0c',
2877                    'val': ofproto.OFP_VENDOR_HEADER_SIZE}
2878         xid = {'buf': b'\x05\x45\xdf\x18', 'val': 88465176}
2879         vendor = {'buf': b'\x53\xea\x25\x3e', 'val': 1407853886}
2880         data = b'Vendor Message.'
2881
2882         buf = version['buf'] \
2883             + msg_type['buf'] \
2884             + msg_len['buf'] \
2885             + xid['buf'] \
2886             + vendor['buf'] \
2887             + data
2888
2889         res = OFPVendor.parser(object,
2890                                version['val'],
2891                                msg_type['val'],
2892                                msg_len['val'],
2893                                xid['val'],
2894                                buf)
2895
2896         eq_(version['val'], res.version)
2897         eq_(msg_type['val'], res.msg_type)
2898         eq_(msg_len['val'], res.msg_len)
2899         eq_(xid['val'], res.xid)
2900         eq_(vendor['val'], res.vendor)
2901         eq_(data, res.data)
2902
2903     def test_serialize(self):
2904         class Datapath(object):
2905             ofproto = ofproto  # copy to class attribute
2906             ofproto_parser = ofproto_v1_0_parser
2907
2908         vendor = {'buf': b'\x38\x4b\xf9\x6c', 'val': 944503148}
2909         data = b'Reply Message.'
2910
2911         c = OFPVendor(Datapath)
2912         c.vendor = vendor['val']
2913         c.data = data
2914
2915         c.serialize()
2916
2917         eq_(ofproto.OFP_VERSION, c.version)
2918         eq_(ofproto.OFPT_VENDOR, c.msg_type)
2919         eq_(0, c.xid)
2920         eq_(vendor['val'], c.vendor)
2921
2922         fmt = '!' \
2923             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2924             + ofproto.OFP_VENDOR_HEADER_PACK_STR.replace('!', '') \
2925             + str(len(data)) + 's'
2926
2927         res = struct.unpack(fmt, six.binary_type(c.buf))
2928         eq_(ofproto.OFP_VERSION, res[0])
2929         eq_(ofproto.OFPT_VENDOR, res[1])
2930         eq_(len(c.buf), res[2])
2931         eq_(0, res[3])
2932         eq_(vendor['val'], res[4])
2933         eq_(data, res[5])
2934
2935
2936 # class TestNXTRequest(unittest.TestCase):
2937 class TestNiciraHeader(unittest.TestCase):
2938     """ Test case for ofproto_v1_0_parser.NiciraHeader
2939     """
2940
2941     def setUp(self):
2942         pass
2943
2944     def tearDown(self):
2945         pass
2946
2947     def test_init(self):
2948         subtype = ofproto.NXT_FLOW_MOD_TABLE_ID
2949
2950         c = NiciraHeader(object, subtype)
2951         eq_(subtype, c.subtype)
2952
2953     def test_parser(self):
2954         # Not used.
2955         pass
2956
2957     def test_serialize(self):
2958         class Datapath(object):
2959             ofproto = ofproto  # copy to class attribute
2960             ofproto_parser = ofproto_v1_0_parser
2961
2962         data = b'Reply Message.'
2963         subtype = ofproto.NXT_FLOW_MOD_TABLE_ID
2964
2965         c = NiciraHeader(Datapath, subtype)
2966         c.data = data
2967
2968         c.serialize()
2969
2970         eq_(ofproto.OFP_VERSION, c.version)
2971         eq_(ofproto.OFPT_VENDOR, c.msg_type)
2972         eq_(0, c.xid)
2973         eq_(ofproto_common.NX_EXPERIMENTER_ID, c.vendor)
2974
2975         fmt = '!' \
2976             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2977             + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
2978             + str(len(data)) + 's'
2979
2980         res = struct.unpack(fmt, six.binary_type(c.buf))
2981         eq_(ofproto.OFP_VERSION, res[0])
2982         eq_(ofproto.OFPT_VENDOR, res[1])
2983         eq_(len(c.buf), res[2])
2984         eq_(0, res[3])
2985         eq_(ofproto_common.NX_EXPERIMENTER_ID, res[4])
2986         eq_(subtype, res[5])
2987         eq_(data, res[6])
2988
2989
2990 class TestNXTSetFlowFormat(unittest.TestCase):
2991     """ Test case for ofproto_v1_0_parser.NXTSetFlowFormat
2992     """
2993
2994     def setUp(self):
2995         pass
2996
2997     def tearDown(self):
2998         pass
2999
3000     def test_init(self):
3001         flow_format = {'buf': b'\xdc\x6b\xf5\x24', 'val': 3698062628}
3002
3003         c = NXTSetFlowFormat(object, flow_format['val'])
3004         eq_(flow_format['val'], c.format)
3005
3006     def test_parser(self):
3007         # Not used.
3008         pass
3009
3010     def test_serialize(self):
3011         class Datapath(object):
3012             ofproto = ofproto  # copy to class attribute
3013             ofproto_parser = ofproto_v1_0_parser
3014
3015         flow_format = {'buf': b'\x5a\x4e\x59\xad', 'val': 1515084205}
3016
3017         c = NXTSetFlowFormat(Datapath, flow_format['val'])
3018         c.serialize()
3019
3020         eq_(ofproto.OFP_VERSION, c.version)
3021         eq_(ofproto.OFPT_VENDOR, c.msg_type)
3022         eq_(0, c.xid)
3023         eq_(ofproto_common.NX_EXPERIMENTER_ID, c.vendor)
3024
3025         fmt = '!' \
3026             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3027             + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3028             + ofproto.NX_SET_FLOW_FORMAT_PACK_STR.replace('!', '')
3029
3030         res = struct.unpack(fmt, six.binary_type(c.buf))
3031         eq_(ofproto.OFP_VERSION, res[0])
3032         eq_(ofproto.OFPT_VENDOR, res[1])
3033         eq_(len(c.buf), res[2])
3034         eq_(0, res[3])
3035         eq_(ofproto_common.NX_EXPERIMENTER_ID, res[4])
3036         eq_(ofproto.NXT_SET_FLOW_FORMAT, res[5])
3037         eq_(flow_format['val'], res[6])
3038
3039
3040 class TestNXTFlowMod(unittest.TestCase):
3041     """ Test case for ofproto_v1_0_parser.NXTFlowMod
3042     """
3043
3044     # NX_FLOW_MOD_PACK_STR
3045     # '!Q4HI3H6x'...cokkie, command, idle_timeout, head_timeout,
3046     #               priority, buffer_id, out_port, flags, rule, zfill
3047     cookie = {'buf': b'\x04\x56\x27\xad\xbd\x43\xd6\x83',
3048               'val': 312480851306993283}
3049     command = {'buf': b'\x61\xaa', 'val': 25002}
3050     idle_timeout = {'buf': b'\x4e\xff', 'val': 20223}
3051     hard_timeout = {'buf': b'\x80\x16', 'val': 32790}
3052     priority = {'buf': b'\x70\x5f', 'val': 28767}
3053     buffer_id = {'buf': b'\x7b\x97\x3a\x09', 'val': 2073508361}
3054     out_port = {'buf': b'\x11\x7d', 'val': 4477}
3055     flags = {'buf': b'\x5c\xb9', 'val': 23737}
3056     rule = nx_match.ClsRule()
3057     zfill = b'\x00' * 6
3058
3059     port = {'buf': b'\x2a\xe0', 'val': 10976}
3060     actions = [OFPActionOutput(port['val'])]
3061
3062     def _get_obj(self, append_action=False):
3063         class Datapath(object):
3064             ofproto = ofproto  # copy to class attribute
3065             ofproto_parser = ofproto_v1_0_parser
3066
3067         actions = None
3068         if append_action:
3069             actions = self.actions
3070
3071         c = NXTFlowMod(Datapath,
3072                        self.cookie['val'],
3073                        self.command['val'],
3074                        self.idle_timeout['val'],
3075                        self.hard_timeout['val'],
3076                        self.priority['val'],
3077                        self.buffer_id['val'],
3078                        self.out_port['val'],
3079                        self.flags['val'],
3080                        self.rule,
3081                        actions)
3082
3083         return c
3084
3085     def setUp(self):
3086         pass
3087
3088     def tearDown(self):
3089         pass
3090
3091     def test_init(self):
3092         c = self._get_obj()
3093
3094         eq_(self.cookie['val'], c.cookie)
3095         eq_(self.command['val'], c.command)
3096         eq_(self.idle_timeout['val'], c.idle_timeout)
3097         eq_(self.hard_timeout['val'], c.hard_timeout)
3098         eq_(self.priority['val'], c.priority)
3099         eq_(self.buffer_id['val'], c.buffer_id)
3100         eq_(self.out_port['val'], c.out_port)
3101         eq_(self.flags['val'], c.flags)
3102         eq_(self.rule.__hash__(), c.rule.__hash__())
3103
3104     def test_init_append_actions(self):
3105         c = self._get_obj(True)
3106
3107         action = c.actions[0]
3108         eq_(ofproto.OFPAT_OUTPUT, action.type)
3109         eq_(ofproto.OFP_ACTION_OUTPUT_SIZE, action.len)
3110         eq_(self.port['val'], action.port)
3111
3112     def test_parser(self):
3113         # Not used.
3114         pass
3115
3116     def test_serialize(self):
3117         c = self._get_obj()
3118         c.serialize()
3119
3120         eq_(ofproto.OFP_VERSION, c.version)
3121         eq_(ofproto.OFPT_VENDOR, c.msg_type)
3122         eq_(0, c.xid)
3123         eq_(ofproto_common.NX_EXPERIMENTER_ID, c.vendor)
3124
3125         fmt = '!' \
3126             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3127             + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3128             + ofproto.NX_FLOW_MOD_PACK_STR.replace('!', '')
3129
3130         res = struct.unpack(fmt, six.binary_type(c.buf))
3131         eq_(ofproto.OFP_VERSION, res[0])
3132         eq_(ofproto.OFPT_VENDOR, res[1])
3133         eq_(len(c.buf), res[2])
3134         eq_(0, res[3])
3135         eq_(ofproto_common.NX_EXPERIMENTER_ID, res[4])
3136         eq_(ofproto.NXT_FLOW_MOD, res[5])
3137         eq_(self.cookie['val'], res[6])
3138         eq_(self.command['val'], res[7])
3139         eq_(self.idle_timeout['val'], res[8])
3140         eq_(self.hard_timeout['val'], res[9])
3141         eq_(self.priority['val'], res[10])
3142         eq_(self.buffer_id['val'], res[11])
3143         eq_(self.out_port['val'], res[12])
3144         eq_(self.flags['val'], res[13])
3145
3146     def test_serialize_append_actions(self):
3147         c = self._get_obj(True)
3148         c.serialize()
3149
3150         eq_(ofproto.OFP_VERSION, c.version)
3151         eq_(ofproto.OFPT_VENDOR, c.msg_type)
3152         eq_(0, c.xid)
3153         eq_(ofproto_common.NX_EXPERIMENTER_ID, c.vendor)
3154
3155         fmt = '!' \
3156             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3157             + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3158             + ofproto.NX_FLOW_MOD_PACK_STR.replace('!', '') \
3159             + ofproto.OFP_ACTION_OUTPUT_PACK_STR.replace('!', '')
3160
3161         res = struct.unpack(fmt, six.binary_type(c.buf))
3162         eq_(ofproto.OFP_VERSION, res[0])
3163         eq_(ofproto.OFPT_VENDOR, res[1])
3164         eq_(len(c.buf), res[2])
3165         eq_(0, res[3])
3166         eq_(ofproto_common.NX_EXPERIMENTER_ID, res[4])
3167         eq_(ofproto.NXT_FLOW_MOD, res[5])
3168         eq_(self.cookie['val'], res[6])
3169         eq_(self.command['val'], res[7])
3170         eq_(self.idle_timeout['val'], res[8])
3171         eq_(self.hard_timeout['val'], res[9])
3172         eq_(self.priority['val'], res[10])
3173         eq_(self.buffer_id['val'], res[11])
3174         eq_(self.out_port['val'], res[12])
3175         eq_(self.flags['val'], res[13])
3176
3177         # action
3178         eq_(0, res[14])
3179         eq_(ofproto.OFPAT_OUTPUT, res[15])
3180         eq_(ofproto.OFP_ACTION_OUTPUT_SIZE, res[16])
3181         eq_(self.port['val'], res[17])
3182         eq_(0xffe5, res[18])
3183
3184
3185 class TestNXTRoleRequest(unittest.TestCase):
3186     """ Test case for ofproto_v1_0_parser.NXTRoleRequest
3187     """
3188
3189     # NX_ROLE_PACK_STR
3190     # '!I'...role
3191     role = {'buf': b'\x62\x81\x27\x61', 'val': 1652631393}
3192
3193     class Datapath(object):
3194         ofproto = ofproto  # copy to class attribute
3195         ofproto_parser = ofproto_v1_0_parser
3196
3197     c = NXTRoleRequest(Datapath, role['val'])
3198
3199     def setUp(self):
3200         pass
3201
3202     def tearDown(self):
3203         pass
3204
3205     def test_init(self):
3206         eq_(self.role['val'], self.c.role)
3207
3208     def test_parser(self):
3209         # Not used.
3210         pass
3211
3212     def test_serialize(self):
3213         self.c.serialize()
3214
3215         eq_(ofproto.OFP_VERSION, self.c.version)
3216         eq_(ofproto.OFPT_VENDOR, self.c.msg_type)
3217         eq_(0, self.c.xid)
3218         eq_(ofproto_common.NX_EXPERIMENTER_ID, self.c.vendor)
3219
3220         fmt = '!' \
3221             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3222             + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3223             + ofproto.NX_ROLE_PACK_STR.replace('!', '')
3224
3225         res = struct.unpack(fmt, six.binary_type(self.c.buf))
3226
3227         eq_(ofproto.OFP_VERSION, res[0])
3228         eq_(ofproto.OFPT_VENDOR, res[1])
3229         eq_(len(self.c.buf), res[2])
3230         eq_(0, res[3])
3231         eq_(ofproto_common.NX_EXPERIMENTER_ID, res[4])
3232         eq_(ofproto.NXT_ROLE_REQUEST, res[5])
3233         eq_(self.role['val'], res[6])
3234
3235
3236 class TestNXTFlowModTableId(unittest.TestCase):
3237     """ Test case for ofproto_v1_0_parser.NXTFlowModTableId
3238     """
3239
3240     # NX_FLOW_MOD_TABLE_ID_PACK_STR
3241     # '!B7x'...set_, zfill
3242     set_ = {'buf': b'\x71', 'val': 113}
3243     zfill = b'\x00' * 7
3244
3245     class Datapath(object):
3246         ofproto = ofproto  # copy to class attribute
3247         ofproto_parser = ofproto_v1_0_parser
3248
3249     c = NXTFlowModTableId(Datapath, set_['val'])
3250
3251     def setUp(self):
3252         pass
3253
3254     def tearDown(self):
3255         pass
3256
3257     def test_init(self):
3258         eq_(self.set_['val'], self.c.set)
3259
3260     def test_parser(self):
3261         # Not used.
3262         pass
3263
3264     def test_serialize(self):
3265         self.c.serialize()
3266
3267         eq_(ofproto.OFP_VERSION, self.c.version)
3268         eq_(ofproto.OFPT_VENDOR, self.c.msg_type)
3269         eq_(0, self.c.xid)
3270         eq_(ofproto_common.NX_EXPERIMENTER_ID, self.c.vendor)
3271
3272         fmt = '!' \
3273             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3274             + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3275             + ofproto.NX_FLOW_MOD_TABLE_ID_PACK_STR.replace('!', '')
3276
3277         res = struct.unpack(fmt, six.binary_type(self.c.buf))
3278         eq_(ofproto.OFP_VERSION, res[0])
3279         eq_(ofproto.OFPT_VENDOR, res[1])
3280         eq_(len(self.c.buf), res[2])
3281         eq_(0, res[3])
3282         eq_(ofproto_common.NX_EXPERIMENTER_ID, res[4])
3283         eq_(ofproto.NXT_FLOW_MOD_TABLE_ID, res[5])
3284         eq_(self.set_['val'], res[6])
3285
3286
3287 class TestOFPSwitchFeatures(unittest.TestCase):
3288     """ Test case for ofproto_v1_0_parser.OFPSwitchFeatures
3289     """
3290
3291     class Datapath(object):
3292         ofproto = ofproto  # copy to class attribute
3293         ofproto_parser = ofproto_v1_0_parser
3294
3295     c = OFPSwitchFeatures(Datapath)
3296
3297     def setUp(self):
3298         pass
3299
3300     def tearDown(self):
3301         pass
3302
3303     def test_init(self):
3304         pass
3305
3306     def test_parser(self):
3307         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3308         msg_type = {'buf': b'\x06', 'val': ofproto.OFPT_FEATURES_REPLY}
3309         msg_len_val = ofproto.OFP_SWITCH_FEATURES_SIZE \
3310             + ofproto.OFP_PHY_PORT_SIZE
3311         msg_len = {'buf': b'\x00\x4c', 'val': msg_len_val}
3312         xid = {'buf': b'\xcc\x0a\x41\xd4', 'val': 3423224276}
3313
3314         # OFP_SWITCH_FEATURES_PACK_STR
3315         # '!QIB3xII'...datapath_id, n_buffers, n_tables,
3316         #              zfill, capabilities, actions
3317         datapath_id = {'buf': b'\x11\xa3\x72\x63\x61\xde\x39\x81',
3318                        'val': 1270985291017894273}
3319         n_buffers = {'buf': b'\x80\x14\xd7\xf6', 'val': 2148849654}
3320         n_tables = {'buf': b'\xe4', 'val': 228}
3321         zfill = b'\x00' * 3
3322         capabilities = {'buf': b'\x69\x4f\xe4\xc2', 'val': 1766843586}
3323         actions = {'buf': b'\x78\x06\xd9\x0c', 'val': 2013714700}
3324
3325         # OFP_PHY_PORT_PACK_STR
3326         # '!H6s16sIIIIII'... port_no, hw_addr, name, config, state
3327         #                    curr, advertised, supported, peer
3328         port_no = {'buf': b'\xe7\x6b', 'val': 59243}
3329         hw_addr = '3c:d1:2b:8d:3f:d6'
3330         name = b'name'.ljust(16)
3331         config = {'buf': b'\x84\xb6\x8c\x53', 'val': 2226555987}
3332         state = {'buf': b'\x64\x07\xfb\xc9', 'val': 1678244809}
3333         curr = {'buf': b'\xa9\xe8\x0a\x2b', 'val': 2850556459}
3334         advertised = {'buf': b'\x78\xb9\x7b\x72', 'val': 2025421682}
3335         supported = {'buf': b'\x7e\x65\x68\xad', 'val': 2120575149}
3336         peer = {'buf': b'\xa4\x5b\x8b\xed', 'val': 2757463021}
3337
3338         buf = version['buf'] \
3339             + msg_type['buf'] \
3340             + msg_len['buf'] \
3341             + xid['buf'] \
3342             + datapath_id['buf'] \
3343             + n_buffers['buf'] \
3344             + n_tables['buf'] \
3345             + zfill \
3346             + capabilities['buf'] \
3347             + actions['buf'] \
3348             + port_no['buf'] \
3349             + addrconv.mac.text_to_bin(hw_addr) \
3350             + name \
3351             + config['buf'] \
3352             + state['buf'] \
3353             + curr['buf'] \
3354             + advertised['buf'] \
3355             + supported['buf'] \
3356             + peer['buf']
3357
3358         res = OFPSwitchFeatures.parser(object,
3359                                        version['val'],
3360                                        msg_type['val'],
3361                                        msg_len['val'],
3362                                        xid['val'],
3363                                        buf)
3364
3365         eq_(version['val'], res.version)
3366         eq_(msg_type['val'], res.msg_type)
3367         eq_(msg_len['val'], res.msg_len)
3368         eq_(xid['val'], res.xid)
3369         eq_(datapath_id['val'], res.datapath_id)
3370         eq_(n_buffers['val'], res.n_buffers)
3371         eq_(n_tables['val'], res.n_tables)
3372         eq_(capabilities['val'], res.capabilities)
3373         eq_(actions['val'], res.actions)
3374
3375         # port
3376         port = res.ports[port_no['val']]
3377         eq_(port_no['val'], port.port_no)
3378         eq_(hw_addr, hw_addr)
3379         eq_(name, port.name)
3380         eq_(config['val'], port.config)
3381         eq_(state['val'], port.state)
3382         eq_(curr['val'], port.curr)
3383         eq_(advertised['val'], port.advertised)
3384         eq_(supported['val'], port.supported)
3385         eq_(peer['val'], port.peer)
3386
3387     def test_serialize(self):
3388         # Not used.
3389         pass
3390
3391
3392 class TestOFPPortStatus(unittest.TestCase):
3393     """ Test case for ofproto_v1_0_parser.OFPPortStatus
3394     """
3395
3396     class Datapath(object):
3397         ofproto = ofproto  # copy to class attribute
3398         ofproto_parser = ofproto_v1_0_parser
3399
3400     c = OFPPortStatus(Datapath)
3401
3402     def setUp(self):
3403         pass
3404
3405     def tearDown(self):
3406         pass
3407
3408     def test_init(self):
3409         pass
3410
3411     def test_parser(self):
3412         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3413         msg_type = {'buf': b'\x0c', 'val': ofproto.OFPT_PORT_STATUS}
3414         msg_len = {'buf': b'\x00\x40',
3415                    'val': ofproto.OFP_PORT_STATUS_SIZE}
3416         xid = {'buf': b'\x06\x27\x8b\x7b', 'val': 103254907}
3417
3418         # OFP_PORT_STATUS_PACK_STR
3419         # '!B7xH6s16sIIIIII'...reason, zfill, port_no, hw_addr,
3420         #                      name, config, state, curr,
3421         #                      advertised, supported, peer
3422         reason = {'buf': b'\x71', 'val': 113}
3423         zfill = b'\x00' * 7
3424         port_no = {'buf': b'\x48\xd8', 'val': 18648}
3425         hw_addr = '41:f7:a3:52:8f:6b'
3426         name = b'name'.ljust(16)
3427         config = {'buf': b'\xae\x73\x90\xec', 'val': 2926809324}
3428         state = {'buf': b'\x41\x37\x32\x1d', 'val': 1094136349}
3429         curr = {'buf': b'\xa9\x47\x13\x2c', 'val': 2840007468}
3430         advertised = {'buf': b'\xce\x6b\x4a\x87', 'val': 3463137927}
3431         supported = {'buf': b'\xb8\x06\x65\xa1', 'val': 3087426977}
3432         peer = {'buf': b'\x6a\x11\x52\x39', 'val': 1779520057}
3433
3434         buf = version['buf'] \
3435             + msg_type['buf'] \
3436             + msg_len['buf'] \
3437             + xid['buf'] \
3438             + reason['buf'] \
3439             + zfill \
3440             + port_no['buf'] \
3441             + addrconv.mac.text_to_bin(hw_addr) \
3442             + name \
3443             + config['buf'] \
3444             + state['buf'] \
3445             + curr['buf'] \
3446             + advertised['buf'] \
3447             + supported['buf'] \
3448             + peer['buf']
3449
3450         res = OFPPortStatus.parser(object,
3451                                    version['val'],
3452                                    msg_type['val'],
3453                                    msg_len['val'],
3454                                    xid['val'],
3455                                    buf)
3456
3457         eq_(version['val'], res.version)
3458         eq_(msg_type['val'], res.msg_type)
3459         eq_(msg_len['val'], res.msg_len)
3460         eq_(xid['val'], res.xid)
3461         eq_(reason['val'], res.reason)
3462
3463         # desc
3464         desc = res.desc
3465         eq_(port_no['val'], desc.port_no)
3466         eq_(hw_addr, desc.hw_addr)
3467         eq_(name, desc.name)
3468         eq_(config['val'], desc.config)
3469         eq_(state['val'], desc.state)
3470         eq_(curr['val'], desc.curr)
3471         eq_(advertised['val'], desc.advertised)
3472         eq_(supported['val'], desc.supported)
3473         eq_(peer['val'], desc.peer)
3474
3475     def test_serialize(self):
3476         # Not used.
3477         pass
3478
3479
3480 class TestOFPPacketIn(unittest.TestCase):
3481     """ Test case for ofproto_v1_0_parser.OFPPacketIn
3482     """
3483
3484     class Datapath(object):
3485         ofproto = ofproto  # copy to class attribute
3486         ofproto_parser = ofproto_v1_0_parser
3487
3488     c = OFPPacketIn(Datapath)
3489
3490     def setUp(self):
3491         pass
3492
3493     def tearDown(self):
3494         pass
3495
3496     def test_init(self):
3497         pass
3498
3499     def _test_parser(self, padding=False):
3500         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3501         msg_type = {'buf': b'\x0a', 'val': ofproto.OFPT_PACKET_IN}
3502         msg_len = {'buf': b'\x00\x14',
3503                    'val': ofproto.OFP_PACKET_IN_SIZE}
3504         xid = {'buf': b'\xd0\x23\x8c\x34', 'val': 3491990580}
3505
3506         # OFP_PACKET_IN_PACK_STR
3507         # '!IHHBx2x'...buffer_id, total_len,
3508         #              in_port, reason, zfill, data
3509         buffer_id = {'buf': b'\xae\x73\x90\xec', 'val': 2926809324}
3510         total_len = {'buf': b'\x00\x10', 'val': 16}
3511         in_port = {'buf': b'\x08\x42', 'val': 2114}
3512         reason = {'buf': b'\x43', 'val': 67}
3513         zfill = b'\x00' * 1
3514         if padding:
3515             data = b'PACKET IN'.ljust(20)
3516         else:
3517             data = b'PACKET IN'.ljust(16)
3518
3519         buf = version['buf'] \
3520             + msg_type['buf'] \
3521             + msg_len['buf'] \
3522             + xid['buf'] \
3523             + buffer_id['buf'] \
3524             + total_len['buf'] \
3525             + in_port['buf'] \
3526             + reason['buf'] \
3527             + zfill \
3528             + data
3529
3530         res = OFPPacketIn.parser(object,
3531                                  version['val'],
3532                                  msg_type['val'],
3533                                  msg_len['val'],
3534                                  xid['val'],
3535                                  buf)
3536
3537         eq_(version['val'], res.version)
3538         eq_(msg_type['val'], res.msg_type)
3539         eq_(msg_len['val'], res.msg_len)
3540         eq_(xid['val'], res.xid)
3541         eq_(buffer_id['val'], res.buffer_id)
3542         eq_(total_len['val'], res.total_len)
3543         eq_(in_port['val'], res.in_port)
3544         eq_(reason['val'], res.reason)
3545         eq_(data[0:16], res.data)
3546
3547         return True
3548
3549     def test_parser(self):
3550         ok_(self._test_parser())
3551
3552     def test_parser_padding(self):
3553         ok_(self._test_parser(True))
3554
3555     def test_serialize(self):
3556         # Not used.
3557         pass
3558
3559
3560 class TestOFPGetConfigReply(unittest.TestCase):
3561     """ Test case for ofproto_v1_0_parser.OFPGetConfigReply
3562     """
3563
3564     class Datapath(object):
3565         ofproto = ofproto  # copy to class attribute
3566         ofproto_parser = ofproto_v1_0_parser
3567
3568     c = OFPGetConfigReply(Datapath)
3569
3570     def setUp(self):
3571         pass
3572
3573     def tearDown(self):
3574         pass
3575
3576     def test_init(self):
3577         pass
3578
3579     def test_parser(self):
3580         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3581         msg_type = {'buf': b'\x0a', 'val': ofproto.OFPT_GET_CONFIG_REPLY}
3582         msg_len = {'buf': b'\x00\x14',
3583                    'val': ofproto.OFP_SWITCH_CONFIG_SIZE}
3584         xid = {'buf': b'\x94\xc4\xd2\xcd', 'val': 2495926989}
3585
3586         # OFP_SWITCH_CONFIG_PACK_STR
3587         # '!HH'...flags, miss_send_len
3588         flags = {'buf': b'\xa0\xe2', 'val': 41186}
3589         miss_send_len = {'buf': b'\x36\x0e', 'val': 13838}
3590
3591         buf = version['buf'] \
3592             + msg_type['buf'] \
3593             + msg_len['buf'] \
3594             + xid['buf'] \
3595             + flags['buf'] \
3596             + miss_send_len['buf']
3597
3598         res = OFPGetConfigReply.parser(object,
3599                                        version['val'],
3600                                        msg_type['val'],
3601                                        msg_len['val'],
3602                                        xid['val'],
3603                                        buf)
3604
3605         eq_(version['val'], res.version)
3606         eq_(msg_type['val'], res.msg_type)
3607         eq_(msg_len['val'], res.msg_len)
3608         eq_(xid['val'], res.xid)
3609         eq_(flags['val'], res.flags)
3610         eq_(miss_send_len['val'], res.miss_send_len)
3611
3612     def test_serialize(self):
3613         # Not used.
3614         pass
3615
3616
3617 class TestOFPBarrierReply(unittest.TestCase):
3618     """ Test case for ofproto_v1_0_parser.OFPBarrierReply
3619     """
3620
3621     class Datapath(object):
3622         ofproto = ofproto  # copy to class attribute
3623         ofproto_parser = ofproto_v1_0_parser
3624
3625     c = OFPBarrierReply(Datapath)
3626
3627     def setUp(self):
3628         pass
3629
3630     def tearDown(self):
3631         pass
3632
3633     def test_init(self):
3634         pass
3635
3636     def test_parser(self):
3637         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3638         msg_type = {'buf': b'\x13', 'val': ofproto.OFPT_BARRIER_REPLY}
3639         msg_len = {'buf': b'\x00\x08',
3640                    'val': ofproto.OFP_HEADER_SIZE}
3641         xid = {'buf': b'\x66\xc4\xc3\xac', 'val': 1724171180}
3642
3643         buf = version['buf'] \
3644             + msg_type['buf'] \
3645             + msg_len['buf'] \
3646             + xid['buf']
3647
3648         res = OFPBarrierReply.parser(object,
3649                                      version['val'],
3650                                      msg_type['val'],
3651                                      msg_len['val'],
3652                                      xid['val'],
3653                                      buf)
3654
3655         eq_(version['val'], res.version)
3656         eq_(msg_type['val'], res.msg_type)
3657         eq_(msg_len['val'], res.msg_len)
3658         eq_(xid['val'], res.xid)
3659
3660     def test_serialize(self):
3661         # Not used.
3662         pass
3663
3664
3665 class TestOFPFlowRemoved(unittest.TestCase):
3666     """ Test case for ofproto_v1_0_parser.OFPFlowRemoved
3667     """
3668
3669     class Datapath(object):
3670         ofproto = ofproto  # copy to class attribute
3671         ofproto_parser = ofproto_v1_0_parser
3672
3673     c = OFPFlowRemoved(Datapath)
3674
3675     def setUp(self):
3676         pass
3677
3678     def tearDown(self):
3679         pass
3680
3681     def test_init(self):
3682         pass
3683
3684     def test_parser(self):
3685         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3686         msg_type = {'buf': b'\x0a', 'val': ofproto.OFPT_FLOW_REMOVED}
3687         msg_len = {'buf': b'\x00\x14',
3688                    'val': ofproto.OFP_FLOW_REMOVED_SIZE}
3689         xid = {'buf': b'\x94\xc4\xd2\xcd', 'val': 2495926989}
3690
3691         buf = version['buf'] \
3692             + msg_type['buf'] \
3693             + msg_len['buf'] \
3694             + xid['buf']
3695
3696         # OFP_MATCH_PACK_STR
3697         # '!IH6s6sHBxHBB2xIIHH'...wildcards, in_port, dl_src, dl_dst, dl_vlan,
3698         #                         dl_vlan_pcp, dl_type, nw_tos, nw_proto,
3699         #                         nw_src, nw_dst, tp_src, tp_dst
3700         wildcards = {'buf': b'\xd2\x71\x25\x23', 'val': 3530630435}
3701         in_port = {'buf': b'\x37\x8b', 'val': 14219}
3702         dl_src = b'\x7f\x85\xc4\x70\x12\xda'
3703         dl_dst = b'\x0a\x51\x17\x58\xb0\xbb'
3704         dl_vlan = {'buf': b'\xc1\xf9', 'val': 49657}
3705         dl_vlan_pcp = {'buf': b'\x79', 'val': 121}
3706         zfill0 = b'\x00'
3707         dl_type = {'buf': b'\xa6\x9e', 'val': 42654}
3708         nw_tos = {'buf': b'\xde', 'val': 222}
3709         nw_proto = {'buf': b'\xe5', 'val': 229}
3710         zfil11 = b'\x00' * 2
3711         nw_src = {'buf': b'\x1b\x6d\x8d\x4b', 'val': 460164427}
3712         nw_dst = {'buf': b'\xab\x25\xe1\x20', 'val': 2871386400}
3713         tp_src = {'buf': b'\xd5\xc3', 'val': 54723}
3714         tp_dst = {'buf': b'\x78\xb9', 'val': 30905}
3715
3716         buf += wildcards['buf'] \
3717             + in_port['buf'] \
3718             + dl_src \
3719             + dl_dst \
3720             + dl_vlan['buf'] \
3721             + dl_vlan_pcp['buf'] \
3722             + zfill0 \
3723             + dl_type['buf'] \
3724             + nw_tos['buf'] \
3725             + nw_proto['buf'] \
3726             + zfil11 \
3727             + nw_src['buf'] \
3728             + nw_dst['buf'] \
3729             + tp_src['buf'] \
3730             + tp_dst['buf']
3731
3732         # OFP_FLOW_REMOVED_PACK_STR0
3733         # '!QHBxIIH2xQQ'...cookie, priority, reason, zfill,
3734         #                  duration_sec, duration_nsec, idle_timeout,
3735         #                  zfill, packet_count, byte_count
3736         cookie = {'buf': b'\x02\x79\xba\x00\xef\xab\xee\x44',
3737                   'val': 178378173441633860}
3738         priority = {'buf': b'\x02\xce', 'val': 718}
3739         reason = {'buf': b'\xa9', 'val': 169}
3740         zfill0 = b'\x00' * 1
3741         duration_sec = {'buf': b'\x86\x24\xa3\xba', 'val': 2250548154}
3742         duration_nsec = {'buf': b'\x94\x94\xc2\x23', 'val': 2492776995}
3743         idle_timeout = {'buf': b'\xeb\x7c', 'val': 60284}
3744         zfill1 = b'\x00' * 2
3745         packet_count = {'buf': b'\x5a\x0d\xf2\x03\x8e\x0a\xbb\x8d',
3746                         'val': 6489108735192644493}
3747         byte_count = {'buf': b'\x65\xc8\xd3\x72\x51\xb5\xbb\x7c',
3748                       'val': 7334344481123449724}
3749
3750         buf += cookie['buf'] \
3751             + priority['buf'] \
3752             + reason['buf'] \
3753             + zfill0 \
3754             + duration_sec['buf'] \
3755             + duration_nsec['buf'] \
3756             + idle_timeout['buf'] \
3757             + zfill1 \
3758             + packet_count['buf'] \
3759             + byte_count['buf']
3760
3761         res = OFPFlowRemoved.parser(object,
3762                                     version['val'],
3763                                     msg_type['val'],
3764                                     msg_len['val'],
3765                                     xid['val'],
3766                                     buf)
3767
3768         eq_(version['val'], res.version)
3769         eq_(msg_type['val'], res.msg_type)
3770         eq_(msg_len['val'], res.msg_len)
3771         eq_(xid['val'], res.xid)
3772         eq_(cookie['val'], res.cookie)
3773         eq_(priority['val'], res.priority)
3774         eq_(reason['val'], res.reason)
3775         eq_(duration_sec['val'], res.duration_sec)
3776         eq_(duration_nsec['val'], res.duration_nsec)
3777         eq_(idle_timeout['val'], res.idle_timeout)
3778         eq_(packet_count['val'], res.packet_count)
3779         eq_(byte_count['val'], res.byte_count)
3780
3781         # match
3782         match = res.match
3783         eq_(wildcards['val'], match.wildcards)
3784         eq_(in_port['val'], match.in_port)
3785         eq_(dl_src, match.dl_src)
3786         eq_(dl_dst, match.dl_dst)
3787         eq_(dl_vlan['val'], match.dl_vlan)
3788         eq_(dl_vlan_pcp['val'], match.dl_vlan_pcp)
3789         eq_(dl_type['val'], match.dl_type)
3790         eq_(nw_tos['val'], match.nw_tos)
3791         eq_(nw_proto['val'], match.nw_proto)
3792         eq_(nw_src['val'], match.nw_src)
3793         eq_(nw_dst['val'], match.nw_dst)
3794         eq_(tp_src['val'], match.tp_src)
3795         eq_(tp_dst['val'], match.tp_dst)
3796
3797     def test_serialize(self):
3798         # Not used.
3799         pass
3800
3801
3802 class TestOFPQueueGetConfigReply(unittest.TestCase):
3803     """ Test case for ofproto_v1_0_parser.OFPQueueGetConfigReply
3804     """
3805
3806     class Datapath(object):
3807         ofproto = ofproto  # copy to class attribute
3808         ofproto_parser = ofproto_v1_0_parser
3809
3810     c = OFPQueueGetConfigReply(Datapath)
3811
3812     def setUp(self):
3813         pass
3814
3815     def tearDown(self):
3816         pass
3817
3818     def test_init(self):
3819         pass
3820
3821     def test_parser(self):
3822         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3823         msg_type = {'buf': b'\x0a',
3824                     'val': ofproto.OFPT_QUEUE_GET_CONFIG_REPLY}
3825         msg_len_val = ofproto.OFP_QUEUE_GET_CONFIG_REPLY_SIZE \
3826             + ofproto.OFP_PACKET_QUEUE_SIZE
3827         msg_len = {'buf': b'\x00\x14', 'val': msg_len_val}
3828         xid = {'buf': b'\x94\xc4\xd2\xcd', 'val': 2495926989}
3829
3830         buf = version['buf'] \
3831             + msg_type['buf'] \
3832             + msg_len['buf'] \
3833             + xid['buf']
3834
3835         # OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR
3836         # '!H6x'...port, zfill
3837         port = {'buf': b'\xfe\x66', 'val': 65126}
3838         zfill = b'\x00' * 6
3839
3840         buf += port['buf'] \
3841             + zfill
3842
3843         # OFP_PACKET_QUEUE_PQCK_STR
3844         # '!IH2x'...queue_id, len_, zfill
3845         queue_id = {'buf': b'\x4d\x4b\x3a\xd1', 'val': 1296775889}
3846         len_ = {'buf': b'\x00\x08',
3847                 'val': ofproto.OFP_QUEUE_PROP_HEADER_SIZE}
3848         zfill = b'\x00' * 2
3849
3850         buf += queue_id['buf'] \
3851             + len_['buf'] \
3852             + zfill
3853
3854         res = OFPQueueGetConfigReply.parser(object,
3855                                             version['val'],
3856                                             msg_type['val'],
3857                                             msg_len['val'],
3858                                             xid['val'],
3859                                             buf)
3860
3861         eq_(version['val'], res.version)
3862         eq_(msg_type['val'], res.msg_type)
3863         eq_(msg_len['val'], res.msg_len)
3864         eq_(xid['val'], res.xid)
3865         eq_(port['val'], res.port)
3866
3867         # queue
3868         queue = res.queues[0]
3869         eq_(queue_id['val'], queue.queue_id)
3870         eq_(len_['val'], queue.len)
3871
3872     def test_serialize(self):
3873         # Not used.
3874         pass
3875
3876
3877 class TestOFPDescStatsReply(unittest.TestCase):
3878     """ Test case for ofproto_v1_0_parser.OFPDescStatsReply
3879     """
3880
3881     class Datapath(object):
3882         ofproto = ofproto  # copy to class attribute
3883         ofproto_parser = ofproto_v1_0_parser
3884
3885     c = OFPDescStatsReply(Datapath)
3886
3887     def setUp(self):
3888         pass
3889
3890     def tearDown(self):
3891         pass
3892
3893     def test_init(self):
3894         pass
3895
3896     def test_parser(self):
3897         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3898         msg_type = {'buf': b'\x11', 'val': ofproto.OFPT_STATS_REPLY}
3899         msg_len_val = ofproto.OFP_STATS_MSG_SIZE \
3900             + ofproto.OFP_DESC_STATS_SIZE
3901         msg_len = {'buf': b'\x04\x38', 'val': msg_len_val}
3902         xid = {'buf': b'\x94\xc4\xd2\xcd', 'val': 2495926989}
3903
3904         buf = version['buf'] \
3905             + msg_type['buf'] \
3906             + msg_len['buf'] \
3907             + xid['buf']
3908
3909         # OFP_STATS_MSG_PACK_STR
3910         # '!HH'...type_, flags
3911         type_ = {'buf': b'\x00\x00', 'val': ofproto.OFPST_DESC}
3912         flags = {'buf': b'\x30\xd9', 'val': 12505}
3913
3914         buf += type_['buf'] \
3915             + flags['buf']
3916
3917         # stats_type_cls = OFPDescStats
3918         # OFP_DESC_STATS_PACK_STR
3919         # '!256s256s256s32s256s'...mfr_desc, hw_desc, sw_desc,
3920         #                          serial_num, dp_desc
3921         mfr_desc = b'mfr_desc'.ljust(256)
3922         hw_desc = b'hw_desc'.ljust(256)
3923         sw_desc = b'sw_desc'.ljust(256)
3924         serial_num = b'serial_num'.ljust(32)
3925         dp_desc = b'dp_desc'.ljust(256)
3926
3927         buf += mfr_desc \
3928             + hw_desc \
3929             + sw_desc \
3930             + serial_num \
3931             + dp_desc
3932
3933         res = OFPDescStatsReply.parser(object,
3934                                        version['val'],
3935                                        msg_type['val'],
3936                                        msg_len['val'],
3937                                        xid['val'],
3938                                        buf)
3939
3940         eq_(version['val'], res.version)
3941         eq_(msg_type['val'], res.msg_type)
3942         eq_(msg_len['val'], res.msg_len)
3943         eq_(xid['val'], res.xid)
3944         eq_(type_['val'], res.type)
3945         eq_(flags['val'], res.flags)
3946
3947         # body
3948         body = res.body
3949         eq_(mfr_desc, body.mfr_desc)
3950         eq_(hw_desc, body.hw_desc)
3951         eq_(sw_desc, body.sw_desc)
3952         eq_(serial_num, body.serial_num)
3953         eq_(dp_desc, body.dp_desc)
3954
3955     def test_serialize(self):
3956         # Not used.
3957         pass
3958
3959
3960 class TestOFPFlowStatsReply(unittest.TestCase):
3961     """ Test case for ofproto_v1_0_parser.OFPFlowStatsReply
3962     """
3963
3964     class Datapath(object):
3965         ofproto = ofproto  # copy to class attribute
3966         ofproto_parser = ofproto_v1_0_parser
3967
3968     c = OFPFlowStatsReply(Datapath)
3969
3970     def setUp(self):
3971         pass
3972
3973     def tearDown(self):
3974         pass
3975
3976     def test_init(self):
3977         pass
3978
3979     def test_parser(self):
3980         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
3981         msg_type = {'buf': b'\x11', 'val': ofproto.OFPT_STATS_REPLY}
3982         msg_len_val = ofproto.OFP_STATS_MSG_SIZE \
3983             + ofproto.OFP_FLOW_STATS_SIZE
3984         msg_len = {'buf': b'\x00\x64', 'val': msg_len_val}
3985         xid = {'buf': b'\x94\xc4\xd2\xcd', 'val': 2495926989}
3986
3987         buf = version['buf'] \
3988             + msg_type['buf'] \
3989             + msg_len['buf'] \
3990             + xid['buf']
3991
3992         # OFP_STATS_MSG_PACK_STR
3993         # '!HH'...type_, flags
3994         type_ = {'buf': b'\x00\x01', 'val': ofproto.OFPST_FLOW}
3995         flags = {'buf': b'\x95\xf4', 'val': 38388}
3996
3997         buf += type_['buf'] \
3998             + flags['buf']
3999
4000         # stats_type_cls = OFPFlowStats
4001         # OFP_FLOW_STATS_0_PACK_STR
4002         # '!HBx'...length, table_id, zfill
4003         length = {'buf': b'\x00\x60', 'val': 96}
4004         table_id = {'buf': b'\x51', 'val': 81}
4005         zfill = b'\x00'
4006
4007         buf += length['buf'] \
4008             + table_id['buf'] \
4009             + zfill
4010
4011         # OFP_MATCH_PACK_STR
4012         # '!IH6s6sHBxHBB2xIIHH'...
4013         match = b'\x97\x7c\xa6\x1e' \
4014             + b'\x5e\xa0' \
4015             + b'\x70\x17\xdc\x80\x59\x9e' \
4016             + b'\x79\xc6\x56\x87\x92\x28' \
4017             + b'\xb1\x81' \
4018             + b'\xbe' \
4019             + b'\x00' \
4020             + b'\x01\xab' \
4021             + b'\x42' \
4022             + b'\xfe' \
4023             + b'\x00\x00' \
4024             + b'\xa4\x5d\x5c\x42' \
4025             + b'\xa2\x5c\x2e\x05' \
4026             + b'\x5a\x94' \
4027             + b'\x64\xd4'
4028
4029         buf += match
4030
4031         # OFP_FLOW_STATS_1_PACK_STR
4032         # '!IIHHH6xQQQ'...duration_sec, duration_nsec, priority,
4033         #                 idle_timeout, hard_timeout, zfill,
4034         #                 cookie, packet_count, byte_count
4035         duration_sec = {'buf': b'\x94\x19\xb3\xd2', 'val': 2484712402}
4036         duration_nsec = {'buf': b'\xee\x66\xcf\x7c', 'val': 3999715196}
4037         priority = {'buf': b'\xe1\xc0', 'val': 57792}
4038         idle_timeout = {'buf': b'\x8e\x10', 'val': 36368}
4039         hard_timeout = {'buf': b'\xd4\x99', 'val': 54425}
4040         zfill = b'\x00' * 6
4041         cookie = {'buf': b'\x0b\x01\xe8\xe5\xf0\x84\x8a\xe0',
4042                   'val': 793171083674290912}
4043         packet_count = {'buf': b'\x47\x5c\xc6\x05\x28\xff\x7c\xdb',
4044                         'val': 5142202600015232219}
4045         byte_count = {'buf': b'\x24\xe9\x4b\xee\xcb\x57\xd9\xc3',
4046                       'val': 2659740543924820419}
4047
4048         buf += duration_sec['buf']
4049         buf += duration_nsec['buf']
4050         buf += priority['buf']
4051         buf += idle_timeout['buf']
4052         buf += hard_timeout['buf']
4053         buf += zfill
4054         buf += cookie['buf']
4055         buf += packet_count['buf']
4056         buf += byte_count['buf']
4057
4058         # <action>_PACK_STR...type_, len_ [others...]
4059         type = {'buf': b'\x00\x00', 'val': ofproto.OFPAT_OUTPUT}
4060         len = {'buf': b'\x00\x08',
4061                'val': ofproto.OFP_ACTION_OUTPUT_SIZE}
4062         port = {'buf': b'\x59\x2a', 'val': 22826}
4063         max_len = {'buf': b'\x00\x08',
4064                    'val': ofproto.OFP_ACTION_OUTPUT_SIZE}
4065
4066         buf += type['buf'] \
4067             + len['buf'] \
4068             + port['buf'] \
4069             + max_len['buf']
4070
4071         res = OFPFlowStatsReply.parser(object,
4072                                        version['val'],
4073                                        msg_type['val'],
4074                                        msg_len['val'],
4075                                        xid['val'],
4076                                        buf)
4077
4078         eq_(version['val'], res.version)
4079         eq_(msg_type['val'], res.msg_type)
4080         eq_(msg_len['val'], res.msg_len)
4081         eq_(xid['val'], res.xid)
4082         eq_(type_['val'], res.type)
4083         eq_(flags['val'], res.flags)
4084
4085         # body
4086         body = res.body[0]
4087         eq_(length['val'], body.length)
4088         eq_(table_id['val'], body.table_id)
4089         eq_(duration_sec['val'], body.duration_sec)
4090         eq_(duration_nsec['val'], body.duration_nsec)
4091         eq_(priority['val'], body.priority)
4092         eq_(idle_timeout['val'], body.idle_timeout)
4093         eq_(hard_timeout['val'], body.hard_timeout)
4094         eq_(cookie['val'], body.cookie)
4095         eq_(packet_count['val'], body.packet_count)
4096         eq_(byte_count['val'], body.byte_count)
4097
4098         # action
4099         action = body.actions[0]
4100         eq_(type['val'], action.type)
4101         eq_(len['val'], action.len)
4102         eq_(port['val'], action.port)
4103         eq_(max_len['val'], action.max_len)
4104
4105     def test_serialize(self):
4106         # Not used.
4107         pass
4108
4109
4110 class TestOFPAggregateStatsReply(unittest.TestCase):
4111     """ Test case for ofproto_v1_0_parser.OFPAggregateStatsReply
4112     """
4113
4114     class Datapath(object):
4115         ofproto = ofproto  # copy to class attribute
4116         ofproto_parser = ofproto_v1_0_parser
4117
4118     c = OFPAggregateStatsReply(Datapath)
4119
4120     def setUp(self):
4121         pass
4122
4123     def tearDown(self):
4124         pass
4125
4126     def test_init(self):
4127         pass
4128
4129     def test_parser(self):
4130         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
4131         msg_type = {'buf': b'\x11', 'val': ofproto.OFPT_STATS_REPLY}
4132         msg_len_val = ofproto.OFP_STATS_MSG_SIZE \
4133             + ofproto.OFP_AGGREGATE_STATS_REPLY_SIZE
4134         msg_len = {'buf': b'\x00\x4c', 'val': msg_len_val}
4135         xid = {'buf': b'\xc6\xd6\xce\x38', 'val': 3335966264}
4136
4137         buf = version['buf'] \
4138             + msg_type['buf'] \
4139             + msg_len['buf'] \
4140             + xid['buf']
4141
4142         # OFP_STATS_MSG_PACK_STR
4143         # '!HH'...type_, flags
4144         type_ = {'buf': b'\x00\x02', 'val': ofproto.OFPST_AGGREGATE}
4145         flags = {'buf': b'\x65\x66', 'val': 25958}
4146
4147         buf += type_['buf'] \
4148             + flags['buf']
4149
4150         # stats_type_cls = OFPAggregateStats
4151         # OFP_AGGREGATE_STATS_REPLY_PACK_STR
4152         # '!QQI4x'...packet_count, byte_count, flow_count, zfill
4153         packet_count = {'buf': b'\x43\x95\x1b\xfb\x0f\xf6\xa7\xdd',
4154                         'val': 4869829337189623773}
4155         byte_count = {'buf': b'\x36\xda\x2d\x80\x2a\x95\x35\xdd',
4156                       'val': 3952521651464517085}
4157         flow_count = {'buf': b'\xc3\x0d\xc3\xed', 'val': 3272459245}
4158         zfill = b'\x00' * 4
4159
4160         buf += packet_count['buf'] \
4161             + byte_count['buf'] \
4162             + flow_count['buf'] \
4163             + zfill
4164
4165         res = OFPAggregateStatsReply.parser(object,
4166                                             version['val'],
4167                                             msg_type['val'],
4168                                             msg_len['val'],
4169                                             xid['val'],
4170                                             buf)
4171
4172         eq_(version['val'], res.version)
4173         eq_(msg_type['val'], res.msg_type)
4174         eq_(msg_len['val'], res.msg_len)
4175         eq_(xid['val'], res.xid)
4176         eq_(type_['val'], res.type)
4177         eq_(flags['val'], res.flags)
4178
4179         # body
4180         body = res.body[0]
4181         eq_(packet_count['val'], body.packet_count)
4182         eq_(byte_count['val'], body.byte_count)
4183         eq_(flow_count['val'], body.flow_count)
4184
4185     def test_serialize(self):
4186         # Not used.
4187         pass
4188
4189
4190 class TestOFPTableStatsReply(unittest.TestCase):
4191     """ Test case for ofproto_v1_0_parser.OFPTableStatsReply
4192     """
4193
4194     class Datapath(object):
4195         ofproto = ofproto  # copy to class attribute
4196         ofproto_parser = ofproto_v1_0_parser
4197
4198     c = OFPTableStatsReply(Datapath)
4199
4200     def setUp(self):
4201         pass
4202
4203     def tearDown(self):
4204         pass
4205
4206     def test_init(self):
4207         pass
4208
4209     def test_parser(self):
4210         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
4211         msg_type = {'buf': b'\x11', 'val': ofproto.OFPT_STATS_REPLY}
4212         msg_len_val = ofproto.OFP_STATS_MSG_SIZE \
4213             + ofproto.OFP_TABLE_STATS_SIZE
4214         msg_len = {'buf': b'\x00\x4c', 'val': msg_len_val}
4215         xid = {'buf': b'\xd6\xb4\x8d\xe6', 'val': 3602157030}
4216
4217         buf = version['buf'] \
4218             + msg_type['buf'] \
4219             + msg_len['buf'] \
4220             + xid['buf']
4221
4222         # OFP_STATS_MSG_PACK_STR
4223         # '!HH'...type_, flags
4224         type_ = {'buf': b'\x00\x03', 'val': ofproto.OFPST_TABLE}
4225         flags = {'buf': b'\xb3\xf0', 'val': 46064}
4226
4227         buf += type_['buf'] \
4228             + flags['buf']
4229
4230         # stats_type_cls = OFPTableStats
4231         # OFP_TABLE_STATS_PACK_STR
4232         # '!B3x32sIIIQQ'...table_id, zfill, name, wildcards, max_entries,
4233         #                  active_count, lookup_count, matched_count
4234         table_id = {'buf': b'\x5b', 'val': 91}
4235         zfill = b'\x00' * 3
4236         name = b'name'.ljust(32)
4237         wildcards = {'buf': b'\xc5\xaf\x6e\x12', 'val': 3316608530}
4238         max_entries = {'buf': b'\x95\x6c\x78\x4d', 'val': 2506913869}
4239         active_count = {'buf': b'\x78\xac\xa8\x1e', 'val': 2024581150}
4240         lookup_count = {'buf': b'\x40\x1d\x9c\x39\x19\xec\xd4\x1c',
4241                         'val': 4620020561814017052}
4242         matched_count = {'buf': b'\x27\x35\x02\xb6\xc5\x5e\x17\x65',
4243                          'val': 2825167325263435621}
4244
4245         buf += table_id['buf'] \
4246             + zfill \
4247             + name \
4248             + wildcards['buf'] \
4249             + max_entries['buf'] \
4250             + active_count['buf'] \
4251             + lookup_count['buf'] \
4252             + matched_count['buf']
4253
4254         res = OFPTableStatsReply.parser(object,
4255                                         version['val'],
4256                                         msg_type['val'],
4257                                         msg_len['val'],
4258                                         xid['val'],
4259                                         buf)
4260
4261         eq_(version['val'], res.version)
4262         eq_(msg_type['val'], res.msg_type)
4263         eq_(msg_len['val'], res.msg_len)
4264         eq_(xid['val'], res.xid)
4265         eq_(type_['val'], res.type)
4266         eq_(flags['val'], res.flags)
4267
4268         # body
4269         body = res.body[0]
4270         eq_(table_id['val'], body.table_id)
4271         eq_(name, body.name)
4272         eq_(wildcards['val'], body.wildcards)
4273         eq_(max_entries['val'], body.max_entries)
4274         eq_(active_count['val'], body.active_count)
4275         eq_(lookup_count['val'], body.lookup_count)
4276         eq_(matched_count['val'], body.matched_count)
4277
4278     def test_serialize(self):
4279         # Not used.
4280         pass
4281
4282
4283 class TestOFPPortStatsReply(unittest.TestCase):
4284     """ Test case for ofproto_v1_0_parser.OFPPortStatsReply
4285     """
4286
4287     class Datapath(object):
4288         ofproto = ofproto  # copy to class attribute
4289         ofproto_parser = ofproto_v1_0_parser
4290
4291     c = OFPPortStatsReply(Datapath)
4292
4293     def setUp(self):
4294         pass
4295
4296     def tearDown(self):
4297         pass
4298
4299     def test_init(self):
4300         pass
4301
4302     def test_parser(self):
4303         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
4304         msg_type = {'buf': b'\x11', 'val': ofproto.OFPT_STATS_REPLY}
4305         msg_len_val = ofproto.OFP_STATS_MSG_SIZE \
4306             + ofproto.OFP_PORT_STATS_SIZE
4307         msg_len = {'buf': b'\x00\x74', 'val': msg_len_val}
4308         xid = {'buf': b'\xc2\xaf\x3d\xff', 'val': 3266264575}
4309
4310         buf = version['buf'] \
4311             + msg_type['buf'] \
4312             + msg_len['buf'] \
4313             + xid['buf']
4314
4315         # OFP_STATS_MSG_PACK_STR
4316         # '!HH'...type_, flags
4317         type_ = {'buf': b'\x00\x04', 'val': ofproto.OFPST_PORT}
4318         flags = {'buf': b'\xda\xde', 'val': 56030}
4319
4320         buf += type_['buf'] \
4321             + flags['buf']
4322
4323         # stats_type_cls = OFPPortStats
4324         # OFP_PORT_STATS_PACK_STR
4325         # '!H6xQQQQQQQQQQQQ'... port_no, zfill, rx_packets, tx_packets,
4326         #                       rx_bytes, tx_bytes, rx_dropped, tx_dropped,
4327         #                       rx_errors, tx_errors, rx_frame_err,
4328         #                       rx_over_err, rx_crc_err, collisions
4329         port_no = {'buf': b'\xe7\x6b', 'val': 59243}
4330         zfill = b'\x00' * 6
4331         rx_packets = {'buf': b'\x53\x44\x36\x61\xc4\x86\xc0\x37',
4332                       'val': 5999980397101236279}
4333         tx_packets = {'buf': b'\x27\xa4\x41\xd7\xd4\x53\x9e\x42',
4334                       'val': 2856480458895760962}
4335         rx_bytes = {'buf': b'\x55\xa1\x38\x60\x43\x97\x0d\x89',
4336                     'val': 6170274950576278921}
4337         tx_bytes = {'buf': b'\x77\xe1\xd5\x63\x18\xae\x63\xaa',
4338                     'val': 8638420181865882538}
4339         rx_dropped = {'buf': b'\x60\xe6\x20\x01\x24\xda\x4e\x5a',
4340                       'val': 6982303461569875546}
4341         tx_dropped = {'buf': b'\x09\x2d\x5d\x71\x71\xb6\x8e\xc7',
4342                       'val': 661287462113808071}
4343         rx_errors = {'buf': b'\x2f\x7e\x35\xb3\x66\x3c\x19\x0d',
4344                      'val': 3422231811478788365}
4345         tx_errors = {'buf': b'\x57\x32\x08\x2f\x88\x32\x40\x6b',
4346                      'val': 6283093430376743019}
4347         rx_frame_err = {'buf': b'\x0c\x28\x6f\xad\xce\x66\x6e\x8b',
4348                         'val': 876072919806406283}
4349         rx_over_err = {'buf': b'\x5a\x90\x8f\x9b\xfc\x82\x2e\xa0',
4350                        'val': 6525873760178941600}
4351         rx_crc_err = {'buf': b'\x73\x3a\x71\x17\xd6\x74\x69\x47',
4352                       'val': 8303073210207070535}
4353         collisions = {'buf': b'\x2f\x52\x0c\x79\x96\x03\x6e\x79',
4354                       'val': 3409801584220270201}
4355
4356         buf += port_no['buf'] \
4357             + zfill \
4358             + rx_packets['buf'] \
4359             + tx_packets['buf'] \
4360             + rx_bytes['buf'] \
4361             + tx_bytes['buf'] \
4362             + rx_dropped['buf'] \
4363             + tx_dropped['buf'] \
4364             + rx_errors['buf'] \
4365             + tx_errors['buf'] \
4366             + rx_frame_err['buf'] \
4367             + rx_over_err['buf'] \
4368             + rx_crc_err['buf'] \
4369             + collisions['buf']
4370
4371         res = OFPPortStatsReply.parser(object,
4372                                        version['val'],
4373                                        msg_type['val'],
4374                                        msg_len['val'],
4375                                        xid['val'],
4376                                        buf)
4377
4378         eq_(version['val'], res.version)
4379         eq_(msg_type['val'], res.msg_type)
4380         eq_(msg_len['val'], res.msg_len)
4381         eq_(xid['val'], res.xid)
4382         eq_(type_['val'], res.type)
4383         eq_(flags['val'], res.flags)
4384
4385         # body
4386         body = res.body[0]
4387         eq_(port_no['val'], body.port_no)
4388         eq_(rx_packets['val'], body.rx_packets)
4389         eq_(tx_packets['val'], body.tx_packets)
4390         eq_(rx_bytes['val'], body.rx_bytes)
4391         eq_(tx_bytes['val'], body.tx_bytes)
4392         eq_(rx_dropped['val'], body.rx_dropped)
4393         eq_(tx_dropped['val'], body.tx_dropped)
4394         eq_(rx_errors['val'], body.rx_errors)
4395         eq_(tx_errors['val'], body.tx_errors)
4396         eq_(rx_frame_err['val'], body.rx_frame_err)
4397         eq_(rx_over_err['val'], body.rx_over_err)
4398         eq_(rx_crc_err['val'], body.rx_crc_err)
4399         eq_(collisions['val'], body.collisions)
4400
4401     def test_serialize(self):
4402         # Not used.
4403         pass
4404
4405
4406 class TestOFPQueueStatsReply(unittest.TestCase):
4407     """ Test case for ofproto_v1_0_parser.OFPQueueStatsReply
4408     """
4409
4410     class Datapath(object):
4411         ofproto = ofproto  # copy to class attribute
4412         ofproto_parser = ofproto_v1_0_parser
4413
4414     c = OFPQueueStatsReply(Datapath)
4415
4416     def setUp(self):
4417         pass
4418
4419     def tearDown(self):
4420         pass
4421
4422     def test_init(self):
4423         pass
4424
4425     def test_parser(self):
4426         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
4427         msg_type = {'buf': b'\x11', 'val': ofproto.OFPT_STATS_REPLY}
4428         msg_len_val = ofproto.OFP_STATS_MSG_SIZE \
4429             + ofproto.OFP_QUEUE_STATS_SIZE
4430         msg_len = {'buf': b'\x00\x2c', 'val': msg_len_val}
4431         xid = {'buf': b'\x19\xfc\x28\x6c', 'val': 435955820}
4432
4433         buf = version['buf'] \
4434             + msg_type['buf'] \
4435             + msg_len['buf'] \
4436             + xid['buf']
4437
4438         # OFP_STATS_MSG_PACK_STR
4439         # '!HH'...type_, flags
4440         type_ = {'buf': b'\x00\x05', 'val': ofproto.OFPST_QUEUE}
4441         flags = {'buf': b'\x3b\x2b', 'val': 15147}
4442
4443         buf += type_['buf'] \
4444             + flags['buf']
4445
4446         # stats_type_cls = OFPQueueStats
4447         # OFP_QUEUE_STATS_PACK_STR
4448         # '!H2xIQQQ...port_no, queue_id, tx_bytes, tx_packets, tx_errors
4449         port_no = {'buf': b'\xe7\x6b', 'val': 59243}
4450         zfill = b'\x00' * 2
4451         queue_id = {'buf': b'\x2a\xa8\x7f\x32', 'val': 715685682}
4452         tx_bytes = {'buf': b'\x77\xe1\xd5\x63\x18\xae\x63\xaa',
4453                     'val': 8638420181865882538}
4454         tx_packets = {'buf': b'\x27\xa4\x41\xd7\xd4\x53\x9e\x42',
4455                       'val': 2856480458895760962}
4456         tx_errors = {'buf': b'\x57\x32\x08\x2f\x88\x32\x40\x6b',
4457                      'val': 6283093430376743019}
4458
4459         buf += port_no['buf'] \
4460             + zfill \
4461             + queue_id['buf'] \
4462             + tx_bytes['buf'] \
4463             + tx_packets['buf'] \
4464             + tx_errors['buf']
4465
4466         res = OFPQueueStatsReply.parser(object,
4467                                         version['val'],
4468                                         msg_type['val'],
4469                                         msg_len['val'],
4470                                         xid['val'],
4471                                         buf)
4472
4473         eq_(version['val'], res.version)
4474         eq_(msg_type['val'], res.msg_type)
4475         eq_(msg_len['val'], res.msg_len)
4476         eq_(xid['val'], res.xid)
4477         eq_(type_['val'], res.type)
4478         eq_(flags['val'], res.flags)
4479
4480         # body
4481         body = res.body[0]
4482         eq_(port_no['val'], body.port_no)
4483         eq_(queue_id['val'], body.queue_id)
4484         eq_(tx_bytes['val'], body.tx_bytes)
4485         eq_(tx_packets['val'], body.tx_packets)
4486         eq_(tx_errors['val'], body.tx_errors)
4487
4488     def test_serialize(self):
4489         # Not used.
4490         pass
4491
4492
4493 class TestOFPVendorStatsReply(unittest.TestCase):
4494     """ Test case for ofproto_v1_0_parser.OFPVendorStatsReply
4495     """
4496
4497     class Datapath(object):
4498         ofproto = ofproto  # copy to class attribute
4499         ofproto_parser = ofproto_v1_0_parser
4500
4501     c = OFPVendorStatsReply(Datapath)
4502
4503     def setUp(self):
4504         pass
4505
4506     def tearDown(self):
4507         pass
4508
4509     def test_init(self):
4510         pass
4511
4512     def test_parser(self):
4513         version = {'buf': b'\x01', 'val': ofproto.OFP_VERSION}
4514         msg_type = {'buf': b'\x11', 'val': ofproto.OFPT_STATS_REPLY}
4515         # ofproto.OFP_STATS_MSG_SIZE + len(specific_data)
4516         msg_len = {'buf': b'\x00\x18',
4517                    'val': ofproto.OFP_STATS_MSG_SIZE + 12}
4518         xid = {'buf': b'\x94\xc4\xd2\xcd', 'val': 2495926989}
4519
4520         buf = version['buf'] \
4521             + msg_type['buf'] \
4522             + msg_len['buf'] \
4523             + xid['buf']
4524
4525         # OFP_STATS_MSG_PACK_STR
4526         # '!HH'...type_, flags
4527         type_ = {'buf': b'\xff\xff', 'val': ofproto.OFPST_VENDOR}
4528         flags = {'buf': b'\x30\xd9', 'val': 12505}
4529
4530         buf += type_['buf'] \
4531             + flags['buf']
4532
4533         # stats_type_cls = OFPVendorStats
4534         specific_data = b'specific_data'
4535
4536         buf += specific_data
4537
4538         res = OFPVendorStatsReply.parser(object,
4539                                          version['val'],
4540                                          msg_type['val'],
4541                                          msg_len['val'],
4542                                          xid['val'],
4543                                          buf)
4544
4545         eq_(version['val'], res.version)
4546         eq_(msg_type['val'], res.msg_type)
4547         eq_(msg_len['val'], res.msg_len)
4548         eq_(xid['val'], res.xid)
4549         eq_(type_['val'], res.type)
4550         eq_(flags['val'], res.flags)
4551
4552         # body
4553         body = res.body[0]
4554         eq_(specific_data, body)
4555
4556     def test_serialize(self):
4557         # Not used.
4558         pass
4559
4560
4561 class TestOFPFeaturesRequest(unittest.TestCase):
4562     """ Test case for ofproto_v1_0_parser.OFPFeaturesRequest
4563     """
4564
4565     class Datapath(object):
4566         ofproto = ofproto  # copy to class attribute
4567         ofproto_parser = ofproto_v1_0_parser
4568
4569     c = OFPFeaturesRequest(Datapath)
4570
4571     def setUp(self):
4572         pass
4573
4574     def tearDown(self):
4575         pass
4576
4577     def test_init(self):
4578         pass
4579
4580     def test_parser(self):
4581         # Not used.
4582         pass
4583
4584     def test_serialize(self):
4585         self.c.serialize()
4586
4587         eq_(ofproto.OFP_VERSION, self.c.version)
4588         eq_(ofproto.OFPT_FEATURES_REQUEST, self.c.msg_type)
4589         eq_(0, self.c.xid)
4590
4591         fmt = ofproto.OFP_HEADER_PACK_STR
4592
4593         res = struct.unpack(fmt, six.binary_type(self.c.buf))
4594         eq_(ofproto.OFP_VERSION, res[0])
4595         eq_(ofproto.OFPT_FEATURES_REQUEST, res[1])
4596         eq_(len(self.c.buf), res[2])
4597         eq_(0, res[3])
4598
4599
4600 class TestOFPGetConfigRequest(unittest.TestCase):
4601     """ Test case for ofproto_v1_0_parser.OFPGetConfigRequest
4602     """
4603
4604     class Datapath(object):
4605         ofproto = ofproto  # copy to class attribute
4606         ofproto_parser = ofproto_v1_0_parser
4607
4608     c = OFPGetConfigRequest(Datapath)
4609
4610     def setUp(self):
4611         pass
4612
4613     def tearDown(self):
4614         pass
4615
4616     def test_init(self):
4617         pass
4618
4619     def test_parser(self):
4620         # Not used.
4621         pass
4622
4623     def test_serialize(self):
4624         self.c.serialize()
4625
4626         eq_(ofproto.OFP_VERSION, self.c.version)
4627         eq_(ofproto.OFPT_GET_CONFIG_REQUEST, self.c.msg_type)
4628         eq_(0, self.c.xid)
4629
4630         fmt = ofproto.OFP_HEADER_PACK_STR
4631
4632         res = struct.unpack(fmt, six.binary_type(self.c.buf))
4633         eq_(ofproto.OFP_VERSION, res[0])
4634         eq_(ofproto.OFPT_GET_CONFIG_REQUEST, res[1])
4635         eq_(len(self.c.buf), res[2])
4636         eq_(0, res[3])
4637
4638
4639 class TestOFPSetConfig(unittest.TestCase):
4640     """ Test case for ofproto_v1_0_parser.OFPSetConfig
4641     """
4642
4643     class Datapath(object):
4644         ofproto = ofproto  # copy to class attribute
4645         ofproto_parser = ofproto_v1_0_parser
4646
4647     # OFP_SWITCH_CONFIG_PACK_STR
4648     # '!HH'...flags, miss_send_len
4649     flags = {'buf': b'\xa0\xe2', 'val': 41186}
4650     miss_send_len = {'buf': b'\x36\x0e', 'val': 13838}
4651
4652     c = OFPSetConfig(Datapath,
4653                      flags['val'],
4654                      miss_send_len['val'])
4655
4656     def setUp(self):
4657         pass
4658
4659     def tearDown(self):
4660         pass
4661
4662     def test_init(self):
4663         eq_(self.flags['val'], self.c.flags)
4664         eq_(self.miss_send_len['val'], self.c.miss_send_len)
4665
4666     def test_parser(self):
4667         # Not used.
4668         pass
4669
4670     def test_serialize(self):
4671         self.c.serialize()
4672
4673         eq_(ofproto.OFP_VERSION, self.c.version)
4674         eq_(ofproto.OFPT_SET_CONFIG, self.c.msg_type)
4675         eq_(0, self.c.xid)
4676
4677         fmt = '!' \
4678             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
4679             + ofproto.OFP_SWITCH_CONFIG_PACK_STR.replace('!', '')
4680
4681         res = struct.unpack(fmt, six.binary_type(self.c.buf))
4682         eq_(ofproto.OFP_VERSION, res[0])
4683         eq_(ofproto.OFPT_SET_CONFIG, res[1])
4684         eq_(len(self.c.buf), res[2])
4685         eq_(0, res[3])
4686         eq_(self.flags['val'], res[4])
4687         eq_(self.miss_send_len['val'], res[5])
4688
4689
4690 class TestOFPPacketOut(unittest.TestCase):
4691     """ Test case for ofproto_v1_0_parser.OFPPacketOut
4692     """
4693
4694     port = 0x2ae0
4695     actions = [OFPActionOutput(port, max_len=0)]
4696
4697     def setUp(self):
4698         pass
4699
4700     def tearDown(self):
4701         pass
4702
4703     def _get_obj(self, buffer_id, in_port, data=None):
4704         class Datapath(object):
4705             ofproto = ofproto  # copy to class attribute
4706             ofproto_parser = ofproto_v1_0_parser
4707
4708         c = OFPPacketOut(Datapath,
4709                          buffer_id,
4710                          in_port,
4711                          self.actions,
4712                          data)
4713         return c
4714
4715     def test_init(self):
4716         buffer_id = 0xffffffff
4717         in_port = 0x40455
4718         data = 'Message'
4719
4720         c = self._get_obj(buffer_id, in_port, data)
4721
4722         eq_(buffer_id, c.buffer_id)
4723         eq_(in_port, c.in_port)
4724         eq_(data, c.data)
4725
4726     def test_parser(self):
4727         # Not used.
4728         pass
4729
4730     def test_serialize(self):
4731         buffer_id = 0xffffffff
4732         in_port = 0x9e07
4733         data = b'Message'
4734
4735         c = self._get_obj(buffer_id, in_port, data)
4736         c.serialize()
4737
4738         eq_(ofproto.OFP_VERSION, c.version)
4739         eq_(ofproto.OFPT_PACKET_OUT, c.msg_type)
4740         eq_(0, c.xid)
4741
4742         fmt = '!' \
4743             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
4744             + ofproto.OFP_PACKET_OUT_PACK_STR.replace('!', '') \
4745             + ofproto.OFP_ACTION_OUTPUT_PACK_STR.replace('!', '') \
4746             + str(len(data)) + 's'
4747
4748         res = struct.unpack(fmt, six.binary_type(c.buf))
4749
4750         # OFP_HEADER_PACK_STR
4751         eq_(ofproto.OFP_VERSION, res[0])
4752         eq_(ofproto.OFPT_PACKET_OUT, res[1])
4753         eq_(len(c.buf), res[2])
4754         eq_(0, res[3])
4755
4756         # OFP_PACKET_OUT_PACK_STR
4757         eq_(buffer_id, res[4])
4758         eq_(in_port, res[5])
4759         eq_(ofproto.OFP_ACTION_OUTPUT_SIZE, res[6])
4760
4761         # OFP_ACTION_OUTPUT_PACK_STR
4762         eq_(ofproto.OFPAT_OUTPUT, res[7])
4763         eq_(ofproto.OFP_ACTION_OUTPUT_SIZE, res[8])
4764         eq_(self.port, res[9])
4765         eq_(0, res[10])
4766
4767         # data
4768         eq_(data, res[11])
4769
4770     @raises(AssertionError)
4771     def test_serialize_check_buffer_id(self):
4772         buffer_id = 0xffffff00
4773         in_port = 0xaa92
4774         data = 'Message'
4775
4776         c = self._get_obj(buffer_id, in_port, data)
4777         c.serialize()
4778
4779
4780 class TestOFPFlowMod(unittest.TestCase):
4781     """ Test case for ofproto_v1_0_parser.OFPFlowMod
4782     """
4783
4784     # OFP_FLOW_MOD_PACK_STR0
4785     # '!QHHHHIHH'...cookie, command, idle_timeout, hard_timeout,
4786     #               priority, buffer_id, out_port, flags
4787     cookie = {'buf': b'\x1d\x86\xce\x6e\x8d\xc0\xbe\xa8',
4788               'val': 2127614848199081640}
4789     command = {'buf': b'\xe1\x55', 'val': 57685}
4790     idle_timeout = {'buf': b'\xf3\x6d', 'val': 62317}
4791     hard_timeout = {'buf': b'\x1c\xc5', 'val': 7365}
4792     priority = {'buf': b'\x9c\xe3', 'val': 40163}
4793     buffer_id = {'buf': b'\xf0\xa1\x80\x33', 'val': 4037115955}
4794     out_port = {'buf': b'\xfe\x0d', 'val': 65037}
4795     flags = {'buf': b'\x00\x87', 'val': 135}
4796
4797     # OFP_MATCH_PACK_STR
4798     # '!IH6s6sHBxHBB2xIIHH'...wildcards, in_port, dl_src, dl_dst, dl_vlan,
4799     #                         dl_vlan_pcp, dl_type, nw_tos, nw_proto,
4800     #                         nw_src, nw_dst, tp_src, tp_dst
4801     wildcards = {'buf': b'\xd2\x71\x25\x23', 'val': 3530630435}
4802     in_port = {'buf': b'\x37\x8b', 'val': 14219}
4803     dl_src = b'\xdf\xcf\xe1\x5d\xcf\xc0'
4804     dl_dst = b'\x76\xb3\xfb\xc6\x21\x2f'
4805     dl_vlan = {'buf': b'\xc1\xf9', 'val': 49657}
4806     dl_vlan_pcp = {'buf': b'\x79', 'val': 121}
4807     zfill0 = b'\x00'
4808     dl_type = {'buf': b'\xa6\x9e', 'val': 42654}
4809     nw_tos = {'buf': b'\xde', 'val': 222}
4810     nw_proto = {'buf': b'\xe5', 'val': 229}
4811     zfil11 = b'\x00' * 2
4812     nw_src = {'buf': b'\x1b\x6d\x8d\x4b', 'val': 460164427}
4813     nw_dst = {'buf': b'\xab\x25\xe1\x20', 'val': 2871386400}
4814     tp_src = {'buf': b'\xd5\xc3', 'val': 54723}
4815     tp_dst = {'buf': b'\x78\xb9', 'val': 30905}
4816
4817     match = OFPMatch(wildcards['val'],
4818                      in_port['val'],
4819                      dl_src,
4820                      dl_dst,
4821                      dl_vlan['val'],
4822                      dl_vlan_pcp['val'],
4823                      dl_type['val'],
4824                      nw_tos['val'],
4825                      nw_proto['val'],
4826                      nw_src['val'],
4827                      nw_dst['val'],
4828                      tp_src['val'],
4829                      tp_dst['val'])
4830
4831     port = 0x2ae0
4832     actions = [OFPActionOutput(port, max_len=1000)]
4833
4834     def setUp(self):
4835         pass
4836
4837     def tearDown(self):
4838         pass
4839
4840     def _get_obj(self, actions=None):
4841         class Datapath(object):
4842             ofproto = ofproto  # copy to class attribute
4843             ofproto_parser = ofproto_v1_0_parser
4844
4845         c = OFPFlowMod(Datapath,
4846                        self.match,
4847                        self.cookie['val'],
4848                        self.command['val'],
4849                        self.idle_timeout['val'],
4850                        self.hard_timeout['val'],
4851                        self.priority['val'],
4852                        self.buffer_id['val'],
4853                        self.out_port['val'],
4854                        self.flags['val'],
4855                        actions)
4856
4857         return c
4858
4859     def test_init(self):
4860         c = self._get_obj()
4861
4862         eq_(self.cookie['val'], c.cookie)
4863         eq_(self.command['val'], c.command)
4864         eq_(self.idle_timeout['val'], c.idle_timeout)
4865         eq_(self.hard_timeout['val'], c.hard_timeout)
4866         eq_(self.priority['val'], c.priority)
4867         eq_(self.buffer_id['val'], c.buffer_id)
4868         eq_(self.out_port['val'], c.out_port)
4869         eq_(self.flags['val'], c.flags)
4870
4871     def test_init_actions(self):
4872         c = self._get_obj(self.actions)
4873         action = c.actions[0]
4874
4875         eq_(self.port, action.port)
4876
4877     def test_parser(self):
4878         # Not used.
4879         pass
4880
4881     def test_serialize(self):
4882         c = self._get_obj(self.actions)
4883         c.serialize()
4884
4885         eq_(ofproto.OFP_VERSION, c.version)
4886         eq_(ofproto.OFPT_FLOW_MOD, c.msg_type)
4887         eq_(0, c.xid)
4888
4889         fmt = '!' \
4890             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
4891             + ofproto.OFP_MATCH_PACK_STR.replace('!', '') \
4892             + ofproto.OFP_FLOW_MOD_PACK_STR0.replace('!', '') \
4893             + ofproto.OFP_ACTION_OUTPUT_PACK_STR.replace('!', '')
4894
4895         res = struct.unpack(fmt, six.binary_type(c.buf))
4896
4897         # OFP_HEADER_PACK_STR
4898         eq_(ofproto.OFP_VERSION, res[0])
4899         eq_(ofproto.OFPT_FLOW_MOD, res[1])
4900         eq_(len(c.buf), res[2])
4901         eq_(0, res[3])
4902
4903         # OFP_MATCH_PACK_STR
4904         eq_(self.wildcards['val'], res[4])
4905         eq_(self.in_port['val'], res[5])
4906         eq_(self.dl_src, res[6])
4907         eq_(self.dl_dst, res[7])
4908         eq_(self.dl_vlan['val'], res[8])
4909         eq_(self.dl_vlan_pcp['val'], res[9])
4910         eq_(self.dl_type['val'], res[10])
4911         eq_(self.nw_tos['val'], res[11])
4912         eq_(self.nw_proto['val'], res[12])
4913         eq_(self.nw_src['val'], res[13])
4914         eq_(self.nw_dst['val'], res[14])
4915         eq_(self.tp_src['val'], res[15])
4916         eq_(self.tp_dst['val'], res[16])
4917
4918         # OFP_FLOW_MOD_PACK_STR0
4919         eq_(self.cookie['val'], res[17])
4920         eq_(self.command['val'], res[18])
4921         eq_(self.idle_timeout['val'], res[19])
4922         eq_(self.hard_timeout['val'], res[20])
4923         eq_(self.priority['val'], res[21])
4924         eq_(self.buffer_id['val'], res[22])
4925         eq_(self.out_port['val'], res[23])
4926         eq_(self.flags['val'], res[24])
4927
4928         # OFP_ACTION_OUTPUT_PACK_STR
4929         eq_(ofproto.OFPAT_OUTPUT, res[25])
4930         eq_(ofproto.OFP_ACTION_OUTPUT_SIZE, res[26])
4931         eq_(self.port, res[27])
4932         eq_(1000, res[28])
4933
4934
4935 class TestOFPBarrierRequest(unittest.TestCase):
4936     """ Test case for ofproto_v1_0_parser.OFPBarrierRequest
4937     """
4938
4939     class Datapath(object):
4940         ofproto = ofproto  # copy to class attribute
4941         ofproto_parser = ofproto_v1_0_parser
4942
4943     c = OFPBarrierRequest(Datapath)
4944
4945     def setUp(self):
4946         pass
4947
4948     def tearDown(self):
4949         pass
4950
4951     def test_init(self):
4952         pass
4953
4954     def test_parser(self):
4955         # Not used.
4956         pass
4957
4958     def test_serialize(self):
4959         self.c.serialize()
4960
4961         eq_(ofproto.OFP_VERSION, self.c.version)
4962         eq_(ofproto.OFPT_BARRIER_REQUEST, self.c.msg_type)
4963         eq_(0, self.c.xid)
4964
4965         fmt = ofproto.OFP_HEADER_PACK_STR
4966
4967         res = struct.unpack(fmt, six.binary_type(self.c.buf))
4968         eq_(ofproto.OFP_VERSION, res[0])
4969         eq_(ofproto.OFPT_BARRIER_REQUEST, res[1])
4970         eq_(len(self.c.buf), res[2])
4971         eq_(0, res[3])
4972
4973
4974 class TestOFPQueueGetConfigRequest(unittest.TestCase):
4975     """ Test case for ofproto_v1_0_parser.OFPQueueGetConfigRequest
4976     """
4977
4978     class Datapath(object):
4979         ofproto = ofproto  # copy to class attribute
4980         ofproto_parser = ofproto_v1_0_parser
4981
4982     # OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR
4983     # '!H2x'...port, zfill
4984     port = {'buf': b'\xa0\xe2', 'val': 41186}
4985     zfill = b'\x00' * 2
4986
4987     c = OFPQueueGetConfigRequest(Datapath,
4988                                  port['val'])
4989
4990     def setUp(self):
4991         pass
4992
4993     def tearDown(self):
4994         pass
4995
4996     def test_init(self):
4997         eq_(self.port['val'], self.c.port)
4998
4999     def test_parser(self):
5000         # Not used.
5001         pass
5002
5003     def test_serialize(self):
5004         self.c.serialize()
5005
5006         eq_(ofproto.OFP_VERSION, self.c.version)
5007         eq_(ofproto.OFPT_QUEUE_GET_CONFIG_REQUEST, self.c.msg_type)
5008         eq_(0, self.c.xid)
5009
5010         a = ofproto.OFP_HEADER_PACK_STR.replace('!', '')
5011         b = ofproto.OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR.replace('!', '')
5012         fmt = '!' + a + b
5013
5014         res = struct.unpack(fmt, six.binary_type(self.c.buf))
5015         eq_(ofproto.OFP_VERSION, res[0])
5016         eq_(ofproto.OFPT_QUEUE_GET_CONFIG_REQUEST, res[1])
5017         eq_(len(self.c.buf), res[2])
5018         eq_(0, res[3])
5019         eq_(self.port['val'], res[4])
5020
5021
5022 class TestOFPDescStatsRequest(unittest.TestCase):
5023     """ Test case for ofproto_v1_0_parser.OFPDescStatsRequest
5024     """
5025
5026     class Datapath(object):
5027         ofproto = ofproto  # copy to class attribute
5028         ofproto_parser = ofproto_v1_0_parser
5029
5030     flags = {'buf': b'\x00\x00', 'val': 0}
5031
5032     c = OFPDescStatsRequest(Datapath, flags['val'])
5033
5034     def setUp(self):
5035         pass
5036
5037     def tearDown(self):
5038         pass
5039
5040     def test_init(self):
5041         eq_(ofproto.OFPST_DESC, self.c.type)
5042         eq_(self.flags['val'], self.c.flags)
5043
5044     def test_parser(self):
5045         # Not used.
5046         pass
5047
5048     def test_serialize(self):
5049         self.c.serialize()
5050
5051         eq_(ofproto.OFP_VERSION, self.c.version)
5052         eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5053         eq_(0, self.c.xid)
5054
5055         fmt = '!' \
5056             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5057             + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '')
5058
5059         res = struct.unpack(fmt, six.binary_type(self.c.buf))
5060
5061         # OFP_HEADER_PACK_STR
5062         eq_(ofproto.OFP_VERSION, res[0])
5063         eq_(ofproto.OFPT_STATS_REQUEST, res[1])
5064         eq_(len(self.c.buf), res[2])
5065         eq_(0, res[3])
5066
5067         # OFP_STATS_MSG_PACK_STR
5068         eq_(ofproto.OFPST_DESC, res[4])
5069         eq_(self.flags['val'], res[5])
5070
5071
5072 class TestOFPFlowStatsRequest(unittest.TestCase):
5073     """ Test case for ofproto_v1_0_parser.OFPFlowStatsRequest
5074     """
5075
5076     class Datapath(object):
5077         ofproto = ofproto  # copy to class attribute
5078         ofproto_parser = ofproto_v1_0_parser
5079
5080     flags = {'buf': b'\x00\x00', 'val': 0}
5081
5082     # OFP_MATCH_PACK_STR
5083     # '!IH6s6sHBxHBB2xIIHH'...wildcards, in_port, dl_src, dl_dst, dl_vlan,
5084     #                         dl_vlan_pcp, dl_type, nw_tos, nw_proto,
5085     #                         nw_src, nw_dst, tp_src, tp_dst
5086     wildcards = {'buf': b'\xd2\x71\x25\x23', 'val': 3530630435}
5087     in_port = {'buf': b'\x37\x8b', 'val': 14219}
5088     dl_src = b'\x58\xd0\x8a\x69\xa4\xfc'
5089     dl_dst = b'\xb6\xe2\xef\xb1\xa6\x2d'
5090     dl_vlan = {'buf': b'\xc1\xf9', 'val': 49657}
5091     dl_vlan_pcp = {'buf': b'\x79', 'val': 121}
5092     zfill0 = b'\x00'
5093     dl_type = {'buf': b'\xa6\x9e', 'val': 42654}
5094     nw_tos = {'buf': b'\xde', 'val': 222}
5095     nw_proto = {'buf': b'\xe5', 'val': 229}
5096     zfil11 = b'\x00' * 2
5097     nw_src = {'buf': b'\x1b\x6d\x8d\x4b', 'val': 460164427}
5098     nw_dst = {'buf': b'\xab\x25\xe1\x20', 'val': 2871386400}
5099     tp_src = {'buf': b'\xd5\xc3', 'val': 54723}
5100     tp_dst = {'buf': b'\x78\xb9', 'val': 30905}
5101
5102     match = OFPMatch(wildcards['val'],
5103                      in_port['val'],
5104                      dl_src,
5105                      dl_dst,
5106                      dl_vlan['val'],
5107                      dl_vlan_pcp['val'],
5108                      dl_type['val'],
5109                      nw_tos['val'],
5110                      nw_proto['val'],
5111                      nw_src['val'],
5112                      nw_dst['val'],
5113                      tp_src['val'],
5114                      tp_dst['val'])
5115
5116     # OFP_FLOW_STATS_REQUEST_ID_PORT_STR
5117     # '!BxH'...table_id, zfill, out_port
5118     table_id = {'buf': b'\xd1', 'val': 209}
5119     zfill = b'\x00' * 1
5120     out_port = {'buf': b'\xe4\x9a', 'val': 58522}
5121
5122     c = OFPFlowStatsRequest(Datapath,
5123                             flags['val'],
5124                             match,
5125                             table_id['val'],
5126                             out_port['val'])
5127
5128     def setUp(self):
5129         pass
5130
5131     def tearDown(self):
5132         pass
5133
5134     def test_init(self):
5135         eq_(ofproto.OFPST_FLOW, self.c.type)
5136         eq_(self.flags['val'], self.c.flags)
5137         eq_(self.table_id['val'], self.c.table_id)
5138         eq_(self.out_port['val'], self.c.out_port)
5139
5140         # match
5141         match = self.c.match
5142         eq_(self.match.__hash__(), match.__hash__())
5143
5144     def test_parser(self):
5145         # Not used.
5146         pass
5147
5148     def test_serialize(self):
5149         self.c.serialize()
5150
5151         eq_(ofproto.OFP_VERSION, self.c.version)
5152         eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5153         eq_(0, self.c.xid)
5154
5155         fmt = '!' \
5156             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5157             + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
5158             + ofproto.OFP_MATCH_PACK_STR.replace('!', '') \
5159             + ofproto.OFP_FLOW_STATS_REQUEST_ID_PORT_STR.replace('!', '')
5160
5161         res = struct.unpack(fmt, six.binary_type(self.c.buf))
5162
5163         # OFP_HEADER_PACK_STR
5164         eq_(ofproto.OFP_VERSION, res[0])
5165         eq_(ofproto.OFPT_STATS_REQUEST, res[1])
5166         eq_(len(self.c.buf), res[2])
5167         eq_(0, res[3])
5168
5169         # OFP_STATS_MSG_PACK_STR
5170         eq_(ofproto.OFPST_FLOW, res[4])
5171         eq_(self.flags['val'], res[5])
5172
5173         # OFP_MATCH_PACK_STR
5174         eq_(self.wildcards['val'], res[6])
5175         eq_(self.in_port['val'], res[7])
5176         eq_(self.dl_src, res[8])
5177         eq_(self.dl_dst, res[9])
5178         eq_(self.dl_vlan['val'], res[10])
5179         eq_(self.dl_vlan_pcp['val'], res[11])
5180         eq_(self.dl_type['val'], res[12])
5181         eq_(self.nw_tos['val'], res[13])
5182         eq_(self.nw_proto['val'], res[14])
5183         eq_(self.nw_src['val'], res[15])
5184         eq_(self.nw_dst['val'], res[16])
5185         eq_(self.tp_src['val'], res[17])
5186         eq_(self.tp_dst['val'], res[18])
5187
5188         # OFP_FLOW_STATS_REQUEST_ID_PORT_STR
5189         eq_(self.table_id['val'], res[19])
5190         eq_(self.out_port['val'], res[20])
5191
5192
5193 class TestOFPAggregateStatsRequest(unittest.TestCase):
5194     """ Test case for ofproto_v1_0_parser.OFPAggregateStatsRequest
5195     """
5196
5197     class Datapath(object):
5198         ofproto = ofproto  # copy to class attribute
5199         ofproto_parser = ofproto_v1_0_parser
5200
5201     flags = {'buf': b'\x00\x00', 'val': 0}
5202
5203     # OFP_MATCH_PACK_STR
5204     # '!IH6s6sHBxHBB2xIIHH'...wildcards, in_port, dl_src, dl_dst, dl_vlan,
5205     #                         dl_vlan_pcp, dl_type, nw_tos, nw_proto,
5206     #                         nw_src, nw_dst, tp_src, tp_dst
5207     wildcards = {'buf': b'\xea\x66\x4a\xd4', 'val': 3932572372}
5208     in_port = {'buf': b'\x64\xac', 'val': 25772}
5209     dl_src = b'\x90\x13\x60\x5e\x20\x4d'
5210     dl_dst = b'\xb5\x5d\x14\x5e\xb9\x22'
5211     dl_vlan = {'buf': b'\x8b\xeb', 'val': 35819}
5212     dl_vlan_pcp = {'buf': b'\xe8', 'val': 232}
5213     zfill0 = b'\x00'
5214     dl_type = {'buf': b'\62\xc9', 'val': 25289}
5215     nw_tos = {'buf': b'\xb5', 'val': 181}
5216     nw_proto = {'buf': b'\xc4', 'val': 196}
5217     zfil11 = b'\x00' * 2
5218     nw_src = {'buf': b'\xb7\xd1\xb7\xef', 'val': 3083974639}
5219     nw_dst = {'buf': b'\x7c\xc6\x18\x15', 'val': 2093357077}
5220     tp_src = {'buf': b'\x26\x9a', 'val': 9882}
5221     tp_dst = {'buf': b'\x7a\x89', 'val': 31369}
5222
5223     match = OFPMatch(wildcards['val'],
5224                      in_port['val'],
5225                      dl_src,
5226                      dl_dst,
5227                      dl_vlan['val'],
5228                      dl_vlan_pcp['val'],
5229                      dl_type['val'],
5230                      nw_tos['val'],
5231                      nw_proto['val'],
5232                      nw_src['val'],
5233                      nw_dst['val'],
5234                      tp_src['val'],
5235                      tp_dst['val'])
5236
5237     # OFP_FLOW_STATS_REQUEST_ID_PORT_STR
5238     # '!BxH'...table_id, zfill, out_port
5239     table_id = {'buf': b'\xd1', 'val': 209}
5240     zfill = b'\x00' * 1
5241     out_port = {'buf': b'\xb5\xe8', 'val': 46568}
5242
5243     c = OFPAggregateStatsRequest(Datapath,
5244                                  flags['val'],
5245                                  match,
5246                                  table_id['val'],
5247                                  out_port['val'])
5248
5249     def setUp(self):
5250         pass
5251
5252     def tearDown(self):
5253         pass
5254
5255     def test_init(self):
5256         eq_(ofproto.OFPST_AGGREGATE, self.c.type)
5257         eq_(self.flags['val'], self.c.flags)
5258         eq_(self.table_id['val'], self.c.table_id)
5259         eq_(self.out_port['val'], self.c.out_port)
5260
5261         # match
5262         match = self.c.match
5263         eq_(self.match.__hash__(), match.__hash__())
5264
5265     def test_parser(self):
5266         # Not used.
5267         pass
5268
5269     def test_serialize(self):
5270         self.c.serialize()
5271
5272         eq_(ofproto.OFP_VERSION, self.c.version)
5273         eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5274         eq_(0, self.c.xid)
5275
5276         fmt = '!' \
5277             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5278             + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
5279             + ofproto.OFP_MATCH_PACK_STR.replace('!', '') \
5280             + ofproto.OFP_FLOW_STATS_REQUEST_ID_PORT_STR.replace('!', '')
5281
5282         res = struct.unpack(fmt, six.binary_type(self.c.buf))
5283
5284         # OFP_HEADER_PACK_STR
5285         eq_(ofproto.OFP_VERSION, res[0])
5286         eq_(ofproto.OFPT_STATS_REQUEST, res[1])
5287         eq_(len(self.c.buf), res[2])
5288         eq_(0, res[3])
5289
5290         # OFP_STATS_MSG_PACK_STR
5291         eq_(ofproto.OFPST_AGGREGATE, res[4])
5292         eq_(self.flags['val'], res[5])
5293
5294         # OFP_MATCH_PACK_STR
5295         eq_(self.wildcards['val'], res[6])
5296         eq_(self.in_port['val'], res[7])
5297         eq_(self.dl_src, res[8])
5298         eq_(self.dl_dst, res[9])
5299         eq_(self.dl_vlan['val'], res[10])
5300         eq_(self.dl_vlan_pcp['val'], res[11])
5301         eq_(self.dl_type['val'], res[12])
5302         eq_(self.nw_tos['val'], res[13])
5303         eq_(self.nw_proto['val'], res[14])
5304         eq_(self.nw_src['val'], res[15])
5305         eq_(self.nw_dst['val'], res[16])
5306         eq_(self.tp_src['val'], res[17])
5307         eq_(self.tp_dst['val'], res[18])
5308
5309         # OFP_FLOW_STATS_REQUEST_ID_PORT_STR
5310         eq_(self.table_id['val'], res[19])
5311         eq_(self.out_port['val'], res[20])
5312
5313
5314 class TestOFPTableStatsRequest(unittest.TestCase):
5315     """ Test case for ofproto_v1_0_parser.OFPTableStatsRequest
5316     """
5317
5318     class Datapath(object):
5319         ofproto = ofproto  # copy to class attribute
5320         ofproto_parser = ofproto_v1_0_parser
5321
5322     flags = {'buf': b'\x00\x00', 'val': 0}
5323
5324     c = OFPTableStatsRequest(Datapath, flags['val'])
5325
5326     def setUp(self):
5327         pass
5328
5329     def tearDown(self):
5330         pass
5331
5332     def test_init(self):
5333         eq_(ofproto.OFPST_TABLE, self.c.type)
5334         eq_(self.flags['val'], self.c.flags)
5335
5336     def test_parser(self):
5337         # Not used.
5338         pass
5339
5340     def test_serialize(self):
5341         self.c.serialize()
5342
5343         eq_(ofproto.OFP_VERSION, self.c.version)
5344         eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5345         eq_(0, self.c.xid)
5346
5347         fmt = '!' \
5348             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5349             + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '')
5350
5351         res = struct.unpack(fmt, six.binary_type(self.c.buf))
5352
5353         # OFP_HEADER_PACK_STR
5354         eq_(ofproto.OFP_VERSION, res[0])
5355         eq_(ofproto.OFPT_STATS_REQUEST, res[1])
5356         eq_(len(self.c.buf), res[2])
5357         eq_(0, res[3])
5358
5359         # OFP_STATS_MSG_PACK_STR
5360         eq_(ofproto.OFPST_TABLE, res[4])
5361         eq_(self.flags['val'], res[5])
5362
5363
5364 class TestOFPPortStatsRequest(unittest.TestCase):
5365     """ Test case for ofproto_v1_0_parser.OFPPortStatsRequest
5366     """
5367
5368     class Datapath(object):
5369         ofproto = ofproto  # copy to class attribute
5370         ofproto_parser = ofproto_v1_0_parser
5371
5372     flags = {'buf': b'\x00\x00', 'val': 0}
5373
5374     # OFP_PORT_STATS_REQUEST_PACK_STR
5375     # '!H6x'...port_no, zfill
5376     port_no = {'buf': b'\x6d\x27', 'val': 27943}
5377
5378     c = OFPPortStatsRequest(Datapath,
5379                             flags['val'],
5380                             port_no['val'])
5381
5382     def setUp(self):
5383         pass
5384
5385     def tearDown(self):
5386         pass
5387
5388     def test_init(self):
5389         eq_(ofproto.OFPST_PORT, self.c.type)
5390         eq_(self.flags['val'], self.c.flags)
5391         eq_(self.port_no['val'], self.c.port_no)
5392
5393     def test_parser(self):
5394         # Not used.
5395         pass
5396
5397     def test_serialize(self):
5398         self.c.serialize()
5399
5400         eq_(ofproto.OFP_VERSION, self.c.version)
5401         eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5402         eq_(0, self.c.xid)
5403
5404         fmt = '!' \
5405             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5406             + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
5407             + ofproto.OFP_PORT_STATS_REQUEST_PACK_STR.replace('!', '')
5408
5409         res = struct.unpack(fmt, six.binary_type(self.c.buf))
5410
5411         # OFP_HEADER_PACK_STR
5412         eq_(ofproto.OFP_VERSION, res[0])
5413         eq_(ofproto.OFPT_STATS_REQUEST, res[1])
5414         eq_(len(self.c.buf), res[2])
5415         eq_(0, res[3])
5416
5417         # OFP_STATS_MSG_PACK_STR
5418         eq_(ofproto.OFPST_PORT, res[4])
5419         eq_(self.flags['val'], res[5])
5420
5421         # OFP_PORT_STATS_REQUEST_PACK_STR
5422         eq_(self.port_no['val'], res[6])
5423
5424
5425 class TestOFPQueueStatsRequest(unittest.TestCase):
5426     """ Test case for ofproto_v1_0_parser.OFPQueueStatsRequest
5427     """
5428
5429     class Datapath(object):
5430         ofproto = ofproto  # copy to class attribute
5431         ofproto_parser = ofproto_v1_0_parser
5432
5433     flags = {'buf': b'\x00\x00', 'val': 0}
5434
5435     # OFP_QUEUE_STATS_REQUEST_PACK_STR
5436     # '!HxxI'...port_no, zfill, zfill, queue_id
5437     port_no = {'buf': b'\x0c\x2d', 'val': 3117}
5438     queue_id = {'buf': b'\x1b\xe6\xba\x36', 'val': 468105782}
5439
5440     c = OFPQueueStatsRequest(Datapath,
5441                              flags['val'],
5442                              port_no['val'],
5443                              queue_id['val'])
5444
5445     def setUp(self):
5446         pass
5447
5448     def tearDown(self):
5449         pass
5450
5451     def test_init(self):
5452         eq_(ofproto.OFPST_QUEUE, self.c.type)
5453         eq_(self.flags['val'], self.c.flags)
5454         eq_(self.port_no['val'], self.c.port_no)
5455         eq_(self.queue_id['val'], self.c.queue_id)
5456
5457     def test_parser(self):
5458         # Not used.
5459         pass
5460
5461     def test_serialize(self):
5462         self.c.serialize()
5463
5464         eq_(ofproto.OFP_VERSION, self.c.version)
5465         eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5466         eq_(0, self.c.xid)
5467
5468         fmt = '!' \
5469             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5470             + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
5471             + ofproto.OFP_QUEUE_STATS_REQUEST_PACK_STR.replace('!', '')
5472
5473         res = struct.unpack(fmt, six.binary_type(self.c.buf))
5474
5475         # OFP_HEADER_PACK_STR
5476         eq_(ofproto.OFP_VERSION, res[0])
5477         eq_(ofproto.OFPT_STATS_REQUEST, res[1])
5478         eq_(len(self.c.buf), res[2])
5479         eq_(0, res[3])
5480
5481         # OFP_STATS_MSG_PACK_STR
5482         eq_(ofproto.OFPST_QUEUE, res[4])
5483         eq_(self.flags['val'], res[5])
5484
5485         # OFP_QUEUE_STATS_REQUEST_PACK_STR
5486         eq_(self.port_no['val'], res[6])
5487         eq_(self.queue_id['val'], res[7])
5488
5489
5490 class TestOFPVendorStatsRequest(unittest.TestCase):
5491     """ Test case for ofproto_v1_0_parser.OFPVendorStatsRequest
5492     """
5493
5494     class Datapath(object):
5495         ofproto = ofproto  # copy to class attribute
5496         ofproto_parser = ofproto_v1_0_parser
5497
5498     flags = {'buf': b'\x00\x00', 'val': 0}
5499
5500     # OFP_VENDOR_STATS_MSG_PACK_STR
5501     # '!I'...vendor
5502     vendor = {'buf': b'\xff\xff\xff\xff', 'val': ofproto.OFPAT_VENDOR}
5503
5504     specific_data = b'specific_data'
5505
5506     c = OFPVendorStatsRequest(Datapath,
5507                               flags['val'],
5508                               vendor['val'],
5509                               specific_data)
5510
5511     def setUp(self):
5512         pass
5513
5514     def tearDown(self):
5515         pass
5516
5517     def test_init(self):
5518         eq_(ofproto.OFPST_VENDOR, self.c.type)
5519         eq_(self.flags['val'], self.c.flags)
5520         eq_(self.vendor['val'], self.c.vendor)
5521         eq_(self.specific_data, self.c.specific_data)
5522
5523     def test_parser(self):
5524         # Not used.
5525         pass
5526
5527     def test_serialize(self):
5528         self.c.serialize()
5529
5530         eq_(ofproto.OFP_VERSION, self.c.version)
5531         eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5532         eq_(0, self.c.xid)
5533
5534         fmt = '!' \
5535             + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5536             + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
5537             + ofproto.OFP_VENDOR_STATS_MSG_PACK_STR.replace('!', '') \
5538             + str(len(self.specific_data)) + 's'
5539
5540         res = struct.unpack(fmt, six.binary_type(self.c.buf))
5541
5542         # OFP_HEADER_PACK_STR
5543         eq_(ofproto.OFP_VERSION, res[0])
5544         eq_(ofproto.OFPT_STATS_REQUEST, res[1])
5545         eq_(len(self.c.buf), res[2])
5546         eq_(0, res[3])
5547
5548         # OFP_STATS_MSG_PACK_STR
5549         eq_(ofproto.OFPST_VENDOR, res[4])
5550         eq_(self.flags['val'], res[5])
5551
5552         # OFP_VENDOR_STATS_MSG_PACK_STR
5553         eq_(self.vendor['val'], res[6])
5554
5555         # specific_data
5556         eq_(self.specific_data, res[7])