summaryrefslogtreecommitdiff
path: root/tests/TestSuite_kni.py
blob: 69a20fecd7c0a3b84cd8c7972d80c19edad81e94 (plain)
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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
# <COPYRIGHT_TAG>
# BSD LICENSE
#
# Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in
#     the documentation and/or other materials provided with the
#     distribution.
#   * Neither the name of Intel Corporation nor the names of its
#     contributors may be used to endorse or promote products derived
#     from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
DPDK Test suite.

Test Kernel NIC Interface.
"""

import dts
import re
import time
from random import randint

dut_ports = []
port_virtual_interaces = []

ports_without_kni = 2
flows_without_kni = 2

packet_sizes_loopback = [64, 256]
packet_sizes_routing = [64, 256]

ports_cores_template = '\(P([0123]),(C\{\d.\d.\d\}),(C\{\d.\d.\d\}),(C\{\d.\d.\d\}),?(C\{\d.\d.\d\})?\),?'

default_1_port_cores_config = '(P0,C{1.0.0},C{1.1.0},C{1.0.1})'
default_2_port_cores_config = '(P0,C{1.0.0},C{1.1.0},C{1.0.1}),(P1,C{1.2.0},C{1.3.0},C{1.2.1})'

stress_test_iterations = 50
stress_test_random_iterations = 50

routing_performance_steps = [
    {'kthread_mode': 'single', 'config': '(P0,C{1.0.0},C{1.1.0},C{1.0.1})'},
    {'kthread_mode': 'single', 'config': '(P0,C{1.0.0},C{1.0.1},C{1.1.0})'},
    {'kthread_mode': 'single', 'config': '(P0,C{1.0.0},C{1.1.0},C{1.2.0})'},

    {'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.0.1})'},
    {'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.4.0})'},
    {'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.2.0})'},
    {'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.0.1})'},
    {'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.4.0})'},
    {'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.2.0})'},

    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1})'},
    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.3.0})'},
    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0})'},
    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1})'},
    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.3.0})'},
    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0})'},

    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1},C{1.2.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1},C{1.2.1})'},
    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.1.1},C{1.5.0})'},
    {'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0},C{1.6.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0},C{1.7.0})'}
]

bridge_performance_steps = [
    {'flows': 1, 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.0.1})'},
    {'flows': 1, 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.4.0})'},
    {'flows': 1, 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.2.0})'},
    {'flows': 2, 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.0.1})'},
    {'flows': 2, 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.4.0})'},
    {'flows': 2, 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.2.0})'},

    {'flows': 1, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1})'},
    {'flows': 1, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.3.0})'},
    {'flows': 1, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0})'},
    {'flows': 2, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1})'},
    {'flows': 2, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.3.0})'},
    {'flows': 2, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0})'},

    {'flows': 1, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1},C{1.2.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1},C{1.2.1})'},
    {'flows': 1, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.1.1},C{1.5.0})'},
    {'flows': 1, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0},C{1.6.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0},C{1.7.0})'},
    {'flows': 2, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1},C{1.2.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1},C{1.2.1})'},
    {'flows': 2, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.1.1},C{1.5.0})'},
    {'flows': 2, 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0},C{1.6.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0},C{1.7.0})'}
]

loopback_performance_steps = [
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'single',
        'config': '(P0,C{1.0.0},C{1.1.0},C{1.0.1})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'single',
        'config': '(P0,C{1.0.0},C{1.0.1},C{1.1.0})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'single',
        'config': '(P0,C{1.0.0},C{1.1.0},C{1.2.0})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.0.1})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.4.0})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.2.0})'},

    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple',
        'config': '(P0,C{1.0.0},C{1.1.0},C{1.0.1})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple',
        'config': '(P0,C{1.0.0},C{1.0.1},C{1.1.0})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple',
        'config': '(P0,C{1.0.0},C{1.1.0},C{1.2.0})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.3.0})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0})'},

    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1},C{1.2.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1},C{1.3.1})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.1.1},C{1.5.0})'},
    {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0},C{1.6.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0},C{1.7.0})'},

    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode':
        'single', 'config': '(P0,C{1.0.0},C{1.1.0},C{1.0.1})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode':
        'single', 'config': '(P0,C{1.0.0},C{1.0.1},C{1.1.0})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode':
        'single', 'config': '(P0,C{1.0.0},C{1.1.0},C{1.2.0})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.0.1})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.4.0})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': 'single', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.2.0})'},

    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode':
        'multiple', 'config': '(P0,C{1.0.0},C{1.1.0},C{1.0.1})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode':
        'multiple', 'config': '(P0,C{1.0.0},C{1.0.1},C{1.1.0})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode':
        'multiple', 'config': '(P0,C{1.0.0},C{1.1.0},C{1.2.0})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.0.1}),(P1,C{1.1.0},C{1.3.0},C{1.1.1})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.0.1},C{1.2.0}),(P1,C{1.1.0},C{1.1.1},C{1.3.0})'},
    {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': 'multiple', 'config':
        '(P0,C{1.0.0},C{1.2.0},C{1.4.0}),(P1,C{1.1.0},C{1.3.0},C{1.5.0})'}
]

loopback_perf_results_header = ['lo_mode', 'kthread_mode', 'Ports', 'Config']
bridge_perf_results_header = ['kthread_mode', 'Flows', 'Config', '64 Mpps']
bridge_perf_no_kni_results_header = ['Flows', '64 Mpps']
routing_perf_results_header = ['kthread_mode', 'Ports', 'Config']
routing_perf_no_kni_results_header = ['Ports']

stress_modes_output = [{'lo_mode': None, 'kthread_mode': None,
                        'output': 'loopback disabled.*DPDK kni module loaded.*Single kernel thread'},
                       {'lo_mode': 'lo_mode_none', 'kthread_mode': None,
                        'output': 'loopback disabled.*DPDK kni module loaded.*Single kernel thread'},
                       {'lo_mode': 'lo_mode_fifo', 'kthread_mode': None,
                        'output': 'loopback mode=lo_mode_fifo enabled.*Single kernel thread'},
                       {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': None,
                        'output': 'loopback mode=lo_mode_fifo_skb enabled.*Single kernel thread'},
                       {'lo_mode': 'lo_mode_random', 'kthread_mode': None,
                        'output': 'Incognizant parameter, loopback disabled.*DPDK kni module loaded.*Single kernel thread'},
                       {'lo_mode': None, 'kthread_mode': 'single',
                        'output': 'loopback disabled.*DPDK kni module loaded.*Single kernel thread'},
                       {'lo_mode': None, 'kthread_mode': 'multiple',
                        'output': 'loopback disabled.*DPDK kni module loaded.*Multiple kernel thread'},
                       {'lo_mode': None, 'kthread_mode': 'singlemulti',
                        'output': 'KNI.* Invalid parameter for kthread_mode'},
                       {'lo_mode': 'lo_mode_fifo', 'kthread_mode': 'multiple',
                        'output': 'loopback mode=lo_mode_fifo enabled.*Multiple kernel thread'},
                       {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': 'multiple',
                        'output': 'loopback mode=lo_mode_fifo_skb enabled.*Multiple kernel thread'},
                       {'lo_mode': 'lo_mode_fifo_skb', 'kthread_mode': 'singlemulti',
                        'output': 'Invalid parameter for kthread_mode'},
                       {'lo_mode': 'lo_mode_random', 'kthread_mode': 'multiple',
                        'output': 'KNI.* Incognizant parameter, loopback disabled'}
                       ]


from test_case import TestCase

#
#
# Test class.
#


class TestKni(TestCase):

    #
    #
    # Utility methods and other non-test code.
    #
    # Insert or move non-test functions here.

    def set_up_all(self):
        """
        Run at the start of each test suite.

        KNI Prerequisites
        """
        out = self.dut.send_expect("which brctl", "# ")
        self.verify('no brctl' not in out,
                    "The linux tool brctl is needed to run this test suite")

        out = self.dut.send_expect("make -C ./examples/kni/", "# ", 5)
        self.verify('Error' not in out, "Compilation failed")

        self.extract_ports_cores_config(default_1_port_cores_config)
        out = self.start_kni()
        self.verify("Error" not in out, "Error found during kni start")

        self.dut.send_expect("service iptables stop", "# ")
        self.dut.send_expect("service firewalld stop", "# ")

    def set_up(self):
        """
        Run before each test case.
        """
        pass

    def start_kni(self, lo_mode=None, kthread_mode=None):
        """
        Insert the igb_uio and rte_kni modules with passed parameters and launch
        kni application.
        """
        module_param = ""
        if lo_mode is not None:
            module_param += "lo_mode=%s " % lo_mode

        if kthread_mode is not None:
            module_param += "kthread_mode=%s" % kthread_mode
        self.dut.kill_all()
        out = self.dut.send_expect("rmmod rte_kni", "# ", 10)
        self.verify("in use" not in out, "Error unloading KNI module: " + out)
        if dts.drivername == "igb_uio":
            self.dut.send_expect("rmmod igb_uio", "# ", 5)
            self.dut.send_expect(
                'insmod ./%s/kmod/igb_uio.ko' % (self.target), "# ", 20)
        self.dut.bind_interfaces_linux()
        out = self.dut.send_expect(
            'insmod ./%s/kmod/rte_kni.ko %s' % (self.target, module_param), "# ", 10)

        self.verify("Error" not in out, "Error loading KNI module: " + out)

        port_mask = dts.create_mask(self.config['ports'])
        core_mask = dts.create_mask(
            self.config['rx_cores'] + self.config['tx_cores'] + self.config['kernel_cores'])

        config_param = self.build_config_param()

        out_kni = self.dut.send_expect(
            './examples/kni/build/app/kni -c %s -n %d -- -P -p %s %s &' %
            (core_mask, self.dut.get_memory_channels(), port_mask, config_param),
            "APP: Lcore [0-9]+ is reading from port [0-9]+", 20)

        time.sleep(5)
        if kthread_mode == 'single':
            kthread_mask = dts.create_mask(self.config['kernel_cores'])
            out = self.dut.send_expect(
                "taskset -p %s `pgrep -fl kni_single | awk '{print $1}'`" % kthread_mask, "#")
            self.verify(
                'new affinity mask' in out, 'Unable to set core affinity')

        return out_kni

    def extract_ports_cores_config(self, ports_cores_config):
        """
        Parses a ports/cores configuration string into the 'self.config' variable.
        """
        ports_cores_pattern = re.compile(ports_cores_template)
        port_configs = ports_cores_pattern.findall(ports_cores_config)
        dut_ports = self.dut.get_ports(self.nic)

        config = {}
        ports = []
        rx_cores = []
        tx_cores = []
        k_cores = []
        port_details = []
        for port_config in port_configs:
            details = {}

            port_number = int(port_config[0])
            self.verify(
                port_number < len(dut_ports), "Not enough ports available")

            ports.append(dut_ports[port_number])
            details['port'] = dut_ports[port_number]
            rx_cores.append(self.dut.get_lcore_id(port_config[1]))
            details['rx_core'] = self.dut.get_lcore_id(port_config[1])
            tx_cores.append(self.dut.get_lcore_id(port_config[2]))
            details['tx_core'] = self.dut.get_lcore_id(port_config[2])

            details['kernel_cores'] = []
            for k_core in port_config[3:]:
                if k_core != '':
                    k_cores.append(self.dut.get_lcore_id(k_core))
                    details['kernel_cores'].append(
                        self.dut.get_lcore_id(k_core))

            port_details.append(details)

        config['ports'] = ports
        config['rx_cores'] = rx_cores
        config['tx_cores'] = tx_cores
        config['kernel_cores'] = k_cores
        config['port_details'] = port_details

        self.config = config

    def build_config_param(self):
        """
        Formats the '--conf=(xxx)' parameter for kni application calls
        """
        config_param = '--config="%s'
        port_cores = '(%s,%s,%s)'
        port_cores_kernel = '(%s,%s,%s,'

        for port in self.config['port_details']:

            # Kernel threads specified
            if len(port['kernel_cores']) > 0:

                port_config = port_cores_kernel % (port['port'],
                                                   port['rx_core'],
                                                   port['tx_core'])

                for core in port['kernel_cores']:
                    port_config += str(core) + ','

                port_config = port_config[:-1] + ')'

            # No kernel threads specified
            else:
                port_config = port_cores % (port['port'],
                                            port['rx_core'],
                                            port['tx_core'])

            config_param = config_param % port_config + ',%s'

        config_param = config_param.replace(',%s', '"')

        return config_param

    def stripped_config_param(self):
        """
        Removes the '--config=' prefix from the config string.
        Used for reporting.
        """
        config_param = self.build_config_param()
        config_param = config_param.replace('--config="', '')
        config_param = config_param.replace('"', '')
        return config_param

    def virtual_interface_name(self, port, sub_port=0):
        """
        Given a port and subport name, formats the virtual interface name.
        """
        return 'vEth%d_%d' % (port, sub_port)

    def dut_physical_cores(self):
        """
        Returns the number of physical cores in socket 0.
        """
        dut_cores = self.dut.get_all_cores()

        first_core = dut_cores[0]
        cores = []

        for core in dut_cores[1:]:
            if core['core'] not in cores and \
                    core['socket'] == first_core['socket']:
                cores.append(core['core'])

        return len(cores)

    def make_white_list(self, target, nic):
        """
        Create white list with ports.
        """
        white_list = []
        dut_ports = self.dut.get_ports(self.nic)
        self.dut.restore_interfaces()
        allPort = self.dut.ports_info
        if dts.drivername in ["igb_uio"]:
            self.dut.send_expect(
                "insmod ./" + self.target + "/kmod/igb_uio.ko", "#")
        for port in range(0, len(allPort)):
            if port in dut_ports:
                white_list.append(allPort[port]['pci'])
        return white_list

    #
    #
    #
    # Test cases.
    #

    def test_ifconfig(self):
        """
        Ifconfig support KNI.
        """

        # Ports and cores configuration set in set_up_all function
        # Check that all virtual interfaces support ifconfig calls.
        out = self.dut.send_expect("ifconfig -a", "# ")
        for port in self.config['ports']:
            virtual_interface = self.virtual_interface_name(port)
            self.verify(
                virtual_interface in out, "ifconfig not supported for %s" % virtual_interface)

        # For each virtual interface perform the following operations
        for port in self.config['ports']:
            virtual_interface = self.virtual_interface_name(port)

            # Set up
            out = self.dut.send_expect(
                "ifconfig %s up" % virtual_interface, "# ")
            self.verify("Configure network interface of %d up" %
                        port in out, "ifconfig up not supported")

            out = self.dut.send_expect(
                "ip -family inet6 address show dev %s" % virtual_interface, "# ")
            self.verify(
                "inet6 " in out, "ifconfig up the port_virtual_interaces not support")

            # Add an IPv6 address
            out = self.dut.send_expect(
                "ifconfig %s add fe80::%d" % (virtual_interface, port + 1), "# ")
            out = self.dut.send_expect(
                "ip -family inet6 address show dev %s" % virtual_interface, "# ")
            self.verify("inet6 fe80::%d" %
                        (port + 1) in out, "ifconfig add ipv6 address not supported")

            # Delete the IPv6 address
            out = self.dut.send_expect(
                "ifconfig %s del fe80::%d" % (virtual_interface, port + 1), "# ")
            out = self.dut.send_expect(
                "ip -family inet6 address show dev %s" % virtual_interface, "# ")
            self.verify("inet6 fe80::%d/128" %
                        (port + 1) not in out, "ifconfig del ipv6 address not supported")

            # Add an IPv4 address
            out = self.dut.send_expect(
                "ifconfig %s 192.168.%d.1 netmask 255.255.255.192" % (virtual_interface, port), "# ")
            out = self.dut.send_expect(
                "ip -family inet address show dev %s" % virtual_interface, "# ")
            self.verify("inet 192.168.%d.1/26" %
                        port in out, "ifconfig set ip address not supported")

            # Set the MTU
            out = self.dut.send_expect(
                "ifconfig %s mtu 1300" % virtual_interface, "# ")
            out = self.dut.send_expect(
                "ip link show %s" % virtual_interface, "# ")
            self.verify("mtu 1300" in out, "mtu setup not supported")

            # Bring down
            self.dut.send_expect("ifconfig %s down" % virtual_interface, "# ")
            out = self.dut.send_expect(
                "ip -family inet6 address show dev %s" % virtual_interface, "# ")
            self.verify("inet6 addr" not in out, "ifconfig down not supported")

    def test_ping(self):
        """
        Ping support KNI.
        """

        # Ports and cores configuration set in set_up_all function
        # Setup IP address on virtual interfaces and tester ports
        self.dut.kill_all()
        self.start_kni()
        for port in self.config['ports']:
            virtual_interface = self.virtual_interface_name(port)

            tx_port = self.tester.get_local_port(port)
            tx_interface = self.tester.get_interface(tx_port)
            out = self.dut.send_expect(
                "ifconfig %s up" % virtual_interface, "# ")
            time.sleep(5)
            self.dut.send_expect(
                 "ifconfig %s 192.168.%d.1 netmask 255.255.255.192" % (virtual_interface, port), "# ")
            self.tester.send_expect(
                 "ifconfig %s 192.168.%d.2 netmask 255.255.255.192" % (tx_interface, port), "# ")
            self.tester.enable_ipv6(tx_interface)
            time.sleep(5)
        # Send ping requests and check for answers
        for port in self.config['ports']:

            tx_port = self.tester.get_local_port(port)
            tx_interface = self.tester.get_interface(tx_port)

            virtual_interface = self.virtual_interface_name(port)

            out = self.dut.send_expect(
                "ping -w 2 -I %s 192.168.%d.1" % (virtual_interface, port), "# ", 10)
            self.verify("64 bytes from 192.168.%d.1:" %
                        port in out, "ping not supported")

            out = self.dut.send_expect(
                "ping -w 2 -I %s 192.168.%d.2" % (virtual_interface, port), "# ", 10)
            self.verify("64 bytes from 192.168.%d.2:" %
                        port in out, "ping not supported")

            out = self.tester.send_expect(
                "ping -w 1 -I %s 192.168.%d.1" % (tx_interface, port), "# ", 10)
            self.verify("64 bytes from 192.168.%d.1:" %
                        port in out, "kni cannot reply ping packet")

            out = self.dut.send_expect(
                "ping -w 1 -I %s 192.168.%d.123" % (virtual_interface, port), "# ", 10)
            self.verify(
                "0 received, 100% packet loss" in out, "ping not supported")

            out = self.dut.send_expect(
                "ip -family inet6 address show dev %s | awk '/inet6/ { print $2 }'| cut -d'/' -f1" % virtual_interface, "# ", 10)
            ipv6_address = out.split('\r\n')[0]

            out = self.dut.send_expect("ping6 -w 1 -I %s %s" %
                                       (virtual_interface, str(ipv6_address)), "# ", 10)
            self.verify("64 bytes from %s: icmp_seq=1 ttl=64" %
                        ipv6_address in out, "ping6 not supported")

            out = self.tester.send_expect(
                "ping6 -w 1 -I %s %s" % (tx_interface, str(ipv6_address)), "# ", 10)
            self.verify("64 bytes from %s: icmp_seq=1 ttl=64" %
                        ipv6_address in out, "kni cannot reply ping6 packet")

            ipv6list = list(ipv6_address)
            for j in range(10):
                if str(j) == ipv6list[-1]:
                    continue
                else:
                    ipv6list[-1] = str(j)
                    break

            out = self.dut.send_expect("ping6 -w 1 -I %s %s" %
                                       (virtual_interface, ''.join(ipv6list)), "# ", 10)
            self.verify(
                "0 received, 100% packet loss" in out, "ping6 not supported")
            # remove ip from tester
            self.tester.send_expect(
                 "ip addr del 192.168.%d.2 dev %s" % (port, tx_interface), "# ")
          
        for port in self.config['ports']:
            tx_port = self.tester.get_local_port(port)
            tx_interface = self.tester.get_interface(tx_port)
            self.tester.disable_ipv6(tx_interface)
            time.sleep(1)
        
    def test_tcpdump(self):
        """
        Tcpdump support KNI.
        """

        # Ports and cores configuration set in set_up_all function
        self.dut.kill_all()
        self.start_kni()
        for port in self.config['ports']:

            virtual_interface = self.virtual_interface_name(port)

            tx_port = self.tester.get_local_port(port)
            rx_mac = self.dut.get_mac_address(port)
            tx_mac = self.tester.get_mac(tx_port)
            tx_interface = self.tester.get_interface(tx_port)

            self.dut.send_expect("ifconfig %s up" % virtual_interface, "# ")
            time.sleep(5)

            # Start tcpdump with filters for src and dst MAC address, this avoids
            # unwanted broadcast, ICPM6... packets
            out = self.dut.send_expect(
                'tcpdump -i %s -e -w packet.log "ether src %s and ether dst %s"' %
                (virtual_interface, tx_mac, rx_mac),
                "listening on %s" % virtual_interface, 30)

            packets_to_send = [
                'sendp([Ether(src=srcmac,dst=dstmac)/IP()/UDP()/("W"*28)],iface="%s")',
                'sendp([Ether(src=srcmac,dst=dstmac)/IP()/TCP()/("W"*28)],iface="%s")',
                'sendp([Ether(src=srcmac,dst=dstmac)/IP()/ICMP()/("W"*28)],iface="%s")',
                'sendp([Ether(src=srcmac,dst=dstmac)/IP()/("W"*38)],iface="%s")',
                'sendp([Ether(src=srcmac,dst=dstmac)/("W"*46)],iface="%s")'
            ]

            self.tester.scapy_append('dstmac="%s"' % rx_mac)
            self.tester.scapy_append('srcmac="%s"' % tx_mac)

            for packet in packets_to_send:
                self.tester.scapy_append(packet % tx_interface)

            self.tester.scapy_execute()

            out = self.dut.send_expect("^C", "# ", 20)

            self.verify("%d packets captured" % len(packets_to_send) in out,
                        "Wrong number of packets captured")

    def test_ethtool(self):
        """
        Ethtool support KNI.
        """

        # Ports and cores configuration set in set_up_all function
        # For each virtual interface perform the following operations
        for port in self.config['ports']:

            virtual_interface = self.virtual_interface_name(port)

            # Request settings
            out = self.dut.send_expect("ethtool %s" % virtual_interface,
                                       "# ")
            self.verify("Settings for %s" % virtual_interface in out,
                        "ethtool not supported")
            self.verify("Operation not supported" not in out,
                        "ethtool not supported")

            # Request driver information
            out = self.dut.send_expect("ethtool -i %s" % virtual_interface,
                                       "# ")
            self.verify("driver: ixgbe" or "driver: igb" in out,
                        "'ethtool -i' not supported")
            self.verify("Operation not supported" not in out,
                        "'ethtool -i' not supported")

            # Request pause parameters
            out = self.dut.send_expect("ethtool -a %s" % virtual_interface,
                                       "# ")
            self.verify("Pause parameters for %s" % virtual_interface in out,
                        "'ethtool -a' not supported")
            self.verify("Operation not supported" not in out,
                        "ethtool '-a' not supported")

            # Request statistics
            out = self.dut.send_expect("ethtool -S %s" % virtual_interface,
                                       "# ")
            self.verify("NIC statistics" in out,
                        "'ethtool -S' not supported")
            self.verify("Operation not supported" not in out,
                        "ethtool '-S' not supported")

            # Request features status
            out = self.dut.send_expect("ethtool -k %s" % virtual_interface, "# ")
            self.verify(("Features for %s" % virtual_interface in out) or
                        ("Offload parameters for %s" %
                         virtual_interface in out),
                        "'ethtool -k' not supported")
            self.verify("Operation not supported" not in out,
                        "'ethtool -k' not supported")

            # Request ring parameters
            out = self.dut.send_expect("ethtool -g %s" % virtual_interface,
                                       "# ")
            self.verify("Ring parameters for %s" % virtual_interface in out,
                        "'ethtool -g' not supported")
            self.verify("Operation not supported" not in out,
                        "'ethtool -g' not supported")

            # Request coalesce parameters. NOT SUPORTED
            out = self.dut.send_expect("ethtool -c %s" % virtual_interface,
                                       "# ")
            self.verify("Operation not supported" in out,
                        "'ethtool -c' seems to be supported. Check it.")

            # Request register dump
            out = self.dut.send_expect("ethtool -d %s" % virtual_interface,
                                       "# ")
            expectstring = "0x00000: CTRL.*0x00008: STATUS"
            self.verify(len(re.findall(expectstring, out , re.DOTALL)) > 0, "'ethtool -d' not supported")
            self.verify("Operation not supported" not in out,
                        "'ethtool -d' not supported")

            # Request eeprom dump
            out = self.dut.send_expect("ethtool -e %s" % virtual_interface,
                                       "# ")
            self.verify("Offset" and "Values" in out,
                        "'ethtool -e' not support")
            self.verify("Operation not supported" not in out,
                        "'ethtool -e' not support")

    def test_statistics(self):
        """
        KNI Statistics test.
        """
        rx_match = "RX packets.(\d+)"

        self.dut.kill_all()
        self.start_kni(lo_mode='lo_mode_ring_skb')

        # Ports and cores configuration set in set_up_all function
        # For each virtual interface perform the following operations
        for port in self.config['ports']:

            virtual_interface = self.virtual_interface_name(port)

            out = self.dut.send_expect(
                "ifconfig %s up" % virtual_interface, "# ")
            time.sleep(5)
            out = self.dut.send_expect("ifconfig %s" % virtual_interface, "# ")
            m = re.search(rx_match, out)
            previous_rx_packets = int(m.group(1))

            tx_port = self.tester.get_local_port(port)
            rx_mac = self.dut.get_mac_address(port)
            tx_mac = self.tester.get_mac(tx_port)
            tx_interface = self.tester.get_interface(tx_port)

            self.tester.scapy_append('dstmac = "%s"' % rx_mac)
            self.tester.scapy_append('srcmac = "%s"' % tx_mac)

            self.tester.scapy_append(
                'sendp([Ether(src = srcmac,dst=dstmac)/IP()/UDP()/("X"*28)],iface="%s")' % tx_interface)
            self.tester.scapy_append(
                'sendp([Ether(src = srcmac,dst=dstmac)/IP()/TCP()/("X"*28)],iface="%s")' % tx_interface)
            self.tester.scapy_append(
                'sendp([Ether(src = srcmac,dst=dstmac)/IP()/ICMP()/("X"*28)],iface="%s")' % tx_interface)
            self.tester.scapy_append(
                'sendp([Ether(src = srcmac,dst=dstmac)/IP()/("X"*38)],iface="%s")' % tx_interface)
            self.tester.scapy_append(
                'sendp([Ether(src = srcmac,dst=dstmac)/("X"*46)],iface="%s")' % tx_interface)
            self.tester.scapy_execute()

            out = self.dut.send_expect("ifconfig %s" % virtual_interface, "# ")
            m = re.search(rx_match, out)
            rx_packets = int(m.group(1))

            self.verify(rx_packets == (previous_rx_packets + 5),
                        "Rx statistics error in iface %s" % virtual_interface)

        self.dut.kill_all()

    def test_stress(self):
        """
        KNI stress test.
        """
        self.extract_ports_cores_config(default_2_port_cores_config)
        self.dut.send_expect('dmesg -c', "]# ")  # Clean the dmesg ring buffer
        for i in range(stress_test_iterations + stress_test_random_iterations):

            self.dut.kill_all()

            if i < stress_test_iterations:
                step = stress_modes_output[i % len(stress_modes_output)]
            else:
                step = stress_modes_output[
                    randint(0, len(stress_modes_output) - 1)]

            expectedMessage = step['output']

            try:
                out = self.start_kni(step['lo_mode'], step['kthread_mode'])
                self.verify("Error" not in out, "Error found during kni start")
            except:
                # some permutations have to fail
                pass

            out = self.dut.send_expect('dmesg -c | grep "KNI"', "]# ")
            self.verify(len(re.findall(expectedMessage, out, re.DOTALL)) > 0,
                        "Module not properly loaded")

    def test_perf_loopback(self):
        """
        KNI loopback performance
        """
        self.dut.kill_all()

        header = loopback_perf_results_header
        for size in packet_sizes_loopback:
            header.append('%d (pps)' % size)

        dts.results_table_add_header(header)

        # Execute the permutations of the test
        for step in loopback_performance_steps:

            self.extract_ports_cores_config(step['config'])

            total_cores = len(self.config['tx_cores'] + self.config[
                              'rx_cores'] + self.config['kernel_cores'])
            if total_cores > self.dut_physical_cores():
                print dts.RED("Skiping step %s (%d cores needed, got %d)" %
                              (step['config'], total_cores,
                               self.dut_physical_cores())
                              )
                continue

            self.start_kni(
                lo_mode=step['lo_mode'], kthread_mode=step['kthread_mode'])

            pps_results = []

            for size in packet_sizes_loopback:

                payload_size = size - 38

                ports_number = len(self.config['ports'])

                # Set up the flows for the ports
                tgen_input = []
                for port in self.config['ports']:

                    rx_mac = self.dut.get_mac_address(port)
                    tx_port = self.tester.get_local_port(port)
                    self.tester.scapy_append('dstmac = "%s"' % rx_mac)
                    self.tester.scapy_append(
                        'flows = [Ether(dst=dstmac)/IP()/("X"*%d)]' % payload_size)
                    self.tester.scapy_append(
                        'wrpcap("tester%d.pcap",flows)' % tx_port)
                    self.tester.scapy_execute()
                    tgen_input.append(
                        (tx_port, tx_port, "tester%d.pcap" % tx_port))

                time.sleep(1)
                _, pps = self.tester.traffic_generator_throughput(tgen_input)
                pps_results.append(float(pps) / 1000000)

            ports_number = len(self.config['ports'])
            results_row = [step['lo_mode'], step['kthread_mode'], ports_number,
                           self.stripped_config_param()] + pps_results
            dts.results_table_add_row(results_row)

            self.dut.kill_all()

        dts.results_table_print()

    def test_perf_bridge(self):
        """
        KNI performance bridge mode.
        """
        dts.results_table_add_header(bridge_perf_results_header)

        self.tester.scapy_append('srcmac="00:00:00:00:00:01"')
        self.tester.scapy_append(
            'wrpcap("kni.pcap", [Ether(src=srcmac, dst="ff:ff:ff:ff:ff:ff")/IP(len=46)/UDP()/("X"*18)])')
        self.tester.scapy_execute()

        for step in bridge_performance_steps:

            self.extract_ports_cores_config(step['config'])

            total_cores = len(self.config['tx_cores'] + self.config[
                              'rx_cores'] + self.config['kernel_cores'])
            if total_cores > self.dut_physical_cores():
                print dts.RED("Skiping step %s (%d cores needed, got %d)" %
                              (step['config'], total_cores,
                               self.dut_physical_cores())
                              )
                continue

            port_virtual_interaces = []
            for port in self.config['port_details']:
                for i in range(len(port['kernel_cores'])):
                    port_virtual_interaces.append(
                        self.virtual_interface_name(port['port'], i))

            self.dut.kill_all()
            self.start_kni(lo_mode=None, kthread_mode=step['kthread_mode'])

            for virtual_interace in port_virtual_interaces:
                out = self.dut.send_expect(
                    "ifconfig %s up" % virtual_interace, "# ")
                self.verify("ERROR" not in out, "Virtual interface not found")

            self.dut.send_expect("brctl addbr \"br_kni\"", "# ")

            for virtual_interace in port_virtual_interaces:
                out = self.dut.send_expect(
                    "brctl addif br_kni %s" % virtual_interace, "# ")
                self.verify("ERROR" not in out, "Device not found")

            self.dut.send_expect("ifconfig br_kni up", "# ")
            time.sleep(3)

            tx_port = self.tester.get_local_port(self.config['ports'][0])
            rx_port = self.tester.get_local_port(self.config['ports'][1])

            tgenInput = []
            tgenInput.append((tx_port, rx_port, "kni.pcap"))

            if step['flows'] == 2:
                tgenInput.append((rx_port, tx_port, "kni.pcap"))

            time.sleep(1)
            _, pps = self.tester.traffic_generator_throughput(tgenInput)
            step['pps'] = float(pps) / 10 ** 6

            results_row = [step['kthread_mode'], step['flows'],
                           self.stripped_config_param(), (float(pps) / 10 ** 6)]

            dts.results_table_add_row(results_row)

            self.dut.send_expect("ifconfig br_kni down", "# ")
            self.dut.send_expect("brctl delbr \"br_kni\"", "# ", 10)

        dts.results_table_print()

    def test_perf_bridge_without_kni(self):
        """
        Bridge mode performance without KNI.
        """
        dts.results_table_add_header(bridge_perf_no_kni_results_header)

        self.dut.kill_all()

        dut_ports = self.dut.get_ports(self.nic)

        self.tester.scapy_append('srcmac="00:00:00:00:00:01"')
        self.tester.scapy_append(
            'wrpcap("kni.pcap", [Ether(src=srcmac, dst="ff:ff:ff:ff:ff:ff")/IP(len=46)/UDP()/("X"*18)])')
        self.tester.scapy_execute()

        white_list = self.make_white_list(self.target, self.nic)
        port_virtual_interaces = []
        for port in white_list:
            information = self.dut.send_expect(
                "./tools/dpdk_nic_bind.py --status | grep '%s'" % port, "# ")
            data = information.split(' ')
            for field in data:
                if field.rfind("if=") != -1:
                    port_virtual_interaces.append(field.replace("if=", ""))

        self.dut.send_expect("ifconfig %s up" %
                             port_virtual_interaces[0], "# ")
        self.dut.send_expect("ifconfig %s up" %
                             port_virtual_interaces[1], "# ")
        self.dut.send_expect("brctl addbr \"br1\"", "# ")
        self.dut.send_expect("brctl addif br1 %s" %
                             port_virtual_interaces[0], "# ")
        self.dut.send_expect("brctl addif br1 %s" %
                             port_virtual_interaces[1], "# ")
        self.dut.send_expect("ifconfig br1 up", "# ")
        time.sleep(3)

        tx_port = self.tester.get_local_port(dut_ports[0])
        rx_port = self.tester.get_local_port(dut_ports[1])

        for flows in range(1, flows_without_kni + 1):
            tgenInput = []
            tgenInput.append((tx_port, rx_port, "kni.pcap"))

            if flows == 2:
                tgenInput.append((rx_port, tx_port, "kni.pcap"))

            _, pps = self.tester.traffic_generator_throughput(tgenInput)
            dts.results_table_add_row([flows, float(pps) / 10 ** 6])

        self.dut.send_expect("ifconfig br1 down", "# ")
        self.dut.send_expect("brctl delbr \"br1\"", "# ", 30)

        for port in white_list:
            self.dut.send_expect(
                "./tools/dpdk_nic_bind.py -b igb_uio %s" % (port), "# ")
        dts.results_table_print()

    def test_perf_routing(self):
        """
        Routing performance.
        """

        header = routing_perf_results_header

        for size in packet_sizes_routing:
            header.append("%d Mpps" % size)

        dts.results_table_add_header(header)

        self.dut.send_expect("echo 1 > /proc/sys/net/ipv4/ip_forward", "# ")

        # Run the test steps
        for step in routing_performance_steps:
            self.extract_ports_cores_config(step['config'])

            resutls_row = [step['kthread_mode'], len(
                self.config['ports']), self.stripped_config_param()]

            self.dut.kill_all()
            self.start_kni()

            # Set up the IP addresses, routes and arp entries of the virtual
            # interfaces
            virtual_interaces = {}
            ip_subnet = 0
            for port in self.config['port_details']:

                port_number = port['port']

                # Get the virtual interfaces base on the number of kernel
                # lcores
                port_virtual_interaces = []
                for i in range(len(port['kernel_cores'])):
                    port_virtual_interaces.append(
                        self.virtual_interface_name(port_number, i))

                virtual_interaces[port_number] = port_virtual_interaces

                # Setup IP, ARP and route for each virtual interface
                for interface in range(len(virtual_interaces[port_number])):
                    tx_port = self.tester.get_local_port(port_number)

                    self.dut.send_expect("ifconfig %s 192.170.%d.1" % (
                        virtual_interaces[port_number][interface], ip_subnet), "# ")
                    self.dut.send_expect(
                        "route add -net 192.170.%d.0  netmask 255.255.255.0 gw 192.170.%d.1" % (ip_subnet, ip_subnet), "# ")
                    self.dut.send_expect("arp -s 192.170.%d.2 %s" %
                                         (ip_subnet, self.tester.get_mac(tx_port)), "# ")
                    ip_subnet += 1

            # Get performance for each frame size
            for packet_size in packet_sizes_routing:
                payload_size = packet_size - 38
                tgen_input = []

                # Test one port
                tx_port = self.tester.get_local_port(self.config['ports'][0])
                rx_mac = self.dut.get_mac_address(self.config['ports'][0])
                self.tester.scapy_append('flows = []')

                self.tester.scapy_append('flows = []')
                port_iterator = 0
                for port in self.config['port_details']:
                    port_number = port['port']

                    rx_mac = self.dut.get_mac_address(port_number)
                    tx_port = self.tester.get_local_port(port_number)

                    num_interfaces_per_port = len(
                        virtual_interaces[port_number])

                    # Set flows from and to virtual interfaces in the same port
                    src_ip_subnet = port_iterator * num_interfaces_per_port
                    for interface in range(len(virtual_interaces[port_number])):
                        dst_ip_subnet = (
                            src_ip_subnet + 1) % num_interfaces_per_port
                        dst_ip_subnet += port_iterator * \
                            num_interfaces_per_port
                        self.tester.scapy_append(
                            'flows.append(Ether(dst="%s")/IP(src="192.170.%d.2",dst="192.170.%d.2")/("X"*%d))' %
                            (rx_mac, src_ip_subnet, dst_ip_subnet, payload_size))
                        src_ip_subnet += 1

                    tgen_input.append((tx_port, tx_port, "routePerf.pcap"))

                self.tester.scapy_append('wrpcap("routePerf.pcap",flows)')
                self.tester.scapy_execute()

                time.sleep(1)
                _, pps = self.tester.traffic_generator_throughput(tgen_input)
                resutls_row.append(float(pps) / 10 ** 6)

            dts.results_table_add_row(resutls_row)

        dts.results_table_print()

    def test_perf_routing_without_kni(self):
        """
        Routing performance without KNI.
        """

        header = routing_perf_no_kni_results_header

        for size in packet_sizes_routing:
            header.append("%d Mpps" % size)

        dts.results_table_add_header(header)

        self.dut.kill_all()
        self.dut.send_expect("rmmod rte_kni", "# ", 20)

        self.dut.send_expect("systemctl stop NetworkManager.service", "# ")

        dut_ports = self.dut.get_ports(self.nic)

        white_list = self.make_white_list(self.target, self.nic)
        port_virtual_interaces = []

        for port in white_list:

            # Enables the interfaces
            information = self.dut.send_expect(
                "./tools/dpdk_nic_bind.py --status | grep '%s'" % port, "# ")
            print information
            data = information.split(' ')
            for field in data:
                if field.rfind("if=") != -1:
                    interface_aux = field.replace("if=", "")
                    port_virtual_interaces.append(interface_aux)
                    self.dut.send_expect(
                        "ifconfig %s up" % interface_aux, "# ")

        self.dut.send_expect("echo 1 > /proc/sys/net/ipv4/ip_forward", "# ")

        for port in range(0, ports_without_kni):
            tx_port = self.tester.get_local_port(dut_ports[port])
            self.dut.send_expect("ifconfig %s 192.170.%d.1 up" %
                                 (port_virtual_interaces[port], port + 100), "# ")
            self.dut.send_expect(
                "route add -net 192.170.%d.0  netmask 255.255.255.0 gw 192.170.%d.1" % (port + 100, port + 100), "# ")
            self.dut.send_expect("arp -s 192.170.%d.2 %s" %
                                 (port + 100, self.tester.get_mac(tx_port)), "# ")

        one_port_resutls_row = [1]
        two_port_resutls_row = [2]
        for packet_size in packet_sizes_routing:

            payload_size = packet_size - 38
            tgen_input = []

            # Prepare test with 1 port
            tx_port = self.tester.get_local_port(dut_ports[0])
            rx_mac = self.dut.get_mac_address(dut_ports[0])
            self.tester.scapy_append('flows = []')
            self.tester.scapy_append(
                'flows.append(Ether(dst="%s")/IP(src="192.170.100.2",dst="192.170.100.2")/("X"*%d))' % (rx_mac, payload_size))
            self.tester.scapy_append('wrpcap("routePerf_1.pcap",flows)')
            self.tester.scapy_execute()

            tgen_input = []
            tgen_input.append((tx_port, tx_port, "routePerf_1.pcap"))

            # Get throughput with 1 port
            _, pps = self.tester.traffic_generator_throughput(tgen_input)
            one_port_resutls_row.append(float(pps) / 10 ** 6)
            dts.results_table_add_row(one_port_resutls_row)

            # Prepare test with 'ports_without_kni' ports
            self.tester.scapy_append('flows = []')
            for port in range(ports_without_kni):
                rx_mac = self.dut.get_mac_address(dut_ports[port])
                tx_port = self.tester.get_local_port(dut_ports[port])
                self.tester.scapy_append(
                    'flows.append(Ether(dst="%s")/IP(src="192.170.%d.2",dst="192.170.%d.2")/("X"*%d))' %
                    (rx_mac, 100 + port, 100 + (port + 1) % ports_without_kni, payload_size))
                tgen_input.append((tx_port, tx_port, "routePerf.pcap"))

            self.tester.scapy_append(
                'wrpcap("routePerf_%d.pcap",flows)' % ports_without_kni)
            self.tester.scapy_execute()

            # Get throughput with 'ports_without_kni' ports
            _, pps = self.tester.traffic_generator_throughput(tgen_input)
            two_port_resutls_row.append(float(pps) / 10 ** 6)
            dts.results_table_add_row(two_port_resutls_row)

        dts.results_table_print()

        for port in white_list:
            self.dut.send_expect(
                "./tools/dpdk_nic_bind.py -b %s %s" % (dts.drivername, port), "# ")

    def tear_down(self):
        """
        Run after each test case.
        """
        pass

    def tear_down_all(self):
        """
        Run after each test suite.
        """
        self.dut.kill_all()
        self.dut.send_expect("rmmod rte_kni", "# ", 10)