From 7abdaf0c7f318363c8ff3bf1d57aac77466071b1 Mon Sep 17 00:00:00 2001 From: Preetham Singh Date: Wed, 15 Sep 2021 01:42:51 -0700 Subject: [PATCH 1/6] Adding support to get routed subinterface long name to get correct parent interface for the routed subinterface --- .../sonic_py_common/interface.py | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/interface.py b/src/sonic-py-common/sonic_py_common/interface.py index b56326e82aa..0435433d086 100644 --- a/src/sonic-py-common/sonic_py_common/interface.py +++ b/src/sonic-py-common/sonic_py_common/interface.py @@ -14,7 +14,8 @@ "Vlan": "Vlan", "Loopback": "Loopback", "Ethernet-Backplane": "Ethernet-BP", - "Ethernet-Inband": "Ethernet-IB" + "Ethernet-SubPort": "Eth", + "PortChannel-SubPort": "Po" } VLAN_SUB_INTERFACE_SEPARATOR = '.' @@ -49,11 +50,17 @@ def loopback_prefix(): """ return SONIC_INTERFACE_PREFIXES["Loopback"] -def inband_prefix(): +def physical_subinterface_prefix(): """ - Retrieves the SONIC recycle port inband interface name prefix. + Retrieves the SONIC Subinterface name prefix. """ - return SONIC_INTERFACE_PREFIXES["Ethernet-Inband"] + return SONIC_INTERFACE_PREFIXES["Ethernet-SubPort"] + +def portchannel_subinterface_prefix(): + """ + Retrieves the SONIC Subinterface name prefix. + """ + return SONIC_INTERFACE_PREFIXES["PortChannel-SubPort"] def get_interface_table_name(interface_name): """Get table name by interface_name prefix @@ -70,6 +77,9 @@ def get_interface_table_name(interface_name): return "VLAN_INTERFACE" elif interface_name.startswith(loopback_prefix()): return "LOOPBACK_INTERFACE" + elif VLAN_SUB_INTERFACE_SEPARATOR in interface_name: + if interface_name.startswith(physical_subinterface_prefix()) or interface_name.startswith(portchannel_subinterface_prefix()): + return "VLAN_SUB_INTERFACE" else: return "" @@ -88,5 +98,30 @@ def get_port_table_name(interface_name): return "VLAN_INTERFACE" elif interface_name.startswith(loopback_prefix()): return "LOOPBACK_INTERFACE" + elif VLAN_SUB_INTERFACE_SEPARATOR in interface_name: + if interface_name.startswith(physical_subinterface_prefix()) or interface_name.startswith(portchannel_subinterface_prefix()): + return "VLAN_SUB_INTERFACE" else: return "" + +def intf_get_longname(intf): + if intf is None: + return None + + if VLAN_SUB_INTERFACE_SEPARATOR in intf: + return subintf_get_longname(intf) + else: + if intf.startswith("Eth"): + if intf.startswith("Ethernet"): + return intf + intf_index=intf[len("Eth"):len(intf)] + return "Ethernet"+intf_index + elif intf.startswith("Po"): + if intf.startswith("PortChannel"): + return intf + intf_index=intf[len("Po"):len(intf)] + return "PortChannel"+intf_index + else: + return intf + + From f1b3f4923b1ebea75cc0592acdcde8b8d64355af Mon Sep 17 00:00:00 2001 From: Preetham Singh Date: Fri, 1 Oct 2021 03:16:03 -0700 Subject: [PATCH 2/6] Resolving merge issue --- src/sonic-py-common/sonic_py_common/interface.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sonic-py-common/sonic_py_common/interface.py b/src/sonic-py-common/sonic_py_common/interface.py index 0435433d086..ef78365b292 100644 --- a/src/sonic-py-common/sonic_py_common/interface.py +++ b/src/sonic-py-common/sonic_py_common/interface.py @@ -14,6 +14,7 @@ "Vlan": "Vlan", "Loopback": "Loopback", "Ethernet-Backplane": "Ethernet-BP", + "Ethernet-Inband": "Ethernet-IB", "Ethernet-SubPort": "Eth", "PortChannel-SubPort": "Po" } @@ -50,6 +51,12 @@ def loopback_prefix(): """ return SONIC_INTERFACE_PREFIXES["Loopback"] +def inband_prefix(): + """ + Retrieves the SONIC recycle port inband interface name prefix. + """ + return SONIC_INTERFACE_PREFIXES["Ethernet-Inband"] + def physical_subinterface_prefix(): """ Retrieves the SONIC Subinterface name prefix. From 2bd7dd1baed70893f9e6fd4f1f769c3b49669cab Mon Sep 17 00:00:00 2001 From: Preetham Singh Date: Mon, 8 Nov 2021 22:24:05 -0800 Subject: [PATCH 3/6] Updating the commit with subintf_get_longname routine. --- .../sonic_py_common/interface.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sonic-py-common/sonic_py_common/interface.py b/src/sonic-py-common/sonic_py_common/interface.py index ef78365b292..c84b5473513 100644 --- a/src/sonic-py-common/sonic_py_common/interface.py +++ b/src/sonic-py-common/sonic_py_common/interface.py @@ -111,6 +111,23 @@ def get_port_table_name(interface_name): else: return "" +def subintf_get_longname(intf): + if intf is None: + return None + sub_intf_sep_idx = intf.find(VLAN_SUB_INTERFACE_SEPARATOR) + if sub_intf_sep_idx == -1: + return str(intf) + parent_intf = intf[:sub_intf_sep_idx] + sub_intf_idx = intf[(sub_intf_sep_idx+1):] + if intf.startswith("Eth"): + intf_index=intf[len("Eth"):sub_intf_sep_idx] + return "Ethernet"+intf_index+VLAN_SUB_INTERFACE_SEPARATOR+sub_intf_idx + elif intf.startswith("Po"): + intf_index=intf[len("Po"):sub_intf_sep_idx] + return "PortChannel"+intf_index+VLAN_SUB_INTERFACE_SEPARATOR+sub_intf_idx + else: + return str(intf) + def intf_get_longname(intf): if intf is None: return None From e8dd73b0d8d9bbb288c0066c55f84c3720acb483 Mon Sep 17 00:00:00 2001 From: Preetham Singh Date: Tue, 16 Nov 2021 06:26:47 -0800 Subject: [PATCH 4/6] Updating unit testcases for subinterfaces --- src/sonic-py-common/tests/interface_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sonic-py-common/tests/interface_test.py b/src/sonic-py-common/tests/interface_test.py index 5e5b81b0408..d2e8b2e705f 100644 --- a/src/sonic-py-common/tests/interface_test.py +++ b/src/sonic-py-common/tests/interface_test.py @@ -17,6 +17,10 @@ def test_get_interface_table_name(self): assert result == "VLAN_INTERFACE" result = interface.get_interface_table_name("Loopback0") assert result == "LOOPBACK_INTERFACE" + result = interface.get_interface_table_name("Eth0.1001") + assert result == "VLAN_SUB_INTERFACE" + result = interface.get_interface_table_name("Pol0.1001") + assert result == "VLAN_SUB_INTERFACE" def test_get_port_table_name(self): result = interface.get_port_table_name("Ethernet0") @@ -31,3 +35,7 @@ def test_get_port_table_name(self): assert result == "VLAN_INTERFACE" result = interface.get_port_table_name("Loopback0") assert result == "LOOPBACK_INTERFACE" + result = interface.get_port_table_name("Eth0.1001") + assert result == "VLAN_SUB_INTERFACE" + result = interface.get_port_table_name("Pol0.1001") + assert result == "VLAN_SUB_INTERFACE" From 4646c3d90244b80abe48a1f214d7ab47cf6c1038 Mon Sep 17 00:00:00 2001 From: Preetham Singh Date: Tue, 16 Nov 2021 06:29:26 -0800 Subject: [PATCH 5/6] Updating Unit Test Cases --- src/sonic-py-common/tests/interface_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-py-common/tests/interface_test.py b/src/sonic-py-common/tests/interface_test.py index d2e8b2e705f..4ee6b3ed98d 100644 --- a/src/sonic-py-common/tests/interface_test.py +++ b/src/sonic-py-common/tests/interface_test.py @@ -19,7 +19,7 @@ def test_get_interface_table_name(self): assert result == "LOOPBACK_INTERFACE" result = interface.get_interface_table_name("Eth0.1001") assert result == "VLAN_SUB_INTERFACE" - result = interface.get_interface_table_name("Pol0.1001") + result = interface.get_interface_table_name("Po0.1001") assert result == "VLAN_SUB_INTERFACE" def test_get_port_table_name(self): @@ -37,5 +37,5 @@ def test_get_port_table_name(self): assert result == "LOOPBACK_INTERFACE" result = interface.get_port_table_name("Eth0.1001") assert result == "VLAN_SUB_INTERFACE" - result = interface.get_port_table_name("Pol0.1001") + result = interface.get_port_table_name("Po0.1001") assert result == "VLAN_SUB_INTERFACE" From 3fbf12f1075bdc31a4fa6f7d5223f9203b030e78 Mon Sep 17 00:00:00 2001 From: Preetham Singh Date: Tue, 16 Nov 2021 18:32:58 -0800 Subject: [PATCH 6/6] Addressing review comments --- src/sonic-py-common/sonic_py_common/interface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/interface.py b/src/sonic-py-common/sonic_py_common/interface.py index c84b5473513..59aeacf0131 100644 --- a/src/sonic-py-common/sonic_py_common/interface.py +++ b/src/sonic-py-common/sonic_py_common/interface.py @@ -111,7 +111,7 @@ def get_port_table_name(interface_name): else: return "" -def subintf_get_longname(intf): +def get_subintf_longname(intf): if intf is None: return None sub_intf_sep_idx = intf.find(VLAN_SUB_INTERFACE_SEPARATOR) @@ -128,12 +128,12 @@ def subintf_get_longname(intf): else: return str(intf) -def intf_get_longname(intf): +def get_intf_longname(intf): if intf is None: return None if VLAN_SUB_INTERFACE_SEPARATOR in intf: - return subintf_get_longname(intf) + return get_subintf_longname(intf) else: if intf.startswith("Eth"): if intf.startswith("Ethernet"):