1 | # encoding: utf-8 |
||
2 | """ |
||
3 | temetric.py |
||
4 | |||
5 | Created by Evelio Vila on 2016-12-01. |
||
6 | Copyright (c) 2014-2017 Exa Networks. All rights reserved. |
||
7 | """ |
||
8 | from struct import unpack |
||
9 | |||
10 | from exabgp.bgp.message.notification import Notify |
||
11 | |||
12 | from exabgp.bgp.message.update.attribute.bgpls.linkstate import LINKSTATE |
||
13 | |||
14 | |||
15 | # 0 1 2 3 |
||
16 | # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
||
17 | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
18 | # | Type | Length | |
||
19 | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
20 | # | TE Default Link Metric | |
||
21 | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
22 | # https://tools.ietf.org/html/rfc7752#section-3.3.2.3 TE Metric |
||
23 | |||
24 | |||
25 | View Code Duplication | @LINKSTATE.register() |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
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 |