4 # Copyright (c) 2022 Donatas Abraitis <donatas@opensourcerouting.org>
6 # Permission to use, copy, modify, and/or distribute this software
7 # for any purpose with or without fee is hereby granted, provided
8 # that the above copyright notice and this permission notice appear
11 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
15 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
17 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 Test some of the BGP4V2-MIB entries.
28 from time
import sleep
32 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
33 sys
.path
.append(os
.path
.join(CWD
, "../"))
35 # pylint: disable=C0413
36 # Import topogen and topotest helpers
37 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
38 from lib
.snmptest
import SnmpTester
39 from lib
import topotest
41 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.snmp
]
48 switch
= tgen
.add_switch("s1")
49 switch
.add_link(tgen
.gears
["r1"])
50 switch
.add_link(tgen
.gears
["r2"])
53 def setup_module(mod
):
54 snmpd
= os
.system("which snmpd")
56 error_msg
= "SNMP not installed - skipping"
57 pytest
.skip(error_msg
)
59 tgen
= Topogen(build_topo
, mod
.__name
__)
62 for rname
, router
in tgen
.routers().items():
64 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
68 os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
)),
73 os
.path
.join(CWD
, "{}/snmpd.conf".format(rname
)),
74 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX",
80 def teardown_module(mod
):
85 def test_bgp_snmp_bgp4v2():
90 def _bgp_converge_summary():
91 output
= json
.loads(r2
.vtysh_cmd("show bgp summary json"))
96 "state": "Established",
104 "state": "Established",
110 return topotest
.json_cmp(output
, expected
)
112 test_func
= functools
.partial(_bgp_converge_summary
)
113 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
114 assert result
is None, "Can't see connections established"
116 def _bgp_converge_prefixes():
117 output
= json
.loads(r2
.vtysh_cmd("show bgp all json"))
130 "origin": "incomplete",
146 "origin": "incomplete",
152 return topotest
.json_cmp(output
, expected
)
154 test_func
= functools
.partial(_bgp_converge_prefixes
)
155 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
156 assert result
is None, "Can't see prefixes from R1"
158 snmp
= SnmpTester(r2
, "localhost", "public", "2c", "-Ln -On")
160 def _snmpwalk_remote_addr():
162 "1.3.6.1.3.5.1.1.2.1.5.1.4.192.168.12.1": "C0 A8 0C 01",
163 "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",
166 # bgp4V2PeerRemoteAddr
167 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.2.1.5")
168 return output
== expected
170 _
, result
= topotest
.run_and_expect(_snmpwalk_remote_addr
, True, count
=10, wait
=1)
171 assertmsg
= "Can't fetch SNMP for bgp4V2PeerRemoteAddr"
172 assert result
, assertmsg
174 def _snmpwalk_peer_state():
176 "1.3.6.1.3.5.1.1.2.1.13.1.4.192.168.12.1": "6",
177 "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",
181 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.2.1.13")
182 return output
== expected
184 _
, result
= topotest
.run_and_expect(_snmpwalk_peer_state
, True, count
=10, wait
=1)
185 assertmsg
= "Can't fetch SNMP for bgp4V2PeerState"
186 assert result
, assertmsg
188 def _snmpwalk_peer_last_error_code_received():
190 "1.3.6.1.3.5.1.1.3.1.1.1.4.192.168.12.1": "0",
191 "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",
194 # bgp4V2PeerLastErrorCodeReceived
195 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.3.1.1")
196 return output
== expected
198 _
, result
= topotest
.run_and_expect(
199 _snmpwalk_peer_last_error_code_received
, True, count
=10, wait
=1
201 assertmsg
= "Can't fetch SNMP for bgp4V2PeerLastErrorCodeReceived"
202 assert result
, assertmsg
204 def _snmpwalk_origin():
206 "1.3.6.1.3.5.1.1.9.1.9.1.4.10.0.0.0.31.192.168.12.1": "1",
207 "1.3.6.1.3.5.1.1.9.1.9.1.4.10.0.0.2.32.192.168.12.1": "3",
208 "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",
209 "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",
213 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.9.1.9")
214 return output
== expected
216 _
, result
= topotest
.run_and_expect(_snmpwalk_origin
, True, count
=10, wait
=1)
217 assertmsg
= "Can't fetch SNMP for bgp4V2NlriOrigin"
218 assert result
, assertmsg
222 "1.3.6.1.3.5.1.1.9.1.17.1.4.10.0.0.0.31.192.168.12.1": "1",
223 "1.3.6.1.3.5.1.1.9.1.17.1.4.10.0.0.2.32.192.168.12.1": "2",
224 "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",
225 "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",
229 output
, _
= snmp
.walk(".1.3.6.1.3.5.1.1.9.1.17")
230 return output
== expected
232 _
, result
= topotest
.run_and_expect(_snmpwalk_med
, True, count
=10, wait
=1)
233 assertmsg
= "Can't fetch SNMP for bgp4V2NlriMed"
234 assert result
, assertmsg
237 def test_memory_leak():
238 "Run the memory leak test and report results."
240 if not tgen
.is_memleak_enabled():
241 pytest
.skip("Memory leak test/report is disabled")
243 tgen
.report_memory_leaks()
246 if __name__
== "__main__":
247 args
= ["-s"] + sys
.argv
[1:]
248 sys
.exit(pytest
.main(args
))