11import logging
22from tabulate import tabulate
3- from tests .common .utilities import (wait , wait_until )
4- from tests .common .helpers .assertions import pytest_assert
3+ from tests .common .utilities import wait
54logger = logging .getLogger (__name__ )
65
76TGEN_AS_NUM = 65200
1211aspaths = [65002 , 65003 ]
1312
1413
15- def run_lacp_add_remove_link_from_dut (api ,
14+ def run_lacp_add_remove_link_from_dut (snappi_api ,
1615 duthost ,
1716 tgen_ports ,
1817 iteration ,
1918 port_count ,
20- number_of_routes ,
21- port_speed ,):
19+ number_of_routes ,):
2220 """
2321 Run Local link failover test
2422
@@ -29,7 +27,6 @@ def run_lacp_add_remove_link_from_dut(api,
2927 iteration: number of iterations for running convergence test on a port
3028 port_count: total number of ports used in test
3129 number_of_routes: Number of IPv4/IPv6 Routes
32- port_speed: speed of the port used for test
3330 """
3431
3532 """ Create bgp config on dut """
@@ -38,25 +35,21 @@ def run_lacp_add_remove_link_from_dut(api,
3835 port_count ,)
3936
4037 """ Create bgp config on TGEN """
41- tgen_bgp_config = __tgen_bgp_config (api ,
38+ tgen_bgp_config = __tgen_bgp_config (snappi_api ,
4239 port_count ,
43- number_of_routes ,
44- port_speed ,)
40+ number_of_routes ,)
4541
4642 """
4743 Run the convergence test by flapping all the rx
4844 links one by one and calculate the convergence values
4945 """
50- get_lacp_add_remove_link_from_dut (api ,
46+ get_lacp_add_remove_link_from_dut (snappi_api ,
5147 duthost ,
5248 tgen_bgp_config ,
5349 iteration ,
5450 port_count ,
5551 number_of_routes ,)
5652
57- """ Cleanup the dut configs after getting the convergence numbers """
58- cleanup_config (duthost )
59-
6053
6154def duthost_bgp_config (duthost ,
6255 tgen_ports ,
@@ -130,20 +123,18 @@ def duthost_bgp_config(duthost,
130123 duthost .shell (bgp_config )
131124
132125
133- def __tgen_bgp_config (api ,
126+ def __tgen_bgp_config (snappi_api ,
134127 port_count ,
135- number_of_routes ,
136- port_speed ,):
128+ number_of_routes ,):
137129 """
138130 Creating BGP config on TGEN
139131
140132 Args:
141133 api (pytest fixture): snappi API
142134 port_count: total number of ports used in test
143135 number_of_routes: Number of IPv4/IPv6 Routes
144- port_speed: speed of the port used for test
145136 """
146- config = api .config ()
137+ config = snappi_api .config ()
147138 for i in range (1 , port_count + 1 ):
148139 config .ports .port (name = 'Test_Port_%d' %
149140 i , location = temp_tg_port [i - 1 ]['location' ])
@@ -169,15 +160,15 @@ def __tgen_bgp_config(api,
169160 layer1 .name = 'port settings'
170161 layer1 .port_names = [port .name for port in config .ports ]
171162 layer1 .ieee_media_defaults = False
172- layer1 .auto_negotiation .rs_fec = True
163+ layer1 .auto_negotiation .rs_fec = False
173164 layer1 .auto_negotiation .link_training = False
174- layer1 .speed = port_speed
165+ layer1 .speed = temp_tg_port [ 0 ][ 'speed' ]
175166 layer1 .auto_negotiate = False
176167
177168 # Source
178169 config .devices .device (name = 'Tx' )
179170 eth_1 = config .devices [0 ].ethernets .add ()
180- eth_1 .port_name = lag0 .name
171+ eth_1 .connection . port_name = lag0 .name
181172 eth_1 .name = 'Ethernet 1'
182173 eth_1 .mac = "00:14:0a:00:00:01"
183174 ipv4_1 = eth_1 .ipv4_addresses .add ()
@@ -194,7 +185,7 @@ def __tgen_bgp_config(api,
194185 # Destination
195186 config .devices .device (name = "Rx" )
196187 eth_2 = config .devices [1 ].ethernets .add ()
197- eth_2 .port_name = lag1 .name
188+ eth_2 .connection . port_name = lag1 .name
198189 eth_2 .name = 'Ethernet 2'
199190 eth_2 .mac = "00:14:01:00:00:01"
200191 ipv4_2 = eth_2 .ipv4_addresses .add ()
@@ -254,31 +245,31 @@ def createTrafficItem(traffic_name, src, dest):
254245 return config
255246
256247
257- def get_flow_stats (api ):
248+ def get_flow_stats (snappi_api ):
258249 """
259250 Args:
260- api (pytest fixture): Snappi API
251+ snappi_api (pytest fixture): Snappi API
261252 """
262- request = api .metrics_request ()
253+ request = snappi_api .metrics_request ()
263254 request .flow .flow_names = []
264- return api .get_metrics (request ).flow_metrics
255+ return snappi_api .get_metrics (request ).flow_metrics
265256
266257
267- def get_port_stats (api , port_name ):
258+ def get_port_stats (snappi_api , port_name ):
268259 """
269260 Args:
270- api (pytest fixture): Snappi API
261+ snappi_api (pytest fixture): Snappi API
271262 """
272- request = api .metrics_request ()
263+ request = snappi_api .metrics_request ()
273264 request .port .port_names = [port_name ]
274- return api .get_metrics (request ).port_metrics
265+ return snappi_api .get_metrics (request ).port_metrics
275266
276267
277- def print_port_stats (api , port_names ):
268+ def print_port_stats (snappi_api , port_names ):
278269 table1 = []
279270 for i , j in enumerate (port_names ):
280271 port_table = []
281- port_stats = get_port_stats (api , j )
272+ port_stats = get_port_stats (snappi_api , j )
282273 port_table .append (temp_tg_port [i ]['peer_port' ])
283274 port_table .append (j )
284275 port_table .append (port_stats [0 ].frames_tx_rate )
@@ -289,7 +280,7 @@ def print_port_stats(api, port_names):
289280 tabulate (table1 , headers = columns , tablefmt = "psql" ))
290281
291282
292- def get_lacp_add_remove_link_from_dut (api ,
283+ def get_lacp_add_remove_link_from_dut (snappi_api ,
293284 duthost ,
294285 bgp_config ,
295286 iteration ,
@@ -310,7 +301,7 @@ def get_lacp_add_remove_link_from_dut(api,
310301 dut .append (temp_tg_port [i ]['peer_port' ])
311302 port_names = rx_port_names
312303 port_names .insert (0 , 'Test_Port_1' )
313- api .set_config (bgp_config )
304+ snappi_api .set_config (bgp_config )
314305
315306 def get_avg_cpdp_convergence_time (port_name , dut_port_name ):
316307 """
@@ -319,32 +310,32 @@ def get_avg_cpdp_convergence_time(port_name, dut_port_name):
319310 """
320311 table , tx_frate , rx_frate = [], [], []
321312 print ("Starting all protocols ..." )
322- ps = api . protocol_state ()
323- ps . state = ps .START
324- api . set_protocol_state ( ps )
313+ cs = snappi_api . control_state ()
314+ cs . protocol . all . state = cs . protocol . all .START
315+ snappi_api . set_control_state ( cs )
325316 wait (TIMEOUT , "For Protocols To start" )
326317 for i in range (0 , iteration ):
327318 logger .info (
328319 '|---- {} Link Flap Iteration : {} ----|' .format (dut_port_name , i + 1 ))
329320 """ Starting Traffic """
330321 logger .info ('Starting Traffic' )
331- ts = api . transmit_state ()
332- ts . state = ts .START
333- api . set_transmit_state ( ts )
322+ cs = snappi_api . control_state ()
323+ cs . traffic . flow_transmit . state = cs . traffic . flow_transmit .START
324+ snappi_api . set_control_state ( cs )
334325 wait (TIMEOUT , "For Traffic To start" )
335- flow_stats = get_flow_stats (api )
326+ flow_stats = get_flow_stats (snappi_api )
336327 tx_frame_rate = flow_stats [0 ].frames_tx_rate
337328 assert tx_frame_rate != 0 , "Traffic has not started"
338329 logger .info ('Traffic has started' )
339330 logger .info ('Port Stats before {} failover' .format (dut_port_name ))
340- print_port_stats (api , port_names )
331+ print_port_stats (snappi_api , port_names )
341332 """ Flapping Link """
342333 logger .info (
343334 'Simulating Link Failure on {} from dut side ' .format (port_name ))
344335 duthost .shell (
345336 "sudo config portchannel member del PortChannel2 %s\n " % (dut_port_name ))
346337 wait (TIMEOUT - 20 , "For Link to go down and traffic to stabilize" )
347- flows = get_flow_stats (api )
338+ flows = get_flow_stats (snappi_api )
348339 for flow in flows :
349340 tx_frate .append (flow .frames_tx_rate )
350341 rx_frate .append (flow .frames_tx_rate )
@@ -353,7 +344,7 @@ def get_avg_cpdp_convergence_time(port_name, dut_port_name):
353344 .format (sum (tx_frate ), sum (rx_frate ))
354345 logger .info ("Traffic has converged after link flap with no loss" )
355346 logger .info ('Port Stats after {} failover' .format (dut_port_name ))
356- print_port_stats (api , port_names )
347+ print_port_stats (snappi_api , port_names )
357348 """ Performing link up at the end of iteration """
358349 logger .info ('Simulating Link Up on {} from dut side at the end of iteration {}' .format (
359350 dut_port_name , i + 1 ))
@@ -372,19 +363,3 @@ def get_avg_cpdp_convergence_time(port_name, dut_port_name):
372363 tgen_port_name , dut_port_name ))
373364 columns = ['Event Name' , 'No. of Routes' , 'Iterations' , 'Loss%' ]
374365 logger .info ("\n %s" % tabulate (table , headers = columns , tablefmt = "psql" ))
375-
376-
377- def cleanup_config (duthost ):
378- """
379- Cleaning up dut config at the end of the test
380-
381- Args:
382- duthost (pytest fixture): duthost fixture
383- """
384- logger .info ('Cleaning up config' )
385- duthost .command ("sudo cp {} {}" .format (
386- "/etc/sonic/config_db_backup.json" , "/etc/sonic/config_db.json" ))
387- duthost .shell ("sudo config reload -y \n " )
388- pytest_assert (wait_until (360 , 10 , 1 , duthost .critical_services_fully_started ),
389- "Not all critical services are fully started" )
390- logger .info ('Convergence Test Completed' )
0 commit comments