Code Duplication    Length = 26-26 lines in 2 locations

v0x04/match_fields.py 2 locations

@@ 252-277 (lines=26) @@
249
        return cls(value)
250
251
252
class MatchNwDst(MatchField):
253
    """Match for IPV4 destination."""
254
255
    name = 'nw_dst'
256
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_DST
257
258
    def as_of_tlv(self):
259
        """Return a pyof OXM TLV instance."""
260
        ip_addr = IPAddress(self.value)
261
        value_bytes = ip_addr.pack()
262
        if ip_addr.netmask < 32:
263
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
264
        return OxmTLV(oxm_field=self.oxm_field,
265
                      oxm_hasmask=ip_addr.netmask < 32,
266
                      oxm_value=value_bytes)
267
268
    @classmethod
269
    def from_of_tlv(cls, tlv):
270
        """Return an instance from a pyof OXM TLV."""
271
        ip_address = IPAddress()
272
        ip_address.unpack(tlv.oxm_value)
273
        addr_str = str(ip_address)
274
        value = addr_str
275
        if tlv.oxm_hasmask:
276
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
277
        return cls(value)
278
279
280
class MatchNwProto(MatchField):
@@ 224-249 (lines=26) @@
221
        return cls(port)
222
223
224
class MatchNwSrc(MatchField):
225
    """Match for IPV4 source."""
226
227
    name = 'nw_src'
228
    oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_SRC
229
230
    def as_of_tlv(self):
231
        """Return a pyof OXM TLV instance."""
232
        ip_addr = IPAddress(self.value)
233
        value_bytes = ip_addr.pack()
234
        if ip_addr.netmask < 32:
235
            value_bytes += mask_to_bytes(ip_addr.netmask, 32)
236
        return OxmTLV(oxm_field=self.oxm_field,
237
                      oxm_hasmask=ip_addr.netmask < 32,
238
                      oxm_value=value_bytes)
239
240
    @classmethod
241
    def from_of_tlv(cls, tlv):
242
        """Return an instance from a pyof OXM TLV."""
243
        ip_address = IPAddress()
244
        ip_address.unpack(tlv.oxm_value)
245
        addr_str = str(ip_address)
246
        value = addr_str
247
        if tlv.oxm_hasmask:
248
            value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}'
249
        return cls(value)
250
251
252
class MatchNwDst(MatchField):