Completed
Push — master ( 229cac...232edf )
by Thomas
10:56
created

bgp/message/update/attribute/bgpls/prefix/srrid.py (1 issue)

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
12
#    draft-gredler-idr-bgp-ls-segment-routing-ext-03
13
#    0                   1                   2                   3
14
#    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
15
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
16
#   |            Type               |            Length             |
17
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
18
#   //                  IPv4/IPv6 Address (Router-ID)              //
19
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
20
#     Source Router Identifier (Source Router-ID) TLV
21
22
23 View Code Duplication
@LINKSTATE.register()
24
class SrSourceRouterID(object):
25
    TLV = 1171
26
27
    def __init__(self, srid):
28
        self.srid = srid
29
30
    def __repr__(self):
31
        return "Source router identifier: %s" % (self.srid)
32
33
    @classmethod
34
    def unpack(cls, data, length):
35
        size = len(data)
36
        if size not in (4, 16):
37
            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...
38
39
        return cls(IP.unpack(data[:size]))
40
41
    def json(self, compact=None):
42
        return '"sr-source-router-id": "%s"' % str(self.srid)
43