forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfdbclear
More file actions
56 lines (43 loc) · 1.58 KB
/
fdbclear
File metadata and controls
56 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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 swsscommon.swsscommon import SonicV2Connector
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()