Skip to content

Routed subinterface enhancements #8761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion src/sonic-py-common/sonic_py_common/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"Vlan": "Vlan",
"Loopback": "Loopback",
"Ethernet-Backplane": "Ethernet-BP",
"Ethernet-Inband": "Ethernet-IB"
"Ethernet-Inband": "Ethernet-IB",
"Ethernet-SubPort": "Eth",
"PortChannel-SubPort": "Po"
}

VLAN_SUB_INTERFACE_SEPARATOR = '.'
Expand Down Expand Up @@ -55,6 +57,18 @@ def inband_prefix():
"""
return SONIC_INTERFACE_PREFIXES["Ethernet-Inband"]

def physical_subinterface_prefix():
"""
Retrieves the SONIC Subinterface name prefix.
"""
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
"""
Expand All @@ -70,6 +84,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 ""

Expand All @@ -88,5 +105,47 @@ 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 get_subintf_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 get_intf_longname(intf):
if intf is None:
return None

if VLAN_SUB_INTERFACE_SEPARATOR in intf:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check Eth or Po prefix as well instead of blindly checking for "." in the intf string and returning long interface name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In certain case we need to fetch full name for the given subinterface parent interface which could be in short name format. Just checking for "." will not suffice here.

return get_subintf_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


8 changes: 8 additions & 0 deletions src/sonic-py-common/tests/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("Po0.1001")
assert result == "VLAN_SUB_INTERFACE"

def test_get_port_table_name(self):
result = interface.get_port_table_name("Ethernet0")
Expand All @@ -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("Po0.1001")
assert result == "VLAN_SUB_INTERFACE"