]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_orf/test_bgp_orf.py
2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2022 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
9 Test if BGP ORF filtering is working correctly when modifying
12 Initially advertise 10.10.10.1/32 from R1 to R2. Add new prefix
13 10.10.10.2/32 to r1 prefix list on R2. Test if we updated ORF
14 prefix-list correctly.
23 pytestmark
= pytest
.mark
.bgpd
25 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
26 sys
.path
.append(os
.path
.join(CWD
, "../"))
28 # pylint: disable=C0413
29 from lib
import topotest
30 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
32 pytestmark
= [pytest
.mark
.bgpd
]
35 def setup_module(mod
):
36 topodef
= {"s1": ("r1", "r2")}
37 tgen
= Topogen(topodef
, mod
.__name
__)
40 router_list
= tgen
.routers()
42 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
44 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
47 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
53 def teardown_module(mod
):
61 if tgen
.routers_have_failure():
62 pytest
.skip(tgen
.errors
)
67 def _bgp_converge_r1():
70 "show bgp ipv4 unicast neighbor 192.168.1.2 advertised-routes json"
73 expected
= {"advertisedRoutes": {"10.10.10.1/32": {}, "10.10.10.2/32": None}}
74 return topotest
.json_cmp(output
, expected
)
76 test_func
= functools
.partial(_bgp_converge_r1
)
77 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
78 assert result
is None, "Can't apply ORF from R1 to R2"
80 def _bgp_converge_r2():
81 output
= json
.loads(r2
.vtysh_cmd("show bgp ipv4 unicast summary json"))
87 "state": "Established",
92 return topotest
.json_cmp(output
, expected
)
94 test_func
= functools
.partial(_bgp_converge_r2
)
95 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
96 assert result
is None, "ORF filtering is not working from R1 to R2"
101 ip prefix-list r1 seq 10 permit 10.10.10.2/32
105 def _bgp_orf_changed_r1():
108 "show bgp ipv4 unicast neighbor 192.168.1.2 advertised-routes json"
111 expected
= {"advertisedRoutes": {"10.10.10.1/32": {}, "10.10.10.2/32": {}}}
112 return topotest
.json_cmp(output
, expected
)
114 test_func
= functools
.partial(_bgp_orf_changed_r1
)
115 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
116 assert result
is None, "Can't apply new ORF from R1 to R2"
118 def _bgp_orf_changed_r2():
119 output
= json
.loads(r2
.vtysh_cmd("show bgp ipv4 unicast json"))
122 "10.10.10.1/32": [{"valid": True}],
123 "10.10.10.2/32": [{"valid": True}],
126 return topotest
.json_cmp(output
, expected
)
128 test_func
= functools
.partial(_bgp_orf_changed_r2
)
129 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
130 assert result
is None, "New ORF filtering is not working from R1 to R2"
135 no ip prefix-list r1 seq 10 permit 10.10.10.2/32
139 test_func
= functools
.partial(_bgp_converge_r1
)
140 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
141 assert result
is None, "Can't apply initial ORF from R1 to R2"
144 if __name__
== "__main__":
145 args
= ["-s"] + sys
.argv
[1:]
146 sys
.exit(pytest
.main(args
))