Code Duplication    Length = 23-23 lines in 2 locations

v0x04/match_fields.py 2 locations

@@ 266-288 (lines=23) @@
263
            value = f'{value}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
264
        return cls(value)
265
266
class MatchNwDst(MatchField):
267
    """Match for IPV4 destination."""
268
269
    name = 'nw_dst'
270
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_DST
271
272
    def as_of_tlv(self):
273
        """Return a pyof OXM TLV instance."""
274
        ip = IPAddress(self.value)
275
        value_bytes = ip.pack()
276
        if ip.netmask < 32:
277
            value_bytes += mask_to_bytes(ip.netmask, 32)
278
        return OxmTLV(oxm_field=self.oxm_field, oxm_hasmask = ip.netmask < 32, oxm_value=value_bytes)
279
280
    @classmethod
281
    def from_of_tlv(cls, tlv):
282
        """Return an instance from a pyof OXM TLV."""
283
        ip_address = IPAddress()
284
        ip_address.unpack(tlv.oxm_value)
285
        value = str(ip_address)
286
        if tlv.oxm_hasmask:
287
            value = f'{value}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
288
        return cls(value)
289
290
291
class MatchNwProto(MatchField):
@@ 242-264 (lines=23) @@
239
        return cls(port)
240
241
242
class MatchNwSrc(MatchField):
243
    """Match for IPV4 source."""
244
245
    name = 'nw_src'
246
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_SRC
247
248
    def as_of_tlv(self):
249
        """Return a pyof OXM TLV instance."""
250
        ip = IPAddress(self.value)
251
        value_bytes = ip.pack()
252
        if ip.netmask < 32:
253
            value_bytes += mask_to_bytes(ip.netmask, 32)
254
        return OxmTLV(oxm_field=self.oxm_field, oxm_hasmask = ip.netmask < 32, oxm_value=value_bytes)
255
256
    @classmethod
257
    def from_of_tlv(cls, tlv):
258
        """Return an instance from a pyof OXM TLV."""
259
        ip_address = IPAddress()
260
        ip_address.unpack(tlv.oxm_value)
261
        value = str(ip_address)
262
        if tlv.oxm_hasmask:
263
            value = f'{value}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
264
        return cls(value)
265
266
class MatchNwDst(MatchField):
267
    """Match for IPV4 destination."""