Skip to content

Commit

Permalink
Implementation changes for CiscoBgp4MIB (#158)
Browse files Browse the repository at this point in the history
* [BGP]:  Currently the data required for CiscoBgp4MIB is retrieved from bgpd deamon. snmp_ax_impl connects to bgpd daemon via tcp socket and retreives the BGP neighbor information required for CiscoBgp4MIB. This design is modified to support multi-asic platform. The data required by CiscoBgp4MIB can be populated in STATE_DB by a new daemon in BGP docker. Changes made:
- snmp_ax_impl to retrieve NEIGH_STATE_TABLE from STATE_DB. This change will affect both single and multi asic platforms. 
- Update bgp MIB unit tests to use STATE_DB data instead of using vtysh socket.
  • Loading branch information
SuvarnaMeenakshi authored and abdosi committed Sep 28, 2020
1 parent 4fc06ad commit a951db0
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 353 deletions.
44 changes: 0 additions & 44 deletions src/sonic_ax_impl/lib/perseverantsocket.py

This file was deleted.

165 changes: 0 additions & 165 deletions src/sonic_ax_impl/lib/quaggaclient.py

This file was deleted.

74 changes: 40 additions & 34 deletions src/sonic_ax_impl/mibs/vendor/cisco/bgp4.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
import socket
from bisect import bisect_right
from sonic_ax_impl import mibs
from sonic_ax_impl.lib.perseverantsocket import PerseverantSocket
from sonic_ax_impl.lib.quaggaclient import QuaggaClient, bgp_peer_tuple
from ax_interface import MIBMeta, ValueType, MIBUpdater, SubtreeMIBEntry
from ax_interface.mib import MIBEntry
from sonic_ax_impl.mibs import Namespace
import ipaddress

STATE_CODE = {
"Idle": 1,
"Idle (Admin)": 1,
"Connect": 2,
"Active": 3,
"OpenSent": 4,
"OpenConfirm": 5,
"Established": 6
};


class BgpSessionUpdater(MIBUpdater):
def __init__(self):
super().__init__()
self.sock = PerseverantSocket(socket.AF_INET, socket.SOCK_STREAM
, address_tuple=(QuaggaClient.HOST, QuaggaClient.PORT))
self.QuaggaClient = QuaggaClient(self.sock)
self.db_conn = Namespace.init_namespace_dbs()

self.neigh_state_map = {}
self.session_status_map = {}
self.session_status_list = []

def reinit_data(self):
if not self.sock.connected:
try:
self.sock.reconnect()
mibs.logger.info('Connected quagga socket')
except (ConnectionRefusedError, socket.timeout) as e:
mibs.logger.debug('Failed to connect quagga socket. Retry later...: {}.'.format(e))
return
self.QuaggaClient.auth()
mibs.logger.info('Authed quagga socket')
Namespace.connect_all_dbs(self.db_conn, mibs.STATE_DB)
self.neigh_state_map = Namespace.dbs_keys_namespace(self.db_conn, mibs.STATE_DB, "NEIGH_STATE_TABLE|*")

def update_data(self):
self.session_status_map = {}
self.session_status_list = []

try:
if not self.sock.connected:
return

sessions = self.QuaggaClient.union_bgp_sessions()

except (socket.error, socket.timeout) as e:
self.sock.close()
mibs.logger.error('Failed to talk with quagga socket. Reconnect later...: {}.'.format(e))
return
except ValueError as e:
self.sock.close()
mibs.logger.error('Receive unexpected data from quagga socket. Reconnect later...: {}.'.format(e))
return

for nei, ses in sessions.items():
oid, status = bgp_peer_tuple(ses)
if oid is None: continue
self.session_status_list.append(oid)
self.session_status_map[oid] = status
for neigh_key, db_index in self.neigh_state_map.items():
neigh_str = neigh_key.decode()
neigh_str = neigh_str.split('|')[1]
neigh_info = self.db_conn[db_index].get_all(mibs.STATE_DB, neigh_key, blocking=False)
if neigh_info is not None:
state = neigh_info[b'state'].decode()
ip = ipaddress.ip_address(neigh_str)
if type(ip) is ipaddress.IPv4Address:
oid_head = (1, 4)
else:
oid_head = (2, 16)
oid_ip = tuple(i for i in ip.packed)

if state.isdigit():
status = 6
elif state in STATE_CODE:
status = STATE_CODE[state]
else:
continue

oid = oid_head + oid_ip
self.session_status_list.append(oid)
self.session_status_map[oid] = status

self.session_status_list.sort()

Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
import tests.mock_tables.socket
12 changes: 12 additions & 0 deletions tests/mock_tables/asic0/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,17 @@
"tx2power": -5.4,
"tx3power": -5.4,
"tx4power": -5.4
},
"NEIGH_STATE_TABLE|10.0.0.0": {
"state": "Connect"
},
"NEIGH_STATE_TABLE|10.0.0.2": {
"state": "Active"
},
"NEIGH_STATE_TABLE|10.10.0.0": {
"state": "Established"
},
"NEIGH_STATE_TABLE|fec0::ffff:afa:07": {
"state": "Active"
}
}
9 changes: 9 additions & 0 deletions tests/mock_tables/asic1/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@
"tx2power": -5.4,
"tx3power": -5.4,
"tx4power": -5.4
},
"NEIGH_STATE_TABLE|10.0.0.6": {
"state": "Idle"
},
"NEIGH_STATE_TABLE|10.0.0.8": {
"state": "Active"
},
"NEIGH_STATE_TABLE|10.10.0.4": {
"state": "Established"
}
}
2 changes: 1 addition & 1 deletion tests/mock_tables/asic2/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"scope": "global",
"family": "IPv4"
},
"INTF_TABLE:PortChannel04:10.10.0.5/31": {
"INTF_TABLE:PortChannel04:10.10.0.4/31": {
"scope": "global",
"family": "IPv4"
},
Expand Down
6 changes: 6 additions & 0 deletions tests/mock_tables/asic2/state_db.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
{
"NEIGH_STATE_TABLE|10.10.0.1": {
"state": "Established"
},
"NEIGH_STATE_TABLE|10.10.0.5": {
"state": "Established"
}
}
19 changes: 0 additions & 19 deletions tests/mock_tables/bgpsummary_ipv6.txt

This file was deleted.

1 change: 0 additions & 1 deletion tests/mock_tables/bgpsummary_ipv6_nobgp.txt

This file was deleted.

Loading

0 comments on commit a951db0

Please sign in to comment.