Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation changes for CiscoBgp4MIB #158

Merged
merged 5 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

67 changes: 37 additions & 30 deletions src/sonic_ax_impl/mibs/vendor/cisco/bgp4.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
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()
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 None:
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if neigh_info is None:
if neigh_info:
``` #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the condition check/

continue
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)

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
if state.isdigit():
status = 6
elif state in STATE_CODE:
status = STATE_CODE[state]
else:
continue

for nei, ses in sessions.items():
oid, status = bgp_peer_tuple(ses)
if oid is None: continue
oid = oid_head + oid_ip
self.session_status_list.append(oid)
self.session_status_map[oid] = status

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