Skip to content
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

[sonic-clear] add a clear fdb command #186

Merged
merged 4 commits into from
Jan 26, 2018
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
30 changes: 30 additions & 0 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,35 @@ def arp(ipaddress):
cli.add_command(arp)
ip.add_command(arp)

#
# 'fdb' command ####
#
@cli.group()
def fdb():
"""Clear FDB table"""
pass

@fdb.command('all')
def clear_all_fdb():
"""Clear All FDB entries"""
command = 'fdbclear'
run_command(command)

# 'sonic-clear fdb port' and 'sonic-clear fdb vlan' will be added later
'''
@fdb.command('port')
@click.argument('portid', required=True)
def clear_port_fdb(portid):
"""Clear FDB entries learned from one port"""
command = 'fdbclear' + ' -p ' + portid
run_command(command)

@fdb.command('vlan')
@click.argument('vlanid', required=True)
def clear_vlan_fdb(vlanid):
"""Clear FDB entries learned in one VLAN"""
command = 'fdbclear' + ' -v ' + vlanid
run_command(command)
'''
if __name__ == '__main__':
cli()
58 changes: 58 additions & 0 deletions scripts/fdbclear
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/python
"""
Script to clear MAC/FDB entries learnt in Hardware

usage: fdbclear [-p PORT] [-v VLAN]
optional arguments:
-p, --port FDB learned on specific port: Ethernet0
-v, --vlan FDB learned on specific Vlan: 1000

Example of the output:

"""

import argparse
import json
import sys

from natsort import natsorted
from swsssdk import SonicV2Connector, port_util
from tabulate import tabulate

class FdbClear(object):


def __init__(self):
super(FdbClear,self).__init__()
self.db = SonicV2Connector(host="127.0.0.1")
self.db.connect(self.db.APPL_DB)
return

def send_notification(self, op, data):
opdata = [op,data]
msg = json.dumps(opdata,separators=(',',':'))
self.db.publish('APPL_DB','FLUSHFDBREQUEST', msg)
return

def main():

parser = argparse.ArgumentParser(description='Clear FDB entries', formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-p', '--port', type=str, help='Clear FDB learned on specific port: Ethernet0', default=None)
parser.add_argument('-v', '--vlan', type=str, help='Clear FDB learned on specific Vlan: 1001', default=None)
args = parser.parse_args()

try:
fdb = FdbClear()
if args.vlan is not None:
print("command not supported yet.")
elif args.port is not None:
print("command not supported yet.")
else:
fdb.send_notification("ALL", "ALL")
print("FDB entries are cleared.")
except Exception as e:
print e.message
sys.exit(1)

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def get_test_suite():
'scripts/ecnconfig',
'scripts/fast-reboot',
'scripts/fast-reboot-dump.py',
'scripts/fdbclear',
'scripts/fdbshow',
'scripts/generate_dump',
'scripts/intfutil',
Expand Down