Routed subinterface enhancements (#8761)
* Routed subinterfae enhancements HLD #833 * Adding python API support to get routed subinterface long name to get correct parent interface for the routed subinterface.
This commit is contained in:
parent
ba853348d5
commit
858f430f94
@ -14,7 +14,9 @@ SONIC_INTERFACE_PREFIXES = {
|
|||||||
"Vlan": "Vlan",
|
"Vlan": "Vlan",
|
||||||
"Loopback": "Loopback",
|
"Loopback": "Loopback",
|
||||||
"Ethernet-Backplane": "Ethernet-BP",
|
"Ethernet-Backplane": "Ethernet-BP",
|
||||||
"Ethernet-Inband": "Ethernet-IB"
|
"Ethernet-Inband": "Ethernet-IB",
|
||||||
|
"Ethernet-SubPort": "Eth",
|
||||||
|
"PortChannel-SubPort": "Po"
|
||||||
}
|
}
|
||||||
|
|
||||||
VLAN_SUB_INTERFACE_SEPARATOR = '.'
|
VLAN_SUB_INTERFACE_SEPARATOR = '.'
|
||||||
@ -55,6 +57,18 @@ def inband_prefix():
|
|||||||
"""
|
"""
|
||||||
return SONIC_INTERFACE_PREFIXES["Ethernet-Inband"]
|
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):
|
def get_interface_table_name(interface_name):
|
||||||
"""Get table name by interface_name prefix
|
"""Get table name by interface_name prefix
|
||||||
"""
|
"""
|
||||||
@ -70,6 +84,9 @@ def get_interface_table_name(interface_name):
|
|||||||
return "VLAN_INTERFACE"
|
return "VLAN_INTERFACE"
|
||||||
elif interface_name.startswith(loopback_prefix()):
|
elif interface_name.startswith(loopback_prefix()):
|
||||||
return "LOOPBACK_INTERFACE"
|
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:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@ -88,5 +105,47 @@ def get_port_table_name(interface_name):
|
|||||||
return "VLAN_INTERFACE"
|
return "VLAN_INTERFACE"
|
||||||
elif interface_name.startswith(loopback_prefix()):
|
elif interface_name.startswith(loopback_prefix()):
|
||||||
return "LOOPBACK_INTERFACE"
|
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:
|
else:
|
||||||
return ""
|
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:
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,10 @@ class TestInterface(object):
|
|||||||
assert result == "VLAN_INTERFACE"
|
assert result == "VLAN_INTERFACE"
|
||||||
result = interface.get_interface_table_name("Loopback0")
|
result = interface.get_interface_table_name("Loopback0")
|
||||||
assert result == "LOOPBACK_INTERFACE"
|
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):
|
def test_get_port_table_name(self):
|
||||||
result = interface.get_port_table_name("Ethernet0")
|
result = interface.get_port_table_name("Ethernet0")
|
||||||
@ -31,3 +35,7 @@ class TestInterface(object):
|
|||||||
assert result == "VLAN_INTERFACE"
|
assert result == "VLAN_INTERFACE"
|
||||||
result = interface.get_port_table_name("Loopback0")
|
result = interface.get_port_table_name("Loopback0")
|
||||||
assert result == "LOOPBACK_INTERFACE"
|
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"
|
||||||
|
Reference in New Issue
Block a user