]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_rmap_extcommunity_none / test_bgp_rmap_extcommunity_none.py
CommitLineData
bd941b7a 1#!/usr/bin/env python
acddc0ed 2# SPDX-License-Identifier: ISC
bd941b7a
DA
3
4# Copyright (c) 2021 by
5# Donatas Abraitis <donatas.abraitis@gmail.com>
6#
bd941b7a
DA
7
8"""
9Test if route-map extcommunity none works:
10
11route-map <name> permit 10
12 set extcommunity none
13"""
14
15import os
16import sys
17import json
bd941b7a
DA
18import pytest
19import functools
20
21pytestmark = pytest.mark.bgpd
22
23CWD = os.path.dirname(os.path.realpath(__file__))
24sys.path.append(os.path.join(CWD, "../"))
25
26# pylint: disable=C0413
27from lib import topotest
28from lib.topogen import Topogen, TopoRouter, get_topogen
bd941b7a
DA
29
30pytestmark = [pytest.mark.bgpd]
31
32
e82b531d
CH
33def build_topo(tgen):
34 for routern in range(1, 3):
35 tgen.add_router("r{}".format(routern))
bd941b7a 36
e82b531d
CH
37 switch = tgen.add_switch("s1")
38 switch.add_link(tgen.gears["r1"])
39 switch.add_link(tgen.gears["r2"])
bd941b7a
DA
40
41
42def setup_module(mod):
e82b531d 43 tgen = Topogen(build_topo, mod.__name__)
bd941b7a
DA
44 tgen.start_topology()
45
46 router_list = tgen.routers()
47
48 for i, (rname, router) in enumerate(router_list.items(), 1):
49 router.load_config(
50 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
51 )
52 router.load_config(
53 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
54 )
55
56 tgen.start_router()
57
58
59def teardown_module(mod):
60 tgen = get_topogen()
61 tgen.stop_topology()
62
63
64def test_bgp_extcommunity_none():
65 tgen = get_topogen()
66
67 if tgen.routers_have_failure():
68 pytest.skip(tgen.errors)
69
70 router = tgen.gears["r1"]
71
72 def _bgp_converge(router):
73 output = json.loads(
74 router.vtysh_cmd("show bgp ipv4 unicast 172.16.16.1/32 json")
75 )
76 expected = {
77 "prefix": "172.16.16.1/32",
78 "paths": [
79 {
80 "community": {
81 "string": "123:123",
82 },
83 "extendedCommunity": {"string": "LB:65002:25000000 (200.000 Mbps)"},
84 }
85 ],
86 }
87
88 return topotest.json_cmp(output, expected)
89
90 test_func = functools.partial(_bgp_converge, router)
91 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
92 assert result is None, "BGP Converge failed"
93
94 def _bgp_extcommunity_strip(router):
95 router.vtysh_cmd(
96 "conf t\nrouter bgp 65001\naddress-family ipv4\nneighbor 192.168.1.2 route-map r2 in"
97 )
98 output = json.loads(
99 router.vtysh_cmd("show bgp ipv4 unicast 172.16.16.1/32 json")
100 )
101 expected = {
102 "prefix": "172.16.16.1/32",
103 "paths": [
104 {
105 "community": {
106 "string": "123:123",
107 },
108 "extendedCommunity": None,
109 }
110 ],
111 }
112
113 return topotest.json_cmp(output, expected)
114
115 test_func = functools.partial(_bgp_extcommunity_strip, router)
116 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
117 assert result is None, "Failed to strip incoming extended communities from r2"
118
119
120if __name__ == "__main__":
121 args = ["-s"] + sys.argv[1:]
122 sys.exit(pytest.main(args))