]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_default_route/test_bgp_default-originate.py
tests: Add pytest.mark.bgpd for tests missing this mark
[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
28import time
29import pytest
30import functools
31
32CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 33sys.path.append(os.path.join(CWD, "../"))
462b3067
DA
34
35# pylint: disable=C0413
36from lib import topotest
37from lib.topogen import Topogen, TopoRouter, get_topogen
38from lib.topolog import logger
39from mininet.topo import Topo
40
bf3a0a9a
DS
41pytestmark = [pytest.mark.bgpd]
42
787e7624 43
462b3067
DA
44class TemplateTopo(Topo):
45 def build(self, *_args, **_opts):
46 tgen = get_topogen(self)
47
48 for routern in range(1, 3):
787e7624 49 tgen.add_router("r{}".format(routern))
50
51 switch = tgen.add_switch("s1")
52 switch.add_link(tgen.gears["r1"])
53 switch.add_link(tgen.gears["r2"])
462b3067 54
462b3067
DA
55
56def setup_module(mod):
57 tgen = Topogen(TemplateTopo, mod.__name__)
58 tgen.start_topology()
59
60 router_list = tgen.routers()
61
e5f0ed14 62 for i, (rname, router) in enumerate(router_list.items(), 1):
462b3067 63 router.load_config(
787e7624 64 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
462b3067
DA
65 )
66 router.load_config(
787e7624 67 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
462b3067
DA
68 )
69
70 tgen.start_router()
71
787e7624 72
462b3067
DA
73def teardown_module(mod):
74 tgen = get_topogen()
75 tgen.stop_topology()
76
787e7624 77
462b3067
DA
78def test_bgp_default_originate_route_map():
79 tgen = get_topogen()
80
81 if tgen.routers_have_failure():
82 pytest.skip(tgen.errors)
83
5fa869fc
DA
84 def _bgp_check_if_received():
85 output = json.loads(
86 tgen.gears["r2"].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")
87 )
462b3067 88 expected = {
787e7624 89 "192.168.255.1": {
90 "bgpState": "Established",
91 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}},
462b3067
DA
92 }
93 }
94 return topotest.json_cmp(output, expected)
95
5fa869fc
DA
96 def _bgp_check_if_originated():
97 output = json.loads(tgen.gears["r1"].vtysh_cmd("show ip bgp summary json"))
98 expected = {"ipv4Unicast": {"peers": {"192.168.255.2": {"pfxSnt": 1}}}}
99 return topotest.json_cmp(output, expected)
100
55b15c38 101 def _bgp_default_route_is_valid(router):
462b3067 102 output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json"))
55b15c38 103 expected = {"paths": [{"valid": True}]}
462b3067
DA
104 return topotest.json_cmp(output, expected)
105
5fa869fc 106 test_func = functools.partial(_bgp_check_if_received)
55b15c38 107 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
5fa869fc 108 assert result is None, "No 0.0.0.0/0 at r2 from r1"
462b3067 109
5fa869fc 110 test_func = functools.partial(_bgp_check_if_originated)
55b15c38 111 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
5fa869fc 112 assert result is None, "No 0.0.0.0/0 from r1 to r2"
462b3067 113
5fa869fc
DA
114 test_func = functools.partial(_bgp_default_route_is_valid, tgen.gears["r2"])
115 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
116 assert result is None, "Failed to see 0.0.0.0/0 in r2"
787e7624 117
462b3067 118
787e7624 119if __name__ == "__main__":
462b3067
DA
120 args = ["-s"] + sys.argv[1:]
121 sys.exit(pytest.main(args))