| @@ 38-63 (lines=26) @@ | ||
| 35 | return cls(value) |
|
| 36 | ||
| 37 | ||
| 38 | class MatchIPv6Dst(MatchField): |
|
| 39 | """Match for IPv6 destination.""" |
|
| 40 | ||
| 41 | name = 'ipv6_dst' |
|
| 42 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV6_DST |
|
| 43 | ||
| 44 | def as_of_tlv(self): |
|
| 45 | """Return a pyof OXM TLV instance.""" |
|
| 46 | ip_addr = IPv6Address(self.value) |
|
| 47 | value_bytes = ip_addr.pack() |
|
| 48 | if ip_addr.netmask < 128: |
|
| 49 | value_bytes += mask_to_bytes(ip_addr.netmask, 128) |
|
| 50 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 51 | oxm_hasmask=ip_addr.netmask < 128, |
|
| 52 | oxm_value=value_bytes) |
|
| 53 | ||
| 54 | @classmethod |
|
| 55 | def from_of_tlv(cls, tlv): |
|
| 56 | """Return an instance from a pyof OXM TLV.""" |
|
| 57 | ip_address = IPv6Address() |
|
| 58 | ip_address.unpack(tlv.oxm_value) |
|
| 59 | addr_str = str(ip_address) |
|
| 60 | value = addr_str |
|
| 61 | if tlv.oxm_hasmask: |
|
| 62 | value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[16:], 128)}' |
|
| 63 | return cls(value) |
|
| 64 | ||
| 65 | ||
| 66 | class MatchIPv6FLabel(MatchField): |
|
| @@ 10-35 (lines=26) @@ | ||
| 7 | from napps.kytos.of_core.v0x04.utils import bytes_to_mask, mask_to_bytes |
|
| 8 | ||
| 9 | ||
| 10 | class MatchIPv6Src(MatchField): |
|
| 11 | """Match for IPv6 source.""" |
|
| 12 | ||
| 13 | name = 'ipv6_src' |
|
| 14 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV6_SRC |
|
| 15 | ||
| 16 | def as_of_tlv(self): |
|
| 17 | """Return a pyof OXM TLV instance.""" |
|
| 18 | ip_addr = IPv6Address(self.value) |
|
| 19 | value_bytes = ip_addr.pack() |
|
| 20 | if ip_addr.netmask < 128: |
|
| 21 | value_bytes += mask_to_bytes(ip_addr.netmask, 128) |
|
| 22 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 23 | oxm_hasmask=ip_addr.netmask < 128, |
|
| 24 | oxm_value=value_bytes) |
|
| 25 | ||
| 26 | @classmethod |
|
| 27 | def from_of_tlv(cls, tlv): |
|
| 28 | """Return an instance from a pyof OXM TLV.""" |
|
| 29 | ip_address = IPv6Address() |
|
| 30 | ip_address.unpack(tlv.oxm_value) |
|
| 31 | addr_str = str(ip_address) |
|
| 32 | value = addr_str |
|
| 33 | if tlv.oxm_hasmask: |
|
| 34 | value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[16:], 128)}' |
|
| 35 | return cls(value) |
|
| 36 | ||
| 37 | ||
| 38 | class MatchIPv6Dst(MatchField): |
|
| @@ 521-546 (lines=26) @@ | ||
| 518 | return cls(value) |
|
| 519 | ||
| 520 | ||
| 521 | class MatchARPTPA(MatchField): |
|
| 522 | """Match for ARP Target IP Address.""" |
|
| 523 | ||
| 524 | name = 'arp_tpa' |
|
| 525 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_ARP_TPA |
|
| 526 | ||
| 527 | def as_of_tlv(self): |
|
| 528 | """Return a pyof OXM TLV instance.""" |
|
| 529 | ip_addr = IPAddress(self.value) |
|
| 530 | value_bytes = ip_addr.pack() |
|
| 531 | if ip_addr.netmask < 32: |
|
| 532 | value_bytes += mask_to_bytes(ip_addr.netmask, 32) |
|
| 533 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 534 | oxm_hasmask=ip_addr.netmask < 32, |
|
| 535 | oxm_value=value_bytes) |
|
| 536 | ||
| 537 | @classmethod |
|
| 538 | def from_of_tlv(cls, tlv): |
|
| 539 | """Return an instance from a pyof OXM TLV.""" |
|
| 540 | ip_address = IPAddress() |
|
| 541 | ip_address.unpack(tlv.oxm_value) |
|
| 542 | addr_str = str(ip_address) |
|
| 543 | value = addr_str |
|
| 544 | if tlv.oxm_hasmask: |
|
| 545 | value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}' |
|
| 546 | return cls(value) |
|
| 547 | ||
| 548 | ||
| 549 | class MatchARPSHA(MatchField): |
|
| @@ 493-518 (lines=26) @@ | ||
| 490 | return cls(opcode) |
|
| 491 | ||
| 492 | ||
| 493 | class MatchARPSPA(MatchField): |
|
| 494 | """Match for ARP Sender IP Address.""" |
|
| 495 | ||
| 496 | name = 'arp_spa' |
|
| 497 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_ARP_SPA |
|
| 498 | ||
| 499 | def as_of_tlv(self): |
|
| 500 | """Return a pyof OXM TLV instance.""" |
|
| 501 | ip_addr = IPAddress(self.value) |
|
| 502 | value_bytes = ip_addr.pack() |
|
| 503 | if ip_addr.netmask < 32: |
|
| 504 | value_bytes += mask_to_bytes(ip_addr.netmask, 32) |
|
| 505 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 506 | oxm_hasmask=ip_addr.netmask < 32, |
|
| 507 | oxm_value=value_bytes) |
|
| 508 | ||
| 509 | @classmethod |
|
| 510 | def from_of_tlv(cls, tlv): |
|
| 511 | """Return an instance from a pyof OXM TLV.""" |
|
| 512 | ip_address = IPAddress() |
|
| 513 | ip_address.unpack(tlv.oxm_value) |
|
| 514 | addr_str = str(ip_address) |
|
| 515 | value = addr_str |
|
| 516 | if tlv.oxm_hasmask: |
|
| 517 | value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}' |
|
| 518 | return cls(value) |
|
| 519 | ||
| 520 | ||
| 521 | class MatchARPTPA(MatchField): |
|
| @@ 213-238 (lines=26) @@ | ||
| 210 | return cls(value) |
|
| 211 | ||
| 212 | ||
| 213 | class MatchNwDst(MatchField): |
|
| 214 | """Match for IPV4 destination.""" |
|
| 215 | ||
| 216 | name = 'nw_dst' |
|
| 217 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_DST |
|
| 218 | ||
| 219 | def as_of_tlv(self): |
|
| 220 | """Return a pyof OXM TLV instance.""" |
|
| 221 | ip_addr = IPAddress(self.value) |
|
| 222 | value_bytes = ip_addr.pack() |
|
| 223 | if ip_addr.netmask < 32: |
|
| 224 | value_bytes += mask_to_bytes(ip_addr.netmask, 32) |
|
| 225 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 226 | oxm_hasmask=ip_addr.netmask < 32, |
|
| 227 | oxm_value=value_bytes) |
|
| 228 | ||
| 229 | @classmethod |
|
| 230 | def from_of_tlv(cls, tlv): |
|
| 231 | """Return an instance from a pyof OXM TLV.""" |
|
| 232 | ip_address = IPAddress() |
|
| 233 | ip_address.unpack(tlv.oxm_value) |
|
| 234 | addr_str = str(ip_address) |
|
| 235 | value = addr_str |
|
| 236 | if tlv.oxm_hasmask: |
|
| 237 | value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}' |
|
| 238 | return cls(value) |
|
| 239 | ||
| 240 | ||
| 241 | class MatchNwProto(MatchField): |
|
| @@ 185-210 (lines=26) @@ | ||
| 182 | return cls(port) |
|
| 183 | ||
| 184 | ||
| 185 | class MatchNwSrc(MatchField): |
|
| 186 | """Match for IPV4 source.""" |
|
| 187 | ||
| 188 | name = 'nw_src' |
|
| 189 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_SRC |
|
| 190 | ||
| 191 | def as_of_tlv(self): |
|
| 192 | """Return a pyof OXM TLV instance.""" |
|
| 193 | ip_addr = IPAddress(self.value) |
|
| 194 | value_bytes = ip_addr.pack() |
|
| 195 | if ip_addr.netmask < 32: |
|
| 196 | value_bytes += mask_to_bytes(ip_addr.netmask, 32) |
|
| 197 | return OxmTLV(oxm_field=self.oxm_field, |
|
| 198 | oxm_hasmask=ip_addr.netmask < 32, |
|
| 199 | oxm_value=value_bytes) |
|
| 200 | ||
| 201 | @classmethod |
|
| 202 | def from_of_tlv(cls, tlv): |
|
| 203 | """Return an instance from a pyof OXM TLV.""" |
|
| 204 | ip_address = IPAddress() |
|
| 205 | ip_address.unpack(tlv.oxm_value) |
|
| 206 | addr_str = str(ip_address) |
|
| 207 | value = addr_str |
|
| 208 | if tlv.oxm_hasmask: |
|
| 209 | value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}' |
|
| 210 | return cls(value) |
|
| 211 | ||
| 212 | ||
| 213 | class MatchNwDst(MatchField): |
|