@@ -55,6 +55,11 @@ def __init__(self):
55
55
self .myip = test_params .get ('myip' , None )
56
56
self .peerip = test_params .get ('peerip' , None )
57
57
self .default_server_send_rate_limit_pps = test_params .get ('send_rate_limit' , 2000 )
58
+
59
+ # For counter test
60
+ self .expect_send_pkt_number = test_params .get ('sent_pkt_number' , None )
61
+ self .send_duration = test_params .get ('send_duration' , None )
62
+ self .is_counter_test = self .expect_send_pkt_number is not None and self .send_duration is not None
58
63
59
64
self .needPreSend = None
60
65
@@ -110,6 +115,9 @@ def copp_test(self, packet, send_intf, recv_intf):
110
115
'''
111
116
Pre-send some packets for a second to absorb the CBS capacity.
112
117
'''
118
+ if self .is_counter_test :
119
+ return self .copp_counter_test (packet , send_intf , recv_intf )
120
+
113
121
if self .needPreSend :
114
122
pre_send_count = 0
115
123
end_time = datetime .datetime .now () + datetime .timedelta (seconds = self .DEFAULT_PRE_SEND_INTERVAL_SEC )
@@ -178,6 +186,67 @@ def copp_test(self, packet, send_intf, recv_intf):
178
186
179
187
return send_count , recv_count , time_delta , time_delta_ms , tx_pps , rx_pps
180
188
189
+ def copp_counter_test (self , packet , send_intf , recv_intf ):
190
+ pre_test_ptf_tx_counter = self .dataplane .get_counters (* send_intf )
191
+ pre_test_ptf_rx_counter = self .dataplane .get_counters (* recv_intf )
192
+ pre_test_nn_tx_counter = self .dataplane .get_nn_counters (* send_intf )
193
+ pre_test_nn_rx_counter = self .dataplane .get_nn_counters (* recv_intf )
194
+
195
+ send_count = 0
196
+ start_time = datetime .datetime .now ()
197
+ send_window = float (self .send_duration ) / float (self .expect_send_pkt_number )
198
+ while send_count < self .expect_send_pkt_number :
199
+ begin = time .time ()
200
+ testutils .send_packet (self , send_intf , packet )
201
+ send_count += 1
202
+ elapse = time .time () - begin
203
+
204
+ # Depending on the server/platform combination it is possible for the server to
205
+ # overwhelm the DUT, so we add an artificial delay here to rate-limit the server.
206
+ if elapse > 0 :
207
+ time .sleep (send_window - elapse )
208
+
209
+ end_time = datetime .datetime .now ()
210
+ time .sleep (self .DEFAULT_RECEIVE_WAIT_TIME ) # Wait a little bit for all the packets to make it through
211
+ recv_count = testutils .count_matched_packets (self , packet , recv_intf [1 ], recv_intf [0 ])
212
+
213
+ post_test_ptf_tx_counter = self .dataplane .get_counters (* send_intf )
214
+ post_test_ptf_rx_counter = self .dataplane .get_counters (* recv_intf )
215
+ post_test_nn_tx_counter = self .dataplane .get_nn_counters (* send_intf )
216
+ post_test_nn_rx_counter = self .dataplane .get_nn_counters (* recv_intf )
217
+
218
+ ptf_tx_count = int (post_test_ptf_tx_counter [1 ] - pre_test_ptf_tx_counter [1 ])
219
+ nn_tx_count = int (post_test_nn_tx_counter [1 ] - pre_test_nn_tx_counter [1 ])
220
+ ptf_rx_count = int (post_test_ptf_rx_counter [0 ] - pre_test_ptf_rx_counter [0 ])
221
+ nn_rx_count = int (post_test_nn_rx_counter [0 ] - pre_test_nn_rx_counter [0 ])
222
+
223
+ self .log ("" , True )
224
+ self .log ("Counters before the test:" , True )
225
+ self .log ("If counter (0, n): %s" % str (pre_test_ptf_tx_counter ), True )
226
+ self .log ("NN counter (0, n): %s" % str (pre_test_nn_tx_counter ), True )
227
+ self .log ("If counter (1, n): %s" % str (pre_test_ptf_rx_counter ), True )
228
+ self .log ("NN counter (1, n): %s" % str (pre_test_nn_rx_counter ), True )
229
+ self .log ("" , True )
230
+ self .log ("Counters after the test:" , True )
231
+ self .log ("If counter (0, n): %s" % str (post_test_ptf_tx_counter ), True )
232
+ self .log ("NN counter (0, n): %s" % str (post_test_nn_tx_counter ), True )
233
+ self .log ("If counter (1, n): %s" % str (post_test_ptf_rx_counter ), True )
234
+ self .log ("NN counter (1, n): %s" % str (post_test_nn_rx_counter ), True )
235
+ self .log ("" )
236
+ self .log ("Sent through NN to local ptf_nn_agent: %d" % ptf_tx_count )
237
+ self .log ("Sent through If to remote ptf_nn_agent: %d" % nn_tx_count )
238
+ self .log ("Recv from If on remote ptf_nn_agent: %d" % ptf_rx_count )
239
+ self .log ("Recv from NN on from remote ptf_nn_agent: %d" % nn_rx_count )
240
+
241
+ time_delta = end_time - start_time
242
+ self .log ("Sent out %d packets in %ds" % (send_count , time_delta .seconds ))
243
+ time_delta_ms = (time_delta .microseconds + time_delta .seconds * 10 ** 6 ) / 1000
244
+ tx_pps = int (send_count / (float (time_delta_ms ) / 1000 ))
245
+ rx_pps = int (recv_count / (float (time_delta_ms ) / 1000 ))
246
+
247
+ return send_count , recv_count , time_delta , time_delta_ms , tx_pps , rx_pps
248
+
249
+
181
250
def contruct_packet (self , port_number ):
182
251
raise NotImplementedError
183
252
@@ -214,21 +283,22 @@ def __init__(self):
214
283
self .needPreSend = False
215
284
216
285
def check_constraints (self , send_count , recv_count , time_delta_ms , rx_pps ):
217
- pkt_rx_limit = send_count * 0.90
286
+ if not self .is_counter_test :
287
+ pkt_rx_limit = send_count * 0.90
218
288
219
- self .log ("" )
220
- self .log ("Checking constraints (NoPolicy):" )
221
- self .log (
222
- "rx_pps (%d) > NO_POLICER_LIMIT (%d): %s" %
223
- (int (rx_pps ), int (self .NO_POLICER_LIMIT ), str (rx_pps > self .NO_POLICER_LIMIT ))
224
- )
225
- self .log (
226
- "recv_count (%d) > pkt_rx_limit (%d): %s" %
227
- (int (recv_count ), int (pkt_rx_limit ), str (recv_count > pkt_rx_limit ))
228
- )
289
+ self .log ("" )
290
+ self .log ("Checking constraints (NoPolicy):" )
291
+ self .log (
292
+ "rx_pps (%d) > NO_POLICER_LIMIT (%d): %s" %
293
+ (int (rx_pps ), int (self .NO_POLICER_LIMIT ), str (rx_pps > self .NO_POLICER_LIMIT ))
294
+ )
295
+ self .log (
296
+ "recv_count (%d) > pkt_rx_limit (%d): %s" %
297
+ (int (recv_count ), int (pkt_rx_limit ), str (recv_count > pkt_rx_limit ))
298
+ )
229
299
230
- assert (rx_pps > self .NO_POLICER_LIMIT )
231
- assert (recv_count > pkt_rx_limit )
300
+ assert (rx_pps > self .NO_POLICER_LIMIT )
301
+ assert (recv_count > pkt_rx_limit )
232
302
233
303
234
304
class PolicyTest (ControlPlaneBaseTest ):
@@ -237,17 +307,18 @@ def __init__(self):
237
307
self .needPreSend = True
238
308
239
309
def check_constraints (self , send_count , recv_count , time_delta_ms , rx_pps ):
240
- self .log ("" )
241
- self .log ("Checking constraints (PolicyApplied):" )
242
- self .log (
243
- "PPS_LIMIT_MIN (%d) <= rx_pps (%d) <= PPS_LIMIT_MAX (%d): %s" %
244
- (int (self .PPS_LIMIT_MIN ),
245
- int (rx_pps ),
246
- int (self .PPS_LIMIT_MAX ),
247
- str (self .PPS_LIMIT_MIN <= rx_pps <= self .PPS_LIMIT_MAX ))
248
- )
249
-
250
- assert (self .PPS_LIMIT_MIN <= rx_pps <= self .PPS_LIMIT_MAX )
310
+ if not self .is_counter_test :
311
+ self .log ("" )
312
+ self .log ("Checking constraints (PolicyApplied):" )
313
+ self .log (
314
+ "PPS_LIMIT_MIN (%d) <= rx_pps (%d) <= PPS_LIMIT_MAX (%d): %s" %
315
+ (int (self .PPS_LIMIT_MIN ),
316
+ int (rx_pps ),
317
+ int (self .PPS_LIMIT_MAX ),
318
+ str (self .PPS_LIMIT_MIN <= rx_pps <= self .PPS_LIMIT_MAX ))
319
+ )
320
+
321
+ assert (self .PPS_LIMIT_MIN <= rx_pps <= self .PPS_LIMIT_MAX )
251
322
252
323
253
324
# SONIC config contains policer CIR=600 for ARP
0 commit comments