Completed
Push — master ( 5af33a...81e1b1 )
by Thomas
13:24
created

SrSourceRouterID.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 2
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 2
loc 2
rs 10
c 0
b 0
f 0
1
# encoding: utf-8
2
"""
3
srrid.py
4
5
Created by Evelio Vila
6
Copyright (c) 2014-2017 Exa Networks. All rights reserved.
7
"""
8
9
from exabgp.protocol.ip import IP
10
from exabgp.bgp.message.update.attribute.bgpls.linkstate import LinkState
11
from exabgp.bgp.message.update.attribute.bgpls.linkstate import BaseLS
12
13
#    draft-gredler-idr-bgp-ls-segment-routing-ext-03
14
#    0                   1                   2                   3
15
#    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
16
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17
#   |            Type               |            Length             |
18
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
19
#   //                  IPv4/IPv6 Address (Router-ID)              //
20
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21
#     Source Router Identifier (Source Router-ID) TLV
22
23
24
@LinkState.register()
25
class SrSourceRouterID(BaseLS):
26
    TLV = 1171
27
    REPR = 'Source router identifier'
28
    JSON = 'sr-source-router-id'
29
30
    @classmethod
31
    def unpack(cls, data, length):
32
        size = len(data)
33
        if size not in (4, 16):
34
            raise Notify(3, 5, "Error parsing SR Source Router ID. Wrong size")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Notify does not seem to be defined.
Loading history...
35
        return cls(IP.unpack(data[:size]))
36