Skip to content

Commit aa7a2f8

Browse files
committed
use APP DB table
1 parent 55d0ec9 commit aa7a2f8

File tree

4 files changed

+76
-23
lines changed

4 files changed

+76
-23
lines changed

show/muxcable.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asi
503503
if soc_ipv4_value is not None:
504504
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["soc_ipv4"] = soc_ipv4_value
505505

506-
def get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_asic_db, asic_id, port):
506+
def get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port):
507507

508508
mux_cfg_dict = per_npu_configdb[asic_id].get_all(
509509
per_npu_configdb[asic_id].CONFIG_DB, 'MUX_CABLE|{}'.format(port))
@@ -513,24 +513,24 @@ def get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_a
513513
dest_address = mux_cfg_dict.get(name, None)
514514

515515
if dest_address is not None:
516-
route_keys = per_npu_asic_db[asic_id].keys(
517-
per_npu_asic_db[asic_id].ASIC_DB, 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY:*{}*'.format(dest_address))
516+
route_keys = per_npu_appl_db[asic_id].keys(
517+
per_npu_appl_db[asic_id].APPL_DB, 'TUNNEL_ROUTE_TABLE:*{}'.format(dest_address))
518518

519519
if route_keys is not None and len(route_keys):
520520

521521
port_tunnel_route["TUNNEL_ROUTE"][port] = port_tunnel_route["TUNNEL_ROUTE"].get(port, {})
522522
port_tunnel_route["TUNNEL_ROUTE"][port][name] = {}
523523
port_tunnel_route["TUNNEL_ROUTE"][port][name]['DEST'] = dest_address
524524

525-
def create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_asic_db, asic_id, port):
525+
def create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port):
526526

527-
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_asic_db, asic_id, port)
527+
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port)
528528

529-
def create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_asic_db, asic_id, port):
529+
def create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, asic_id, port):
530530

531531
port_tunnel_route = {}
532532
port_tunnel_route["TUNNEL_ROUTE"] = {}
533-
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_asic_db, asic_id, port)
533+
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port)
534534

535535
for port, route in port_tunnel_route["TUNNEL_ROUTE"].items():
536536
for dest_name, values in route.items():
@@ -1797,16 +1797,16 @@ def tunnel_route(db, port, json_output):
17971797

17981798
port = platform_sfputil_helper.get_interface_name(port, db)
17991799

1800-
per_npu_asic_db = {}
1800+
per_npu_appl_db = {}
18011801
per_npu_configdb = {}
18021802
mux_tbl_keys = {}
18031803

18041804
namespaces = multi_asic.get_front_end_namespaces()
18051805
for namespace in namespaces:
18061806
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
18071807

1808-
per_npu_asic_db[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
1809-
per_npu_asic_db[asic_id].connect(per_npu_asic_db[asic_id].ASIC_DB)
1808+
per_npu_appl_db[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
1809+
per_npu_appl_db[asic_id].connect(per_npu_appl_db[asic_id].APPL_DB)
18101810

18111811
per_npu_configdb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
18121812
per_npu_configdb[asic_id].connect(per_npu_configdb[asic_id].CONFIG_DB)
@@ -1841,14 +1841,14 @@ def tunnel_route(db, port, json_output):
18411841
port_tunnel_route = {}
18421842
port_tunnel_route["TUNNEL_ROUTE"] = {}
18431843

1844-
create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_asic_db, asic_index, port)
1844+
create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_index, port)
18451845

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

18481848
else:
18491849
print_data = []
18501850

1851-
create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_asic_db, asic_index, port)
1851+
create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, asic_index, port)
18521852

18531853
headers = ['PORT', 'DEST_TYPE', 'DEST_ADDRESS']
18541854

@@ -1866,7 +1866,7 @@ def tunnel_route(db, port, json_output):
18661866
for key in natsorted(mux_tbl_keys[asic_id]):
18671867
port = key.split("|")[1]
18681868

1869-
create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_asic_db, asic_id, port)
1869+
create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, asic_id, port)
18701870

18711871
click.echo("{}".format(json.dumps(port_tunnel_route, indent=4)))
18721872
else:
@@ -1877,10 +1877,10 @@ def tunnel_route(db, port, json_output):
18771877
for key in natsorted(mux_tbl_keys[asic_id]):
18781878
port = key.split("|")[1]
18791879

