| @@ 651-680 (lines=30) @@ | ||
| 648 | return cls(value) |
|
| 649 | ||
| 650 | ||
| 651 | class MatchEXTHDR(MatchField): |
|
| 652 | """Match for IPV6 EXTHDR.""" |
|
| 653 | ||
| 654 | name = 'v6_hdr' |
|
| 655 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV6_EXTHDR |
|
| 656 | ||
| 657 | def as_of_tlv(self): |
|
| 658 | """Return a pyof OXM TLV instance.""" |
|
| 659 | try: |
|
| 660 | value = int(self.value) |
|
| 661 | mask = None |
|
| 662 | oxm_hasmask = False |
|
| 663 | except ValueError: |
|
| 664 | value, mask = map(int, self.value.split('/')) |
|
| 665 | oxm_hasmask = True |
|
| 666 | value_bytes = value.to_bytes(2, 'big') |
|
| 667 | if mask: |
|
| 668 | value_bytes += mask.to_bytes(2, 'big') |
|
| 669 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 670 | oxm_hasmask=oxm_hasmask, |
|
| 671 | oxm_value=value_bytes) |
|
| 672 | ||
| 673 | @classmethod |
|
| 674 | def from_of_tlv(cls, tlv): |
|
| 675 | """Return an instance from a pyof OXM TLV.""" |
|
| 676 | value = int.from_bytes(tlv.oxm_value[:2], 'big') |
|
| 677 | if tlv.oxm_hasmask: |
|
| 678 | exhead_mask = int.from_bytes(tlv.oxm_value[2:], 'big') |
|
| 679 | value = f'{value}/{exhead_mask}' |
|
| 680 | return cls(value) |
|
| 681 | ||
| 682 | ||
| 683 | class MatchFieldFactory(ABC): |
|
| @@ 619-648 (lines=30) @@ | ||
| 616 | return cls(tll) |
|
| 617 | ||
| 618 | ||
| 619 | class MatchPBBISID(MatchField): |
|
| 620 | """Match for PBB ISID.""" |
|
| 621 | ||
| 622 | name = 'pbb_isid' |
|
| 623 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_PBB_ISID |
|
| 624 | ||
| 625 | def as_of_tlv(self): |
|
| 626 | """Return a pyof OXM TLV instance.""" |
|
| 627 | try: |
|
| 628 | value = int(self.value) |
|
| 629 | mask = None |
|
| 630 | oxm_hasmask = False |
|
| 631 | except ValueError: |
|
| 632 | value, mask = map(int, self.value.split('/')) |
|
| 633 | oxm_hasmask = True |
|
| 634 | value_bytes = value.to_bytes(3, 'big') |
|
| 635 | if mask: |
|
| 636 | value_bytes += mask.to_bytes(3, 'big') |
|
| 637 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 638 | oxm_hasmask=oxm_hasmask, |
|
| 639 | oxm_value=value_bytes) |
|
| 640 | ||
| 641 | @classmethod |
|
| 642 | def from_of_tlv(cls, tlv): |
|
| 643 | """Return an instance from a pyof OXM TLV.""" |
|
| 644 | value = int.from_bytes(tlv.oxm_value[:3], 'big') |
|
| 645 | if tlv.oxm_hasmask: |
|
| 646 | pbb_isid_mask = int.from_bytes(tlv.oxm_value[3:], 'big') |
|
| 647 | value = f'{value}/{pbb_isid_mask}' |
|
| 648 | return cls(value) |
|
| 649 | ||
| 650 | ||
| 651 | class MatchEXTHDR(MatchField): |
|
| @@ 497-526 (lines=30) @@ | ||
| 494 | return cls(opcode) |
|
| 495 | ||
| 496 | ||
| 497 | class MatchIVP6FLabel(MatchField): |
|
| 498 | """Match for IPV6 Flow Label.""" |
|
| 499 | ||
| 500 | name = 'ipv6_flabel' |
|
| 501 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV6_FLABEL |
|
| 502 | ||
| 503 | def as_of_tlv(self): |
|
| 504 | """Return a pyof OXM TLV instance.""" |
|
| 505 | try: |
|
| 506 | value = int(self.value) |
|
| 507 | mask = None |
|
| 508 | oxm_hasmask = False |
|
| 509 | except ValueError: |
|
| 510 | value, mask = map(int, self.value.split('/')) |
|
| 511 | oxm_hasmask = True |
|
| 512 | value_bytes = value.to_bytes(4, 'big') |
|
| 513 | if mask: |
|
| 514 | value_bytes += mask.to_bytes(4, 'big') |
|
| 515 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 516 | oxm_hasmask=oxm_hasmask, |
|
| 517 | oxm_value=value_bytes) |
|
| 518 | ||
| 519 | @classmethod |
|
| 520 | def from_of_tlv(cls, tlv): |
|
| 521 | """Return an instance from a pyof OXM TLV.""" |
|
| 522 | value = int.from_bytes(tlv.oxm_value[:4], 'big') |
|
| 523 | if tlv.oxm_hasmask: |
|
| 524 | flabel_mask = int.from_bytes(tlv.oxm_value[4:], 'big') |
|
| 525 | value = f'{value}/{flabel_mask}' |
|
| 526 | return cls(value) |
|
| 527 | ||
| 528 | ||
| 529 | class MatchICMPV6Type(MatchField): |
|