]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py
tests: micronet: adapt tests
[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 time
38 import pytest
39 import functools
40
41 CWD = os.path.dirname(os.path.realpath(__file__))
42 sys.path.append(os.path.join(CWD, "../"))
43
44 # pylint: disable=C0413
45 from lib import topotest
46 from lib.topogen import Topogen, TopoRouter, get_topogen
47 from lib.topolog import logger
48 from lib.micronet_compat import Topo
49
50 pytestmark = [pytest.mark.bgpd]
51
52
53 class TemplateTopo(Topo):
54 def build(self, *_args, **_opts):
55 tgen = get_topogen(self)
56
57 for routern in range(1, 3):
58 tgen.add_router("r{}".format(routern))
59
60 switch = tgen.add_switch("s1")
61 switch.add_link(tgen.gears["r1"])
62 switch.add_link(tgen.gears["r2"])
63
64
65 def setup_module(mod):
66 tgen = Topogen(TemplateTopo, mod.__name__)
67 tgen.start_topology()
68
69 router_list = tgen.routers()
70
71 for i, (rname, router) in enumerate(router_list.items(), 1):
72 router.load_config(
73 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
74 )
75 router.load_config(
76 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
77 )
78
79 tgen.start_router()
80
81
82 def teardown_module(mod):
83 tgen = get_topogen()
84 tgen.stop_topology()
85
86
87 def test_bgp_aggregate_address_origin():
88 tgen = get_topogen()
89
90 if tgen.routers_have_failure():
91 pytest.skip(tgen.errors)
92
93 router = tgen.gears["r2"]
94
95 def _bgp_converge(router):
96 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
97 expected = {
98 "192.168.255.1": {
99 "bgpState": "Established",
100 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}},
101 }
102 }
103 return topotest.json_cmp(output, expected)
104
105 def _bgp_aggregate_address_has_metric(router):
106 output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.0/24 json"))
107 expected = {"paths": [{"origin": "IGP"}]}
108 return topotest.json_cmp(output, expected)
109
110 test_func = functools.partial(_bgp_converge, router)
111 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
112
113 assert result is None, 'Failed to see bgp convergence in "{}"'.format(router)
114
115 test_func = functools.partial(_bgp_aggregate_address_has_metric, router)
116 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
117
118 assert (
119 result is None
120 ), 'Failed to see applied ORIGIN (igp) for aggregated prefix in "{}"'.format(router)
121
122
123 if __name__ == "__main__":
124 args = ["-s"] + sys.argv[1:]
125 sys.exit(pytest.main(args))