Code Duplication    Length = 19-20 lines in 8 locations

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/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

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

@@ 26-44 (lines=19) @@
23
#  ----------------------------
24
25
26
@LINKSTATE.register()
27
class UnRsvpBw(object):
28
    TLV = 1091
29
30
    def __init__(self, unrsvpbw):
31
        self.unrsvpbw = unrsvpbw
32
33
    def __repr__(self):
34
        return "Maximum link bandwidth: %s" % (self.unrsvpbw)
35
36
    @classmethod
37
    def unpack(cls, data, length):
38
        if length != 32:
39
            raise Notify(3, 5, "Wrong Unreservable Bw metric size")
40
41
        return cls(unpack('!ffffffff', data))
42
43
    def json(self, compact=None):
44
        return '"unreserved-bandwidth": %s' % str(self.unrsvpbw)
45

lib/exabgp/bgp/message/update/attribute/bgpls/node/nodename.py 1 location

@@ 26-44 (lines=19) @@
23
#     https://tools.ietf.org/html/rfc7752 Sec 3.3.1.3.  Node Name TLV
24
25
26
@LINKSTATE.register()
27
class NodeName(object):
28
    TLV = 1026
29
30
    def __init__(self, nodename):
31
        self.nodename = nodename
32
33
    def __repr__(self):
34
        return "nodename: %s" % (self.nodename)
35
36
    @classmethod
37
    def unpack(cls, data, length):
38
        if length > 255:
39
            raise Notify(3, 5, "Node Name TLV length too large")
40
41
        return cls(data[:length].decode('ascii'))
42
43
    def json(self, compact=None):
44
        return '"node-name": "%s"' % str(self.nodename)
45

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

@@ 25-43 (lines=19) @@
22
#    https://tools.ietf.org/html/rfc7752#section-3.3.2.3 TE Metric
23
24
25
@LINKSTATE.register()
26
class TeMetric(object):
27
    TLV = 1092
28
29
    def __init__(self, temetric):
30
        self.temetric = temetric
31
32
    def __repr__(self):
33
        return "TE Default Metric: %s" % (self.temetric)
34
35
    @classmethod
36
    def unpack(cls, data, length):
37
        if len(data) != 4:
38
            raise Notify(3, 5, "Incorrect TE Metric Size")
39
40
        return cls(unpack('!L', data)[0])
41
42
    def json(self, compact=None):
43
        return '"te-metric": %d' % int(str(self.temetric))
44

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

@@ 23-41 (lines=19) @@
20
#  ----------------------------
21
22
23
@LINKSTATE.register()
24
class MaxBw(object):
25
    TLV = 1089
26
27
    def __init__(self, maxbw):
28
        self.maxbw = maxbw
29
30
    def __repr__(self):
31
        return "Maximum link bandwidth: %s" % (self.maxbw)
32
33
    @classmethod
34
    def unpack(cls, data, length):
35
        if length != 4:
36
            raise Notify(3, 5, "Incorrect maximum link bw metric")
37
38
        return cls(unpack('!f', data)[0])
39
40
    def json(self, compact=None):
41
        return '"maximum-link-bandwidth": %s' % self.maxbw
42