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.
42 # add after imports, before defining classes or functions:
43 pytestmark
= [pytest
.mark
.bgpd
]
45 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
46 sys
.path
.append(os
.path
.join(CWD
, "../"))
48 # pylint: disable=C0413
49 from lib
import topotest
50 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
51 from lib
.topolog
import logger
52 from mininet
.topo
import Topo
54 pytestmark
= [pytest
.mark
.bgpd
]
57 class TemplateTopo(Topo
):
58 def build(self
, *_args
, **_opts
):
59 tgen
= get_topogen(self
)
61 for routern
in range(1, 3):
62 tgen
.add_router("r{}".format(routern
))
64 switch
= tgen
.add_switch("s1")
65 switch
.add_link(tgen
.gears
["r1"])
66 switch
.add_link(tgen
.gears
["r2"])
69 def setup_module(mod
):
70 tgen
= Topogen(TemplateTopo
, mod
.__name
__)
73 router_list
= tgen
.routers()
75 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
77 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
80 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
86 def teardown_module(mod
):
91 def test_bgp_tcp_mss():
94 if tgen
.routers_have_failure():
95 pytest
.skip(tgen
.errors
)
97 router1
= tgen
.gears
["r1"]
98 router2
= tgen
.gears
["r2"]
100 def _bgp_converge(router
):
101 output
= json
.loads(router
.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json"))
104 "bgpState": "Established",
105 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 0}},
108 return topotest
.json_cmp(output
, expected
)
110 def _bgp_conf_tcp_mss(router
, as_num
, neigh
):
112 """configure terminal
114 neighbor {1} tcp-mss 500""".format(
119 def _bgp_clear_session(router
):
120 router
.vtysh_cmd("clear bgp *")
122 def _bgp_check_neighbor_tcp_mss(router
, neigh
):
123 output
= json
.loads(router
.vtysh_cmd("show bgp neighbor {} json".format(neigh
)))
125 "{}".format(neigh
): {"bgpTcpMssConfigured": 500, "bgpTcpMssSynced": 488}
127 return topotest
.json_cmp(output
, expected
)
129 logger
.info("Check if neighbor sessions are up in {}".format(router1
.name
))
130 test_func
= functools
.partial(_bgp_converge
, router1
)
131 success
, result
= topotest
.run_and_expect(test_func
, None, count
=15, wait
=0.5)
132 assert result
is None, 'Failed to see BGP convergence in "{}"'.format(router1
.name
)
134 logger
.info("BGP neighbor session is up in {}".format(router1
.name
))
137 "Configure tcp-mss 500 on {} and reset the session".format(router1
.name
)
139 _bgp_conf_tcp_mss(router1
, "65000", "192.168.255.2")
140 _bgp_clear_session(router1
)
143 "Configure tcp-mss 500 on {} and reset the session".format(router2
.name
)
145 _bgp_conf_tcp_mss(router2
, "65001", "192.168.255.1")
146 _bgp_clear_session(router2
)
149 "Check if neighbor session is up after reset in {}".format(router1
.name
)
151 test_func
= functools
.partial(_bgp_converge
, router1
)
152 success
, result
= topotest
.run_and_expect(test_func
, None, count
=15, wait
=0.5)
153 assert result
is None, 'Failed to see BGP convergence after reset in "{}"'.format(
158 "Verify if TCP MSS value is synced with neighbor in {}".format(router1
.name
)
160 test_func
= functools
.partial(_bgp_check_neighbor_tcp_mss
, router1
, "192.168.255.2")
161 success
, result
= topotest
.run_and_expect(test_func
, None, count
=3, wait
=0.5)
164 ), 'Failed to sync TCP MSS value over BGP session in "{}"'.format(router1
.name
)
165 logger
.info("TCP MSS value is synced with neighbor in {}".format(router1
.name
))
168 "Verify if TCP MSS value is synced with neighbor in {}".format(router2
.name
)
170 test_func
= functools
.partial(_bgp_check_neighbor_tcp_mss
, router2
, "192.168.255.1")
171 success
, result
= topotest
.run_and_expect(test_func
, None, count
=3, wait
=0.5)
174 ), 'Failed to sync TCP MSS value over BGP session in "{}"'.format(router2
.name
)
175 logger
.info("TCP MSS value is synced with neighbor in {}".format(router2
.name
))
178 if __name__
== "__main__":
179 args
= ["-s"] + sys
.argv
[1:]
180 sys
.exit(pytest
.main(args
))