Added change to add 'peerType' as element in NEIGH_STATE_TABLE. (#15265)
What I did: Added change to add 'peerType' as element in NEIGH_STATE_TABLE. 'peerType' can be i-BGP vs e-BGP determined based on local and remote AS number. Why I did: This is useful to filter neighbors in SONiC as internal vs external in chassis use-case (example: telemetry) Verification: Manual Verification 127.0.0.1:6379[6]> hgetall "NEIGH_STATE_TABLE|10.0.0.5" 1) "state" 2) "Established" 3) "peerType" 4) "e-BGP" 127.0.0.1:6379[6]> hgetall "NEIGH_STATE_TABLE|2603:10e2:400::4" 1) "state" 2) "Established" 3) "peerType" 4) "i-BGP" Also sonic-mgmt test case test_bgp_fact.py is enhanced: Enhanced bgp_fact to validate NEIGH_STATE_TABLE element 'peerType' sonic-mgmt#8462
This commit is contained in:
parent
70d637d904
commit
a53ad57765
@ -6,7 +6,8 @@ Description: bgpmon.py -- populating bgp related information in stateDB.
|
|||||||
|
|
||||||
Initial creation of this daemon is to assist SNMP agent in obtaining the
|
Initial creation of this daemon is to assist SNMP agent in obtaining the
|
||||||
BGP related information for its MIB support. The MIB that this daemon is
|
BGP related information for its MIB support. The MIB that this daemon is
|
||||||
assisting is for the CiscoBgp4MIB (Neighbor state only). If there are other
|
assisting is for the CiscoBgp4MIB (Neighbor state only). Also for chassis use-case
|
||||||
|
it identify if the given BGP neighbors as i-BGP vs e-BGP. If there are other
|
||||||
BGP related items that needs to be updated in a periodic manner in the
|
BGP related items that needs to be updated in a periodic manner in the
|
||||||
future, then more can be added into this process.
|
future, then more can be added into this process.
|
||||||
|
|
||||||
@ -69,7 +70,9 @@ class BgpStateGet:
|
|||||||
peer_l = peer_dict["peers"].keys()
|
peer_l = peer_dict["peers"].keys()
|
||||||
self.new_peer_l.update(peer_l)
|
self.new_peer_l.update(peer_l)
|
||||||
for peer in peer_l:
|
for peer in peer_l:
|
||||||
self.new_peer_state[peer] = peer_dict["peers"][peer]["state"]
|
self.new_peer_state[peer] = (peer_dict["peers"][peer]["state"],
|
||||||
|
peer_dict["peers"][peer]["remoteAs"],
|
||||||
|
peer_dict["peers"][peer]["localAs"])
|
||||||
|
|
||||||
# Get a new snapshot of BGP neighbors and store them in the "new" location
|
# Get a new snapshot of BGP neighbors and store them in the "new" location
|
||||||
def get_all_neigh_states(self):
|
def get_all_neigh_states(self):
|
||||||
@ -124,17 +127,19 @@ class BgpStateGet:
|
|||||||
key = "NEIGH_STATE_TABLE|%s" % peer
|
key = "NEIGH_STATE_TABLE|%s" % peer
|
||||||
if peer in self.peer_l:
|
if peer in self.peer_l:
|
||||||
# only update the entry if state changed
|
# only update the entry if state changed
|
||||||
if self.peer_state[peer] != self.new_peer_state[peer]:
|
if self.peer_state[peer] != self.new_peer_state[peer][0]:
|
||||||
# state changed. Update state DB for this entry
|
# state changed. Update state DB for this entry
|
||||||
state = self.new_peer_state[peer]
|
state = self.new_peer_state[peer][0]
|
||||||
data[key] = {'state':state}
|
peerType = "i-BGP" if self.new_peer_state[peer][1] == self.new_peer_state[peer][2] else "e-BGP"
|
||||||
|
data[key] = {'state':state, 'peerType':peerType}
|
||||||
self.peer_state[peer] = state
|
self.peer_state[peer] = state
|
||||||
# remove this neighbor from old set since it is accounted for
|
# remove this neighbor from old set since it is accounted for
|
||||||
self.peer_l.remove(peer)
|
self.peer_l.remove(peer)
|
||||||
else:
|
else:
|
||||||
# New neighbor found case. Add to dictionary and state DB
|
# New neighbor found case. Add to dictionary and state DB
|
||||||
state = self.new_peer_state[peer]
|
state = self.new_peer_state[peer][0]
|
||||||
data[key] = {'state':state}
|
peerType = "i-BGP" if self.new_peer_state[peer][1] == self.new_peer_state[peer][2] else "e-BGP"
|
||||||
|
data[key] = {'state':state, 'peerType':peerType}
|
||||||
self.peer_state[peer] = state
|
self.peer_state[peer] = state
|
||||||
if len(data) > PIPE_BATCH_MAX_COUNT:
|
if len(data) > PIPE_BATCH_MAX_COUNT:
|
||||||
self.flush_pipe(data)
|
self.flush_pipe(data)
|
||||||
|
Reference in New Issue
Block a user