From 963adafb014c4489e70cbd1d4cc0050fe2456d80 Mon Sep 17 00:00:00 2001 From: ray_wang Date: Wed, 26 Mar 2025 15:52:03 +0800 Subject: [PATCH] Add config and show cli command for neigh-suppress --- config/main.py | 1 + config/vlan.py | 31 +++++++++++++++++++++++++--- show/main.py | 1 + show/vlan.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 3 deletions(-) diff --git a/config/main.py b/config/main.py index 8a5534a2..42144c6a 100644 --- a/config/main.py +++ b/config/main.py @@ -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) diff --git a/config/vlan.py b/config/vlan.py index 7ace1d6d..816c384a 100644 --- a/config/vlan.py +++ b/config/vlan.py @@ -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): @@ -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 @@ -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): @@ -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='', required=True, type=int) +@click.argument('state', metavar='', required=True, type=click.Choice(["on", "off"])) +@clicommon.pass_db +def set_neigh_suppress(db, vid, state): + 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) diff --git a/show/main.py b/show/main.py index 0745b2d0..bc6b5886 100755 --- a/show/main.py +++ b/show/main.py @@ -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) diff --git a/show/vlan.py b/show/vlan.py index daa5be48..d3dcf51c 100644 --- a/show/vlan.py +++ b/show/vlan.py @@ -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:] + 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='', 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")