From 57b74bf7b2c27c35970860444fc1702e4ddee30c Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Wed, 9 May 2018 16:31:09 +0800 Subject: [PATCH] fix lan adj sid issue and improve isis ios decode Signed-off-by: Peng Xiao --- yabgp/message/attribute/linkstate/link/lan_adj_sid.py | 9 ++++++--- yabgp/message/attribute/nlri/linkstate.py | 10 ++++++++-- yabgp/tests/unit/message/attribute/nlri/test_bgpls.py | 4 ++-- yabgp/tests/unit/message/attribute/test_mpreachnlri.py | 4 ++-- yabgp/tests/unit/message/test_update.py | 4 ++-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/yabgp/message/attribute/linkstate/link/lan_adj_sid.py b/yabgp/message/attribute/linkstate/link/lan_adj_sid.py index 9c94485..8e169e9 100644 --- a/yabgp/message/attribute/linkstate/link/lan_adj_sid.py +++ b/yabgp/message/attribute/linkstate/link/lan_adj_sid.py @@ -56,6 +56,7 @@ class LanAdjSegID(TLV): @classmethod def unpack(cls, data, pro_id): flags = ord(data[0:1]) + weight = ord(data[1:2]) flag = {} if pro_id in [1, 2]: flag['F'] = flags >> 7 @@ -64,7 +65,10 @@ def unpack(cls, data, pro_id): flag['L'] = (flags << 3) % 256 >> 7 flag['S'] = (flags << 4) % 256 >> 7 flag['P'] = (flags << 5) % 256 >> 7 - nei_or_sys_id = int(binascii.b2a_hex(data[4:10]), 16) + tmp = binascii.b2a_hex(data[4:10]) + chunks, chunk_size = len(tmp), len(tmp)/3 + sid_index_label = '.'.join([tmp[i:i+chunk_size] for i in range(0, chunks, chunk_size)]) + sid_index_label = int(binascii.b2a_hex(data[10:]), 16) else: # 3, 6 flag['B'] = flags >> 7 flag['V'] = (flags << 1) % 256 >> 7 @@ -72,8 +76,7 @@ def unpack(cls, data, pro_id): flag['G'] = (flags << 3) % 256 >> 7 flag['P'] = (flags << 4) % 256 >> 7 nei_or_sys_id = str(netaddr.IPAddress(int(binascii.b2a_hex(data[4:8]), 16))) - weight = ord(data[1:2]) - sid_index_label = int(binascii.b2a_hex(data[8:]), 16) + sid_index_label = int(binascii.b2a_hex(data[8:]), 16) return cls(value={ "flags": flag, "weight": weight, diff --git a/yabgp/message/attribute/nlri/linkstate.py b/yabgp/message/attribute/nlri/linkstate.py index f386c88..a237dc4 100644 --- a/yabgp/message/attribute/nlri/linkstate.py +++ b/yabgp/message/attribute/nlri/linkstate.py @@ -191,7 +191,7 @@ def parse_node_descriptor(cls, data, proto): if (proto == 1 or proto == 2) and length == 6: return_data['igp_router_id'] = { "pseudonode": False, - "iso_node_id": str(binascii.b2a_hex(value)) + "iso_node_id": cls.parse_iso_node_id(value) } # IS-IS LAN pseudonode = ISO Node-ID + PSN # Unpack ISO address @@ -199,6 +199,12 @@ def parse_node_descriptor(cls, data, proto): return_data['igp_router_id'] = { "pseudonode": True, "psn": ord(value[6: 7]), - "iso_node_id": str(binascii.b2a_hex(value[:6])) + "iso_node_id": cls.parse_iso_node_id(value[:6]) } return return_data + + @classmethod + def parse_iso_node_id(cls, data): + tmp = binascii.b2a_hex(data) + chunks, chunk_size = len(tmp), len(tmp)/3 + return '.'.join([tmp[i:i+chunk_size] for i in range(0, chunks, chunk_size)]) diff --git a/yabgp/tests/unit/message/attribute/nlri/test_bgpls.py b/yabgp/tests/unit/message/attribute/nlri/test_bgpls.py index d9d5e23..9b1daf8 100644 --- a/yabgp/tests/unit/message/attribute/nlri/test_bgpls.py +++ b/yabgp/tests/unit/message/attribute/nlri/test_bgpls.py @@ -40,7 +40,7 @@ def test_parse(self): 'value': { 'as_num': 65534, 'bgpls_id': '0.0.0.0', - 'igp_router_id': {'pseudonode': False, 'iso_node_id': '000000000003'}}}, + 'igp_router_id': {'pseudonode': False, 'iso_node_id': '0000.0000.0003'}}}, { 'type': 'remote_node', 'value': { @@ -48,7 +48,7 @@ def test_parse(self): 'bgpls_id': '0.0.0.0', 'igp_router_id': { 'pseudonode': False, - 'iso_node_id': '000000000001' + 'iso_node_id': '0000.0000.0001' }}}, { 'type': 'link_local_ipv4', diff --git a/yabgp/tests/unit/message/attribute/test_mpreachnlri.py b/yabgp/tests/unit/message/attribute/test_mpreachnlri.py index 61cf341..31fd969 100644 --- a/yabgp/tests/unit/message/attribute/test_mpreachnlri.py +++ b/yabgp/tests/unit/message/attribute/test_mpreachnlri.py @@ -281,7 +281,7 @@ def test_linkstate(self): 'bgpls_id': '0.0.0.0', 'igp_router_id': { 'pseudonode': False, - 'iso_node_id': '000000000001' + 'iso_node_id': '0000.0000.0001' }}}, { 'type': 'remote_node', @@ -290,7 +290,7 @@ def test_linkstate(self): 'bgpls_id': '0.0.0.0', 'igp_router_id': { 'pseudonode': False, - 'iso_node_id': '000000000003' + 'iso_node_id': '0000.0000.0003' }}}, {'type': 'link_local_ipv4', 'value': '1.3.0.1'}, {'type': 'link_remote_ipv4', 'value': '1.3.0.2'}]}]} diff --git a/yabgp/tests/unit/message/test_update.py b/yabgp/tests/unit/message/test_update.py index f924745..20701c4 100644 --- a/yabgp/tests/unit/message/test_update.py +++ b/yabgp/tests/unit/message/test_update.py @@ -252,7 +252,7 @@ def test_parse_link_state(self): 'bgpls_id': '0.0.0.0', 'igp_router_id': { 'pseudonode': False, - 'iso_node_id': b"000000000001" + 'iso_node_id': b"0000.0000.0001" } } }, @@ -263,7 +263,7 @@ def test_parse_link_state(self): 'bgpls_id': '0.0.0.0', 'igp_router_id': { 'pseudonode': False, - 'iso_node_id': b"000000000003" + 'iso_node_id': b"0000.0000.0003" }}}, { 'type': 'link_local_ipv4',