4343 "topo" ,
4444 "myip" ,
4545 "peerip" ,
46- "nn_target_interface" ])
46+ "nn_target_interface" ,
47+ "nn_target_namespace" ])
4748_SUPPORTED_PTF_TOPOS = ["ptf32" , "ptf64" ]
4849_SUPPORTED_T1_TOPOS = ["t1" , "t1-lag" , "t1-64-lag" ]
4950_TOR_ONLY_PROTOCOL = ["DHCP" ]
@@ -112,8 +113,7 @@ def copp_testbed(
112113 creds ,
113114 ptfhost ,
114115 tbinfo ,
115- request ,
116- disable_lldp_for_testing # usefixtures not supported on fixtures
116+ request
117117):
118118 """
119119 Pytest fixture to handle setup and cleanup for the COPP tests.
@@ -125,10 +125,12 @@ def copp_testbed(
125125 pytest .skip ("Topology not supported by COPP tests" )
126126
127127 try :
128- _setup_testbed (duthost , creds , ptfhost , test_params )
128+ _setup_multi_asic_proxy (duthost , creds , test_params , tbinfo )
129+ _setup_testbed (duthost , creds , ptfhost , test_params , tbinfo )
129130 yield test_params
130131 finally :
131- _teardown_testbed (duthost , creds , ptfhost , test_params )
132+ _teardown_multi_asic_proxy (duthost , creds , test_params , tbinfo )
133+ _teardown_testbed (duthost , creds , ptfhost , test_params , tbinfo )
132134
133135@pytest .fixture (autouse = True )
134136def ignore_expected_loganalyzer_exceptions (rand_one_dut_hostname , loganalyzer ):
@@ -143,10 +145,6 @@ def ignore_expected_loganalyzer_exceptions(rand_one_dut_hostname, loganalyzer):
143145 loganalyzer: Loganalyzer utility fixture
144146 """
145147 ignoreRegex = [
146- ".*ERR monit.*'lldpd_monitor' process is not running.*" ,
147- ".*ERR monit.* 'lldp\|lldpd_monitor' status failed.*-- 'lldpd:' is not running.*" ,
148- ".*ERR monit.*'lldp_syncd' process is not running.*" ,
149- ".*ERR monit.*'lldp\|lldp_syncd' status failed.*'python2 -m lldp_syncd' is not running.*" ,
150148 ".*snmp#snmp-subagent.*" ,
151149 ".*kernel reports TIME_ERROR: 0x4041: Clock Unsynchronized.*"
152150 ]
@@ -207,80 +205,106 @@ def _gather_test_params(tbinfo, duthost, request):
207205 peerip = bgp_peer ["peer_addr" ]
208206 break
209207
210- logging .info ("nn_target_port {} nn_target_interface {}" .format (nn_target_port , nn_target_interface ))
208+ nn_target_namespace = mg_facts ["minigraph_neighbors" ][nn_target_interface ]['namespace' ]
209+
210+ logging .info ("nn_target_port {} nn_target_interface {} nn_target_namespace {}" .format (nn_target_port , nn_target_interface , nn_target_namespace ))
211211
212212 return _COPPTestParameters (nn_target_port = nn_target_port ,
213213 swap_syncd = swap_syncd ,
214214 topo = topo ,
215215 myip = myip ,
216216 peerip = peerip ,
217- nn_target_interface = nn_target_interface )
217+ nn_target_interface = nn_target_interface ,
218+ nn_target_namespace = nn_target_namespace )
218219
219- def _setup_testbed (dut , creds , ptf , test_params ):
220+ def _setup_testbed (dut , creds , ptf , test_params , tbinfo ):
220221 """
221222 Sets up the testbed to run the COPP tests.
222223 """
223-
224224 logging .info ("Set up the PTF for COPP tests" )
225225 copp_utils .configure_ptf (ptf , test_params .nn_target_port )
226226
227227 logging .info ("Update the rate limit for the COPP policer" )
228- copp_utils .limit_policer (dut , _TEST_RATE_LIMIT )
228+ copp_utils .limit_policer (dut , _TEST_RATE_LIMIT , test_params . nn_target_namespace )
229229
230- if test_params .swap_syncd :
230+ # Multi-asic will not support this mode as of now.
231+ if test_params .swap_syncd and not dut .is_multi_asic :
231232 logging .info ("Swap out syncd to use RPC image..." )
232233 docker .swap_syncd (dut , creds )
233234 else :
235+ # Set sysctl RCVBUF parameter for tests
236+ dut .command ("sysctl -w net.core.rmem_max=609430500" )
237+
238+ # Set sysctl SENDBUF parameter for tests
239+ dut .command ("sysctl -w net.core.wmem_max=609430500" )
240+
234241 # NOTE: Even if the rpc syncd image is already installed, we need to restart
235242 # SWSS for the COPP changes to take effect.
236243 logging .info ("Reloading config and restarting swss..." )
237244 config_reload (dut )
238245
239246 logging .info ("Configure syncd RPC for testing" )
240- copp_utils .configure_syncd (dut , test_params .nn_target_port , test_params .nn_target_interface , creds )
247+ copp_utils .configure_syncd (dut , test_params .nn_target_port , test_params .nn_target_interface ,
248+ test_params .nn_target_namespace , creds )
241249
242- def _teardown_testbed (dut , creds , ptf , test_params ):
250+ def _teardown_testbed (dut , creds , ptf , test_params , tbinfo ):
243251 """
244252 Tears down the testbed, returning it to its initial state.
245253 """
246-
247254 logging .info ("Restore PTF post COPP test" )
248255 copp_utils .restore_ptf (ptf )
249256
250257 logging .info ("Restore COPP policer to default settings" )
251- copp_utils .restore_policer (dut )
258+ copp_utils .restore_policer (dut , test_params . nn_target_namespace )
252259
253- if test_params .swap_syncd :
260+ if test_params .swap_syncd and not dut . is_multi_asic :
254261 logging .info ("Restore default syncd docker..." )
255262 docker .restore_default_syncd (dut , creds )
256263 else :
264+ copp_utils .restore_syncd (dut , test_params .nn_target_namespace )
257265 logging .info ("Reloading config and restarting swss..." )
258266 config_reload (dut )
259267
260-
261- @pytest .fixture (scope = "class" )
262- def disable_lldp_for_testing (
263- duthosts ,
264- rand_one_dut_hostname ,
265- disable_container_autorestart ,
266- enable_container_autorestart
267- ):
268- """Disables LLDP during testing so that it doesn't interfere with the policer."""
269- duthost = duthosts [rand_one_dut_hostname ]
270-
271- logging .info ("Disabling LLDP for the COPP tests" )
272-
273- feature_list = ['lldp' ]
274- disable_container_autorestart (duthost , testcase = "test_copp" , feature_list = feature_list )
275-
276- duthost .command ("docker exec lldp supervisorctl stop lldp-syncd" )
277- duthost .command ("docker exec lldp supervisorctl stop lldpd" )
278-
279- yield
280-
281- logging .info ("Restoring LLDP after the COPP tests" )
282-
283- duthost .command ("docker exec lldp supervisorctl start lldpd" )
284- duthost .command ("docker exec lldp supervisorctl start lldp-syncd" )
285-
286- enable_container_autorestart (duthost , testcase = "test_copp" , feature_list = feature_list )
268+ def _setup_multi_asic_proxy (dut , creds , test_params , tbinfo ):
269+ """
270+ Sets up the testbed to run the COPP tests on multi-asic platfroms via setting proxy.
271+ """
272+ if not dut .is_multi_asic :
273+ return
274+
275+ logging .info ("Adding iptables rules and enabling eth0 port forwarding" )
276+ http_proxy , https_proxy = copp_utils ._get_http_and_https_proxy_ip (creds )
277+ # Add IP Table rule for http and ptf nn_agent traffic.
278+ dut .command ("sudo sysctl net.ipv4.conf.eth0.forwarding=1" )
279+ mgmt_ip = dut .host .options ["inventory_manager" ].get_host (dut .hostname ).vars ["ansible_host" ]
280+ # Add Rule to communicate to http/s proxy from namespace
281+ dut .command ("sudo iptables -t nat -A POSTROUTING -p tcp --dport 8080 -j SNAT --to-source {}" .format (mgmt_ip ))
282+ dut .command ("sudo ip -n {} rule add from all to {} pref 1 lookup default" .format (test_params .nn_target_namespace , http_proxy ))
283+ if http_proxy != https_proxy :
284+ dut .command ("sudo ip -n {} rule add from all to {} pref 2 lookup default" .format (test_params .nn_target_namespace , https_proxy ))
285+ # Add Rule to communicate to ptf nn agent client from namespace
286+ ns_ip = dut .shell ("sudo ip -n {} -4 -o addr show eth0" .format (test_params .nn_target_namespace ) + " | awk '{print $4}' | cut -d'/' -f1" )["stdout" ]
287+ dut .command ("sudo iptables -t nat -A PREROUTING -p tcp --dport 10900 -j DNAT --to-destination {}" .format (ns_ip ))
288+ dut .command ("sudo ip -n {} rule add from {} to {} pref 3 lookup default" .format (test_params .nn_target_namespace , ns_ip , tbinfo ["ptf_ip" ]))
289+
290+ def _teardown_multi_asic_proxy (dut , creds , test_params , tbinfo ):
291+ """
292+ Tears down multi asic proxy settings, returning it to its initial state.
293+ """
294+ if not dut .is_multi_asic :
295+ return
296+
297+ logging .info ("Removing iptables rules and disabling eth0 port forwarding" )
298+ http_proxy , https_proxy = copp_utils ._get_http_and_https_proxy_ip (creds )
299+ dut .command ("sudo sysctl net.ipv4.conf.eth0.forwarding=0" )
300+ # Delete IP Table rule for http and ptf nn_agent traffic.
301+ mgmt_ip = dut .host .options ["inventory_manager" ].get_host (dut .hostname ).vars ["ansible_host" ]
302+ # Delete Rule to communicate to http/s proxy from namespace
303+ dut .command ("sudo iptables -t nat -D POSTROUTING -p tcp --dport 8080 -j SNAT --to-source {}" .format (mgmt_ip ))
304+ dut .command ("sudo ip -n {} rule delete from all to {} pref 1 lookup default" .format (test_params .nn_target_namespace , http_proxy ))
305+ if http_proxy != https_proxy :
306+ dut .command ("sudo ip -n {} rule delete from all to {} pref 2 lookup default" .format (test_params .nn_target_namespace , https_proxy ))
307+ # Delete Rule to communicate to ptf nn agent client from namespace
308+ ns_ip = dut .shell ("sudo ip -n {} -4 -o addr show eth0" .format (test_params .nn_target_namespace ) + " | awk '{print $4}' | cut -d'/' -f1" )["stdout" ]
309+ dut .command ("sudo iptables -t nat -D PREROUTING -p tcp --dport 10900 -j DNAT --to-destination {}" .format (ns_ip ))
310+ dut .command ("sudo ip -n {} rule delete from {} to {} pref 3 lookup default" .format (test_params .nn_target_namespace , ns_ip , tbinfo ["ptf_ip" ]))
0 commit comments