1880-
create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_asic_db, asic_id, port)
1880+
create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, asic_id, port)
18811881

18821882
headers = ['PORT', 'DEST_TYPE', 'DEST_ADDRESS']
18831883

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

1886-
sys.exit(STATUS_SUCCESSFUL)
1886+
sys.exit(STATUS_SUCCESSFUL)

tests/mock_tables/appl_db.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,5 +281,11 @@
281281
},
282282
"MUX_CABLE_TABLE:Ethernet12": {
283283
"state": "active"
284+
},
285+
"TUNNEL_ROUTE_TABLE:10.2.1.1": {
286+
"alias": "Vlan1000"
287+
},
288+
"TUNNEL_ROUTE_TABLE:10.3.1.1": {
289+
"alias": "Vlan1000"
284290
}
285291
}

tests/mock_tables/asic_db.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,5 @@
1919
"VIDTORID":{
2020
"oid:0xd00000000056d": "oid:0xd",
2121
"oid:0x10000000004a4": "oid:0x1690000000001"
22-
},
23-
"ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY:{\"dest\":\"10.2.1.1\",\"switch_id\":\"oid:0x21000000000000\",\"vr\":\"oid:0x300000000007c\"}": {
24-
"SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION": "SAI_PACKET_ACTION_FORWARD",
25-
"SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": "oid:0x40000000015d8"
26-
}
22+
}
2723
}

tests/muxcable_test.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@
484484
"server_ipv4": {
485485
"DEST": "10.2.1.1"
486486
}
487+
},
488+
"Ethernet4": {
489+
"server_ipv4": {
490+
"DEST": "10.3.1.1"
491+
}
487492
}
488493
}
489494
}
@@ -493,6 +498,25 @@
493498
PORT DEST_TYPE DEST_ADDRESS
494499
--------- ----------- --------------
495500
Ethernet0 server_ipv4 10.2.1.1
501+
Ethernet4 server_ipv4 10.3.1.1
502+
"""
503+
504+
show_muxcable_tunnel_route_expected_output_port_json="""\
505+
{
506+
"TUNNEL_ROUTE": {
507+
"Ethernet0": {
508+
"server_ipv4": {
509+
"DEST": "10.2.1.1"
510+
}
511+
}
512+
}
513+
}
514+
"""
515+
516+
show_muxcable_tunnel_route_expected_port_output="""\
517+
PORT DEST_TYPE DEST_ADDRESS
518+
--------- ----------- --------------
519+
Ethernet0 server_ipv4 10.2.1.1
496520
"""
497521

498522
class TestMuxcable(object):
@@ -2139,8 +2163,7 @@ def test_show_muxcable_tunnel_route(self):
21392163
runner = CliRunner()
21402164
db = Db()
21412165

2142-
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"],
2143-
["Ethernet0"], obj=db)
2166+
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], obj=db)
21442167

21452168
assert result.exit_code == 0
21462169
assert result.output == show_muxcable_tunnel_route_expected_output
@@ -2154,10 +2177,38 @@ def test_show_muxcable_tunnel_route_json(self):
21542177
db = Db()
21552178

21562179
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"],
2157-
["Ethernet0", "--json"], obj=db)
2180+
["--json"], obj=db)
2181+
21582182
assert result.exit_code == 0
21592183
assert result.output == show_muxcable_tunnel_route_expected_output_json
21602184

2185+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
2186+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
2187+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
2188+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
2189+
def test_show_muxcable_tunnel_route(self):
2190+
runner = CliRunner()
2191+
db = Db()
2192+
2193+
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"],
2194+
["Ethernet0"], obj=db)
2195+
2196+
assert result.exit_code == 0
2197+
assert result.output == show_muxcable_tunnel_route_expected_port_output
2198+
2199+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
2200+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
2201+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
2202+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
2203+
def test_show_muxcable_tunnel_route_json(self):
2204+
runner = CliRunner()
2205+
db = Db()
2206+
2207+
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"],
2208+
["Ethernet0", "--json"], obj=db)
2209+
assert result.exit_code == 0
2210+
assert result.output == show_muxcable_tunnel_route_expected_output_port_json
2211+
21612212
@classmethod
21622213
def teardown_class(cls):
21632214
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)