Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Jipan Yang <[email protected]>
  • Loading branch information
jipanyang committed Jun 24, 2019
1 parent 9e092ca commit e3e14ef
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions fpmsyncd/bgp_eoiu_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,31 @@ def __init__(self):
self.keepalivesRecvCnt = {}
self.bgp_ipv4_eoiu = False
self.bgp_ipv6_eoiu = False
self.get_peers_wt = self.DEF_TIME_OUT

def get_all_peers(self):
try:
cmd = "vtysh -c 'show bgp summary json'"
output = commands.getoutput(cmd)
peer_info = json.loads(output)
if "ipv4Unicast" in peer_info and "peers" in peer_info["ipv4Unicast"]:
self.ipv4_neighbors = peer_info["ipv4Unicast"]["peers"].keys()

if "ipv6Unicast" in peer_info and "peers" in peer_info["ipv6Unicast"]:
self.ipv6_neighbors = peer_info["ipv6Unicast"]["peers"].keys()

syslog.syslog('BGP ipv4 neighbors: {}'.format(self.ipv4_neighbors))
syslog.syslog('BGP ipv4 neighbors: {}'.format(self.ipv6_neighbors))

except Exception:
syslog.syslog(syslog.LOG_ERR, "*ERROR* get_all_peers Exception: %s" % (traceback.format_exc()))
time.sleep(5)
self.get_all_peers()
while self.get_peers_wt >= 0:
try:
cmd = "vtysh -c 'show bgp summary json'"
output = commands.getoutput(cmd)
peer_info = json.loads(output)
if "ipv4Unicast" in peer_info and "peers" in peer_info["ipv4Unicast"]:
self.ipv4_neighbors = peer_info["ipv4Unicast"]["peers"].keys()

if "ipv6Unicast" in peer_info and "peers" in peer_info["ipv6Unicast"]:
self.ipv6_neighbors = peer_info["ipv6Unicast"]["peers"].keys()

syslog.syslog('BGP ipv4 neighbors: {}'.format(self.ipv4_neighbors))
syslog.syslog('BGP ipv4 neighbors: {}'.format(self.ipv6_neighbors))
return

except Exception:
syslog.syslog(syslog.LOG_ERR, "*ERROR* get_all_peers Exception: %s" % (traceback.format_exc()))
time.sleep(5)
self.get_peers_wt -= 5
self.get_all_peers()
syslog.syslog(syslog.LOG_ERR, "Failed to get bgp neighbor info in {} seconds, exiting".format(self.DEF_TIME_OUT));
sys.exit(1)

def init_peers_eor_status(self):
# init neigh eor status to unknown
Expand Down Expand Up @@ -116,7 +122,7 @@ def bgp_eor_received(self, neigh, is_ipv4):
# it looks we need to record the keepalivesRecv count for detecting count change
if neighstr not in self.keepalivesRecvCnt:
self.keepalivesRecvCnt[neighstr] = neig_status[neighstr]["messageStats"]["keepalivesRecv"]
else :
else:
eor_received = (self.keepalivesRecvCnt[neighstr] is not neig_status[neighstr]["messageStats"]["keepalivesRecv"])
if eor_received:
syslog.syslog('BGP implicit eor received for neighbors: {}'.format(neigh))
Expand Down

0 comments on commit e3e14ef

Please sign in to comment.