Completed
Push — master ( ae553d...3df76a )
by Thomas
25:18 queued 11:15
created

message/update/attribute/bgpls/link/unrsvpbw.py (1 issue)

1
# encoding: utf-8
2
"""
3
nunrsvpbw.py
4
5
Created by Evelio Vila on 2016-12-01.
6
Copyright (c) 2014-2017 Exa Networks. All rights reserved.
7
"""
8
9
from struct import unpack
10
11
from exabgp.bgp.message.notification import Notify
12
13
from exabgp.bgp.message.update.attribute.bgpls.linkstate import LINKSTATE
14
15
16
#   This sub-TLV contains the amount of bandwidth reservable in this
17
#   direction on this link.  Note that for oversubscription purposes,
18
#   this can be greater than the bandwidth of the link.
19
#    [ One value per priority]
20
#   https://tools.ietf.org/html/rfc5305#section-3.6
21
#
22
#  Units are in Bytes not Bits.
23
#  ----------------------------
24
25
26 View Code Duplication
@LINKSTATE.register()
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
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