Code Duplication    Length = 25-25 lines in 2 locations

v0x04/match_fields.py 2 locations

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