]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_aggregate_address_origin / test_bgp_aggregate-address_origin.py
1 #!/usr/bin/env python
2
3 #
4 # bgp_aggregate-address_origin.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2020 by
8 # Donatas Abraitis <donatas.abraitis@gmail.com>
9 #
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
13 # in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 bgp_aggregate-address_origin.py:
27
28 Test if works the following commands:
29 router bgp 65031
30 address-family ipv4 unicast
31 aggregate-address 192.168.255.0/24 origin igp
32 """
33
34 import os
35 import sys
36 import json
37 import pytest
38 import functools
39
40 CWD = os.path.dirname(os.path.realpath(__file__))
41 sys.path.append(os.path.join(CWD, "../"))
42
43 # pylint: disable=C0413
44 from lib import topotest
45 from lib.topogen import Topogen, TopoRouter, get_topogen
46
47 pytestmark = [pytest.mark.bgpd]
48
49
50 def build_topo(tgen):
51 for routern in range(1, 3):
52 tgen.add_router("r{}".format(routern))
53
54 switch = tgen.add_switch("s1")
55 switch.add_link(tgen.gears["r1"])
56 switch.add_link(tgen.gears["r2"])
57
58
59 def setup_module(mod):
60 tgen = Topogen(build_topo, mod.__name__)
61 tgen.start_topology()
62
63 router_list = tgen.routers()
64
65 for i, (rname, router) in enumerate(router_list.items(), 1):
66 router.load_config(
67 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
68 )
69 router.load_config(
70 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
71 )
72
73 tgen.start_router()
74
75
76 def teardown_module(mod):
77 tgen = get_topogen()
78 tgen.stop_topology()
79
80
81 def test_bgp_aggregate_address_origin():
82 tgen = get_topogen()
83
84 if tgen.routers_have_failure():
85 pytest.skip(tgen.errors)
86
87 router = tgen.gears["r2"]
88
89 def _bgp_converge(router):
90 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
91 expected = {
92 "192.168.255.1": {
93 "bgpState": "Established",
94 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}},
95 }
96 }
97 return topotest.json_cmp(output, expected)
98
99 def _bgp_aggregate_address_has_metric(router):
100 output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.0/24 json"))
101 expected = {"paths": [{"origin": "IGP"}]}
102 return topotest.json_cmp(output, expected)
103
104 test_func = functools.partial(_bgp_converge, router)
105 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
106
107 assert result is None, 'Failed to see bgp convergence in "{}"'.format(router)
108
109 test_func = functools.partial(_bgp_aggregate_address_has_metric, router)
110 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
111
112 assert (
113 result is None
114 ), 'Failed to see applied ORIGIN (igp) for aggregated prefix in "{}"'.format(router)
115
116
117 if __name__ == "__main__":
118 args = ["-s"] + sys.argv[1:]
119 sys.exit(pytest.main(args))