]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_default_route_route_map_match_set / test_bgp_default-originate_route-map_match_set.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 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 with match operations.
23 And verify if set operations work as well.
24 """
25
26 import os
27 import sys
28 import json
29 import pytest
30 import functools
31
32 CWD = os.path.dirname(os.path.realpath(__file__))
33 sys.path.append(os.path.join(CWD, "../"))
34
35 # pylint: disable=C0413
36 from lib import topotest
37 from lib.topogen import Topogen, TopoRouter, get_topogen
38
39
40 pytestmark = [pytest.mark.bgpd]
41
42
43 def build_topo(tgen):
44 for routern in range(1, 3):
45 tgen.add_router("r{}".format(routern))
46
47 switch = tgen.add_switch("s1")
48 switch.add_link(tgen.gears["r1"])
49 switch.add_link(tgen.gears["r2"])
50
51
52 def setup_module(mod):
53 tgen = Topogen(build_topo, mod.__name__)
54 tgen.start_topology()
55
56 router_list = tgen.routers()
57
58 for i, (rname, router) in enumerate(router_list.items(), 1):
59 router.load_config(
60 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
61 )
62 router.load_config(
63 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
64 )
65
66 tgen.start_router()
67
68
69 def teardown_module(mod):
70 tgen = get_topogen()
71 tgen.stop_topology()
72
73
74 def test_bgp_default_originate_route_map():
75 tgen = get_topogen()
76
77 if tgen.routers_have_failure():
78 pytest.skip(tgen.errors)
79
80 router = tgen.gears["r2"]
81
82 def _bgp_converge(router):
83 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
84 expected = {
85 "192.168.255.1": {
86 "bgpState": "Established",
87 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}},
88 }
89 }
90 return topotest.json_cmp(output, expected)
91
92 def _bgp_default_route_has_metric(router):
93 output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json"))
94 expected = {
95 "paths": [
96 {
97 "aspath": {"string": "65000 65000 65000 65000"},
98 "metric": 123,
99 "community": None,
100 }
101 ]
102 }
103 return topotest.json_cmp(output, expected)
104
105 test_func = functools.partial(_bgp_converge, router)
106 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
107
108 assert result is None, 'Failed to see bgp convergence in "{}"'.format(router)
109
110 test_func = functools.partial(_bgp_default_route_has_metric, router)
111 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
112
113 assert (
114 result is None
115 ), 'Failed to see applied metric for default route in "{}"'.format(router)
116
117
118 if __name__ == "__main__":
119 args = ["-s"] + sys.argv[1:]
120 sys.exit(pytest.main(args))