Skip to content

Commit f5b70df

Browse files
authored
Fix quagga/FRR parser on IPv6 BGP sessions (sonic-net#122)
1 parent 29ebe43 commit f5b70df

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/sonic_ax_impl/lib/quaggaclient.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ def parse_bgp_summary(summ):
2222
l = ls[li]
2323
if l.startswith('Neighbor '):
2424
break
25-
if l.startswith('No IPv'): # eg. No IPv6 neighbor is configured
25+
if l.startswith('No IPv'): # eg. No IPv6 neighbor is configured, in Quagga (version 0.99.24.1)
2626
return bgpinfo
27-
if l.endswith('> exit'): # last command in the lines
27+
if l.startswith('% No BGP neighbors found'): # in FRRouting (version 7.2)
28+
return bgpinfo
29+
if l.endswith('> '): # directly hostname prompt, in FRRouting (version 4.0)
2830
return bgpinfo
2931
li += 1
3032

3133
## Read and store the table header
3234
if li >= n:
33-
raise ValueError('No table header found')
35+
raise ValueError('No table header found: ' + summ)
3436
hl = ls[li]
3537
li += 1
3638
ht = re.split('\s+', hl.rstrip())
+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
Hello, this is Quagga (version 0.99.24.1). Copyright 1996-2005 Kunihiro Ishiguro, et al. User Access Verification
2-
"Password:
3-
str-msn2700-05> show ipv6 bgp summary
4-
str-msn2700-05> exit
1+
show ip bgp ipv6 summary

tests/test_vtysh.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import sys
33

4+
INPUT_DIR = os.path.dirname(os.path.abspath(__file__))
45
modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
56
sys.path.insert(0, os.path.join(modules_path, 'src'))
7+
sys.path.insert(0, os.path.join(modules_path, 'tests'))
68

79
from unittest import TestCase
810
from unittest.mock import patch, mock_open
@@ -17,6 +19,7 @@
1719
from sonic_ax_impl.mibs.ietf import rfc4363
1820
from sonic_ax_impl.main import SonicMIB
1921
from sonic_ax_impl.lib.quaggaclient import parse_bgp_summary
22+
from mock_tables.socket import MockGetHostname
2023

2124
class TestSonicMIB(TestCase):
2225
@classmethod
@@ -106,10 +109,13 @@ def test_getpdu_ipv4_overwite_ipv6(self):
106109
self.assertEqual(str(value0.name), str(oid))
107110
self.assertEqual(value0.data, 6)
108111

109-
def parse_no_bgp():
110-
filename = 'bgpsummary_ipv6_nobgp.txt'
112+
def test_parse_no_bgp(self):
113+
filename = INPUT_DIR + '/mock_tables/bgpsummary_ipv6_nobgp.txt'
111114
with open(filename, 'rb') as f:
112115
bgpsu = f.read()
116+
hostname = MockGetHostname()
117+
prompt_hostname = ('\r\n' + hostname + '> ').encode()
118+
bgpsu += prompt_hostname
119+
bgpsu = bgpsu.decode('ascii', 'ignore')
113120
bgpsumm_ipv6 = parse_bgp_summary(bgpsu)
114121
self.assertEqual(bgpsumm_ipv6, [])
115-

0 commit comments

Comments
 (0)