forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopp_tests.py
More file actions
812 lines (675 loc) · 26.5 KB
/
Copy pathcopp_tests.py
File metadata and controls
812 lines (675 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
"""
ptf --test-dir saitests copp_tests \
--qlen=100000 \
--platform nn \
-t "verbose=True;target_port=3" \
--device-socket 0-3@tcp://127.0.0.1:10900 \
--device-socket 1-3@tcp://10.3.147.47:10900
or
ptf --test-dir saitests copp_tests \
--qlen=100000 \
--platform nn \
-t "verbose=True;target_port=10" \
--device-socket 0-10@tcp://127.0.0.1:10900 \
--device-socket 1-10@tcp://10.3.147.47:10900
"""
# copp_test.${name_test}
#
# ARPTest
# DHCPTest
# DHCPTopoT1Test
# DHCP6Test
# LLDPTest
# BGPTest
# LACPTest
# SNMPTest
# SSHTest
# IP2METest
# DefaultTest
# VlanSubnetTest
# VlanSubnetIPinIPTest
import datetime
import os
import ptf
import signal
import threading
import time
import macsec # noqa F401
import ptf.packet as scapy
import ptf.testutils as testutils
from ptf.base_tests import BaseTest
from ptf import config
class ControlPlaneBaseTest(BaseTest):
MAX_PORTS = 128
PPS_LIMIT = 600
PPS_LIMIT_MIN = PPS_LIMIT * 0.9
PPS_LIMIT_MAX = PPS_LIMIT * 1.3
NO_POLICER_LIMIT = PPS_LIMIT * 1.4
TARGET_PORT = "3" # Historically we have port 3 as a target port
TASK_TIMEOUT = 600 # Wait up to 10 minutes for tasks to complete
DEFAULT_PRE_SEND_INTERVAL_SEC = 1
DEFAULT_SEND_INTERVAL_SEC = 30
DEFAULT_RECEIVE_WAIT_TIME = 3
def __init__(self):
BaseTest.__init__(self)
self.log_fp = open('/tmp/copp.log', 'a')
test_params = testutils.test_params_get()
self.verbose = 'verbose' in test_params and test_params['verbose']
target_port_str = test_params.get('target_port', self.TARGET_PORT)
self.target_port = int(target_port_str)
self.timeout_thr = None
self.myip = test_params.get('myip', None)
self.peerip = test_params.get('peerip', None)
self.vlanip = test_params.get('vlanip', None)
self.loopbackip = test_params.get('loopbackip', None)
self.default_server_send_rate_limit_pps = test_params.get(
'send_rate_limit', 2000)
self.needPreSend = None
self.has_trap = test_params.get('has_trap', True)
self.hw_sku = test_params.get('hw_sku', None)
if (self.hw_sku == "Cisco-8111-O64" or
self.hw_sku == "Cisco-8111-O32" or
self.hw_sku == "Cisco-8111-C32" or
self.hw_sku == "Cisco-8111-O62C2"):
self.PPS_LIMIT_MAX = self.PPS_LIMIT * 1.4
self.asic_type = test_params.get('asic_type', None)
self.platform = test_params.get('platform', None)
self.topo_type = test_params.get('topo_type', None)
self.ip_version = test_params.get('ip_version', None)
def log(self, message, debug=False):
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if (debug and self.verbose) or (not debug):
print(("%s : %s" % (current_time, message)))
self.log_fp.write("%s : %s\n" % (current_time, message))
def setUp(self):
self.dataplane = ptf.dataplane_instance
self.my_mac = {}
self.peer_mac = {}
for port_id, port in list(self.dataplane.ports.items()):
if port_id[0] == 0:
self.my_mac[port_id[1]] = port.mac()
elif port_id[0] == 1:
self.peer_mac[port_id[1]] = port.mac()
else:
assert True
self.dataplane.flush()
if config["log_dir"] is not None:
filename = os.path.join(config["log_dir"], str(self)) + ".pcap"
self.dataplane.start_pcap(filename)
def tearDown(self):
if config["log_dir"] is not None:
self.dataplane.stop_pcap()
self.log_fp.close()
def timeout(self, seconds, message):
def timeout_exception(self, message):
self.log('Timeout is reached: %s' % message)
self.tearDown()
os.kill(os.getpid(), signal.SIGINT)
if self.timeout_thr is None:
self.timeout_thr = threading.Timer(
seconds, timeout_exception, args=(self, message))
self.timeout_thr.start()
else:
raise Exception("Timeout already set")
def cancel_timeout(self):
if self.timeout_thr is not None:
self.timeout_thr.cancel()
self.timeout_thr = None
def copp_test(self, packet, send_intf, recv_intf):
'''
Pre-send some packets for a second to absorb the CBS capacity.
'''
if self.needPreSend:
pre_send_count = 0
end_time = datetime.datetime.now(
) + datetime.timedelta(seconds=self.DEFAULT_PRE_SEND_INTERVAL_SEC)
while datetime.datetime.now() < end_time:
testutils.send_packet(self, send_intf, packet)
pre_send_count += 1
rcv_pkt_cnt = testutils.count_matched_packets_all_ports(
self, packet, [recv_intf[1]], recv_intf[0], timeout=5)
self.log("Send %d and receive %d packets in the first second (PolicyTest)" % (
pre_send_count, rcv_pkt_cnt))
pre_test_ptf_tx_counter = self.dataplane.get_counters(*send_intf)
pre_test_ptf_rx_counter = self.dataplane.get_counters(*recv_intf)
pre_test_nn_tx_counter = self.dataplane.get_nn_counters(*send_intf)
pre_test_nn_rx_counter = self.dataplane.get_nn_counters(*recv_intf)
start_time = datetime.datetime.now()
end_time = datetime.datetime.now(
) + datetime.timedelta(seconds=self.DEFAULT_SEND_INTERVAL_SEC)
send_count = 0
self.dataplane.flush()
while datetime.datetime.now() < end_time:
testutils.send_packet(self, send_intf, packet)
send_count += 1
# Depending on the server/platform combination it is possible for the server to
# overwhelm the DUT, so we add an artificial delay here to rate-limit the server.
time.sleep(1.0 / float(self.default_server_send_rate_limit_pps))
self.log("Sent out %d packets in %ds" %
(send_count, self.DEFAULT_SEND_INTERVAL_SEC))
# Wait a little bit for all the packets to make it through
time.sleep(self.DEFAULT_RECEIVE_WAIT_TIME)
recv_count = testutils.count_matched_packets_all_ports(
self, packet, [recv_intf[1]], recv_intf[0], timeout=10)
self.log("Received %d packets after sleep %ds" %
(recv_count, self.DEFAULT_RECEIVE_WAIT_TIME))
post_test_ptf_tx_counter = self.dataplane.get_counters(*send_intf)
post_test_ptf_rx_counter = self.dataplane.get_counters(*recv_intf)
post_test_nn_tx_counter = self.dataplane.get_nn_counters(*send_intf)
post_test_nn_rx_counter = self.dataplane.get_nn_counters(*recv_intf)
ptf_tx_count = int(
post_test_ptf_tx_counter[1] - pre_test_ptf_tx_counter[1])
nn_tx_count = int(
post_test_nn_tx_counter[1] - pre_test_nn_tx_counter[1])
ptf_rx_count = int(
post_test_ptf_rx_counter[0] - pre_test_ptf_rx_counter[0])
nn_rx_count = int(
post_test_nn_rx_counter[0] - pre_test_nn_rx_counter[0])
self.log("", True)
self.log("Counters before the test:", True)
self.log("If counter (0, n): %s" % str(pre_test_ptf_tx_counter), True)
self.log("NN counter (0, n): %s" % str(pre_test_nn_tx_counter), True)
self.log("If counter (1, n): %s" % str(pre_test_ptf_rx_counter), True)
self.log("NN counter (1, n): %s" % str(pre_test_nn_rx_counter), True)
self.log("", True)
self.log("Counters after the test:", True)
self.log("If counter (0, n): %s" % str(post_test_ptf_tx_counter), True)
self.log("NN counter (0, n): %s" % str(post_test_nn_tx_counter), True)
self.log("If counter (1, n): %s" % str(post_test_ptf_rx_counter), True)
self.log("NN counter (1, n): %s" % str(post_test_nn_rx_counter), True)
self.log("")
self.log("Sent through NN to local ptf_nn_agent: %d" % ptf_tx_count)
self.log("Sent through If to remote ptf_nn_agent: %d" % nn_tx_count)
self.log("Recv from If on remote ptf_nn_agent: %d" % ptf_rx_count)
self.log("Recv from NN on from remote ptf_nn_agent: %d" % nn_rx_count)
time_delta = end_time - start_time
time_delta_ms = (time_delta.microseconds +
time_delta.seconds * 10**6) / 1000
tx_pps = int(send_count / (float(time_delta_ms) / 1000))
rx_pps = int(recv_count / (float(time_delta_ms) / 1000))
return send_count, recv_count, time_delta, time_delta_ms, tx_pps, rx_pps
def construct_packet(self, port_number):
raise NotImplementedError
def check_constraints(self, send_count, recv_count, time_delta_ms, rx_pps):
raise NotImplementedError
def one_port_test(self, port_number):
packet = self.construct_packet(port_number)
send_count, recv_count, time_delta, time_delta_ms, tx_pps, rx_pps = \
self.copp_test(bytes(packet), (0, port_number), (1, port_number))
self.printStats(send_count, recv_count, time_delta, tx_pps, rx_pps)
self.check_constraints(send_count, recv_count, time_delta_ms, rx_pps)
# FIXME: better make it decorator
def run_suite(self):
self.timeout(
self.TASK_TIMEOUT, "The test case hasn't been completed in %d seconds" % self.TASK_TIMEOUT)
self.one_port_test(self.target_port)
self.cancel_timeout()
def printStats(self, pkt_send_count, recv_count, time_delta, tx_pps, rx_pps):
self.log("")
self.log('test stats')
self.log('Packet sent = %10d' % pkt_send_count)
self.log('Packet rcvd = %10d' % recv_count)
self.log('Test time = %s' % str(time_delta))
self.log('TX PPS = %d' % tx_pps)
self.log('RX PPS = %d' % rx_pps)
class PolicyTest(ControlPlaneBaseTest):
def __init__(self):
ControlPlaneBaseTest.__init__(self)
self.needPreSend = True
def check_constraints(self, send_count, recv_count, time_delta_ms, rx_pps):
self.log("")
if self.has_trap:
self.log("Checking constraints (PolicyApplied):")
self.log(
"PPS_LIMIT_MIN (%d) <= rx_pps (%d) <= PPS_LIMIT_MAX (%d): %s" %
(int(self.PPS_LIMIT_MIN),
int(rx_pps),
int(self.PPS_LIMIT_MAX),
str(self.PPS_LIMIT_MIN <= rx_pps <= self.PPS_LIMIT_MAX))
)
assert self.PPS_LIMIT_MIN <= rx_pps <= self.PPS_LIMIT_MAX, "Copp policer constraint check failed, " \
"Actual PPS: {} Expected PPS range: {} - {}".format(rx_pps, self.PPS_LIMIT_MIN, self.PPS_LIMIT_MAX)
else:
self.log("Checking constraints (NoPolicyApplied):")
self.log(
"rx_pps (%d) <= PPS_LIMIT_MIN (%d): %s" %
(int(rx_pps),
int(self.PPS_LIMIT_MIN),
str(rx_pps <= self.PPS_LIMIT_MIN))
)
assert rx_pps <= self.PPS_LIMIT_MIN, "Copp policer constraint check failed, Actual PPS: {} " \
"Expected PPS range: 0 - {}".format(rx_pps, self.PPS_LIMIT_MIN)
# SONIC config contains policer CIR=600 for ARP
class ARPTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("ARPTest")
self.run_suite()
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
src_ip = self.myip
dst_ip = self.peerip
packet = testutils.simple_arp_packet(
eth_dst='ff:ff:ff:ff:ff:ff',
eth_src=src_mac,
arp_op=1,
ip_snd=src_ip,
ip_tgt=dst_ip,
hw_snd=src_mac,
hw_tgt='ff:ff:ff:ff:ff:ff'
)
return packet
# SONIC configuration has no packets to CPU for DHCP-T1 Topo
class DHCPTopoT1Test(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
# T1 DHCP no packet to packet to CPU so police rate is 0
self.PPS_LIMIT_MIN = 0
self.PPS_LIMIT_MAX = 0
def runTest(self):
self.log("DHCPTopoT1Test")
self.run_suite()
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
packet = testutils.simple_udp_packet(
pktlen=100,
eth_dst='ff:ff:ff:ff:ff:ff',
eth_src=src_mac,
dl_vlan_enable=False,
vlan_vid=0,
vlan_pcp=0,
dl_vlan_cfi=0,
ip_src='0.0.0.0',
ip_dst='255.255.255.255',
ip_tos=0,
ip_ttl=64,
udp_sport=68,
udp_dport=67,
ip_ihl=None,
ip_options=False,
with_udp_chksum=True
)
return packet
# SONIC config contains policer CIR=100 for DHCP
class DHCPTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
# Marvell based platforms have cir/cbs in steps of 125
if self.hw_sku in {"Nokia-M0-7215", "Nokia-7215", "Nokia-7215-A1"}:
self.PPS_LIMIT = 250
# Cisco G100 based platform has CIR 600
elif self.asic_type == "cisco-8000" and "8111" in self.platform:
self.PPS_LIMIT = 600
elif self.asic_type == "cisco-8000":
self.PPS_LIMIT = 400
# M0 devices have CIR of 300 for DHCP
elif self.topo_type in {"m0", "mx"}:
self.PPS_LIMIT = 300
else:
self.PPS_LIMIT = 100
self.PPS_LIMIT_MIN = self.PPS_LIMIT * 0.9
self.PPS_LIMIT_MAX = self.PPS_LIMIT * 1.3
def runTest(self):
self.log("DHCPTest")
self.run_suite()
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
packet = testutils.simple_udp_packet(
pktlen=100,
eth_dst='ff:ff:ff:ff:ff:ff',
eth_src=src_mac,
dl_vlan_enable=False,
vlan_vid=0,
vlan_pcp=0,
dl_vlan_cfi=0,
ip_src='0.0.0.0',
ip_dst='255.255.255.255',
ip_tos=0,
ip_ttl=64,
udp_sport=68,
udp_dport=67,
ip_ihl=None,
ip_options=False,
with_udp_chksum=True
)
return packet
# SONIC config contains policer CIR=100 for DHCPv6
class DHCP6Test(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
# Marvell based platforms have cir/cbs in steps of 125
if self.hw_sku in {"Nokia-M0-7215", "Nokia-7215", "Nokia-7215-A1"}:
self.PPS_LIMIT = 250
# Cisco G100 based platform has CIR 600
elif self.asic_type == "cisco-8000" and "8111" in self.platform:
self.PPS_LIMIT = 600
elif self.asic_type == "cisco-8000":
self.PPS_LIMIT = 400
# M0 devices have CIR of 300 for DHCP
elif self.topo_type in {"m0", "mx"}:
self.PPS_LIMIT = 300
else:
self.PPS_LIMIT = 100
self.PPS_LIMIT_MIN = self.PPS_LIMIT * 0.9
self.PPS_LIMIT_MAX = self.PPS_LIMIT * 1.3
def runTest(self):
self.log("DHCP6Test")
self.run_suite()
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
packet = testutils.simple_udpv6_packet(
pktlen=100,
eth_dst='33:33:00:01:00:02',
eth_src=src_mac,
ipv6_src='::1',
ipv6_dst='ff02::1:2',
udp_sport=546,
udp_dport=547
)
return packet
# SONIC configuration has no packets to CPU for DHCPv6-T1 Topo
class DHCP6TopoT1Test(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
# T1 DHCP6 no packet to packet to CPU so police rate is 0
self.PPS_LIMIT_MIN = 0
self.PPS_LIMIT_MAX = 0
def runTest(self):
self.log("DHCP6TopoT1Test")
self.run_suite()
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
packet = testutils.simple_udpv6_packet(
pktlen=100,
eth_dst='33:33:00:01:00:02',
eth_src=src_mac,
ipv6_src='::1',
ipv6_dst='ff02::1:2',
udp_sport=546,
udp_dport=547
)
return packet
# SONIC config contains policer CIR=100 for LLDP
class LLDPTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
# Marvell based platforms have cir/cbs in steps of 125
if self.hw_sku in {"Nokia-M0-7215", "Nokia-7215", "Nokia-7215-A1"}:
self.PPS_LIMIT = 250
# Cisco G100 based platform has CIR 600
elif self.asic_type == "cisco-8000" and "8111" in self.platform:
self.PPS_LIMIT = 600
elif self.asic_type == "cisco-8000":
self.PPS_LIMIT = 400
# M0 devices have CIR of 300 for DHCP
elif self.topo_type in {"m0", "mx"}:
self.PPS_LIMIT = 300
else:
self.PPS_LIMIT = 100
self.PPS_LIMIT_MIN = self.PPS_LIMIT * 0.9
self.PPS_LIMIT_MAX = self.PPS_LIMIT * 1.3
def runTest(self):
self.log("LLDPTest")
self.run_suite()
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
packet = testutils.simple_eth_packet(
eth_dst='01:80:c2:00:00:0e',
eth_src=src_mac,
eth_type=0x88cc
)
return packet
# SONIC config contains policer CIR=100 for UDLD
class UDLDTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
# Marvell based platforms have cir/cbs in steps of 125
if self.hw_sku in {"Nokia-M0-7215", "Nokia-7215", "Nokia-7215-A1"}:
self.PPS_LIMIT = 250
# Cisco G100 based platform has CIR 600
elif self.asic_type == "cisco-8000" and "8111" in self.platform:
self.PPS_LIMIT = 600
elif self.asic_type == "cisco-8000":
self.PPS_LIMIT = 400
# M0 devices have CIR of 300 for DHCP
elif self.topo_type in {"m0", "mx"}:
self.PPS_LIMIT = 300
else:
self.PPS_LIMIT = 100
self.PPS_LIMIT_MIN = self.PPS_LIMIT * 0.9
self.PPS_LIMIT_MAX = self.PPS_LIMIT * 1.3
def runTest(self):
self.log("UDLDTest")
self.run_suite()
# UDLD uses Ethernet multicast address 01-00-0c-cc-cc-cc
# as its destination MAC address. eth_type is to indicate
# the length of the data in Ethernet 802.3 frame. pktlen
# = 117 = 103 (0x67) + 6 (dst MAC) + 6 (dst MAC) + 2 (len)
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
packet = testutils.simple_eth_packet(
pktlen=117,
eth_dst='01:00:0c:cc:cc:cc',
eth_src=src_mac,
eth_type=0x0067
)
return packet
# SONIC config contains policer CIR=6000 for BGP
class BGPTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("BGPTest")
self.run_suite()
def construct_packet(self, port_number):
dst_mac = self.peer_mac[port_number]
dst_ip = self.peerip
packet = testutils.simple_tcp_packet(
eth_dst=dst_mac,
ip_dst=dst_ip,
ip_ttl=1,
tcp_dport=179
)
return packet
def check_constraints(self, send_count, recv_count, time_delta_ms, rx_pps):
self.log("")
if self.has_trap:
self.log("Checking constraints (PolicyApplied):")
self.log(
"PPS_LIMIT_MIN (%d) <= rx_pps (%d) <= PPS_LIMIT_MAX (%d): %s" %
(int(self.PPS_LIMIT_MIN),
int(rx_pps),
int(self.PPS_LIMIT_MAX),
str(self.PPS_LIMIT_MIN <= rx_pps <= self.PPS_LIMIT_MAX))
)
assert self.PPS_LIMIT_MIN <= rx_pps <= self.PPS_LIMIT_MAX, "Copp policer constraint check failed, " \
"Actual PPS: {} Expected PPS range: {} - {}".format(rx_pps, self.PPS_LIMIT_MIN, self.PPS_LIMIT_MAX)
elif self.asic_type not in ['broadcom']:
self.log("Checking constraints (NoPolicyApplied):")
self.log(
"rx_pps (%d) <= PPS_LIMIT_MIN (%d): %s" %
(int(rx_pps),
int(self.PPS_LIMIT_MIN),
str(rx_pps <= self.PPS_LIMIT_MIN))
)
assert rx_pps <= self.PPS_LIMIT_MIN, "Copp policer constraint check failed, Actual PPS: {} " \
"Expected PPS range: 0 - {}".format(rx_pps, self.PPS_LIMIT_MIN)
else:
self.log("Checking constraints (DefaultPolicyApplied):")
self.log(
"PPS_LIMIT_MIN (%d) <= rx_pps (%d) <= PPS_LIMIT_MAX (%d): %s" %
(int(self.PPS_LIMIT_MIN),
int(rx_pps),
int(self.PPS_LIMIT_MAX),
str(self.PPS_LIMIT_MIN <= rx_pps <= self.PPS_LIMIT_MAX))
)
assert self.PPS_LIMIT_MIN <= rx_pps <= self.PPS_LIMIT_MAX, "Copp policer constraint " \
"check failed, Actual PPS: {} Expected PPS range: {} - {}".format(
rx_pps, self.PPS_LIMIT_MIN, self.PPS_LIMIT_MAX)
# SONIC config contains policer CIR=6000 for LACP
class LACPTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("LACPTest")
self.run_suite()
def construct_packet(self, port_number):
packet = testutils.simple_eth_packet(
pktlen=14,
eth_dst='01:80:c2:00:00:02',
eth_type=0x8809
) / (chr(0x01)*50)
return packet
# SNMP packets are trapped as IP2ME packets.
# IP2ME configuration in SONIC contains policer CIR=600
class SNMPTest(PolicyTest): # FIXME: trapped as ip2me. mellanox should add support for SNMP trap
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("SNMPTest")
self.run_suite()
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
dst_mac = self.peer_mac[port_number]
dst_ip = self.peerip
packet = testutils.simple_udp_packet(
eth_dst=dst_mac,
ip_dst=dst_ip,
eth_src=src_mac,
udp_dport=161
)
return packet
# SONIC config contains policer CIR=600 for SSH
class SSHTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("SSHTest")
self.run_suite()
def construct_packet(self, port_number):
dst_mac = self.peer_mac[port_number]
src_ip = self.myip
dst_ip = self.peerip
packet = testutils.simple_tcp_packet(
eth_dst=dst_mac,
ip_dst=dst_ip,
ip_src=src_ip,
tcp_flags='F',
tcp_sport=22,
tcp_dport=22
)
return packet
# IP2ME configuration in SONIC contains policer CIR=600
class IP2METest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("IP2METest")
self.run_suite()
def one_port_test(self, port_number):
for port in self.dataplane.ports.keys():
if port[0] == 0:
continue
packet = self.construct_packet(port[1])
send_count, recv_count, time_delta, time_delta_ms, tx_pps, rx_pps = \
self.copp_test(bytes(packet), (0, port_number), (1, port_number))
self.printStats(send_count, recv_count, time_delta, tx_pps, rx_pps)
self.check_constraints(
send_count, recv_count, time_delta_ms, rx_pps)
def construct_packet(self, port_number):
src_mac = self.my_mac[port_number]
dst_mac = self.peer_mac[port_number]
dst_ip = self.peerip
packet = testutils.simple_tcp_packet(
eth_src=src_mac,
eth_dst=dst_mac,
ip_dst=dst_ip
)
return packet
# Verify policer functionality for TTL 1 packets
class DefaultTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("DefaultTest")
self.run_suite()
def construct_packet(self, port_number):
dst_mac = self.peer_mac[port_number]
src_ip = self.myip
dst_ip = self.peerip
packet = testutils.simple_tcp_packet(
eth_dst=dst_mac,
ip_dst=dst_ip,
ip_src=src_ip,
tcp_sport=10000,
tcp_dport=10000,
ip_ttl=1
)
return packet
# Verify policer functionality for Vlan subnet packets
class VlanSubnetTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("VlanSubnetTest")
self.run_suite()
def construct_packet(self, port_number):
dst_mac = self.peer_mac[port_number]
src_ip = self.myip
dst_ip = self.vlanip
if self.ip_version == "4":
packet = testutils.simple_tcp_packet(
eth_dst=dst_mac,
ip_dst=dst_ip,
ip_src=src_ip,
ip_ttl=25,
tcp_sport=5000,
tcp_dport=8000
)
else:
packet = testutils.simple_tcpv6_packet(
eth_dst=dst_mac,
ipv6_dst=dst_ip,
ipv6_src=src_ip,
ipv6_hlim=25,
tcp_sport=5000,
tcp_dport=8000
)
return packet
# Verify policer functionality for Vlan subnet IPinIP packets
class VlanSubnetIPinIPTest(PolicyTest):
def __init__(self):
PolicyTest.__init__(self)
def runTest(self):
self.log("VlanSubnetIpinIPTest")
self.run_suite()
def construct_packet(self, port_number):
dst_mac = self.peer_mac[port_number]
inner_src_ip = self.myip
inner_dst_ip = self.vlanip
outer_dst_ip = self.loopbackip
if self.ip_version == "4":
inner_packet = testutils.simple_tcp_packet(
ip_dst=inner_dst_ip,
ip_src=inner_src_ip,
ip_ttl=25,
tcp_sport=5000,
tcp_dport=8000
).getlayer(scapy.IP)
else:
inner_packet = testutils.simple_tcpv6_packet(
ipv6_dst=inner_dst_ip,
ipv6_src=inner_src_ip,
ipv6_hlim=25,
tcp_sport=5000,
tcp_dport=8000
).getlayer(scapy.IPv6)
packet = testutils.simple_ipv4ip_packet(
eth_dst=dst_mac,
ip_src='1.1.1.1',
ip_dst=outer_dst_ip,
ip_ttl=40,
inner_frame=inner_packet
)
return packet