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

LocalTeRid.merge()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
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
from exabgp.protocol.ip import IP
10
from exabgp.bgp.message.notification import Notify
11
12
from exabgp.bgp.message.update.attribute.bgpls.linkstate import LinkState
13
14
15
#   |     1028    | IPv4 Router-ID of    |        4 | [RFC5305]/4.3     |
16
#   |             | Local Node           |          |                   |
17
#   |     1029    | IPv6 Router-ID of    |       16 | [RFC6119]/4.1     |
18
#   |             | Local Node           |          |                   |
19
#   +-------------+----------------------+----------+-------------------+
20
#   https://tools.ietf.org/html/rfc7752 sec 3.3.1.4  - Traffic Engineering RouterID
21
22
23
@LinkState.register(lsid=1028)
24
@LinkState.register(lsid=1029)
25
class LocalTeRid(object):
26
    MERGE = True
27
28
    def __init__(self, terids):
29
        self.terids = terids
30
31
    def __repr__(self):
32
        return "Local TE Router IDs: %s" % ', '.join(self.terids)
33
34
    @classmethod
35
    def unpack(cls, data, length):
36
        size = len(data)
37
38
        if size not in (4, 16):
39
            raise Notify(3, 5, "Invalid remote-te size")
40
41
        return cls([str(IP.unpack(data[:size]))])
42
43
    def json(self, compact=None):
44
        return '"local-te-router-ids": ["%s"]' % '", "'.join(self.terids)
45
46
    def merge(self, klass):
47
        self.terids.extend(klass.terids)
48