Code Duplication    Length = 26-26 lines in 6 locations

v0x04/match_fields.py 6 locations

@@ 557-582 (lines=26) @@
554
        return cls(value)
555
556
557
class MatchIPV6Dst(MatchField):
558
    """Match for IPV6 destination."""
559
560
    name = 'ipv6_dst'
561
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV6_DST
562
563
    def as_of_tlv(self):
564
        """Return a pyof OXM TLV instance."""
565
        ip_addr = IPV6Address(self.value)
566
        value_bytes = ip_addr.pack()
567
        if ip_addr.netmask < 128:
568
            value_bytes += mask_to_bytes(ip_addr.netmask, 128)
569
        return OxmTLV(oxm_field=self.oxm_field,
570
                      oxm_hasmask=ip_addr.netmask < 128,
571
                      oxm_value=value_bytes)
572
573
    @classmethod
574
    def from_of_tlv(cls, tlv):
575
        """Return an instance from a pyof OXM TLV."""
576
        ip_address = IPV6Address()
577
        ip_address.unpack(tlv.oxm_value)
578
        addr_str = str(ip_address)
579
        value = addr_str
580
        if tlv.oxm_hasmask:
581
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[16:], 128)}'
582
        return cls(value)
583
584
585
class MatchMPLSLabel(MatchField):
@@ 529-554 (lines=26) @@
526
        return cls(value)
527
528
529
class MatchIPV6Src(MatchField):
530
    """Match for IPV6 source."""
531
532
    name = 'ipv6_src'
533
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV6_SRC
534
535
    def as_of_tlv(self):
536
        """Return a pyof OXM TLV instance."""
537
        ip_addr = IPV6Address(self.value)
538
        value_bytes = ip_addr.pack()
539
        if ip_addr.netmask < 128:
540
            value_bytes += mask_to_bytes(ip_addr.netmask, 128)
541
        return OxmTLV(oxm_field=self.oxm_field,
542
                      oxm_hasmask=ip_addr.netmask < 128,
543
                      oxm_value=value_bytes)
544
545
    @classmethod
546
    def from_of_tlv(cls, tlv):
547
        """Return an instance from a pyof OXM TLV."""
548
        ip_address = IPV6Address()
549
        ip_address.unpack(tlv.oxm_value)
550
        addr_str = str(ip_address)
551
        value = addr_str
552
        if tlv.oxm_hasmask:
553
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[16:], 128)}'
554
        return cls(value)
555
556
557
class MatchIPV6Dst(MatchField):
@@ 417-442 (lines=26) @@
414
        return cls(value)
415
416
417
class MatchARPTPA(MatchField):
418
    """Match for ARP Target IP Address."""
419
420
    name = 'arp_tpa'
421
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_ARP_TPA
422
423
    def as_of_tlv(self):
424
        """Return a pyof OXM TLV instance."""
425
        ip_addr = IPAddress(self.value)
426
        value_bytes = ip_addr.pack()
427
        if ip_addr.netmask < 32:
428
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
429
        return OxmTLV(oxm_field=self.oxm_field,
430
                      oxm_hasmask=ip_addr.netmask < 32,
431
                      oxm_value=value_bytes)
432
433
    @classmethod
434
    def from_of_tlv(cls, tlv):
435
        """Return an instance from a pyof OXM TLV."""
436
        ip_address = IPAddress()
437
        ip_address.unpack(tlv.oxm_value)
438
        addr_str = str(ip_address)
439
        value = addr_str
440
        if tlv.oxm_hasmask:
441
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
442
        return cls(value)
443
444
445
class MatchARPSHA(MatchField):
@@ 389-414 (lines=26) @@
386
        return cls(priority)
387
388
389
class MatchARPSPA(MatchField):
390
    """Match for ARP Sender IP Address."""
391
392
    name = 'arp_spa'
393
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_ARP_SPA
394
395
    def as_of_tlv(self):
396
        """Return a pyof OXM TLV instance."""
397
        ip_addr = IPAddress(self.value)
398
        value_bytes = ip_addr.pack()
399
        if ip_addr.netmask < 32:
400
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
401
        return OxmTLV(oxm_field=self.oxm_field,
402
                      oxm_hasmask=ip_addr.netmask < 32,
403
                      oxm_value=value_bytes)
404
405
    @classmethod
406
    def from_of_tlv(cls, tlv):
407
        """Return an instance from a pyof OXM TLV."""
408
        ip_address = IPAddress()
409
        ip_address.unpack(tlv.oxm_value)
410
        addr_str = str(ip_address)
411
        value = addr_str
412
        if tlv.oxm_hasmask:
413
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
414
        return cls(value)
415
416
417
class MatchARPTPA(MatchField):
@@ 253-278 (lines=26) @@
250
        return cls(value)
251
252
253
class MatchNwDst(MatchField):
254
    """Match for IPV4 destination."""
255
256
    name = 'nw_dst'
257
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_DST
258
259
    def as_of_tlv(self):
260
        """Return a pyof OXM TLV instance."""
261
        ip_addr = IPAddress(self.value)
262
        value_bytes = ip_addr.pack()
263
        if ip_addr.netmask < 32:
264
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
265
        return OxmTLV(oxm_field=self.oxm_field,
266
                      oxm_hasmask=ip_addr.netmask < 32,
267
                      oxm_value=value_bytes)
268
269
    @classmethod
270
    def from_of_tlv(cls, tlv):
271
        """Return an instance from a pyof OXM TLV."""
272
        ip_address = IPAddress()
273
        ip_address.unpack(tlv.oxm_value)
274
        addr_str = str(ip_address)
275
        value = addr_str
276
        if tlv.oxm_hasmask:
277
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
278
        return cls(value)
279
280
281
class MatchNwProto(MatchField):
@@ 225-250 (lines=26) @@
222
        return cls(port)
223
224
225
class MatchNwSrc(MatchField):
226
    """Match for IPV4 source."""
227
228
    name = 'nw_src'
229
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_SRC
230
231
    def as_of_tlv(self):
232
        """Return a pyof OXM TLV instance."""
233
        ip_addr = IPAddress(self.value)
234
        value_bytes = ip_addr.pack()
235
        if ip_addr.netmask < 32:
236
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
237
        return OxmTLV(oxm_field=self.oxm_field,
238
                      oxm_hasmask=ip_addr.netmask < 32,
239
                      oxm_value=value_bytes)
240
241
    @classmethod
242
    def from_of_tlv(cls, tlv):
243
        """Return an instance from a pyof OXM TLV."""
244
        ip_address = IPAddress()
245
        ip_address.unpack(tlv.oxm_value)
246
        addr_str = str(ip_address)
247
        value = addr_str
248
        if tlv.oxm_hasmask:
249
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
250
        return cls(value)
251
252
253
class MatchNwDst(MatchField):