Code Duplication    Length = 19-21 lines in 6 locations

lib/exabgp/bgp/message/update/attribute/bgpls/link/rterid.py 1 location

@@ 21-41 (lines=21) @@
18
#   |           | Remote Node         |              |                  |
19
20
21
@LinkState.register(lsid=1030)
22
@LinkState.register(lsid=1031)
23
class RemoteTeRid(object):
24
    def __init__(self, terid):
25
        self.terid = terid
26
27
    def __repr__(self):
28
        return "Remote TE Router ID: %s" % (self.terid)
29
30
    @classmethod
31
    def unpack(cls, data, length):
32
        size = len(data)
33
34
        if size not in (4, 16):
35
            raise Notify(3, 5, "Invalid remote-te size")
36
37
        terid = IP.unpack(data[:size])
38
        return cls(terid=terid)
39
40
    def json(self, compact=None):
41
        return '"remote-te-router-id": "%s"' % str(self.terid)
42

lib/exabgp/bgp/message/update/attribute/bgpls/link/rsvpbw.py 1 location

@@ 26-45 (lines=20) @@
23
#  ----------------------------
24
25
26
@LinkState.register()
27
class RsvpBw(object):
28
    TLV = 1090
29
30
    def __init__(self, rsvpbw):
31
        self.rsvpbw = rsvpbw
32
33
    def __repr__(self):
34
        return "Maximum reservable link bandwidth: %s" % (self.rsvpbw)
35
36
    @classmethod
37
    def unpack(cls, data, length):
38
        if len(data) != 4:
39
            raise Notify(3, 5, "Incorrect maximum reservable link bw metric")
40
41
        rsvpbw = unpack('!f', data)[0]
42
        return cls(rsvpbw=rsvpbw)
43
44
    def json(self, compact=None):
45
        return '"maximum-reservable-link-bandwidth": %s' % str(self.rsvpbw)
46

lib/exabgp/bgp/message/update/attribute/bgpls/prefix/ospfaddr.py 1 location

@@ 24-43 (lines=20) @@
21
#     https://tools.ietf.org/html/rfc7752#section-3.3.3.5
22
23
24
@LinkState.register()
25
class OspfForwardingAddress(object):
26
    TLV = 1156
27
28
    def __init__(self, addr):
29
        self.addr = addr
30
31
    def __repr__(self):
32
        return "Ospf forwarding address: '%s'" % (self.addr)
33
34
    @classmethod
35
    def unpack(cls, data, length):
36
        size = len(data)
37
        if size not in (4, 16):
38
            raise Notify(3, 5, "Error parsing OSPF Forwarding Address. Wrong size")
39
40
        return cls(IP.unpack(data[:size]))
41
42
    def json(self, compact=None):
43
        return '"ospf-forwarding-address": "%s"' % str(self.addr)
44

lib/exabgp/bgp/message/update/attribute/bgpls/prefix/srrid.py 1 location

@@ 23-42 (lines=20) @@
20
#     Source Router Identifier (Source Router-ID) TLV
21
22
23
@LinkState.register()
24
class SrSourceRouterID(object):
25
    TLV = 1171
26
27
    def __init__(self, srid):
28
        self.srid = srid
29
30
    def __repr__(self):
31
        return "Source router identifier: %s" % (self.srid)
32
33
    @classmethod
34
    def unpack(cls, data, length):
35
        size = len(data)
36
        if size not in (4, 16):
37
            raise Notify(3, 5, "Error parsing SR Source Router ID. Wrong size")
38
39
        return cls(IP.unpack(data[:size]))
40
41
    def json(self, compact=None):
42
        return '"sr-source-router-id": "%s"' % str(self.srid)
43

lib/exabgp/bgp/message/update/attribute/bgpls/link/admingroup.py 1 location

@@ 15-34 (lines=20) @@
12
from exabgp.bgp.message.update.attribute.bgpls.linkstate import LinkState
13
14
15
@LinkState.register()
16
class AdminGroup(object):
17
    TLV = 1088
18
19
    def __init__(self, colormask):
20
        self.colormask = colormask
21
22
    def __repr__(self):
23
        return "Admin Group mask: %s" % (self.colormask)
24
25
    @classmethod
26
    def unpack(cls, data, length):
27
        if length != 4:
28
            raise Notify(3, 5, "Unable to decode attribute. Incorrect Size")
29
30
        colormask = unpack('!L', data[:4])[0]
31
        return cls(colormask=colormask)
32
33
    def json(self, compact=None):
34
        return '"admin-group-mask": %s' % self.colormask
35

lib/exabgp/bgp/message/update/attribute/bgpls/prefix/prefixmetric.py 1 location

@@ 26-44 (lines=19) @@
23
#     https://tools.ietf.org/html/rfc7752#section-3.3.3.4
24
25
26
@LinkState.register()
27
class PrefixMetric(object):
28
    TLV = 1155
29
30
    def __init__(self, prefixmetric):
31
        self.prefixmetric = prefixmetric
32
33
    def __repr__(self):
34
        return "prefix_metric: %s" % (self.prefixmetric)
35
36
    @classmethod
37
    def unpack(cls, data, length):
38
        if length != 4:
39
            raise Notify(3, 5, "Incorrect Prefix Metric size")
40
41
        return cls(unpack("!L", data)[0])
42
43
    def json(self, compact=None):
44
        return '"prefix-metric": %d' % int(self.prefixmetric)
45