Code Duplication    Length = 26-26 lines in 6 locations

v0x04/match_fields.py 4 locations

@@ 516-541 (lines=26) @@
513
        return cls(value)
514
515
516
class MatchARPTPA(MatchField):
517
    """Match for ARP Target IP Address."""
518
519
    name = 'arp_tpa'
520
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_ARP_TPA
521
522
    def as_of_tlv(self):
523
        """Return a pyof OXM TLV instance."""
524
        ip_addr = IPAddress(self.value)
525
        value_bytes = ip_addr.pack()
526
        if ip_addr.netmask < 32:
527
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
528
        return OxmTLV(oxm_field=self.oxm_field,
529
                      oxm_hasmask=ip_addr.netmask < 32,
530
                      oxm_value=value_bytes)
531
532
    @classmethod
533
    def from_of_tlv(cls, tlv):
534
        """Return an instance from a pyof OXM TLV."""
535
        ip_address = IPAddress()
536
        ip_address.unpack(tlv.oxm_value)
537
        addr_str = str(ip_address)
538
        value = addr_str
539
        if tlv.oxm_hasmask:
540
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
541
        return cls(value)
542
543
544
class MatchARPSHA(MatchField):
@@ 488-513 (lines=26) @@
485
        return cls(opcode)
486
487
488
class MatchARPSPA(MatchField):
489
    """Match for ARP Sender IP Address."""
490
491
    name = 'arp_spa'
492
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_ARP_SPA
493
494
    def as_of_tlv(self):
495
        """Return a pyof OXM TLV instance."""
496
        ip_addr = IPAddress(self.value)
497
        value_bytes = ip_addr.pack()
498
        if ip_addr.netmask < 32:
499
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
500
        return OxmTLV(oxm_field=self.oxm_field,
501
                      oxm_hasmask=ip_addr.netmask < 32,
502
                      oxm_value=value_bytes)
503
504
    @classmethod
505
    def from_of_tlv(cls, tlv):
506
        """Return an instance from a pyof OXM TLV."""
507
        ip_address = IPAddress()
508
        ip_address.unpack(tlv.oxm_value)
509
        addr_str = str(ip_address)
510
        value = addr_str
511
        if tlv.oxm_hasmask:
512
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
513
        return cls(value)
514
515
516
class MatchARPTPA(MatchField):
@@ 208-233 (lines=26) @@
205
        return cls(value)
206
207
208
class MatchNwDst(MatchField):
209
    """Match for IPV4 destination."""
210
211
    name = 'nw_dst'
212
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_DST
213
214
    def as_of_tlv(self):
215
        """Return a pyof OXM TLV instance."""
216
        ip_addr = IPAddress(self.value)
217
        value_bytes = ip_addr.pack()
218
        if ip_addr.netmask < 32:
219
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
220
        return OxmTLV(oxm_field=self.oxm_field,
221
                      oxm_hasmask=ip_addr.netmask < 32,
222
                      oxm_value=value_bytes)
223
224
    @classmethod
225
    def from_of_tlv(cls, tlv):
226
        """Return an instance from a pyof OXM TLV."""
227
        ip_address = IPAddress()
228
        ip_address.unpack(tlv.oxm_value)
229
        addr_str = str(ip_address)
230
        value = addr_str
231
        if tlv.oxm_hasmask:
232
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
233
        return cls(value)
234
235
236
class MatchNwProto(MatchField):
@@ 180-205 (lines=26) @@
177
        return cls(port)
178
179
180
class MatchNwSrc(MatchField):
181
    """Match for IPV4 source."""
182
183
    name = 'nw_src'
184
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_SRC
185
186
    def as_of_tlv(self):
187
        """Return a pyof OXM TLV instance."""
188
        ip_addr = IPAddress(self.value)
189
        value_bytes = ip_addr.pack()
190
        if ip_addr.netmask < 32:
191
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
192
        return OxmTLV(oxm_field=self.oxm_field,
193
                      oxm_hasmask=ip_addr.netmask < 32,
194
                      oxm_value=value_bytes)
195
196
    @classmethod
197
    def from_of_tlv(cls, tlv):
198
        """Return an instance from a pyof OXM TLV."""
199
        ip_address = IPAddress()
200
        ip_address.unpack(tlv.oxm_value)
201
        addr_str = str(ip_address)
202
        value = addr_str
203
        if tlv.oxm_hasmask:
204
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
205
        return cls(value)
206
207
208
class MatchNwDst(MatchField):

v0x04/match_fields_ipv6.py 2 locations

@@ 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):