5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2021 by
8 # Abhinay Ramesh <rabhinay@vmware.com>
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
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
28 Test if works the following commands:
30 neighbor 192.168.255.2 tcp-mss 500
32 Need to verify if the tcp-mss value is reflected in the TCP session.
41 # add after imports, before defining classes or functions:
42 pytestmark
= [pytest
.mark
.bgpd
]
44 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
45 sys
.path
.append(os
.path
.join(CWD
, "../"))
47 # pylint: disable=C0413
48 from lib
import topotest
49 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
50 from lib
.topolog
import logger
52 pytestmark
= [pytest
.mark
.bgpd
]
56 for routern
in range(1, 3):
57 tgen
.add_router("r{}".format(routern
))
59 switch
= tgen
.add_switch("s1")
60 switch
.add_link(tgen
.gears
["r1"])
61 switch
.add_link(tgen
.gears
["r2"])
64 def setup_module(mod
):
65 tgen
= Topogen(build_topo
, mod
.__name
__)
68 router_list
= tgen
.routers()
70 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
72 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
75 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
81 def teardown_module(mod
):
86 def test_bgp_tcp_mss():
89 if tgen
.routers_have_failure():
90 pytest
.skip(tgen
.errors
)
92 router1
= tgen
.gears
["r1"]
93 router2
= tgen
.gears
["r2"]
95 def _bgp_converge(router
):
96 output
= json
.loads(router
.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json"))
99 "bgpState": "Established",
100 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 0}},
103 return topotest
.json_cmp(output
, expected
)
105 def _bgp_conf_tcp_mss(router
, as_num
, neigh
):
107 """configure terminal
109 neighbor {1} tcp-mss 500""".format(
114 def _bgp_clear_session(router
):
115 router
.vtysh_cmd("clear bgp *")
117 def _bgp_check_neighbor_tcp_mss(router
, neigh
):
118 output
= json
.loads(router
.vtysh_cmd("show bgp neighbor {} json".format(neigh
)))
120 "{}".format(neigh
): {"bgpTcpMssConfigured": 500, "bgpTcpMssSynced": 488}
122 return topotest
.json_cmp(output
, expected
)
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
)
129 logger
.info("BGP neighbor session is up in {}".format(router1
.name
))
132 "Configure tcp-mss 500 on {} and reset the session".format(router1
.name
)
134 _bgp_conf_tcp_mss(router1
, "65000", "192.168.255.2")
135 _bgp_clear_session(router1
)
138 "Configure tcp-mss 500 on {} and reset the session".format(router2
.name
)
140 _bgp_conf_tcp_mss(router2
, "65001", "192.168.255.1")
141 _bgp_clear_session(router2
)
144 "Check if neighbor session is up after reset in {}".format(router1
.name
)
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(
153 "Verify if TCP MSS value is synced with neighbor in {}".format(router1
.name
)
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)
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
))
163 "Verify if TCP MSS value is synced with neighbor in {}".format(router2
.name
)
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)
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
))
173 if __name__
== "__main__":
174 args
= ["-s"] + sys
.argv
[1:]
175 sys
.exit(pytest
.main(args
))