]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_default_route/test_bgp_default-originate.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_default_route / test_bgp_default-originate.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2019-2020 by
4 # Donatas Abraitis <donatas.abraitis@gmail.com>
5 #
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
9 # in all copies.
10 #
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
18 # OF THIS SOFTWARE.
19 #
20
21 """
22 Test if default-originate works without route-map.
23 """
24
25 import os
26 import sys
27 import json
28 import pytest
29 import functools
30
31 CWD = os.path.dirname(os.path.realpath(__file__))
32 sys.path.append(os.path.join(CWD, "../"))
33
34 # pylint: disable=C0413
35 from lib import topotest
36 from lib.topogen import Topogen, TopoRouter, get_topogen
37
38 pytestmark = [pytest.mark.bgpd]
39
40
41 def build_topo(tgen):
42 for routern in range(1, 3):
43 tgen.add_router("r{}".format(routern))
44
45 switch = tgen.add_switch("s1")
46 switch.add_link(tgen.gears["r1"])
47 switch.add_link(tgen.gears["r2"])
48
49
50 def setup_module(mod):
51 tgen = Topogen(build_topo, mod.__name__)
52 tgen.start_topology()
53
54 router_list = tgen.routers()
55
56 for i, (rname, router) in enumerate(router_list.items(), 1):
57 router.load_config(
58 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
59 )
60 router.load_config(
61 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
62 )
63
64 tgen.start_router()
65
66
67 def teardown_module(mod):
68 tgen = get_topogen()
69 tgen.stop_topology()
70
71
72 def test_bgp_default_originate_route_map():
73 tgen = get_topogen()
74
75 if tgen.routers_have_failure():
76 pytest.skip(tgen.errors)
77
78 def _bgp_check_if_received():
79 output = json.loads(
80 tgen.gears["r2"].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")
81 )
82 expected = {
83 "192.168.255.1": {
84 "bgpState": "Established",
85 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}},
86 }
87 }
88 return topotest.json_cmp(output, expected)
89
90 def _bgp_check_if_originated():
91 output = json.loads(tgen.gears["r1"].vtysh_cmd("show ip bgp summary json"))
92 expected = {"ipv4Unicast": {"peers": {"192.168.255.2": {"pfxSnt": 1}}}}
93 return topotest.json_cmp(output, expected)
94
95 def _bgp_default_route_is_valid(router):
96 output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json"))
97 expected = {"paths": [{"valid": True}]}
98 return topotest.json_cmp(output, expected)
99
100 test_func = functools.partial(_bgp_check_if_received)
101 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
102 assert result is None, "No 0.0.0.0/0 at r2 from r1"
103
104 test_func = functools.partial(_bgp_check_if_originated)
105 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
106 assert result is None, "No 0.0.0.0/0 from r1 to r2"
107
108 test_func = functools.partial(_bgp_default_route_is_valid, tgen.gears["r2"])
109 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
110 assert result is None, "Failed to see 0.0.0.0/0 in r2"
111
112
113 if __name__ == "__main__":
114 args = ["-s"] + sys.argv[1:]
115 sys.exit(pytest.main(args))