@@ -503,6 +503,42 @@ def create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asi
503
503
if soc_ipv4_value is not None :
504
504
port_status_dict ["MUX_CABLE" ]["PORTS" ][port_name ]["SERVER" ]["soc_ipv4" ] = soc_ipv4_value
505
505
506
+ def get_tunnel_route_per_port (db , port_tunnel_route , per_npu_configdb , per_npu_appl_db , asic_id , port ):
507
+
508
+ mux_cfg_dict = per_npu_configdb [asic_id ].get_all (
509
+ per_npu_configdb [asic_id ].CONFIG_DB , 'MUX_CABLE|{}' .format (port ))
510
+ dest_names = ["server_ipv4" , "server_ipv6" , "soc_ipv4" ]
511
+
512
+ for name in dest_names :
513
+ dest_address = mux_cfg_dict .get (name , None )
514
+
515
+ if dest_address is not None :
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 ))
518
+
519
+ if route_keys is not None and len (route_keys ):
520
+
521
+ port_tunnel_route ["TUNNEL_ROUTE" ][port ] = port_tunnel_route ["TUNNEL_ROUTE" ].get (port , {})
522
+ port_tunnel_route ["TUNNEL_ROUTE" ][port ][name ] = {}
523
+ port_tunnel_route ["TUNNEL_ROUTE" ][port ][name ]['DEST' ] = dest_address
524
+
525
+ def create_json_dump_per_port_tunnel_route (db , port_tunnel_route , per_npu_configdb , per_npu_appl_db , asic_id , port ):
526
+
527
+ get_tunnel_route_per_port (db , port_tunnel_route , per_npu_configdb , per_npu_appl_db , asic_id , port )
528
+
529
+ def create_table_dump_per_port_tunnel_route (db , print_data , per_npu_configdb , per_npu_appl_db , asic_id , port ):
530
+
531
+ port_tunnel_route = {}
532
+ port_tunnel_route ["TUNNEL_ROUTE" ] = {}
533
+ get_tunnel_route_per_port (db , port_tunnel_route , per_npu_configdb , per_npu_appl_db , asic_id , port )
534
+
535
+ for port , route in port_tunnel_route ["TUNNEL_ROUTE" ].items ():
536
+ for dest_name , values in route .items ():
537
+ print_line = []
538
+ print_line .append (port )
539
+ print_line .append (dest_name )
540
+ print_line .append (values ['DEST' ])
541
+ print_data .append (print_line )
506
542
507
543
@muxcable .command ()
508
544
@click .argument ('port' , required = False , default = None )
@@ -558,8 +594,8 @@ def status(db, port, json_output):
558
594
click .echo ("Got invalid asic index for port {}, cant retreive mux status" .format (port_name ))
559
595
sys .exit (STATUS_FAIL )
560
596
561
- muxcable_info_dict [asic_index ] = per_npu_appl_db [asic_id ].get_all (
562
- per_npu_appl_db [asic_id ].APPL_DB , 'MUX_CABLE_TABLE:{}' .format (port ))
597
+ muxcable_info_dict [asic_index ] = per_npu_appl_db [asic_index ].get_all (
598
+ per_npu_appl_db [asic_index ].APPL_DB , 'MUX_CABLE_TABLE:{}' .format (port ))
563
599
muxcable_grpc_dict [asic_index ] = per_npu_statedb [asic_index ].get_all (
564
600
per_npu_statedb [asic_index ].STATE_DB , 'MUX_CABLE_TABLE|{}' .format (port ))
565
601
muxcable_health_dict [asic_index ] = per_npu_statedb [asic_index ].get_all (
@@ -1751,3 +1787,100 @@ def packetloss(db, port, json_output):
1751
1787
1752
1788
click .echo (tabulate (print_count , headers = count_headers ))
1753
1789
click .echo (tabulate (print_event , headers = event_headers ))
1790
+
1791
+ @muxcable .command ()
1792
+ @click .argument ('port' , metavar = '<port_name>' , required = False , default = None )
1793
+ @click .option ('--json' , 'json_output' , required = False , is_flag = True , type = click .BOOL , help = "display the output in json format" )
1794
+ @clicommon .pass_db
1795
+ def tunnel_route (db , port , json_output ):
1796
+ """show muxcable tunnel-route <port_name>"""
1797
+
1798
+ port = platform_sfputil_helper .get_interface_name (port , db )
1799
+
1800
+ per_npu_appl_db = {}
1801
+ per_npu_configdb = {}
1802
+ mux_tbl_keys = {}
1803
+
1804
+ namespaces = multi_asic .get_front_end_namespaces ()
1805
+ for namespace in namespaces :
1806
+ asic_id = multi_asic .get_asic_index_from_namespace (namespace )
1807
+
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 )
1810
+
1811
+ per_npu_configdb [asic_id ] = swsscommon .SonicV2Connector (use_unix_socket_path = False , namespace = namespace )
1812
+ per_npu_configdb [asic_id ].connect (per_npu_configdb [asic_id ].CONFIG_DB )
1813
+
1814
+ mux_tbl_keys [asic_id ] = per_npu_configdb [asic_id ].keys (
1815
+ per_npu_configdb [asic_id ].CONFIG_DB , "MUX_CABLE|*" )
1816
+
1817
+ if port is not None :
1818
+
1819
+ logical_port_list = platform_sfputil_helper .get_logical_list ()
1820
+
1821
+ if port not in logical_port_list :
1822
+ port_name = platform_sfputil_helper .get_interface_alias (port , db )
1823
+ click .echo (("ERR: Not a valid logical port for dualtor firmware {}" .format (port_name )))
1824
+ sys .exit (CONFIG_FAIL )
1825
+
1826
+ asic_index = None
1827
+ if platform_sfputil is not None :
1828
+ asic_index = platform_sfputil_helper .get_asic_id_for_logical_port (port )
1829
+ if asic_index is None :
1830
+ # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
1831
+ # is fully mocked
1832
+ import sonic_platform_base .sonic_sfp .sfputilhelper
1833
+ asic_index = sonic_platform_base .sonic_sfp .sfputilhelper .SfpUtilHelper ().get_asic_id_for_logical_port (port )
1834
+ if asic_index is None :
1835
+ port_name = platform_sfputil_helper .get_interface_alias (port , db )
1836
+ click .echo ("Got invalid asic index for port {}, cant retreive tunnel route info" .format (port_name ))
1837
+ sys .exit (STATUS_FAIL )
1838
+
1839
+ if mux_tbl_keys [asic_index ] is not None and "MUX_CABLE|{}" .format (port ) in mux_tbl_keys [asic_index ]:
1840
+ if json_output :
1841
+ port_tunnel_route = {}
1842
+ port_tunnel_route ["TUNNEL_ROUTE" ] = {}
1843
+
1844
+ create_json_dump_per_port_tunnel_route (db , port_tunnel_route , per_npu_configdb , per_npu_appl_db , asic_index , port )
1845
+
1846
+ click .echo ("{}" .format (json .dumps (port_tunnel_route , indent = 4 )))
1847
+
1848
+ else :
1849
+ print_data = []
1850
+
1851
+ create_table_dump_per_port_tunnel_route (db , print_data , per_npu_configdb , per_npu_appl_db , asic_index , port )
1852
+
1853
+ headers = ['PORT' , 'DEST_TYPE' , 'DEST_ADDRESS' ]
1854
+
1855
+ click .echo (tabulate (print_data , headers = headers ))
1856
+ else :
1857
+ click .echo ("this is not a valid port present on dualToR" .format (port ))
1858
+ sys .exit (STATUS_FAIL )
1859
+
1860
+ else :
1861
+ if json_output :
1862
+ port_tunnel_route = {}
1863
+ port_tunnel_route ["TUNNEL_ROUTE" ] = {}
1864
+ for namespace in namespaces :
1865
+ asic_id = multi_asic .get_asic_index_from_namespace (namespace )
1866
+ for key in natsorted (mux_tbl_keys [asic_id ]):
1867
+ port = key .split ("|" )[1 ]
1868
+
1869
+ create_json_dump_per_port_tunnel_route (db , port_tunnel_route , per_npu_configdb , per_npu_appl_db , asic_id , port )
1870
+
1871
+ click .echo ("{}" .format (json .dumps (port_tunnel_route , indent = 4 )))
1872
+ else :
1873
+ print_data = []
1874
+
1875
+ for namespace in namespaces :
1876
+ asic_id = multi_asic .get_asic_index_from_namespace (namespace )
1877
+ for key in natsorted (mux_tbl_keys [asic_id ]):
1878
+ port = key .split ("|" )[1 ]
1879
+
1880
+ create_table_dump_per_port_tunnel_route (db , print_data , per_npu_configdb , per_npu_appl_db , asic_id , port )
1881
+
1882
+ headers = ['PORT' , 'DEST_TYPE' , 'DEST_ADDRESS' ]
1883
+
1884
+ click .echo (tabulate (print_data , headers = headers ))
1885
+
1886
+ sys .exit (STATUS_SUCCESSFUL )
0 commit comments