Skip to content

Commit 51b09a8

Browse files
Implementation changes for CiscoBgp4MIB (#158)
* [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.
1 parent 5957460 commit 51b09a8

14 files changed

+233
-353
lines changed

src/sonic_ax_impl/lib/perseverantsocket.py

-44
This file was deleted.

src/sonic_ax_impl/lib/quaggaclient.py

-165
This file was deleted.

src/sonic_ax_impl/mibs/vendor/cisco/bgp4.py

+40-34
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
11
import socket
22
from bisect import bisect_right
33
from sonic_ax_impl import mibs
4-
from sonic_ax_impl.lib.perseverantsocket import PerseverantSocket
5-
from sonic_ax_impl.lib.quaggaclient import QuaggaClient, bgp_peer_tuple
64
from ax_interface import MIBMeta, ValueType, MIBUpdater, SubtreeMIBEntry
75
from ax_interface.mib import MIBEntry
6+
from sonic_ax_impl.mibs import Namespace
7+
import ipaddress
8+
9+
STATE_CODE = {
10+
"Idle": 1,
11+
"Idle (Admin)": 1,
12+
"Connect": 2,
13+
"Active": 3,
14+
"OpenSent": 4,
15+
"OpenConfirm": 5,
16+
"Established": 6
17+
};
18+
819

920
class BgpSessionUpdater(MIBUpdater):
1021
def __init__(self):
1122
super().__init__()
12-
self.sock = PerseverantSocket(socket.AF_INET, socket.SOCK_STREAM
13-
, address_tuple=(QuaggaClient.HOST, QuaggaClient.PORT))
14-
self.QuaggaClient = QuaggaClient(self.sock)
23+
self.db_conn = Namespace.init_namespace_dbs()
1524

25+
self.neigh_state_map = {}
1626
self.session_status_map = {}
1727
self.session_status_list = []
1828

1929
def reinit_data(self):
20-
if not self.sock.connected:
21-
try:
22-
self.sock.reconnect()
23-
mibs.logger.info('Connected quagga socket')
24-
except (ConnectionRefusedError, socket.timeout) as e:
25-
mibs.logger.debug('Failed to connect quagga socket. Retry later...: {}.'.format(e))
26-
return
27-
self.QuaggaClient.auth()
28-
mibs.logger.info('Authed quagga socket')
30+
Namespace.connect_all_dbs(self.db_conn, mibs.STATE_DB)
31+
self.neigh_state_map = Namespace.dbs_keys_namespace(self.db_conn, mibs.STATE_DB, "NEIGH_STATE_TABLE|*")
2932

3033
def update_data(self):
3134
self.session_status_map = {}
3235
self.session_status_list = []
3336

34-
try:
35-
if not self.sock.connected:
36-
return
37-
38-
sessions = self.QuaggaClient.union_bgp_sessions()
39-
40-
except (socket.error, socket.timeout) as e:
41-
self.sock.close()
42-
mibs.logger.error('Failed to talk with quagga socket. Reconnect later...: {}.'.format(e))
43-
return
44-
except ValueError as e:
45-
self.sock.close()
46-
mibs.logger.error('Receive unexpected data from quagga socket. Reconnect later...: {}.'.format(e))
47-
return
48-
49-
for nei, ses in sessions.items():
50-
oid, status = bgp_peer_tuple(ses)
51-
if oid is None: continue
52-
self.session_status_list.append(oid)
53-
self.session_status_map[oid] = status
37+
for neigh_key, db_index in self.neigh_state_map.items():
38+
neigh_str = neigh_key.decode()
39+
neigh_str = neigh_str.split('|')[1]
40+
neigh_info = self.db_conn[db_index].get_all(mibs.STATE_DB, neigh_key, blocking=False)
41+
if neigh_info is not None:
42+
state = neigh_info[b'state'].decode()
43+
ip = ipaddress.ip_address(neigh_str)
44+
if type(ip) is ipaddress.IPv4Address:
45+
oid_head = (1, 4)
46+
else:
47+
oid_head = (2, 16)
48+
oid_ip = tuple(i for i in ip.packed)
49+
50+
if state.isdigit():
51+
status = 6
52+
elif state in STATE_CODE:
53+
status = STATE_CODE[state]
54+
else:
55+
continue
56+
57+
oid = oid_head + oid_ip
58+
self.session_status_list.append(oid)
59+
self.session_status_map[oid] = status
5460

5561
self.session_status_list.sort()
5662

tests/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
import tests.mock_tables.socket

tests/mock_tables/asic0/state_db.json

+12
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,17 @@
2121
"tx2power": -5.4,
2222
"tx3power": -5.4,
2323
"tx4power": -5.4
24+
},
25+
"NEIGH_STATE_TABLE|10.0.0.0": {
26+
"state": "Connect"
27+
},
28+
"NEIGH_STATE_TABLE|10.0.0.2": {
29+
"state": "Active"
30+
},
31+
"NEIGH_STATE_TABLE|10.10.0.0": {
32+
"state": "Established"
33+
},
34+
"NEIGH_STATE_TABLE|fec0::ffff:afa:07": {
35+
"state": "Active"
2436
}
2537
}

tests/mock_tables/asic1/state_db.json

+9
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@
2121
"tx2power": -5.4,
2222
"tx3power": -5.4,
2323
"tx4power": -5.4
24+
},
25+
"NEIGH_STATE_TABLE|10.0.0.6": {
26+
"state": "Idle"
27+
},
28+
"NEIGH_STATE_TABLE|10.0.0.8": {
29+
"state": "Active"
30+
},
31+
"NEIGH_STATE_TABLE|10.10.0.4": {
32+
"state": "Established"
2433
}
2534
}

tests/mock_tables/asic2/appl_db.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"scope": "global",
7676
"family": "IPv4"
7777
},
78-
"INTF_TABLE:PortChannel04:10.10.0.5/31": {
78+
"INTF_TABLE:PortChannel04:10.10.0.4/31": {
7979
"scope": "global",
8080
"family": "IPv4"
8181
},

tests/mock_tables/asic2/state_db.json

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
{
2+
"NEIGH_STATE_TABLE|10.10.0.1": {
3+
"state": "Established"
4+
},
5+
"NEIGH_STATE_TABLE|10.10.0.5": {
6+
"state": "Established"
7+
}
28
}

tests/mock_tables/bgpsummary_ipv6.txt

-19
This file was deleted.

tests/mock_tables/bgpsummary_ipv6_nobgp.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)