1 # Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # vim: tabstop=4 shiftwidth=4 softtabstop=4
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
28 LOG = logging.getLogger('test_ofproto_v10')
31 class TestOFPPhyPort(unittest.TestCase):
32 """ Test case for ofproto_v1_0_parser.OFPPhyPort
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}
48 buf = port_no['buf'] \
49 + addrconv.mac.text_to_bin(hw_addr) \
58 c = OFPPhyPort(port_no['val'],
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)
85 def test_parser(self):
86 res = self.c.parser(self.buf, 0)
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)
99 class TestOFPMatch(unittest.TestCase):
100 """ Test case for ofproto_v1_0_parser.OFPMatch
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}
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}
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}
127 buf = wildcards['buf'] \
132 + dl_vlan_pcp['buf'] \
143 def _get_obj(self, dl_src, dl_dst):
144 c = OFPMatch(self.wildcards['val'],
149 self.dl_vlan_pcp['val'],
152 self.nw_proto['val'],
166 c = self._get_obj(self.dl_src['buf'], self.dl_dst['buf'])
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)
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)
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)
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)
205 def test_serialize(self):
207 c = self._get_obj(self.dl_src['buf'], self.dl_dst['buf'])
211 fmt = ofproto.OFP_MATCH_PACK_STR
212 res = struct.unpack_from(fmt, six.binary_type(buf))
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])
228 def test_getitem(self):
229 c = self._get_obj(self.dl_src['buf'], self.dl_dst['buf'])
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"])
246 class TestOFPActionHeader(unittest.TestCase):
247 """ Test case for ofproto_v1_0_parser.OFPActionHeader
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}
260 c = OFPActionHeader(type['val'], len['val'])
269 eq_(self.type['val'], self.c.type)
270 eq_(self.len['val'], self.c.len)
272 def test_serialize(self):
274 self.c.serialize(buf, 0)
276 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
277 res = struct.unpack(fmt, six.binary_type(buf))
279 eq_(self.type['val'], res[0])
280 eq_(self.len['val'], res[1])
283 class TestOFPActionOutput(unittest.TestCase):
284 """ Test case for ofproto_v1_0_parser.OFPActionOutput
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}
299 c = OFPActionOutput(port['val'], max_len['val'])
308 eq_(self.port['val'], self.c.port)
309 eq_(self.max_len['val'], self.c.max_len)
311 def test_parser(self):
312 res = self.c.parser(self.buf, 0)
314 eq_(self.port['val'], res.port)
315 eq_(self.max_len['val'], res.max_len)
317 @raises(AssertionError)
318 def test_parser_check_type(self):
319 type_ = {'buf': b'\x00\x01', 'val': 1}
324 + self.max_len['buf']
326 self.c.parser(buf, 0)
328 @raises(AssertionError)
329 def test_parser_check_len(self):
330 len_ = {'buf': b'\x00\x07', 'val': 7}
332 buf = self.type_['buf'] \
335 + self.max_len['buf']
337 self.c.parser(buf, 0)
339 def test_serialize(self):
341 self.c.serialize(buf, 0)
343 fmt = ofproto.OFP_ACTION_OUTPUT_PACK_STR
344 res = struct.unpack(fmt, six.binary_type(buf))
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])
352 class TestOFPActionVlanVid(unittest.TestCase):
353 """ Test case for ofproto_v1_0_parser.OFPActionVlanVid
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}
368 c = OFPActionVlanVid(vlan_vid['val'])
377 eq_(self.vlan_vid['val'], self.c.vlan_vid)
379 def test_parser(self):
380 res = self.c.parser(self.buf, 0)
382 eq_(self.vlan_vid['val'], res.vlan_vid)
384 @raises(AssertionError)
385 def test_parser_check_type(self):
386 type_ = {'buf': b'\x00\x02', 'val': 2}
390 + self.vlan_vid['buf'] \
393 self.c.parser(buf, 0)
395 @raises(AssertionError)
396 def test_parser_check_len(self):
397 len_ = {'buf': b'\x00\x07', 'val': 7}
399 buf = self.type_['buf'] \
401 + self.vlan_vid['buf'] \
404 self.c.parser(buf, 0)
406 def test_serialize(self):
408 self.c.serialize(buf, 0)
410 fmt = ofproto.OFP_ACTION_VLAN_VID_PACK_STR
411 res = struct.unpack(fmt, six.binary_type(buf))
413 eq_(self.type_['val'], res[0])
414 eq_(self.len_['val'], res[1])
415 eq_(self.vlan_vid['val'], res[2])
418 class TestOFPActionVlanPcp(unittest.TestCase):
419 """ Test case for ofproto_v1_0_parser.OFPActionVlanPcp
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}
434 c = OFPActionVlanPcp(vlan_pcp['val'])
443 eq_(self.vlan_pcp['val'], self.c.vlan_pcp)
445 def test_parser(self):
446 res = self.c.parser(self.buf, 0)
447 eq_(self.vlan_pcp['val'], res.vlan_pcp)
449 @raises(AssertionError)
450 def test_parser_check_type(self):
451 type_ = {'buf': b'\x00\x01', 'val': 1}
455 + self.vlan_pcp['buf'] \
458 self.c.parser(buf, 0)
460 @raises(AssertionError)
461 def test_parser_check_len(self):
462 len_ = {'buf': b'\x00\x07', 'val': 7}
464 buf = self.type_['buf'] \
466 + self.vlan_pcp['buf'] \
469 self.c.parser(buf, 0)
471 def test_serialize(self):
473 self.c.serialize(buf, 0)
475 fmt = ofproto.OFP_ACTION_VLAN_PCP_PACK_STR
476 res = struct.unpack(fmt, six.binary_type(buf))
478 eq_(self.type_['val'], res[0])
479 eq_(self.len_['val'], res[1])
480 eq_(self.vlan_pcp['val'], res[2])
483 class TestOFPActionStripVlan(unittest.TestCase):
484 """ Test case for ofproto_v1_0_parser.OFPActionStripVlan
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}
497 c = OFPActionStripVlan()
508 def test_parser(self):
509 ok_(self.c.parser(self.buf, 0))
511 @raises(AssertionError)
512 def test_parser_check_type(self):
513 type_ = {'buf': b'\x00\x01', 'val': 1}
519 self.c.parser(buf, 0)
521 @raises(AssertionError)
522 def test_parser_check_len(self):
523 len_ = {'buf': b'\x00\x07', 'val': 7}
525 buf = self.type_['buf'] \
529 self.c.parser(buf, 0)
532 class TestOFPActionSetDlSrc(unittest.TestCase):
533 """ Test case for ofproto_v1_0_parser.OFPActionSetDlSrc
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'
548 c = OFPActionSetDlSrc(dl_addr)
557 eq_(self.dl_addr, self.c.dl_addr)
559 def test_parser_type_src(self):
560 res = self.c.parser(self.buf, 0)
561 eq_(self.dl_addr, res.dl_addr)
563 def test_parser_type_dst(self):
564 type_ = {'buf': b'\x00\x05', 'val': ofproto.OFPAT_SET_DL_DST}
570 res = self.c.parser(buf, 0)
572 eq_(self.dl_addr, res.dl_addr)
574 @raises(AssertionError)
575 def test_parser_check_type(self):
576 type_ = {'buf': b'\x00\x06', 'val': 6}
582 res = self.c.parser(buf, 0)
584 @raises(AssertionError)
585 def test_parser_check_len(self):
586 len_ = {'buf': b'\x00\x07', 'val': 7}
587 buf = self.type_['buf'] \
592 res = self.c.parser(buf, 0)
594 def test_serialize(self):
596 self.c.serialize(buf, 0)
598 fmt = ofproto.OFP_ACTION_DL_ADDR_PACK_STR
599 res = struct.unpack(fmt, six.binary_type(buf))
601 eq_(self.type_['val'], res[0])
602 eq_(self.len_['val'], res[1])
603 eq_(self.dl_addr, res[2])
606 class TestOFPActionSetDlDst(unittest.TestCase):
607 """ Test case for ofproto_v1_0_parser.OFPActionSetDlDst
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'
622 c = OFPActionSetDlDst(dl_addr)
631 eq_(self.dl_addr, self.c.dl_addr)
633 def test_parser_type_dst(self):
634 res = self.c.parser(self.buf, 0)
635 eq_(self.dl_addr, res.dl_addr)
637 def test_parser_type_src(self):
638 type_ = {'buf': b'\x00\x04', 'val': ofproto.OFPAT_SET_DL_SRC}
644 res = self.c.parser(buf, 0)
646 eq_(self.dl_addr, res.dl_addr)
648 @raises(AssertionError)
649 def test_parser_check_type(self):
650 type_ = {'buf': b'\x00\x06', 'val': 6}
656 res = self.c.parser(buf, 0)
658 @raises(AssertionError)
659 def test_parser_check_len(self):
660 len_ = {'buf': b'\x00\x07', 'val': 7}
661 buf = self.type_['buf'] \
666 res = self.c.parser(buf, 0)
668 def test_serialize(self):
670 self.c.serialize(buf, 0)
672 fmt = ofproto.OFP_ACTION_DL_ADDR_PACK_STR
673 res = struct.unpack(fmt, six.binary_type(buf))
675 eq_(self.type_['val'], res[0])
676 eq_(self.len_['val'], res[1])
677 eq_(self.dl_addr, res[2])
680 class TestOFPActionSetNwSrc(unittest.TestCase):
681 """ Test case for ofproto_v1_0_parser.OFPActionSetNwSrc
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}
694 c = OFPActionSetNwSrc(nw_addr['val'])
703 eq_(self.nw_addr['val'], self.c.nw_addr)
705 def test_parser_src(self):
706 res = self.c.parser(self.buf, 0)
707 eq_(self.nw_addr['val'], res.nw_addr)
709 def test_parser_dst(self):
710 type_ = {'buf': b'\x00\x07', 'val': ofproto.OFPAT_SET_NW_DST}
714 + self.nw_addr['buf']
716 res = self.c.parser(buf, 0)
717 eq_(self.nw_addr['val'], res.nw_addr)
719 @raises(AssertionError)
720 def test_parser_check_type(self):
721 type_ = {'buf': b'\x00\x05', 'val': 5}
725 + self.nw_addr['buf']
727 self.c.parser(buf, 0)
729 @raises(AssertionError)
730 def test_parser_check_len(self):
731 len_ = {'buf': b'\x00\x10', 'val': 16}
733 buf = self.type_['buf'] \
735 + self.nw_addr['buf']
737 self.c.parser(buf, 0)
739 def test_serialize(self):
741 self.c.serialize(buf, 0)
743 fmt = ofproto.OFP_ACTION_NW_ADDR_PACK_STR
744 res = struct.unpack(fmt, six.binary_type(buf))
746 eq_(self.type_['val'], res[0])
747 eq_(self.len_['val'], res[1])
748 eq_(self.nw_addr['val'], res[2])
751 class TestOFPActionSetNwDst(unittest.TestCase):
752 """ Test case for ofproto_v1_0_parser.OFPActionSetNwDst
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}
765 c = OFPActionSetNwDst(nw_addr['val'])
774 eq_(self.nw_addr['val'], self.c.nw_addr)
776 def test_parser_dst(self):
777 res = self.c.parser(self.buf, 0)
778 eq_(self.nw_addr['val'], res.nw_addr)
780 def test_parser_src(self):
781 type_ = {'buf': b'\x00\x06', 'val': ofproto.OFPAT_SET_NW_SRC}
785 + self.nw_addr['buf']
787 res = self.c.parser(buf, 0)
788 eq_(self.nw_addr['val'], res.nw_addr)
790 @raises(AssertionError)
791 def test_parser_check_type(self):
792 type_ = {'buf': b'\x00\x05', 'val': 5}
796 + self.nw_addr['buf']
798 self.c.parser(buf, 0)
800 @raises(AssertionError)
801 def test_parser_check_len(self):
802 len_ = {'buf': b'\x00\x10', 'val': 16}
804 buf = self.type_['buf'] \
806 + self.nw_addr['buf']
808 self.c.parser(buf, 0)
810 def test_serialize(self):
812 self.c.serialize(buf, 0)
814 fmt = ofproto.OFP_ACTION_NW_ADDR_PACK_STR
815 res = struct.unpack(fmt, six.binary_type(buf))
817 eq_(self.type_['val'], res[0])
818 eq_(self.len_['val'], res[1])
819 eq_(self.nw_addr['val'], res[2])
822 class TestOFPActionSetNwTos(unittest.TestCase):
823 """ Test case for ofproto_v1_0_parser.OFPActionSetNwTos
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}
838 c = OFPActionSetNwTos(tos['val'])
847 eq_(self.tos['val'], self.c.tos)
849 def test_parser(self):
850 res = self.c.parser(self.buf, 0)
851 eq_(self.tos['val'], res.tos)
853 @raises(AssertionError)
854 def test_parser_check_type(self):
855 type_ = {'buf': b'\x00\x05', 'val': 5}
862 self.c.parser(buf, 0)
864 @raises(AssertionError)
865 def test_parser_check_len(self):
866 len_ = {'buf': b'\x00\x07', 'val': 7}
868 buf = self.type_['buf'] \
873 self.c.parser(buf, 0)
875 def test_serialize(self):
877 self.c.serialize(buf, 0)
879 fmt = ofproto.OFP_ACTION_NW_TOS_PACK_STR
880 res = struct.unpack(fmt, six.binary_type(buf))
882 eq_(self.type_['val'], res[0])
883 eq_(self.len_['val'], res[1])
884 eq_(self.tos['val'], res[2])
887 class TestOFPActionSetTpSrc(unittest.TestCase):
888 """ Test case for ofproto_v1_0_parser.OFPActionSetTpSrc
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}
903 c = OFPActionSetTpSrc(tp['val'])
912 eq_(self.tp['val'], self.c.tp)
914 def test_parser_src(self):
915 res = self.c.parser(self.buf, 0)
916 eq_(self.tp['val'], res.tp)
918 def test_parser_dst(self):
919 type_ = {'buf': b'\x00\x0a', 'val': ofproto.OFPAT_SET_TP_DST}
926 res = self.c.parser(self.buf, 0)
927 eq_(self.tp['val'], res.tp)
929 @raises(AssertionError)
930 def test_parser_check_type(self):
931 type_ = {'buf': b'\x00\x07', 'val': 7}
938 self.c.parser(buf, 0)
940 @raises(AssertionError)
941 def test_parser_check_len(self):
942 len_ = {'buf': b'\x00\x07', 'val': 7}
944 buf = self.type_['buf'] \
949 self.c.parser(buf, 0)
951 def test_serialize(self):
953 self.c.serialize(buf, 0)
955 fmt = ofproto.OFP_ACTION_TP_PORT_PACK_STR
956 res = struct.unpack(fmt, six.binary_type(buf))
958 eq_(self.type_['val'], res[0])
959 eq_(self.len_['val'], res[1])
960 eq_(self.tp['val'], res[2])
963 class TestOFPActionSetTpDst(unittest.TestCase):
964 """ Test case for ofproto_v1_0_parser.OFPActionSetTpDst
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}
979 c = OFPActionSetTpDst(tp['val'])
988 eq_(self.tp['val'], self.c.tp)
990 def test_parser_dst(self):
991 res = self.c.parser(self.buf, 0)
992 eq_(self.tp['val'], res.tp)
994 def test_parser_src(self):
995 type_ = {'buf': b'\x00\x09', 'val': ofproto.OFPAT_SET_TP_SRC}
1002 res = self.c.parser(buf, 0)
1003 eq_(self.tp['val'], res.tp)
1005 @raises(AssertionError)
1006 def test_parser_check_type(self):
1007 type_ = {'buf': b'\x00\x10', 'val': 16}
1009 buf = type_['buf'] \
1010 + self.len_['buf'] \
1014 self.c.parser(buf, 0)
1016 @raises(AssertionError)
1017 def test_parser_check_len(self):
1018 len_ = {'buf': b'\x00\x07', 'val': 7}
1020 buf = self.type_['buf'] \
1025 self.c.parser(buf, 0)
1027 def test_serialize(self):
1029 self.c.serialize(buf, 0)
1031 fmt = ofproto.OFP_ACTION_TP_PORT_PACK_STR
1032 res = struct.unpack(fmt, six.binary_type(buf))
1034 eq_(self.type_['val'], res[0])
1035 eq_(self.len_['val'], res[1])
1036 eq_(self.tp['val'], res[2])
1039 class TestOFPActionEnqueue(unittest.TestCase):
1040 """ Test case for ofproto_v1_0_parser.OFPActionEnqueue
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}
1049 queue_id = {'buf': b'\x0a\x5b\x03\x5e', 'val': 173736798}
1051 buf = type_['buf'] \
1057 c = OFPActionEnqueue(port['val'], queue_id['val'])
1065 def test_init(self):
1066 eq_(self.port['val'], self.c.port)
1067 eq_(self.queue_id['val'], self.c.queue_id)
1069 def test_parser(self):
1070 res = self.c.parser(self.buf, 0)
1072 eq_(self.port['val'], res.port)
1073 eq_(self.queue_id['val'], res.queue_id)
1075 @raises(AssertionError)
1076 def test_parser_check_type(self):
1077 type_ = {'buf': b'\x00\x0a', 'val': 10}
1079 buf = type_['buf'] \
1080 + self.len_['buf'] \
1081 + self.port['buf'] \
1083 + self.queue_id['buf']
1085 self.c.parser(buf, 0)
1087 @raises(AssertionError)
1088 def test_parser_check_len(self):
1089 len_ = {'buf': b'\x00\x05', 'val': 5}
1091 buf = self.type_['buf'] \
1093 + self.port['buf'] \
1095 + self.queue_id['buf']
1097 self.c.parser(buf, 0)
1099 def test_serialize(self):
1101 self.c.serialize(buf, 0)
1103 fmt = ofproto.OFP_ACTION_ENQUEUE_PACK_STR
1104 res = struct.unpack(fmt, six.binary_type(buf))
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])
1112 class TestNXActionResubmit(unittest.TestCase):
1113 """ Test case for ofproto_v1_0_parser.NXActionResubmit
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}
1126 buf = type_['buf'] \
1134 c = NXActionResubmit(in_port['val'])
1142 def test_init(self):
1143 eq_(self.subtype['val'], self.c.subtype)
1144 eq_(self.in_port['val'], self.c.in_port)
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)
1152 def test_serialize(self):
1154 self.c.serialize(buf, 0)
1156 fmt = ofproto.NX_ACTION_RESUBMIT_PACK_STR
1157 res = struct.unpack(fmt, six.binary_type(buf))
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])
1166 class TestNXActionResubmitTable(unittest.TestCase):
1167 """ Test case for ofproto_v1_0_parser.NXActionResubmitTable
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}
1180 buf = type_['buf'] \
1188 c = NXActionResubmitTable(in_port['val'], table_id['val'])
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)
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)
1208 def test_serialize(self):
1210 self.c.serialize(buf, 0)
1212 fmt = ofproto.NX_ACTION_RESUBMIT_PACK_STR
1213 res = struct.unpack(fmt, six.binary_type(buf))
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])
1223 class TestNXActionSetTunnel(unittest.TestCase):
1224 """ Test case for ofproto_v1_0_parser.NXActionSetTunnel
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}
1234 tun_id = {'buf': b'\x01\x6f\x01\xd0', 'val': 24052176}
1236 buf = type_['buf'] \
1243 c = NXActionSetTunnel(tun_id['val'])
1251 def test_init(self):
1252 eq_(self.subtype['val'], self.c.subtype)
1253 eq_(self.tun_id['val'], self.c.tun_id)
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)
1261 def test_serialize(self):
1263 self.c.serialize(buf, 0)
1265 fmt = ofproto.NX_ACTION_SET_TUNNEL_PACK_STR
1266 res = struct.unpack(fmt, six.binary_type(buf))
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])
1275 class TestNXActionSetQueue(unittest.TestCase):
1276 """ Test case for ofproto_v1_0_parser.NXActionSetQueue
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}
1287 queue_id = {'buf': b'\xde\xbe\xc5\x18', 'val': 3737044248}
1289 buf = type_['buf'] \
1296 c = NXActionSetQueue(queue_id['val'])
1304 def test_init(self):
1305 eq_(self.subtype['val'], self.c.subtype)
1306 eq_(self.queue_id['val'], self.c.queue_id)
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)
1314 def test_serialize(self):
1316 self.c.serialize(buf, 0)
1318 fmt = ofproto.NX_ACTION_SET_QUEUE_PACK_STR
1319 res = struct.unpack(fmt, six.binary_type(buf))
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])
1328 class TestNXActionPopQueue(unittest.TestCase):
1329 """ Test case for ofproto_v1_0_parser.NXActionPopQueue
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}
1341 buf = type_['buf'] \
1347 c = NXActionPopQueue()
1355 def test_init(self):
1356 eq_(self.subtype['val'], self.c.subtype)
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)
1364 def test_serialize(self):
1366 self.c.serialize(buf, 0)
1368 fmt = ofproto.NX_ACTION_POP_QUEUE_PACK_STR
1369 res = struct.unpack(fmt, six.binary_type(buf))
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])
1377 class TestNXActionRegMove(unittest.TestCase):
1378 """ Test case for ofproto_v1_0_parser.NXActionRegMove
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}
1395 buf = type_['buf'] \
1402 + src_field['buf'] \
1405 c = NXActionRegMove(src_field['val'],
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)
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)
1436 def test_serialize(self):
1438 self.c.serialize(buf, 0)
1440 fmt = ofproto.NX_ACTION_REG_MOVE_PACK_STR
1441 res = struct.unpack(fmt, six.binary_type(buf))
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])
1454 class TestNXActionRegLoad(unittest.TestCase):
1455 """ Test case for ofproto_v1_0_parser.NXActionRegLoad
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}
1473 buf = type_['buf'] \
1477 + ofs_nbits['buf'] \
1481 c = NXActionRegLoad(ofs_nbits['val'],
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)
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)
1505 def test_serialize(self):
1507 self.c.serialize(buf, 0)
1509 fmt = ofproto.NX_ACTION_REG_LOAD_PACK_STR
1510 res = struct.unpack(fmt, six.binary_type(buf))
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])
1521 class TestNXActionSetTunnel64(unittest.TestCase):
1522 """ Test case for ofproto_v1_0_parser.NXActionSetTunnel64
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}
1533 tun_id = {'buf': b'\x6e\x01\xa6\xea\x7e\x36\x1d\xd9',
1534 'val': 7926800345218817497}
1536 buf = type_['buf'] \
1543 c = NXActionSetTunnel64(tun_id['val'])
1551 def test_init(self):
1552 eq_(self.subtype['val'], self.c.subtype)
1553 eq_(self.tun_id['val'], self.c.tun_id)
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)
1562 def test_serialize(self):
1564 self.c.serialize(buf, 0)
1566 fmt = ofproto.NX_ACTION_SET_TUNNEL64_PACK_STR
1567 res = struct.unpack(fmt, six.binary_type(buf))
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])
1576 class TestNXActionMultipath(unittest.TestCase):
1577 """ Test case for ofproto_v1_0_parser.NXActionMultipath
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}
1600 buf = type_['buf'] \
1607 + algorithm['buf'] \
1611 + ofs_nbits['buf'] \
1614 c = NXActionMultipath(fields['val'],
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)
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)
1651 def test_serialize(self):
1653 self.c.serialize(buf, 0)
1655 fmt = ofproto.NX_ACTION_MULTIPATH_PACK_STR
1656 res = struct.unpack(fmt, six.binary_type(buf))
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])
1671 class TestNXActionBundle(unittest.TestCase):
1672 """ Test case for ofproto_v1_0_parser.NXActionBundle
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}
1693 slaves_buf = (b'\x00\x01', b'\x00\x02')
1696 _len = len_['val'] + len(slaves_val) * 2
1699 buf = type_['buf'] \
1703 + algorithm['buf'] \
1706 + slave_type['buf'] \
1708 + ofs_nbits['buf'] \
1714 c = NXActionBundle(algorithm['val'],
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)
1740 slaves = self.c.slaves
1741 eq_(self.slaves_val[0], slaves[0])
1742 eq_(self.slaves_val[1], slaves[1])
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)
1759 eq_(self.slaves_val[0], slaves[0])
1760 eq_(self.slaves_val[1], slaves[1])
1762 def test_serialize(self):
1764 self.c.serialize(buf, 0)
1767 + ofproto.NX_ACTION_BUNDLE_PACK_STR.replace('!', '') \
1770 res = struct.unpack(fmt, six.binary_type(buf))
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])
1785 class TestNXActionBundleLoad(unittest.TestCase):
1786 """ Test case for ofproto_v1_0_parser.NXActionBundleLoad
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}
1807 slaves_buf = (b'\x00\x01', b'\x00\x02')
1810 _len = len_['val'] + len(slaves_val) * 2
1813 buf = type_['buf'] \
1817 + algorithm['buf'] \
1820 + slave_type['buf'] \
1822 + ofs_nbits['buf'] \
1828 c = NXActionBundleLoad(algorithm['val'],
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)
1854 slaves = self.c.slaves
1855 eq_(self.slaves_val[0], slaves[0])
1856 eq_(self.slaves_val[1], slaves[1])
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)
1873 eq_(self.slaves_val[0], slaves[0])
1874 eq_(self.slaves_val[1], slaves[1])
1876 def test_serialize(self):
1878 self.c.serialize(buf, 0)
1881 + ofproto.NX_ACTION_BUNDLE_PACK_STR.replace('!', '') \
1884 res = struct.unpack(fmt, six.binary_type(buf))
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])
1899 class TestNXActionOutputReg(unittest.TestCase):
1900 """ Test case for ofproto_v1_0_parser.NXActionOutputReg
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}
1916 buf = type_['buf'] \
1920 + ofs_nbits['buf'] \
1925 c = NXActionOutputReg(ofs_nbits['val'],
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)
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)
1950 def test_serialize(self):
1952 self.c.serialize(buf, 0)
1954 fmt = ofproto.NX_ACTION_OUTPUT_REG_PACK_STR
1955 res = struct.unpack(fmt, six.binary_type(buf))
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])
1966 class TestNXActionExit(unittest.TestCase):
1967 """ Test case for ofproto_v1_0_parser.NXActionExit
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}
1979 buf = type_['buf'] \
1993 def test_init(self):
1994 eq_(self.subtype['val'], self.c.subtype)
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)
2002 def test_serialize(self):
2004 self.c.serialize(buf, 0)
2006 fmt = ofproto.NX_ACTION_HEADER_PACK_STR
2007 res = struct.unpack(fmt, six.binary_type(buf))
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])
2015 class TestOFPDescStats(unittest.TestCase):
2016 """ Test case for ofproto_v1_0_parser.OFPDescStats
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)
2033 c = OFPDescStats(mfr_desc, hw_desc, sw_desc, serial_num, dp_desc)
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)
2048 def test_parser(self):
2049 res = self.c.parser(self.buf, 0)
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)
2058 class TestOFPFlowStats(unittest.TestCase):
2059 """ Test case for ofproto_v1_0_parser.OFPFlowStats
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}
2069 # OFP_MATCH_PACK_STR
2070 # '!IH6s6sHBxHBB2xIIHH'...
2071 match = b'\x97\x7c\xa6\x1e' \
2073 + b'\x7a\x3e\xed\x30\x4a\x90' \
2074 + b'\x96\x8e\x67\xbe\x2f\xe2' \
2082 + b'\xa4\x5d\x5c\x42' \
2083 + b'\xa2\x5c\x2e\x05' \
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}
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)
2124 def test_init(self):
2127 def _parser(self, action=None):
2128 buf = self.table_id['buf'] \
2131 + self.duration_sec['buf'] \
2132 + self.duration_nsec['buf'] \
2133 + self.priority['buf'] \
2134 + self.idle_timeout['buf'] \
2135 + self.hard_timeout['buf'] \
2137 + self.cookie['buf'] \
2138 + self.packet_count['buf'] \
2139 + self.byte_count['buf']
2142 buf = self.length['buf'] + buf
2144 buf = self.length_append_action['buf'] + buf
2146 for a in self.action:
2147 buf = buf + a['buf']
2149 return self.c.parser(buf, 0)
2151 def test_parser(self):
2152 res = self._parser()
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)
2165 def test_parser_append_actions(self):
2166 res = self._parser(True).actions[0]
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)
2174 class TestOFPAggregateStats(unittest.TestCase):
2175 """ Test case for ofproto_v1_0_parser.OFPAggregateStats
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}
2187 buf = packet_count['buf'] \
2188 + byte_count['buf'] \
2189 + flow_count['buf'] \
2192 c = OFPAggregateStats(packet_count['val'],
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)
2207 def test_parser(self):
2209 res = self.c.parser(self.buf, 0)
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)
2216 class TestOFPTableStats(unittest.TestCase):
2217 """ Test case for ofproto_v1_0_parser.OFPTableStats
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}
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}
2234 buf = table_id['buf'] \
2237 + wildcards['buf'] \
2238 + max_entries['buf'] \
2239 + active_count['buf'] \
2240 + lookup_count['buf'] \
2241 + matched_count['buf']
2243 c = OFPTableStats(table_id['val'],
2247 active_count['val'],
2248 lookup_count['val'],
2249 matched_count['val'])
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)
2266 def test_parser(self):
2267 res = self.c.parser(self.buf, 0)
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)
2278 class TestOFPPortStats(unittest.TestCase):
2279 """ Test case for ofproto_v1_0_parser.OFPPortStats
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}
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}
2314 buf = port_no['buf'] \
2316 + rx_packets['buf'] \
2317 + tx_packets['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'] \
2329 c = OFPPortStats(port_no['val'],
2338 rx_frame_err['val'],
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)
2364 def test_parser(self):
2365 res = self.c.parser(self.buf, 0)
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)
2382 class TestOFPQueueStats(unittest.TestCase):
2383 """ Test case for ofproto_v1_0_parser.OFPQueueStats
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}
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}
2398 c = OFPQueueStats(port_no['val'],
2404 buf = port_no['buf'] \
2408 + tx_packets['buf'] \
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)
2424 def test_parser(self):
2425 res = self.c.parser(self.buf, 0)
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)
2434 class TestOFPVendorStats(unittest.TestCase):
2435 """ Test case for ofproto_v1_0_parser.OFPVendorStats
2438 specific_data = 'specific_data'
2439 specific_data_after = 'data'
2440 offset = specific_data.find(specific_data_after)
2442 c = OFPVendorStats(specific_data)
2450 def test_init(self):
2451 eq_(self.specific_data, self.c.specific_data)
2453 def test_parser(self):
2454 res = self.c.parser(self.specific_data, self.offset)
2455 eq_(self.specific_data_after, res.specific_data)
2458 class TestOFPQueuePropNone(unittest.TestCase):
2459 """ Test case for ofproto_v1_0_parser.OFPQueuePropNone
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}
2468 c = OFPQueuePropNone()
2476 def test_init(self):
2477 cls = OFPQueuePropHeader._QUEUE_PROPERTIES[self.c.cls_prop_type]
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)
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)
2487 def test_parser(self):
2488 buf = self.property['buf'] \
2492 ok_(self.c.parser(buf, 0))
2495 class TestOFPQueuePropMinRate(unittest.TestCase):
2496 """ Test case for ofproto_v1_0_parser.OFPQueuePropMinRate
2499 # OFP_QUEUE_PROP_MIN_RATE_PACK_STR
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}
2508 c = OFPQueuePropMinRate(rate['val'])
2516 def test_init(self):
2517 cls = OFPQueuePropHeader._QUEUE_PROPERTIES[self.c.cls_prop_type]
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)
2523 eq_(self.len['val'], self.c.cls_prop_len)
2524 eq_(self.len['val'], cls.cls_prop_len)
2526 def test_parser(self):
2527 res = self.c.parser(self.buf, 0)
2528 eq_(self.rate['val'], res.rate)
2531 class TestOFPPacketQueue(unittest.TestCase):
2532 """ Test case for ofproto_v1_0_parser.OFPPacketQueue
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}
2542 buf = queue_id['buf'] \
2546 c = OFPPacketQueue(queue_id['val'],
2555 def test_init(self):
2556 eq_(self.queue_id['val'], self.c.queue_id)
2557 eq_(self.len_['val'], self.c.len)
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)
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
2576 buf = self.queue_id['buf'] \
2585 res = self.c.parser(buf, 0)
2587 eq_(self.queue_id['val'], res.queue_id)
2588 eq_(len_['val'], res.len)
2590 append_cls = res.properties[0]
2592 eq_(a_type['val'], append_cls.property)
2593 eq_(a_len['val'], append_cls.len)
2594 eq_(a_rate['val'], append_cls.rate)
2597 class TestOFPHello(unittest.TestCase):
2598 """ Test case for ofproto_v1_0_parser.OFPHello
2607 def test_init(self):
2610 def test_parser(self):
2611 version = ofproto.OFP_VERSION
2612 msg_type = ofproto.OFPT_HELLO
2613 msg_len = ofproto.OFP_HEADER_SIZE
2615 data = b'\x00\x01\x02\x03'
2617 fmt = ofproto.OFP_HEADER_PACK_STR
2618 buf = struct.pack(fmt, version, msg_type, msg_len, xid) \
2621 res = OFPHello.parser(object, version, msg_type, msg_len, xid,
2624 eq_(version, res.version)
2625 eq_(msg_type, res.msg_type)
2626 eq_(msg_len, res.msg_len)
2628 eq_(six.binary_type(buf), six.binary_type(res.buf))
2630 def test_serialize(self):
2632 class Datapath(object):
2633 ofproto = ofproto # copy to class attribute
2634 ofproto_parser = ofproto_v1_0_parser
2636 c = OFPHello(Datapath)
2638 eq_(ofproto.OFP_VERSION, c.version)
2639 eq_(ofproto.OFPT_HELLO, c.msg_type)
2643 class TestOFPErrorMsg(unittest.TestCase):
2644 """ Test case for ofproto_v1_0_parser.OFPErrorMsg
2653 def test_init(self):
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.'
2666 buf = version['buf'] \
2674 res = OFPErrorMsg.parser(object,
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)
2689 def test_serialize(self):
2690 class Datapath(object):
2691 ofproto = ofproto # copy to class attribute
2692 ofproto_parser = ofproto_v1_0_parser
2696 data = b'Error Message.'
2698 c = OFPErrorMsg(Datapath)
2705 eq_(ofproto.OFP_VERSION, c.version)
2706 eq_(ofproto.OFPT_ERROR, c.msg_type)
2710 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2711 + ofproto.OFP_ERROR_MSG_PACK_STR.replace('!', '') \
2712 + str(len(data)) + 's'
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])
2724 class TestOFPEchoRequest(unittest.TestCase):
2725 """ Test case for ofproto_v1_0_parser.OFPEchoRequest
2734 def test_init(self):
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.'
2745 buf = version['buf'] \
2751 res = OFPEchoRequest.parser(object,
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)
2764 def test_serialize(self):
2765 class Datapath(object):
2766 ofproto = ofproto # copy to class attribute
2767 ofproto_parser = ofproto_v1_0_parser
2769 data = b'Request Message.'
2771 c = OFPEchoRequest(Datapath)
2776 eq_(ofproto.OFP_VERSION, c.version)
2777 eq_(ofproto.OFPT_ECHO_REQUEST, c.msg_type)
2781 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2782 + str(len(data)) + 's'
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])
2792 class TestOFPEchoReply(unittest.TestCase):
2793 """ Test case for ofproto_v1_0_parser.OFPEchoReply
2802 def test_init(self):
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.'
2813 buf = version['buf'] \
2819 res = OFPEchoReply.parser(object,
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)
2832 def test_serialize(self):
2833 class Datapath(object):
2834 ofproto = ofproto # copy to class attribute
2835 ofproto_parser = ofproto_v1_0_parser
2837 data = b'Reply Message.'
2839 c = OFPEchoReply(Datapath)
2844 eq_(ofproto.OFP_VERSION, c.version)
2845 eq_(ofproto.OFPT_ECHO_REPLY, c.msg_type)
2849 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2850 + str(len(data)) + 's'
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])
2860 class TestOFPVendor(unittest.TestCase):
2861 """ Test case for ofproto_v1_0_parser.OFPVendor
2870 def test_init(self):
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.'
2882 buf = version['buf'] \
2889 res = OFPVendor.parser(object,
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)
2903 def test_serialize(self):
2904 class Datapath(object):
2905 ofproto = ofproto # copy to class attribute
2906 ofproto_parser = ofproto_v1_0_parser
2908 vendor = {'buf': b'\x38\x4b\xf9\x6c', 'val': 944503148}
2909 data = b'Reply Message.'
2911 c = OFPVendor(Datapath)
2912 c.vendor = vendor['val']
2917 eq_(ofproto.OFP_VERSION, c.version)
2918 eq_(ofproto.OFPT_VENDOR, c.msg_type)
2920 eq_(vendor['val'], c.vendor)
2923 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2924 + ofproto.OFP_VENDOR_HEADER_PACK_STR.replace('!', '') \
2925 + str(len(data)) + 's'
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])
2932 eq_(vendor['val'], res[4])
2936 # class TestNXTRequest(unittest.TestCase):
2937 class TestNiciraHeader(unittest.TestCase):
2938 """ Test case for ofproto_v1_0_parser.NiciraHeader
2947 def test_init(self):
2948 subtype = ofproto.NXT_FLOW_MOD_TABLE_ID
2950 c = NiciraHeader(object, subtype)
2951 eq_(subtype, c.subtype)
2953 def test_parser(self):
2957 def test_serialize(self):
2958 class Datapath(object):
2959 ofproto = ofproto # copy to class attribute
2960 ofproto_parser = ofproto_v1_0_parser
2962 data = b'Reply Message.'
2963 subtype = ofproto.NXT_FLOW_MOD_TABLE_ID
2965 c = NiciraHeader(Datapath, subtype)
2970 eq_(ofproto.OFP_VERSION, c.version)
2971 eq_(ofproto.OFPT_VENDOR, c.msg_type)
2973 eq_(ofproto_common.NX_EXPERIMENTER_ID, c.vendor)
2976 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2977 + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
2978 + str(len(data)) + 's'
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])
2985 eq_(ofproto_common.NX_EXPERIMENTER_ID, res[4])
2986 eq_(subtype, res[5])
2990 class TestNXTSetFlowFormat(unittest.TestCase):
2991 """ Test case for ofproto_v1_0_parser.NXTSetFlowFormat
3000 def test_init(self):
3001 flow_format = {'buf': b'\xdc\x6b\xf5\x24', 'val': 3698062628}
3003 c = NXTSetFlowFormat(object, flow_format['val'])
3004 eq_(flow_format['val'], c.format)
3006 def test_parser(self):
3010 def test_serialize(self):
3011 class Datapath(object):
3012 ofproto = ofproto # copy to class attribute
3013 ofproto_parser = ofproto_v1_0_parser
3015 flow_format = {'buf': b'\x5a\x4e\x59\xad', 'val': 1515084205}
3017 c = NXTSetFlowFormat(Datapath, flow_format['val'])
3020 eq_(ofproto.OFP_VERSION, c.version)
3021 eq_(ofproto.OFPT_VENDOR, c.msg_type)
3023 eq_(ofproto_common.NX_EXPERIMENTER_ID, c.vendor)
3026 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3027 + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3028 + ofproto.NX_SET_FLOW_FORMAT_PACK_STR.replace('!', '')
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])
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])
3040 class TestNXTFlowMod(unittest.TestCase):
3041 """ Test case for ofproto_v1_0_parser.NXTFlowMod
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()
3059 port = {'buf': b'\x2a\xe0', 'val': 10976}
3060 actions = [OFPActionOutput(port['val'])]
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
3069 actions = self.actions
3071 c = NXTFlowMod(Datapath,
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'],
3091 def test_init(self):
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__())
3104 def test_init_append_actions(self):
3105 c = self._get_obj(True)
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)
3112 def test_parser(self):
3116 def test_serialize(self):
3120 eq_(ofproto.OFP_VERSION, c.version)
3121 eq_(ofproto.OFPT_VENDOR, c.msg_type)
3123 eq_(ofproto_common.NX_EXPERIMENTER_ID, c.vendor)
3126 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3127 + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3128 + ofproto.NX_FLOW_MOD_PACK_STR.replace('!', '')
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])
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])
3146 def test_serialize_append_actions(self):
3147 c = self._get_obj(True)
3150 eq_(ofproto.OFP_VERSION, c.version)
3151 eq_(ofproto.OFPT_VENDOR, c.msg_type)
3153 eq_(ofproto_common.NX_EXPERIMENTER_ID, c.vendor)
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('!', '')
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])
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])
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])
3185 class TestNXTRoleRequest(unittest.TestCase):
3186 """ Test case for ofproto_v1_0_parser.NXTRoleRequest
3191 role = {'buf': b'\x62\x81\x27\x61', 'val': 1652631393}
3193 class Datapath(object):
3194 ofproto = ofproto # copy to class attribute
3195 ofproto_parser = ofproto_v1_0_parser
3197 c = NXTRoleRequest(Datapath, role['val'])
3205 def test_init(self):
3206 eq_(self.role['val'], self.c.role)
3208 def test_parser(self):
3212 def test_serialize(self):
3215 eq_(ofproto.OFP_VERSION, self.c.version)
3216 eq_(ofproto.OFPT_VENDOR, self.c.msg_type)
3218 eq_(ofproto_common.NX_EXPERIMENTER_ID, self.c.vendor)
3221 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3222 + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3223 + ofproto.NX_ROLE_PACK_STR.replace('!', '')
3225 res = struct.unpack(fmt, six.binary_type(self.c.buf))
3227 eq_(ofproto.OFP_VERSION, res[0])
3228 eq_(ofproto.OFPT_VENDOR, res[1])
3229 eq_(len(self.c.buf), res[2])
3231 eq_(ofproto_common.NX_EXPERIMENTER_ID, res[4])
3232 eq_(ofproto.NXT_ROLE_REQUEST, res[5])
3233 eq_(self.role['val'], res[6])
3236 class TestNXTFlowModTableId(unittest.TestCase):
3237 """ Test case for ofproto_v1_0_parser.NXTFlowModTableId
3240 # NX_FLOW_MOD_TABLE_ID_PACK_STR
3241 # '!B7x'...set_, zfill
3242 set_ = {'buf': b'\x71', 'val': 113}
3245 class Datapath(object):
3246 ofproto = ofproto # copy to class attribute
3247 ofproto_parser = ofproto_v1_0_parser
3249 c = NXTFlowModTableId(Datapath, set_['val'])
3257 def test_init(self):
3258 eq_(self.set_['val'], self.c.set)
3260 def test_parser(self):
3264 def test_serialize(self):
3267 eq_(ofproto.OFP_VERSION, self.c.version)
3268 eq_(ofproto.OFPT_VENDOR, self.c.msg_type)
3270 eq_(ofproto_common.NX_EXPERIMENTER_ID, self.c.vendor)
3273 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
3274 + ofproto.NICIRA_HEADER_PACK_STR.replace('!', '') \
3275 + ofproto.NX_FLOW_MOD_TABLE_ID_PACK_STR.replace('!', '')
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])
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])
3287 class TestOFPSwitchFeatures(unittest.TestCase):
3288 """ Test case for ofproto_v1_0_parser.OFPSwitchFeatures
3291 class Datapath(object):
3292 ofproto = ofproto # copy to class attribute
3293 ofproto_parser = ofproto_v1_0_parser
3295 c = OFPSwitchFeatures(Datapath)
3303 def test_init(self):
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}
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}
3322 capabilities = {'buf': b'\x69\x4f\xe4\xc2', 'val': 1766843586}
3323 actions = {'buf': b'\x78\x06\xd9\x0c', 'val': 2013714700}
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}
3338 buf = version['buf'] \
3342 + datapath_id['buf'] \
3343 + n_buffers['buf'] \
3346 + capabilities['buf'] \
3349 + addrconv.mac.text_to_bin(hw_addr) \
3354 + advertised['buf'] \
3355 + supported['buf'] \
3358 res = OFPSwitchFeatures.parser(object,
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)
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)
3387 def test_serialize(self):
3392 class TestOFPPortStatus(unittest.TestCase):
3393 """ Test case for ofproto_v1_0_parser.OFPPortStatus
3396 class Datapath(object):
3397 ofproto = ofproto # copy to class attribute
3398 ofproto_parser = ofproto_v1_0_parser
3400 c = OFPPortStatus(Datapath)
3408 def test_init(self):
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}
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}
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}
3434 buf = version['buf'] \
3441 + addrconv.mac.text_to_bin(hw_addr) \
3446 + advertised['buf'] \
3447 + supported['buf'] \
3450 res = OFPPortStatus.parser(object,
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)
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)
3475 def test_serialize(self):
3480 class TestOFPPacketIn(unittest.TestCase):
3481 """ Test case for ofproto_v1_0_parser.OFPPacketIn
3484 class Datapath(object):
3485 ofproto = ofproto # copy to class attribute
3486 ofproto_parser = ofproto_v1_0_parser
3488 c = OFPPacketIn(Datapath)
3496 def test_init(self):
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}
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}
3515 data = b'PACKET IN'.ljust(20)
3517 data = b'PACKET IN'.ljust(16)
3519 buf = version['buf'] \
3523 + buffer_id['buf'] \
3524 + total_len['buf'] \
3530 res = OFPPacketIn.parser(object,
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)
3549 def test_parser(self):
3550 ok_(self._test_parser())
3552 def test_parser_padding(self):
3553 ok_(self._test_parser(True))
3555 def test_serialize(self):
3560 class TestOFPGetConfigReply(unittest.TestCase):
3561 """ Test case for ofproto_v1_0_parser.OFPGetConfigReply
3564 class Datapath(object):
3565 ofproto = ofproto # copy to class attribute
3566 ofproto_parser = ofproto_v1_0_parser
3568 c = OFPGetConfigReply(Datapath)
3576 def test_init(self):
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}
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}
3591 buf = version['buf'] \
3596 + miss_send_len['buf']
3598 res = OFPGetConfigReply.parser(object,
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)
3612 def test_serialize(self):
3617 class TestOFPBarrierReply(unittest.TestCase):
3618 """ Test case for ofproto_v1_0_parser.OFPBarrierReply
3621 class Datapath(object):
3622 ofproto = ofproto # copy to class attribute
3623 ofproto_parser = ofproto_v1_0_parser
3625 c = OFPBarrierReply(Datapath)
3633 def test_init(self):
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}
3643 buf = version['buf'] \
3648 res = OFPBarrierReply.parser(object,
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)
3660 def test_serialize(self):
3665 class TestOFPFlowRemoved(unittest.TestCase):
3666 """ Test case for ofproto_v1_0_parser.OFPFlowRemoved
3669 class Datapath(object):
3670 ofproto = ofproto # copy to class attribute
3671 ofproto_parser = ofproto_v1_0_parser
3673 c = OFPFlowRemoved(Datapath)
3681 def test_init(self):
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}
3691 buf = version['buf'] \
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}
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}
3716 buf += wildcards['buf'] \
3721 + dl_vlan_pcp['buf'] \
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}
3750 buf += cookie['buf'] \
3754 + duration_sec['buf'] \
3755 + duration_nsec['buf'] \
3756 + idle_timeout['buf'] \
3758 + packet_count['buf'] \
3761 res = OFPFlowRemoved.parser(object,
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)
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)
3797 def test_serialize(self):
3802 class TestOFPQueueGetConfigReply(unittest.TestCase):
3803 """ Test case for ofproto_v1_0_parser.OFPQueueGetConfigReply
3806 class Datapath(object):
3807 ofproto = ofproto # copy to class attribute
3808 ofproto_parser = ofproto_v1_0_parser
3810 c = OFPQueueGetConfigReply(Datapath)
3818 def test_init(self):
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}
3830 buf = version['buf'] \
3835 # OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR
3836 # '!H6x'...port, zfill
3837 port = {'buf': b'\xfe\x66', 'val': 65126}
3840 buf += port['buf'] \
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}
3850 buf += queue_id['buf'] \
3854 res = OFPQueueGetConfigReply.parser(object,
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)
3868 queue = res.queues[0]
3869 eq_(queue_id['val'], queue.queue_id)
3870 eq_(len_['val'], queue.len)
3872 def test_serialize(self):
3877 class TestOFPDescStatsReply(unittest.TestCase):
3878 """ Test case for ofproto_v1_0_parser.OFPDescStatsReply
3881 class Datapath(object):
3882 ofproto = ofproto # copy to class attribute
3883 ofproto_parser = ofproto_v1_0_parser
3885 c = OFPDescStatsReply(Datapath)
3893 def test_init(self):
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}
3904 buf = version['buf'] \
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}
3914 buf += type_['buf'] \
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)
3933 res = OFPDescStatsReply.parser(object,
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)
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)
3955 def test_serialize(self):
3960 class TestOFPFlowStatsReply(unittest.TestCase):
3961 """ Test case for ofproto_v1_0_parser.OFPFlowStatsReply
3964 class Datapath(object):
3965 ofproto = ofproto # copy to class attribute
3966 ofproto_parser = ofproto_v1_0_parser
3968 c = OFPFlowStatsReply(Datapath)
3976 def test_init(self):
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}
3987 buf = version['buf'] \
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}
3997 buf += type_['buf'] \
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}
4007 buf += length['buf'] \
4011 # OFP_MATCH_PACK_STR
4012 # '!IH6s6sHBxHBB2xIIHH'...
4013 match = b'\x97\x7c\xa6\x1e' \
4015 + b'\x70\x17\xdc\x80\x59\x9e' \
4016 + b'\x79\xc6\x56\x87\x92\x28' \
4024 + b'\xa4\x5d\x5c\x42' \
4025 + b'\xa2\x5c\x2e\x05' \
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}
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}
4048 buf += duration_sec['buf']
4049 buf += duration_nsec['buf']
4050 buf += priority['buf']
4051 buf += idle_timeout['buf']
4052 buf += hard_timeout['buf']
4054 buf += cookie['buf']
4055 buf += packet_count['buf']
4056 buf += byte_count['buf']
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}
4066 buf += type['buf'] \
4071 res = OFPFlowStatsReply.parser(object,
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)
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)
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)
4105 def test_serialize(self):
4110 class TestOFPAggregateStatsReply(unittest.TestCase):
4111 """ Test case for ofproto_v1_0_parser.OFPAggregateStatsReply
4114 class Datapath(object):
4115 ofproto = ofproto # copy to class attribute
4116 ofproto_parser = ofproto_v1_0_parser
4118 c = OFPAggregateStatsReply(Datapath)
4126 def test_init(self):
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}
4137 buf = version['buf'] \
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}
4147 buf += type_['buf'] \
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}
4160 buf += packet_count['buf'] \
4161 + byte_count['buf'] \
4162 + flow_count['buf'] \
4165 res = OFPAggregateStatsReply.parser(object,
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)
4181 eq_(packet_count['val'], body.packet_count)
4182 eq_(byte_count['val'], body.byte_count)
4183 eq_(flow_count['val'], body.flow_count)
4185 def test_serialize(self):
4190 class TestOFPTableStatsReply(unittest.TestCase):
4191 """ Test case for ofproto_v1_0_parser.OFPTableStatsReply
4194 class Datapath(object):
4195 ofproto = ofproto # copy to class attribute
4196 ofproto_parser = ofproto_v1_0_parser
4198 c = OFPTableStatsReply(Datapath)
4206 def test_init(self):
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}
4217 buf = version['buf'] \
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}
4227 buf += type_['buf'] \
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}
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}
4245 buf += table_id['buf'] \
4248 + wildcards['buf'] \
4249 + max_entries['buf'] \
4250 + active_count['buf'] \
4251 + lookup_count['buf'] \
4252 + matched_count['buf']
4254 res = OFPTableStatsReply.parser(object,
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)
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)
4278 def test_serialize(self):
4283 class TestOFPPortStatsReply(unittest.TestCase):
4284 """ Test case for ofproto_v1_0_parser.OFPPortStatsReply
4287 class Datapath(object):
4288 ofproto = ofproto # copy to class attribute
4289 ofproto_parser = ofproto_v1_0_parser
4291 c = OFPPortStatsReply(Datapath)
4299 def test_init(self):
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}
4310 buf = version['buf'] \
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}
4320 buf += type_['buf'] \
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}
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}
4356 buf += port_no['buf'] \
4358 + rx_packets['buf'] \
4359 + tx_packets['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'] \
4371 res = OFPPortStatsReply.parser(object,
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)
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)
4401 def test_serialize(self):
4406 class TestOFPQueueStatsReply(unittest.TestCase):
4407 """ Test case for ofproto_v1_0_parser.OFPQueueStatsReply
4410 class Datapath(object):
4411 ofproto = ofproto # copy to class attribute
4412 ofproto_parser = ofproto_v1_0_parser
4414 c = OFPQueueStatsReply(Datapath)
4422 def test_init(self):
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}
4433 buf = version['buf'] \
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}
4443 buf += type_['buf'] \
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}
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}
4459 buf += port_no['buf'] \
4463 + tx_packets['buf'] \
4466 res = OFPQueueStatsReply.parser(object,
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)
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)
4488 def test_serialize(self):
4493 class TestOFPVendorStatsReply(unittest.TestCase):
4494 """ Test case for ofproto_v1_0_parser.OFPVendorStatsReply
4497 class Datapath(object):
4498 ofproto = ofproto # copy to class attribute
4499 ofproto_parser = ofproto_v1_0_parser
4501 c = OFPVendorStatsReply(Datapath)
4509 def test_init(self):
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}
4520 buf = version['buf'] \
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}
4530 buf += type_['buf'] \
4533 # stats_type_cls = OFPVendorStats
4534 specific_data = b'specific_data'
4536 buf += specific_data
4538 res = OFPVendorStatsReply.parser(object,
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)
4554 eq_(specific_data, body)
4556 def test_serialize(self):
4561 class TestOFPFeaturesRequest(unittest.TestCase):
4562 """ Test case for ofproto_v1_0_parser.OFPFeaturesRequest
4565 class Datapath(object):
4566 ofproto = ofproto # copy to class attribute
4567 ofproto_parser = ofproto_v1_0_parser
4569 c = OFPFeaturesRequest(Datapath)
4577 def test_init(self):
4580 def test_parser(self):
4584 def test_serialize(self):
4587 eq_(ofproto.OFP_VERSION, self.c.version)
4588 eq_(ofproto.OFPT_FEATURES_REQUEST, self.c.msg_type)
4591 fmt = ofproto.OFP_HEADER_PACK_STR
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])
4600 class TestOFPGetConfigRequest(unittest.TestCase):
4601 """ Test case for ofproto_v1_0_parser.OFPGetConfigRequest
4604 class Datapath(object):
4605 ofproto = ofproto # copy to class attribute
4606 ofproto_parser = ofproto_v1_0_parser
4608 c = OFPGetConfigRequest(Datapath)
4616 def test_init(self):
4619 def test_parser(self):
4623 def test_serialize(self):
4626 eq_(ofproto.OFP_VERSION, self.c.version)
4627 eq_(ofproto.OFPT_GET_CONFIG_REQUEST, self.c.msg_type)
4630 fmt = ofproto.OFP_HEADER_PACK_STR
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])
4639 class TestOFPSetConfig(unittest.TestCase):
4640 """ Test case for ofproto_v1_0_parser.OFPSetConfig
4643 class Datapath(object):
4644 ofproto = ofproto # copy to class attribute
4645 ofproto_parser = ofproto_v1_0_parser
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}
4652 c = OFPSetConfig(Datapath,
4654 miss_send_len['val'])
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)
4666 def test_parser(self):
4670 def test_serialize(self):
4673 eq_(ofproto.OFP_VERSION, self.c.version)
4674 eq_(ofproto.OFPT_SET_CONFIG, self.c.msg_type)
4678 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
4679 + ofproto.OFP_SWITCH_CONFIG_PACK_STR.replace('!', '')
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])
4686 eq_(self.flags['val'], res[4])
4687 eq_(self.miss_send_len['val'], res[5])
4690 class TestOFPPacketOut(unittest.TestCase):
4691 """ Test case for ofproto_v1_0_parser.OFPPacketOut
4695 actions = [OFPActionOutput(port, max_len=0)]
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
4708 c = OFPPacketOut(Datapath,
4715 def test_init(self):
4716 buffer_id = 0xffffffff
4720 c = self._get_obj(buffer_id, in_port, data)
4722 eq_(buffer_id, c.buffer_id)
4723 eq_(in_port, c.in_port)
4726 def test_parser(self):
4730 def test_serialize(self):
4731 buffer_id = 0xffffffff
4735 c = self._get_obj(buffer_id, in_port, data)
4738 eq_(ofproto.OFP_VERSION, c.version)
4739 eq_(ofproto.OFPT_PACKET_OUT, c.msg_type)
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'
4748 res = struct.unpack(fmt, six.binary_type(c.buf))
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])
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])
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])
4770 @raises(AssertionError)
4771 def test_serialize_check_buffer_id(self):
4772 buffer_id = 0xffffff00
4776 c = self._get_obj(buffer_id, in_port, data)
4780 class TestOFPFlowMod(unittest.TestCase):
4781 """ Test case for ofproto_v1_0_parser.OFPFlowMod
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}
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}
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}
4817 match = OFPMatch(wildcards['val'],
4832 actions = [OFPActionOutput(port, max_len=1000)]
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
4845 c = OFPFlowMod(Datapath,
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'],
4859 def test_init(self):
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)
4871 def test_init_actions(self):
4872 c = self._get_obj(self.actions)
4873 action = c.actions[0]
4875 eq_(self.port, action.port)
4877 def test_parser(self):
4881 def test_serialize(self):
4882 c = self._get_obj(self.actions)
4885 eq_(ofproto.OFP_VERSION, c.version)
4886 eq_(ofproto.OFPT_FLOW_MOD, c.msg_type)
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('!', '')
4895 res = struct.unpack(fmt, six.binary_type(c.buf))
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])
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])
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])
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])
4935 class TestOFPBarrierRequest(unittest.TestCase):
4936 """ Test case for ofproto_v1_0_parser.OFPBarrierRequest
4939 class Datapath(object):
4940 ofproto = ofproto # copy to class attribute
4941 ofproto_parser = ofproto_v1_0_parser
4943 c = OFPBarrierRequest(Datapath)
4951 def test_init(self):
4954 def test_parser(self):
4958 def test_serialize(self):
4961 eq_(ofproto.OFP_VERSION, self.c.version)
4962 eq_(ofproto.OFPT_BARRIER_REQUEST, self.c.msg_type)
4965 fmt = ofproto.OFP_HEADER_PACK_STR
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])
4974 class TestOFPQueueGetConfigRequest(unittest.TestCase):
4975 """ Test case for ofproto_v1_0_parser.OFPQueueGetConfigRequest
4978 class Datapath(object):
4979 ofproto = ofproto # copy to class attribute
4980 ofproto_parser = ofproto_v1_0_parser
4982 # OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR
4983 # '!H2x'...port, zfill
4984 port = {'buf': b'\xa0\xe2', 'val': 41186}
4987 c = OFPQueueGetConfigRequest(Datapath,
4996 def test_init(self):
4997 eq_(self.port['val'], self.c.port)
4999 def test_parser(self):
5003 def test_serialize(self):
5006 eq_(ofproto.OFP_VERSION, self.c.version)
5007 eq_(ofproto.OFPT_QUEUE_GET_CONFIG_REQUEST, self.c.msg_type)
5010 a = ofproto.OFP_HEADER_PACK_STR.replace('!', '')
5011 b = ofproto.OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR.replace('!', '')
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])
5019 eq_(self.port['val'], res[4])
5022 class TestOFPDescStatsRequest(unittest.TestCase):
5023 """ Test case for ofproto_v1_0_parser.OFPDescStatsRequest
5026 class Datapath(object):
5027 ofproto = ofproto # copy to class attribute
5028 ofproto_parser = ofproto_v1_0_parser
5030 flags = {'buf': b'\x00\x00', 'val': 0}
5032 c = OFPDescStatsRequest(Datapath, flags['val'])
5040 def test_init(self):
5041 eq_(ofproto.OFPST_DESC, self.c.type)
5042 eq_(self.flags['val'], self.c.flags)
5044 def test_parser(self):
5048 def test_serialize(self):
5051 eq_(ofproto.OFP_VERSION, self.c.version)
5052 eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5056 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5057 + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '')
5059 res = struct.unpack(fmt, six.binary_type(self.c.buf))
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])
5067 # OFP_STATS_MSG_PACK_STR
5068 eq_(ofproto.OFPST_DESC, res[4])
5069 eq_(self.flags['val'], res[5])
5072 class TestOFPFlowStatsRequest(unittest.TestCase):
5073 """ Test case for ofproto_v1_0_parser.OFPFlowStatsRequest
5076 class Datapath(object):
5077 ofproto = ofproto # copy to class attribute
5078 ofproto_parser = ofproto_v1_0_parser
5080 flags = {'buf': b'\x00\x00', 'val': 0}
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}
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}
5102 match = OFPMatch(wildcards['val'],
5116 # OFP_FLOW_STATS_REQUEST_ID_PORT_STR
5117 # '!BxH'...table_id, zfill, out_port
5118 table_id = {'buf': b'\xd1', 'val': 209}
5120 out_port = {'buf': b'\xe4\x9a', 'val': 58522}
5122 c = OFPFlowStatsRequest(Datapath,
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)
5141 match = self.c.match
5142 eq_(self.match.__hash__(), match.__hash__())
5144 def test_parser(self):
5148 def test_serialize(self):
5151 eq_(ofproto.OFP_VERSION, self.c.version)
5152 eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
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('!', '')
5161 res = struct.unpack(fmt, six.binary_type(self.c.buf))
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])
5169 # OFP_STATS_MSG_PACK_STR
5170 eq_(ofproto.OFPST_FLOW, res[4])
5171 eq_(self.flags['val'], res[5])
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])
5188 # OFP_FLOW_STATS_REQUEST_ID_PORT_STR
5189 eq_(self.table_id['val'], res[19])
5190 eq_(self.out_port['val'], res[20])
5193 class TestOFPAggregateStatsRequest(unittest.TestCase):
5194 """ Test case for ofproto_v1_0_parser.OFPAggregateStatsRequest
5197 class Datapath(object):
5198 ofproto = ofproto # copy to class attribute
5199 ofproto_parser = ofproto_v1_0_parser
5201 flags = {'buf': b'\x00\x00', 'val': 0}
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}
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}
5223 match = OFPMatch(wildcards['val'],
5237 # OFP_FLOW_STATS_REQUEST_ID_PORT_STR
5238 # '!BxH'...table_id, zfill, out_port
5239 table_id = {'buf': b'\xd1', 'val': 209}
5241 out_port = {'buf': b'\xb5\xe8', 'val': 46568}
5243 c = OFPAggregateStatsRequest(Datapath,
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)
5262 match = self.c.match
5263 eq_(self.match.__hash__(), match.__hash__())
5265 def test_parser(self):
5269 def test_serialize(self):
5272 eq_(ofproto.OFP_VERSION, self.c.version)
5273 eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
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('!', '')
5282 res = struct.unpack(fmt, six.binary_type(self.c.buf))
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])
5290 # OFP_STATS_MSG_PACK_STR
5291 eq_(ofproto.OFPST_AGGREGATE, res[4])
5292 eq_(self.flags['val'], res[5])
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])
5309 # OFP_FLOW_STATS_REQUEST_ID_PORT_STR
5310 eq_(self.table_id['val'], res[19])
5311 eq_(self.out_port['val'], res[20])
5314 class TestOFPTableStatsRequest(unittest.TestCase):
5315 """ Test case for ofproto_v1_0_parser.OFPTableStatsRequest
5318 class Datapath(object):
5319 ofproto = ofproto # copy to class attribute
5320 ofproto_parser = ofproto_v1_0_parser
5322 flags = {'buf': b'\x00\x00', 'val': 0}
5324 c = OFPTableStatsRequest(Datapath, flags['val'])
5332 def test_init(self):
5333 eq_(ofproto.OFPST_TABLE, self.c.type)
5334 eq_(self.flags['val'], self.c.flags)
5336 def test_parser(self):
5340 def test_serialize(self):
5343 eq_(ofproto.OFP_VERSION, self.c.version)
5344 eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5348 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5349 + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '')
5351 res = struct.unpack(fmt, six.binary_type(self.c.buf))
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])
5359 # OFP_STATS_MSG_PACK_STR
5360 eq_(ofproto.OFPST_TABLE, res[4])
5361 eq_(self.flags['val'], res[5])
5364 class TestOFPPortStatsRequest(unittest.TestCase):
5365 """ Test case for ofproto_v1_0_parser.OFPPortStatsRequest
5368 class Datapath(object):
5369 ofproto = ofproto # copy to class attribute
5370 ofproto_parser = ofproto_v1_0_parser
5372 flags = {'buf': b'\x00\x00', 'val': 0}
5374 # OFP_PORT_STATS_REQUEST_PACK_STR
5375 # '!H6x'...port_no, zfill
5376 port_no = {'buf': b'\x6d\x27', 'val': 27943}
5378 c = OFPPortStatsRequest(Datapath,
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)
5393 def test_parser(self):
5397 def test_serialize(self):
5400 eq_(ofproto.OFP_VERSION, self.c.version)
5401 eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5405 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5406 + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
5407 + ofproto.OFP_PORT_STATS_REQUEST_PACK_STR.replace('!', '')
5409 res = struct.unpack(fmt, six.binary_type(self.c.buf))
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])
5417 # OFP_STATS_MSG_PACK_STR
5418 eq_(ofproto.OFPST_PORT, res[4])
5419 eq_(self.flags['val'], res[5])
5421 # OFP_PORT_STATS_REQUEST_PACK_STR
5422 eq_(self.port_no['val'], res[6])
5425 class TestOFPQueueStatsRequest(unittest.TestCase):
5426 """ Test case for ofproto_v1_0_parser.OFPQueueStatsRequest
5429 class Datapath(object):
5430 ofproto = ofproto # copy to class attribute
5431 ofproto_parser = ofproto_v1_0_parser
5433 flags = {'buf': b'\x00\x00', 'val': 0}
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}
5440 c = OFPQueueStatsRequest(Datapath,
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)
5457 def test_parser(self):
5461 def test_serialize(self):
5464 eq_(ofproto.OFP_VERSION, self.c.version)
5465 eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
5469 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5470 + ofproto.OFP_STATS_MSG_PACK_STR.replace('!', '') \
5471 + ofproto.OFP_QUEUE_STATS_REQUEST_PACK_STR.replace('!', '')
5473 res = struct.unpack(fmt, six.binary_type(self.c.buf))
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])
5481 # OFP_STATS_MSG_PACK_STR
5482 eq_(ofproto.OFPST_QUEUE, res[4])
5483 eq_(self.flags['val'], res[5])
5485 # OFP_QUEUE_STATS_REQUEST_PACK_STR
5486 eq_(self.port_no['val'], res[6])
5487 eq_(self.queue_id['val'], res[7])
5490 class TestOFPVendorStatsRequest(unittest.TestCase):
5491 """ Test case for ofproto_v1_0_parser.OFPVendorStatsRequest
5494 class Datapath(object):
5495 ofproto = ofproto # copy to class attribute
5496 ofproto_parser = ofproto_v1_0_parser
5498 flags = {'buf': b'\x00\x00', 'val': 0}
5500 # OFP_VENDOR_STATS_MSG_PACK_STR
5502 vendor = {'buf': b'\xff\xff\xff\xff', 'val': ofproto.OFPAT_VENDOR}
5504 specific_data = b'specific_data'
5506 c = OFPVendorStatsRequest(Datapath,
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)
5523 def test_parser(self):
5527 def test_serialize(self):
5530 eq_(ofproto.OFP_VERSION, self.c.version)
5531 eq_(ofproto.OFPT_STATS_REQUEST, self.c.msg_type)
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'
5540 res = struct.unpack(fmt, six.binary_type(self.c.buf))
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])
5548 # OFP_STATS_MSG_PACK_STR
5549 eq_(ofproto.OFPST_VENDOR, res[4])
5550 eq_(self.flags['val'], res[5])
5552 # OFP_VENDOR_STATS_MSG_PACK_STR
5553 eq_(self.vendor['val'], res[6])
5556 eq_(self.specific_data, res[7])