]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_local_as/test_bgp_local_as.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_local_as / test_bgp_local_as.py
CommitLineData
f3bc47b7 1#!/usr/bin/env python
acddc0ed 2# SPDX-License-Identifier: ISC
f3bc47b7
DA
3
4#
5# Copyright (c) 2022 by
6# Donatas Abraitis <donatas@opensourcerouting.org>
7#
f3bc47b7
DA
8
9"""
10
11"""
12
13import os
14import sys
15import json
16import pytest
17import functools
18
19CWD = os.path.dirname(os.path.realpath(__file__))
20sys.path.append(os.path.join(CWD, "../"))
21
22# pylint: disable=C0413
23from lib import topotest
24from lib.topogen import Topogen, TopoRouter, get_topogen
25from lib.common_config import step
26
27pytestmark = [pytest.mark.bgpd]
28
29
30def build_topo(tgen):
31 for routern in range(1, 4):
32 tgen.add_router("r{}".format(routern))
33
34 switch = tgen.add_switch("s1")
35 switch.add_link(tgen.gears["r1"])
36 switch.add_link(tgen.gears["r2"])
37
38 switch = tgen.add_switch("s2")
39 switch.add_link(tgen.gears["r1"])
40 switch.add_link(tgen.gears["r3"])
41
42
43def setup_module(mod):
44 tgen = Topogen(build_topo, mod.__name__)
45 tgen.start_topology()
46
47 router_list = tgen.routers()
48
49 for i, (rname, router) in enumerate(router_list.items(), 1):
50 router.load_config(
51 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
52 )
53 router.load_config(
54 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
55 )
56
57 tgen.start_router()
58
59
60def teardown_module(mod):
61 tgen = get_topogen()
62 tgen.stop_topology()
63
64
65def test_bgp_local_as_same_remote_as():
66 tgen = get_topogen()
67
68 if tgen.routers_have_failure():
69 pytest.skip(tgen.errors)
70
71 def _bgp_check_local_as_same_remote_as():
72 output = json.loads(
73 tgen.gears["r2"].vtysh_cmd("show bgp ipv4 unicast 172.16.255.1/32 json")
74 )
75 expected = {
76 "paths": [
77 {
78 "valid": True,
79 "aspath": {"string": "Local"},
80 "nexthops": [{"ip": "192.168.1.1", "hostname": "r1"}],
81 }
82 ]
83 }
84 return topotest.json_cmp(output, expected)
85
86 step("Check if iBGP works when local-as == remote-as")
87 test_func = functools.partial(_bgp_check_local_as_same_remote_as)
88 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
89 assert result is None, "Failed to see BGP prefixes on R2"
90
91
92def test_bgp_peer_group_local_as_same_remote_as():
93 tgen = get_topogen()
94
95 if tgen.routers_have_failure():
96 pytest.skip(tgen.errors)
97
98 def _bgp_check_local_as_same_remote_as():
99 output = json.loads(
100 tgen.gears["r3"].vtysh_cmd("show bgp ipv4 unicast 172.16.255.1/32 json")
101 )
102 expected = {
103 "paths": [
104 {
105 "valid": True,
106 "aspath": {"string": "Local"},
107 "nexthops": [{"ip": "192.168.2.1", "hostname": "r1"}],
108 }
109 ]
110 }
111 return topotest.json_cmp(output, expected)
112
113 step("Initial BGP converge")
114 test_func = functools.partial(_bgp_check_local_as_same_remote_as)
115 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
116 assert result is None, "Failed to see BGP prefixes on R3"
117
118
119if __name__ == "__main__":
120 args = ["-s"] + sys.argv[1:]
121 sys.exit(pytest.main(args))