Completed
Push — master ( 3df76a...5af33a )
by Thomas
10:27
created

Srlg.unpack()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# encoding: utf-8
2
"""
3
srlg.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
from exabgp.util import split
11
12
from exabgp.bgp.message.notification import Notify
13
14
from exabgp.bgp.message.update.attribute.bgpls.linkstate import LinkState
15
from exabgp.bgp.message.update.attribute.bgpls.linkstate import BaseLS
16
17
18
#      0                   1                   2                   3
19
#      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
20
#     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21
#     |              Type             |             Length            |
22
#     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
23
#     |                  Shared Risk Link Group Value                 |
24
#     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25
#     //                         ............                        //
26
#     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27
#     |                  Shared Risk Link Group Value                 |
28
#     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29
#     https://tools.ietf.org/html/rfc7752#section-3.3.2.5 Shared Risk Link Group TLV
30
31
32
@LinkState.register()
33
class Srlg(BaseLS):
34
    TLV = 1096
35
    REPR = 'link SRLG values'
36
    JSON = 'shared-risk-link-groups'
37
38
    @classmethod
39
    def unpack(cls, data, length):
40
        if len(data) % 4:
41
            raise Notify(3, 5, "Unable to decode SRLG")
42
        return cls([unpack('!L', _)[0] for _ in split(data, 4)])
43