From 7712317fd06298002942a87394b276f6837e3474 Mon Sep 17 00:00:00 2001 From: Dmytro Shytyi Date: Thu, 8 Aug 2024 15:42:40 +0200 Subject: [PATCH] topotest: test_bgp_snmp_bgpv4v2_notification This test checks the bgp crash on rt2 when 2 commands launched consequently: T0: rr, config -> router bgp 65004 -> neighbor 192.168.12.2 password 8888 T1: rt2, snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.7336.4.2.1 T2: test if rt2 bgp is crashed. Signed-off-by: Dmytro Shytyi --- .../bgp_snmp_bgp4v2_notification/r1/bgpd.conf | 32 +++++ .../r1/zebra.conf | 5 + .../bgp_snmp_bgp4v2_notification/r2/bgpd.conf | 25 ++++ .../r2/snmpd.conf | 17 +++ .../r2/zebra.conf | 5 + .../bgp_snmp_bgp4v2_notification/r3/bgpd.conf | 25 ++++ .../r3/zebra.conf | 5 + .../bgp_snmp_bgp4v2_notification/rr/bgpd.conf | 48 +++++++ .../rr/zebra.conf | 5 + .../test_bgp_snmp_bgp4v2_notification.py | 123 ++++++++++++++++++ 10 files changed, 290 insertions(+) create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/r1/bgpd.conf create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/r1/zebra.conf create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/r2/bgpd.conf create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/r2/snmpd.conf create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/r2/zebra.conf create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/r3/bgpd.conf create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/r3/zebra.conf create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/rr/bgpd.conf create mode 100644 tests/topotests/bgp_snmp_bgp4v2_notification/rr/zebra.conf create mode 100755 tests/topotests/bgp_snmp_bgp4v2_notification/test_bgp_snmp_bgp4v2_notification.py diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/r1/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/r1/bgpd.conf new file mode 100644 index 000000000000..73b02b71118d --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/r1/bgpd.conf @@ -0,0 +1,32 @@ +! +router bgp 65001 + no bgp ebgp-requires-policy + no bgp network import-check + no bgp default ipv4-unicast + neighbor 192.168.12.4 remote-as external + neighbor 192.168.12.4 timers 1 3 + neighbor 192.168.12.4 timers connect 1 + neighbor 2001:db8::12:4 remote-as external + neighbor 2001:db8::12:4 timers 1 3 + neighbor 2001:db8::12:4 timers connect 1 + ! + address-family ipv4 unicast + network 10.0.0.0/31 route-map p1 + network 10.0.0.2/32 route-map p2 + neighbor 192.168.12.4 activate + neighbor 192.168.12.4 addpath-tx-all-paths + network 7.7.7.7/32 + exit-address-family + address-family ipv6 unicast + network 2001:db8::1/128 route-map p1 + network 2001:db8:1::/56 route-map p2 + neighbor 2001:db8::12:4 activate + exit-address-family +! +route-map p1 permit 10 + set metric 1 +exit +route-map p2 permit 10 + set metric 2 + set origin incomplete +exit diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/r1/zebra.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/r1/zebra.conf new file mode 100644 index 000000000000..0807e89d08ce --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/r1/zebra.conf @@ -0,0 +1,5 @@ +! +interface r1-eth0 + ip address 192.168.12.1/24 + ipv6 address 2001:db8::12:1/64 +! diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/r2/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/r2/bgpd.conf new file mode 100644 index 000000000000..df49fef45625 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/r2/bgpd.conf @@ -0,0 +1,25 @@ +! +debug bgp updates +! +router bgp 65002 + no bgp ebgp-requires-policy + no bgp network import-check + no bgp default ipv4-unicast + neighbor 192.168.12.4 remote-as external + neighbor 192.168.12.4 timers 1 3 + neighbor 192.168.12.4 timers connect 1 + neighbor 2001:db8::12:4 remote-as external + neighbor 2001:db8::12:4 timers 1 3 + neighbor 2001:db8::12:4 timers connect 1 + ! + address-family ipv4 unicast + neighbor 192.168.12.4 activate + neighbor 192.168.12.4 addpath-tx-all-paths + + exit-address-family + address-family ipv6 unicast + neighbor 2001:db8::12:4 activate + exit-address-family +! +agentx +! diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/r2/snmpd.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/r2/snmpd.conf new file mode 100644 index 000000000000..032b93b67615 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/r2/snmpd.conf @@ -0,0 +1,17 @@ +agentAddress 127.0.0.1,[::1] + +group public_group v1 public +group public_group v2c public +access public_group "" any noauth prefix all all none + +rocommunity public default + +view all included .1 + +iquerySecName frr +rouser frr + +master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/r2/zebra.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/r2/zebra.conf new file mode 100644 index 000000000000..db6d7005a04a --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/r2/zebra.conf @@ -0,0 +1,5 @@ +! +interface r2-eth0 + ip address 192.168.12.2/24 + ipv6 address 2001:db8::12:2/64 +! diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/r3/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/r3/bgpd.conf new file mode 100644 index 000000000000..cfda6e084ebd --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/r3/bgpd.conf @@ -0,0 +1,25 @@ +! +debug bgp updates +! +router bgp 65003 + no bgp ebgp-requires-policy + no bgp network import-check + no bgp default ipv4-unicast + neighbor 192.168.12.4 remote-as external + neighbor 192.168.12.4 timers 1 3 + neighbor 192.168.12.4 timers connect 1 + neighbor 2001:db8::12:4 remote-as external + neighbor 2001:db8::12:4 timers 1 3 + neighbor 2001:db8::12:4 timers connect 1 + ! + address-family ipv4 unicast + neighbor 192.168.12.4 activate + neighbor 192.168.12.4 addpath-tx-all-paths + network 7.7.7.7/32 + exit-address-family + address-family ipv6 unicast + neighbor 2001:db8::12:4 activate + exit-address-family +! +agentx +! diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/r3/zebra.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/r3/zebra.conf new file mode 100644 index 000000000000..398af65ffe57 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/r3/zebra.conf @@ -0,0 +1,5 @@ +! +interface r3-eth0 + ip address 192.168.12.3/24 + ipv6 address 2001:db8::12:3/64 +! diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/rr/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/rr/bgpd.conf new file mode 100644 index 000000000000..8f2d0b129cc0 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/rr/bgpd.conf @@ -0,0 +1,48 @@ +! +debug bgp updates +! +router bgp 65004 + no bgp ebgp-requires-policy + no bgp network import-check + no bgp default ipv4-unicast + neighbor 192.168.12.1 remote-as external + neighbor 192.168.12.1 timers 1 3 + neighbor 192.168.12.1 timers connect 1 + neighbor 192.168.12.2 remote-as external + neighbor 192.168.12.2 timers 1 3 + neighbor 192.168.12.2 timers connect 1 + neighbor 192.168.12.3 remote-as external + neighbor 192.168.12.3 timers 1 3 + neighbor 192.168.12.3 timers connect 1 + neighbor 2001:db8::12:1 remote-as external + neighbor 2001:db8::12:1 timers 1 3 + neighbor 2001:db8::12:1 timers connect 1 + neighbor 2001:db8::12:2 remote-as external + neighbor 2001:db8::12:2 timers 1 3 + neighbor 2001:db8::12:2 timers connect 1 + neighbor 2001:db8::12:3 remote-as external + neighbor 2001:db8::12:3 timers 1 3 + neighbor 2001:db8::12:3 timers connect 1 + ! + address-family ipv4 unicast + neighbor 192.168.12.1 activate + neighbor 192.168.12.1 addpath-tx-all-paths + neighbor 192.168.12.1 route-server-client + neighbor 192.168.12.2 activate + neighbor 192.168.12.2 addpath-tx-all-paths + neighbor 192.168.12.2 route-server-client + neighbor 192.168.12.3 activate + neighbor 192.168.12.3 addpath-tx-all-paths + neighbor 192.168.12.3 route-server-client + exit-address-family + address-family ipv6 unicast + neighbor 2001:db8::12:1 activate + neighbor 2001:db8::12:1 route-server-client + neighbor 2001:db8::12:2 activate + neighbor 2001:db8::12:2 route-server-client + neighbor 2001:db8::12:3 activate + neighbor 2001:db8::12:3 route-server-client + exit-address-family +! +agentx +! diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/rr/zebra.conf b/tests/topotests/bgp_snmp_bgp4v2_notification/rr/zebra.conf new file mode 100644 index 000000000000..092673b8a977 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/rr/zebra.conf @@ -0,0 +1,5 @@ +! +interface rr-eth0 + ip address 192.168.12.4/24 + ipv6 address 2001:db8::12:4/64 +! diff --git a/tests/topotests/bgp_snmp_bgp4v2_notification/test_bgp_snmp_bgp4v2_notification.py b/tests/topotests/bgp_snmp_bgp4v2_notification/test_bgp_snmp_bgp4v2_notification.py new file mode 100755 index 000000000000..65354ccfc314 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2_notification/test_bgp_snmp_bgp4v2_notification.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python + +# +# Copyright (c) 2024 Dmytro Shytyi +# + + +""" +Test BGP OPEN NOTIFY (Configuration mismatch) followed by snmpwalk. +""" + +import os +import sys +import json +from time import sleep +import pytest +import functools +import subprocess + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib import topotest + +pytestmark = [pytest.mark.bgpd, pytest.mark.snmp] + + +def build_topo(tgen): + """Build function""" + + tgen.add_router("r1") + tgen.add_router("r2") + tgen.add_router("r3") + tgen.add_router("rr") + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["rr"]) + + +def setup_module(mod): + snmpd = os.system("which snmpd") + if snmpd: + error_msg = "SNMP not installed - skipping" + pytest.skip(error_msg) + + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + for rname, router in tgen.routers().items(): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, + os.path.join(CWD, "{}/bgpd.conf".format(rname)), + "-M snmp", + ) + router.load_config( + TopoRouter.RD_SNMP, + os.path.join(CWD, "{}/snmpd.conf".format(rname)), + "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX", + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_open_notification_change_configuration(): + tgen = get_topogen() + + tgen.gears["rr"].vtysh_multicmd( + """ +configure terminal +router bgp 65004 +neighbor 192.168.12.2 password 8888" +""" + ) + tgen.net["r2"].cmd("snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.7336.4.2.1") + tgen.gears["rr"].vtysh_multicmd( + """ +configure terminal +router bgp 65004 +no neighbor 192.168.12.2 password 8888" +""" + ) + + def _check_bgp_session(): + r1 = tgen.gears["r2"] + + output = json.loads(r1.vtysh_cmd("show bgp summary json")) + + if output["ipv4Unicast"]["peers"]["192.168.12.4"]["state"] == "Established": + return None + return False + + test_func1 = functools.partial(_check_bgp_session) + _, result1 = topotest.run_and_expect(test_func1, None, count=60, wait=0.5) + + assert result1 is None, "Failed to verify the nexthop_resolution MPLS: bgp session" + + +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip("Memory leak test/report is disabled") + + tgen.report_memory_leaks() + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args))