Skip to content
Open
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
1 change: 1 addition & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ def config(ctx):
config.add_command(kube.kubernetes)
config.add_command(muxcable.muxcable)
config.add_command(nat.nat)
config.add_command(vlan.neigh_suppress)
config.add_command(vlan.vlan)
config.add_command(vxlan.vxlan)

Expand Down
31 changes: 28 additions & 3 deletions config/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def add_vlan_member(db, vid, port, untagged):
log.log_info("'vlan member add {} {}' executing...".format(vid, port))

vlan = 'Vlan{}'.format(vid)

config_db = ValidatedConfigDBConnector(db.cfgdb)
if ADHOC_VALIDATION:
if not clicommon.is_vlanid_in_range(vid):
Expand Down Expand Up @@ -233,7 +233,7 @@ def add_vlan_member(db, vid, port, untagged):
if (is_port and clicommon.is_port_router_interface(db.cfgdb, port)) or \
(not is_port and clicommon.is_pc_router_interface(db.cfgdb, port)): # TODO: MISSING CONSTRAINT IN YANG MODEL
ctx.fail("{} is a router interface!".format(port))

portchannel_member_table = db.cfgdb.get_table('PORTCHANNEL_MEMBER')

if (is_port and clicommon.interface_is_in_portchannel(portchannel_member_table, port)): # TODO: MISSING CONSTRAINT IN YANG MODEL
Expand All @@ -257,7 +257,7 @@ def del_vlan_member(db, vid, port):
ctx = click.get_current_context()
log.log_info("'vlan member del {} {}' executing...".format(vid, port))
vlan = 'Vlan{}'.format(vid)

config_db = ValidatedConfigDBConnector(db.cfgdb)
if ADHOC_VALIDATION:
if not clicommon.is_vlanid_in_range(vid):
Expand All @@ -283,3 +283,28 @@ def del_vlan_member(db, vid, port):
except JsonPatchConflict:
ctx.fail("{} invalid or does not exist, or {} is not a member of {}".format(vlan, port, vlan))

#######
#
# 'neigh-suppress' group ('config neigh-suppress vlan...')
#
@click.group(cls=clicommon.AbbreviationGroup, name='neigh-suppress')
def neigh_suppress():
""" Neighbour Suppress VLAN-related configuration """
pass

@neigh_suppress.command('vlan')
@click.argument('vid', metavar='<vid>', required=True, type=int)
@click.argument('state', metavar='<on|off>', required=True, type=click.Choice(["on", "off"]))
@clicommon.pass_db
def set_neigh_suppress(db, vid, state):
Copy link

Copilot AI Apr 15, 2025

Choose a reason for hiding this comment

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

The variable 'ctx' is used but not defined in this function. Pass the click context via a parameter or use appropriate error reporting like click.echo before exiting.

Suggested change
def set_neigh_suppress(db, vid, state):
def set_neigh_suppress(db, vid, state):
ctx = click.get_current_context()

Copilot uses AI. Check for mistakes.
if vid<1 or vid>4094:
ctx.fail("Invalid Vlan Id, Valid Range : 1 to 4094")
vlan = 'Vlan{}'.format(vid)
if clicommon.check_if_vlanid_exist(db.cfgdb, vlan) == False:
click.echo("{} doesn't exist".format(vlan))
return
if state == "on":
fvs = {'suppress': "on"}
db.cfgdb.set_entry('SUPPRESS_VLAN_NEIGH', vlan, fvs)
else:
db.cfgdb.set_entry('SUPPRESS_VLAN_NEIGH', vlan, None)
1 change: 1 addition & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def cli(ctx):
cli.add_command(processes.processes)
cli.add_command(reboot_cause.reboot_cause)
cli.add_command(sflow.sflow)
cli.add_command(vlan.neigh_suppress)
cli.add_command(vlan.vlan)
cli.add_command(vnet.vnet)
cli.add_command(vxlan.vxlan)
Expand Down
56 changes: 56 additions & 0 deletions show/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,59 @@ def tablelize(keys, data):
header = ['Name', 'VID', 'Member', 'Mode']
click.echo(tabulate(tablelize(keys, data), header))

#Neigh Suppress
@click.group(cls=clicommon.AliasedGroup)
def neigh_suppress():
""" show neigh-suppress """
pass
@neigh_suppress.command('all')
@clicommon.pass_db
def neigh_suppress_all(db):
""" Show neigh-suppress all """

header = ['VLAN', 'STATUS', 'ASSOCIATED_NETDEV']
body = []

vxlan_table = db.cfgdb.get_table('VXLAN_TUNNEL_MAP')
suppress_table = db.cfgdb.get_table('SUPPRESS_VLAN_NEIGH')
vxlan_keys = vxlan_table.keys()
num=0
if vxlan_keys is not None:
for key in natsorted(vxlan_keys):
key1 = vxlan_table[key]['vlan']
netdev = vxlan_keys[0][0]+"-"+key1[4:]
Copy link

Copilot AI Apr 15, 2025

Choose a reason for hiding this comment

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

Using vxlan_keys[0][0] inside the loop may not correctly reflect the current key being processed. Consider using the current key variable (e.g., 'key') to construct netdev to avoid potential mismatches.

Suggested change
netdev = vxlan_keys[0][0]+"-"+key1[4:]
netdev = key[0]+"-"+key1[4:]

Copilot uses AI. Check for mistakes.
if key1 not in suppress_table:
supp_str = "Not Configured"
else:
supp_str = "Configured"
body.append([vxlan_table[key]['vlan'], supp_str, netdev])
num += 1
click.echo(tabulate(body, header, tablefmt="grid"))
output = 'Total count : '
output += ('%s \n' % (str(num)))
click.echo(output)

@neigh_suppress.command('vlan')
@click.argument('vid', metavar='<vid>', required=True, type=int)
@clicommon.pass_db
def neigh_suppress_vlan(db,vid):
""" Show neigh-suppress vlan"""
header = ['VLAN', 'STATUS', 'ASSOCIATED_NETDEV']
body = []

vxlan_table = db.cfgdb.get_table('VXLAN_TUNNEL_MAP')
suppress_table = db.cfgdb.get_table('SUPPRESS_VLAN_NEIGH')
vlan = 'Vlan{}'.format(vid)
vxlan_keys = vxlan_table.keys()

if vxlan_keys is not None:
for key in natsorted(vxlan_keys):
key1 = vxlan_table[key]['vlan']
if(key1 == vlan):
netdev = vxlan_keys[0][0]+"-"+key1[4:]
if key1 in suppress_table:
supp_str = "Configured"
body.append([vxlan_table[key]['vlan'], supp_str, netdev])
click.echo(tabulate(body, header, tablefmt="grid"))
return
print(vlan + " is not configured in vxlan tunnel map table")
Copy link

Copilot AI Apr 15, 2025

Choose a reason for hiding this comment

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

Using print here is inconsistent with the rest of the CLI output which uses click.echo. Consider replacing print with click.echo to maintain a consistent output format.

Suggested change
print(vlan + " is not configured in vxlan tunnel map table")
click.echo(vlan + " is not configured in vxlan tunnel map table")

Copilot uses AI. Check for mistakes.