1 | # encoding: utf-8 |
||
2 | """ |
||
3 | maxbw.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 | from exabgp.bgp.message.update.attribute.bgpls.linkstate import LINKSTATE |
||
13 | |||
14 | # This sub-TLV contains the maximum bandwidth that can be used on this |
||
15 | # link in this direction (from the system originating the LSP to its |
||
16 | # neighbors). |
||
17 | # https://tools.ietf.org/html/rfc5305#section-3.4 |
||
18 | # |
||
19 | # Units are in Bytes not Bits. |
||
20 | # ---------------------------- |
||
21 | |||
22 | |||
23 | View Code Duplication | @LINKSTATE.register() |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
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 |