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