| @@ 671-700 (lines=30) @@ | ||
| 668 | return cls(value) |
|
| 669 | ||
| 670 | ||
| 671 | class MatchTunnelID(MatchField): |
|
| 672 | """Match for tunnel id.""" |
|
| 673 | ||
| 674 | name = 'tun_id' |
|
| 675 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_TUNNEL_ID |
|
| 676 | ||
| 677 | def as_of_tlv(self): |
|
| 678 | """Return a pyof OXM TLV instance.""" |
|
| 679 | try: |
|
| 680 | value = int(self.value) |
|
| 681 | mask = None |
|
| 682 | oxm_hasmask = False |
|
| 683 | except ValueError: |
|
| 684 | value, mask = map(int,self.value.split('/')) |
|
| 685 | oxm_hasmask = True |
|
| 686 | value_bytes = value.to_bytes(8, 'big') |
|
| 687 | if mask: |
|
| 688 | value_bytes += mask.to_bytes(8, 'big') |
|
| 689 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 690 | oxm_hasmask=oxm_hasmask, |
|
| 691 | oxm_value=value_bytes) |
|
| 692 | ||
| 693 | @classmethod |
|
| 694 | def from_of_tlv(cls, tlv): |
|
| 695 | """Return an instance from a pyof OXM TLV.""" |
|
| 696 | value = int.from_bytes(tlv.oxm_value[:8], 'big') |
|
| 697 | if tlv.oxm_hasmask: |
|
| 698 | tunnel_mask = int.from_bytes(tlv.oxm_value[8:], 'big') |
|
| 699 | value = f'{value}/{tunnel_mask}' |
|
| 700 | return cls(value) |
|
| 701 | ||
| 702 | ||
| 703 | class MatchFieldFactory(ABC): |
|
| @@ 639-668 (lines=30) @@ | ||
| 636 | return cls(bos) |
|
| 637 | ||
| 638 | ||
| 639 | class MatchMetadata(MatchField): |
|
| 640 | """Match for table metadata.""" |
|
| 641 | ||
| 642 | name = 'metadata' |
|
| 643 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_METADATA |
|
| 644 | ||
| 645 | def as_of_tlv(self): |
|
| 646 | """Return a pyof OXM TLV instance.""" |
|
| 647 | try: |
|
| 648 | value = int(self.value) |
|
| 649 | mask = None |
|
| 650 | oxm_hasmask = False |
|
| 651 | except ValueError: |
|
| 652 | value, mask = map(int, self.value.split('/')) |
|
| 653 | oxm_hasmask = True |
|
| 654 | value_bytes = value.to_bytes(8, 'big') |
|
| 655 | if mask: |
|
| 656 | value_bytes += mask.to_bytes(8, 'big') |
|
| 657 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 658 | oxm_hasmask=oxm_hasmask, |
|
| 659 | oxm_value=value_bytes) |
|
| 660 | ||
| 661 | @classmethod |
|
| 662 | def from_of_tlv(cls, tlv): |
|
| 663 | """Return an instance from a pyof OXM TLV.""" |
|
| 664 | value = int.from_bytes(tlv.oxm_value[:8], 'big') |
|
| 665 | if tlv.oxm_hasmask: |
|
| 666 | metadata_mask = int.from_bytes(tlv.oxm_value[8:], 'big') |
|
| 667 | value = f'{value}/{metadata_mask}' |
|
| 668 | return cls(value) |
|
| 669 | ||
| 670 | ||
| 671 | class MatchTunnelID(MatchField): |
|