2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2022 Donatas Abraitis <donatas@opensourcerouting.org>
9 Test some of the BGP4V2-MIB entries.
15 from time
import sleep
19 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
20 sys
.path
.append(os
.path
.join(CWD
, "../"))
22 # pylint: disable=C0413
23 # Import topogen and topotest helpers
24 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
25 from lib
.snmptest
import SnmpTester
26 from lib
import topotest
28 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.snmp
]
35 switch
= tgen
.add_switch("s1")
36 switch
.add_link(tgen
.gears
["r1"])
37 switch
.add_link(tgen
.gears
["r2"])
40 def setup_module(mod
):
41 snmpd
= os
.system("which snmpd")
43 error_msg
= "SNMP not installed - skipping"
44 pytest
.skip(error_msg
)
46 tgen
= Topogen(build_topo
, mod
.__name
__)
49 for rname
, router
in tgen
.routers().items():
51 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
55 os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
)),
60 os
.path
.join(CWD
, "{}/snmpd.conf".format(rname
)),
61 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX",
67 def teardown_module(mod
):
72 def test_bgp_snmp_bgp4v2():
77 def _bgp_converge_summary():
78 output
= json
.loads(r2
.vtysh_cmd("show bgp summary json"))
83 "state": "Established",
91 "state": "Established",
97 return topotest
.json_cmp(output
, expected
)
99 test_func
= functools
.partial(_bgp_converge_summary
)
100 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
101 assert result
is None, "Can't see connections established"
103 def _bgp_converge_prefixes():
104 output
= json
.loads(r2
.vtysh_cmd("show bgp all json"))
117 "origin": "incomplete",
133 "origin": "incomplete",
139 return topotest
.json_cmp(output
, expected
)
141 test_func
= functools
.partial(_bgp_converge_prefixes
)
142 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
143 assert result
is None, "Can't see prefixes from R1"
145 snmp
= SnmpTester(r2
, "localhost", "public", "2c", "-Ln -On")
147 def _snmpwalk_remote_addr():
149 "1.3.6.1.3.5.1.1.2.1.5.1.4.192.168.12.1": "C0 A8 0C 01",
150 "1.3.6.1.3.5.1.1.2.1.5.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "20 01 0D B8 00 00 00 00 00 00 00 00 00 12 00 01",
153 # bgp4V2PeerRemoteAddr
154 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.2.1.5")
155 return output
== expected
157 _
, result
= topotest
.run_and_expect(_snmpwalk_remote_addr
, True, count
=10, wait
=1)
158 assertmsg
= "Can't fetch SNMP for bgp4V2PeerRemoteAddr"
159 assert result
, assertmsg
161 def _snmpwalk_peer_state():
163 "1.3.6.1.3.5.1.1.2.1.13.1.4.192.168.12.1": "6",
164 "1.3.6.1.3.5.1.1.2.1.13.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "6",
168 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.2.1.13")
169 return output
== expected
171 _
, result
= topotest
.run_and_expect(_snmpwalk_peer_state
, True, count
=10, wait
=1)
172 assertmsg
= "Can't fetch SNMP for bgp4V2PeerState"
173 assert result
, assertmsg
175 def _snmpwalk_peer_last_error_code_received():
177 "1.3.6.1.3.5.1.1.3.1.1.1.4.192.168.12.1": "0",
178 "1.3.6.1.3.5.1.1.3.1.1.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "0",
181 # bgp4V2PeerLastErrorCodeReceived
182 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.3.1.1")
183 return output
== expected
185 _
, result
= topotest
.run_and_expect(
186 _snmpwalk_peer_last_error_code_received
, True, count
=10, wait
=1
188 assertmsg
= "Can't fetch SNMP for bgp4V2PeerLastErrorCodeReceived"
189 assert result
, assertmsg
191 def _snmpwalk_origin():
193 "1.3.6.1.3.5.1.1.9.1.9.1.4.10.0.0.0.31.192.168.12.1": "1",
194 "1.3.6.1.3.5.1.1.9.1.9.1.4.10.0.0.2.32.192.168.12.1": "3",
195 "1.3.6.1.3.5.1.1.9.1.9.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "1",
196 "1.3.6.1.3.5.1.1.9.1.9.2.16.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "3",
200 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.9.1.9")
201 return output
== expected
203 _
, result
= topotest
.run_and_expect(_snmpwalk_origin
, True, count
=10, wait
=1)
204 assertmsg
= "Can't fetch SNMP for bgp4V2NlriOrigin"
205 assert result
, assertmsg
209 "1.3.6.1.3.5.1.1.9.1.17.1.4.10.0.0.0.31.192.168.12.1": "1",
210 "1.3.6.1.3.5.1.1.9.1.17.1.4.10.0.0.2.32.192.168.12.1": "2",
211 "1.3.6.1.3.5.1.1.9.1.17.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "1",
212 "1.3.6.1.3.5.1.1.9.1.17.2.16.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "2",
216 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.9.1.17")
217 return output
== expected
219 _
, result
= topotest
.run_and_expect(_snmpwalk_med
, True, count
=10, wait
=1)
220 assertmsg
= "Can't fetch SNMP for bgp4V2NlriMed"
221 assert result
, assertmsg
224 def test_memory_leak():
225 "Run the memory leak test and report results."
227 if not tgen
.is_memleak_enabled():
228 pytest
.skip("Memory leak test/report is disabled")
230 tgen
.report_memory_leaks()
233 if __name__
== "__main__":
234 args
= ["-s"] + sys
.argv
[1:]
235 sys
.exit(pytest
.main(args
))