Skip to content

Commit

Permalink
tests: add bgp4v2 MIB traps test
Browse files Browse the repository at this point in the history
Signed-off-by: Francois Dumontet <[email protected]>
  • Loading branch information
fdumontet6WIND committed Sep 28, 2023
1 parent af2cff6 commit 9c78fc4
Showing 1 changed file with 50 additions and 15 deletions.
65 changes: 50 additions & 15 deletions tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,38 +229,73 @@ def _snmpwalk_med():

def _snmptrap_ipv4():
expected = [
[
("1.3.6.1.2.1.15.3.1.7.192.168.12.1", "0.0.0.0"),
("1.3.6.1.2.1.15.3.1.14.192.168.12.1", '"00 00 "'),
("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "2"),
],
[
("1.3.6.1.2.1.15.3.1.7.192.168.12.1", "192.168.12.1"),
("1.3.6.1.2.1.15.3.1.14.192.168.12.1", '"00 00 "'),
("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "6"),
],
[
("1.3.6.1.2.1.15.3.1.7.192.168.12.1", "192.168.12.1"),
("1.3.6.1.2.1.15.3.1.14.192.168.12.1", '"06 04 "'),
("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "1"),
],
("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "7"),
("1.3.6.1.2.1.15.3.1.7.192.168.12.1", "192.168.12.1"),
("1.3.6.1.2.1.15.3.1.14.192.168.12.1", '"06 04 "'),
("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "6")
]

# load trapd resulting file
tgen.mininet_cli()
# os.path.join(CWD, "{}/{}/snmptrapd.log".format(r2.logdir,r2.name))
# tgen.mininet_cli()

snmptrapfile = "{}/{}/snmptrapd.log".format(r2.logdir, r2.name)
outputfile = open(snmptrapfile).read()
output = snmp.trap(outputfile)
logger.info(output)
output = snmp.trap_v4(outputfile)
return output == expected

r1.vtysh_cmd("clear bgp *")
_, result = topotest.run_and_expect(_snmptrap_ipv4, True, count=15, wait=2)
_, result = topotest.run_and_expect(_snmptrap_ipv4, True, count=2, wait=10)
assertmsg = "Can't fetch SNMP trap for ipv4"
assert result, assertmsg


def _snmptrap_ipv6():

expected = [
('1.3.6.1.3.5.1.1.2.1.13.1.4.192.168.12.1', '7'),
('1.3.6.1.3.5.1.1.2.1.6.1.4.192.168.12.1', '179'),
('1.3.6.1.3.5.1.1.3.1.1.1.4.192.168.12.1', '6'),
('1.3.6.1.3.5.1.1.3.1.2.1.4.192.168.12.1', '4'),
('1.3.6.1.3.5.1.1.3.1.4.1.4.192.168.12.1', '"00 "'),
('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', '7'),
('1.3.6.1.3.5.1.1.2.1.6.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1', '179'),
('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', '6'),
('1.3.6.1.3.5.1.1.3.1.2.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1', '4'),
('1.3.6.1.3.5.1.1.3.1.4.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1', '"00 "'),
('1.3.6.1.3.5.1.1.2.1.13.1.4.192.168.12.1', '6'),
('1.3.6.1.3.5.1.1.2.1.6.1.4.192.168.12.1', '179'),
('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'),
('1.3.6.1.3.5.1.1.2.1.6.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1', '179')
]




# load trapd resulting file
# tgen.mininet_cli()

snmptrapfile = "{}/{}/snmptrapd.log".format(r2.logdir,r2.name)
outputfile = open(snmptrapfile).read()
output = snmp.trap_v6(outputfile)
return output == expected

snmptrapfile = "{}/{}/snmptrapd.log".format(r2.logdir,r2.name)
trap_file = open(snmptrapfile, 'w')
trap_file.truncate(0)
trap_file.close()
r2.vtysh_cmd("conf\nbgp snmp traps bgp4-mibv2 enable")
r2.vtysh_cmd("conf\nbgp snmp traps rfc4273 disable")
r1.vtysh_cmd("clear bgp *")
_, result = topotest.run_and_expect(_snmptrap_ipv6, True, count=2, wait=10)
assertmsg = "Can't fetch SNMP trap for ipv6"
assert result, assertmsg


def test_memory_leak():
"Run the memory leak test and report results."
tgen = get_topogen()
Expand Down

0 comments on commit 9c78fc4

Please sign in to comment.