Code Duplication    Length = 51-55 lines in 2 locations

lib/exabgp/bgp/message/update/attribute/bgpls/link/sradjlan.py 1 location

@@ 38-92 (lines=55) @@
35
#   +---------------------------------------------------------------+
36
#		draft-gredler-idr-bgp-ls-segment-routing-ext-03
37
38
@LINKSTATE.register()
39
class SrAdjacencyLan(object):
40
	TLV = 1100
41
	_sr_adj_lan_sids = []
42
43
	def __init__ (self):
44
		self.sr_adj_lan_sids = SrAdjacencyLan._sr_adj_lan_sids.copy()
45
46
	def __repr__ (self):
47
		return "sr-adj-lan-sids: {}".format(self.sr_adj_lan_sids)
48
49
	@classmethod
50
	def unpack (cls,data,length):
51
		# We only support IS-IS flags for now.
52
		flags = LsGenericFlags.unpack(data[0:1],LsGenericFlags.ISIS_SR_ADJ_FLAGS).flags
53
		# Parse adj weight
54
		weight = six.indexbytes(data,1)
55
		# Parse neighbor System-ID
56
		system_id = ISO.unpack_sysid(data[4:10])
57
		# Move pointer 10 bytes: Flags(1) + Weight(1) + Reserved(2) + System-ID(6)
58
		data = data[10:]
59
     	# SID/Index/Label: according to the V and L flags, it contains
60
      	# either:
61
		# *  A 3 octet local label where the 20 rightmost bits are used for
62
		#	 encoding the label value.  In this case the V and L flags MUST
63
		#	 be set.
64
		#
65
		# *  A 4 octet index defining the offset in the SID/Label space
66
		# 	 advertised by this router using the encodings defined in
67
		#  	 Section 3.1.  In this case V and L flags MUST be unset.
68
		raw = []
69
		while data:
70
			# Range Size: 3 octet value indicating the number of labels in
71
			# the range.
72
			if int(flags['V']) and int(flags['L']):
73
				b = BitArray(bytes=data[:3])
74
				sid = b.unpack('uintbe:24')[0]
75
				data = data[3:]
76
			elif (not flags['V']) and (not flags['L']):
77
				sid = unpack('!I',data[:4])[0]
78
				data = data[4:]
79
			else:
80
				raw.append(hexstring(data))
81
				break
82
		cls._sr_adj_lan_sids.append(
83
			{'flags': flags, 'weight': weight, 'system-id': system_id, 'sid': sid, 'undecoded': raw}
84
		)
85
		return cls()
86
87
	def json (self,compact=None):
88
		return '"sr-adj-lan-sids": {}'.format(json.dumps(self.sr_adj_lan_sids))
89
90
	@classmethod
91
	def reset(cls):
92
		cls._sr_adj_sids = []
93

lib/exabgp/bgp/message/update/attribute/bgpls/link/sradj.py 1 location

@@ 29-79 (lines=51) @@
26
#   +---------------------------------------------------------------+
27
#
28
29
@LINKSTATE.register()
30
class SrAdjacency(object):
31
	TLV = 1099
32
	_sr_adj_sids = []
33
34
	def __init__ (self):
35
		self.sr_adj_sids = SrAdjacency._sr_adj_sids.copy()
36
37
	def __repr__ (self):
38
		return "sr-adj-sids: {}".format(self.sr_adj_sids)
39
40
	@classmethod
41
	def unpack (cls,data,length):
42
		# We only support IS-IS flags for now.
43
		flags = LsGenericFlags.unpack(data[0:1],LsGenericFlags.ISIS_SR_ADJ_FLAGS).flags
44
		# Parse adj weight
45
		weight = six.indexbytes(data,1)
46
		# Move pointer 4 bytes: Flags(1) + Weight(1) + Reserved(2)
47
		data = data[4:]
48
     	# SID/Index/Label: according to the V and L flags, it contains
49
      	# either:
50
		# *  A 3 octet local label where the 20 rightmost bits are used for
51
		#	 encoding the label value.  In this case the V and L flags MUST
52
		#	 be set.
53
		#
54
		# *  A 4 octet index defining the offset in the SID/Label space
55
		# 	 advertised by this router using the encodings defined in
56
		#  	 Section 3.1.  In this case V and L flags MUST be unset.
57
		raw = []
58
		while data:
59
			# Range Size: 3 octet value indicating the number of labels in
60
			# the range.
61
			if int(flags['V']) and int(flags['L']):
62
				b = BitArray(bytes=data[:3])
63
				sid = b.unpack('uintbe:24')[0]
64
				data = data[3:]
65
			elif (not flags['V']) and (not flags['L']):
66
				sid = unpack('!I',data[:4])[0]
67
				data = data[4:]
68
			else:
69
				raw.append(hexstring(data))
70
				break
71
		cls._sr_adj_sids.append({'flags': flags, 'weight': weight, 'sid': sid, 'undecoded': raw})
72
		return cls()
73
74
	def json (self,compact=None):
75
		return '"sr-adj-sids": {}'.format(json.dumps(self.sr_adj_sids))
76
77
	@classmethod
78
	def reset(cls):
79
		cls._sr_adj_sids = []
80