Skip to content

Commit

Permalink
[muxcable][show] update show mux tunnel-route to separate ASIC and …
Browse files Browse the repository at this point in the history
…kernel into two columns (sonic-net#2553)

Stemming from sonic-net/sonic-swss#2557.

This PR is to update show mux tunnel-route command to show status of both ASIC and kernel tunnel routes.

sign-off: Jing Zhang zhangjing@microsoft.com

What I did
How I did it
How to verify it
Previous command output (if the output of a command-line utility has changed)
Only check Kernel Route, if removing tunnel route for server_ipv4 in kernel, it won't show in CMD output:

zhangjing@********************:~$ show mux tunnel-route Ethernet4
PORT       DEST_TYPE    DEST_ADDRESS
---------  -----------  --------------------------------
Ethernet4  server_ipv6  2603:10b0:d11:8614::a32:9112/128
New command output (if the output of a command-line utility has changed)
Check both ASIC and APP DB for tunnel route status

zhangjing@********************:~$ show mux tunnel-route Ethernet4
PORT       DEST_TYPE    DEST_ADDRESS                      kernel    asic
---------  -----------  --------------------------------  --------  ------
Ethernet4  server_ipv4  10.50.145.18/32                   -         added
Ethernet4  server_ipv6  2603:10b0:d11:8614::a32:9112/128  added     added
  • Loading branch information
zjswhhh authored Dec 14, 2022
1 parent 49fc389 commit ce1c444
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
41 changes: 27 additions & 14 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asi
if soc_ipv4_value is not None:
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["soc_ipv4"] = soc_ipv4_value

def get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port):
def get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port):

mux_cfg_dict = per_npu_configdb[asic_id].get_all(
per_npu_configdb[asic_id].CONFIG_DB, 'MUX_CABLE|{}'.format(port))
Expand All @@ -559,31 +559,40 @@ def get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_a
dest_address = mux_cfg_dict.get(name, None)

if dest_address is not None:
route_keys = per_npu_appl_db[asic_id].keys(
kernel_route_keys = per_npu_appl_db[asic_id].keys(
per_npu_appl_db[asic_id].APPL_DB, 'TUNNEL_ROUTE_TABLE:*{}'.format(dest_address))

if route_keys is not None and len(route_keys):
if_kernel_tunnel_route_programed = kernel_route_keys is not None and len(kernel_route_keys)

asic_route_keys = per_npu_asic_db[asic_id].keys(
per_npu_asic_db[asic_id].ASIC_DB, 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY:*{}*'.format(dest_address))
if_asic_tunnel_route_programed = asic_route_keys is not None and len(asic_route_keys)

if if_kernel_tunnel_route_programed or if_asic_tunnel_route_programed:
port_tunnel_route["TUNNEL_ROUTE"][port] = port_tunnel_route["TUNNEL_ROUTE"].get(port, {})
port_tunnel_route["TUNNEL_ROUTE"][port][name] = {}
port_tunnel_route["TUNNEL_ROUTE"][port][name]['DEST'] = dest_address

def create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port):
port_tunnel_route["TUNNEL_ROUTE"][port][name]['kernel'] = if_kernel_tunnel_route_programed
port_tunnel_route["TUNNEL_ROUTE"][port][name]['asic'] = if_asic_tunnel_route_programed

get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port)
def create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port):

def create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, asic_id, port):
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port)

def create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port):

port_tunnel_route = {}
port_tunnel_route["TUNNEL_ROUTE"] = {}
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port)
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port)

for port, route in port_tunnel_route["TUNNEL_ROUTE"].items():
for dest_name, values in route.items():
print_line = []
print_line.append(port)
print_line.append(dest_name)
print_line.append(values['DEST'])
print_line.append('added' if values['kernel'] else '-')
print_line.append('added' if values['asic'] else '-')
print_data.append(print_line)

@muxcable.command()
Expand Down Expand Up @@ -1904,6 +1913,7 @@ def tunnel_route(db, port, json_output):
port = platform_sfputil_helper.get_interface_name(port, db)

per_npu_appl_db = {}
per_npu_asic_db = {}
per_npu_configdb = {}
mux_tbl_keys = {}

