Completed
Push — master ( ae553d...3df76a )
by Thomas
25:18 queued 11:15
created

message/update/attribute/bgpls/node/nodename.py (1 issue)

1
# encoding: utf-8
2
"""
3
nodename.py
4
5
Created by Evelio Vila on 2016-12-01.
6
Copyright (c) 2014-2017 Exa Networks. All rights reserved.
7
"""
8
9
import binascii
10
11
from exabgp.bgp.message.notification import Notify
12
13
from exabgp.bgp.message.update.attribute.bgpls.linkstate import LINKSTATE
14
15
16
#      0                   1                   2                   3
17
#      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
18
#     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
19
#     |              Type             |             Length            |
20
#     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21
#     //                     Node Name (variable)                    //
22
#     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
23
#     https://tools.ietf.org/html/rfc7752 Sec 3.3.1.3.  Node Name TLV
24
25
26 View Code Duplication
@LINKSTATE.register()
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
27
class NodeName(object):
28
    TLV = 1026
29
30
    def __init__(self, nodename):
31
        self.nodename = nodename
32
33
    def __repr__(self):
34
        return "nodename: %s" % (self.nodename)
35
36
    @classmethod
37
    def unpack(cls, data, length):
38
        if length > 255:
39
            raise Notify(3, 5, "Node Name TLV length too large")
40
41
        return cls(data[:length].decode('ascii'))
42
43
    def json(self, compact=None):
44
        return '"node-name": "%s"' % str(self.nodename)
45