]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_tcp_mss / test_bgp_tcp_mss.py
1 #!/usr/bin/env python
2
3 #
4 # bgp_tcp_mss.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2021 by
8 # Abhinay Ramesh <rabhinay@vmware.com>
9 #
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
13 # in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 bgp_tcp_mss.py:
27
28 Test if works the following commands:
29 router bgp 65000
30 neighbor 192.168.255.2 tcp-mss 500
31
32 Need to verify if the tcp-mss value is reflected in the TCP session.
33 """
34
35 import os
36 import sys
37 import json
38 import pytest
39 import functools
40
41 # add after imports, before defining classes or functions:
42 pytestmark = [pytest.mark.bgpd]
43
44 CWD = os.path.dirname(os.path.realpath(__file__))
45 sys.path.append(os.path.join(CWD, "../"))
46
47 # pylint: disable=C0413
48 from lib import topotest
49 from lib.topogen import Topogen, TopoRouter, get_topogen
50 from lib.topolog import logger
51
52 pytestmark = [pytest.mark.bgpd]
53
54
55 def build_topo(tgen):
56 for routern in range(1, 3):
57 tgen.add_router("r{}".format(routern))
58
59 switch = tgen.add_switch("s1")
60 switch.add_link(tgen.gears["r1"])
61 switch.add_link(tgen.gears["r2"])
62
63
64 def setup_module(mod):
65 tgen = Topogen(build_topo, mod.__name__)
66 tgen.start_topology()
67
68 router_list = tgen.routers()
69
70 for i, (rname, router) in enumerate(router_list.items(), 1):
71 router.load_config(
72 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
73 )
74 router.load_config(
75 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
76 )
77
78 tgen.start_router()
79
80
81 def teardown_module(mod):
82 tgen = get_topogen()
83 tgen.stop_topology()
84
85
86 def test_bgp_tcp_mss():
87 tgen = get_topogen()
88
89 if tgen.routers_have_failure():
90 pytest.skip(tgen.errors)
91
92 router1 = tgen.gears["r1"]
93 router2 = tgen.gears["r2"]
94
95 def _bgp_converge(router):
96 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json"))
97 expected = {
98 "192.168.255.2": {
99 "bgpState": "Established",
100 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 0}},
101 }
102 }
103 return topotest.json_cmp(output, expected)
104
105 def _bgp_conf_tcp_mss(router, as_num, neigh):
106 router.vtysh_cmd(
107 """configure terminal
108 router bgp {0}
109 neighbor {1} tcp-mss 500""".format(
110 as_num, neigh
111 )
112 )
113
114 def _bgp_clear_session(router):
115 router.vtysh_cmd("clear bgp *")
116
117 def _bgp_check_neighbor_tcp_mss(router, neigh):
118 output = json.loads(router.vtysh_cmd("show bgp neighbor {} json".format(neigh)))
119 expected = {
120 "{}".format(neigh): {"bgpTcpMssConfigured": 500, "bgpTcpMssSynced": 488}
121 }
122 return topotest.json_cmp(output, expected)
123
124 logger.info("Check if neighbor sessions are up in {}".format(router1.name))
125 test_func = functools.partial(_bgp_converge, router1)
126 success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5)
127 assert result is None, 'Failed to see BGP convergence in "{}"'.format(router1.name)
128
129 logger.info("BGP neighbor session is up in {}".format(router1.name))
130
131 logger.info(
132 "Configure tcp-mss 500 on {} and reset the session".format(router1.name)
133 )
134 _bgp_conf_tcp_mss(router1, "65000", "192.168.255.2")
135 _bgp_clear_session(router1)
136
137 logger.info(
138 "Configure tcp-mss 500 on {} and reset the session".format(router2.name)
139 )
140 _bgp_conf_tcp_mss(router2, "65001", "192.168.255.1")
141 _bgp_clear_session(router2)
142
143 logger.info(
144 "Check if neighbor session is up after reset in {}".format(router1.name)
145 )
146 test_func = functools.partial(_bgp_converge, router1)
147 success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5)
148 assert result is None, 'Failed to see BGP convergence after reset in "{}"'.format(
149 router1.name
150 )
151
152 logger.info(
153 "Verify if TCP MSS value is synced with neighbor in {}".format(router1.name)
154 )
155 test_func = functools.partial(_bgp_check_neighbor_tcp_mss, router1, "192.168.255.2")
156 success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
157 assert (
158 result is None
159 ), 'Failed to sync TCP MSS value over BGP session in "{}"'.format(router1.name)
160 logger.info("TCP MSS value is synced with neighbor in {}".format(router1.name))
161
162 logger.info(
163 "Verify if TCP MSS value is synced with neighbor in {}".format(router2.name)
164 )
165 test_func = functools.partial(_bgp_check_neighbor_tcp_mss, router2, "192.168.255.1")
166 success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
167 assert (
168 result is None
169 ), 'Failed to sync TCP MSS value over BGP session in "{}"'.format(router2.name)
170 logger.info("TCP MSS value is synced with neighbor in {}".format(router2.name))
171
172
173 if __name__ == "__main__":
174 args = ["-s"] + sys.argv[1:]
175 sys.exit(pytest.main(args))