Completed
Pull Request — master (#960)
by
unknown
10:43
created

LocalTeRid.reset()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
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
@LINKSTATE.register(lsid=1028)
23
@LINKSTATE.register(lsid=1029)
24
class LocalTeRid(object):
25
	_terids = []
26
27
	def __init__ (self):
28
		self.terids = [str(terid) for terid in LocalTeRid._terids]
29
30
	def __repr__ (self):
31
		return "Local TE Router IDs: %s" % ', '.join(self.terids)
32
33
	@classmethod
34
	def unpack (cls,data,length):
35
		if len(data) == 4:
36
			# IPv4 address
37
			terid = IP.unpack(data[:4])
38
		elif len(data) == 16:
39
			# IPv6
40
			terid = IP.unpack(data[:16])
41
		cls._terids.append(terid)
0 ignored issues
show
introduced by
The variable terid does not seem to be defined for all execution paths.
Loading history...
42
		return cls()
43
44
	def json (self,compact=None):
45
		return '"local-te-router-ids": ["%s"]' % '", "'.join(self.terids)
46
47
	@classmethod
48
	def reset(cls):
49
	    cls._terids = []
50