Skip to content

Commit

Permalink
test: add bgp4 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 26, 2023
1 parent 3cd72d3 commit 0d131b5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/topotests/bgp_snmp_bgp4v2mib/r2/snmpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ access public_group "" any noauth prefix all all none

rocommunity public default

trapsess -v2c -c public 127.0.0.1

notificationEvent linkUpTrap linkUp ifIndex ifAdminStatus ifOperStatus
notificationEvent linkDownTrap linkDown ifIndex ifAdminStatus ifOperStatus

monitor -r 2 -e linkUpTrap "Generate linkUp" ifOperStatus != 2
monitor -r 2 -e linkDownTrap "Generate linkDown" ifOperStatus == 2


view all included .1

iquerySecName frr
Expand Down
2 changes: 2 additions & 0 deletions tests/topotests/bgp_snmp_bgp4v2mib/r2/snmptrapd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
authCommunity net,log public
disableAuthorization yes
35 changes: 35 additions & 0 deletions tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from lib.topogen import Topogen, TopoRouter, get_topogen
from lib.snmptest import SnmpTester
from lib import topotest
from lib.topolog import logger

pytestmark = [pytest.mark.bgpd, pytest.mark.snmp]

Expand Down Expand Up @@ -60,6 +61,11 @@ def setup_module(mod):
os.path.join(CWD, "{}/snmpd.conf".format(rname)),
"-Le -Ivacm_conf,usmConf,iquery -V -DAgentX",
)
router.load_config(
TopoRouter.RD_TRAP,
os.path.join(CWD, "{}/snmptrapd.conf".format(rname)),
" -On -OQ ",
)

tgen.start_router()

Expand All @@ -72,6 +78,7 @@ def teardown_module(mod):
def test_bgp_snmp_bgp4v2():
tgen = get_topogen()

r1 = tgen.gears["r1"]
r2 = tgen.gears["r2"]

def _bgp_converge_summary():
Expand Down Expand Up @@ -221,6 +228,34 @@ def _snmpwalk_med():
assert result, assertmsg



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')]]

# load trapd resulting file
tgen.mininet_cli()
# os.path.join(CWD, "{}/{}/snmptrapd.log".format(r2.logdir,r2.name))
snmptrapfile = "{}/{}/snmptrapd.log".format(r2.logdir,r2.name)
outputfile = open(snmptrapfile).read()
output = snmp.trap(outputfile)
logger.info(output)
return output == expected

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


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

0 comments on commit 0d131b5

Please sign in to comment.