]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py
tests: Add pytest.mark.ospfd on tests missing this mark
[mirror_frr.git] / tests / topotests / bgp_tcp_mss / test_bgp_tcp_mss.py
CommitLineData
4ab46701
AR
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"""
26bgp_tcp_mss.py:
27
28Test if works the following commands:
29router bgp 65000
30 neighbor 192.168.255.2 tcp-mss 500
31
32Need to verify if the tcp-mss value is reflected in the TCP session.
33"""
34
35import os
36import sys
37import json
38import time
39import pytest
40import functools
41
42# add after imports, before defining classes or functions:
43pytestmark = [pytest.mark.bgpd]
44
45CWD = os.path.dirname(os.path.realpath(__file__))
46sys.path.append(os.path.join(CWD, "../"))
47
48# pylint: disable=C0413
49from lib import topotest
50from lib.topogen import Topogen, TopoRouter, get_topogen
51from lib.topolog import logger
52from mininet.topo import Topo
53
54
55class TemplateTopo(Topo):
56 def build(self, *_args, **_opts):
57 tgen = get_topogen(self)
58
59 for routern in range(1, 3):
60 tgen.add_router("r{}".format(routern))
61
62 switch = tgen.add_switch("s1")
63 switch.add_link(tgen.gears["r1"])
64 switch.add_link(tgen.gears["r2"])
65
66
67def setup_module(mod):
68 tgen = Topogen(TemplateTopo, mod.__name__)
69 tgen.start_topology()
70
71 router_list = tgen.routers()
72
73 for i, (rname, router) in enumerate(router_list.items(), 1):
74 router.load_config(
75 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
76 )
77 router.load_config(
78 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
79 )
80
81 tgen.start_router()
82
83
84def teardown_module(mod):
85 tgen = get_topogen()
86 tgen.stop_topology()
87
88
89def test_bgp_tcp_mss():
90 tgen = get_topogen()
91
92 if tgen.routers_have_failure():
93 pytest.skip(tgen.errors)
94
95 router1 = tgen.gears["r1"]
96 router2 = tgen.gears["r2"]
97
98 def _bgp_converge(router):
99 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json"))
100 expected = {
101 "192.168.255.2": {
102 "bgpState": "Established",
103 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 0}},
104 }
105 }
106 return topotest.json_cmp(output, expected)
107
108 def _bgp_conf_tcp_mss(router, as_num, neigh):
109 router.vtysh_cmd(
110 """configure terminal
111 router bgp {0}
112 neighbor {1} tcp-mss 500""".format(
113 as_num, neigh
114 )
115 )
116
117 def _bgp_clear_session(router):
118 router.vtysh_cmd("clear bgp *")
119
120 def _bgp_check_neighbor_tcp_mss(router, neigh):
121 output = json.loads(router.vtysh_cmd("show bgp neighbor {} json".format(neigh)))
122 expected = {
123 "{}".format(neigh): {"bgpTcpMssConfigured": 500, "bgpTcpMssSynced": 488}
124 }
125 return topotest.json_cmp(output, expected)
126
127 logger.info("Check if neighbor sessions are up in {}".format(router1.name))
128 test_func = functools.partial(_bgp_converge, router1)
129 success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5)
130 assert result is None, 'Failed to see BGP convergence in "{}"'.format(router1.name)
131
132 logger.info("BGP neighbor session is up in {}".format(router1.name))
133
134 logger.info(
135 "Configure tcp-mss 500 on {} and reset the session".format(router1.name)
136 )
137 _bgp_conf_tcp_mss(router1, "65000", "192.168.255.2")
138 _bgp_clear_session(router1)
139
140 logger.info(
141 "Configure tcp-mss 500 on {} and reset the session".format(router2.name)
142 )
143 _bgp_conf_tcp_mss(router2, "65001", "192.168.255.1")
144 _bgp_clear_session(router2)
145
146 logger.info(
147 "Check if neighbor session is up after reset in {}".format(router1.name)
148 )
149 test_func = functools.partial(_bgp_converge, router1)
150 success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5)
151 assert result is None, 'Failed to see BGP convergence after reset in "{}"'.format(
152 router1.name
153 )
154
155 logger.info(
156 "Verify if TCP MSS value is synced with neighbor in {}".format(router1.name)
157 )
158 test_func = functools.partial(_bgp_check_neighbor_tcp_mss, router1, "192.168.255.2")
159 success, result = topotest.run_and_expect(test_func, None, count=3, wait=0.5)
160 assert (
161 result is None
162 ), 'Failed to sync TCP MSS value over BGP session in "{}"'.format(router1.name)
163 logger.info("TCP MSS value is synced with neighbor in {}".format(router1.name))
164
165 logger.info(
166 "Verify if TCP MSS value is synced with neighbor in {}".format(router2.name)
167 )
168 test_func = functools.partial(_bgp_check_neighbor_tcp_mss, router2, "192.168.255.1")
169 success, result = topotest.run_and_expect(test_func, None, count=3, wait=0.5)
170 assert (
171 result is None
172 ), 'Failed to sync TCP MSS value over BGP session in "{}"'.format(router2.name)
173 logger.info("TCP MSS value is synced with neighbor in {}".format(router2.name))
174
175
176if __name__ == "__main__":
177 args = ["-s"] + sys.argv[1:]
178 sys.exit(pytest.main(args))