Code Duplication    Length = 30-30 lines in 2 locations

v0x04/match_fields.py 2 locations

@@ 421-450 (lines=30) @@
418
        return cls(value)
419
420
421
class MatchPBBISID(MatchField):
422
    """Match for PBB ISID."""
423
424
    name = 'pbb_isid'
425
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_PBB_ISID
426
427
    def as_of_tlv(self):
428
        """Return a pyof OXM TLV instance."""
429
        try:
430
            value = int(self.value)
431
            mask = None
432
            oxm_hasmask = False
433
        except ValueError:
434
            value, mask = map(int, self.value.split('/'))
435
            oxm_hasmask = True
436
        value_bytes = value.to_bytes(3, 'big')
437
        if mask:
438
            value_bytes += mask.to_bytes(3, 'big')
439
        return OxmTLV(oxm_field=self.oxm_field,
440
                      oxm_hasmask=oxm_hasmask,
441
                      oxm_value=value_bytes)
442
443
    @classmethod
444
    def from_of_tlv(cls, tlv):
445
        """Return an instance from a pyof OXM TLV."""
446
        value = int.from_bytes(tlv.oxm_value[:3], 'big')
447
        if tlv.oxm_hasmask:
448
            pbb_isid_mask = int.from_bytes(tlv.oxm_value[3:], 'big')
449
            value = f'{value}/{pbb_isid_mask}'
450
        return cls(value)
451
    
452
    
453
class MatchFieldFactory(ABC):
@@ 389-418 (lines=30) @@
386
        return cls(priority)
387
388
389
class MatchIVP6FLabel(MatchField):
390
    """Match for IPV6 Flow Label."""
391
392
    name = 'ipv6_flabel'
393
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV6_FLABEL
394
395
    def as_of_tlv(self):
396
        """Return a pyof OXM TLV instance."""
397
        try:
398
            value = int(self.value)
399
            mask = None
400
            oxm_hasmask = False
401
        except ValueError:
402
            value, mask = map(int, self.value.split('/'))
403
            oxm_hasmask = True
404
        value_bytes = value.to_bytes(4, 'big')
405
        if mask:
406
            value_bytes += mask.to_bytes(4, 'big')
407
        return OxmTLV(oxm_field=self.oxm_field,
408
                      oxm_hasmask=oxm_hasmask,
409
                      oxm_value=value_bytes)
410
411
    @classmethod
412
    def from_of_tlv(cls, tlv):
413
        """Return an instance from a pyof OXM TLV."""
414
        value = int.from_bytes(tlv.oxm_value[:4], 'big')
415
        if tlv.oxm_hasmask:
416
            flabel_mask = int.from_bytes(tlv.oxm_value[4:], 'big')
417
            value = f'{value}/{flabel_mask}'
418
        return cls(value)
419
420
421
class MatchPBBISID(MatchField):