Skip to content

Commit

Permalink
fix lan adj sid issue and improve isis ios decode
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Xiao <xiaoquwl@gmail.com>
  • Loading branch information
xiaopeng163 committed May 9, 2018
1 parent ff26a71 commit 57b74bf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
9 changes: 6 additions & 3 deletions yabgp/message/attribute/linkstate/link/lan_adj_sid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,16 +65,18 @@ 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
flag['L'] = (flags << 2) % 256 >> 7
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,
Expand Down
10 changes: 8 additions & 2 deletions yabgp/message/attribute/nlri/linkstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,20 @@ 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
if (proto == 1 or proto == 2) and length == 7:
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)])
4 changes: 2 additions & 2 deletions yabgp/tests/unit/message/attribute/nlri/test_bgpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ 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': {
'as_num': 65534,
'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',
Expand Down
4 changes: 2 additions & 2 deletions yabgp/tests/unit/message/attribute/test_mpreachnlri.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'}]}]}
Expand Down
4 changes: 2 additions & 2 deletions yabgp/tests/unit/message/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand All @@ -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',
Expand Down

0 comments on commit 57b74bf

Please sign in to comment.