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
23 from nose.tools import *
24 from ryu.ofproto.ofproto_v1_2_parser import *
25 from ryu.ofproto import ofproto_v1_2_parser
26 from ryu.ofproto import ofproto_v1_2
27 from ryu.ofproto import ofproto_protocol
28 from ryu.ofproto import ether
29 from ryu.ofproto.ofproto_parser import MsgBase
31 from ryu.lib import addrconv
32 from ryu.lib import pack_utils
34 LOG = logging.getLogger('test_ofproto_v12')
37 _Datapath = ofproto_protocol.ProtocolDesc(version=ofproto_v1_2.OFP_VERSION)
40 class TestRegisterParser(unittest.TestCase):
41 """ Test case for ofproto_v1_2_parser._register_parser
44 class _OFPDummy(MsgBase):
45 def __init__(self, datapath):
51 def test_cls_msg_type(self):
53 cls = self._OFPDummy(_Datapath)
54 cls.cls_msg_type = msg_type
56 res = ofproto_v1_2_parser._register_parser(cls)
57 res_parser = ofproto_v1_2_parser._MSG_PARSERS[msg_type]
58 del ofproto_v1_2_parser._MSG_PARSERS[msg_type]
60 eq_(res.cls_msg_type, msg_type)
62 eq_(res_parser(), 'dummy')
64 @raises(AssertionError)
65 def test_cls_msg_type_none(self):
66 cls = OFPHello(_Datapath)
67 cls.cls_msg_type = None
68 ofproto_v1_2_parser._register_parser(cls)
70 @raises(AssertionError)
71 def test_cls_msg_type_already_registed(self):
72 cls = OFPHello(_Datapath)
73 ofproto_v1_2_parser._register_parser(cls)
76 class TestMsgParser(unittest.TestCase):
77 """ Test case for ofproto_v1_2_parser.msg_parser
80 def _test_msg_parser(self, xid, msg_len):
82 # '!BBHI'...version, msg_type, msg_len, xid
83 version = ofproto.OFP_VERSION
84 msg_type = ofproto.OFPT_HELLO
86 fmt = ofproto.OFP_HEADER_PACK_STR
87 buf = pack(fmt, version, msg_type, msg_len, xid)
89 c = msg_parser(_Datapath, version, msg_type, msg_len, xid, buf)
91 eq_(version, c.version)
92 eq_(msg_type, c.msg_type)
93 eq_(msg_len, c.msg_len)
97 fmt = ofproto.OFP_HEADER_PACK_STR
98 res = struct.unpack(fmt, c.buf)
101 eq_(msg_type, res[1])
105 def test_parser_mid(self):
108 self._test_msg_parser(xid, msg_len)
110 def test_parser_max(self):
113 self._test_msg_parser(xid, msg_len)
115 def test_parser_min(self):
118 self._test_msg_parser(xid, msg_len)
121 class TestOFPHello(unittest.TestCase):
122 """ Test case for ofproto_v1_2_parser.OFPHello
125 def _test_parser(self, xid):
126 version = ofproto.OFP_VERSION
127 msg_type = ofproto.OFPT_HELLO
128 msg_len = ofproto.OFP_HEADER_SIZE
130 fmt = ofproto.OFP_HEADER_PACK_STR
131 buf = pack(fmt, version, msg_type, msg_len, xid)
133 res = OFPHello.parser(object, version, msg_type, msg_len, xid,
136 eq_(version, res.version)
137 eq_(msg_type, res.msg_type)
138 eq_(msg_len, res.msg_len)
140 eq_(six.binary_type(buf), six.binary_type(res.buf))
142 def test_parser_xid_min(self):
144 self._test_parser(xid)
146 def test_parser_xid_mid(self):
148 self._test_parser(xid)
150 def test_parser_xid_max(self):
152 self._test_parser(xid)
154 def test_serialize(self):
155 c = OFPHello(_Datapath)
157 eq_(ofproto.OFP_VERSION, c.version)
158 eq_(ofproto.OFPT_HELLO, c.msg_type)
162 class TestOFPErrorMsg(unittest.TestCase):
163 """ Test case for ofproto_v1_2_parser.OFPErrorMsg
166 # OFP_HEADER_PACK_STR
167 # '!BBHI'...version, msg_type, msg_len, xid
168 version = ofproto.OFP_VERSION
169 msg_type = ofproto.OFPT_ERROR
170 msg_len = ofproto.OFP_ERROR_MSG_SIZE
173 fmt = ofproto.OFP_HEADER_PACK_STR
174 buf = pack(fmt, version, msg_type, msg_len, xid)
177 c = OFPErrorMsg(_Datapath)
182 def _test_parser(self, type_, code, data=None):
184 # OFP_ERROR_MSG_PACK_STR = '!HH'
185 fmt = ofproto.OFP_ERROR_MSG_PACK_STR
186 buf = self.buf + pack(fmt, type_, code)
191 res = OFPErrorMsg.parser(object, self.version, self.msg_type,
192 self.msg_len, self.xid, buf)
194 eq_(res.version, self.version)
195 eq_(res.msg_type, self.msg_type)
196 eq_(res.msg_len, self.msg_len)
197 eq_(res.xid, self.xid)
204 def test_parser_mid(self):
207 data = b'Error Message.'
208 self._test_parser(type_, code, data)
210 def test_parser_max(self):
213 data = b'Error Message.'.ljust(65523)
214 self._test_parser(type_, code, data)
216 def test_parser_min(self):
220 self._test_parser(type_, code, data)
222 def test_parser_p0_1(self):
223 type_ = ofproto.OFPET_HELLO_FAILED
224 code = ofproto.OFPHFC_EPERM
225 data = b'Error Message.'
226 self._test_parser(type_, code, data)
228 def test_parser_p1_0(self):
229 type_ = ofproto.OFPET_BAD_REQUEST
230 code = ofproto.OFPBRC_BAD_VERSION
231 data = b'Error Message.'
232 self._test_parser(type_, code, data)
234 def test_parser_p1_1(self):
235 type_ = ofproto.OFPET_BAD_REQUEST
236 code = ofproto.OFPBRC_BAD_TYPE
237 data = b'Error Message.'
238 self._test_parser(type_, code, data)
240 def test_parser_p1_2(self):
241 type_ = ofproto.OFPET_BAD_REQUEST
242 code = ofproto.OFPBRC_BAD_STAT
243 data = b'Error Message.'
244 self._test_parser(type_, code, data)
246 def test_parser_p1_3(self):
247 type_ = ofproto.OFPET_BAD_REQUEST
248 code = ofproto.OFPBRC_BAD_EXPERIMENTER
249 data = b'Error Message.'
250 self._test_parser(type_, code, data)
252 def test_parser_p1_4(self):
253 type_ = ofproto.OFPET_BAD_REQUEST
254 code = ofproto.OFPBRC_BAD_EXP_TYPE
255 data = b'Error Message.'
256 self._test_parser(type_, code, data)
258 def test_parser_p1_5(self):
259 type_ = ofproto.OFPET_BAD_REQUEST
260 code = ofproto.OFPBRC_EPERM
261 data = b'Error Message.'
262 self._test_parser(type_, code, data)
264 def test_parser_p1_6(self):
265 type_ = ofproto.OFPET_BAD_REQUEST
266 code = ofproto.OFPBRC_BAD_LEN
267 data = b'Error Message.'
268 self._test_parser(type_, code, data)
270 def test_parser_p1_7(self):
271 type_ = ofproto.OFPET_BAD_REQUEST
272 code = ofproto.OFPBRC_BUFFER_EMPTY
273 data = b'Error Message.'
274 self._test_parser(type_, code, data)
276 def test_parser_p1_8(self):
277 type_ = ofproto.OFPET_BAD_REQUEST
278 code = ofproto.OFPBRC_BUFFER_UNKNOWN
279 data = b'Error Message.'
280 self._test_parser(type_, code, data)
282 def test_parser_p1_9(self):
283 type_ = ofproto.OFPET_BAD_REQUEST
284 code = ofproto.OFPBRC_BAD_TABLE_ID
285 data = b'Error Message.'
286 self._test_parser(type_, code, data)
288 def test_parser_p1_10(self):
289 type_ = ofproto.OFPET_BAD_REQUEST
290 code = ofproto.OFPBRC_IS_SLAVE
291 data = b'Error Message.'
292 self._test_parser(type_, code, data)
294 def test_parser_p1_11(self):
295 type_ = ofproto.OFPET_BAD_REQUEST
296 code = ofproto.OFPBRC_BAD_PORT
297 data = b'Error Message.'
298 self._test_parser(type_, code, data)
300 def test_parser_p1_12(self):
301 type_ = ofproto.OFPET_BAD_REQUEST
302 code = ofproto.OFPBRC_BAD_PACKET
303 data = b'Error Message.'
304 self._test_parser(type_, code, data)
306 def test_parser_p2_0(self):
307 type_ = ofproto.OFPET_BAD_ACTION
308 code = ofproto.OFPBAC_BAD_TYPE
309 data = b'Error Message.'
310 self._test_parser(type_, code, data)
312 def test_parser_p2_1(self):
313 type_ = ofproto.OFPET_BAD_ACTION
314 code = ofproto.OFPBAC_BAD_LEN
315 data = b'Error Message.'
316 self._test_parser(type_, code, data)
318 def test_parser_p2_2(self):
319 type_ = ofproto.OFPET_BAD_ACTION
320 code = ofproto.OFPBAC_BAD_EXPERIMENTER
321 data = b'Error Message.'
322 self._test_parser(type_, code, data)
324 def test_parser_p2_3(self):
325 type_ = ofproto.OFPET_BAD_ACTION
326 code = ofproto.OFPBAC_BAD_EXP_TYPE
327 data = b'Error Message.'
328 self._test_parser(type_, code, data)
330 def test_parser_p2_4(self):
331 type_ = ofproto.OFPET_BAD_ACTION
332 code = ofproto.OFPBAC_BAD_OUT_PORT
333 data = b'Error Message.'
334 self._test_parser(type_, code, data)
336 def test_parser_p2_5(self):
337 type_ = ofproto.OFPET_BAD_ACTION
338 code = ofproto.OFPBAC_BAD_ARGUMENT
339 data = b'Error Message.'
340 self._test_parser(type_, code, data)
342 def test_parser_p2_6(self):
343 type_ = ofproto.OFPET_BAD_ACTION
344 code = ofproto.OFPBAC_EPERM
345 data = b'Error Message.'
346 self._test_parser(type_, code, data)
348 def test_parser_p2_7(self):
349 type_ = ofproto.OFPET_BAD_ACTION
350 code = ofproto.OFPBAC_TOO_MANY
351 data = b'Error Message.'
352 self._test_parser(type_, code, data)
354 def test_parser_p2_8(self):
355 type_ = ofproto.OFPET_BAD_ACTION
356 code = ofproto.OFPBAC_BAD_QUEUE
357 data = b'Error Message.'
358 self._test_parser(type_, code, data)
360 def test_parser_p2_9(self):
361 type_ = ofproto.OFPET_BAD_ACTION
362 code = ofproto.OFPBAC_BAD_OUT_GROUP
363 data = b'Error Message.'
364 self._test_parser(type_, code, data)
366 def test_parser_p2_10(self):
367 type_ = ofproto.OFPET_BAD_ACTION
368 code = ofproto.OFPBAC_MATCH_INCONSISTENT
369 data = b'Error Message.'
370 self._test_parser(type_, code, data)
372 def test_parser_p2_11(self):
373 type_ = ofproto.OFPET_BAD_ACTION
374 code = ofproto.OFPBAC_UNSUPPORTED_ORDER
375 data = b'Error Message.'
376 self._test_parser(type_, code, data)
378 def test_parser_p2_12(self):
379 type_ = ofproto.OFPET_BAD_ACTION
380 code = ofproto.OFPBAC_BAD_TAG
381 data = b'Error Message.'
382 self._test_parser(type_, code, data)
384 def test_parser_p2_13(self):
385 type_ = ofproto.OFPET_BAD_ACTION
386 code = ofproto.OFPBAC_BAD_SET_TYPE
387 data = b'Error Message.'
388 self._test_parser(type_, code, data)
390 def test_parser_p2_14(self):
391 type_ = ofproto.OFPET_BAD_ACTION
392 code = ofproto.OFPBAC_BAD_SET_LEN
393 data = b'Error Message.'
394 self._test_parser(type_, code, data)
396 def test_parser_p2_15(self):
397 type_ = ofproto.OFPET_BAD_ACTION
398 code = ofproto.OFPBAC_BAD_SET_ARGUMENT
399 data = b'Error Message.'
400 self._test_parser(type_, code, data)
402 def test_parser_p3_0(self):
403 type_ = ofproto.OFPET_BAD_INSTRUCTION
404 code = ofproto.OFPBIC_UNKNOWN_INST
405 data = b'Error Message.'
406 self._test_parser(type_, code, data)
408 def test_parser_p3_1(self):
409 type_ = ofproto.OFPET_BAD_INSTRUCTION
410 code = ofproto.OFPBIC_UNSUP_INST
411 data = b'Error Message.'
412 self._test_parser(type_, code, data)
414 def test_parser_p3_2(self):
415 type_ = ofproto.OFPET_BAD_INSTRUCTION
416 code = ofproto.OFPBIC_BAD_TABLE_ID
417 data = b'Error Message.'
418 self._test_parser(type_, code, data)
420 def test_parser_p3_3(self):
421 type_ = ofproto.OFPET_BAD_INSTRUCTION
422 code = ofproto.OFPBIC_UNSUP_METADATA
423 data = b'Error Message.'
424 self._test_parser(type_, code, data)
426 def test_parser_p3_4(self):
427 type_ = ofproto.OFPET_BAD_INSTRUCTION
428 code = ofproto.OFPBIC_UNSUP_METADATA_MASK
429 data = b'Error Message.'
430 self._test_parser(type_, code, data)
432 def test_parser_p3_5(self):
433 type_ = ofproto.OFPET_BAD_INSTRUCTION
434 code = ofproto.OFPBIC_BAD_EXPERIMENTER
435 data = b'Error Message.'
436 self._test_parser(type_, code, data)
438 def test_parser_p3_6(self):
439 type_ = ofproto.OFPET_BAD_INSTRUCTION
440 code = ofproto.OFPBIC_BAD_EXP_TYPE
441 data = b'Error Message.'
442 self._test_parser(type_, code, data)
444 def test_parser_p3_7(self):
445 type_ = ofproto.OFPET_BAD_INSTRUCTION
446 code = ofproto.OFPBIC_BAD_LEN
447 data = b'Error Message.'
448 self._test_parser(type_, code, data)
450 def test_parser_p3_8(self):
451 type_ = ofproto.OFPET_BAD_INSTRUCTION
452 code = ofproto.OFPBIC_EPERM
453 data = b'Error Message.'
454 self._test_parser(type_, code, data)
456 def test_parser_p4_0(self):
457 type_ = ofproto.OFPET_BAD_MATCH
458 code = ofproto.OFPBMC_BAD_TYPE
459 data = b'Error Message.'
460 self._test_parser(type_, code, data)
462 def test_parser_p4_1(self):
463 type_ = ofproto.OFPET_BAD_MATCH
464 code = ofproto.OFPBMC_BAD_LEN
465 data = b'Error Message.'
466 self._test_parser(type_, code, data)
468 def test_parser_p4_2(self):
469 type_ = ofproto.OFPET_BAD_MATCH
470 code = ofproto.OFPBMC_BAD_TAG
471 data = b'Error Message.'
472 self._test_parser(type_, code, data)
474 def test_parser_p4_3(self):
475 type_ = ofproto.OFPET_BAD_MATCH
476 code = ofproto.OFPBMC_BAD_DL_ADDR_MASK
477 data = b'Error Message.'
478 self._test_parser(type_, code, data)
480 def test_parser_p4_4(self):
481 type_ = ofproto.OFPET_BAD_MATCH
482 code = ofproto.OFPBMC_BAD_NW_ADDR_MASK
483 data = b'Error Message.'
484 self._test_parser(type_, code, data)
486 def test_parser_p4_5(self):
487 type_ = ofproto.OFPET_BAD_MATCH
488 code = ofproto.OFPBMC_BAD_WILDCARDS
489 data = b'Error Message.'
490 self._test_parser(type_, code, data)
492 def test_parser_p4_6(self):
493 type_ = ofproto.OFPET_BAD_MATCH
494 code = ofproto.OFPBMC_BAD_FIELD
495 data = b'Error Message.'
496 self._test_parser(type_, code, data)
498 def test_parser_p4_7(self):
499 type_ = ofproto.OFPET_BAD_MATCH
500 code = ofproto.OFPBMC_BAD_VALUE
501 data = b'Error Message.'
502 self._test_parser(type_, code, data)
504 def test_parser_p4_8(self):
505 type_ = ofproto.OFPET_BAD_MATCH
506 code = ofproto.OFPBMC_BAD_MASK
507 data = b'Error Message.'
508 self._test_parser(type_, code, data)
510 def test_parser_p4_9(self):
511 type_ = ofproto.OFPET_BAD_MATCH
512 code = ofproto.OFPBMC_BAD_PREREQ
513 data = b'Error Message.'
514 self._test_parser(type_, code, data)
516 def test_parser_p4_10(self):
517 type_ = ofproto.OFPET_BAD_MATCH
518 code = ofproto.OFPBMC_DUP_FIELD
519 data = b'Error Message.'
520 self._test_parser(type_, code, data)
522 def test_parser_p4_11(self):
523 type_ = ofproto.OFPET_BAD_MATCH
524 code = ofproto.OFPBMC_EPERM
525 data = b'Error Message.'
526 self._test_parser(type_, code, data)
528 def test_parser_p5_0(self):
529 type_ = ofproto.OFPET_FLOW_MOD_FAILED
530 code = ofproto.OFPFMFC_UNKNOWN
531 data = b'Error Message.'
532 self._test_parser(type_, code, data)
534 def test_parser_p5_1(self):
535 type_ = ofproto.OFPET_FLOW_MOD_FAILED
536 code = ofproto.OFPFMFC_TABLE_FULL
537 data = b'Error Message.'
538 self._test_parser(type_, code, data)
540 def test_parser_p5_2(self):
541 type_ = ofproto.OFPET_FLOW_MOD_FAILED
542 code = ofproto.OFPFMFC_BAD_TABLE_ID
543 data = b'Error Message.'
544 self._test_parser(type_, code, data)
546 def test_parser_p5_3(self):
547 type_ = ofproto.OFPET_FLOW_MOD_FAILED
548 code = ofproto.OFPFMFC_OVERLAP
549 data = b'Error Message.'
550 self._test_parser(type_, code, data)
552 def test_parser_p5_4(self):
553 type_ = ofproto.OFPET_FLOW_MOD_FAILED
554 code = ofproto.OFPFMFC_EPERM
555 data = b'Error Message.'
556 self._test_parser(type_, code, data)
558 def test_parser_p5_5(self):
559 type_ = ofproto.OFPET_FLOW_MOD_FAILED
560 code = ofproto.OFPFMFC_BAD_TIMEOUT
561 data = b'Error Message.'
562 self._test_parser(type_, code, data)
564 def test_parser_p5_6(self):
565 type_ = ofproto.OFPET_FLOW_MOD_FAILED
566 code = ofproto.OFPFMFC_BAD_COMMAND
567 data = b'Error Message.'
568 self._test_parser(type_, code, data)
570 def test_parser_p5_7(self):
571 type_ = ofproto.OFPET_FLOW_MOD_FAILED
572 code = ofproto.OFPFMFC_BAD_FLAGS
573 data = b'Error Message.'
574 self._test_parser(type_, code, data)
576 def test_parser_p6_0(self):
577 type_ = ofproto.OFPET_GROUP_MOD_FAILED
578 code = ofproto.OFPGMFC_GROUP_EXISTS
579 data = b'Error Message.'
580 self._test_parser(type_, code, data)
582 def test_parser_p6_1(self):
583 type_ = ofproto.OFPET_GROUP_MOD_FAILED
584 code = ofproto.OFPGMFC_INVALID_GROUP
585 data = b'Error Message.'
586 self._test_parser(type_, code, data)
588 def test_parser_p6_2(self):
589 type_ = ofproto.OFPET_GROUP_MOD_FAILED
590 code = ofproto.OFPGMFC_WEIGHT_UNSUPPORTED
591 data = b'Error Message.'
592 self._test_parser(type_, code, data)
594 def test_parser_p6_3(self):
595 type_ = ofproto.OFPET_GROUP_MOD_FAILED
596 code = ofproto.OFPGMFC_OUT_OF_GROUPS
597 data = b'Error Message.'
598 self._test_parser(type_, code, data)
600 def test_parser_p6_4(self):
601 type_ = ofproto.OFPET_GROUP_MOD_FAILED
602 code = ofproto.OFPGMFC_OUT_OF_BUCKETS
603 data = b'Error Message.'
604 self._test_parser(type_, code, data)
606 def test_parser_p6_5(self):
607 type_ = ofproto.OFPET_GROUP_MOD_FAILED
608 code = ofproto.OFPGMFC_CHAINING_UNSUPPORTED
609 data = b'Error Message.'
610 self._test_parser(type_, code, data)
612 def test_parser_p6_6(self):
613 type_ = ofproto.OFPET_GROUP_MOD_FAILED
614 code = ofproto.OFPGMFC_WATCH_UNSUPPORTED
615 data = b'Error Message.'
616 self._test_parser(type_, code, data)
618 def test_parser_p6_7(self):
619 type_ = ofproto.OFPET_GROUP_MOD_FAILED
620 code = ofproto.OFPGMFC_LOOP
621 data = b'Error Message.'
622 self._test_parser(type_, code, data)
624 def test_parser_p6_8(self):
625 type_ = ofproto.OFPET_GROUP_MOD_FAILED
626 code = ofproto.OFPGMFC_UNKNOWN_GROUP
627 data = b'Error Message.'
628 self._test_parser(type_, code, data)
630 def test_parser_p6_9(self):
631 type_ = ofproto.OFPET_GROUP_MOD_FAILED
632 code = ofproto.OFPGMFC_CHAINED_GROUP
633 data = b'Error Message.'
634 self._test_parser(type_, code, data)
636 def test_parser_p6_10(self):
637 type_ = ofproto.OFPET_GROUP_MOD_FAILED
638 code = ofproto.OFPGMFC_BAD_TYPE
639 data = b'Error Message.'
640 self._test_parser(type_, code, data)
642 def test_parser_p6_11(self):
643 type_ = ofproto.OFPET_GROUP_MOD_FAILED
644 code = ofproto.OFPGMFC_BAD_COMMAND
645 data = b'Error Message.'
646 self._test_parser(type_, code, data)
648 def test_parser_p6_12(self):
649 type_ = ofproto.OFPET_GROUP_MOD_FAILED
650 code = ofproto.OFPGMFC_BAD_BUCKET
651 data = b'Error Message.'
652 self._test_parser(type_, code, data)
654 def test_parser_p6_13(self):
655 type_ = ofproto.OFPET_GROUP_MOD_FAILED
656 code = ofproto.OFPGMFC_BAD_WATCH
657 data = b'Error Message.'
658 self._test_parser(type_, code, data)
660 def test_parser_p6_14(self):
661 type_ = ofproto.OFPET_GROUP_MOD_FAILED
662 code = ofproto.OFPGMFC_EPERM
663 data = b'Error Message.'
664 self._test_parser(type_, code, data)
666 def test_parser_p7_0(self):
667 type_ = ofproto.OFPET_PORT_MOD_FAILED
668 code = ofproto.OFPPMFC_BAD_PORT
669 data = b'Error Message.'
670 self._test_parser(type_, code, data)
672 def test_parser_p7_1(self):
673 type_ = ofproto.OFPET_PORT_MOD_FAILED
674 code = ofproto.OFPPMFC_BAD_HW_ADDR
675 data = b'Error Message.'
676 self._test_parser(type_, code, data)
678 def test_parser_p7_2(self):
679 type_ = ofproto.OFPET_PORT_MOD_FAILED
680 code = ofproto.OFPPMFC_BAD_CONFIG
681 data = b'Error Message.'
682 self._test_parser(type_, code, data)
684 def test_parser_p7_3(self):
685 type_ = ofproto.OFPET_PORT_MOD_FAILED
686 code = ofproto.OFPPMFC_BAD_ADVERTISE
687 data = b'Error Message.'
688 self._test_parser(type_, code, data)
690 def test_parser_p7_4(self):
691 type_ = ofproto.OFPET_PORT_MOD_FAILED
692 code = ofproto.OFPPMFC_EPERM
693 data = b'Error Message.'
694 self._test_parser(type_, code, data)
696 def test_parser_p8_0(self):
697 type_ = ofproto.OFPET_TABLE_MOD_FAILED
698 code = ofproto.OFPTMFC_BAD_TABLE
699 data = b'Error Message.'
700 self._test_parser(type_, code, data)
702 def test_parser_p8_1(self):
703 type_ = ofproto.OFPET_TABLE_MOD_FAILED
704 code = ofproto.OFPTMFC_BAD_CONFIG
705 data = b'Error Message.'
706 self._test_parser(type_, code, data)
708 def test_parser_p8_2(self):
709 type_ = ofproto.OFPET_TABLE_MOD_FAILED
710 code = ofproto.OFPTMFC_EPERM
711 data = b'Error Message.'
712 self._test_parser(type_, code, data)
714 def test_parser_p9_0(self):
715 type_ = ofproto.OFPET_QUEUE_OP_FAILED
716 code = ofproto.OFPQOFC_BAD_PORT
717 data = b'Error Message.'
718 self._test_parser(type_, code, data)
720 def test_parser_p9_1(self):
721 type_ = ofproto.OFPET_QUEUE_OP_FAILED
722 code = ofproto.OFPQOFC_BAD_QUEUE
723 data = b'Error Message.'
724 self._test_parser(type_, code, data)
726 def test_parser_p9_2(self):
727 type_ = ofproto.OFPET_QUEUE_OP_FAILED
728 code = ofproto.OFPQOFC_EPERM
729 data = b'Error Message.'
730 self._test_parser(type_, code, data)
732 def test_parser_p10_0(self):
733 type_ = ofproto.OFPET_SWITCH_CONFIG_FAILED
734 code = ofproto.OFPSCFC_BAD_FLAGS
735 data = b'Error Message.'
736 self._test_parser(type_, code, data)
738 def test_parser_p10_1(self):
739 type_ = ofproto.OFPET_SWITCH_CONFIG_FAILED
740 code = ofproto.OFPSCFC_BAD_LEN
741 data = b'Error Message.'
742 self._test_parser(type_, code, data)
744 def test_parser_p10_2(self):
745 type_ = ofproto.OFPET_SWITCH_CONFIG_FAILED
746 code = ofproto.OFPSCFC_EPERM
747 data = b'Error Message.'
748 self._test_parser(type_, code, data)
750 def test_parser_p11_0(self):
751 type_ = ofproto.OFPET_ROLE_REQUEST_FAILED
752 code = ofproto.OFPRRFC_STALE
753 data = b'Error Message.'
754 self._test_parser(type_, code, data)
756 def test_parser_p11_1(self):
757 type_ = ofproto.OFPET_ROLE_REQUEST_FAILED
758 code = ofproto.OFPRRFC_UNSUP
759 data = b'Error Message.'
760 self._test_parser(type_, code, data)
762 def test_parser_p11_2(self):
763 type_ = ofproto.OFPET_ROLE_REQUEST_FAILED
764 code = ofproto.OFPRRFC_BAD_ROLE
765 data = b'Error Message.'
766 self._test_parser(type_, code, data)
768 def test_parser_experimenter(self):
772 data = b'Error Experimenter Message.'
774 # OFP_ERROR_EXPERIMENTER_MSG_PACK_STR = '!HHI'
775 fmt = ofproto.OFP_ERROR_EXPERIMENTER_MSG_PACK_STR
776 buf = self.buf + pack(fmt, type_, exp_type, experimenter) \
779 res = OFPErrorMsg.parser(object, self.version, self.msg_type,
780 self.msg_len, self.xid, buf)
782 eq_(res.version, self.version)
783 eq_(res.msg_type, self.msg_type)
784 eq_(res.msg_len, self.msg_len)
785 eq_(res.xid, self.xid)
787 eq_(res.exp_type, exp_type)
788 eq_(res.experimenter, experimenter)
791 def _test_serialize(self, type_, code, data):
792 # OFP_ERROR_MSG_PACK_STR = '!HH'
793 fmt = ofproto.OFP_ERROR_MSG_PACK_STR
794 buf = self.buf + pack(fmt, type_, code) + data
797 c = OFPErrorMsg(_Datapath)
804 eq_(ofproto.OFP_VERSION, c.version)
805 eq_(ofproto.OFPT_ERROR, c.msg_type)
807 eq_(len(buf), c.msg_len)
810 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
811 + ofproto.OFP_ERROR_MSG_PACK_STR.replace('!', '') \
812 + str(len(c.data)) + 's'
814 res = struct.unpack(fmt, six.binary_type(c.buf))
816 eq_(res[0], ofproto.OFP_VERSION)
817 eq_(res[1], ofproto.OFPT_ERROR)
818 eq_(res[2], len(buf))
824 def test_serialize_mid(self):
827 data = b'Error Message.'
828 self._test_serialize(type_, code, data)
830 def test_serialize_max(self):
831 type_ = 65534 # 65535 collides OFPET_EXPERIMENTER
833 data = b'Error Message.'.ljust(65523)
834 self._test_serialize(type_, code, data)
836 def test_serialize_min_except_data(self):
837 type_ = ofproto.OFPET_HELLO_FAILED
838 code = ofproto.OFPHFC_INCOMPATIBLE
839 data = b'Error Message.'
840 self._test_serialize(type_, code, data)
842 @raises(AssertionError)
843 def test_serialize_check_data(self):
844 c = OFPErrorMsg(_Datapath)
847 def _test_serialize_p(self, type_, code):
848 self._test_serialize(type_, code, b'Error Message.')
850 def test_serialize_p0_1(self):
851 self._test_serialize_p(ofproto.OFPET_HELLO_FAILED,
852 ofproto.OFPHFC_EPERM)
854 def test_serialize_p1_0(self):
855 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
856 ofproto.OFPBRC_BAD_VERSION)
858 def test_serialize_p1_1(self):
859 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
860 ofproto.OFPBRC_BAD_TYPE)
862 def test_serialize_p1_2(self):
863 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
864 ofproto.OFPBRC_BAD_STAT)
866 def test_serialize_p1_3(self):
867 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
868 ofproto.OFPBRC_BAD_EXPERIMENTER)
870 def test_serialize_p1_4(self):
871 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
872 ofproto.OFPBRC_BAD_EXP_TYPE)
874 def test_serialize_p1_5(self):
875 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
876 ofproto.OFPBRC_EPERM)
878 def test_serialize_p1_6(self):
879 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
880 ofproto.OFPBRC_BAD_LEN)
882 def test_serialize_p1_7(self):
883 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
884 ofproto.OFPBRC_BUFFER_EMPTY)
886 def test_serialize_p1_8(self):
887 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
888 ofproto.OFPBRC_BUFFER_UNKNOWN)
890 def test_serialize_p1_9(self):
891 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
892 ofproto.OFPBRC_BAD_TABLE_ID)
894 def test_serialize_p1_10(self):
895 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
896 ofproto.OFPBRC_IS_SLAVE)
898 def test_serialize_p1_11(self):
899 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
900 ofproto.OFPBRC_BAD_PORT)
902 def test_serialize_p1_12(self):
903 self._test_serialize_p(ofproto.OFPET_BAD_REQUEST,
904 ofproto.OFPBRC_BAD_PACKET)
906 def test_serialize_p2_0(self):
907 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
908 ofproto.OFPBAC_BAD_TYPE)
910 def test_serialize_p2_1(self):
911 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
912 ofproto.OFPBAC_BAD_LEN)
914 def test_serialize_p2_2(self):
915 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
916 ofproto.OFPBAC_BAD_EXPERIMENTER)
918 def test_serialize_p2_3(self):
919 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
920 ofproto.OFPBAC_BAD_EXP_TYPE)
922 def test_serialize_p2_4(self):
923 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
924 ofproto.OFPBAC_BAD_OUT_PORT)
926 def test_serialize_p2_5(self):
927 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
928 ofproto.OFPBAC_BAD_ARGUMENT)
930 def test_serialize_p2_6(self):
931 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
932 ofproto.OFPBAC_EPERM)
934 def test_serialize_p2_7(self):
935 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
936 ofproto.OFPBAC_TOO_MANY)
938 def test_serialize_p2_8(self):
939 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
940 ofproto.OFPBAC_BAD_QUEUE)
942 def test_serialize_p2_9(self):
943 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
944 ofproto.OFPBAC_BAD_OUT_GROUP)
946 def test_serialize_p2_10(self):
947 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
948 ofproto.OFPBAC_MATCH_INCONSISTENT)
950 def test_serialize_p2_11(self):
951 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
952 ofproto.OFPBAC_UNSUPPORTED_ORDER)
954 def test_serialize_p2_12(self):
955 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
956 ofproto.OFPBAC_BAD_TAG)
958 def test_serialize_p2_13(self):
959 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
960 ofproto.OFPBAC_BAD_SET_TYPE)
962 def test_serialize_p2_14(self):
963 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
964 ofproto.OFPBAC_BAD_SET_LEN)
966 def test_serialize_p2_15(self):
967 self._test_serialize_p(ofproto.OFPET_BAD_ACTION,
968 ofproto.OFPBAC_BAD_SET_ARGUMENT)
970 def test_serialize_p3_0(self):
971 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
972 ofproto.OFPBIC_UNKNOWN_INST)
974 def test_serialize_p3_1(self):
975 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
976 ofproto.OFPBIC_UNSUP_INST)
978 def test_serialize_p3_2(self):
979 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
980 ofproto.OFPBIC_BAD_TABLE_ID)
982 def test_serialize_p3_3(self):
983 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
984 ofproto.OFPBIC_UNSUP_METADATA)
986 def test_serialize_p3_4(self):
987 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
988 ofproto.OFPBIC_UNSUP_METADATA_MASK)
990 def test_serialize_p3_5(self):
991 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
992 ofproto.OFPBIC_BAD_EXPERIMENTER)
994 def test_serialize_p3_6(self):
995 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
996 ofproto.OFPBIC_BAD_EXP_TYPE)
998 def test_serialize_p3_7(self):
999 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
1000 ofproto.OFPBIC_BAD_LEN)
1002 def test_serialize_p3_8(self):
1003 self._test_serialize_p(ofproto.OFPET_BAD_INSTRUCTION,
1004 ofproto.OFPBIC_EPERM)
1006 def test_serialize_p4_0(self):
1007 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1008 ofproto.OFPBMC_BAD_TYPE)
1010 def test_serialize_p4_1(self):
1011 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1012 ofproto.OFPBMC_BAD_LEN)
1014 def test_serialize_p4_2(self):
1015 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1016 ofproto.OFPBMC_BAD_TAG)
1018 def test_serialize_p4_3(self):
1019 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1020 ofproto.OFPBMC_BAD_DL_ADDR_MASK)
1022 def test_serialize_p4_4(self):
1023 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1024 ofproto.OFPBMC_BAD_NW_ADDR_MASK)
1026 def test_serialize_p4_5(self):
1027 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1028 ofproto.OFPBMC_BAD_WILDCARDS)
1030 def test_serialize_p4_6(self):
1031 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1032 ofproto.OFPBMC_BAD_FIELD)
1034 def test_serialize_p4_7(self):
1035 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1036 ofproto.OFPBMC_BAD_VALUE)
1038 def test_serialize_p4_8(self):
1039 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1040 ofproto.OFPBMC_BAD_MASK)
1042 def test_serialize_p4_9(self):
1043 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1044 ofproto.OFPBMC_BAD_PREREQ)
1046 def test_serialize_p4_10(self):
1047 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1048 ofproto.OFPBMC_DUP_FIELD)
1050 def test_serialize_p4_11(self):
1051 self._test_serialize_p(ofproto.OFPET_BAD_MATCH,
1052 ofproto.OFPBMC_EPERM)
1054 def test_serialize_p5_0(self):
1055 self._test_serialize_p(ofproto.OFPET_FLOW_MOD_FAILED,
1056 ofproto.OFPFMFC_UNKNOWN)
1058 def test_serialize_p5_1(self):
1059 self._test_serialize_p(ofproto.OFPET_FLOW_MOD_FAILED,
1060 ofproto.OFPFMFC_TABLE_FULL)
1062 def test_serialize_p5_2(self):
1063 self._test_serialize_p(ofproto.OFPET_FLOW_MOD_FAILED,
1064 ofproto.OFPFMFC_BAD_TABLE_ID)
1066 def test_serialize_p5_3(self):
1067 self._test_serialize_p(ofproto.OFPET_FLOW_MOD_FAILED,
1068 ofproto.OFPFMFC_OVERLAP)
1070 def test_serialize_p5_4(self):
1071 self._test_serialize_p(ofproto.OFPET_FLOW_MOD_FAILED,
1072 ofproto.OFPFMFC_EPERM)
1074 def test_serialize_p5_5(self):
1075 self._test_serialize_p(ofproto.OFPET_FLOW_MOD_FAILED,
1076 ofproto.OFPFMFC_BAD_TIMEOUT)
1078 def test_serialize_p5_6(self):
1079 self._test_serialize_p(ofproto.OFPET_FLOW_MOD_FAILED,
1080 ofproto.OFPFMFC_BAD_COMMAND)
1082 def test_serialize_p5_7(self):
1083 self._test_serialize_p(ofproto.OFPET_FLOW_MOD_FAILED,
1084 ofproto.OFPFMFC_BAD_FLAGS)
1086 def test_serialize_p6_0(self):
1087 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1088 ofproto.OFPGMFC_GROUP_EXISTS)
1090 def test_serialize_p6_1(self):
1091 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1092 ofproto.OFPGMFC_INVALID_GROUP)
1094 def test_serialize_p6_2(self):
1095 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1096 ofproto.OFPGMFC_WEIGHT_UNSUPPORTED)
1098 def test_serialize_p6_3(self):
1099 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1100 ofproto.OFPGMFC_OUT_OF_GROUPS)
1102 def test_serialize_p6_4(self):
1103 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1104 ofproto.OFPGMFC_OUT_OF_BUCKETS)
1106 def test_serialize_p6_5(self):
1107 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1108 ofproto.OFPGMFC_CHAINING_UNSUPPORTED)
1110 def test_serialize_p6_6(self):
1111 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1112 ofproto.OFPGMFC_WATCH_UNSUPPORTED)
1114 def test_serialize_p6_7(self):
1115 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1116 ofproto.OFPGMFC_LOOP)
1118 def test_serialize_p6_8(self):
1119 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1120 ofproto.OFPGMFC_UNKNOWN_GROUP)
1122 def test_serialize_p6_9(self):
1123 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1124 ofproto.OFPGMFC_CHAINED_GROUP)
1126 def test_serialize_p6_10(self):
1127 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1128 ofproto.OFPGMFC_BAD_TYPE)
1130 def test_serialize_p6_11(self):
1131 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1132 ofproto.OFPGMFC_BAD_COMMAND)
1134 def test_serialize_p6_12(self):
1135 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1136 ofproto.OFPGMFC_BAD_BUCKET)
1138 def test_serialize_p6_13(self):
1139 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1140 ofproto.OFPGMFC_BAD_WATCH)
1142 def test_serialize_p6_14(self):
1143 self._test_serialize_p(ofproto.OFPET_GROUP_MOD_FAILED,
1144 ofproto.OFPGMFC_EPERM)
1146 def test_serialize_p7_0(self):
1147 self._test_serialize_p(ofproto.OFPET_PORT_MOD_FAILED,
1148 ofproto.OFPPMFC_BAD_PORT)
1150 def test_serialize_p7_1(self):
1151 self._test_serialize_p(ofproto.OFPET_PORT_MOD_FAILED,
1152 ofproto.OFPPMFC_BAD_HW_ADDR)
1154 def test_serialize_p7_2(self):
1155 self._test_serialize_p(ofproto.OFPET_PORT_MOD_FAILED,
1156 ofproto.OFPPMFC_BAD_CONFIG)
1158 def test_serialize_p7_3(self):
1159 self._test_serialize_p(ofproto.OFPET_PORT_MOD_FAILED,
1160 ofproto.OFPPMFC_BAD_ADVERTISE)
1162 def test_serialize_p7_4(self):
1163 self._test_serialize_p(ofproto.OFPET_PORT_MOD_FAILED,
1164 ofproto.OFPPMFC_EPERM)
1166 def test_serialize_p8_0(self):
1167 self._test_serialize_p(ofproto.OFPET_TABLE_MOD_FAILED,
1168 ofproto.OFPTMFC_BAD_TABLE)
1170 def test_serialize_p8_1(self):
1171 self._test_serialize_p(ofproto.OFPET_TABLE_MOD_FAILED,
1172 ofproto.OFPTMFC_BAD_CONFIG)
1174 def test_serialize_p8_2(self):
1175 self._test_serialize_p(ofproto.OFPET_TABLE_MOD_FAILED,
1176 ofproto.OFPTMFC_EPERM)
1178 def test_serialize_p9_0(self):
1179 self._test_serialize_p(ofproto.OFPET_QUEUE_OP_FAILED,
1180 ofproto.OFPQOFC_BAD_PORT)
1182 def test_serialize_p9_1(self):
1183 self._test_serialize_p(ofproto.OFPET_QUEUE_OP_FAILED,
1184 ofproto.OFPQOFC_BAD_QUEUE)
1186 def test_serialize_p9_2(self):
1187 self._test_serialize_p(ofproto.OFPET_QUEUE_OP_FAILED,
1188 ofproto.OFPQOFC_EPERM)
1190 def test_serialize_p10_0(self):
1191 self._test_serialize_p(ofproto.OFPET_SWITCH_CONFIG_FAILED,
1192 ofproto.OFPSCFC_BAD_FLAGS)
1194 def test_serialize_p10_1(self):
1195 self._test_serialize_p(ofproto.OFPET_SWITCH_CONFIG_FAILED,
1196 ofproto.OFPSCFC_BAD_LEN)
1198 def test_serialize_p10_2(self):
1199 self._test_serialize_p(ofproto.OFPET_SWITCH_CONFIG_FAILED,
1200 ofproto.OFPSCFC_EPERM)
1202 def test_serialize_p11_0(self):
1203 self._test_serialize_p(ofproto.OFPET_ROLE_REQUEST_FAILED,
1204 ofproto.OFPRRFC_STALE)
1206 def test_serialize_p11_1(self):
1207 self._test_serialize_p(ofproto.OFPET_ROLE_REQUEST_FAILED,
1208 ofproto.OFPRRFC_UNSUP)
1210 def test_serialize_p11_2(self):
1211 self._test_serialize_p(ofproto.OFPET_ROLE_REQUEST_FAILED,
1212 ofproto.OFPRRFC_BAD_ROLE)
1215 class TestOFPErrorExperimenterMsg(unittest.TestCase):
1216 """ Test case for ofproto_v1_2_parser.OFPErrorExperimenterMsg
1219 def test_init(self):
1220 c = OFPErrorExperimenterMsg(_Datapath)
1222 eq_(c.exp_type, None)
1223 eq_(c.experimenter, None)
1226 def _test_parser(self, exp_type, experimenter, data=None):
1227 # OFP_HEADER_PACK_STR
1228 # '!BBHI'...version, msg_type, msg_len, xid
1229 version = ofproto.OFP_VERSION
1230 msg_type = ofproto.OFPT_ERROR
1231 msg_len = ofproto.OFP_ERROR_MSG_SIZE
1234 fmt = ofproto.OFP_HEADER_PACK_STR
1235 buf = pack(fmt, version, msg_type, msg_len, xid)
1237 # OFP_ERROR_EXPERIMENTER_MSG_PACK_STR = '!HHI'
1239 fmt = ofproto.OFP_ERROR_EXPERIMENTER_MSG_PACK_STR
1240 buf += pack(fmt, type_, exp_type, experimenter)
1242 if data is not None:
1245 res = OFPErrorMsg.parser(
1246 object, version, msg_type, msg_len, xid, buf)
1248 eq_(res.version, version)
1249 eq_(res.msg_type, msg_type)
1250 eq_(res.msg_len, msg_len)
1252 eq_(res.type, type_)
1253 eq_(res.exp_type, exp_type)
1254 eq_(res.experimenter, experimenter)
1256 if data is not None:
1259 def test_parser_mid(self):
1261 experimenter = 2147483648
1262 data = b'Error Experimenter Message.'
1263 self._test_parser(exp_type, experimenter, data)
1265 def test_parser_max(self):
1267 experimenter = 4294967295
1268 data = b'Error Experimenter Message.'.ljust(65519)
1269 self._test_parser(exp_type, experimenter, data)
1271 def test_parser_min(self):
1274 self._test_parser(exp_type, experimenter)
1277 class TestOFPEchoRequest(unittest.TestCase):
1278 """ Test case for ofproto_v1_2_parser.OFPEchoRequest
1280 # OFP_HEADER_PACK_STR
1281 # '!BBHI'...version, msg_type, msg_len, xid
1282 version = ofproto.OFP_VERSION
1283 msg_type = ofproto.OFPT_ECHO_REQUEST
1284 msg_len = ofproto.OFP_HEADER_SIZE
1287 def test_init(self):
1288 c = OFPEchoRequest(_Datapath)
1291 def _test_parser(self, data=None):
1292 fmt = ofproto.OFP_HEADER_PACK_STR
1293 buf = pack(fmt, self.version, self.msg_type,
1294 self.msg_len, self.xid)
1296 if data is not None:
1299 res = OFPEchoRequest.parser(object, self.version, self.msg_type,
1300 self.msg_len, self.xid, buf)
1302 eq_(res.version, self.version)
1303 eq_(res.msg_type, self.msg_type)
1304 eq_(res.msg_len, self.msg_len)
1305 eq_(res.xid, self.xid)
1307 if data is not None:
1310 def test_parser_mid(self):
1311 data = b'Request Message.'
1312 self._test_parser(data)
1314 def test_parser_max(self):
1315 data = b'Request Message.'.ljust(65527)
1316 self._test_parser(data)
1318 def test_parser_min(self):
1320 self._test_parser(data)
1322 def _test_serialize(self, data):
1323 c = OFPEchoRequest(_Datapath)
1327 eq_(ofproto.OFP_VERSION, c.version)
1328 eq_(ofproto.OFPT_ECHO_REQUEST, c.msg_type)
1331 fmt = ofproto.OFP_HEADER_PACK_STR
1333 if data is not None:
1334 fmt += str(len(c.data)) + 's'
1336 res = struct.unpack(fmt, six.binary_type(c.buf))
1338 eq_(res[0], ofproto.OFP_VERSION)
1339 eq_(res[1], ofproto.OFPT_ECHO_REQUEST)
1340 eq_(res[2], len(c.buf))
1343 if data is not None:
1346 def test_serialize_mid(self):
1347 data = b'Request Message.'
1348 self._test_serialize(data)
1350 def test_serialize_max(self):
1351 data = b'Request Message.'.ljust(65527)
1352 self._test_serialize(data)
1354 def test_serialize_min(self):
1356 self._test_serialize(data)
1359 class TestOFPEchoReply(unittest.TestCase):
1360 """ Test case for ofproto_v1_2_parser.OFPEchoReply
1363 # OFP_HEADER_PACK_STR
1364 # '!BBHI'...version, msg_type, msg_len, xid
1365 version = ofproto.OFP_VERSION
1366 msg_type = ofproto.OFPT_ECHO_REPLY
1367 msg_len = ofproto.OFP_HEADER_SIZE
1370 def test_init(self):
1371 c = OFPEchoReply(_Datapath)
1374 def _test_parser(self, data):
1375 fmt = ofproto.OFP_HEADER_PACK_STR
1376 buf = pack(fmt, self.version, self.msg_type,
1377 self.msg_len, self.xid)
1379 if data is not None:
1382 res = OFPEchoReply.parser(object, self.version, self.msg_type,
1383 self.msg_len, self.xid, buf)
1385 eq_(res.version, self.version)
1386 eq_(res.msg_type, self.msg_type)
1387 eq_(res.msg_len, self.msg_len)
1388 eq_(res.xid, self.xid)
1390 if data is not None:
1393 def test_parser_mid(self):
1394 data = b'Reply Message.'
1395 self._test_parser(data)
1397 def test_parser_max(self):
1398 data = b'Reply Message.'.ljust(65527)
1399 self._test_parser(data)
1401 def test_parser_min(self):
1403 self._test_parser(data)
1405 def _test_serialize(self, data):
1406 fmt = ofproto.OFP_HEADER_PACK_STR
1407 buf = pack(fmt, self.version, self.msg_type,
1408 self.msg_len, self.xid) + data
1410 c = OFPEchoReply(_Datapath)
1414 eq_(ofproto.OFP_VERSION, c.version)
1415 eq_(ofproto.OFPT_ECHO_REPLY, c.msg_type)
1419 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
1420 + str(len(c.data)) + 's'
1422 res = struct.unpack(fmt, six.binary_type(c.buf))
1424 eq_(res[0], ofproto.OFP_VERSION)
1425 eq_(res[1], ofproto.OFPT_ECHO_REPLY)
1426 eq_(res[2], len(buf))
1430 def test_serialize_mid(self):
1431 data = b'Reply Message.'
1432 self._test_serialize(data)
1434 def test_serialize_max(self):
1435 data = b'Reply Message.'.ljust(65527)
1436 self._test_serialize(data)
1438 @raises(AssertionError)
1439 def test_serialize_check_data(self):
1440 c = OFPEchoReply(_Datapath)
1444 class TestOFPExperimenter(unittest.TestCase):
1445 """ Test case for ofproto_v1_2_parser.OFPExperimenter
1448 c = OFPExperimenter(_Datapath)
1450 def _test_parser(self, xid, experimenter, exp_type):
1451 # OFP_HEADER_PACK_STR
1452 # '!BBHI'...version, msg_type, msg_len, xid
1453 version = ofproto.OFP_VERSION
1454 msg_type = ofproto.OFPT_EXPERIMENTER
1455 msg_len = ofproto.OFP_EXPERIMENTER_HEADER_SIZE
1457 fmt = ofproto.OFP_HEADER_PACK_STR
1458 buf = pack(fmt, version, msg_type, msg_len, xid)
1460 # OFP_EXPERIMENTER_HEADER_PACK_STR
1461 # '!II'...experimenter, exp_type
1462 fmt = ofproto.OFP_EXPERIMENTER_HEADER_PACK_STR
1463 buf += pack(fmt, experimenter, exp_type)
1465 res = OFPExperimenter.parser(object, version, msg_type,
1468 eq_(version, res.version)
1469 eq_(msg_type, res.msg_type)
1470 eq_(msg_len, res.msg_len)
1472 eq_(experimenter, res.experimenter)
1473 eq_(exp_type, res.exp_type)
1475 def test_parser_mid(self):
1477 experimenter = 2147483648
1479 self._test_parser(xid, experimenter, exp_type)
1481 def test_parser_max(self):
1483 experimenter = 4294967295
1485 self._test_parser(xid, experimenter, exp_type)
1487 def test_parser_min(self):
1491 self._test_parser(xid, experimenter, exp_type)
1494 class TestOFPPort(unittest.TestCase):
1495 """ Test case for ofproto_v1_2_parser.OFPPort
1498 def test_init(self):
1500 # '!I4x6s2x16sIIIIIIII'... port_no, pad(4), hw_addr, pad(2),
1501 # name, config, state, curr, advertised,
1502 # peer, curr_speed, max_speed
1503 port_no = 1119692796
1504 hw_addr = 'c0:26:53:c4:29:e2'
1505 name = b'name'.ljust(16)
1509 advertised = 2025421682
1510 supported = 2120575149
1512 curr_speed = 2641353507
1513 max_speed = 1797291672
1515 fmt = ofproto.OFP_PORT_PACK_STR
1517 c = OFPPort(port_no, hw_addr, name, config, state, curr,
1518 advertised, supported, peer, curr_speed, max_speed)
1520 eq_(port_no, c.port_no)
1521 eq_(hw_addr, c.hw_addr)
1523 eq_(config, c.config)
1526 eq_(advertised, c.advertised)
1527 eq_(supported, c.supported)
1529 eq_(curr_speed, c.curr_speed)
1530 eq_(max_speed, c.max_speed)
1532 def _test_parser(self, port_no, hw_addr, config, state, curr, advertised,
1533 supported, peer, curr_speed, max_speed):
1534 name = b'name'.ljust(16)
1535 fmt = ofproto.OFP_PORT_PACK_STR
1536 buf = pack(fmt, port_no, addrconv.mac.text_to_bin(hw_addr), name,
1537 config, state, curr,
1538 advertised, supported, peer, curr_speed, max_speed)
1540 res = OFPPort.parser(buf, 0)
1542 eq_(port_no, res.port_no)
1543 eq_(hw_addr, res.hw_addr)
1545 eq_(config, res.config)
1546 eq_(state, res.state)
1548 eq_(advertised, res.advertised)
1549 eq_(supported, res.supported)
1551 eq_(curr_speed, res.curr_speed)
1552 eq_(max_speed, res.max_speed)
1554 def test_parser_mid(self):
1555 port_no = 1119692796
1556 hw_addr = 'c0:26:53:c4:29:e2'
1560 advertised = 2025421682
1561 supported = 2120575149
1563 curr_speed = 2641353507
1564 max_speed = 1797291672
1565 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1566 supported, peer, curr_speed, max_speed)
1568 def test_parser_max(self):
1569 port_no = ofproto.OFPP_ANY
1570 hw_addr = 'ff:ff:ff:ff:ff:ff'
1574 advertised = 4294967295
1575 supported = 4294967295
1577 curr_speed = 4294967295
1578 max_speed = 4294967295
1579 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1580 supported, peer, curr_speed, max_speed)
1582 def test_parser_min(self):
1584 hw_addr = '00:00:00:00:00:00'
1593 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1594 supported, peer, curr_speed, max_speed)
1596 def test_parser_p1(self):
1597 port_no = ofproto.OFPP_MAX
1598 hw_addr = 'c0:26:53:c4:29:e2'
1599 config = ofproto.OFPPC_PORT_DOWN
1600 state = ofproto.OFPPS_LINK_DOWN
1601 curr = advertised = supported \
1602 = peer = curr_speed = max_speed \
1603 = ofproto.OFPPF_10MB_HD
1604 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1605 supported, peer, curr_speed, max_speed)
1607 def test_parser_p2(self):
1608 port_no = ofproto.OFPP_IN_PORT
1609 hw_addr = 'c0:26:53:c4:29:e2'
1610 config = ofproto.OFPPC_NO_RECV
1611 state = ofproto.OFPPS_BLOCKED
1612 curr = advertised = supported \
1613 = peer = curr_speed = max_speed \
1614 = ofproto.OFPPF_10MB_FD
1615 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1616 supported, peer, curr_speed, max_speed)
1618 def test_parser_p3(self):
1619 port_no = ofproto.OFPP_TABLE
1620 hw_addr = 'c0:26:53:c4:29:e2'
1621 config = ofproto.OFPPC_NO_FWD
1622 state = ofproto.OFPPS_LIVE
1623 curr = advertised = supported \
1624 = peer = curr_speed = max_speed \
1625 = ofproto.OFPPF_100MB_HD
1626 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1627 supported, peer, curr_speed, max_speed)
1629 def test_parser_p4(self):
1630 port_no = ofproto.OFPP_NORMAL
1631 hw_addr = 'c0:26:53:c4:29:e2'
1632 config = ofproto.OFPPC_NO_PACKET_IN
1633 state = ofproto.OFPPS_LIVE
1634 curr = advertised = supported \
1635 = peer = curr_speed = max_speed \
1636 = ofproto.OFPPF_100MB_FD
1637 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1638 supported, peer, curr_speed, max_speed)
1640 def test_parser_p5(self):
1641 port_no = ofproto.OFPP_FLOOD
1642 hw_addr = 'c0:26:53:c4:29:e2'
1643 config = ofproto.OFPPC_NO_PACKET_IN
1644 state = ofproto.OFPPS_LIVE
1645 curr = advertised = supported \
1646 = peer = curr_speed = max_speed \
1647 = ofproto.OFPPF_1GB_HD
1648 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1649 supported, peer, curr_speed, max_speed)
1651 def test_parser_p6(self):
1652 port_no = ofproto.OFPP_ALL
1653 hw_addr = 'c0:26:53:c4:29:e2'
1654 config = ofproto.OFPPC_NO_PACKET_IN
1655 state = ofproto.OFPPS_LIVE
1656 curr = advertised = supported \
1657 = peer = curr_speed = max_speed \
1658 = ofproto.OFPPF_1GB_FD
1659 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1660 supported, peer, curr_speed, max_speed)
1662 def test_parser_p7(self):
1663 port_no = ofproto.OFPP_CONTROLLER
1664 hw_addr = 'c0:26:53:c4:29:e2'
1665 config = ofproto.OFPPC_NO_PACKET_IN
1666 state = ofproto.OFPPS_LIVE
1667 curr = advertised = supported \
1668 = peer = curr_speed = max_speed \
1669 = ofproto.OFPPF_10GB_FD
1670 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1671 supported, peer, curr_speed, max_speed)
1673 def test_parser_p8(self):
1674 port_no = ofproto.OFPP_LOCAL
1675 hw_addr = 'c0:26:53:c4:29:e2'
1676 config = ofproto.OFPPC_NO_PACKET_IN
1677 state = ofproto.OFPPS_LIVE
1678 curr = advertised = supported \
1679 = peer = curr_speed = max_speed \
1680 = ofproto.OFPPF_40GB_FD
1681 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1682 supported, peer, curr_speed, max_speed)
1684 def test_parser_p9(self):
1685 port_no = ofproto.OFPP_LOCAL
1686 hw_addr = 'c0:26:53:c4:29:e2'
1687 config = ofproto.OFPPC_NO_PACKET_IN
1688 state = ofproto.OFPPS_LIVE
1689 curr = advertised = supported \
1690 = peer = curr_speed = max_speed \
1691 = ofproto.OFPPF_100GB_FD
1692 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1693 supported, peer, curr_speed, max_speed)
1695 def test_parser_p10(self):
1696 port_no = ofproto.OFPP_LOCAL
1697 hw_addr = 'c0:26:53:c4:29:e2'
1698 config = ofproto.OFPPC_NO_PACKET_IN
1699 state = ofproto.OFPPS_LIVE
1700 curr = advertised = supported \
1701 = peer = curr_speed = max_speed \
1702 = ofproto.OFPPF_1TB_FD
1703 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1704 supported, peer, curr_speed, max_speed)
1706 def test_parser_p11(self):
1707 port_no = ofproto.OFPP_LOCAL
1708 hw_addr = 'c0:26:53:c4:29:e2'
1709 config = ofproto.OFPPC_NO_PACKET_IN
1710 state = ofproto.OFPPS_LIVE
1711 curr = advertised = supported \
1712 = peer = curr_speed = max_speed \
1713 = ofproto.OFPPF_OTHER
1714 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1715 supported, peer, curr_speed, max_speed)
1717 def test_parser_p12(self):
1718 port_no = ofproto.OFPP_LOCAL
1719 hw_addr = 'c0:26:53:c4:29:e2'
1720 config = ofproto.OFPPC_NO_PACKET_IN
1721 state = ofproto.OFPPS_LIVE
1722 curr = advertised = supported \
1723 = peer = curr_speed = max_speed \
1724 = ofproto.OFPPF_COPPER
1725 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1726 supported, peer, curr_speed, max_speed)
1728 def test_parser_p13(self):
1729 port_no = ofproto.OFPP_LOCAL
1730 hw_addr = 'c0:26:53:c4:29:e2'
1731 config = ofproto.OFPPC_NO_PACKET_IN
1732 state = ofproto.OFPPS_LIVE
1733 curr = advertised = supported \
1734 = peer = curr_speed = max_speed \
1735 = ofproto.OFPPF_FIBER
1736 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1737 supported, peer, curr_speed, max_speed)
1739 def test_parser_p14(self):
1740 port_no = ofproto.OFPP_LOCAL
1741 hw_addr = 'c0:26:53:c4:29:e2'
1742 config = ofproto.OFPPC_NO_PACKET_IN
1743 state = ofproto.OFPPS_LIVE
1744 curr = advertised = supported \
1745 = peer = curr_speed = max_speed \
1746 = ofproto.OFPPF_AUTONEG
1747 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1748 supported, peer, curr_speed, max_speed)
1750 def test_parser_p15(self):
1751 port_no = ofproto.OFPP_LOCAL
1752 hw_addr = 'c0:26:53:c4:29:e2'
1753 config = ofproto.OFPPC_NO_PACKET_IN
1754 state = ofproto.OFPPS_LIVE
1755 curr = advertised = supported \
1756 = peer = curr_speed = max_speed \
1757 = ofproto.OFPPF_PAUSE
1758 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1759 supported, peer, curr_speed, max_speed)
1761 def test_parser_p16(self):
1762 port_no = ofproto.OFPP_LOCAL
1763 hw_addr = 'c0:26:53:c4:29:e2'
1764 config = ofproto.OFPPC_NO_PACKET_IN
1765 state = ofproto.OFPPS_LIVE
1766 curr = advertised = supported \
1767 = peer = curr_speed = max_speed \
1768 = ofproto.OFPPF_PAUSE_ASYM
1769 self._test_parser(port_no, hw_addr, config, state, curr, advertised,
1770 supported, peer, curr_speed, max_speed)
1773 class TestOFPFeaturesRequest(unittest.TestCase):
1774 """ Test case for ofproto_v1_2_parser.OFPFeaturesRequest
1777 def test_serialize(self):
1778 c = OFPFeaturesRequest(_Datapath)
1781 eq_(ofproto.OFP_VERSION, c.version)
1782 eq_(ofproto.OFPT_FEATURES_REQUEST, c.msg_type)
1785 fmt = ofproto.OFP_HEADER_PACK_STR
1787 res = struct.unpack(fmt, six.binary_type(c.buf))
1789 eq_(res[0], ofproto.OFP_VERSION)
1790 eq_(res[1], ofproto.OFPT_FEATURES_REQUEST)
1791 eq_(res[2], len(c.buf))
1795 class TestOFPSwitchFeatures(unittest.TestCase):
1796 """ Test case for ofproto_v1_2_parser.OFPSwitchFeatures
1799 def _test_parser(self, xid, datapath_id, n_buffers,
1800 n_tables, capabilities, reserved, port_cnt=0):
1802 # OFP_HEADER_PACK_STR
1803 # '!BBHI'...version, msg_type, msg_len, xid
1804 version = ofproto.OFP_VERSION
1805 msg_type = ofproto.OFPT_FEATURES_REPLY
1806 msg_len = ofproto.OFP_SWITCH_FEATURES_SIZE \
1807 + ofproto.OFP_PORT_SIZE * port_cnt
1809 fmt = ofproto.OFP_HEADER_PACK_STR
1810 buf = pack(fmt, version, msg_type, msg_len, xid)
1812 # OFP_SWITCH_FEATURES_PACK_STR
1813 # '!QIB3xII'...datapath_id, n_buffers, n_tables,
1814 # pad(3), capabilities, reserved
1816 fmt = ofproto.OFP_SWITCH_FEATURES_PACK_STR
1817 buf += pack(fmt, datapath_id, n_buffers, n_tables,
1818 capabilities, reserved)
1820 for i in range(port_cnt):
1822 # '!I4x6s2x16sIIIIIIII'... port_no, pad(4), hw_addr, pad(2),
1823 # name, config, state, curr, advertised,
1824 # peer, curr_speed, max_speed
1827 fmt = ofproto.OFP_PORT_PACK_STR
1828 buf += pack(fmt, port_no, b'\x00' * 6, b'\x00' * 16, 0, 0, 0,
1831 res = OFPSwitchFeatures.parser(object, version, msg_type,
1834 eq_(res.version, version)
1835 eq_(res.msg_type, msg_type)
1836 eq_(res.msg_len, msg_len)
1839 eq_(res.datapath_id, datapath_id)
1840 eq_(res.n_buffers, n_buffers)
1841 eq_(res.n_tables, n_tables)
1842 eq_(res.capabilities, capabilities)
1843 eq_(res._reserved, reserved)
1845 for i in range(port_cnt):
1846 eq_(res.ports[i].port_no, i)
1848 def test_parser_mid(self):
1850 datapath_id = 1270985291017894273
1851 n_buffers = 2148849654
1853 capabilities = 1766843586
1854 reserved = 2013714700
1857 self._test_parser(xid, datapath_id, n_buffers, n_tables,
1858 capabilities, reserved, port_cnt)
1860 def test_parser_max(self):
1862 datapath_id = 18446744073709551615
1863 n_buffers = 4294967295
1865 capabilities = 4294967295
1866 reserved = 4294967295
1869 self._test_parser(xid, datapath_id, n_buffers, n_tables,
1870 capabilities, reserved, port_cnt)
1872 def test_parser_min(self):
1881 self._test_parser(xid, datapath_id, n_buffers, n_tables,
1882 capabilities, reserved, port_cnt)
1885 class TestOFPGetConfigRequest(unittest.TestCase):
1886 """ Test case for ofproto_v1_2_parser.OFPGetConfigRequest
1889 def test_serialize(self):
1890 c = OFPGetConfigRequest(_Datapath)
1893 eq_(ofproto.OFP_VERSION, c.version)
1894 eq_(ofproto.OFPT_GET_CONFIG_REQUEST, c.msg_type)
1897 fmt = ofproto.OFP_HEADER_PACK_STR
1899 res = struct.unpack(fmt, six.binary_type(c.buf))
1900 eq_(res[0], ofproto.OFP_VERSION)
1901 eq_(res[1], ofproto.OFPT_GET_CONFIG_REQUEST)
1902 eq_(res[2], len(c.buf))
1906 class TestOFPGetConfigReply(unittest.TestCase):
1907 """ Test case for ofproto_v1_2_parser.OFPGetConfigReply
1910 def _test_parser(self, xid, flags, miss_send_len):
1911 # OFP_HEADER_PACK_STR
1912 # '!BBHI'...version, msg_type, msg_len, xid
1913 version = ofproto.OFP_VERSION
1914 msg_type = ofproto.OFPT_GET_CONFIG_REPLY
1915 msg_len = ofproto.OFP_SWITCH_CONFIG_SIZE
1917 fmt = ofproto.OFP_HEADER_PACK_STR
1918 buf = pack(fmt, version, msg_type, msg_len, xid)
1920 # OFP_SWITCH_CONFIG_PACK_STR
1921 # '!HH'...flags, miss_send_len
1922 fmt = ofproto.OFP_SWITCH_CONFIG_PACK_STR
1923 buf += pack(fmt, flags, miss_send_len)
1925 res = OFPGetConfigReply.parser(object, version, msg_type,
1928 eq_(version, res.version)
1929 eq_(msg_type, res.msg_type)
1930 eq_(msg_len, res.msg_len)
1932 eq_(flags, res.flags)
1933 eq_(miss_send_len, res.miss_send_len)
1935 def test_parser_mid(self):
1938 miss_send_len = 13838
1939 self._test_parser(xid, flags, miss_send_len)
1941 def test_parser_max(self):
1944 miss_send_len = 65535
1945 self._test_parser(xid, flags, miss_send_len)
1947 def test_parser_min(self):
1949 flags = ofproto.OFPC_FRAG_NORMAL
1951 self._test_parser(xid, flags, miss_send_len)
1953 def test_parser_p1(self):
1955 flags = ofproto.OFPC_FRAG_DROP
1956 miss_send_len = 13838
1957 self._test_parser(xid, flags, miss_send_len)
1959 def test_parser_p2(self):
1961 flags = ofproto.OFPC_FRAG_REASM
1962 miss_send_len = 13838
1963 self._test_parser(xid, flags, miss_send_len)
1965 def test_parser_p3(self):
1967 flags = ofproto.OFPC_FRAG_MASK
1968 miss_send_len = 13838
1969 self._test_parser(xid, flags, miss_send_len)
1971 def test_parser_p4(self):
1973 flags = ofproto.OFPC_INVALID_TTL_TO_CONTROLLER
1974 miss_send_len = 13838
1975 self._test_parser(xid, flags, miss_send_len)
1978 class TestOFPSetConfig(unittest.TestCase):
1979 """ Test case for ofproto_v1_2_parser.OFPSetConfig
1982 def test_init(self):
1983 # OFP_SWITCH_CONFIG_PACK_STR
1984 # '!HH'...flags, miss_send_len
1986 miss_send_len = 13838
1988 c = OFPSetConfig(_Datapath, flags, miss_send_len)
1991 eq_(miss_send_len, c.miss_send_len)
1993 def _test_serialize(self, flags, miss_send_len):
1994 c = OFPSetConfig(_Datapath, flags, miss_send_len)
1997 eq_(ofproto.OFP_VERSION, c.version)
1998 eq_(ofproto.OFPT_SET_CONFIG, c.msg_type)
2002 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
2003 + ofproto.OFP_SWITCH_CONFIG_PACK_STR.replace('!', '')
2005 res = struct.unpack(fmt, six.binary_type(c.buf))
2007 eq_(res[0], ofproto.OFP_VERSION)
2008 eq_(res[1], ofproto.OFPT_SET_CONFIG)
2009 eq_(res[2], len(c.buf))
2012 eq_(res[5], miss_send_len)
2014 def test_serialize_mid(self):
2016 miss_send_len = 13838
2017 self._test_serialize(flags, miss_send_len)
2019 def test_serialize_max(self):
2021 miss_send_len = 65535
2022 self._test_serialize(flags, miss_send_len)
2024 def test_serialize_min(self):
2025 flags = ofproto.OFPC_FRAG_NORMAL
2027 self._test_serialize(flags, miss_send_len)
2029 def test_serialize_p1(self):
2030 flags = ofproto.OFPC_FRAG_DROP
2031 miss_send_len = 13838
2032 self._test_serialize(flags, miss_send_len)
2034 def test_serialize_p2(self):
2035 flags = ofproto.OFPC_FRAG_REASM
2036 miss_send_len = 13838
2037 self._test_serialize(flags, miss_send_len)
2039 def test_serialize_p3(self):
2040 flags = ofproto.OFPC_FRAG_MASK
2041 miss_send_len = 13838
2042 self._test_serialize(flags, miss_send_len)
2044 def test_serialize_p4(self):
2045 flags = ofproto.OFPC_INVALID_TTL_TO_CONTROLLER
2046 miss_send_len = 13838
2047 self._test_serialize(flags, miss_send_len)
2049 @raises(AssertionError)
2050 def test_serialize_check_flags(self):
2052 miss_send_len = 13838
2053 c = OFPSetConfig(_Datapath, flags, miss_send_len)
2056 @raises(AssertionError)
2057 def test_serialize_check_miss_send_len(self):
2059 miss_send_len = None
2060 c = OFPSetConfig(_Datapath, flags, miss_send_len)
2064 class TestOFPPacketIn(unittest.TestCase):
2065 """ Test case for ofproto_v1_2_parser.OFPPacketIn
2068 def _test_parser(self, xid, buffer_id, total_len=0,
2069 reason=0, table_id=0, data=None):
2073 # OFP_HEADER_PACK_STR
2074 # '!BBHI'...version, msg_type, msg_len, xid
2075 version = ofproto.OFP_VERSION
2076 msg_type = ofproto.OFPT_PACKET_IN
2077 msg_len = ofproto.OFP_PACKET_IN_SIZE + len(data)
2079 fmt = ofproto.OFP_HEADER_PACK_STR
2080 buf = pack(fmt, version, msg_type, msg_len, xid)
2082 # OFP_PACKET_IN_PACK_STR
2083 fmt = ofproto.OFP_PACKET_IN_PACK_STR
2084 buf += pack(fmt, buffer_id, total_len, reason, table_id)
2087 buf_match = bytearray()
2089 match.serialize(buf_match, 0)
2090 buf += six.binary_type(buf_match)
2096 res = OFPPacketIn.parser(object, version, msg_type, msg_len,
2099 eq_(version, res.version)
2100 eq_(msg_type, res.msg_type)
2101 eq_(msg_len, res.msg_len)
2103 eq_(buffer_id, res.buffer_id)
2104 eq_(total_len, res.total_len)
2105 eq_(reason, res.reason)
2106 eq_(table_id, res.table_id)
2107 ok_(hasattr(res, 'match'))
2108 eq_(ofproto.OFPMT_OXM, res.match.type)
2111 eq_(data[:total_len], res.data)
2113 def test_data_is_total_len(self):
2115 buffer_id = 2926809324
2119 total_len = len(data)
2120 self._test_parser(xid, buffer_id, total_len, reason, table_id, data)
2122 def test_data_is_not_total_len(self):
2124 buffer_id = 2926809324
2128 total_len = len(data) - 1
2129 self._test_parser(xid, buffer_id, total_len, reason, table_id, data)
2131 def test_parser_max(self):
2132 # 65535(!H max) - 24(without data) = 65511
2134 buffer_id = 4294967295
2137 data = b'data'.ljust(65511)
2138 total_len = len(data)
2139 self._test_parser(xid, buffer_id, total_len, reason, table_id, data)
2141 def test_parser_min(self):
2144 reason = ofproto.OFPR_NO_MATCH
2147 self._test_parser(xid, buffer_id, total_len, reason, table_id)
2149 def test_parser_p1(self):
2150 data = b'data'.ljust(8)
2152 buffer_id = 2926809324
2153 total_len = len(data)
2154 reason = ofproto.OFPR_ACTION
2156 self._test_parser(xid, buffer_id, total_len, reason, table_id, data)
2158 def test_parser_p2(self):
2159 data = b'data'.ljust(8)
2161 buffer_id = 2926809324
2162 total_len = len(data)
2163 reason = ofproto.OFPR_INVALID_TTL
2165 self._test_parser(xid, buffer_id, total_len, reason, table_id, data)
2168 class TestOFPFlowRemoved(unittest.TestCase):
2169 """ Test case for ofproto_v1_2_parser.OFPFlowRemoved
2172 def _test_parser(self, xid, cookie, priority,
2173 reason, table_id, duration_sec,
2174 duration_nsec, idle_timeout, hard_timeout,
2175 packet_count, byte_count):
2176 # OFP_HEADER_PACK_STR
2177 # '!BBHI'...version, msg_type, msg_len, xid
2178 version = ofproto.OFP_VERSION
2179 msg_type = ofproto.OFPT_FLOW_REMOVED
2180 msg_len = ofproto.OFP_FLOW_REMOVED_SIZE
2182 fmt = ofproto.OFP_HEADER_PACK_STR
2183 buf = pack(fmt, version, msg_type, msg_len, xid)
2185 # OFP_FLOW_REMOVED_PACK_STR0
2186 # '!QHBBIIHHQQ' ...cookie, priority, reason, table_id,
2187 # duration_sec, duration_nsec, idle_timeout,
2188 # hard_timeout, packet_count, byte_count
2190 fmt = ofproto.OFP_FLOW_REMOVED_PACK_STR0
2191 buf += pack(fmt, cookie, priority, reason, table_id,
2192 duration_sec, duration_nsec, idle_timeout,
2193 hard_timeout, packet_count, byte_count)
2195 # OFP_MATCH_PACK_STR
2197 buf_match = bytearray()
2198 match.serialize(buf_match, 0)
2200 buf += six.binary_type(buf_match)
2202 res = OFPFlowRemoved.parser(object, version, msg_type,
2205 eq_(version, res.version)
2206 eq_(msg_type, res.msg_type)
2207 eq_(msg_len, res.msg_len)
2209 eq_(cookie, res.cookie)
2210 eq_(priority, res.priority)
2211 eq_(reason, res.reason)
2212 eq_(table_id, res.table_id)
2213 eq_(duration_sec, res.duration_sec)
2214 eq_(duration_nsec, res.duration_nsec)
2215 eq_(idle_timeout, res.idle_timeout)
2216 eq_(hard_timeout, res.hard_timeout)
2217 eq_(packet_count, res.packet_count)
2218 eq_(byte_count, res.byte_count)
2219 ok_(hasattr(res, 'match'))
2220 eq_(ofproto.OFPMT_OXM, res.match.type)
2222 def test_parser_mid(self):
2224 cookie = 178378173441633860
2228 duration_sec = 2250548154
2229 duration_nsec = 2492776995
2230 idle_timeout = 60284
2231 hard_timeout = 60285
2232 packet_count = 6489108735192644493
2233 byte_count = 7334344481123449724
2234 self._test_parser(xid, cookie, priority,
2235 reason, table_id, duration_sec,
2236 duration_nsec, idle_timeout, hard_timeout,
2237 packet_count, byte_count)
2239 def test_parser_max(self):
2241 cookie = 18446744073709551615
2245 duration_sec = 4294967295
2246 duration_nsec = 4294967295
2247 idle_timeout = 65535
2248 hard_timeout = 65535
2249 packet_count = 18446744073709551615
2250 byte_count = 18446744073709551615
2251 self._test_parser(xid, cookie, priority,
2252 reason, table_id, duration_sec,
2253 duration_nsec, idle_timeout, hard_timeout,
2254 packet_count, byte_count)
2256 def test_parser_min(self):
2260 reason = ofproto.OFPRR_IDLE_TIMEOUT
2268 self._test_parser(xid, cookie, priority,
2269 reason, table_id, duration_sec,
2270 duration_nsec, idle_timeout, hard_timeout,
2271 packet_count, byte_count)
2273 def test_parser_p1(self):
2275 cookie = 178378173441633860
2277 reason = ofproto.OFPRR_HARD_TIMEOUT
2279 duration_sec = 2250548154
2280 duration_nsec = 2492776995
2281 idle_timeout = 60284
2282 hard_timeout = 60285
2283 packet_count = 6489108735192644493
2284 byte_count = 7334344481123449724
2285 self._test_parser(xid, cookie, priority,
2286 reason, table_id, duration_sec,
2287 duration_nsec, idle_timeout, hard_timeout,
2288 packet_count, byte_count)
2290 def test_parser_p2(self):
2292 cookie = 178378173441633860
2294 reason = ofproto.OFPRR_DELETE
2296 duration_sec = 2250548154
2297 duration_nsec = 2492776995
2298 idle_timeout = 60284
2299 hard_timeout = 60285
2300 packet_count = 6489108735192644493
2301 byte_count = 7334344481123449724
2302 self._test_parser(xid, cookie, priority,
2303 reason, table_id, duration_sec,
2304 duration_nsec, idle_timeout, hard_timeout,
2305 packet_count, byte_count)
2307 def test_parser_p3(self):
2309 cookie = 178378173441633860
2311 reason = ofproto.OFPRR_GROUP_DELETE
2313 duration_sec = 2250548154
2314 duration_nsec = 2492776995
2315 idle_timeout = 60284
2316 hard_timeout = 60285
2317 packet_count = 6489108735192644493
2318 byte_count = 7334344481123449724
2319 self._test_parser(xid, cookie, priority,
2320 reason, table_id, duration_sec,
2321 duration_nsec, idle_timeout, hard_timeout,
2322 packet_count, byte_count)
2325 class TestOFPPortStatus(unittest.TestCase):
2326 """ Test case for ofproto_v1_2_parser.OFPPortStatus
2329 def _test_parser(self, xid, reason,
2330 port_no, config, state, curr, advertised,
2331 supported, peer, curr_speed, max_speed):
2333 # OFP_HEADER_PACK_STR
2334 # '!BBHI'...version, msg_type, msg_len, xid
2335 version = ofproto.OFP_VERSION
2336 msg_type = ofproto.OFPT_PORT_STATUS
2337 msg_len = ofproto.OFP_PORT_STATUS_SIZE
2339 fmt = ofproto.OFP_HEADER_PACK_STR
2340 buf = pack(fmt, version, msg_type, msg_len, xid)
2342 # OFP_PORT_STATUS_PACK_STR = '!B7x' + _OFP_PORT_PACK_STR
2343 # '!B7x'...reason, pad(7)
2345 # '!I4x6s2x16sIIIIIIII'... port_no, pad(4), hw_addr, pad(2),
2346 # name, config, state, curr, advertised,
2347 # peer, curr_speed, max_speed
2348 hw_addr = '80:ff:9a:e3:72:85'
2349 name = b'name'.ljust(16)
2351 fmt = ofproto.OFP_PORT_STATUS_PACK_STR
2352 buf += pack(fmt, reason, port_no, addrconv.mac.text_to_bin(hw_addr),
2353 name, config, state, curr, advertised,
2354 supported, peer, curr_speed, max_speed)
2356 res = OFPPortStatus.parser(object, version, msg_type, msg_len,
2359 eq_(reason, res.reason)
2360 eq_(port_no, res.desc.port_no)
2361 eq_(hw_addr, res.desc.hw_addr)
2362 eq_(name, res.desc.name)
2363 eq_(config, res.desc.config)
2364 eq_(state, res.desc.state)
2365 eq_(curr, res.desc.curr)
2366 eq_(advertised, res.desc.advertised)
2367 eq_(supported, res.desc.supported)
2368 eq_(peer, res.desc.peer)
2369 eq_(curr_speed, res.desc.curr_speed)
2370 eq_(max_speed, res.desc.max_speed)
2372 def test_parser_mid(self):
2375 port_no = 1119692796
2379 advertised = 2025421682
2380 supported = 2120575149
2382 curr_speed = 2641353507
2383 max_speed = 1797291672
2384 self._test_parser(xid, reason,
2385 port_no, config, state, curr, advertised,
2386 supported, peer, curr_speed, max_speed)
2388 def test_parser_max(self):
2391 port_no = ofproto.OFPP_ANY
2395 advertised = 4294967295
2396 supported = 4294967295
2398 curr_speed = 4294967295
2399 max_speed = 4294967295
2400 self._test_parser(xid, reason,
2401 port_no, config, state, curr, advertised,
2402 supported, peer, curr_speed, max_speed)
2404 def test_parser_min(self):
2416 self._test_parser(xid, reason,
2417 port_no, config, state, curr, advertised,
2418 supported, peer, curr_speed, max_speed)
2420 def test_parser_p1(self):
2422 reason = ofproto.OFPPR_DELETE
2423 port_no = ofproto.OFPP_MAX
2424 config = ofproto.OFPPC_PORT_DOWN
2425 state = ofproto.OFPPS_LINK_DOWN
2426 curr = advertised = supported \
2427 = peer = curr_speed = max_speed \
2428 = ofproto.OFPPF_10MB_HD
2429 self._test_parser(xid, reason,
2430 port_no, config, state, curr, advertised,
2431 supported, peer, curr_speed, max_speed)
2433 def test_parser_p2(self):
2435 reason = ofproto.OFPPR_MODIFY
2436 port_no = ofproto.OFPP_MAX
2437 config = ofproto.OFPPC_PORT_DOWN
2438 state = ofproto.OFPPS_LINK_DOWN
2439 curr = advertised = supported \
2440 = peer = curr_speed = max_speed \
2441 = ofproto.OFPPF_10MB_HD
2442 self._test_parser(xid, reason,
2443 port_no, config, state, curr, advertised,
2444 supported, peer, curr_speed, max_speed)
2447 class TestOFPPacketOut(unittest.TestCase):
2448 """ Test case for ofproto_v1_2_parser.OFPPacketOut
2451 def _test_init(self, in_port):
2452 buffer_id = 0xffffffff
2454 out_port = 0x00002ae0
2455 actions = [OFPActionOutput(out_port, 0)]
2457 c = OFPPacketOut(_Datapath, buffer_id, in_port, actions, data)
2459 eq_(buffer_id, c.buffer_id)
2460 eq_(in_port, c.in_port)
2461 eq_(0, c.actions_len)
2463 eq_(actions, c.actions)
2465 def test_init(self):
2466 in_port = 0x00040455
2467 self._test_init(in_port)
2469 @raises(AssertionError)
2470 def test_init_check_in_port(self):
2472 self._test_init(in_port)
2474 def _test_serialize(self, buffer_id, in_port, action_cnt=0, data=None):
2476 for i in range(action_cnt):
2477 actions.append(ofproto_v1_2_parser.OFPActionOutput(i, 0))
2479 c = OFPPacketOut(_Datapath, buffer_id, in_port, actions, data)
2482 eq_(ofproto.OFP_VERSION, c.version)
2483 eq_(ofproto.OFPT_PACKET_OUT, c.msg_type)
2486 fmt = ofproto.OFP_HEADER_PACK_STR \
2487 + ofproto.OFP_PACKET_OUT_PACK_STR[1:] \
2488 + ofproto.OFP_ACTION_OUTPUT_PACK_STR[1:] * action_cnt
2490 if data is not None:
2491 fmt += str(len(data)) + 's'
2493 res = struct.unpack(fmt, six.binary_type(c.buf))
2495 eq_(res[0], ofproto.OFP_VERSION)
2496 eq_(res[1], ofproto.OFPT_PACKET_OUT)
2497 eq_(res[2], len(c.buf))
2499 eq_(res[4], buffer_id)
2500 eq_(res[5], in_port)
2501 eq_(res[6], ofproto.OFP_ACTION_OUTPUT_SIZE * action_cnt)
2503 for i in range(action_cnt):
2505 eq_(res[index], ofproto.OFPAT_OUTPUT)
2506 eq_(res[index + 1], ofproto.OFP_ACTION_OUTPUT_SIZE)
2507 eq_(res[index + 2], i)
2508 eq_(res[index + 3], 0)
2513 def test_serialize_true(self):
2514 buffer_id = 0xffffffff
2515 in_port = 0x00040455
2518 self._test_serialize(buffer_id, in_port, action_cnt, data)
2520 def test_serialize_none(self):
2521 buffer_id = 0xffffffff
2522 in_port = 0x00040455
2523 self._test_serialize(buffer_id, in_port)
2525 def test_serialize_max(self):
2526 buffer_id = 0xffffffff
2527 in_port = 4294967295
2529 data = b'Message'.ljust(65495)
2530 self._test_serialize(buffer_id, in_port, action_cnt, data)
2532 def test_serialize_min(self):
2535 self._test_serialize(buffer_id, in_port)
2537 def test_serialize_p1(self):
2538 buffer_id = 2147483648
2539 in_port = ofproto.OFPP_CONTROLLER
2540 self._test_serialize(buffer_id, in_port)
2542 @raises(AssertionError)
2543 def test_serialize_check_buffer_id(self):
2544 buffer_id = 2147483648
2548 self._test_serialize(buffer_id, in_port, action_cnt, data)
2551 class TestOFPFlowMod(unittest.TestCase):
2552 """ Test case for ofproto_v1_2_parser.OFPFlowMod
2555 def test_init(self):
2556 # OFP_FLOW_MOD_PACK_STR0
2557 # '!QQBBHHHIIIH2x'...cookie, cookie_mask, table_id, command,
2558 # idle_timeout, hard_timeout, priority, buffer_id,
2559 # out_port, out_group, flags
2560 cookie = 2127614848199081640
2561 cookie_mask = 2127614848199081641
2564 idle_timeout = 62317
2567 buffer_id = 4037115955
2571 instructions = [OFPInstructionGotoTable(table_id)]
2575 match.set_in_port(in_port)
2577 c = OFPFlowMod(_Datapath, cookie, cookie_mask, table_id, command,
2578 idle_timeout, hard_timeout, priority, buffer_id,
2579 out_port, out_group, flags, match, instructions)
2581 eq_(cookie, c.cookie)
2582 eq_(cookie_mask, c.cookie_mask)
2583 eq_(table_id, c.table_id)
2584 eq_(command, c.command)
2585 eq_(idle_timeout, c.idle_timeout)
2586 eq_(hard_timeout, c.hard_timeout)
2587 eq_(priority, c.priority)
2588 eq_(buffer_id, c.buffer_id)
2589 eq_(out_port, c.out_port)
2590 eq_(out_group, c.out_group)
2592 eq_(in_port, c.match._flow.in_port)
2593 eq_(instructions[0], c.instructions[0])
2595 def _test_serialize(self, cookie, cookie_mask, table_id,
2596 command, idle_timeout, hard_timeout,
2597 priority, buffer_id, out_port,
2598 out_group, flags, inst_cnt=0):
2601 match.set_dl_type(dl_type)
2604 for i in range(inst_cnt):
2605 insts.append(OFPInstructionGotoTable(i))
2607 c = OFPFlowMod(_Datapath, cookie, cookie_mask, table_id, command,
2608 idle_timeout, hard_timeout, priority, buffer_id,
2609 out_port, out_group, flags, match, insts)
2612 eq_(ofproto.OFP_VERSION, c.version)
2613 eq_(ofproto.OFPT_FLOW_MOD, c.msg_type)
2616 fmt = ofproto.OFP_HEADER_PACK_STR \
2617 + ofproto.OFP_FLOW_MOD_PACK_STR0[1:] \
2619 + MTEthType.pack_str[1:] + '6x' \
2620 + ofproto.OFP_INSTRUCTION_GOTO_TABLE_PACK_STR[1:] * inst_cnt
2622 res = struct.unpack(fmt, six.binary_type(c.buf))
2624 eq_(res[0], ofproto.OFP_VERSION)
2625 eq_(res[1], ofproto.OFPT_FLOW_MOD)
2626 eq_(res[2], len(c.buf))
2629 eq_(res[5], cookie_mask)
2630 eq_(res[6], table_id)
2631 eq_(res[7], command)
2632 eq_(res[8], idle_timeout)
2633 eq_(res[9], hard_timeout)
2634 eq_(res[10], priority)
2635 eq_(res[11], buffer_id)
2636 eq_(res[12], out_port)
2637 eq_(res[13], out_group)
2640 # OFP_MATCH (type, length, class, [field, hashmask], n_byte, ip_proto)
2641 eq_(res[15], ofproto.OFPMT_OXM)
2642 eq_(res[16], 10) # OFP_MATCH_STR + MTEthType.pack_str
2643 eq_(res[17], ofproto.OFPXMC_OPENFLOW_BASIC)
2644 eq_(res[18] >> 1, ofproto.OFPXMT_OFB_ETH_TYPE)
2645 eq_(res[18] & 0b0001, 0)
2646 eq_(res[19], calcsize(MTEthType.pack_str))
2647 eq_(res[20], dl_type)
2649 # insts (type, length, table_id)
2650 for i in range(inst_cnt):
2652 eq_(res[index], ofproto.OFPIT_GOTO_TABLE)
2653 eq_(res[index + 1], ofproto.OFP_INSTRUCTION_GOTO_TABLE_SIZE)
2654 eq_(res[index + 2], i)
2656 def test_serialize_mid(self):
2657 cookie = 2127614848199081640
2658 cookie_mask = 2127614848199081641
2661 idle_timeout = 62317
2664 buffer_id = 4037115955
2669 self._test_serialize(cookie, cookie_mask, table_id,
2670 command, idle_timeout, hard_timeout,
2671 priority, buffer_id, out_port,
2672 out_group, flags, inst_cnt)
2674 def test_serialize_max(self):
2675 cookie = 18446744073709551615
2676 cookie_mask = 18446744073709551615
2679 idle_timeout = 65535
2680 hard_timeout = 65535
2682 buffer_id = 0xffffffff
2683 out_port = 0xffffffff
2684 out_group = 0xffffffff
2687 self._test_serialize(cookie, cookie_mask, table_id,
2688 command, idle_timeout, hard_timeout,
2689 priority, buffer_id, out_port,
2690 out_group, flags, inst_cnt)
2692 def test_serialize_min(self):
2696 command = ofproto.OFPFC_ADD
2704 self._test_serialize(cookie, cookie_mask, table_id,
2705 command, idle_timeout, hard_timeout,
2706 priority, buffer_id, out_port,
2709 def test_serialize_p1(self):
2710 cookie = 2127614848199081640
2711 cookie_mask = 2127614848199081641
2714 idle_timeout = 62317
2717 buffer_id = 4037115955
2721 self._test_serialize(cookie, cookie_mask, table_id,
2722 command, idle_timeout, hard_timeout,
2723 priority, buffer_id, out_port,
2726 def test_serialize_p2(self):
2727 cookie = 2127614848199081640
2728 cookie_mask = 2127614848199081641
2731 idle_timeout = 62317
2734 buffer_id = 4037115955
2738 self._test_serialize(cookie, cookie_mask, table_id,
2739 command, idle_timeout, hard_timeout,
2740 priority, buffer_id, out_port,
2743 def test_serialize_p3(self):
2744 cookie = 2127614848199081640
2745 cookie_mask = 2127614848199081641
2748 idle_timeout = 62317
2751 buffer_id = 4037115955
2755 self._test_serialize(cookie, cookie_mask, table_id,
2756 command, idle_timeout, hard_timeout,
2757 priority, buffer_id, out_port,
2760 def test_serialize_p4(self):
2761 cookie = 2127614848199081640
2762 cookie_mask = 2127614848199081641
2765 idle_timeout = 62317
2768 buffer_id = 4037115955
2772 self._test_serialize(cookie, cookie_mask, table_id,
2773 command, idle_timeout, hard_timeout,
2774 priority, buffer_id, out_port,
2778 class TestOFPInstructionGotoTable(unittest.TestCase):
2779 """ Test case for ofproto_v1_2_parser.OFPInstructionGotoTable
2782 # OFP_INSTRUCTION_GOTO_TABLE_PACK_STR
2783 # '!HHB3x'...type, len, table_id, pad(3)
2784 type_ = ofproto.OFPIT_GOTO_TABLE
2785 len_ = ofproto.OFP_INSTRUCTION_GOTO_TABLE_SIZE
2787 fmt = ofproto.OFP_INSTRUCTION_GOTO_TABLE_PACK_STR
2789 def test_init(self):
2791 c = OFPInstructionGotoTable(table_id)
2793 eq_(self.type_, c.type)
2794 eq_(self.len_, c.len)
2795 eq_(table_id, c.table_id)
2797 def _test_parser(self, table_id):
2798 buf = pack(self.fmt, self.type_, self.len_, table_id)
2799 res = OFPInstructionGotoTable.parser(buf, 0)
2801 eq_(res.len, self.len_)
2802 eq_(res.type, self.type_)
2803 eq_(res.table_id, table_id)
2805 def test_parser_mid(self):
2806 self._test_parser(3)
2808 def test_parser_max(self):
2809 self._test_parser(255)
2811 def test_parser_min(self):
2812 self._test_parser(0)
2814 def _test_serialize(self, table_id):
2815 c = OFPInstructionGotoTable(table_id)
2820 res = struct.unpack(self.fmt, six.binary_type(buf))
2821 eq_(res[0], self.type_)
2822 eq_(res[1], self.len_)
2823 eq_(res[2], table_id)
2825 def test_serialize_mid(self):
2826 self._test_serialize(3)
2828 def test_serialize_max(self):
2829 self._test_serialize(255)
2831 def test_serialize_min(self):
2832 self._test_serialize(0)
2835 class TestOFPInstructionWriteMetadata(unittest.TestCase):
2836 """ Test case for ofproto_v1_2_parser.OFPInstructionWriteMetadata
2839 # OFP_INSTRUCTION_WRITE_METADATA_PACK_STR
2840 # '!HH4xQQ'...type, len, pad(4), metadata, metadata_mask
2841 type_ = ofproto.OFPIT_WRITE_METADATA
2842 len_ = ofproto.OFP_INSTRUCTION_WRITE_METADATA_SIZE
2843 metadata = 0x1212121212121212
2844 metadata_mask = 0xff00ff00ff00ff00
2846 fmt = ofproto.OFP_INSTRUCTION_WRITE_METADATA_PACK_STR
2848 def test_init(self):
2849 c = OFPInstructionWriteMetadata(self.metadata,
2852 eq_(self.type_, c.type)
2853 eq_(self.len_, c.len)
2854 eq_(self.metadata, c.metadata)
2855 eq_(self.metadata_mask, c.metadata_mask)
2857 def _test_parser(self, metadata, metadata_mask):
2858 buf = pack(self.fmt, self.type_, self.len_,
2859 metadata, metadata_mask)
2861 res = OFPInstructionWriteMetadata.parser(buf, 0)
2862 eq_(res.len, self.len_)
2863 eq_(res.type, self.type_)
2864 eq_(res.metadata, metadata)
2865 eq_(res.metadata_mask, metadata_mask)
2867 def test_parser_metadata_mid(self):
2868 self._test_parser(self.metadata, self.metadata_mask)
2870 def test_parser_metadata_max(self):
2871 metadata = 0xffffffffffffffff
2872 self._test_parser(metadata, self.metadata_mask)
2874 def test_parser_metadata_min(self):
2876 self._test_parser(metadata, self.metadata_mask)
2878 def test_parser_metadata_mask_max(self):
2879 metadata_mask = 0xffffffffffffffff
2880 self._test_parser(self.metadata, metadata_mask)
2882 def test_parser_metadata_mask_min(self):
2884 self._test_parser(self.metadata, metadata_mask)
2886 def _test_serialize(self, metadata, metadata_mask):
2887 c = OFPInstructionWriteMetadata(metadata,
2893 res = struct.unpack(self.fmt, six.binary_type(buf))
2894 eq_(res[0], self.type_)
2895 eq_(res[1], self.len_)
2896 eq_(res[2], metadata)
2897 eq_(res[3], metadata_mask)
2899 def test_serialize_metadata_mid(self):
2900 self._test_serialize(self.metadata, self.metadata_mask)
2902 def test_serialize_metadata_max(self):
2903 metadata = 0xffffffffffffffff
2904 self._test_serialize(metadata, self.metadata_mask)
2906 def test_serialize_metadata_min(self):
2908 self._test_serialize(metadata, self.metadata_mask)
2910 def test_serialize_metadata_mask_max(self):
2911 metadata_mask = 0xffffffffffffffff
2912 self._test_serialize(self.metadata, metadata_mask)
2914 def test_serialize_metadata_mask_min(self):
2916 self._test_serialize(self.metadata, metadata_mask)
2919 class TestOFPInstructionActions(unittest.TestCase):
2920 """ Test case for ofproto_v1_2_parser.OFPInstructionActions
2922 # OFP_INSTRUCTION_ACTIONS_PACK_STR
2923 # '!HH4x'...type, len, pad(4)
2924 type_ = ofproto.OFPIT_WRITE_ACTIONS
2925 len_ = ofproto.OFP_INSTRUCTION_ACTIONS_SIZE \
2926 + ofproto.OFP_ACTION_OUTPUT_SIZE
2928 fmt = ofproto.OFP_INSTRUCTION_ACTIONS_PACK_STR
2929 buf = pack(fmt, type_, len_)
2931 # OFP_ACTION (OFP_ACTION_OUTPUT)
2933 max_len = ofproto.OFP_ACTION_OUTPUT_SIZE
2934 actions = [OFPActionOutput(port, max_len)]
2935 buf_actions = bytearray()
2936 actions[0].serialize(buf_actions, 0)
2938 buf += six.binary_type(buf_actions)
2940 def test_init(self):
2941 c = OFPInstructionActions(self.type_, self.actions)
2943 eq_(self.type_, c.type)
2944 eq_(self.actions, c.actions)
2946 def _test_parser(self, action_cnt):
2947 # OFP_INSTRUCTION_ACTIONS_PACK_STR
2948 # '!HH4x'...type, len, pad(4)
2949 len_ = ofproto.OFP_INSTRUCTION_ACTIONS_SIZE \
2950 + (ofproto.OFP_ACTION_OUTPUT_SIZE * action_cnt)
2952 fmt = ofproto.OFP_INSTRUCTION_ACTIONS_PACK_STR
2953 buf = pack(fmt, self.type_, len_)
2956 for a in range(action_cnt):
2957 # OFP_ACTION (OFP_ACTION_OUTPUT)
2959 action = OFPActionOutput(port, self.max_len)
2960 actions.append(action)
2961 buf_actions = bytearray()
2962 actions[a].serialize(buf_actions, 0)
2963 buf += six.binary_type(buf_actions)
2965 res = OFPInstructionActions.parser(buf, 0)
2969 eq_(res.type, self.type_)
2971 # 8 + 16 * action_cnt < 65535 byte
2972 # action_cnt <= 4095
2973 for a in range(action_cnt):
2974 eq_(res.actions[a].type, actions[a].type)
2975 eq_(res.actions[a].len, actions[a].len)
2976 eq_(res.actions[a].port, actions[a].port)
2977 eq_(res.actions[a].max_len, actions[a].max_len)
2979 def test_parser_mid(self):
2980 self._test_parser(2047)
2982 def test_parser_max(self):
2983 self._test_parser(4095)
2985 def test_parser_min(self):
2986 self._test_parser(0)
2988 def _test_serialize(self, action_cnt):
2989 # OFP_INSTRUCTION_ACTIONS_PACK_STR
2990 # '!HH4x'...type, len, pad(4)
2991 len_ = ofproto.OFP_INSTRUCTION_ACTIONS_SIZE \
2992 + (ofproto.OFP_ACTION_OUTPUT_SIZE * action_cnt)
2995 for a in range(action_cnt):
2996 # OFP_ACTION (OFP_ACTION_OUTPUT)
2998 action = OFPActionOutput(port, self.max_len)
2999 actions.append(action)
3001 c = OFPInstructionActions(self.type_, actions)
3007 + ofproto.OFP_INSTRUCTION_ACTIONS_PACK_STR.replace('!', '')
3009 for a in range(action_cnt):
3010 fmt += ofproto.OFP_ACTION_OUTPUT_PACK_STR.replace('!', '')
3011 res = struct.unpack(fmt, six.binary_type(buf))
3013 eq_(res[0], self.type_)
3016 for a in range(action_cnt):
3018 eq_(res[d], actions[a].type)
3019 eq_(res[d + 1], actions[a].len)
3020 eq_(res[d + 2], actions[a].port)
3021 eq_(res[d + 3], actions[a].max_len)
3023 def test_serialize_mid(self):
3024 self._test_serialize(2047)
3026 def test_serialize_max(self):
3027 self._test_serialize(4095)
3029 def test_serialize_min(self):
3030 self._test_serialize(0)
3033 class TestOFPActionHeader(unittest.TestCase):
3034 """ Test case for ofproto_v1_2_parser.OFPActionHeader
3037 def test_init(self):
3038 # OFP_ACTION_HEADER_PACK_STR
3039 # '!HH4x'...type, len, pad(4)
3040 type_ = ofproto.OFPAT_OUTPUT
3041 len_ = ofproto.OFP_ACTION_HEADER_SIZE
3043 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
3044 buf = pack(fmt, type_, len_)
3046 c = OFPActionHeader(type_, len_)
3051 def _test_serialize(self, type_, len_):
3052 # OFP_ACTION_HEADER_PACK_STR
3053 # '!HH4x'...type, len, pad(4)
3055 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
3056 buf = pack(fmt, type_, len_)
3058 c = OFPActionHeader(type_, len_)
3063 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
3064 res = struct.unpack(fmt, six.binary_type(buf))
3069 def test_serialize_mid(self):
3072 self._test_serialize(type_, len_)
3074 def test_serialize_max(self):
3077 self._test_serialize(type_, len_)
3079 def test_serialize_min(self):
3082 self._test_serialize(type_, len_)
3085 class TestOFPActionOutput(unittest.TestCase):
3086 """ Test case for ofproto_v1_2_parser.OFPActionOutput
3089 # OFP_ACTION_OUTPUT_PACK_STR
3090 # '!HHIH6x'...type, len, port, max_len, pad(6)
3091 type_ = ofproto.OFPAT_OUTPUT
3092 len_ = ofproto.OFP_ACTION_OUTPUT_SIZE
3094 def test_init(self):
3097 fmt = ofproto.OFP_ACTION_OUTPUT_PACK_STR
3098 c = OFPActionOutput(port, max_len)
3100 eq_(max_len, c.max_len)
3102 def _test_parser(self, port, max_len):
3103 fmt = ofproto.OFP_ACTION_OUTPUT_PACK_STR
3104 buf = pack(fmt, self.type_, self.len_, port, max_len)
3106 c = OFPActionOutput(port, max_len)
3108 res = c.parser(buf, 0)
3110 eq_(res.len, self.len_)
3111 eq_(res.type, self.type_)
3113 eq_(res.max_len, max_len)
3115 def test_parser_mid(self):
3118 self._test_parser(port, max_len)
3120 def test_parser_max(self):
3123 self._test_parser(port, max_len)
3125 def test_parser_min(self):
3128 self._test_parser(port, max_len)
3130 def test_parser_p1(self):
3133 self._test_parser(port, max_len)
3135 def _test_serialize(self, port, max_len):
3136 c = OFPActionOutput(port, max_len)
3141 fmt = ofproto.OFP_ACTION_OUTPUT_PACK_STR
3142 res = struct.unpack(fmt, six.binary_type(buf))
3143 eq_(res[0], self.type_)
3144 eq_(res[1], self.len_)
3146 eq_(res[3], max_len)
3148 def test_serialize_mid(self):
3151 self._test_serialize(port, max_len)
3153 def test_serialize_max(self):
3156 self._test_serialize(port, max_len)
3158 def test_serialize_min(self):
3161 self._test_serialize(port, max_len)
3163 def test_serialize_p1(self):
3166 self._test_serialize(port, max_len)
3169 class TestOFPActionGroup(unittest.TestCase):
3170 """ Test case for ofproto_v1_2_parser.OFPActionGroup
3173 # OFP_ACTION_GROUP_PACK_STR
3174 # '!HHI'...type, len, group_id
3175 type_ = ofproto.OFPAT_GROUP
3176 len_ = ofproto.OFP_ACTION_GROUP_SIZE
3179 fmt = ofproto.OFP_ACTION_GROUP_PACK_STR
3181 def test_init(self):
3182 c = OFPActionGroup(self.group_id)
3183 eq_(self.group_id, c.group_id)
3185 def _test_parser(self, group_id):
3186 buf = pack(self.fmt, self.type_, self.len_, group_id)
3188 res = OFPActionGroup.parser(buf, 0)
3189 eq_(res.len, self.len_)
3190 eq_(res.type, self.type_)
3191 eq_(res.group_id, group_id)
3193 def test_parser_mid(self):
3194 self._test_parser(self.group_id)
3196 def test_parser_max(self):
3197 self._test_parser(4294967295)
3199 def test_parser_min(self):
3200 self._test_parser(0)
3202 def _test_serialize(self, group_id):
3203 c = OFPActionGroup(group_id)
3208 res = struct.unpack(self.fmt, six.binary_type(buf))
3209 eq_(res[0], self.type_)
3210 eq_(res[1], self.len_)
3211 eq_(res[2], group_id)
3213 def test_serialize_mid(self):
3214 self._test_serialize(self.group_id)
3216 def test_serialize_max(self):
3217 self._test_serialize(4294967295)
3219 def test_serialize_min(self):
3220 self._test_serialize(0)
3223 class TestOFPActionSetQueue(unittest.TestCase):
3224 """ Test case for ofproto_v1_2_parser.OFPActionSetQueue
3227 # OFP_ACTION_SET_QUEUE_PACK_STR
3228 # '!HHI'...type, len, queue_id
3229 type_ = ofproto.OFPAT_SET_QUEUE
3230 len_ = ofproto.OFP_ACTION_SET_QUEUE_SIZE
3233 fmt = ofproto.OFP_ACTION_SET_QUEUE_PACK_STR
3235 def test_init(self):
3236 c = OFPActionSetQueue(self.queue_id)
3237 eq_(self.queue_id, c.queue_id)
3239 def _test_parser(self, queue_id):
3240 buf = pack(self.fmt, self.type_, self.len_, queue_id)
3242 res = OFPActionSetQueue.parser(buf, 0)
3243 eq_(res.len, self.len_)
3244 eq_(res.type, self.type_)
3245 eq_(res.queue_id, queue_id)
3247 def test_parser_mid(self):
3248 self._test_parser(self.queue_id)
3250 def test_parser_max(self):
3251 self._test_parser(4294967295)
3253 def test_parser_min(self):
3254 self._test_parser(0)
3256 def _test_serialize(self, queue_id):
3257 c = OFPActionSetQueue(queue_id)
3262 res = struct.unpack(self.fmt, six.binary_type(buf))
3263 eq_(res[0], self.type_)
3264 eq_(res[1], self.len_)
3265 eq_(res[2], queue_id)
3267 def test_serialize_mid(self):
3268 self._test_serialize(self.queue_id)
3270 def test_serialize_max(self):
3271 self._test_serialize(4294967295)
3273 def test_serialize_min(self):
3274 self._test_serialize(0)
3277 class TestOFPActionSetMplsTtl(unittest.TestCase):
3278 """ Test case for ofproto_v1_2_parser.OFPActionSetMplsTtl
3281 # OFP_ACTION_MPLS_TTL_PACK_STR
3282 # '!HHB3x'...type, len, mpls_ttl, pad(3)
3283 type_ = ofproto.OFPAT_SET_MPLS_TTL
3284 len_ = ofproto.OFP_ACTION_MPLS_TTL_SIZE
3287 fmt = ofproto.OFP_ACTION_MPLS_TTL_PACK_STR
3289 def test_init(self):
3290 c = OFPActionSetMplsTtl(self.mpls_ttl)
3291 eq_(self.mpls_ttl, c.mpls_ttl)
3293 def _test_parser(self, mpls_ttl):
3294 buf = pack(self.fmt, self.type_, self.len_, mpls_ttl)
3296 res = OFPActionSetMplsTtl.parser(buf, 0)
3297 eq_(res.len, self.len_)
3298 eq_(res.type, self.type_)
3299 eq_(res.mpls_ttl, mpls_ttl)
3301 def test_parser_mid(self):
3302 self._test_parser(self.mpls_ttl)
3304 def test_parser_max(self):
3305 self._test_parser(255)
3307 def test_parser_min(self):
3308 self._test_parser(0)
3310 def _test_serialize(self, mpls_ttl):
3311 c = OFPActionSetMplsTtl(mpls_ttl)
3316 res = struct.unpack(self.fmt, six.binary_type(buf))
3317 eq_(res[0], self.type_)
3318 eq_(res[1], self.len_)
3319 eq_(res[2], mpls_ttl)
3321 def test_serialize_mid(self):
3322 self._test_serialize(self.mpls_ttl)
3324 def test_serialize_max(self):
3325 self._test_serialize(255)
3327 def test_serialize_min(self):
3328 self._test_serialize(0)
3331 class TestOFPActionDecMplsTtl(unittest.TestCase):
3332 """ Test case for ofproto_v1_2_parser.OFPActionDecMplsTtl
3335 type_ = ofproto.OFPAT_DEC_MPLS_TTL
3336 len_ = ofproto.OFP_ACTION_MPLS_TTL_SIZE
3337 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
3338 buf = pack(fmt, type_, len_)
3339 c = OFPActionDecMplsTtl()
3341 def test_parser(self):
3342 res = self.c.parser(self.buf, 0)
3344 eq_(res.len, self.len_)
3345 eq_(res.type, self.type_)
3347 def test_serialize(self):
3349 self.c.serialize(buf, 0)
3351 res = struct.unpack(self.fmt, six.binary_type(buf))
3352 eq_(res[0], self.type_)
3353 eq_(res[1], self.len_)
3356 class TestOFPActionSetNwTtl(unittest.TestCase):
3357 """ Test case for ofproto_v1_2_parser.OFPActionSetNwTtl
3360 # OFP_ACTION_NW_TTL_PACK_STR
3361 # '!HHB3x'...type, len, nw_ttl, pad(3)
3362 type_ = ofproto.OFPAT_SET_NW_TTL
3363 len_ = ofproto.OFP_ACTION_NW_TTL_SIZE
3366 fmt = ofproto.OFP_ACTION_NW_TTL_PACK_STR
3368 def test_init(self):
3369 c = OFPActionSetNwTtl(self.nw_ttl)
3370 eq_(self.nw_ttl, c.nw_ttl)
3372 def _test_parser(self, nw_ttl):
3373 buf = pack(self.fmt, self.type_, self.len_, nw_ttl)
3375 res = OFPActionSetNwTtl.parser(buf, 0)
3376 eq_(res.type, self.type_)
3377 eq_(res.len, self.len_)
3378 eq_(res.nw_ttl, nw_ttl)
3380 def test_parser_mid(self):
3381 self._test_parser(self.nw_ttl)
3383 def test_parser_max(self):
3384 self._test_parser(255)
3386 def test_parser_min(self):
3387 self._test_parser(0)
3389 def _test_serialize(self, nw_ttl):
3390 c = OFPActionSetNwTtl(nw_ttl)
3395 res = struct.unpack(self.fmt, six.binary_type(buf))
3396 eq_(res[0], self.type_)
3397 eq_(res[1], self.len_)
3400 def test_serialize_mid(self):
3401 self._test_serialize(self.nw_ttl)
3403 def test_serialize_max(self):
3404 self._test_serialize(255)
3406 def test_serialize_min(self):
3407 self._test_serialize(0)
3410 class TestOFPActionDecNwTtl(unittest.TestCase):
3411 """ Test case for ofproto_v1_2_parser.OFPActionDecNwTtl
3414 type_ = ofproto.OFPAT_DEC_NW_TTL
3415 len_ = ofproto.OFP_ACTION_NW_TTL_SIZE
3416 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
3417 buf = pack(fmt, type_, len_)
3418 c = OFPActionDecNwTtl()
3420 def test_parser(self):
3421 res = self.c.parser(self.buf, 0)
3423 eq_(res.len, self.len_)
3424 eq_(res.type, self.type_)
3426 def test_serialize(self):
3428 self.c.serialize(buf, 0)
3430 res = struct.unpack(self.fmt, six.binary_type(buf))
3431 eq_(res[0], self.type_)
3432 eq_(res[1], self.len_)
3435 class TestOFPActionCopyTtlOut(unittest.TestCase):
3436 """ Test case for ofproto_v1_2_parser.OFPActionCopyTtlOut
3439 type_ = ofproto.OFPAT_COPY_TTL_OUT
3440 len_ = ofproto.OFP_ACTION_HEADER_SIZE
3441 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
3442 buf = pack(fmt, type_, len_)
3443 c = OFPActionCopyTtlOut()
3445 def test_parser(self):
3446 res = self.c.parser(self.buf, 0)
3447 eq_(res.len, self.len_)
3448 eq_(res.type, self.type_)
3450 def test_serialize(self):
3452 self.c.serialize(buf, 0)
3454 res = struct.unpack(self.fmt, six.binary_type(buf))
3455 eq_(res[0], self.type_)
3456 eq_(res[1], self.len_)
3459 class TestOFPActionCopyTtlIn(unittest.TestCase):
3460 """ Test case for ofproto_v1_2_parser.OFPActionCopyTtlIn
3463 # OFP_ACTION_HEADER_PACK_STR
3465 type_ = ofproto.OFPAT_COPY_TTL_IN
3466 len_ = ofproto.OFP_ACTION_HEADER_SIZE
3467 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
3468 buf = pack(fmt, type_, len_)
3469 c = OFPActionCopyTtlIn()
3471 def test_parser(self):
3472 res = self.c.parser(self.buf, 0)
3474 eq_(res.len, self.len_)
3475 eq_(res.type, self.type_)
3477 def test_serialize(self):
3479 self.c.serialize(buf, 0)
3481 res = struct.unpack(self.fmt, six.binary_type(buf))
3482 eq_(res[0], self.type_)
3483 eq_(res[1], self.len_)
3486 class TestOFPActionPushVlan(unittest.TestCase):
3487 """ Test case for ofproto_v1_2_parser.OFPActionPushVlan
3490 # OFP_ACTION_PUSH_PACK_STR
3491 # '!HHH2x'...type, len, ethertype, pad(2)
3492 type_ = ofproto.OFPAT_PUSH_VLAN
3493 len_ = ofproto.OFP_ACTION_PUSH_SIZE
3494 fmt = ofproto.OFP_ACTION_PUSH_PACK_STR
3496 def test_init(self):
3498 c = OFPActionPushVlan(ethertype)
3499 eq_(ethertype, c.ethertype)
3501 def _test_parser(self, ethertype):
3502 buf = pack(self.fmt, self.type_, self.len_, ethertype)
3504 res = OFPActionPushVlan.parser(buf, 0)
3505 eq_(res.type, self.type_)
3506 eq_(res.len, self.len_)
3507 eq_(res.ethertype, ethertype)
3509 def test_parser_mid(self):
3510 self._test_parser(0x8100)
3512 def test_parser_max(self):
3513 self._test_parser(0xffff)
3515 def test_parser_min(self):
3516 self._test_parser(0)
3518 def _test_serialize(self, ethertype):
3519 c = OFPActionPushVlan(ethertype)
3523 res = struct.unpack(self.fmt, six.binary_type(buf))
3524 eq_(res[0], self.type_)
3525 eq_(res[1], self.len_)
3526 eq_(res[2], ethertype)
3528 def test_serialize_mid(self):
3529 self._test_serialize(0x8100)
3531 def test_serialize_max(self):
3532 self._test_serialize(0xffff)
3534 def test_serialize_min(self):
3535 self._test_serialize(0)
3538 class TestOFPActionPushMpls(unittest.TestCase):
3539 """ Test case for ofproto_v1_2_parser.OFPActionPushMpls
3542 # OFP_ACTION_PUSH_PACK_STR
3543 # '!HHH2x'...type, len, ethertype, pad(2)
3544 type_ = ofproto.OFPAT_PUSH_MPLS
3545 len_ = ofproto.OFP_ACTION_PUSH_SIZE
3546 fmt = ofproto.OFP_ACTION_PUSH_PACK_STR
3548 def test_init(self):
3550 c = OFPActionPushMpls(ethertype)
3551 eq_(ethertype, c.ethertype)
3553 def _test_parser(self, ethertype):
3554 buf = pack(self.fmt, self.type_, self.len_, ethertype)
3556 res = OFPActionPushMpls.parser(buf, 0)
3557 eq_(res.type, self.type_)
3558 eq_(res.len, self.len_)
3559 eq_(res.ethertype, ethertype)
3561 def test_parser_mid(self):
3562 self._test_parser(0x8100)
3564 def test_parser_max(self):
3565 self._test_parser(0xffff)
3567 def test_parser_min(self):
3568 self._test_parser(0)
3570 def _test_serialize(self, ethertype):
3571 c = OFPActionPushMpls(ethertype)
3575 res = struct.unpack(self.fmt, six.binary_type(buf))
3576 eq_(res[0], self.type_)
3577 eq_(res[1], self.len_)
3578 eq_(res[2], ethertype)
3580 def test_serialize_mid(self):
3581 self._test_serialize(0x8100)
3583 def test_serialize_max(self):
3584 self._test_serialize(0xffff)
3586 def test_serialize_min(self):
3587 self._test_serialize(0)
3590 class TestOFPActionPopVlan(unittest.TestCase):
3591 """ Test case for ofproto_v1_2_parser.OFPActionPopVlan
3594 # OFP_ACTION_HEADER_PACK_STR
3596 type_ = ofproto.OFPAT_POP_VLAN
3597 len_ = ofproto.OFP_ACTION_HEADER_SIZE
3598 fmt = ofproto.OFP_ACTION_HEADER_PACK_STR
3599 buf = pack(fmt, type_, len_)
3600 c = OFPActionPopVlan()
3602 def test_parser(self):
3603 res = self.c.parser(self.buf, 0)
3604 eq_(self.type_, res.type)
3605 eq_(self.len_, res.len)
3607 def test_serialize(self):
3609 self.c.serialize(buf, 0)
3611 res = struct.unpack(self.fmt, six.binary_type(buf))
3612 eq_(res[0], self.type_)
3613 eq_(res[1], self.len_)
3616 class TestOFPActionPopMpls(unittest.TestCase):
3617 """ Test case for ofproto_v1_2_parser.OFPActionPopMpls
3620 # OFP_ACTION_POP_MPLS_PACK_STR
3621 # '!HHH2x'...type, len, ethertype, pad(2)
3622 type_ = ofproto.OFPAT_POP_MPLS
3623 len_ = ofproto.OFP_ACTION_POP_MPLS_SIZE
3624 fmt = ofproto.OFP_ACTION_POP_MPLS_PACK_STR
3626 def test_init(self):
3628 c = OFPActionPopMpls(ethertype)
3629 eq_(ethertype, c.ethertype)
3631 def _test_parser(self, ethertype):
3632 buf = pack(self.fmt, self.type_, self.len_, ethertype)
3634 res = OFPActionPopMpls.parser(buf, 0)
3635 eq_(res.type, self.type_)
3636 eq_(res.len, self.len_)
3637 eq_(res.ethertype, ethertype)
3639 def test_parser_mid(self):
3640 self._test_parser(0x8100)
3642 def test_parser_max(self):
3643 self._test_parser(0xffff)
3645 def test_parser_min(self):
3646 self._test_parser(0)
3648 def _test_serialize(self, ethertype):
3649 c = OFPActionPopMpls(ethertype)
3653 res = struct.unpack(self.fmt, six.binary_type(buf))
3654 eq_(res[0], self.type_)
3655 eq_(res[1], self.len_)
3656 eq_(res[2], ethertype)
3658 def test_serialize_mid(self):
3659 self._test_serialize(0x8100)
3661 def test_serialize_max(self):
3662 self._test_serialize(0xffff)
3664 def test_serialize_min(self):
3665 self._test_serialize(0)
3668 class TestOFPActionSetField(unittest.TestCase):
3669 """ Test case for ofproto_v1_2_parser.OFPActionSetField
3672 type_ = ofproto.OFPAT_SET_FIELD
3673 header = ofproto.OXM_OF_IN_PORT
3676 field = MTInPort(header, in_port)
3677 length = ofproto.OFP_ACTION_SET_FIELD_SIZE + field.oxm_len()
3678 len_ = utils.round_up(length, 8)
3681 buf = pack(fmt, type_, len_, header, in_port)
3683 c = OFPActionSetField(field)
3685 def test_init(self):
3686 eq_(self.field, self.c.field)
3688 def test_parser(self):
3689 res = self.c.parser(self.buf, 0)
3691 eq_(res.type, self.type_)
3692 eq_(res.len, self.len_)
3693 eq_(res.field.header, self.header)
3694 eq_(res.field.value, self.in_port)
3696 def test_serialize(self):
3698 self.c.serialize(buf, 0)
3700 res = struct.unpack(self.fmt, six.binary_type(buf))
3702 eq_(res[0], self.type_)
3703 eq_(res[1], self.len_)
3704 eq_(res[2], self.header)
3705 eq_(res[3], self.in_port)
3708 class TestOFPActionExperimenter(unittest.TestCase):
3709 """ Test case for ofproto_v1_2_parser.OFPActionExperimenter
3712 # OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR v1.2
3713 # '!HHI'...type, len, experimenter
3714 type_ = ofproto.OFPAT_EXPERIMENTER
3715 len_ = ofproto.OFP_ACTION_EXPERIMENTER_HEADER_SIZE
3716 fmt = ofproto.OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR
3718 def test_init(self):
3719 experimenter = 4294967295
3720 c = OFPActionExperimenter(experimenter)
3721 eq_(experimenter, c.experimenter)
3723 def _test_parser(self, experimenter):
3724 buf = pack(self.fmt, self.type_, self.len_, experimenter)
3726 res = OFPActionExperimenter.parser(buf, 0)
3727 eq_(res.type, self.type_)
3728 eq_(res.len, self.len_)
3729 eq_(res.experimenter, experimenter)
3731 def test_parser_mid(self):
3732 experimenter = 2147483648
3733 self._test_parser(experimenter)
3735 def test_parser_max(self):
3736 experimenter = 4294967295
3737 self._test_parser(experimenter)
3739 def test_parser_min(self):
3741 self._test_parser(experimenter)
3743 def _test_serialize(self, experimenter):
3744 c = OFPActionExperimenter(experimenter)
3749 res = struct.unpack(self.fmt, six.binary_type(buf))
3750 eq_(res[0], self.type_)
3751 eq_(res[1], self.len_)
3752 eq_(res[2], experimenter)
3754 def test_serialize_mid(self):
3755 experimenter = 2147483648
3756 self._test_serialize(experimenter)
3758 def test_serialize_max(self):
3759 experimenter = 4294967295
3760 self._test_serialize(experimenter)
3762 def test_serialize_min(self):
3764 self._test_serialize(experimenter)
3767 class TestOFPBucket(unittest.TestCase):
3768 """ Test case for ofproto_v1_2_parser.OFPBucket
3771 def test_init(self):
3772 # OFP_BUCKET_PACK_STR
3773 # '!HHII4x'...len, weight, watch_port, watch_group, pad(4)
3778 # OFP_ACTION (OFP_ACTION_OUTPUT)
3781 actions = [OFPActionOutput(port, max_len)]
3783 c = OFPBucket(weight, watch_port, watch_group, actions)
3784 eq_(weight, c.weight)
3785 eq_(watch_port, c.watch_port)
3786 eq_(watch_group, c.watch_group)
3787 eq_(1, len(c.actions))
3788 eq_(port, c.actions[0].port)
3789 eq_(max_len, c.actions[0].max_len)
3791 def _test_parser(self, weight, watch_port, watch_group, action_cnt):
3792 # OFP_BUCKET_PACK_STR
3793 # '!HHII4x'...len, weight, watch_port, watch_group, pad(4)
3794 len_ = ofproto.OFP_BUCKET_SIZE \
3795 + (ofproto.OFP_ACTION_OUTPUT_SIZE * action_cnt)
3797 fmt = ofproto.OFP_BUCKET_PACK_STR
3798 buf = pack(fmt, len_, weight, watch_port, watch_group)
3801 for a in range(action_cnt):
3802 # OFP_ACTION (OFP_ACTION_OUTPUT)
3804 max_len = ofproto.OFP_ACTION_OUTPUT_SIZE
3805 action = OFPActionOutput(port, max_len)
3806 actions.append(action)
3807 buf_actions = bytearray()
3808 actions[a].serialize(buf_actions, 0)
3809 buf += six.binary_type(buf_actions)
3811 res = OFPBucket.parser(buf, 0)
3814 eq_(weight, res.weight)
3815 eq_(watch_port, res.watch_port)
3816 eq_(watch_group, res.watch_group)
3818 # 16 + 16 * action_cnt < 65535 byte
3819 # action_cnt <= 4094
3820 for a in range(action_cnt):
3821 eq_(actions[a].type, res.actions[a].type)
3822 eq_(actions[a].len, res.actions[a].len)
3823 eq_(actions[a].port, res.actions[a].port)
3824 eq_(actions[a].max_len, res.actions[a].max_len)
3826 def test_parser_mid(self):
3831 self._test_parser(weight, watch_port,
3832 watch_group, action_cnt)
3834 def test_parser_max(self):
3836 watch_port = 4294967295
3837 watch_group = 4294967295
3839 self._test_parser(weight, watch_port,
3840 watch_group, action_cnt)
3842 def test_parser_min(self):
3847 self._test_parser(weight, watch_port,
3848 watch_group, action_cnt)
3850 def _test_serialize(self, weight, watch_port, watch_group,
3852 # OFP_BUCKET_PACK_STR
3853 # '!HHII4x'...len, weight, watch_port, watch_group, pad(4)
3854 len_ = ofproto.OFP_BUCKET_SIZE \
3855 + (ofproto.OFP_ACTION_OUTPUT_SIZE * action_cnt)
3858 for a in range(action_cnt):
3859 # OFP_ACTION (OFP_ACTION_OUTPUT)
3861 max_len = ofproto.OFP_ACTION_OUTPUT_SIZE
3862 action = OFPActionOutput(port, max_len)
3863 actions.append(action)
3865 c = OFPBucket(weight, watch_port, watch_group, actions)
3870 fmt = ofproto.OFP_BUCKET_PACK_STR
3871 for a in range(action_cnt):
3872 fmt += ofproto.OFP_ACTION_OUTPUT_PACK_STR[1:]
3873 res = struct.unpack(fmt, six.binary_type(buf))
3877 eq_(res[2], watch_port)
3878 eq_(res[3], watch_group)
3880 for a in range(action_cnt):
3882 eq_(res[d], actions[a].type)
3883 eq_(res[d + 1], actions[a].len)
3884 eq_(res[d + 2], actions[a].port)
3885 eq_(res[d + 3], actions[a].max_len)
3887 def test_serialize_mid(self):
3892 self._test_serialize(weight, watch_port,
3893 watch_group, action_cnt)
3895 def test_serialize_max(self):
3897 watch_port = 4294967295
3898 watch_group = 4294967295
3900 self._test_serialize(weight, watch_port,
3901 watch_group, action_cnt)
3903 def test_serialize_min(self):
3908 self._test_serialize(weight, watch_port,
3909 watch_group, action_cnt)
3912 class TestOFPGroupMod(unittest.TestCase):
3913 """ Test case for ofproto_v1_2_parser.OFPGroupMod
3916 def test_init(self):
3917 # OFP_GROUP_MOD_PACK_STR
3918 # '!HBBI'...command, type, pad, group_id
3919 command = ofproto.OFPFC_ADD
3920 type_ = ofproto.OFPGT_SELECT
3928 # OFP_ACTION (OFP_ACTION_OUTPUT)
3931 actions = [OFPActionOutput(port, max_len)]
3933 buckets = [OFPBucket(weight, watch_port, watch_group, actions)]
3935 c = OFPGroupMod(_Datapath, command, type_, group_id, buckets)
3936 eq_(command, c.command)
3938 eq_(group_id, c.group_id)
3939 eq_(1, len(c.buckets))
3940 eq_(1, len(c.buckets[0].actions))
3941 eq_(port, c.buckets[0].actions[0].port)
3942 eq_(max_len, c.buckets[0].actions[0].max_len)
3944 def _test_serialize(self, command, type_, group_id, bucket_cnt):
3945 len_ = ofproto.OFP_BUCKET_SIZE \
3946 + ofproto.OFP_ACTION_OUTPUT_SIZE
3949 for b in range(bucket_cnt):
3951 weight = watch_port = watch_group = port = b
3952 actions = [OFPActionOutput(port, 0)]
3953 bucket = OFPBucket(weight, watch_port, watch_group, actions)
3954 buckets.append(bucket)
3956 c = OFPGroupMod(_Datapath, command, type_, group_id, buckets)
3960 eq_(ofproto.OFP_VERSION, c.version)
3961 eq_(ofproto.OFPT_GROUP_MOD, c.msg_type)
3963 eq_(len(c.buf), c.msg_len)
3966 fmt = ofproto.OFP_HEADER_PACK_STR \
3967 + ofproto.OFP_GROUP_MOD_PACK_STR[1:]
3969 # 16 + (16 + 16) * bucket_cnt < 65535 byte
3970 # bucket_cnt <= 2047
3971 for b in range(bucket_cnt):
3972 fmt += ofproto.OFP_BUCKET_PACK_STR[1:] \
3973 + ofproto.OFP_ACTION_OUTPUT_PACK_STR[1:]
3975 res = struct.unpack(fmt, six.binary_type(c.buf))
3977 msg_len = ofproto.OFP_GROUP_MOD_SIZE \
3978 + (len_ * bucket_cnt)
3980 eq_(res[0], ofproto.OFP_VERSION)
3981 eq_(res[1], ofproto.OFPT_GROUP_MOD)
3982 eq_(res[2], msg_len)
3984 eq_(res[4], command)
3986 eq_(res[6], group_id)
3988 for d in range(bucket_cnt):
3990 eq_(res[e + 1], buckets[d].weight)
3991 eq_(res[e + 2], buckets[d].watch_port)
3992 eq_(res[e + 3], buckets[d].watch_group)
3993 eq_(res[e + 4], buckets[d].actions[0].type)
3994 eq_(res[e + 5], buckets[d].actions[0].len)
3995 eq_(res[e + 6], buckets[d].actions[0].port)
3996 eq_(res[e + 7], buckets[d].actions[0].max_len)
3998 def test_serialize_mid(self):
4003 self._test_serialize(command, type_, group_id, bucket_cnt)
4005 def test_serialize_max(self):
4008 group_id = 4294967295
4010 self._test_serialize(command, type_, group_id, bucket_cnt)
4012 def test_serialize_min(self):
4017 self._test_serialize(command, type_, group_id, bucket_cnt)
4019 def test_serialize_p1(self):
4024 self._test_serialize(command, type_, group_id, bucket_cnt)
4026 def test_serialize_p2(self):
4031 self._test_serialize(command, type_, group_id, bucket_cnt)
4033 def test_serialize_p3(self):
4038 self._test_serialize(command, type_, group_id, bucket_cnt)
4041 class TestOFPPortMod(unittest.TestCase):
4042 """ Test case for ofproto_v1_2_parser.OFPPortMod
4045 # OFP_PORT_MOD_PACK_STR v1.2
4046 # '!I4xs2xIII4x'...port_no, pad(4), hw_addr, pad(2),
4047 # config, mask, advertise, pad(4)
4048 port_no = 1119692796
4049 hw_addr = 'e8:fe:5e:a9:68:6c'
4052 advertise = 2025421682
4054 def test_init(self):
4055 c = OFPPortMod(_Datapath, self.port_no, self.hw_addr,
4056 self.config, self.mask, self.advertise)
4057 eq_(self.port_no, c.port_no)
4058 eq_(self.hw_addr, c.hw_addr)
4059 eq_(self.config, c.config)
4060 eq_(self.mask, c.mask)
4061 eq_(self.advertise, c.advertise)
4063 def _test_serialize(self, port_no, hw_addr, config, mask, advertise):
4064 c = OFPPortMod(_Datapath, port_no, hw_addr, config,
4068 eq_(ofproto.OFP_VERSION, c.version)
4069 eq_(ofproto.OFPT_PORT_MOD, c.msg_type)
4073 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
4074 + ofproto.OFP_PORT_MOD_PACK_STR.replace('!', '')
4076 res = struct.unpack(fmt, six.binary_type(c.buf))
4078 eq_(res[0], ofproto.OFP_VERSION)
4079 eq_(res[1], ofproto.OFPT_PORT_MOD)
4080 eq_(res[2], len(c.buf))
4082 eq_(res[4], port_no)
4083 eq_(res[5], addrconv.mac.text_to_bin(hw_addr))
4086 eq_(res[8], advertise)
4088 def test_serialize_mid(self):
4089 self._test_serialize(self.port_no, self.hw_addr,
4090 self.config, self.mask, self.advertise)
4092 def test_serialize_max(self):
4093 port_no = ofproto.OFPP_ANY
4094 hw_addr = 'ff:ff:ff:ff:ff:ff'
4097 advertise = 0xffffffff
4098 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4100 def test_serialize_min(self):
4102 hw_addr = '00:00:00:00:00:00'
4106 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4108 def test_serialize_p1(self):
4109 port_no = ofproto.OFPP_MAX
4110 hw_addr = self.hw_addr
4111 config = ofproto.OFPPC_PORT_DOWN
4112 mask = ofproto.OFPPC_PORT_DOWN
4113 advertise = ofproto.OFPPF_10MB_HD
4114 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4116 def test_serialize_p2(self):
4117 port_no = ofproto.OFPP_IN_PORT
4118 hw_addr = self.hw_addr
4119 config = ofproto.OFPPC_NO_RECV
4120 mask = ofproto.OFPPC_NO_RECV
4121 advertise = ofproto.OFPPF_10MB_FD
4122 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4124 def test_serialize_p3(self):
4125 port_no = ofproto.OFPP_TABLE
4126 hw_addr = self.hw_addr
4127 config = ofproto.OFPPC_NO_FWD
4128 mask = ofproto.OFPPC_NO_FWD
4129 advertise = ofproto.OFPPF_100MB_HD
4130 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4132 def test_serialize_p4(self):
4133 port_no = ofproto.OFPP_NORMAL
4134 hw_addr = self.hw_addr
4135 config = ofproto.OFPPC_NO_PACKET_IN
4136 mask = ofproto.OFPPC_NO_PACKET_IN
4137 advertise = ofproto.OFPPF_100MB_FD
4138 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4140 def test_serialize_p5(self):
4141 port_no = ofproto.OFPP_FLOOD
4142 hw_addr = self.hw_addr
4143 config = ofproto.OFPPC_NO_PACKET_IN
4144 mask = ofproto.OFPPC_NO_PACKET_IN
4145 advertise = ofproto.OFPPF_1GB_HD
4146 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4148 def test_serialize_p6(self):
4149 port_no = ofproto.OFPP_ALL
4150 hw_addr = self.hw_addr
4151 config = ofproto.OFPPC_NO_PACKET_IN
4152 mask = ofproto.OFPPC_NO_PACKET_IN
4153 advertise = ofproto.OFPPF_1GB_FD
4154 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4156 def test_serialize_p7(self):
4157 port_no = ofproto.OFPP_CONTROLLER
4158 hw_addr = self.hw_addr
4159 config = ofproto.OFPPC_NO_PACKET_IN
4160 mask = ofproto.OFPPC_NO_PACKET_IN
4161 advertise = ofproto.OFPPF_10GB_FD
4162 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4164 def test_serialize_p8(self):
4165 port_no = ofproto.OFPP_LOCAL
4166 hw_addr = self.hw_addr
4167 config = ofproto.OFPPC_NO_PACKET_IN
4168 mask = ofproto.OFPPC_NO_PACKET_IN
4169 advertise = ofproto.OFPPF_40GB_FD
4170 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4172 def test_serialize_p9(self):
4173 port_no = ofproto.OFPP_LOCAL
4174 hw_addr = self.hw_addr
4175 config = ofproto.OFPPC_NO_PACKET_IN
4176 mask = ofproto.OFPPC_NO_PACKET_IN
4177 advertise = ofproto.OFPPF_100GB_FD
4178 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4180 def test_serialize_p10(self):
4181 port_no = ofproto.OFPP_LOCAL
4182 hw_addr = self.hw_addr
4183 config = ofproto.OFPPC_NO_PACKET_IN
4184 mask = ofproto.OFPPC_NO_PACKET_IN
4185 advertise = ofproto.OFPPF_1TB_FD
4186 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4188 def test_serialize_p11(self):
4189 port_no = ofproto.OFPP_LOCAL
4190 hw_addr = self.hw_addr
4191 config = ofproto.OFPPC_NO_PACKET_IN
4192 mask = ofproto.OFPPC_NO_PACKET_IN
4193 advertise = ofproto.OFPPF_OTHER
4194 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4196 def test_serialize_p12(self):
4197 port_no = ofproto.OFPP_LOCAL
4198 hw_addr = self.hw_addr
4199 config = ofproto.OFPPC_NO_PACKET_IN
4200 mask = ofproto.OFPPC_NO_PACKET_IN
4201 advertise = ofproto.OFPPF_COPPER
4202 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4204 def test_serialize_p13(self):
4205 port_no = ofproto.OFPP_LOCAL
4206 hw_addr = self.hw_addr
4207 config = ofproto.OFPPC_NO_PACKET_IN
4208 mask = ofproto.OFPPC_NO_PACKET_IN
4209 advertise = ofproto.OFPPF_FIBER
4210 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4212 def test_serialize_p14(self):
4213 port_no = ofproto.OFPP_LOCAL
4214 hw_addr = self.hw_addr
4215 config = ofproto.OFPPC_NO_PACKET_IN
4216 mask = ofproto.OFPPC_NO_PACKET_IN
4217 advertise = ofproto.OFPPF_AUTONEG
4218 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4220 def test_serialize_p15(self):
4221 port_no = ofproto.OFPP_LOCAL
4222 hw_addr = self.hw_addr
4223 config = ofproto.OFPPC_NO_PACKET_IN
4224 mask = ofproto.OFPPC_NO_PACKET_IN
4225 advertise = ofproto.OFPPF_PAUSE
4226 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4228 def test_serialize_p16(self):
4229 port_no = ofproto.OFPP_LOCAL
4230 hw_addr = self.hw_addr
4231 config = ofproto.OFPPC_NO_PACKET_IN
4232 mask = ofproto.OFPPC_NO_PACKET_IN
4233 advertise = ofproto.OFPPF_PAUSE_ASYM
4234 self._test_serialize(port_no, hw_addr, config, mask, advertise)
4237 class TestOFPTableMod(unittest.TestCase):
4238 """ Test case for ofproto_v1_2_parser.OFPTableMod
4241 # OFP_PORT_TABLE_PACK_STR v1.2
4242 # '!B3xI'...table_id, pad(3), config
4246 def test_init(self):
4247 c = OFPTableMod(_Datapath, self.table_id, self.config)
4248 eq_(self.table_id, c.table_id)
4249 eq_(self.config, c.config)
4251 def _test_serialize(self, table_id, config):
4252 c = OFPTableMod(_Datapath, table_id, config)
4255 eq_(ofproto.OFP_VERSION, c.version)
4256 eq_(ofproto.OFPT_TABLE_MOD, c.msg_type)
4260 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
4261 + ofproto.OFP_TABLE_MOD_PACK_STR.replace('!', '')
4263 res = struct.unpack(fmt, six.binary_type(c.buf))
4265 eq_(res[0], ofproto.OFP_VERSION)
4266 eq_(res[1], ofproto.OFPT_TABLE_MOD)
4267 eq_(res[2], len(c.buf))
4269 eq_(res[4], table_id)
4272 def test_serialize_mid(self):
4273 self._test_serialize(self.table_id, self.config)
4275 def test_serialize_max(self):
4276 table_id = ofproto.OFPTT_ALL
4278 self._test_serialize(table_id, config)
4280 def test_serialize_min(self):
4283 self._test_serialize(table_id, config)
4285 def test_serialize_p1(self):
4286 table_id = ofproto.OFPTT_MAX
4287 config = ofproto.OFPTC_TABLE_MISS_CONTINUE
4288 self._test_serialize(table_id, config)
4290 def test_serialize_p2(self):
4291 table_id = ofproto.OFPTT_MAX
4292 config = ofproto.OFPTC_TABLE_MISS_DROP
4293 self._test_serialize(table_id, config)
4295 def test_serialize_p3(self):
4296 table_id = ofproto.OFPTT_MAX
4297 config = ofproto.OFPTC_TABLE_MISS_MASK
4298 self._test_serialize(table_id, config)
4301 class TestOFPStatsRequest(unittest.TestCase):
4302 """ Test case for ofproto_v1_2_parser.OFPStatsRequest
4305 type_ = ofproto.OFPST_DESC
4306 c = OFPStatsRequest(_Datapath, type_)
4308 def test_init(self):
4309 eq_(self.type_, self.c.type)
4310 eq_(0, self.c.flags)
4312 def test_serialize_body(self):
4313 len_ = ofproto.OFP_HEADER_SIZE \
4314 + ofproto.OFP_STATS_REQUEST_SIZE
4315 self.c.buf = bytearray(len_)
4316 self.c._serialize_body()
4318 fmt = ofproto.OFP_STATS_REQUEST_PACK_STR
4319 res = struct.unpack_from(fmt, six.binary_type(self.c.buf),
4320 ofproto.OFP_HEADER_SIZE)
4322 eq_(res[0], self.type_)
4326 class TestOFPStatsReply(unittest.TestCase):
4327 """ Test case for ofproto_v1_2_parser.OFPStatsReply
4330 c = OFPStatsReply(_Datapath)
4332 def test_parser_single_struct_true(self):
4333 # OFP_HEADER_PACK_STR
4334 # '!BBHI'...version, msg_type, msg_len, xid
4335 version = ofproto.OFP_VERSION
4336 msg_type = ofproto.OFPT_STATS_REPLY
4337 msg_len = ofproto.OFP_STATS_REPLY_SIZE \
4338 + ofproto.OFP_AGGREGATE_STATS_REPLY_SIZE
4341 fmt = ofproto.OFP_HEADER_PACK_STR
4342 buf = pack(fmt, version, msg_type, msg_len, xid)
4344 # OFP_STATS_REPLY_PACK_STR
4345 # '!HH4x'...type, flags, pad(4)
4346 type_ = ofproto.OFPST_AGGREGATE
4349 fmt = ofproto.OFP_STATS_REPLY_PACK_STR
4350 buf += pack(fmt, type_, flags)
4352 # OFP_AGGREGATE_STATS_REPLY_PACK_STR
4353 packet_count = 5142202600015232219
4354 byte_count = 2659740543924820419
4355 flow_count = 1344694860
4356 body = OFPAggregateStatsReply(packet_count, byte_count, flow_count)
4358 fmt = ofproto.OFP_AGGREGATE_STATS_REPLY_PACK_STR
4359 buf += pack(fmt, packet_count, byte_count, flow_count)
4361 res = self.c.parser(object, version, msg_type, msg_len, xid, buf)
4363 eq_(version, res.version)
4364 eq_(msg_type, res.msg_type)
4365 eq_(msg_len, res.msg_len)
4367 eq_(type_, res.type)
4368 eq_(flags, res.flags)
4369 eq_(packet_count, res.body.packet_count)
4370 eq_(byte_count, res.body.byte_count)
4371 eq_(flow_count, res.body.flow_count)
4373 def test_parser_single_struct_flase(self):
4374 # OFP_HEADER_PACK_STR
4375 # '!BBHI'...version, msg_type, msg_len, xid
4376 version = ofproto.OFP_VERSION
4377 msg_type = ofproto.OFPT_STATS_REPLY
4378 msg_len = ofproto.OFP_STATS_REPLY_SIZE \
4379 + ofproto.OFP_QUEUE_STATS_SIZE
4382 fmt = ofproto.OFP_HEADER_PACK_STR
4383 buf = pack(fmt, version, msg_type, msg_len, xid)
4385 # OFP_STATS_REPLY_PACK_STR
4386 # '!HH4x'...type, flags, pad(4)
4387 type_ = ofproto.OFPST_QUEUE
4390 fmt = ofproto.OFP_STATS_REPLY_PACK_STR
4391 buf += pack(fmt, type_, flags)
4393 # OFP_QUEUE_STATS_PACK_STR
4396 tx_bytes = 8638420181865882538
4397 tx_packets = 2856480458895760962
4398 tx_errors = 6283093430376743019
4399 body = [OFPQueueStats(port_no, queue_id, tx_bytes, tx_packets,
4402 fmt = ofproto.OFP_QUEUE_STATS_PACK_STR
4403 buf += pack(fmt, port_no, queue_id, tx_bytes, tx_packets, tx_errors)
4405 res = self.c.parser(object, version, msg_type, msg_len, xid, buf)
4407 eq_(version, res.version)
4408 eq_(msg_type, res.msg_type)
4409 eq_(msg_len, res.msg_len)
4411 eq_(type_, res.type)
4412 eq_(flags, res.flags)
4413 eq_(port_no, res.body[0].port_no)
4414 eq_(queue_id, res.body[0].queue_id)
4415 eq_(tx_bytes, res.body[0].tx_bytes)
4416 eq_(tx_packets, res.body[0].tx_packets)
4417 eq_(tx_errors, res.body[0].tx_errors)
4419 def test_parser_max(self):
4420 # OFP_HEADER_PACK_STR
4421 # '!BBHI'...version, msg_type, msg_len, xid
4422 version = ofproto.OFP_VERSION
4423 msg_type = ofproto.OFPT_STATS_REPLY
4424 msg_len = ofproto.OFP_STATS_REPLY_SIZE
4427 fmt = ofproto.OFP_HEADER_PACK_STR
4428 buf = pack(fmt, version, msg_type, msg_len, xid)
4430 # OFP_STATS_REPLY_PACK_STR
4431 # '!HH4x'...type, flags, pad(4)
4432 type_ = ofproto.OFPST_QUEUE
4435 fmt = ofproto.OFP_STATS_REPLY_PACK_STR
4436 buf += pack(fmt, type_, flags)
4437 res = self.c.parser(object, version, msg_type, msg_len, xid, buf)
4439 eq_(version, res.version)
4440 eq_(msg_type, res.msg_type)
4441 eq_(msg_len, res.msg_len)
4443 eq_(type_, res.type)
4444 eq_(flags, res.flags)
4446 def test_parser_min(self):
4447 # OFP_HEADER_PACK_STR
4448 # '!BBHI'...version, msg_type, msg_len, xid
4449 version = ofproto.OFP_VERSION
4450 msg_type = ofproto.OFPT_STATS_REPLY
4451 msg_len = ofproto.OFP_STATS_REPLY_SIZE
4454 fmt = ofproto.OFP_HEADER_PACK_STR
4455 buf = pack(fmt, version, msg_type, msg_len, xid)
4457 # OFP_STATS_REPLY_PACK_STR
4458 # '!HH4x'...type, flags, pad(4)
4459 type_ = ofproto.OFPST_QUEUE
4462 fmt = ofproto.OFP_STATS_REPLY_PACK_STR
4463 buf += pack(fmt, type_, flags)
4464 res = self.c.parser(object, version, msg_type, msg_len, xid, buf)
4466 eq_(version, res.version)
4467 eq_(msg_type, res.msg_type)
4468 eq_(msg_len, res.msg_len)
4470 eq_(type_, res.type)
4471 eq_(flags, res.flags)
4474 class TestOFPDescStatsRequest(unittest.TestCase):
4475 """ Test case for ofproto_v1_2_parser.OFPDescStatsRequest
4478 def test_serialize(self):
4479 c = OFPDescStatsRequest(_Datapath)
4483 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
4484 + ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '')
4486 res = struct.unpack(fmt, six.binary_type(c.buf))
4488 eq_(res[0], ofproto.OFP_VERSION)
4489 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
4490 eq_(res[2], len(c.buf))
4492 eq_(res[4], ofproto.OFPST_DESC)
4496 class TestOFPDescStats(unittest.TestCase):
4497 """ Test case for ofproto_v1_2_parser.OFPDescStats
4500 # OFP_DESC_STATS_PACK_STR
4501 # '!256s256s256s32s256s'...mfr_desc, hw_desc, sw_desc, serial_num, dp_desc
4502 mfr_desc = b'mfr_desc'.ljust(256)
4503 hw_desc = b'hw_desc'.ljust(256)
4504 sw_desc = b'sw_desc'.ljust(256)
4505 serial_num = b'serial_num'.ljust(32)
4506 dp_desc = b'dp_desc'.ljust(256)
4514 c = OFPDescStats(mfr_desc, hw_desc, sw_desc, serial_num, dp_desc)
4516 def test_init(self):
4517 eq_(self.mfr_desc, self.c.mfr_desc)
4518 eq_(self.hw_desc, self.c.hw_desc)
4519 eq_(self.sw_desc, self.c.sw_desc)
4520 eq_(self.serial_num, self.c.serial_num)
4521 eq_(self.dp_desc, self.c.dp_desc)
4523 def test_parser(self):
4524 res = self.c.parser(self.buf, 0)
4526 eq_(self.mfr_desc, res.mfr_desc)
4527 eq_(self.hw_desc, res.hw_desc)
4528 eq_(self.sw_desc, res.sw_desc)
4529 eq_(self.serial_num, res.serial_num)
4530 eq_(self.dp_desc, res.dp_desc)
4533 class TestOFPFlowStatsRequest(unittest.TestCase):
4534 """ Test case for ofproto_v1_2_parser.OFPFlowStatsRequest
4537 # OFP_FLOW_STATS_REQUEST_PACK_STR
4538 # '!B3xII4xQQ'...table_id, pad(3), out_port, out_group, pad(4),
4539 # cookie, cookie_mask
4543 cookie = 2127614848199081640
4544 cookie_mask = 2127614848199081641
4546 def test_init(self):
4549 match.set_in_port(in_port)
4551 c = OFPFlowStatsRequest(_Datapath, self.table_id, self.out_port,
4552 self.out_group, self.cookie, self.cookie_mask,
4555 eq_(self.table_id, c.table_id)
4556 eq_(self.out_port, c.out_port)
4557 eq_(self.out_group, c.out_group)
4558 eq_(self.cookie, c.cookie)
4559 eq_(self.cookie_mask, c.cookie_mask)
4560 eq_(in_port, c.match._flow.in_port)
4562 def _test_serialize(self, table_id, out_port, out_group,
4563 cookie, cookie_mask):
4566 match.set_dl_type(dl_type)
4568 c = OFPFlowStatsRequest(_Datapath, table_id, out_port,
4569 out_group, cookie, cookie_mask, match)
4572 eq_(ofproto.OFP_VERSION, c.version)
4573 eq_(ofproto.OFPT_STATS_REQUEST, c.msg_type)
4576 fmt = ofproto.OFP_HEADER_PACK_STR \
4577 + ofproto.OFP_STATS_REQUEST_PACK_STR[1:] \
4578 + ofproto.OFP_FLOW_STATS_REQUEST_PACK_STR[1:] \
4580 + MTEthType.pack_str[1:] + '6x'
4582 res = struct.unpack(fmt, six.binary_type(c.buf))
4584 eq_(res[0], ofproto.OFP_VERSION)
4585 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
4586 size = ofproto.OFP_STATS_REPLY_SIZE \
4587 + ofproto.OFP_FLOW_STATS_REQUEST_SIZE \
4588 + calcsize(MTEthType.pack_str + '6x')
4591 eq_(res[4], ofproto.OFPST_FLOW)
4593 eq_(res[6], table_id)
4594 eq_(res[7], out_port)
4595 eq_(res[8], out_group)
4597 eq_(res[10], cookie_mask)
4599 eq_(res[11], ofproto.OFPMT_OXM)
4601 eq_(res[13], ofproto.OFPXMC_OPENFLOW_BASIC)
4602 eq_(res[14] >> 1, ofproto.OFPXMT_OFB_ETH_TYPE)
4603 eq_(res[14] & 0b0001, 0)
4604 eq_(res[15], calcsize(MTEthType.pack_str))
4605 eq_(res[16], dl_type)
4607 def test_serialize_mid(self):
4608 self._test_serialize(self.table_id, self.out_port, self.out_group,
4609 self.cookie, self.cookie_mask)
4611 def test_serialize_max(self):
4616 cookie_mask = 0xffffffff
4617 self._test_serialize(table_id, out_port, out_group,
4618 cookie, cookie_mask)
4620 def test_serialize_min(self):
4626 self._test_serialize(table_id, out_port, out_group,
4627 cookie, cookie_mask)
4629 def test_serialize_p1(self):
4630 table_id = ofproto.OFPTT_MAX
4631 self._test_serialize(table_id, self.out_port, self.out_group,
4632 self.cookie, self.cookie_mask)
4635 class TestOFPFlowStats(unittest.TestCase):
4636 """ Test case for ofproto_v1_2_parser.OFPFlowStats
4639 def test_init(self):
4640 length = ofproto.OFP_FLOW_STATS_SIZE
4642 duration_sec = 2484712402
4643 duration_nsec = 3999715196
4645 idle_timeout = 36368
4646 hard_timeout = 54425
4647 cookie = 793171083674290912
4648 packet_count = 5142202600015232219
4649 byte_count = 2659740543924820419
4653 match.set_in_port(in_port)
4656 instructions = [OFPInstructionGotoTable(goto_table)]
4657 c = OFPFlowStats(table_id, duration_sec, duration_nsec,
4658 priority, idle_timeout, hard_timeout, cookie,
4659 packet_count, byte_count, match, instructions)
4661 eq_(table_id, c.table_id)
4662 eq_(duration_sec, c.duration_sec)
4663 eq_(duration_nsec, c.duration_nsec)
4664 eq_(priority, c.priority)
4665 eq_(idle_timeout, c.idle_timeout)
4666 eq_(hard_timeout, c.hard_timeout)
4667 eq_(cookie, c.cookie)
4668 eq_(packet_count, c.packet_count)
4669 eq_(byte_count, c.byte_count)
4670 eq_(in_port, c.match._flow.in_port)
4671 eq_(goto_table, c.instructions[0].table_id)
4673 def _test_parser(self, table_id, duration_sec, duration_nsec,
4674 priority, idle_timeout, hard_timeout, cookie,
4675 packet_count, byte_count, inst_cnt=0):
4677 length = ofproto.OFP_FLOW_STATS_SIZE \
4678 + calcsize(MTEthType.pack_str[1:] + '6x') \
4679 + ofproto.OFP_INSTRUCTION_GOTO_TABLE_SIZE * inst_cnt
4681 # OFP_FLOW_STATS_PACK_STR
4682 buf = pack(ofproto.OFP_FLOW_STATS_PACK_STR,
4683 length, table_id, duration_sec, duration_nsec,
4684 priority, idle_timeout, hard_timeout, cookie,
4685 packet_count, byte_count)
4690 match.set_dl_type(dl_type)
4691 match_buf = bytearray()
4692 match.serialize(match_buf, 0)
4693 buf += six.binary_type(match_buf)
4696 # 56 + 8 + 8 * inst_cnt <= 65535
4698 for i in range(inst_cnt):
4699 inst = OFPInstructionGotoTable(1)
4700 inst_buf = bytearray()
4701 inst.serialize(inst_buf, 0)
4702 buf += six.binary_type(inst_buf)
4705 res = OFPFlowStats.parser(buf, 0)
4706 eq_(length, res.length)
4707 eq_(table_id, res.table_id)
4708 eq_(duration_sec, res.duration_sec)
4709 eq_(duration_nsec, res.duration_nsec)
4710 eq_(priority, res.priority)
4711 eq_(idle_timeout, res.idle_timeout)
4712 eq_(hard_timeout, res.hard_timeout)
4713 eq_(cookie, res.cookie)
4714 eq_(packet_count, res.packet_count)
4715 eq_(byte_count, res.byte_count)
4716 eq_(dl_type, res.match.fields[0].value)
4717 for i in range(inst_cnt):
4718 eq_(1, res.instructions[i].table_id)
4720 def test_parser_mid(self):
4722 duration_sec = 2484712402
4723 duration_nsec = 3999715196
4725 idle_timeout = 36368
4726 hard_timeout = 54425
4727 cookie = 793171083674290912
4728 packet_count = 5142202600015232219
4729 byte_count = 2659740543924820419
4732 self._test_parser(table_id, duration_sec, duration_nsec,
4733 priority, idle_timeout, hard_timeout, cookie,
4734 packet_count, byte_count, inst_cnt)
4736 def test_parser_max(self):
4738 duration_sec = 0xffff
4739 duration_nsec = 0xffff
4743 cookie = 0xffffffffffffffff
4744 packet_count = 0xffffffffffffffff
4745 byte_count = 0xffffffffffffffff
4748 self._test_parser(table_id, duration_sec, duration_nsec,
4749 priority, idle_timeout, hard_timeout, cookie,
4750 packet_count, byte_count, inst_cnt)
4752 def test_parser_min(self):
4753 self._test_parser(0, 0, 0, 0, 0, 0, 0, 0, 0)
4756 class TestOFPAggregateStatsRequest(unittest.TestCase):
4757 """ Test case for ofproto_v1_2_parser.OFPAggregateStatsRequest
4760 # OFP_AGGREGATE_STATS_REQUEST_PACK_STR
4761 # '!B3xII4xQQ'...table_id, pad(3), out_port, out_group, pad(4),
4762 # cookie, cookie_mask
4766 cookie = 2127614848199081640
4767 cookie_mask = 2127614848199081641
4769 def test_init(self):
4772 match.set_dl_type(dl_type)
4773 c = OFPAggregateStatsRequest(_Datapath, self.table_id,
4774 self.out_port, self.out_group,
4775 self.cookie, self.cookie_mask,
4778 eq_(self.table_id, c.table_id)
4779 eq_(self.out_port, c.out_port)
4780 eq_(self.out_group, c.out_group)
4781 eq_(self.cookie, c.cookie)
4782 eq_(self.cookie_mask, c.cookie_mask)
4783 eq_(dl_type, c.match._flow.dl_type)
4785 def _test_serialize(self, table_id, out_port, out_group,
4786 cookie, cookie_mask):
4789 match.set_dl_type(dl_type)
4790 c = OFPAggregateStatsRequest(_Datapath, table_id,
4791 out_port, out_group, cookie,
4795 eq_(ofproto.OFP_VERSION, c.version)
4796 eq_(ofproto.OFPT_STATS_REQUEST, c.msg_type)
4799 fmt = ofproto.OFP_HEADER_PACK_STR \
4800 + ofproto.OFP_STATS_REQUEST_PACK_STR[1:] \
4801 + ofproto.OFP_AGGREGATE_STATS_REQUEST_PACK_STR[1:] \
4803 + MTEthType.pack_str[1:] + '6x'
4805 res = struct.unpack(fmt, six.binary_type(c.buf))
4806 eq_(res[0], ofproto.OFP_VERSION)
4807 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
4808 eq_(res[2], len(c.buf))
4810 eq_(res[4], ofproto.OFPST_AGGREGATE)
4812 eq_(res[6], table_id)
4813 eq_(res[7], out_port)
4814 eq_(res[8], out_group)
4816 eq_(res[10], cookie_mask)
4818 eq_(res[11], ofproto.OFPMT_OXM)
4820 eq_(res[13], ofproto.OFPXMC_OPENFLOW_BASIC)
4821 eq_(res[14] >> 1, ofproto.OFPXMT_OFB_ETH_TYPE)
4822 eq_(res[14] & 0b0001, 0)
4823 eq_(res[15], calcsize(MTEthType.pack_str))
4824 eq_(res[16], dl_type)
4826 def test_serialize_mid(self):
4827 self._test_serialize(self.table_id, self.out_port, self.out_group,
4828 self.cookie, self.cookie_mask)
4830 def test_serialize_max(self):
4832 out_port = 0xffffffff
4833 out_group = 0xffffffff
4835 cookie_mask = 0xffffffff
4836 self._test_serialize(table_id, out_port, out_group,
4837 cookie, cookie_mask)
4839 def test_serialize_min(self):
4845 self._test_serialize(table_id, out_port, out_group,
4846 cookie, cookie_mask)
4848 def test_serialize_p1(self):
4849 table_id = ofproto.OFPTT_MAX
4850 self._test_serialize(table_id, self.out_port, self.out_group,
4851 self.cookie, self.cookie_mask)
4854 class TestOFPAggregateStatsReply(unittest.TestCase):
4855 """ Test case for ofproto_v1_2_parser.OFPAggregateStatsReply
4858 # OFP_AGGREGATE_STATS_REPLY_PACK_STR
4859 # '!QQI4x'...packet_count, byte_count, flow_count, pad(4)
4860 packet_count = 5142202600015232219
4861 byte_count = 2659740543924820419
4862 flow_count = 1344694860
4864 def test_init(self):
4865 c = OFPAggregateStatsReply(self.packet_count, self.byte_count,
4868 eq_(c.packet_count, self.packet_count)
4869 eq_(c.byte_count, self.byte_count)
4870 eq_(c.flow_count, self.flow_count)
4872 def _test_parser(self, packet_count, byte_count, flow_count):
4873 fmt = ofproto.OFP_AGGREGATE_STATS_REPLY_PACK_STR
4874 buf = pack(fmt, packet_count, byte_count, flow_count)
4876 res = OFPAggregateStatsReply.parser(buf, 0)
4877 eq_(packet_count, res.packet_count)
4878 eq_(byte_count, res.byte_count)
4879 eq_(flow_count, res.flow_count)
4881 def test_parser_mid(self):
4882 self._test_parser(self.packet_count, self.byte_count,
4885 def test_parser_max(self):
4886 packet_count = 18446744073709551615
4887 byte_count = 18446744073709551615
4888 flow_count = 4294967295
4889 self._test_parser(packet_count, byte_count,
4892 def test_parser_min(self):
4896 self._test_parser(packet_count, byte_count,
4900 class TestOFPTableStatsRequest(unittest.TestCase):
4901 """ Test case for ofproto_v1_2_parser.OFPTableStatsRequest
4904 def test_serialize(self):
4905 c = OFPTableStatsRequest(_Datapath)
4909 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
4910 + ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '')
4912 res = struct.unpack(fmt, six.binary_type(c.buf))
4914 eq_(res[0], ofproto.OFP_VERSION)
4915 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
4916 eq_(res[2], len(c.buf))
4918 eq_(res[4], ofproto.OFPST_TABLE)
4922 class TestOFPTableStats(unittest.TestCase):
4923 """ Test case for ofproto_v1_2_parser.OFPTableStats
4926 def test_init(self):
4929 match = 1270985291017894273
4930 wildcards = 3316608530
4931 write_actions = 2484712402
4932 apply_actions = 3999715196
4933 write_setfields = 5142202600015232219
4934 apply_setfields = 2659740543924820419
4935 metadata_match = 2127614848199081640
4936 metadata_write = 2127614848199081641
4937 instructions = 1119692796
4939 max_entries = 2506913869
4940 active_count = 2024581150
4941 lookup_count = 4620020561814017052
4942 matched_count = 2825167325263435621
4944 res = OFPTableStats(table_id, name, match, wildcards, write_actions,
4945 apply_actions, write_setfields, apply_setfields,
4946 metadata_match, metadata_write, instructions,
4947 config, max_entries, active_count, lookup_count,
4950 eq_(table_id, res.table_id)
4952 eq_(match, res.match)
4953 eq_(wildcards, res.wildcards)
4954 eq_(write_actions, res.write_actions)
4955 eq_(apply_actions, res.apply_actions)
4956 eq_(write_setfields, res.write_setfields)
4957 eq_(apply_setfields, res.apply_setfields)
4958 eq_(metadata_match, res.metadata_match)
4959 eq_(metadata_write, res.metadata_write)
4960 eq_(instructions, res.instructions)
4961 eq_(config, res.config)
4962 eq_(max_entries, res.max_entries)
4963 eq_(active_count, res.active_count)
4964 eq_(lookup_count, res.lookup_count)
4965 eq_(matched_count, res.matched_count)
4967 def _test_parser(self, table_id, name, match, wildcards, write_actions,
4968 apply_actions, write_setfields, apply_setfields,
4969 metadata_match, metadata_write, instructions, config,
4970 max_entries, active_count, lookup_count, matched_count):
4971 # OFP_TABLE_STATS_PACK_STR
4972 # '!B7x32sQQIIQQQQIIIIQQ'
4973 # ...table_id, name, match, wildcards, write_actions, apply_actions,
4974 # write_setfields, apply_setfields', metadata_match, metadata_write,
4975 # instructions, config, max_entries,
4976 # active_count, lookup_count, matched_count
4977 fmt = ofproto.OFP_TABLE_STATS_PACK_STR
4978 buf = pack(fmt, table_id, name,
4979 match, wildcards, write_actions,
4980 apply_actions, write_setfields, apply_setfields,
4981 metadata_match, metadata_write, instructions, config,
4982 max_entries, active_count, lookup_count, matched_count)
4984 res = OFPTableStats.parser(buf, 0)
4986 eq_(table_id, res.table_id)
4987 eq_(name, res.name.replace(b'\x00', b''))
4988 eq_(match, res.match)
4989 eq_(wildcards, res.wildcards)
4990 eq_(write_actions, res.write_actions)
4991 eq_(apply_actions, res.apply_actions)
4992 eq_(write_setfields, res.write_setfields)
4993 eq_(apply_setfields, res.apply_setfields)
4994 eq_(metadata_match, res.metadata_match)
4995 eq_(metadata_write, res.metadata_write)
4996 eq_(instructions, res.instructions)
4997 eq_(config, res.config)
4998 eq_(max_entries, res.max_entries)
4999 eq_(active_count, res.active_count)
5000 eq_(lookup_count, res.lookup_count)
5001 eq_(matched_count, res.matched_count)
5003 def test_parser_mid(self):
5006 match = 1270985291017894273
5007 wildcards = 3316608530
5008 write_actions = 2484712402
5009 apply_actions = 3999715196
5010 write_setfields = 5142202600015232219
5011 apply_setfields = 2659740543924820419
5012 metadata_match = 2127614848199081640
5013 metadata_write = 2127614848199081641
5014 instructions = 1119692796
5016 max_entries = 2506913869
5017 active_count = 2024581150
5018 lookup_count = 4620020561814017052
5019 matched_count = 2825167325263435621
5021 self._test_parser(table_id, name, match, wildcards, write_actions,
5022 apply_actions, write_setfields, apply_setfields,
5023 metadata_match, metadata_write, instructions, config,
5024 max_entries, active_count, lookup_count,
5027 def test_parser_max(self):
5028 # '!B7x32sQQIIQQQQIIIIQQ'
5031 match = 0xffffffffffffffff
5032 wildcards = 0xffffffffffffffff
5033 write_actions = 0xffffffff
5034 apply_actions = 0xffffffff
5035 write_setfields = 0xffffffffffffffff
5036 apply_setfields = 0xffffffffffffffff
5037 metadata_match = 0xffffffffffffffff
5038 metadata_write = 0xffffffffffffffff
5039 instructions = 0xffffffff
5041 max_entries = 0xffffffff
5042 active_count = 0xffffffff
5043 lookup_count = 0xffffffffffffffff
5044 matched_count = 0xffffffffffffffff
5046 self._test_parser(table_id, name, match, wildcards, write_actions,
5047 apply_actions, write_setfields, apply_setfields,
5048 metadata_match, metadata_write, instructions, config,
5049 max_entries, active_count, lookup_count,
5052 def test_parser_min(self):
5070 self._test_parser(table_id, name, match, wildcards, write_actions,
5071 apply_actions, write_setfields, apply_setfields,
5072 metadata_match, metadata_write, instructions, config,
5073 max_entries, active_count, lookup_count,
5076 def _test_parser_p(self, ofpxmt, ofpit, ofptc):
5081 write_actions = 2484712402
5082 apply_actions = 3999715196
5083 write_setfields = ofpxmt
5084 apply_setfields = ofpxmt
5085 metadata_match = 2127614848199081640
5086 metadata_write = 2127614848199081641
5087 instructions = ofpit
5089 max_entries = 2506913869
5090 active_count = 2024581150
5091 lookup_count = 4620020561814017052
5092 matched_count = 2825167325263435621
5094 self._test_parser(table_id, name, match, wildcards, write_actions,
5095 apply_actions, write_setfields, apply_setfields,
5096 metadata_match, metadata_write, instructions, config,
5097 max_entries, active_count, lookup_count,
5100 def test_parser_p1(self):
5101 self._test_parser_p(ofproto.OFPXMT_OFB_IN_PORT,
5102 ofproto.OFPIT_GOTO_TABLE,
5103 ofproto.OFPTC_TABLE_MISS_CONTINUE)
5105 def test_parser_p2(self):
5106 self._test_parser_p(ofproto.OFPXMT_OFB_IN_PHY_PORT,
5107 ofproto.OFPIT_WRITE_METADATA,
5108 ofproto.OFPTC_TABLE_MISS_DROP)
5110 def test_parser_p3(self):
5111 self._test_parser_p(ofproto.OFPXMT_OFB_METADATA,
5112 ofproto.OFPIT_WRITE_ACTIONS,
5113 ofproto.OFPTC_TABLE_MISS_MASK)
5115 def test_parser_p4(self):
5116 self._test_parser_p(ofproto.OFPXMT_OFB_ETH_DST,
5117 ofproto.OFPIT_APPLY_ACTIONS,
5118 ofproto.OFPTC_TABLE_MISS_MASK)
5120 def test_parser_p5(self):
5121 self._test_parser_p(ofproto.OFPXMT_OFB_ETH_SRC,
5122 ofproto.OFPIT_CLEAR_ACTIONS,
5123 ofproto.OFPTC_TABLE_MISS_MASK)
5125 def test_parser_p6(self):
5126 self._test_parser_p(ofproto.OFPXMT_OFB_ETH_TYPE,
5127 ofproto.OFPIT_EXPERIMENTER,
5128 ofproto.OFPTC_TABLE_MISS_MASK)
5130 def test_parser_p7(self):
5131 self._test_parser_p(ofproto.OFPXMT_OFB_VLAN_VID,
5132 ofproto.OFPIT_EXPERIMENTER,
5133 ofproto.OFPTC_TABLE_MISS_MASK)
5135 def test_parser_p8(self):
5136 self._test_parser_p(ofproto.OFPXMT_OFB_VLAN_PCP,
5137 ofproto.OFPIT_EXPERIMENTER,
5138 ofproto.OFPTC_TABLE_MISS_MASK)
5140 def test_parser_p9(self):
5141 self._test_parser_p(ofproto.OFPXMT_OFB_IP_DSCP,
5142 ofproto.OFPIT_EXPERIMENTER,
5143 ofproto.OFPTC_TABLE_MISS_MASK)
5145 def test_parser_p10(self):
5146 self._test_parser_p(ofproto.OFPXMT_OFB_IP_ECN,
5147 ofproto.OFPIT_EXPERIMENTER,
5148 ofproto.OFPTC_TABLE_MISS_MASK)
5150 def test_parser_p11(self):
5151 self._test_parser_p(ofproto.OFPXMT_OFB_IP_PROTO,
5152 ofproto.OFPIT_EXPERIMENTER,
5153 ofproto.OFPTC_TABLE_MISS_MASK)
5155 def test_parser_p12(self):
5156 self._test_parser_p(ofproto.OFPXMT_OFB_IPV4_SRC,
5157 ofproto.OFPIT_EXPERIMENTER,
5158 ofproto.OFPTC_TABLE_MISS_MASK)
5160 def test_parser_p13(self):
5161 self._test_parser_p(ofproto.OFPXMT_OFB_IPV4_DST,
5162 ofproto.OFPIT_EXPERIMENTER,
5163 ofproto.OFPTC_TABLE_MISS_MASK)
5165 def test_parser_p14(self):
5166 self._test_parser_p(ofproto.OFPXMT_OFB_TCP_SRC,
5167 ofproto.OFPIT_EXPERIMENTER,
5168 ofproto.OFPTC_TABLE_MISS_MASK)
5170 def test_parser_p15(self):
5171 self._test_parser_p(ofproto.OFPXMT_OFB_TCP_DST,
5172 ofproto.OFPIT_EXPERIMENTER,
5173 ofproto.OFPTC_TABLE_MISS_MASK)
5175 def test_parser_p16(self):
5176 self._test_parser_p(ofproto.OFPXMT_OFB_UDP_SRC,
5177 ofproto.OFPIT_EXPERIMENTER,
5178 ofproto.OFPTC_TABLE_MISS_MASK)
5180 def test_parser_p17(self):
5181 self._test_parser_p(ofproto.OFPXMT_OFB_UDP_DST,
5182 ofproto.OFPIT_EXPERIMENTER,
5183 ofproto.OFPTC_TABLE_MISS_MASK)
5185 def test_parser_p18(self):
5186 self._test_parser_p(ofproto.OFPXMT_OFB_SCTP_SRC,
5187 ofproto.OFPIT_EXPERIMENTER,
5188 ofproto.OFPTC_TABLE_MISS_MASK)
5190 def test_parser_p19(self):
5191 self._test_parser_p(ofproto.OFPXMT_OFB_SCTP_DST,
5192 ofproto.OFPIT_EXPERIMENTER,
5193 ofproto.OFPTC_TABLE_MISS_MASK)
5195 def test_parser_p20(self):
5196 self._test_parser_p(ofproto.OFPXMT_OFB_ICMPV4_TYPE,
5197 ofproto.OFPIT_EXPERIMENTER,
5198 ofproto.OFPTC_TABLE_MISS_MASK)
5200 def test_parser_p21(self):
5201 self._test_parser_p(ofproto.OFPXMT_OFB_ICMPV4_CODE,
5202 ofproto.OFPIT_EXPERIMENTER,
5203 ofproto.OFPTC_TABLE_MISS_MASK)
5205 def test_parser_p22(self):
5206 self._test_parser_p(ofproto.OFPXMT_OFB_ARP_OP,
5207 ofproto.OFPIT_EXPERIMENTER,
5208 ofproto.OFPTC_TABLE_MISS_MASK)
5210 def test_parser_p23(self):
5211 self._test_parser_p(ofproto.OFPXMT_OFB_ARP_SPA,
5212 ofproto.OFPIT_EXPERIMENTER,
5213 ofproto.OFPTC_TABLE_MISS_MASK)
5215 def test_parser_p24(self):
5216 self._test_parser_p(ofproto.OFPXMT_OFB_ARP_TPA,
5217 ofproto.OFPIT_EXPERIMENTER,
5218 ofproto.OFPTC_TABLE_MISS_MASK)
5220 def test_parser_p25(self):
5221 self._test_parser_p(ofproto.OFPXMT_OFB_ARP_SHA,
5222 ofproto.OFPIT_EXPERIMENTER,
5223 ofproto.OFPTC_TABLE_MISS_MASK)
5225 def test_parser_p26(self):
5226 self._test_parser_p(ofproto.OFPXMT_OFB_ARP_THA,
5227 ofproto.OFPIT_EXPERIMENTER,
5228 ofproto.OFPTC_TABLE_MISS_MASK)
5230 def test_parser_p27(self):
5231 self._test_parser_p(ofproto.OFPXMT_OFB_IPV6_SRC,
5232 ofproto.OFPIT_EXPERIMENTER,
5233 ofproto.OFPTC_TABLE_MISS_MASK)
5235 def test_parser_p28(self):
5236 self._test_parser_p(ofproto.OFPXMT_OFB_IPV6_DST,
5237 ofproto.OFPIT_EXPERIMENTER,
5238 ofproto.OFPTC_TABLE_MISS_MASK)
5240 def test_parser_p29(self):
5241 self._test_parser_p(ofproto.OFPXMT_OFB_IPV6_FLABEL,
5242 ofproto.OFPIT_EXPERIMENTER,
5243 ofproto.OFPTC_TABLE_MISS_MASK)
5245 def test_parser_p30(self):
5246 self._test_parser_p(ofproto.OFPXMT_OFB_ICMPV6_TYPE,
5247 ofproto.OFPIT_EXPERIMENTER,
5248 ofproto.OFPTC_TABLE_MISS_MASK)
5250 def test_parser_p31(self):
5251 self._test_parser_p(ofproto.OFPXMT_OFB_ICMPV6_CODE,
5252 ofproto.OFPIT_EXPERIMENTER,
5253 ofproto.OFPTC_TABLE_MISS_MASK)
5255 def test_parser_p32(self):
5256 self._test_parser_p(ofproto.OFPXMT_OFB_IPV6_ND_TARGET,
5257 ofproto.OFPIT_EXPERIMENTER,
5258 ofproto.OFPTC_TABLE_MISS_MASK)
5260 def test_parser_p33(self):
5261 self._test_parser_p(ofproto.OFPXMT_OFB_IPV6_ND_SLL,
5262 ofproto.OFPIT_EXPERIMENTER,
5263 ofproto.OFPTC_TABLE_MISS_MASK)
5265 def test_parser_p34(self):
5266 self._test_parser_p(ofproto.OFPXMT_OFB_IPV6_ND_TLL,
5267 ofproto.OFPIT_EXPERIMENTER,
5268 ofproto.OFPTC_TABLE_MISS_MASK)
5270 def test_parser_p35(self):
5271 self._test_parser_p(ofproto.OFPXMT_OFB_MPLS_LABEL,
5272 ofproto.OFPIT_EXPERIMENTER,
5273 ofproto.OFPTC_TABLE_MISS_MASK)
5275 def test_parser_p36(self):
5276 self._test_parser_p(ofproto.OFPXMT_OFB_MPLS_TC,
5277 ofproto.OFPIT_EXPERIMENTER,
5278 ofproto.OFPTC_TABLE_MISS_MASK)
5281 class TestOFPPortStatsRequest(unittest.TestCase):
5282 """ Test case for ofproto_v1_2_parser.OFPPortStatsRequest
5285 # OFP_PORT_STATS_REQUEST_PACK_STR
5286 # '!I4x'...port_no, pad(4)
5289 def test_init(self):
5290 c = OFPPortStatsRequest(_Datapath, self.port_no)
5291 eq_(self.port_no, c.port_no)
5293 def _test_serialize(self, port_no):
5294 c = OFPPortStatsRequest(_Datapath, port_no)
5297 eq_(ofproto.OFP_VERSION, c.version)
5298 eq_(ofproto.OFPT_STATS_REQUEST, c.msg_type)
5302 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5303 + ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '') \
5304 + ofproto.OFP_PORT_STATS_REQUEST_PACK_STR.replace('!', '')
5305 res = struct.unpack(fmt, six.binary_type(c.buf))
5307 eq_(res[0], ofproto.OFP_VERSION)
5308 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
5309 eq_(res[2], len(c.buf))
5311 eq_(res[4], ofproto.OFPST_PORT)
5313 eq_(res[6], port_no)
5315 def test_serialize_mid(self):
5316 self._test_serialize(self.port_no)
5318 def test_serialize_max(self):
5319 self._test_serialize(ofproto.OFPP_ANY)
5321 def test_serialize_min(self):
5322 self._test_serialize(0)
5324 def test_serialize_p1(self):
5325 self._test_serialize(ofproto.OFPP_MAX)
5327 def test_serialize_p2(self):
5328 self._test_serialize(ofproto.OFPP_IN_PORT)
5330 def test_serialize_p3(self):
5331 self._test_serialize(ofproto.OFPP_TABLE)
5333 def test_serialize_p4(self):
5334 self._test_serialize(ofproto.OFPP_NORMAL)
5336 def test_serialize_p5(self):
5337 self._test_serialize(ofproto.OFPP_FLOOD)
5339 def test_serialize_p6(self):
5340 self._test_serialize(ofproto.OFPP_ALL)
5342 def test_serialize_p7(self):
5343 self._test_serialize(ofproto.OFPP_CONTROLLER)
5345 def test_serialize_p8(self):
5346 self._test_serialize(ofproto.OFPP_LOCAL)
5349 class TestOFPPortStats(unittest.TestCase):
5350 """ Test case for ofproto_v1_2_parser.OFPPortStats
5353 def test_init(self):
5355 rx_packets = 5999980397101236279
5356 tx_packets = 2856480458895760962
5357 rx_bytes = 6170274950576278921
5358 tx_bytes = 8638420181865882538
5359 rx_dropped = 6982303461569875546
5360 tx_dropped = 661287462113808071
5361 rx_errors = 3422231811478788365
5362 tx_errors = 6283093430376743019
5363 rx_frame_err = 876072919806406283
5364 rx_over_err = 6525873760178941600
5365 rx_crc_err = 8303073210207070535
5366 collisions = 3409801584220270201
5368 res = OFPPortStats(port_no, rx_packets, tx_packets,
5369 rx_bytes, tx_bytes, rx_dropped, tx_dropped,
5370 rx_errors, tx_errors, rx_frame_err,
5371 rx_over_err, rx_crc_err, collisions)
5373 eq_(port_no, res.port_no)
5374 eq_(rx_packets, res.rx_packets)
5375 eq_(tx_packets, res.tx_packets)
5376 eq_(rx_bytes, res.rx_bytes)
5377 eq_(tx_bytes, res.tx_bytes)
5378 eq_(rx_dropped, res.rx_dropped)
5379 eq_(tx_dropped, res.tx_dropped)
5380 eq_(rx_errors, res.rx_errors)
5381 eq_(tx_errors, res.tx_errors)
5382 eq_(rx_frame_err, res.rx_frame_err)
5383 eq_(rx_over_err, res.rx_over_err)
5384 eq_(rx_crc_err, res.rx_crc_err)
5385 eq_(collisions, res.collisions)
5387 def _test_parser(self, port_no, rx_packets, tx_packets,
5388 rx_bytes, tx_bytes, rx_dropped, tx_dropped,
5389 rx_errors, tx_errors, rx_frame_err,
5390 rx_over_err, rx_crc_err, collisions):
5392 # OFP_PORT_STATS_PACK_STR = '!H6xQQQQQQQQQQQQ'
5393 fmt = ofproto.OFP_PORT_STATS_PACK_STR
5394 buf = pack(fmt, port_no, rx_packets, tx_packets, rx_bytes, tx_bytes,
5395 rx_dropped, tx_dropped, rx_errors, tx_errors, rx_frame_err,
5396 rx_over_err, rx_crc_err, collisions)
5398 res = OFPPortStats.parser(buf, 0)
5400 eq_(port_no, res.port_no)
5401 eq_(rx_packets, res.rx_packets)
5402 eq_(tx_packets, res.tx_packets)
5403 eq_(rx_bytes, res.rx_bytes)
5404 eq_(tx_bytes, res.tx_bytes)
5405 eq_(rx_dropped, res.rx_dropped)
5406 eq_(tx_dropped, res.tx_dropped)
5407 eq_(rx_errors, res.rx_errors)
5408 eq_(tx_errors, res.tx_errors)
5409 eq_(rx_frame_err, res.rx_frame_err)
5410 eq_(rx_over_err, res.rx_over_err)
5411 eq_(rx_crc_err, res.rx_crc_err)
5412 eq_(collisions, res.collisions)
5414 def test_parser_mid(self):
5416 rx_packets = 5999980397101236279
5417 tx_packets = 2856480458895760962
5418 rx_bytes = 6170274950576278921
5419 tx_bytes = 8638420181865882538
5420 rx_dropped = 6982303461569875546
5421 tx_dropped = 661287462113808071
5422 rx_errors = 3422231811478788365
5423 tx_errors = 6283093430376743019
5424 rx_frame_err = 876072919806406283
5425 rx_over_err = 6525873760178941600
5426 rx_crc_err = 8303073210207070535
5427 collisions = 3409801584220270201
5429 self._test_parser(port_no, rx_packets, tx_packets, rx_bytes, tx_bytes,
5430 rx_dropped, tx_dropped, rx_errors, tx_errors,
5431 rx_frame_err, rx_over_err, rx_crc_err, collisions)
5433 def test_parser_max(self):
5434 port_no = 0xffffffff
5435 rx_packets = 0xffffffffffffffff
5436 tx_packets = 0xffffffffffffffff
5437 rx_bytes = 0xffffffffffffffff
5438 tx_bytes = 0xffffffffffffffff
5439 rx_dropped = 0xffffffffffffffff
5440 tx_dropped = 0xffffffffffffffff
5441 rx_errors = 0xffffffffffffffff
5442 tx_errors = 0xffffffffffffffff
5443 rx_frame_err = 0xffffffffffffffff
5444 rx_over_err = 0xffffffffffffffff
5445 rx_crc_err = 0xffffffffffffffff
5446 collisions = 0xffffffffffffffff
5448 self._test_parser(port_no, rx_packets, tx_packets, rx_bytes, tx_bytes,
5449 rx_dropped, tx_dropped, rx_errors, tx_errors,
5450 rx_frame_err, rx_over_err, rx_crc_err, collisions)
5452 def test_parser_min(self):
5467 self._test_parser(port_no, rx_packets, tx_packets, rx_bytes, tx_bytes,
5468 rx_dropped, tx_dropped, rx_errors, tx_errors,
5469 rx_frame_err, rx_over_err, rx_crc_err, collisions)
5471 def _test_parser_p(self, port_no):
5473 rx_packets = 5999980397101236279
5474 tx_packets = 2856480458895760962
5475 rx_bytes = 6170274950576278921
5476 tx_bytes = 8638420181865882538
5477 rx_dropped = 6982303461569875546
5478 tx_dropped = 661287462113808071
5479 rx_errors = 3422231811478788365
5480 tx_errors = 6283093430376743019
5481 rx_frame_err = 876072919806406283
5482 rx_over_err = 6525873760178941600
5483 rx_crc_err = 8303073210207070535
5484 collisions = 3409801584220270201
5486 self._test_parser(port_no, rx_packets, tx_packets, rx_bytes, tx_bytes,
5487 rx_dropped, tx_dropped, rx_errors, tx_errors,
5488 rx_frame_err, rx_over_err, rx_crc_err, collisions)
5490 def test_parser_p1(self):
5491 self._test_parser_p(ofproto.OFPP_MAX)
5493 def test_parser_p2(self):
5494 self._test_parser_p(ofproto.OFPP_IN_PORT)
5496 def test_parser_p3(self):
5497 self._test_parser_p(ofproto.OFPP_TABLE)
5499 def test_parser_p4(self):
5500 self._test_parser_p(ofproto.OFPP_NORMAL)
5502 def test_parser_p5(self):
5503 self._test_parser_p(ofproto.OFPP_FLOOD)
5505 def test_parser_p6(self):
5506 self._test_parser_p(ofproto.OFPP_ALL)
5508 def test_parser_p7(self):
5509 self._test_parser_p(ofproto.OFPP_CONTROLLER)
5511 def test_parser_p8(self):
5512 self._test_parser_p(ofproto.OFPP_LOCAL)
5515 class TestOFPQueueStatsRequest(unittest.TestCase):
5516 """ Test case for ofproto_v1_2_parser.OFPQueueStatsRequest
5519 # OFP_QUEUE_STATS_REQUEST_PACK_STR
5520 # '!II'...port_no, queue_id
5524 def test_init(self):
5525 c = OFPQueueStatsRequest(_Datapath, self.port_no, self.queue_id)
5527 eq_(self.port_no, c.port_no)
5528 eq_(self.queue_id, c.queue_id)
5530 def _test_serialize(self, port_no, queue_id):
5531 c = OFPQueueStatsRequest(_Datapath, port_no, queue_id)
5534 eq_(ofproto.OFP_VERSION, c.version)
5535 eq_(ofproto.OFPT_STATS_REQUEST, c.msg_type)
5539 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5540 + ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '') \
5541 + ofproto.OFP_QUEUE_STATS_REQUEST_PACK_STR.replace('!', '')
5542 res = struct.unpack(fmt, six.binary_type(c.buf))
5544 eq_(res[0], ofproto.OFP_VERSION)
5545 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
5546 eq_(res[2], len(c.buf))
5548 eq_(res[4], ofproto.OFPST_QUEUE)
5550 eq_(res[6], port_no)
5551 eq_(res[7], queue_id)
5553 def test_serialize_mid(self):
5554 self._test_serialize(self.port_no, self.queue_id)
5556 def test_serialize_max(self):
5557 self._test_serialize(0xffffffff, 0xffffffff)
5559 def test_serialize_min(self):
5560 self._test_serialize(0, 0)
5562 def test_serialize_p1(self):
5563 self._test_serialize(ofproto.OFPP_MAX, self.queue_id)
5565 def test_serialize_p2(self):
5566 self._test_serialize(ofproto.OFPP_IN_PORT, self.queue_id)
5568 def test_serialize_p3(self):
5569 self._test_serialize(ofproto.OFPP_NORMAL, self.queue_id)
5571 def test_serialize_p4(self):
5572 self._test_serialize(ofproto.OFPP_TABLE, self.queue_id)
5574 def test_serialize_p5(self):
5575 self._test_serialize(ofproto.OFPP_FLOOD, self.queue_id)
5577 def test_serialize_p6(self):
5578 self._test_serialize(ofproto.OFPP_ALL, self.queue_id)
5580 def test_serialize_p7(self):
5581 self._test_serialize(ofproto.OFPP_CONTROLLER, self.queue_id)
5583 def test_serialize_p8(self):
5584 self._test_serialize(ofproto.OFPP_LOCAL, self.queue_id)
5587 class TestOFPQueueStats(unittest.TestCase):
5588 """ Test case for ofproto_v1_2_parser.OFPQueueStats
5591 def test_init(self):
5594 tx_bytes = 8638420181865882538
5595 tx_packets = 2856480458895760962
5596 tx_errors = 6283093430376743019
5598 res = OFPQueueStats(port_no, queue_id, tx_bytes,
5599 tx_packets, tx_errors)
5601 eq_(port_no, res.port_no)
5602 eq_(queue_id, res.queue_id)
5603 eq_(tx_bytes, res.tx_bytes)
5604 eq_(tx_packets, res.tx_packets)
5605 eq_(tx_errors, res.tx_errors)
5607 def _test_parser(self, port_no, queue_id, tx_bytes,
5608 tx_packets, tx_errors):
5610 # OFP_QUEUE_STATS_PACK_STR = '!IIQQQ'
5611 fmt = ofproto.OFP_QUEUE_STATS_PACK_STR
5612 buf = pack(fmt, port_no, queue_id, tx_bytes, tx_packets, tx_errors)
5613 res = OFPQueueStats.parser(buf, 0)
5615 eq_(port_no, res.port_no)
5616 eq_(queue_id, res.queue_id)
5617 eq_(tx_bytes, res.tx_bytes)
5618 eq_(tx_packets, res.tx_packets)
5619 eq_(tx_errors, res.tx_errors)
5621 def test_parser_mid(self):
5624 tx_bytes = 8638420181865882538
5625 tx_packets = 2856480458895760962
5626 tx_errors = 6283093430376743019
5628 self._test_parser(port_no, queue_id, tx_bytes,
5629 tx_packets, tx_errors)
5631 def test_parser_max(self):
5632 port_no = 0xffffffff
5633 queue_id = 0xffffffff
5634 tx_bytes = 0xffffffffffffffff
5635 tx_packets = 0xffffffffffffffff
5636 tx_errors = 0xffffffffffffffff
5638 self._test_parser(port_no, queue_id, tx_bytes,
5639 tx_packets, tx_errors)
5641 def test_parser_min(self):
5648 self._test_parser(port_no, queue_id, tx_bytes,
5649 tx_packets, tx_errors)
5651 def _test_parser_p(self, port_no):
5653 tx_bytes = 8638420181865882538
5654 tx_packets = 2856480458895760962
5655 tx_errors = 6283093430376743019
5657 self._test_parser(port_no, queue_id, tx_bytes,
5658 tx_packets, tx_errors)
5660 def test_parser_p1(self):
5661 self._test_parser_p(ofproto.OFPP_MAX)
5663 def test_parser_p2(self):
5664 self._test_parser_p(ofproto.OFPP_IN_PORT)
5666 def test_parser_p3(self):
5667 self._test_parser_p(ofproto.OFPP_TABLE)
5669 def test_parser_p4(self):
5670 self._test_parser_p(ofproto.OFPP_NORMAL)
5672 def test_parser_p5(self):
5673 self._test_parser_p(ofproto.OFPP_FLOOD)
5675 def test_parser_p6(self):
5676 self._test_parser_p(ofproto.OFPP_ALL)
5678 def test_parser_p7(self):
5679 self._test_parser_p(ofproto.OFPP_CONTROLLER)
5681 def test_parser_p8(self):
5682 self._test_parser_p(ofproto.OFPP_LOCAL)
5685 class TestOFPBucketCounter(unittest.TestCase):
5686 """ Test case for ofproto_v1_2_parser.OFPBucketCounter
5689 # OFP_BUCKET_COUNTER_PACK_STR = '!QQ'
5690 packet_count = 6489108735192644493
5691 byte_count = 7334344481123449724
5693 def test_init(self):
5694 c = OFPBucketCounter(self.packet_count, self.byte_count)
5696 eq_(self.packet_count, c.packet_count)
5697 eq_(self.byte_count, c.byte_count)
5699 def _test_parser(self, packet_count, byte_count):
5700 fmt = ofproto.OFP_BUCKET_COUNTER_PACK_STR
5701 buf = pack(fmt, packet_count, byte_count)
5703 res = OFPBucketCounter.parser(buf, 0)
5704 eq_(packet_count, res.packet_count)
5705 eq_(byte_count, res.byte_count)
5707 def test_parser_mid(self):
5708 self._test_parser(self.packet_count, self.byte_count)
5710 def test_parser_max(self):
5711 packet_count = 18446744073709551615
5712 byte_count = 18446744073709551615
5713 self._test_parser(packet_count, byte_count)
5715 def test_parser_min(self):
5718 self._test_parser(packet_count, byte_count)
5721 class TestOFPGroupStatsRequest(unittest.TestCase):
5722 """ Test case for ofproto_v1_2_parser.OFPGroupStatsRequest
5725 # OFP_GROUP_STATS_REQUEST_PACK_STR
5726 # '!I4x'...group_id, pad(4)
5729 def test_init(self):
5730 c = OFPGroupStatsRequest(_Datapath, self.group_id)
5731 eq_(self.group_id, c.group_id)
5733 def _test_serialize(self, group_id):
5734 c = OFPGroupStatsRequest(_Datapath, group_id)
5737 eq_(ofproto.OFP_VERSION, c.version)
5738 eq_(ofproto.OFPT_STATS_REQUEST, c.msg_type)
5742 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5743 + ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '') \
5744 + ofproto.OFP_GROUP_STATS_REQUEST_PACK_STR.replace('!', '')
5745 res = struct.unpack(fmt, six.binary_type(c.buf))
5747 eq_(res[0], ofproto.OFP_VERSION)
5748 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
5749 eq_(res[2], len(c.buf))
5751 eq_(res[4], ofproto.OFPST_GROUP)
5753 eq_(res[6], group_id)
5755 def test_serialize_mid(self):
5756 self._test_serialize(self.group_id)
5758 def test_serialize_max(self):
5759 self._test_serialize(0xffffffff)
5761 def test_serialize_min(self):
5762 self._test_serialize(0)
5764 def test_serialize_p1(self):
5765 self._test_serialize(ofproto.OFPG_MAX)
5767 def test_serialize_p2(self):
5768 self._test_serialize(ofproto.OFPG_ALL)
5771 class TestOFPGroupStats(unittest.TestCase):
5772 """ Test case for ofproto_v1_2_parser.OFPGroupStats
5775 # OFP_GROUP_STATS_PACK_STR = '!H2xII4xQQ'
5776 length = ofproto.OFP_GROUP_STATS_SIZE \
5777 + ofproto.OFP_BUCKET_COUNTER_SIZE
5780 packet_count = 6489108735192644493
5781 byte_count = 7334344481123449724
5783 # OFP_BUCKET_COUNTER_PACK_STR = '!QQ'
5784 buck_packet_count = 3519264449364891087
5785 buck_byte_count = 3123449724733434448
5786 bucket_counters = [OFPBucketCounter(buck_packet_count, buck_byte_count)]
5787 buf_bucket_counters = pack(ofproto.OFP_BUCKET_COUNTER_PACK_STR,
5788 buck_packet_count, buck_byte_count)
5790 fmt = ofproto.OFP_GROUP_STATS_PACK_STR
5791 buf = pack(fmt, length, group_id, ref_count, packet_count, byte_count) \
5792 + buf_bucket_counters
5794 def test_init(self):
5795 c = OFPGroupStats(self.group_id, self.ref_count,
5796 self.packet_count, self.byte_count,
5797 self.bucket_counters)
5799 eq_(self.group_id, c.group_id)
5800 eq_(self.ref_count, c.ref_count)
5801 eq_(self.packet_count, c.packet_count)
5802 eq_(self.byte_count, c.byte_count)
5803 eq_(self.bucket_counters, c.bucket_counters)
5805 def _test_parser(self, group_id, ref_count, packet_count,
5806 byte_count, bucket_counter_cnt):
5807 # OFP_GROUP_STATS_PACK_STR = '!H2xII4xQQ'
5808 length = ofproto.OFP_GROUP_STATS_SIZE \
5809 + (ofproto.OFP_BUCKET_COUNTER_SIZE * bucket_counter_cnt)
5810 fmt = ofproto.OFP_GROUP_STATS_PACK_STR
5811 buf = pack(fmt, length, group_id, ref_count,
5812 packet_count, byte_count)
5814 bucket_counters = []
5815 for b in range(bucket_counter_cnt):
5816 # OFP_BUCKET_COUNTER_PACK_STR = '!QQ'
5817 buck_packet_count = b
5819 bucket_counter = OFPBucketCounter(buck_packet_count,
5821 bucket_counters.append(bucket_counter)
5822 buf_bucket_counters = \
5823 pack(ofproto.OFP_BUCKET_COUNTER_PACK_STR,
5824 buck_packet_count, buck_byte_count)
5825 buf += buf_bucket_counters
5827 res = OFPGroupStats.parser(buf, 0)
5830 eq_(length, res.length)
5831 eq_(group_id, res.group_id)
5832 eq_(ref_count, res.ref_count)
5833 eq_(packet_count, res.packet_count)
5834 eq_(byte_count, res.byte_count)
5836 # 32 + 16 * bucket_counter_cnt < 65535 byte
5837 # bucket_counter_cnt <= 4093
5838 for b in range(bucket_counter_cnt):
5839 eq_(bucket_counters[b].packet_count,
5840 res.bucket_counters[b].packet_count)
5841 eq_(bucket_counters[b].byte_count,
5842 res.bucket_counters[b].byte_count)
5844 def test_parser_mid(self):
5845 bucket_counter_cnt = 2046
5846 self._test_parser(self.group_id, self.ref_count,
5847 self.packet_count, self.byte_count,
5850 def test_parser_max(self):
5851 group_id = 4294967295
5852 ref_count = 4294967295
5853 packet_count = 18446744073709551615
5854 byte_count = 18446744073709551615
5855 bucket_counter_cnt = 4093
5856 self._test_parser(group_id, ref_count,
5857 packet_count, byte_count,
5860 def test_parser_min(self):
5865 bucket_counter_cnt = 0
5866 self._test_parser(group_id, ref_count,
5867 packet_count, byte_count,
5871 class TestOFPGroupDescStatsRequest(unittest.TestCase):
5872 """ Test case for ofproto_v1_2_parser.OFPGroupDescStatsRequest
5875 def test_serialize(self):
5876 c = OFPGroupDescStatsRequest(_Datapath)
5880 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
5881 + ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '')
5883 res = struct.unpack(fmt, six.binary_type(c.buf))
5885 eq_(res[0], ofproto.OFP_VERSION)
5886 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
5887 eq_(res[2], len(c.buf))
5889 eq_(res[4], ofproto.OFPST_GROUP_DESC)
5893 class TestOFPGroupDescStats(unittest.TestCase):
5894 """ Test case for ofproto_v1_2_parser.OFPGroupDescStats
5897 # OFP_GROUP_DESC_STATS_PACK_STR = '!HBxI'
5898 length = ofproto.OFP_GROUP_DESC_STATS_SIZE \
5899 + ofproto.OFP_BUCKET_SIZE \
5900 + ofproto.OFP_ACTION_OUTPUT_SIZE
5904 # OFP_ACTION (OFP_ACTION_OUTPUT)
5906 max_len = ofproto.OFP_ACTION_OUTPUT_SIZE
5907 actions = [OFPActionOutput(port, max_len)]
5908 buf_actions = bytearray()
5909 actions[0].serialize(buf_actions, 0)
5915 buckets = [OFPBucket(weight, watch_port, watch_group, actions)]
5919 def test_init(self):
5920 c = OFPGroupDescStats(self.type_, self.group_id, self.buckets)
5922 eq_(self.type_, c.type)
5923 eq_(self.group_id, c.group_id)
5924 eq_(self.buckets, c.buckets)
5926 def _test_parser(self, type_, group_id, bucket_cnt):
5927 # OFP_GROUP_DESC_STATS_PACK_STR = '!HBxI'
5928 length = ofproto.OFP_GROUP_DESC_STATS_SIZE \
5929 + (ofproto.OFP_BUCKET_SIZE
5930 + ofproto.OFP_ACTION_OUTPUT_SIZE) * bucket_cnt
5932 fmt = ofproto.OFP_GROUP_DESC_STATS_PACK_STR
5933 buf = pack(fmt, length, type_, group_id)
5936 for b in range(bucket_cnt):
5938 weight = watch_port = watch_group = b
5939 bucket = OFPBucket(weight,
5940 watch_port, watch_group,
5942 buckets.append(bucket)
5943 buf_buckets = bytearray()
5944 buckets[b].serialize(buf_buckets, 0)
5945 buf += six.binary_type(buf_buckets)
5947 res = OFPGroupDescStats.parser(buf, 0)
5950 eq_(type_, res.type)
5951 eq_(group_id, res.group_id)
5953 # 8 + ( 16 + 16 ) * b < 65535 byte
5955 for b in range(bucket_cnt):
5956 eq_(buckets[b].weight, res.buckets[b].weight)
5957 eq_(buckets[b].watch_port, res.buckets[b].watch_port)
5958 eq_(buckets[b].watch_group, res.buckets[b].watch_group)
5959 eq_(buckets[b].actions[0].port,
5960 res.buckets[b].actions[0].port)
5961 eq_(buckets[b].actions[0].max_len,
5962 res.buckets[b].actions[0].max_len)
5964 def test_parser_mid(self):
5965 self._test_parser(self.type_, self.group_id, self.bucket_cnt)
5967 def test_parser_max(self):
5968 group_id = 4294967295
5971 self._test_parser(type_, group_id, bucket_cnt)
5973 def test_parser_min(self):
5975 type_ = ofproto.OFPGT_ALL
5977 self._test_parser(type_, group_id, bucket_cnt)
5979 def test_parser_p1(self):
5980 type_ = ofproto.OFPGT_SELECT
5981 self._test_parser(type_, self.group_id, self.bucket_cnt)
5983 def test_parser_p2(self):
5984 type_ = ofproto.OFPGT_INDIRECT
5985 self._test_parser(type_, self.group_id, self.bucket_cnt)
5987 def test_parser_p3(self):
5988 type_ = ofproto.OFPGT_FF
5989 self._test_parser(type_, self.group_id, self.bucket_cnt)
5992 class TestOFPGroupFeaturesStatsRequest(unittest.TestCase):
5993 """ Test case for ofproto_v1_2_parser.OFPGroupFeaturesStatsRequest
5996 def test_serialize(self):
5997 c = OFPGroupFeaturesStatsRequest(_Datapath)
6001 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
6002 + ofproto.OFP_STATS_REQUEST_PACK_STR.replace('!', '')
6004 res = struct.unpack(fmt, six.binary_type(c.buf))
6006 eq_(res[0], ofproto.OFP_VERSION)
6007 eq_(res[1], ofproto.OFPT_STATS_REQUEST)
6008 eq_(res[2], len(c.buf))
6010 eq_(res[4], ofproto.OFPST_GROUP_FEATURES)
6014 class TestOFPGroupFeaturesStats(unittest.TestCase):
6015 """ Test case for ofproto_v1_2_parser.OFPGroupFeaturesStats
6018 # OFP_GROUP_FEATURES_STATS_PACK_STR = '!II4I4I'
6019 types = ofproto.OFPGT_ALL
6020 capabilities = ofproto.OFPGFC_SELECT_WEIGHT
6021 max_groups = [1, 2, 3, 4]
6022 actions = [1 << ofproto.OFPAT_OUTPUT,
6023 1 << ofproto.OFPAT_COPY_TTL_OUT,
6024 1 << ofproto.OFPAT_SET_MPLS_TTL,
6025 1 << ofproto.OFPAT_PUSH_VLAN]
6027 def test_init(self):
6028 c = OFPGroupFeaturesStats(self.types, self.capabilities,
6029 self.max_groups, self.actions)
6030 eq_(self.types, c.types)
6031 eq_(self.capabilities, c.capabilities)
6032 eq_(self.max_groups, c.max_groups)
6033 eq_(self.actions, c.actions)
6035 def _test_parser(self, types, capabilities, max_groups, actions):
6037 buf = pack('!I', types) \
6038 + pack('!I', capabilities) \
6039 + pack('!I', max_groups[0]) \
6040 + pack('!I', max_groups[1]) \
6041 + pack('!I', max_groups[2]) \
6042 + pack('!I', max_groups[3]) \
6043 + pack('!I', actions[0]) \
6044 + pack('!I', actions[1]) \
6045 + pack('!I', actions[2]) \
6046 + pack('!I', actions[3])
6048 res = OFPGroupFeaturesStats.parser(buf, 0)
6050 # max_groups and actions after the parser is tuple
6051 eq_(types, res.types)
6052 eq_(capabilities, res.capabilities)
6053 eq_(max_groups, res.max_groups)
6054 eq_(actions, res.actions)
6056 def test_parser_mid(self):
6057 self._test_parser(self.types, self.capabilities,
6058 self.max_groups, self.actions)
6060 def test_parser_max(self):
6061 types = 0b11111111111111111111111111111111
6062 capabilities = 0b11111111111111111111111111111111
6063 max_groups = [4294967295] * 4
6064 actions = [0b11111111111111111111111111111111] * 4
6065 self._test_parser(types, capabilities,
6066 max_groups, actions)
6068 def test_parser_min(self):
6069 types = 0b00000000000000000000000000000000
6070 capabilities = 0b00000000000000000000000000000000
6071 max_groups = [0] * 4
6072 actions = [0b00000000000000000000000000000000] * 4
6073 self._test_parser(types, capabilities,
6074 max_groups, actions)
6076 def _test_parser_p(self, types, capabilities, actions):
6077 self._test_parser(types, capabilities,
6078 self.max_groups, actions)
6080 def test_parser_p1(self):
6081 actions = [1 << ofproto.OFPAT_COPY_TTL_IN,
6082 1 << ofproto.OFPAT_DEC_MPLS_TTL,
6083 1 << ofproto.OFPAT_POP_VLAN,
6084 1 << ofproto.OFPAT_PUSH_MPLS]
6085 self._test_parser_p(1 << ofproto.OFPGT_ALL,
6086 ofproto.OFPGFC_CHAINING,
6089 def test_parser_p2(self):
6090 actions = [1 << ofproto.OFPAT_POP_MPLS,
6091 1 << ofproto.OFPAT_SET_QUEUE,
6092 1 << ofproto.OFPAT_GROUP,
6093 1 << ofproto.OFPAT_SET_NW_TTL]
6094 self._test_parser_p(1 << ofproto.OFPGT_SELECT,
6095 ofproto.OFPGFC_SELECT_WEIGHT,
6098 def test_parser_p3(self):
6099 actions = [1 << ofproto.OFPAT_DEC_NW_TTL,
6100 1 << ofproto.OFPAT_SET_FIELD,
6101 1 << ofproto.OFPAT_GROUP,
6102 1 << ofproto.OFPAT_SET_NW_TTL]
6103 self._test_parser_p(1 << ofproto.OFPGT_SELECT,
6104 ofproto.OFPGFC_SELECT_LIVENESS,
6107 def test_parser_p4(self):
6108 self._test_parser_p(1 << ofproto.OFPGT_INDIRECT,
6109 ofproto.OFPGFC_CHAINING,
6112 def test_parser_p5(self):
6113 self._test_parser_p(1 << ofproto.OFPGT_FF,
6114 ofproto.OFPGFC_CHAINING_CHECKS,
6118 class TestOFPQueueGetConfigRequest(unittest.TestCase):
6119 """ Test case for ofproto_v1_2_parser.OFPQueueGetConfigRequest
6122 # OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR v1.2
6123 # '!I4x'...port, pad(4)
6126 def test_init(self):
6127 c = OFPQueueGetConfigRequest(_Datapath, self.port)
6128 eq_(self.port, c.port)
6130 def _test_serialize(self, port):
6131 c = OFPQueueGetConfigRequest(_Datapath, port)
6134 eq_(ofproto.OFP_VERSION, c.version)
6135 eq_(ofproto.OFPT_QUEUE_GET_CONFIG_REQUEST, c.msg_type)
6138 fmt = ofproto.OFP_HEADER_PACK_STR \
6139 + ofproto.OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR[1:]
6141 res = struct.unpack(fmt, six.binary_type(c.buf))
6142 eq_(res[0], ofproto.OFP_VERSION)
6143 eq_(res[1], ofproto.OFPT_QUEUE_GET_CONFIG_REQUEST)
6144 eq_(res[2], len(c.buf))
6148 def test_serialize_mid(self):
6149 self._test_serialize(self.port)
6151 def test_serialize_max(self):
6152 self._test_serialize(0xffffffff)
6154 def test_serialize_min(self):
6155 self._test_serialize(0)
6157 def test_serialize_p1(self):
6158 self._test_serialize(ofproto.OFPP_MAX)
6161 class TestOFPQueuePropHeader(unittest.TestCase):
6162 """ Test case for ofproto_v1_2_parser.OFPQueuePropHeader
6165 # OFP_QUEUE_PROP_HEADER_PACK_STR = '!HH4x'
6169 def test_init(self):
6170 c = OFPQueuePropHeader(self.property_, self.len_)
6171 eq_(self.property_, c.property)
6172 eq_(self.len_, c.len)
6174 def _test_serialize(self, property_, len_):
6175 c = OFPQueuePropHeader(property_, len_)
6179 fmt = ofproto.OFP_QUEUE_PROP_HEADER_PACK_STR
6180 res = struct.unpack(fmt, six.binary_type(buf))
6182 eq_(res[0], property_)
6185 def test_serialize_mid(self):
6186 self._test_serialize(self.property_, self.len_)
6188 def test_serialize_max(self):
6189 self._test_serialize(0xffff, 0xffff)
6191 def test_serialize_min(self):
6192 self._test_serialize(0, 0)
6195 class TestOFPPacketQueue(unittest.TestCase):
6196 """ Test case for ofproto_v1_2_parser.OFPPacketQueue
6199 def test_init(self):
6203 properties = [4, 5, 6]
6204 c = OFPPacketQueue(queue_id, port, properties)
6206 eq_(queue_id, c.queue_id)
6208 eq_(properties, c.properties)
6210 def _test_parser(self, queue_id, port, prop_cnt):
6211 # OFP_PACKET_QUEUE_PACK_STR = '!IIH6x'
6212 fmt = ofproto.OFP_PACKET_QUEUE_PACK_STR
6213 queue_len = ofproto.OFP_PACKET_QUEUE_SIZE \
6214 + ofproto.OFP_QUEUE_PROP_MIN_RATE_SIZE * prop_cnt
6216 buf = pack(fmt, queue_id, port, queue_len)
6218 for rate in range(prop_cnt):
6219 # OFP_QUEUE_PROP_HEADER_PACK_STR = '!HH4x'
6220 fmt = ofproto.OFP_QUEUE_PROP_HEADER_PACK_STR
6221 prop_type = ofproto.OFPQT_MIN_RATE
6222 prop_len = ofproto.OFP_QUEUE_PROP_MIN_RATE_SIZE
6223 buf += pack(fmt, prop_type, prop_len)
6225 # OFP_QUEUE_PROP_MIN_RATE_PACK_STR = '!H6x'
6226 fmt = ofproto.OFP_QUEUE_PROP_MIN_RATE_PACK_STR
6228 buf += pack(fmt, prop_rate)
6230 res = OFPPacketQueue.parser(buf, 0)
6232 eq_(queue_id, res.queue_id)
6234 eq_(queue_len, res.len)
6235 eq_(prop_cnt, len(res.properties))
6237 for rate, p in enumerate(res.properties):
6238 eq_(prop_type, p.property)
6239 eq_(prop_len, p.len)
6242 def test_parser_mid(self):
6246 self._test_parser(queue_id, port, prop_cnt)
6248 def test_parser_max(self):
6249 # queue_len format is 'H' < number 65535
6251 # queue_len = OFP_PACKET_QUEUE_SIZE(16)
6252 # + OFP_QUEUE_PROP_MIN_RATE_SIZE(16) * N
6253 # max_prop_cnt = (65535 - 16) / 16 = 4094
6254 queue_id = 0xffffffff
6257 self._test_parser(queue_id, port, prop_cnt)
6259 def test_parser_min(self):
6263 self._test_parser(queue_id, port, prop_cnt)
6266 class TestOFPQueuePropMinRate(unittest.TestCase):
6267 """ Test case for ofproto_v1_2_parser.OFPQueuePropMinRate
6270 def _test_parser(self, rate):
6271 # OFP_QUEUE_PROP_MIN_RATE_PACK_STR...H6x
6272 buf = pack(ofproto.OFP_QUEUE_PROP_MIN_RATE_PACK_STR, rate)
6273 res = OFPQueuePropMinRate.parser(buf, 0)
6276 def test_parser_mid(self):
6277 self._test_parser(32768)
6279 def test_parser_max(self):
6280 self._test_parser(0xffff)
6282 def test_parser_min(self):
6283 self._test_parser(0)
6286 class TestOFPQueuePropMaxRate(unittest.TestCase):
6287 """ Test case for ofproto_v1_2_parser.OFPQueuePropMaxRate
6291 buf = pack(ofproto.OFP_QUEUE_PROP_MAX_RATE_PACK_STR, rate)
6292 c = OFPQueuePropMaxRate(rate)
6294 def _test_parser(self, rate):
6295 # OFP_QUEUE_PROP_MAX_RATE_PACK_STR...H6x
6296 buf = pack(ofproto.OFP_QUEUE_PROP_MAX_RATE_PACK_STR, rate)
6297 res = OFPQueuePropMaxRate.parser(buf, 0)
6300 def test_parser_mid(self):
6301 self._test_parser(100)
6303 def test_parser_max(self):
6304 self._test_parser(0xffff)
6306 def test_parser_min(self):
6307 self._test_parser(0)
6310 class TestOFPQueueGetConfigReply(unittest.TestCase):
6311 """ Test case for ofproto_v1_2_parser.OFPQueueGetConfigReply
6314 def _test_parser(self, xid, port, queue_cnt):
6315 version = ofproto.OFP_VERSION
6316 msg_type = ofproto.OFPT_QUEUE_GET_CONFIG_REPLY
6319 for q in range(queue_cnt):
6320 queues_len += ofproto.OFP_PACKET_QUEUE_SIZE
6321 queues_len += ofproto.OFP_QUEUE_PROP_MIN_RATE_SIZE
6323 msg_len = ofproto.OFP_QUEUE_GET_CONFIG_REPLY_SIZE \
6326 # OFP_HEADER_PACK_STR = '!BBHI'
6327 fmt = ofproto.OFP_HEADER_PACK_STR
6328 buf = pack(fmt, version, msg_type, msg_len, xid)
6330 # OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR = '!I4x'
6331 fmt = ofproto.OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR
6332 buf += pack(fmt, port)
6335 for q in range(1, queue_cnt + 1):
6336 # OFP_PACKET_QUEUE_PACK_STR = '!IIH6x'
6337 fmt = ofproto.OFP_PACKET_QUEUE_PACK_STR
6340 queue_len = ofproto.OFP_PACKET_QUEUE_SIZE \
6341 + ofproto.OFP_QUEUE_PROP_MIN_RATE_SIZE
6342 buf += pack(fmt, queue_id, queue_port, queue_len)
6344 # OFP_QUEUE_PROP_HEADER_PACK_STR = '!HH4x'
6345 fmt = ofproto.OFP_QUEUE_PROP_HEADER_PACK_STR
6346 prop_type = ofproto.OFPQT_MIN_RATE
6347 prop_len = ofproto.OFP_QUEUE_PROP_MIN_RATE_SIZE
6348 buf += pack(fmt, prop_type, prop_len)
6350 # OFP_QUEUE_PROP_MIN_RATE_PACK_STR = '!H6x'
6351 fmt = ofproto.OFP_QUEUE_PROP_MIN_RATE_PACK_STR
6353 buf += pack(fmt, prop_rate)
6355 queue = {'queue_id': queue_id, 'queue_port': queue_port,
6356 'queue_len': queue_len, 'prop_type': prop_type,
6357 'prop_len': prop_len, 'prop_rate': prop_rate}
6358 queues.append(queue)
6360 res = OFPQueueGetConfigReply.parser(object, version, msg_type,
6362 eq_(version, res.version)
6363 eq_(msg_type, res.msg_type)
6364 eq_(msg_len, res.msg_len)
6367 eq_(queue_cnt, len(res.queues))
6369 for i, val in enumerate(res.queues):
6371 eq_(c['queue_id'], val.queue_id)
6372 eq_(c['queue_port'], val.port)
6373 eq_(c['queue_len'], val.len)
6374 eq_(1, len(val.properties))
6376 prop = val.properties[0]
6377 eq_(c['prop_type'], prop.property)
6378 eq_(c['prop_len'], prop.len)
6379 eq_(c['prop_rate'], prop.rate)
6381 def test_parser_mid(self):
6382 self._test_parser(2495926989, 65037, 2)
6384 def test_parser_max(self):
6385 # total msg_len = 65520
6386 self._test_parser(0xffffffff, 0xffffffff, 2047)
6388 def test_parser_min(self):
6389 self._test_parser(0, 0, 0)
6392 class TestOFPBarrierRequest(unittest.TestCase):
6393 """ Test case for ofproto_v1_2_parser.OFPBarrierRequest
6396 def test_serialize(self):
6397 c = OFPBarrierRequest(_Datapath)
6400 eq_(ofproto.OFP_VERSION, c.version)
6401 eq_(ofproto.OFPT_BARRIER_REQUEST, c.msg_type)
6402 eq_(ofproto.OFP_HEADER_SIZE, c.msg_len)
6405 fmt = ofproto.OFP_HEADER_PACK_STR
6406 res = unpack(fmt, six.binary_type(c.buf))
6407 eq_(ofproto.OFP_VERSION, res[0])
6408 eq_(ofproto.OFPT_BARRIER_REQUEST, res[1])
6409 eq_(len(c.buf), res[2])
6413 class TestOFPBarrierReply(unittest.TestCase):
6414 """ Test case for ofproto_v1_2_parser.OFPBarrierReply
6417 def _test_parser(self, xid):
6418 version = ofproto.OFP_VERSION
6419 msg_type = ofproto.OFPT_BARRIER_REPLY
6420 msg_len = ofproto.OFP_HEADER_SIZE
6422 fmt = ofproto.OFP_HEADER_PACK_STR
6423 buf = pack(fmt, version, msg_type, msg_len, xid)
6425 res = OFPBarrierReply.parser(object, version, msg_type,
6427 eq_(version, res.version)
6428 eq_(msg_type, res.msg_type)
6429 eq_(msg_len, res.msg_len)
6432 def test_parser_mid(self):
6433 self._test_parser(2147483648)
6435 def test_parser_max(self):
6436 self._test_parser(0xffffffff)
6438 def test_parser_min(self):
6439 self._test_parser(0)
6442 class TestOFPRoleRequest(unittest.TestCase):
6443 """ Test case for ofproto_v1_2_parser.OFPRoleRequest
6446 # OFP_ROLE_REQUEST_PACK_STR
6447 # '!I4xQ'...role, pad(4), generation_id
6449 generation_id = 1270985291017894273
6451 def test_init(self):
6452 c = OFPRoleRequest(_Datapath, self.role, self.generation_id)
6453 eq_(self.role, c.role)
6454 eq_(self.generation_id, c.generation_id)
6456 def _test_serialize(self, role, generation_id):
6457 c = OFPRoleRequest(_Datapath, role, generation_id)
6460 eq_(ofproto.OFP_VERSION, c.version)
6461 eq_(ofproto.OFPT_ROLE_REQUEST, c.msg_type)
6465 + ofproto.OFP_HEADER_PACK_STR.replace('!', '') \
6466 + ofproto.OFP_ROLE_REQUEST_PACK_STR.replace('!', '')
6468 res = struct.unpack(fmt, six.binary_type(c.buf))
6470 eq_(ofproto.OFP_VERSION, res[0])
6471 eq_(ofproto.OFPT_ROLE_REQUEST, res[1])
6472 eq_(len(c.buf), res[2])
6475 eq_(generation_id, res[5])
6477 def test_serialize_mid(self):
6478 self._test_serialize(self.role, self.generation_id)
6480 def test_serialize_max(self):
6482 generation_id = 0xffffffffffffffff
6483 self._test_serialize(role, generation_id)
6485 def test_serialize_min(self):
6488 self._test_serialize(role, generation_id)
6490 def test_serialize_p1(self):
6491 role = ofproto.OFPCR_ROLE_EQUAL
6492 self._test_serialize(role, self.generation_id)
6494 def test_serialize_p2(self):
6495 role = ofproto.OFPCR_ROLE_MASTER
6496 self._test_serialize(role, self.generation_id)
6498 def test_serialize_p3(self):
6499 role = ofproto.OFPCR_ROLE_SLAVE
6500 self._test_serialize(role, self.generation_id)
6503 class TestOFPRoleReply(unittest.TestCase):
6504 """ Test case for ofproto_v1_2_parser.OFPRoleReply
6507 # OFP_ROLE_REQUEST_PACK_STR
6508 # '!I4xQ'...role, pad(4), generation_id
6509 # role = ofproto.OFPCR_ROLE_NOCHANGE
6511 generation_id = 1270985291017894273
6513 def _test_parser(self, role, generation_id):
6514 # OFP_HEADER_PACK_STR
6515 version = ofproto.OFP_VERSION
6516 msg_type = ofproto.OFPT_ROLE_REPLY
6517 msg_len = ofproto.OFP_ROLE_REQUEST_SIZE
6520 fmt = ofproto.OFP_HEADER_PACK_STR
6521 buf = pack(fmt, version, msg_type, msg_len, xid)
6523 fmt = ofproto.OFP_ROLE_REQUEST_PACK_STR
6524 buf += pack(fmt, role, generation_id)
6526 res = OFPRoleReply.parser(object, version, msg_type, msg_len, xid, buf)
6528 # OFP_HEADER_PACK_STR
6529 eq_(version, res.version)
6530 eq_(msg_type, res.msg_type)
6531 eq_(msg_len, res.msg_len)
6534 # OFP_ROLE_REQUEST_PACK_STR
6536 eq_(generation_id, res.generation_id)
6538 def test_parser_mid(self):
6539 self._test_parser(self.role, self.generation_id)
6541 def test_parser_max(self):
6543 generation_id = 0xffffffffffffffff
6544 self._test_parser(role, generation_id)
6546 def test_parser_min(self):
6547 role = ofproto.OFPCR_ROLE_NOCHANGE
6549 self._test_parser(role, generation_id)
6551 def test_parser_p1(self):
6552 role = ofproto.OFPCR_ROLE_EQUAL
6553 self._test_parser(role, self.generation_id)
6555 def test_parser_p2(self):
6556 role = ofproto.OFPCR_ROLE_MASTER
6557 self._test_parser(role, self.generation_id)
6559 def test_parser_p3(self):
6560 role = ofproto.OFPCR_ROLE_SLAVE
6561 self._test_parser(role, self.generation_id)
6564 class TestOFPMatch(unittest.TestCase):
6565 """ Test case for ofproto_v1_2_parser.OFPMatch
6568 def test_init(self):
6572 eq_(res._wc.metadata_mask, 0)
6573 eq_(res._wc.dl_dst_mask, 0)
6574 eq_(res._wc.dl_src_mask, 0)
6575 eq_(res._wc.vlan_vid_mask, 0)
6576 eq_(res._wc.ipv4_src_mask, 0)
6577 eq_(res._wc.ipv4_dst_mask, 0)
6578 eq_(res._wc.arp_spa_mask, 0)
6579 eq_(res._wc.arp_tpa_mask, 0)
6580 eq_(res._wc.arp_sha_mask, 0)
6581 eq_(res._wc.arp_tha_mask, 0)
6582 eq_(res._wc.ipv6_src_mask, [])
6583 eq_(res._wc.ipv6_dst_mask, [])
6584 eq_(res._wc.ipv6_flabel_mask, 0)
6585 eq_(res._wc.wildcards, (1 << 64) - 1)
6588 eq_(res._flow.in_port, 0)
6589 eq_(res._flow.in_phy_port, 0)
6590 eq_(res._flow.metadata, 0)
6591 eq_(res._flow.dl_dst, mac.DONTCARE)
6592 eq_(res._flow.dl_src, mac.DONTCARE)
6593 eq_(res._flow.dl_type, 0)
6594 eq_(res._flow.vlan_vid, 0)
6595 eq_(res._flow.vlan_pcp, 0)
6596 eq_(res._flow.ip_dscp, 0)
6597 eq_(res._flow.ip_ecn, 0)
6598 eq_(res._flow.ip_proto, 0)
6599 eq_(res._flow.ipv4_src, 0)
6600 eq_(res._flow.ipv4_dst, 0)
6601 eq_(res._flow.tcp_src, 0)
6602 eq_(res._flow.tcp_dst, 0)
6603 eq_(res._flow.udp_src, 0)
6604 eq_(res._flow.udp_dst, 0)
6605 eq_(res._flow.sctp_src, 0)
6606 eq_(res._flow.sctp_dst, 0)
6607 eq_(res._flow.icmpv4_type, 0)
6608 eq_(res._flow.icmpv4_code, 0)
6609 eq_(res._flow.arp_op, 0)
6610 eq_(res._flow.arp_spa, 0)
6611 eq_(res._flow.arp_tpa, 0)
6612 eq_(res._flow.arp_sha, 0)
6613 eq_(res._flow.arp_tha, 0)
6614 eq_(res._flow.ipv6_src, [])
6615 eq_(res._flow.ipv6_dst, [])
6616 eq_(res._flow.ipv6_flabel, 0)
6617 eq_(res._flow.icmpv6_type, 0)
6618 eq_(res._flow.icmpv6_code, 0)
6619 eq_(res._flow.ipv6_nd_target, [])
6620 eq_(res._flow.ipv6_nd_sll, 0)
6621 eq_(res._flow.ipv6_nd_tll, 0)
6622 eq_(res._flow.mpls_label, 0)
6623 eq_(res._flow.mpls_tc, 0)
6628 def _test_serialize_and_parser(self, match, header, value, mask=None):
6629 cls_ = OFPMatchField._FIELDS_HEADERS.get(header)
6630 pack_str = cls_.pack_str.replace('!', '')
6631 fmt = '!HHI' + pack_str
6635 length = match.serialize(buf, 0)
6636 eq_(length, len(buf))
6637 if mask and len(buf) > calcsize(fmt):
6640 res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
6641 if type(value) is list:
6642 res_value = res[:calcsize(pack_str) // 2]
6643 eq_(res_value, value)
6645 res_mask = res[calcsize(pack_str) // 2:]
6648 res_value = res.pop(0)
6649 if cls_.__name__ == 'MTVlanVid':
6650 eq_(res_value, value | ofproto.OFPVID_PRESENT)
6652 eq_(res_value, value)
6653 if mask and res and res[0]:
6658 res = match.parser(six.binary_type(buf), 0)
6659 eq_(res.type, ofproto.OFPMT_OXM)
6660 eq_(res.fields[0].header, header)
6661 eq_(res.fields[0].value, value)
6662 if mask and res.fields[0].mask is not None:
6663 eq_(res.fields[0].mask, mask)
6666 jsondict = match.to_jsondict()
6669 match2 = match.from_jsondict(jsondict["OFPMatch"])
6671 match2.serialize(buf2, 0)
6672 eq_(str(match), str(match2))
6675 def test_parse_unknown_field(self):
6677 pack_utils.msg_pack_into('!HH', buf, 0, ofproto.OFPMT_OXM, 4 + 6)
6678 header = ofproto.oxm_tlv_header(36, 2)
6679 pack_utils.msg_pack_into('!IH', buf, 4, header, 1)
6680 header = ofproto.OXM_OF_ETH_TYPE
6681 pack_utils.msg_pack_into('!IH', buf, 10, header, 1)
6684 res = match.parser(six.binary_type(buf), 0)
6687 def _test_set_in_port(self, in_port):
6688 header = ofproto.OXM_OF_IN_PORT
6690 match.set_in_port(in_port)
6691 self._test_serialize_and_parser(match, header, in_port)
6693 def test_set_in_port_mid(self):
6694 self._test_set_in_port(0xff8)
6696 def test_set_in_port_max(self):
6697 self._test_set_in_port(0xffffffff)
6699 def test_set_in_port_min(self):
6700 self._test_set_in_port(0)
6703 def _test_set_in_phy_port(self, phy_port):
6704 header = ofproto.OXM_OF_IN_PHY_PORT
6706 match.set_in_phy_port(phy_port)
6707 self._test_serialize_and_parser(match, header, phy_port)
6709 def test_set_in_phy_port_mid(self):
6710 self._test_set_in_phy_port(1)
6712 def test_set_in_phy_port_max(self):
6713 self._test_set_in_phy_port(0xffffffff)
6715 def test_set_in_phy_port_min(self):
6716 self._test_set_in_phy_port(0)
6719 def _test_set_metadata(self, metadata, mask=None):
6720 header = ofproto.OXM_OF_METADATA
6723 match.set_metadata(metadata)
6725 if (mask + 1) >> 64 != 1:
6726 header = ofproto.OXM_OF_METADATA_W
6727 match.set_metadata_masked(metadata, mask)
6729 self._test_serialize_and_parser(match, header, metadata, mask)
6731 def test_set_metadata_mid(self):
6732 self._test_set_metadata(0x1212121212121212)
6734 def test_set_metadata_max(self):
6735 self._test_set_metadata(0xffffffffffffffff)
6737 def test_set_metadata_min(self):
6738 self._test_set_metadata(0)
6740 def test_set_metadata_masked_mid(self):
6741 self._test_set_metadata(0x1212121212121212, 0xff00ff00ff00ff00)
6743 def test_set_metadata_masked_max(self):
6744 self._test_set_metadata(0x1212121212121212, 0xffffffffffffffff)
6746 def test_set_metadata_masked_min(self):
6747 self._test_set_metadata(0x1212121212121212, 0)
6750 def _test_set_dl_dst(self, dl_dst, mask=None):
6751 header = ofproto.OXM_OF_ETH_DST
6753 dl_dst = mac.haddr_to_bin(dl_dst)
6755 match.set_dl_dst(dl_dst)
6757 header = ofproto.OXM_OF_ETH_DST_W
6758 mask = mac.haddr_to_bin(mask)
6759 match.set_dl_dst_masked(dl_dst, mask)
6760 dl_dst = mac.haddr_bitand(dl_dst, mask)
6761 self._test_serialize_and_parser(match, header, dl_dst, mask)
6763 def test_set_dl_dst_mid(self):
6764 self._test_set_dl_dst('e2:7a:09:79:0b:0f')
6766 def test_set_dl_dst_max(self):
6767 self._test_set_dl_dst('ff:ff:ff:ff:ff:ff')
6769 def test_set_dl_dst_min(self):
6770 self._test_set_dl_dst('00:00:00:00:00:00')
6772 def test_set_dl_dst_masked_mid(self):
6773 self._test_set_dl_dst('e2:7a:09:79:0b:0f', 'ff:00:ff:00:ff:00')
6775 def test_set_dl_dst_masked_max(self):
6776 self._test_set_dl_dst('e2:7a:09:79:0b:0f', 'ff:ff:ff:ff:ff:ff')
6778 def test_set_dl_dst_masked_min(self):
6779 self._test_set_dl_dst('e2:7a:09:79:0b:0f', '00:00:00:00:00:00')
6782 def _test_set_dl_src(self, dl_src, mask=None):
6783 header = ofproto.OXM_OF_ETH_SRC
6785 dl_src = mac.haddr_to_bin(dl_src)
6787 match.set_dl_src(dl_src)
6789 header = ofproto.OXM_OF_ETH_SRC_W
6790 mask = mac.haddr_to_bin(mask)
6791 match.set_dl_src_masked(dl_src, mask)
6792 dl_src = mac.haddr_bitand(dl_src, mask)
6793 self._test_serialize_and_parser(match, header, dl_src, mask)
6795 def test_set_dl_src_mid(self):
6796 self._test_set_dl_src('d0:98:79:b4:75:b5')
6798 def test_set_dl_src_max(self):
6799 self._test_set_dl_src('ff:ff:ff:ff:ff:ff')
6801 def test_set_dl_src_min(self):
6802 self._test_set_dl_src('00:00:00:00:00:00')
6804 def test_set_dl_src_masked_mid(self):
6805 self._test_set_dl_src('d0:98:79:b4:75:b5', 'f0:f0:f0:f0:f0:f0')
6807 def test_set_dl_src_masked_max(self):
6808 self._test_set_dl_src('d0:98:79:b4:75:b5', 'ff:ff:ff:ff:ff:ff')
6810 def test_set_dl_src_masked_min(self):
6811 self._test_set_dl_src('d0:98:79:b4:75:b5', '00:00:00:00:00:00')
6814 def _test_set_dl_type(self, value):
6815 header = ofproto.OXM_OF_ETH_TYPE
6817 match.set_dl_type(value)
6818 self._test_serialize_and_parser(match, header, value)
6820 def test_set_dl_type_mid(self):
6821 self._test_set_dl_type(0x7fb6)
6823 def test_set_dl_type_max(self):
6824 self._test_set_dl_type(0xffff)
6826 def test_set_dl_type_min(self):
6827 self._test_set_dl_type(0)
6829 def test_set_dl_type_ip(self):
6830 value = ether.ETH_TYPE_IP
6831 self._test_set_dl_type(value)
6833 def test_set_dl_type_arp(self):
6834 value = ether.ETH_TYPE_ARP
6835 self._test_set_dl_type(value)
6837 def test_set_dl_type_ipv6(self):
6838 value = ether.ETH_TYPE_IPV6
6839 self._test_set_dl_type(value)
6841 def test_set_dl_type_slow(self):
6842 value = ether.ETH_TYPE_SLOW
6843 self._test_set_dl_type(value)
6846 def _test_set_vlan_vid(self, vid, mask=None):
6847 header = ofproto.OXM_OF_VLAN_VID
6850 match.set_vlan_vid(vid)
6852 header = ofproto.OXM_OF_VLAN_VID_W
6853 match.set_vlan_vid_masked(vid, mask)
6854 self._test_serialize_and_parser(match, header, vid, mask)
6856 def _test_set_vlan_vid_none(self):
6857 header = ofproto.OXM_OF_VLAN_VID
6859 match.set_vlan_vid_none()
6860 value = ofproto.OFPVID_NONE
6861 cls_ = OFPMatchField._FIELDS_HEADERS.get(header)
6862 pack_str = cls_.pack_str.replace('!', '')
6863 fmt = '!HHI' + pack_str
6867 length = match.serialize(buf, 0)
6868 eq_(length, len(buf))
6870 res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
6871 res_value = res.pop(0)
6872 eq_(res_value, value)
6875 res = match.parser(six.binary_type(buf), 0)
6876 eq_(res.type, ofproto.OFPMT_OXM)
6877 eq_(res.fields[0].header, header)
6878 eq_(res.fields[0].value, value)
6881 jsondict = match.to_jsondict()
6884 match2 = match.from_jsondict(jsondict["OFPMatch"])
6886 match2.serialize(buf2, 0)
6887 eq_(str(match), str(match2))
6890 def test_set_vlan_vid_mid(self):
6891 self._test_set_vlan_vid(2047)
6893 def test_set_vlan_vid_max(self):
6894 self._test_set_vlan_vid(0xfff)
6896 def test_set_vlan_vid_min(self):
6897 self._test_set_vlan_vid(0)
6899 def test_set_vlan_vid_masked_mid(self):
6900 self._test_set_vlan_vid(2047, 0xf0f)
6902 def test_set_vlan_vid_masked_max(self):
6903 self._test_set_vlan_vid(2047, 0xfff)
6905 def test_set_vlan_vid_masked_min(self):
6906 self._test_set_vlan_vid(2047, 0)
6908 def test_set_vlan_vid_none(self):
6909 self._test_set_vlan_vid_none()
6912 def _test_set_vlan_pcp(self, pcp):
6913 header = ofproto.OXM_OF_VLAN_PCP
6915 match.set_vlan_pcp(pcp)
6916 self._test_serialize_and_parser(match, header, pcp)
6918 def test_set_vlan_pcp_mid(self):
6919 self._test_set_vlan_pcp(5)
6921 def test_set_vlan_pcp_max(self):
6922 self._test_set_vlan_pcp(7)
6924 def test_set_vlan_pcp_min(self):
6925 self._test_set_vlan_pcp(0)
6928 def _test_set_ip_dscp(self, ip_dscp):
6929 header = ofproto.OXM_OF_IP_DSCP
6931 match.set_ip_dscp(ip_dscp)
6932 self._test_serialize_and_parser(match, header, ip_dscp)
6934 def test_set_ip_dscp_mid(self):
6935 self._test_set_ip_dscp(36)
6937 def test_set_ip_dscp_max(self):
6938 self._test_set_ip_dscp(63)
6940 def test_set_ip_dscp_min(self):
6941 self._test_set_ip_dscp(0)
6944 def _test_set_ip_ecn(self, ip_ecn):
6945 header = ofproto.OXM_OF_IP_ECN
6947 match.set_ip_ecn(ip_ecn)
6948 self._test_serialize_and_parser(match, header, ip_ecn)
6950 def test_set_ip_ecn_mid(self):
6951 self._test_set_ip_ecn(1)
6953 def test_set_ip_ecn_max(self):
6954 self._test_set_ip_ecn(3)
6956 def test_set_ip_ecn_min(self):
6957 self._test_set_ip_ecn(0)
6960 def _test_set_ip_proto(self, ip_proto):
6961 header = ofproto.OXM_OF_IP_PROTO
6963 match.set_ip_proto(ip_proto)
6964 self._test_serialize_and_parser(match, header, ip_proto)
6966 def test_set_ip_proto_mid(self):
6967 self._test_set_ip_proto(6)
6969 def test_set_ip_proto_max(self):
6970 self._test_set_ip_proto(0xff)
6972 def test_set_ip_proto_min(self):
6973 self._test_set_ip_proto(0)
6976 def _test_set_ipv4_src(self, ip, mask=None):
6977 header = ofproto.OXM_OF_IPV4_SRC
6979 ip = unpack('!I', socket.inet_aton(ip))[0]
6981 match.set_ipv4_src(ip)
6983 mask = unpack('!I', socket.inet_aton(mask))[0]
6984 if (mask + 1) >> 32 != 1:
6985 header = ofproto.OXM_OF_IPV4_SRC_W
6986 match.set_ipv4_src_masked(ip, mask)
6987 self._test_serialize_and_parser(match, header, ip, mask)
6989 def test_set_ipv4_src_mid(self):
6990 self._test_set_ipv4_src('192.168.196.250')
6992 def test_set_ipv4_src_max(self):
6993 self._test_set_ipv4_src('255.255.255.255')
6995 def test_set_ipv4_src_min(self):
6996 self._test_set_ipv4_src('0.0.0.0')
6998 def test_set_ipv4_src_masked_mid(self):
6999 self._test_set_ipv4_src('192.168.196.250', '255.255.0.0')
7001 def test_set_ipv4_src_masked_max(self):
7002 self._test_set_ipv4_src('192.168.196.250', '255.255.255.255')
7004 def test_set_ipv4_src_masked_min(self):
7005 self._test_set_ipv4_src('192.168.196.250', '0.0.0.0')
7008 def _test_set_ipv4_dst(self, ip, mask=None):
7009 header = ofproto.OXM_OF_IPV4_DST
7011 ip = unpack('!I', socket.inet_aton(ip))[0]
7013 match.set_ipv4_dst(ip)
7015 mask = unpack('!I', socket.inet_aton(mask))[0]
7016 if (mask + 1) >> 32 != 1:
7017 header = ofproto.OXM_OF_IPV4_DST_W
7018 match.set_ipv4_dst_masked(ip, mask)
7019 self._test_serialize_and_parser(match, header, ip, mask)
7021 def test_set_ipv4_dst_mid(self):
7022 self._test_set_ipv4_dst('192.168.196.250')
7024 def test_set_ipv4_dst_max(self):
7025 self._test_set_ipv4_dst('255.255.255.255')
7027 def test_set_ipv4_dst_min(self):
7028 self._test_set_ipv4_dst('0.0.0.0')
7030 def test_set_ipv4_dst_masked_mid(self):
7031 self._test_set_ipv4_dst('192.168.196.250', '255.255.0.0')
7033 def test_set_ipv4_dst_masked_max(self):
7034 self._test_set_ipv4_dst('192.168.196.250', '255.255.255.255')
7036 def test_set_ipv4_dst_masked_min(self):
7037 self._test_set_ipv4_dst('192.168.196.250', '0.0.0.0')
7040 def _test_set_tcp_src(self, tcp_src):
7041 header = ofproto.OXM_OF_TCP_SRC
7043 match.set_tcp_src(tcp_src)
7044 self._test_serialize_and_parser(match, header, tcp_src)
7046 def test_set_tcp_src_mid(self):
7047 self._test_set_tcp_src(1103)
7049 def test_set_tcp_src_max(self):
7050 self._test_set_tcp_src(0xffff)
7052 def test_set_tcp_src_min(self):
7053 self._test_set_tcp_src(0)
7056 def _test_set_tcp_dst(self, tcp_dst):
7057 header = ofproto.OXM_OF_TCP_DST
7059 match.set_tcp_dst(tcp_dst)
7060 self._test_serialize_and_parser(match, header, tcp_dst)
7062 def test_set_tcp_dst_mid(self):
7063 self._test_set_tcp_dst(236)
7065 def test_set_tcp_dst_max(self):
7066 self._test_set_tcp_dst(0xffff)
7068 def test_set_tcp_dst_min(self):
7069 self._test_set_tcp_dst(0)
7072 def _test_set_udp_src(self, udp_src):
7073 header = ofproto.OXM_OF_UDP_SRC
7075 match.set_udp_src(udp_src)
7076 self._test_serialize_and_parser(match, header, udp_src)
7078 def test_set_udp_src_mid(self):
7079 self._test_set_udp_src(56617)
7081 def test_set_udp_src_max(self):
7082 self._test_set_udp_src(0xffff)
7084 def test_set_udp_src_min(self):
7085 self._test_set_udp_src(0)
7088 def _test_set_udp_dst(self, udp_dst):
7089 header = ofproto.OXM_OF_UDP_DST
7091 match.set_udp_dst(udp_dst)
7092 self._test_serialize_and_parser(match, header, udp_dst)
7094 def test_set_udp_dst_mid(self):
7095 self._test_set_udp_dst(61278)
7097 def test_set_udp_dst_max(self):
7098 self._test_set_udp_dst(0xffff)
7100 def test_set_udp_dst_min(self):
7101 self._test_set_udp_dst(0)
7104 def _test_set_sctp_src(self, sctp_src):
7105 header = ofproto.OXM_OF_SCTP_SRC
7107 match.set_sctp_src(sctp_src)
7108 self._test_serialize_and_parser(match, header, sctp_src)
7110 def test_set_sctp_src_mid(self):
7111 self._test_set_sctp_src(9999)
7113 def test_set_sctp_src_max(self):
7114 self._test_set_sctp_src(0xffff)
7116 def test_set_sctp_src_min(self):
7117 self._test_set_sctp_src(0)
7120 def _test_set_sctp_dst(self, sctp_dst):
7121 header = ofproto.OXM_OF_SCTP_DST
7123 match.set_sctp_dst(sctp_dst)
7124 self._test_serialize_and_parser(match, header, sctp_dst)
7126 def test_set_sctp_dst_mid(self):
7127 self._test_set_sctp_dst(1234)
7129 def test_set_sctp_dst_max(self):
7130 self._test_set_sctp_dst(0xffff)
7132 def test_set_sctp_dst_min(self):
7133 self._test_set_sctp_dst(0)
7136 def _test_set_icmpv4_type(self, icmpv4_type):
7137 header = ofproto.OXM_OF_ICMPV4_TYPE
7139 match.set_icmpv4_type(icmpv4_type)
7140 self._test_serialize_and_parser(match, header, icmpv4_type)
7142 def test_set_icmpv4_type_mid(self):
7143 self._test_set_icmpv4_type(8)
7145 def test_set_icmpv4_type_max(self):
7146 self._test_set_icmpv4_type(0xff)
7148 def test_set_icmpv4_type_min(self):
7149 self._test_set_icmpv4_type(0)
7152 def _test_set_icmpv4_code(self, icmpv4_code):
7153 header = ofproto.OXM_OF_ICMPV4_CODE
7155 match.set_icmpv4_code(icmpv4_code)
7156 self._test_serialize_and_parser(match, header, icmpv4_code)
7158 def test_set_icmpv4_code_mid(self):
7159 self._test_set_icmpv4_code(1)
7161 def test_set_icmpv4_code_max(self):
7162 self._test_set_icmpv4_code(0xff)
7164 def test_set_icmpv4_code_min(self):
7165 self._test_set_icmpv4_code(0)
7168 def _test_set_arp_opcode(self, arp_op):
7169 header = ofproto.OXM_OF_ARP_OP
7171 match.set_arp_opcode(arp_op)
7172 self._test_serialize_and_parser(match, header, arp_op)
7174 def test_set_arp_opcode_mid(self):
7175 self._test_set_arp_opcode(1)
7177 def test_set_arp_opcode_max(self):
7178 self._test_set_arp_opcode(0xffff)
7180 def test_set_arp_opcode_min(self):
7181 self._test_set_arp_opcode(0)
7184 def _test_set_arp_spa(self, ip, mask=None):
7185 header = ofproto.OXM_OF_ARP_SPA
7187 ip = unpack('!I', socket.inet_aton(ip))[0]
7189 match.set_arp_spa(ip)
7191 mask = unpack('!I', socket.inet_aton(mask))[0]
7192 if (mask + 1) >> 32 != 1:
7193 header = ofproto.OXM_OF_ARP_SPA_W
7194 match.set_arp_spa_masked(ip, mask)
7195 self._test_serialize_and_parser(match, header, ip, mask)
7197 def test_set_arp_spa_mid(self):
7198 self._test_set_arp_spa('192.168.227.57')
7200 def test_set_arp_spa_max(self):
7201 self._test_set_arp_spa('255.255.255.255')
7203 def test_set_arp_spa_min(self):
7204 self._test_set_arp_spa('0.0.0.0')
7206 def test_set_arp_spa_masked_mid(self):
7207 self._test_set_arp_spa('192.168.227.57', '255.255.0.0')
7209 def test_set_arp_spa_masked_max(self):
7210 self._test_set_arp_spa('192.168.227.57', '255.255.255.255')
7212 def test_set_arp_spa_masked_min(self):
7213 self._test_set_arp_spa('192.168.227.57', '0.0.0.0')
7216 def _test_set_arp_tpa(self, ip, mask=None):
7217 header = ofproto.OXM_OF_ARP_TPA
7219 ip = unpack('!I', socket.inet_aton(ip))[0]
7221 match.set_arp_tpa(ip)
7223 mask = unpack('!I', socket.inet_aton(mask))[0]
7224 if (mask + 1) >> 32 != 1:
7225 header = ofproto.OXM_OF_ARP_TPA_W
7226 match.set_arp_tpa_masked(ip, mask)
7227 self._test_serialize_and_parser(match, header, ip, mask)
7229 def test_set_arp_tpa_mid(self):
7230 self._test_set_arp_tpa('192.168.227.57')
7232 def test_set_arp_tpa_max(self):
7233 self._test_set_arp_tpa('255.255.255.255')
7235 def test_set_arp_tpa_min(self):
7236 self._test_set_arp_tpa('0.0.0.0')
7238 def test_set_arp_tpa_masked_mid(self):
7239 self._test_set_arp_tpa('192.168.227.57', '255.255.0.0')
7241 def test_set_arp_tpa_masked_max(self):
7242 self._test_set_arp_tpa('192.168.227.57', '255.255.255.255')
7244 def test_set_arp_tpa_masked_min(self):
7245 self._test_set_arp_tpa('192.168.227.57', '0.0.0.0')
7248 def _test_set_arp_sha(self, arp_sha, mask=None):
7249 header = ofproto.OXM_OF_ARP_SHA
7251 arp_sha = mac.haddr_to_bin(arp_sha)
7253 match.set_arp_sha(arp_sha)
7255 header = ofproto.OXM_OF_ARP_SHA_W
7256 mask = mac.haddr_to_bin(mask)
7257 match.set_arp_sha_masked(arp_sha, mask)
7258 arp_sha = mac.haddr_bitand(arp_sha, mask)
7259 self._test_serialize_and_parser(match, header, arp_sha, mask)
7261 def test_set_arp_sha_mid(self):
7262 self._test_set_arp_sha('3e:ec:13:9b:f3:0b')
7264 def test_set_arp_sha_max(self):
7265 self._test_set_arp_sha('ff:ff:ff:ff:ff:ff')
7267 def test_set_arp_sha_min(self):
7268 self._test_set_arp_sha('00:00:00:00:00:00')
7270 def test_set_arp_sha_masked_mid(self):
7271 self._test_set_arp_sha('3e:ec:13:9b:f3:0b', 'ff:ff:ff:00:00:00')
7273 def test_set_arp_sha_masked_max(self):
7274 self._test_set_arp_sha('3e:ec:13:9b:f3:0b', 'ff:ff:ff:ff:ff:ff')
7276 def test_set_arp_sha_masked_min(self):
7277 self._test_set_arp_sha('3e:ec:13:9b:f3:0b', '00:00:00:00:00:00')
7280 def _test_set_arp_tha(self, arp_tha, mask=None):
7281 header = ofproto.OXM_OF_ARP_THA
7283 arp_tha = mac.haddr_to_bin(arp_tha)
7285 match.set_arp_tha(arp_tha)
7287 header = ofproto.OXM_OF_ARP_THA_W
7288 mask = mac.haddr_to_bin(mask)
7289 match.set_arp_tha_masked(arp_tha, mask)
7290 arp_tha = mac.haddr_bitand(arp_tha, mask)
7291 self._test_serialize_and_parser(match, header, arp_tha, mask)
7293 def test_set_arp_tha_mid(self):
7294 self._test_set_arp_tha('83:6c:21:52:49:68')
7296 def test_set_arp_tha_max(self):
7297 self._test_set_arp_tha('ff:ff:ff:ff:ff:ff')
7299 def test_set_arp_tha_min(self):
7300 self._test_set_arp_tha('00:00:00:00:00:00')
7302 def test_set_arp_tha_masked_mid(self):
7303 self._test_set_arp_tha('83:6c:21:52:49:68', 'ff:ff:ff:00:00:00')
7305 def test_set_arp_tha_masked_max(self):
7306 self._test_set_arp_tha('83:6c:21:52:49:68', 'ff:ff:ff:ff:ff:ff')
7308 def test_set_arp_tha_masked_min(self):
7309 self._test_set_arp_tha('83:6c:21:52:49:68', '00:00:00:00:00:00')
7312 def _test_set_ipv6_src(self, ipv6, mask=None):
7313 header = ofproto.OXM_OF_IPV6_SRC
7315 ipv6 = [int(x, 16) for x in ipv6.split(":")]
7317 match.set_ipv6_src(ipv6)
7319 header = ofproto.OXM_OF_IPV6_SRC_W
7320 mask = [int(x, 16) for x in mask.split(":")]
7321 match.set_ipv6_src_masked(ipv6, mask)
7322 ipv6 = [x & y for (x, y) in zip(ipv6, mask)]
7323 self._test_serialize_and_parser(match, header, ipv6, mask)
7325 def test_set_ipv6_src_mid(self):
7326 ipv6 = '2001:db8:bd05:1d2:288a:1fc0:1:10ee'
7327 self._test_set_ipv6_src(ipv6)
7329 def test_set_ipv6_src_max(self):
7330 ipv6 = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
7331 self._test_set_ipv6_src(ipv6)
7333 def test_set_ipv6_src_min(self):
7334 ipv6 = '0:0:0:0:0:0:0:0'
7335 self._test_set_ipv6_src(ipv6)
7337 def test_set_ipv6_src_masked_mid(self):
7338 ipv6 = '2001:db8:bd05:1d2:288a:1fc0:1:10ee'
7339 mask = 'ffff:ffff:ffff:ffff:0:0:0:0'
7340 self._test_set_ipv6_src(ipv6, mask)
7342 def test_set_ipv6_src_masked_max(self):
7343 ipv6 = '2001:db8:bd05:1d2:288a:1fc0:1:10ee'
7344 mask = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
7345 self._test_set_ipv6_src(ipv6, mask)
7347 def test_set_ipv6_src_masked_min(self):
7348 ipv6 = '2001:db8:bd05:1d2:288a:1fc0:1:10ee'
7349 mask = '0:0:0:0:0:0:0:0'
7350 self._test_set_ipv6_src(ipv6, mask)
7353 def _test_set_ipv6_dst(self, ipv6, mask=None):
7354 header = ofproto.OXM_OF_IPV6_DST
7356 ipv6 = [int(x, 16) for x in ipv6.split(":")]
7358 match.set_ipv6_dst(ipv6)
7360 header = ofproto.OXM_OF_IPV6_DST_W
7361 mask = [int(x, 16) for x in mask.split(":")]
7362 match.set_ipv6_dst_masked(ipv6, mask)
7363 ipv6 = [x & y for (x, y) in zip(ipv6, mask)]
7364 self._test_serialize_and_parser(match, header, ipv6, mask)
7366 def test_set_ipv6_dst_mid(self):
7367 ipv6 = 'e9e8:9ea5:7d67:82cc:ca54:1fc0:2d24:f038'
7368 self._test_set_ipv6_dst(ipv6)
7370 def test_set_ipv6_dst_max(self):
7371 ipv6 = ':'.join(['ffff'] * 8)
7372 self._test_set_ipv6_dst(ipv6)
7374 def test_set_ipv6_dst_min(self):
7375 ipv6 = ':'.join(['0'] * 8)
7376 self._test_set_ipv6_dst(ipv6)
7378 def test_set_ipv6_dst_mask_mid(self):
7379 ipv6 = 'e9e8:9ea5:7d67:82cc:ca54:1fc0:2d24:f038'
7380 mask = ':'.join(['ffff'] * 4 + ['0'] * 4)
7381 self._test_set_ipv6_dst(ipv6, mask)
7383 def test_set_ipv6_dst_mask_max(self):
7384 ipv6 = 'e9e8:9ea5:7d67:82cc:ca54:1fc0:2d24:f038'
7385 mask = ':'.join(['ffff'] * 8)
7386 self._test_set_ipv6_dst(ipv6, mask)
7388 def test_set_ipv6_dst_mask_min(self):
7389 ipv6 = 'e9e8:9ea5:7d67:82cc:ca54:1fc0:2d24:f038'
7390 mask = ':'.join(['0'] * 8)
7391 self._test_set_ipv6_dst(ipv6, mask)
7394 def _test_set_ipv6_flabel(self, flabel, mask=None):
7395 header = ofproto.OXM_OF_IPV6_FLABEL
7398 match.set_ipv6_flabel(flabel)
7400 header = ofproto.OXM_OF_IPV6_FLABEL_W
7401 match.set_ipv6_flabel_masked(flabel, mask)
7402 self._test_serialize_and_parser(match, header, flabel, mask)
7404 def test_set_ipv6_flabel_mid(self):
7405 self._test_set_ipv6_flabel(0xc5384)
7407 def test_set_ipv6_flabel_max(self):
7408 self._test_set_ipv6_flabel(0xfffff)
7410 def test_set_ipv6_flabel_min(self):
7411 self._test_set_ipv6_flabel(0)
7413 def test_set_ipv6_flabel_masked_mid(self):
7414 self._test_set_ipv6_flabel(0xc5384, 0xfff00)
7416 def test_set_ipv6_flabel_masked_max(self):
7417 self._test_set_ipv6_flabel(0xc5384, 0xfffff)
7419 def test_set_ipv6_flabel_masked_min(self):
7420 self._test_set_ipv6_flabel(0xc5384, 0)
7423 def _test_set_icmpv6_type(self, icmpv6_type):
7424 header = ofproto.OXM_OF_ICMPV6_TYPE
7426 match.set_icmpv6_type(icmpv6_type)
7427 self._test_serialize_and_parser(match, header, icmpv6_type)
7429 def test_set_icmpv6_type_mid(self):
7430 self._test_set_icmpv6_type(129)
7432 def test_set_icmpv6_type_max(self):
7433 self._test_set_icmpv6_type(0xff)
7435 def test_set_icmpv6_type_min(self):
7436 self._test_set_icmpv6_type(0)
7439 def _test_set_icmpv6_code(self, icmpv6_code):
7440 header = ofproto.OXM_OF_ICMPV6_CODE
7442 match.set_icmpv6_code(icmpv6_code)
7443 self._test_serialize_and_parser(match, header, icmpv6_code)
7445 def test_set_icmpv6_code_mid(self):
7446 self._test_set_icmpv6_code(1)
7448 def test_set_icmpv6_code_max(self):
7449 self._test_set_icmpv6_code(0xff)
7451 def test_set_icmpv6_code_min(self):
7452 self._test_set_icmpv6_code(0)
7454 # set_ipv6_nd_target
7455 def _test_set_ipv6_nd_target(self, ipv6):
7456 header = ofproto.OXM_OF_IPV6_ND_TARGET
7458 ipv6 = [int(x, 16) for x in ipv6.split(":")]
7459 match.set_ipv6_nd_target(ipv6)
7460 self._test_serialize_and_parser(match, header, ipv6)
7462 def test_set_ipv6_nd_target_mid(self):
7463 ip = '5420:db3f:921b:3e33:2791:98f:dd7f:2e19'
7464 self._test_set_ipv6_nd_target(ip)
7466 def test_set_ipv6_nd_target_max(self):
7467 ip = ':'.join(['ffff'] * 8)
7468 self._test_set_ipv6_nd_target(ip)
7470 def test_set_ipv6_nd_target_min(self):
7471 ip = ':'.join(['0'] * 8)
7472 self._test_set_ipv6_nd_target(ip)
7475 def _test_set_ipv6_nd_sll(self, nd_sll):
7476 header = ofproto.OXM_OF_IPV6_ND_SLL
7478 nd_sll = mac.haddr_to_bin(nd_sll)
7479 match.set_ipv6_nd_sll(nd_sll)
7480 self._test_serialize_and_parser(match, header, nd_sll)
7482 def test_set_ipv6_nd_sll_mid(self):
7483 self._test_set_ipv6_nd_sll('93:6d:d0:d4:e8:36')
7485 def test_set_ipv6_nd_sll_max(self):
7486 self._test_set_ipv6_nd_sll('ff:ff:ff:ff:ff:ff')
7488 def test_set_ipv6_nd_sll_min(self):
7489 self._test_set_ipv6_nd_sll('00:00:00:00:00:00')
7492 def _test_set_ipv6_nd_tll(self, nd_tll):
7493 header = ofproto.OXM_OF_IPV6_ND_TLL
7495 nd_tll = mac.haddr_to_bin(nd_tll)
7496 match.set_ipv6_nd_tll(nd_tll)
7497 self._test_serialize_and_parser(match, header, nd_tll)
7499 def test_set_ipv6_nd_tll_mid(self):
7500 self._test_set_ipv6_nd_tll('18:f6:66:b6:f1:b3')
7502 def test_set_ipv6_nd_tll_max(self):
7503 self._test_set_ipv6_nd_tll('ff:ff:ff:ff:ff:ff')
7505 def test_set_ipv6_nd_tll_min(self):
7506 self._test_set_ipv6_nd_tll('00:00:00:00:00:00')
7509 def _test_set_mpls_label(self, mpls_label):
7510 header = ofproto.OXM_OF_MPLS_LABEL
7512 match.set_mpls_label(mpls_label)
7513 self._test_serialize_and_parser(match, header, mpls_label)
7515 def test_set_mpls_label_mid(self):
7516 self._test_set_mpls_label(2144)
7518 def test_set_mpls_label_max(self):
7519 self._test_set_mpls_label(0xfffff)
7521 def test_set_mpls_label_min(self):
7522 self._test_set_mpls_label(0)
7525 def _test_set_mpls_tc(self, mpls_tc):
7526 header = ofproto.OXM_OF_MPLS_TC
7528 match.set_mpls_tc(mpls_tc)
7529 self._test_serialize_and_parser(match, header, mpls_tc)
7531 def test_set_mpls_tc_mid(self):
7532 self._test_set_mpls_tc(3)
7534 def test_set_mpls_tc_max(self):
7535 self._test_set_mpls_tc(7)
7537 def test_set_mpls_tc_min(self):
7538 self._test_set_mpls_tc(0)
7541 class TestOFPMatchField(unittest.TestCase):
7542 """ Test case for ofproto_v1_2_parser.OFPMatchField
7545 def test_init_hasmask_true(self):
7548 res = OFPMatchField(header)
7550 eq_(res.header, header)
7551 eq_(res.n_bytes, (header & 0xff) // 2)
7554 def test_init_hasmask_false(self):
7557 res = OFPMatchField(header)
7559 eq_(res.header, header)
7560 eq_(res.n_bytes, header & 0xff)