Expand All @@ -1914,6 +1924,9 @@ def tunnel_route(db, port, json_output):
per_npu_appl_db[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
per_npu_appl_db[asic_id].connect(per_npu_appl_db[asic_id].APPL_DB)

per_npu_asic_db[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
per_npu_asic_db[asic_id].connect(per_npu_asic_db[asic_id].ASIC_DB)

per_npu_configdb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
per_npu_configdb[asic_id].connect(per_npu_configdb[asic_id].CONFIG_DB)

Expand Down Expand Up @@ -1947,16 +1960,16 @@ def tunnel_route(db, port, json_output):
port_tunnel_route = {}
port_tunnel_route["TUNNEL_ROUTE"] = {}

create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_index, port)
create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_index, port)

click.echo("{}".format(json.dumps(port_tunnel_route, indent=4)))

else:
print_data = []

create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, asic_index, port)
create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_index, port)

headers = ['PORT', 'DEST_TYPE', 'DEST_ADDRESS']
headers = ['PORT', 'DEST_TYPE', 'DEST_ADDRESS', 'kernel', 'asic']

click.echo(tabulate(print_data, headers=headers))
else:
Expand All @@ -1972,7 +1985,7 @@ def tunnel_route(db, port, json_output):
for key in natsorted(mux_tbl_keys[asic_id]):
port = key.split("|")[1]

create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port)
create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port)

click.echo("{}".format(json.dumps(port_tunnel_route, indent=4)))
else:
Expand All @@ -1983,9 +1996,9 @@ def tunnel_route(db, port, json_output):
for key in natsorted(mux_tbl_keys[asic_id]):
port = key.split("|")[1]

create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, asic_id, port)
create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port)

headers = ['PORT', 'DEST_TYPE', 'DEST_ADDRESS']
headers = ['PORT', 'DEST_TYPE', 'DEST_ADDRESS', 'kernel', 'asic']

click.echo(tabulate(print_data, headers=headers))

Expand Down
6 changes: 5 additions & 1 deletion tests/mock_tables/asic_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
"VIDTORID":{
"oid:0xd00000000056d": "oid:0xd",
"oid:0x10000000004a4": "oid:0x1690000000001"
}
},
"ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY:{\"dest\":\"10.2.1.1\",\"switch_id\":\"oid:0x21000000000000\",\"vr\":\"oid:0x300000000007c\"}": {
"SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION": "SAI_PACKET_ACTION_FORWARD",
"SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": "oid:0x40000000015d8"
}
}
26 changes: 16 additions & 10 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,41 +515,47 @@
"TUNNEL_ROUTE": {
"Ethernet0": {
"server_ipv4": {
"DEST": "10.2.1.1"
"DEST": "10.2.1.1",
"kernel": 1,
"asic": 1
}
},
"Ethernet4": {
"server_ipv4": {
"DEST": "10.3.1.1"
"DEST": "10.3.1.1",
"kernel": 1,
"asic": false
}
}
}
}
"""

show_muxcable_tunnel_route_expected_output="""\
PORT DEST_TYPE DEST_ADDRESS
--------- ----------- --------------
Ethernet0 server_ipv4 10.2.1.1
Ethernet4 server_ipv4 10.3.1.1
PORT DEST_TYPE DEST_ADDRESS kernel asic
--------- ----------- -------------- -------- ------
Ethernet0 server_ipv4 10.2.1.1 added added
Ethernet4 server_ipv4 10.3.1.1 added -
"""

show_muxcable_tunnel_route_expected_output_port_json="""\
{
"TUNNEL_ROUTE": {
"Ethernet0": {
"server_ipv4": {
"DEST": "10.2.1.1"
"DEST": "10.2.1.1",
"kernel": 1,
"asic": 1
}
}
}
}
"""

show_muxcable_tunnel_route_expected_port_output="""\
PORT DEST_TYPE DEST_ADDRESS
--------- ----------- --------------
Ethernet0 server_ipv4 10.2.1.1
PORT DEST_TYPE DEST_ADDRESS kernel asic
--------- ----------- -------------- -------- ------
Ethernet0 server_ipv4 10.2.1.1 added added
"""

class TestMuxcable(object):
Expand Down

0 comments on commit ce1c444

Please sign in to comment.