]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_orf/test_bgp_orf.py
3 # Copyright (c) 2022 by
4 # 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 if BGP ORF filtering is working correctly when modifying
25 Initially advertise 10.10.10.1/32 from R1 to R2. Add new prefix
26 10.10.10.2/32 to r1 prefix list on R2. Test if we updated ORF
27 prefix-list correctly.
36 pytestmark
= pytest
.mark
.bgpd
38 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
39 sys
.path
.append(os
.path
.join(CWD
, "../"))
41 # pylint: disable=C0413
42 from lib
import topotest
43 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
45 pytestmark
= [pytest
.mark
.bgpd
]
48 def setup_module(mod
):
49 topodef
= {"s1": ("r1", "r2")}
50 tgen
= Topogen(topodef
, mod
.__name
__)
53 router_list
= tgen
.routers()
55 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
57 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
60 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
66 def teardown_module(mod
):
74 if tgen
.routers_have_failure():
75 pytest
.skip(tgen
.errors
)
80 def _bgp_converge_r1():
83 "show bgp ipv4 unicast neighbor 192.168.1.2 advertised-routes json"
86 expected
= {"advertisedRoutes": {"10.10.10.1/32": {}, "10.10.10.2/32": None}}
87 return topotest
.json_cmp(output
, expected
)
89 test_func
= functools
.partial(_bgp_converge_r1
)
90 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
91 assert result
is None, "Can't apply ORF from R1 to R2"
93 def _bgp_converge_r2():
94 output
= json
.loads(r2
.vtysh_cmd("show bgp ipv4 unicast summary json"))
100 "state": "Established",
105 return topotest
.json_cmp(output
, expected
)
107 test_func
= functools
.partial(_bgp_converge_r2
)
108 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
109 assert result
is None, "ORF filtering is not working from R1 to R2"
114 ip prefix-list r1 seq 10 permit 10.10.10.2/32
118 def _bgp_orf_changed_r1():
121 "show bgp ipv4 unicast neighbor 192.168.1.2 advertised-routes json"
124 expected
= {"advertisedRoutes": {"10.10.10.1/32": {}, "10.10.10.2/32": {}}}
125 return topotest
.json_cmp(output
, expected
)
127 test_func
= functools
.partial(_bgp_orf_changed_r1
)
128 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
129 assert result
is None, "Can't apply new ORF from R1 to R2"
131 def _bgp_orf_changed_r2():
132 output
= json
.loads(r2
.vtysh_cmd("show bgp ipv4 unicast json"))
135 "10.10.10.1/32": [{"valid": True}],
136 "10.10.10.2/32": [{"valid": True}],
139 return topotest
.json_cmp(output
, expected
)
141 test_func
= functools
.partial(_bgp_orf_changed_r2
)
142 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
143 assert result
is None, "New ORF filtering is not working from R1 to R2"
148 no ip prefix-list r1 seq 10 permit 10.10.10.2/32
152 test_func
= functools
.partial(_bgp_converge_r1
)
153 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
154 assert result
is None, "Can't apply initial ORF from R1 to R2"
157 if __name__
== "__main__":
158 args
= ["-s"] + sys
.argv
[1:]
159 sys
.exit(pytest
.main(args
))