Skip to content

Commit

Permalink
This commit addresses below issues:
Browse files Browse the repository at this point in the history
1. Short Format Subinterface getting deleted after vrf binding . Issue
10802:sonic-net/sonic-buildimage#10802
2. Do not allow short format subinterface to be created without encap
vlan configuration. Issue 10878:
sonic-net/sonic-buildimage#10878
  • Loading branch information
preetham-singh committed Jun 11, 2022
1 parent 06e0b8d commit 380339c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4772,6 +4772,11 @@ def bind(ctx, interface_name, vrf_name):
interface_addresses = get_interface_ipaddresses(config_db, interface_name)
for ipaddress in interface_addresses:
remove_router_interface_ip_address(config_db, interface_name, ipaddress)
if interface_type == "VLAN_SUB_INTERFACE":
subintf = config_db.get_entry(interface_type, alias)
if 'vrf_name' in subintf_entry:
subintf_entry.pop('vrf')

config_db.set_entry(table_name, interface_name, None)
# When config_db del entry and then add entry with same key, the DEL will lost.
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
Expand All @@ -4783,6 +4788,10 @@ def bind(ctx, interface_name, vrf_name):
while state_db.exists(state_db.STATE_DB, _hash):
time.sleep(0.01)
state_db.close(state_db.STATE_DB)
if interface_type == "VLAN_SUB_INTERFACE":
subintf['vrf_name'] = vrfname
config_db.set_entry(interface_type, alias, subintf)
else:
config_db.set_entry(table_name, interface_name, {"vrf_name": vrf_name})

#
Expand Down Expand Up @@ -6582,6 +6591,18 @@ def subintf_vlan_check(config_db, parent_intf, vlan):
return True
return False

def is_subintf_shortname(intf):
if VLAN_SUB_INTERFACE_SEPARATOR in intf:
if intf.startswith("Eth"):
if intf.startswith("Ethernet"):
return False
return True
elif intf.startswith("Po"):
if intf.startswith("PortChannel"):
return False
return True
return False

@subinterface.command('add')
@click.argument('subinterface_name', metavar='<subinterface_name>', required=True)
@click.argument('vid', metavar='<vid>', required=False, type=click.IntRange(1,4094))
Expand Down Expand Up @@ -6627,6 +6648,8 @@ def add_subinterface(ctx, subinterface_name, vid):
subintf_dict = {}
if vid is not None:
subintf_dict.update({"vlan" : vid})
elif is_subintf_shortname(subinterface_name):
ctx.fail("{} Encap vlan is mandatory for short name subinterfaces".format(subinterface_name))

if subintf_vlan_check(config_db, get_intf_longname(interface_alias), vid) is True:
ctx.fail("Vlan {} encap already configured on other subinterface on {}".format(vid, interface_alias))
Expand Down

0 comments on commit 380339c

Please sign in to comment.