]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_default_route/test_bgp_default-originate.py
*: manual SPDX License ID conversions
[mirror_frr.git] / tests / topotests / bgp_default_route / test_bgp_default-originate.py
CommitLineData
462b3067
DA
1#!/usr/bin/env python
2
55b15c38 3# Copyright (c) 2019-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 22Test if default-originate works without route-map.
462b3067
DA
23"""
24
25import os
26import sys
27import json
462b3067
DA
28import pytest
29import functools
30
31CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 32sys.path.append(os.path.join(CWD, "../"))
462b3067
DA
33
34# pylint: disable=C0413
35from lib import topotest
36from lib.topogen import Topogen, TopoRouter, get_topogen
462b3067 37
bf3a0a9a
DS
38pytestmark = [pytest.mark.bgpd]
39
787e7624 40
e82b531d
CH
41def build_topo(tgen):
42 for routern in range(1, 3):
43 tgen.add_router("r{}".format(routern))
462b3067 44
e82b531d
CH
45 switch = tgen.add_switch("s1")
46 switch.add_link(tgen.gears["r1"])
47 switch.add_link(tgen.gears["r2"])
462b3067 48
462b3067
DA
49
50def setup_module(mod):
e82b531d 51 tgen = Topogen(build_topo, mod.__name__)
462b3067
DA
52 tgen.start_topology()
53
54 router_list = tgen.routers()
55
e5f0ed14 56 for i, (rname, router) in enumerate(router_list.items(), 1):
462b3067 57 router.load_config(
787e7624 58 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
462b3067
DA
59 )
60 router.load_config(
787e7624 61 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
462b3067
DA
62 )
63
64 tgen.start_router()
65
787e7624 66
462b3067
DA
67def teardown_module(mod):
68 tgen = get_topogen()
69 tgen.stop_topology()
70
787e7624 71
462b3067
DA
72def test_bgp_default_originate_route_map():
73 tgen = get_topogen()
74
75 if tgen.routers_have_failure():
76 pytest.skip(tgen.errors)
77
5fa869fc
DA
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 )
462b3067 82 expected = {
787e7624 83 "192.168.255.1": {
84 "bgpState": "Established",
85 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}},
462b3067
DA
86 }
87 }
88 return topotest.json_cmp(output, expected)
89
5fa869fc
DA
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
55b15c38 95 def _bgp_default_route_is_valid(router):
462b3067 96 output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json"))
55b15c38 97 expected = {"paths": [{"valid": True}]}
462b3067
DA
98 return topotest.json_cmp(output, expected)
99
5fa869fc 100 test_func = functools.partial(_bgp_check_if_received)
55b15c38 101 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
5fa869fc 102 assert result is None, "No 0.0.0.0/0 at r2 from r1"
462b3067 103
5fa869fc 104 test_func = functools.partial(_bgp_check_if_originated)
55b15c38 105 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
5fa869fc 106 assert result is None, "No 0.0.0.0/0 from r1 to r2"
462b3067 107
5fa869fc
DA
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"
787e7624 111
462b3067 112
787e7624 113if __name__ == "__main__":
462b3067
DA
114 args = ["-s"] + sys.argv[1:]
115 sys.exit(pytest.main(args))