Skip to content

Commit

Permalink
Separated the notifications for "sonic-clear nat translations" and "…
Browse files Browse the repository at this point in the history
…sonic-clear nat statistics" command (#892)

Signed-off-by: Akhilesh Samineni <[email protected]>
  • Loading branch information
AkhileshSamineni authored Jul 8, 2020
1 parent 7c512f3 commit 9715244
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 11 additions & 4 deletions scripts/natclear
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ class NatClear(object):
self.db.connect(self.db.APPL_DB)
return

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

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


def main():
parser = argparse.ArgumentParser(description='Clear the nat information',
formatter_class=argparse.RawTextHelpFormatter,
Expand All @@ -49,11 +56,11 @@ def main():
try:
nat = NatClear()
if clear_translations:
nat.send_notification("ENTRIES", "ALL")
nat.send_entries_notification("ENTRIES", "ALL")
print ""
print("Dynamic NAT entries are cleared.")
elif clear_statistics:
nat.send_notification("STATISTICS", "ALL")
nat.send_statistics_notification("STATISTICS", "ALL")
print ""
print("NAT statistics are cleared.")
except Exception as e:
Expand Down
10 changes: 8 additions & 2 deletions scripts/natshow
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class NatShow(object):
continue

ip_protocol = "all"
source = "---"
destination = "---"
translated_dst = "---"
translated_src = "---"

Expand Down Expand Up @@ -249,7 +251,7 @@ class NatShow(object):
napt_keys = re.split(':', napt_entry)
napt_values = self.appl_db.get_all(self.appl_db.APPL_DB,'NAPT_TABLE:{}'.format(napt_entry))

ip_protocol = napt_keys[0]
ip_protocol = napt_keys[0].lower()
source = "---"
destination = "---"

Expand Down Expand Up @@ -278,6 +280,8 @@ class NatShow(object):
nat_twice_values = self.appl_db.get_all(self.appl_db.APPL_DB,'NAT_TWICE_TABLE:{}'.format(nat_twice_entry))

ip_protocol = "all"
source = "---"
destination = "---"

source = nat_twice_keys[0]
destination = nat_twice_keys[1]
Expand All @@ -301,7 +305,9 @@ class NatShow(object):
napt_twice_keys = re.split(':', napt_twice_entry)
napt_twice_values = self.appl_db.get_all(self.appl_db.APPL_DB,'NAPT_TWICE_TABLE:{}'.format(napt_twice_entry))

ip_protocol = napt_twice_keys[0]
ip_protocol = napt_twice_keys[0].lower()
source = "---"
destination = "---"

source = napt_twice_keys[1] + ':' + napt_twice_keys[2]
destination = napt_twice_keys[3] + ':' + napt_twice_keys[4]
Expand Down

0 comments on commit 9715244

Please sign in to comment.