]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_path_attribute_discard/test_bgp_path_attribute_discard.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_path_attribute_discard / test_bgp_path_attribute_discard.py
CommitLineData
760aee9a 1#!/usr/bin/env python
acddc0ed 2# SPDX-License-Identifier: ISC
760aee9a
DA
3
4#
5# Copyright (c) 2022 by
6# Donatas Abraitis <donatas@opensourcerouting.org>
7#
760aee9a
DA
8
9"""
10Test if `neighbor path-attribute discard` command works correctly,
11can discard unwanted attributes from UPDATE messages, and ignore them
12by continuing to process UPDATE messages.
13"""
14
15import os
16import sys
17import json
18import pytest
19import functools
20
21CWD = os.path.dirname(os.path.realpath(__file__))
22sys.path.append(os.path.join(CWD, "../"))
23
24# pylint: disable=C0413
25from lib import topotest
26from lib.topogen import Topogen, TopoRouter, get_topogen
27from lib.common_config import step
28
29pytestmark = [pytest.mark.bgpd]
30
31
32def build_topo(tgen):
33 r1 = tgen.add_router("r1")
34 peer1 = tgen.add_exabgp_peer("peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1")
35
36 switch = tgen.add_switch("s1")
37 switch.add_link(r1)
38 switch.add_link(peer1)
39
40
41def setup_module(mod):
42 tgen = Topogen(build_topo, mod.__name__)
43 tgen.start_topology()
44
45 router = tgen.gears["r1"]
46 router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "r1/zebra.conf"))
47 router.load_config(TopoRouter.RD_BGP, os.path.join(CWD, "r1/bgpd.conf"))
48 router.start()
49
50 peer = tgen.gears["peer1"]
51 peer.start(os.path.join(CWD, "peer1"), os.path.join(CWD, "exabgp.env"))
52
53
54def teardown_module(mod):
55 tgen = get_topogen()
56 tgen.stop_topology()
57
58
59def test_bgp_path_attribute_discard():
60 tgen = get_topogen()
61
62 if tgen.routers_have_failure():
63 pytest.skip(tgen.errors)
64
65 r1 = tgen.gears["r1"]
66
67 def _bgp_converge():
68 output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast json detail"))
69 expected = {
70 "routes": {
04705e48
TA
71 "192.168.100.101/32": {
72 "paths": [
73 {
74 "valid": True,
75 "atomicAggregate": True,
76 "community": {
77 "string": "65001:101",
78 },
79 }
80 ],
81 },
82 "192.168.100.102/32": {
83 "paths": [
84 {
85 "valid": True,
86 "originatorId": "10.0.0.2",
87 "community": {
88 "string": "65001:102",
89 },
90 }
91 ],
92 },
760aee9a
DA
93 }
94 }
95 return topotest.json_cmp(output, expected)
96
97 test_func = functools.partial(_bgp_converge)
98 _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
99 assert result is None, "Failed bgp convergence"
100
101 step("Discard atomic-aggregate, community, and originator-id attributes from peer1")
102 r1.vtysh_cmd(
103 """
104 configure terminal
105 router bgp
106 neighbor 10.0.0.2 path-attribute discard 6 8 9
107 """
108 )
109
110 def _bgp_check_if_attributes_discarded():
111 output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast json detail"))
112 expected = {
113 "routes": {
04705e48
TA
114 "192.168.100.101/32": {
115 "paths": [
116 {
117 "valid": True,
118 "atomicAggregate": None,
119 "community": None,
120 }
121 ],
122 },
123 "192.168.100.102/32": {
124 "paths": [
125 {
126 "valid": True,
127 "originatorId": None,
128 "community": None,
129 }
130 ],
131 },
760aee9a
DA
132 }
133 }
134 return topotest.json_cmp(output, expected)
135
136 test_func = functools.partial(_bgp_check_if_attributes_discarded)
137 _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
138 assert (
139 result is None
140 ), "Failed to discard path attributes (atomic-aggregate, community, and originator-id)"
141
142
143def test_memory_leak():
144 "Run the memory leak test and report results."
145 tgen = get_topogen()
146 if not tgen.is_memleak_enabled():
147 pytest.skip("Memory leak test/report is disabled")
148
149 tgen.report_memory_leaks()
150
151
152if __name__ == "__main__":
153 args = ["-s"] + sys.argv[1:]
154 sys.exit(pytest.main(args))