]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py
4 # test_bgp_flowspec_topo.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2019 by 6WIND
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 test_bgp_flowspec_topo.py: Test BGP topology with Flowspec EBGP peering
59 # Save the Current Working Directory to find configuration files.
60 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
61 sys
.path
.append(os
.path
.join(CWD
, "../"))
63 # pylint: disable=C0413
64 # Import topogen and topotest helpers
65 from lib
import topotest
66 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
67 from lib
.topolog
import logger
68 from lib
.lutil
import lUtil
69 from lib
.lutil
import luCommand
71 # Required to instantiate the topology builder class.
72 from lib
.micronet_compat
import Topo
75 pytestmark
= [pytest
.mark
.bgpd
]
78 #####################################################
80 ## Network Topology Definition
82 #####################################################
85 class BGPFLOWSPECTopo1(Topo
):
86 "BGP EBGP Flowspec Topology 1"
88 def build(self
, **_opts
):
89 tgen
= get_topogen(self
)
94 # Setup Control Path Switch 1. r1-eth0
95 switch
= tgen
.add_switch("s1")
96 switch
.add_link(tgen
.gears
["r1"])
98 ## Add eBGP ExaBGP neighbors
99 peer_ip
= "10.0.1.101" ## peer
100 peer_route
= "via 10.0.1.1" ## router
101 peer
= tgen
.add_exabgp_peer("peer1", ip
=peer_ip
, defaultRoute
=peer_route
)
102 switch
.add_link(peer
)
105 #####################################################
109 #####################################################
112 def setup_module(module
):
113 tgen
= Topogen(BGPFLOWSPECTopo1
, module
.__name
__)
115 tgen
.start_topology()
116 # check for zebra capability
117 router
= tgen
.gears
["r1"]
119 # Get r1 reference and run Daemons
120 logger
.info("Launching BGP and ZEBRA on r1")
121 router
= tgen
.gears
["r1"]
123 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format("r1"))
126 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format("r1"))
130 peer_list
= tgen
.exabgp_peers()
131 for pname
, peer
in peer_list
.items():
132 peer_dir
= os
.path
.join(CWD
, pname
)
133 env_file
= os
.path
.join(CWD
, "exabgp.env")
134 peer
.start(peer_dir
, env_file
)
138 def teardown_module(module
):
143 def test_bgp_convergence():
144 "Test for BGP topology convergence"
147 # Skip if previous fatal error condition is raised
149 if tgen
.routers_have_failure():
150 pytest
.skip(tgen
.errors
)
152 logger
.info("waiting for bgp convergence")
155 router
= tgen
.gears
["r1"]
156 reffile
= os
.path
.join(CWD
, "r1/summary.txt")
158 expected
= json
.loads(open(reffile
).read())
160 test_func
= functools
.partial(
161 topotest
.router_json_cmp
, router
, "show bgp summary json", expected
163 _
, res
= topotest
.run_and_expect(test_func
, None, count
=90, wait
=0.5)
164 assertmsg
= "BGP router network did not converge"
165 assert res
is None, assertmsg
168 def test_bgp_flowspec():
171 # Skip if previous fatal error condition is raised
172 if tgen
.routers_have_failure():
173 pytest
.skip(tgen
.errors
)
175 router
= tgen
.gears
["r1"]
177 logger
.info("Check BGP FS entry for 3.3.3.3 with redirect IP")
178 output
= router
.vtysh_cmd(
179 "show bgp ipv4 flowspec 3.3.3.3", isjson
=False, daemon
="bgpd"
183 "NH 50.0.0.2" not in output
184 or "FS:redirect IP" not in output
185 or "Packet Length < 200" not in output
187 assertmsg
= "traffic to 3.3.3.3 should have been detected as FS entry. NOK"
190 logger
.info("Check BGP FS entry for 3.3.3.3 with redirect IP OK")
192 logger
.info("Check BGP FS entry for 3::3 with redirect IP")
193 output
= router
.vtysh_cmd(
194 "show bgp ipv6 flowspec 3::3", isjson
=False, daemon
="bgpd"
198 "NH 50::2" not in output
199 or "FS:redirect IP" not in output
200 or "Packet Length < 200" not in output
202 assertmsg
= "traffic to 3::3 should have been detected as FS entry. NOK"
205 logger
.info("Check BGP FS entry for 3::3 with redirect IP OK")
208 if __name__
== "__main__":
210 args
= ["-s"] + sys
.argv
[1:]
211 ret
= pytest
.main(args
)