-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart-vswitch.sh
executable file
·1769 lines (1619 loc) · 58.3 KB
/
start-vswitch.sh
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
#!/bin/bash
# This script will start a vswitch of your choice, doing the following:
# -use multi-queue (for DPDK)
# -bind DPDK PMDs to optimal CPUs
# -for pvp topologies, provide a list of optimal cpus available for the VM
# configure an overlay network such as VxLAN
# The following features are not implemented but would be nice to add:
# -for ovs, configure x flows
# -for a router, configure x routes
# -configure VLAN
# -configure a firewall
###############################################################################
# Default values
###############################################################################
#
# topology:
#
# Two physical devices on one switch. 'topology' is desctibed by a list
# of 1 or more switches separated by commas. The supported interfaces on
# a switch are:
#
# p: A physical port. This may include host physical ports, or
# SR-IOV PCIe or virtio devices seen within a guest
#
# v: A virtio-net interface like dpdkvhostuser or vhost-net (depending on dataplane)
#
topology="pp"
#
# queues:
#
# Number of queue-pairs (rx/tx) to use per device
#
queues=1
#
# switch:
#
# Type of forwarding engine to be used on the DUT topology.
# Currently supported switch types:
#
# testpmd: DPDK's L2 forwarding test program
#
# ovs: Open vSwitch
#
# linuxbridge: L2 kernel networking stack
#
# linuxrouter: L3 kernel networking stack
#
switch="ovs"
#
# switch_mode:
#
# Configuration of the $switch in use. Currently supported list depends on $switch.
# Modes support by switch type are:
#
# linuxbridge: default
#
# linuxrouter: default
#
# testpmd: default
#
# ovs: default/direct-flow-rule, l2-bridge
#
switch_mode="default"
#
# numa_mode:
#
# 'numa_mode' is for DPDK vswitches only.
#
# strict: All PMD threads for all phys and virt devices use memory and cpu only
# from the numa node where the physical adapters are located.
# This implies the VMs must be on the same node.
#
# preferred: Just like 'strict', but the vswitch also has memory and in some cases
# uses cpu from the non-local NUMA nodes.
#
# cross: The PMD threads for all phys devices use memory and cpu from
# the local NUMA node, but VMs are present on another NUMA node,
# and so the PMD threads for those virt devices are also on
# another NUMA node.
#
numa_mode="strict"
#
# overlay_network:
#
# Currently supported are the following overlay network types:
#
# none: For all switch types
#
# vxlan: For linuxbridge and ovs
#
overlay_network="none"
#
# ovs_build:
#
# Specify to use OVS either from:
#
# rpm: Pre-built package
#
# src: Manually built and installed
#
ovs_build="rpm"
#
# dpdk_nic_kmod:
#
# The kernel module to use when assigning an Intel network device to a
# userspace program (DPDK application)
#
dpdk_nic_kmod="vfio-pci"
#
# dataplane:
#
# The type of forwarding plane to be used on the DUT.
#
# dpdk: Intel's Data Plane Development Kit
#
# kernel: The Linux kernel's networking stack
#
# kernel-hw-offload: OVS dataplane handled in NIC hardware
#
dataplane="dpdk"
#
# use_ht:
#
# Specify if hyperthreaded processors should be used or not for
# forwading packets
#
# y: yes
#
# n: no
#
use_ht="y"
#
# testpmd_path:
#
# Specifies the location of DPDK's L2 forwarding program testpmd
#
testpmd_path="/usr/bin/testpmd"
#
# supported_switches:
#
# The list of supported switches that may be used upon the DUT
#
supported_switches="linuxbridge ovs linuxrouter testpmd"
#
# pci_descriptors:
#
# Sets the DPDK physical port queue size.
# NOTE: Also used to set testpmd rxd/txd ring size. We may want to make this separate
# from the DPDK physical port descriptor programming.
#
# Size should probably not be larger than 2048. Using a size of 4096 may have a negative
# impact upon performance. See: http://docs.openvswitch.org/en/latest/intro/install/dpdk/
#
pci_descriptors=2048
#
# pci_desc_ovveride:
#
# Used to override the desriptor size of any of the vswitches here.
#
pci_desc_override=""
#
# vhu_desc_override:
#
# Use to override the desriptor size of any of the vswitches here.
# NOTE: This needs to be fixed given we also have pci_desc_override as
# well as pci_descriptors all doing similar things
#
vhu_desc_override=""
#
# cpu_usage_file:
#
# After the vswitch is started, it must decide which host cpus the VM uses.
# The file $cpu_usage_file, defaulting to /var/log/isolated_cpu_usage.conf,
# shows which cpus are used for the vswitch and which cpus are left for the
# VM. The shell script can be used virt-pin.sh to pin the vcpus. It will read
# the /var/log/isolated_cpu_usage.conf ($cpu_usage_file) file to make sure
# it does not use cpus already used by the vswitch.
#
cpu_usage_file="/var/log/isolated_cpu_usage.conf"
#
# vhost_affinity:
#
# NOTE: This is not working yet
#
# local: the vhost interface will reside in the same node as the physical interface on the same bridge
#
# remote: The vhost interface will reside in remote node as the physical interface on the same bridge
#
# This locality is an assumption and must match what was configured when VMs are created
#
vhost_affinity="local"
#
# no_kill:
#
# Don't kill all OVS sessions. However, any process
# owning a DPDK device will still be killed
#
no_kill=0
function log() {
echo -e "start-vswitch: $1"
}
function exit_error() {
local error_message=$1
local error_code=$2
if [ -z "$error_code"] ; then
error_code=1
fi
log "ERROR: $error_message"
exit $error_code
}
function init_cpu_usage_file() {
local opt
local var
local val
local cpu
local non_iso_cpu_bitmask
local non_iso_cpu_hexmask
local non_iso_cpu_list
local online_cpu_range
local online_cpu_list
local iso_cpu_list
local iso_cpus
/bin/rm -f $cpu_usage_file
touch $cpu_usage_file
iso_cpus=$(cat /sys/devices/system/cpu/isolated)
if [ -n "${iso_cpus}" ]; then
iso_cpu_list=$(convert_number_range "${iso_cpus}")
else
for opt in `cat /proc/cmdline`; do
var=`echo $opt | awk -F= '{print $1}'`
if [ $var == "tuned.non_isolcpus" ]; then
val=`echo $opt | awk -F= '{print $2}'`
non_iso_cpu_hexmask=`echo "$val" | sed -e s/,//g | tr a-f A-F`
non_iso_cpu_bitmask=`echo "ibase=16; obase=2; $non_iso_cpu_hexmask" | bc`
non_iso_cpu_list=`convert_bitmask_to_list $non_iso_cpu_bitmask`
online_cpu_range=`cat /sys/devices/system/cpu/online`
online_cpu_list=`convert_number_range $online_cpu_range`
iso_cpu_list=`sub_from_list $online_cpu_list $non_iso_cpu_list`
break
fi
done
fi
for cpu in `echo $iso_cpu_list | sed -e 's/,/ /g'`; do
echo "$cpu:" >>$cpu_usage_file
done
echo "$iso_cpu_list"
}
function get_iso_cpus() {
local cpu
local list
for cpu in `grep -E "[0-9]+:$" $cpu_usage_file | awk -F: '{print $1}'`; do
list="$list,$cpu"
done
list=`echo $list | sed -e 's/^,//'`
echo "$list"
}
function log_cpu_usage() {
# $1 = list of cpus, no spaces: 1,2,3
local cpulist=$1
local usage=$2
local cpu
if [ "$usage" == "" ]; then
exit_error "a string describing the usage must accompany the cpu list"
fi
for cpu in `echo $cpulist | sed -e 's/,/ /g'`; do
if grep -q -E "^$cpu:" $cpu_usage_file; then
if grep -q -E "^$cpu:.+" $cpu_usage_file; then
# $cpu is already used
return 1
else
sed -i -e s/^$cpu:$/$cpu:$usage/ $cpu_usage_file
fi
else
# $cpu is not in $cpu_usage_file
return 1
fi
done
return 0
}
function convert_bitmask_to_list() {
# converts a range of cpus, like "10111" to 1,2,3,5"
local bitmask=$1
local cpu=0
local bit=""
while [ "$bitmask" != "" ]; do
bit=${bitmask: -1}
if [ "$bit" == "1" ]; then
cpu_list="$cpu_list,$cpu"
fi
bitmask=`echo $bitmask | sed -e 's/[0-1]$//'`
((cpu++))
done
cpu_list=`echo $cpu_list | sed -e 's/,//'`
echo "$cpu_list"
}
function convert_list_to_bitmask() {
# converts a range of cpus, like "1-3,5" to a bitmask, like "10111"
local cpu_list=$1
local cpu=""
local bitmask=0
for cpu in `echo "$cpu_list" | sed -e 's/,/ /g'`; do
bitmask=`echo "$bitmask + (2^$cpu)" | bc`
done
bitmask=`echo "obase=2; $bitmask | bc"`
echo "$bitmask"
}
function convert_number_range() {
# converts a range of cpus, like "1-3,5" to a list, like "1,2,3,5"
local cpu_range=$1
local cpus_list=""
local cpus=""
for cpus in `echo "$cpu_range" | sed -e 's/,/ /g'`; do
if echo "$cpus" | grep -q -- "-"; then
cpus=`echo $cpus | sed -e 's/-/ /'`
cpus=`seq $cpus | sed -e 's/ /,/g'`
fi
for cpu in $cpus; do
cpus_list="$cpus_list,$cpu"
done
done
cpus_list=`echo $cpus_list | sed -e 's/^,//'`
echo "$cpus_list"
}
function node_cpus_list() {
local node_id=$1
local cpu_range=`cat /sys/devices/system/node/node$node_id/cpulist`
local cpu_list=`convert_number_range $cpu_range`
echo "$cpu_list"
}
function add_to_list() {
local list=$1
local add_list=$2
local list_set
local i
# for easier manipulation, convert the current_elements string to a associative array
for i in `echo $list | sed -e 's/,/ /g'`; do
list_set["$i"]=1
done
list=""
for i in `echo $add_list | sed -e 's/,/ /g'`; do
list_set["$i"]=1
done
for i in "${!list_set[@]}"; do
list="$list,$i"
done
list=`echo $list | sed -e 's/^,//'`
echo "$list"
}
function sub_from_list () {
local list=$1
local sub_list=$2
local list_set
local i
# for easier manipulation, convert the current_elements string to a associative array
for i in `echo $list | sed -e 's/,/ /g'`; do
list_set["$i"]=1
done
list=""
for i in `echo $sub_list | sed -e 's/,/ /g'`; do
unset list_set[$i]
done
for i in "${!list_set[@]}"; do
list="$list,$i"
done
list=`echo $list | sed -e 's/^,//'`
echo "$list"
}
function intersect_cpus() {
local cpus_a=$1
local cpus_b=$2
local cpu_set_a
local cpu_set_b
local intersect_cpu_list=""
# for easier manipulation, convert the cpu list strings to a associative array
for i in `echo $cpus_a | sed -e 's/,/ /g'`; do
cpu_set_a["$i"]=1
done
for i in `echo $cpus_b | sed -e 's/,/ /g'`; do
cpu_set_b["$i"]=1
done
for cpu in "${!cpu_set_a[@]}"; do
if [ "${cpu_set_b[$cpu]}" != "" ]; then
intersect_cpu_list="$intersect_cpu_list,$cpu"
fi
done
intersect_cpu_list=`echo $intersect_cpu_list | sed -e s/^,//`
echo "$intersect_cpu_list"
}
function remove_sibling_cpus() {
local cpu_range=$1
local cpu_list=`convert_number_range $cpu_range`
local no_sibling_list=""
local socket_core_id_list="," #commas on front and end of list and in between IDs for easier grepping
while [ ! -z "$cpu_list" ]; do
this_cpu=`echo $cpu_list | awk -F, '{print $1}'`
cpu_list=`echo $cpu_list | sed -e s/^$this_cpu//`
cpu_list=`echo $cpu_list | sed -e s/^,//`
core=`cat /sys/devices/system/cpu/cpu$this_cpu/topology/core_id`
socket=`cat /sys/devices/system/cpu/cpu$this_cpu/topology/physical_package_id`
socket_core_id="$socket:$core"
if echo $socket_core_id_list | grep -q ",$socket_core_id,"; then
# this core has already been taken
continue
else
# first time this core has been found, use it
socket_core_id_list="${socket_core_id_list}${socket_core_id},"
no_sibling_list="$no_sibling_list,$this_cpu"
fi
done
no_sibling_list=`echo $no_sibling_list | sed -e s/^,//`
echo "$no_sibling_list"
}
function get_pmd_cpus() {
local devs=$1
local nr_queues=$2
local cpu_usage=$3
local pmd_cpu_list=""
local pci_dev=""
local node_id=""
local cpus_list=""
local iso_cpus_list=""
local pmd_cpus_list=""
local queue_num=
local count=
local prev_cpu=""
# for each device, get N cpus, where N = number of queues
local this_dev
for this_dev in `echo $devs | sed -e 's/,/ /g'`; do
if echo $this_dev | grep -q vhost; then
# the file name for vhostuser ends with a number matching the NUMA node
node_id="${this_dev: -1}"
else
node_id=`cat /sys/bus/pci/devices/$(get_dev_loc $this_dev)/numa_node`
# -1 means there is no topology, so we use node0
if [ "$node_id" == "-1" ]; then
node_id=0
fi
fi
cpus_list=`node_cpus_list "$node_id"`
iso_cpus_list=`get_iso_cpus`
node_iso_cpus_list=`intersect_cpus "$cpus_list" "$iso_cpus_list"`
if [ "$use_ht" == "n" ]; then
node_iso_cpus_list=`remove_sibling_cpus $node_iso_cpus_list`
fi
if [ "$node_iso_cpus_list" == "" ]; then
echo ""
exit
fi
queue_num=0
while [ $queue_num -lt $nr_queues ]; do
new_cpu=""
if [ "$use_ht" == "y" -a "$prev_cpu" != "" ]; then
# search for sibling cpu-threads before picking next avail cpu
cpu_siblings_range=`cat /sys/devices/system/cpu/cpu$prev_cpu/topology/thread_siblings_list`
cpu_siblings_list=`convert_number_range $cpu_siblings_range`
cpu_siblings_avail_list=`sub_from_list $cpu_siblings_list $pmd_cpus_list`
if [ "$cpu_siblings_avail_list" != "" ]; then
# if all of the siblings are depleted, then fall back to getting a new (non-sibling) cpu
new_cpu="`echo $cpu_siblings_avail_list | awk -F, '{print $1}'`"
fi
fi
if [ "$new_cpu" == "" ]; then
# allocate a new cpu
new_cpu="`echo $node_iso_cpus_list | awk -F, '{print $1}'`"
fi
if [ "$use_ht" == "n" ]; then
# make sure sibling threads don't get used next time a isolated cpu is found
sibling_cpus=`cat /sys/devices/system/cpu/cpu$new_cpu/topology/thread_siblings_list`
sibling_cpus=`convert_number_range $sibling_cpus`
sibling_cpus=`sub_from_list $sibling_cpus $new_cpu`
for i in `echo $sibling_cpus | sed -e 's/,/ /g'`; do
log_cpu_usage "$i" "idle-sibling-thread"
if [ $? -gt 0 ]; then
exit 1
fi
done
fi
log_cpu_usage "$new_cpu" "$cpu_usage"
if [ $? -gt 0 ]; then
exit 1
fi
node_iso_cpus_list=`sub_from_list "$node_iso_cpus_list" "$new_cpu"`
pmd_cpus_list="$pmd_cpus_list,$new_cpu"
((queue_num++))
((count++))
prev_cpu=$new_cpu
done
done
pmd_cpus_list=`echo $pmd_cpus_list | sed -e 's/^,//'`
echo "$pmd_cpus_list"
return 0
}
function get_cpumask() {
local cpu_list=$1
local pmd_cpu_mask=0
for cpu in `echo $cpu_list | sed -e 's/,/ /'g`; do
bc_math="$bc_math + 2^$cpu"
done
bc_math=`echo $bc_math | sed -e 's/\+//'`
pmd_cpu_mask=`echo "obase=16; $bc_math" | bc`
echo "$pmd_cpu_mask"
}
function set_ovs_bridge_mode() {
local bridge=$1
local switch_mode=$2
$ovs_bin/ovs-ofctl del-flows ${bridge}
case "${switch_mode}" in
"l2-bridge")
$ovs_bin/ovs-ofctl add-flow ${bridge} action=NORMAL
;;
"default"|"direct-flow-rule")
$ovs_bin/ovs-ofctl add-flow ${bridge} "in_port=1,idle_timeout=0 actions=output:2"
$ovs_bin/ovs-ofctl add-flow ${bridge} "in_port=2,idle_timeout=0 actions=output:1"
;;
esac
}
function get_dev_loc() {
# input should be pci_location/port-number, like 0000:86:0.0/1
echo $1 | awk -F/ '{print $1}'
}
function get_devs_locs() {
# input should be a list of pci_location/port-number, like 0000:86:0.0/0,0000:86:0.0/1
# returns a list of PCI location IDs with no repeats
# for exmaple get_devs_locs "0000:86:0.0/0,0000:86:0.0/1" returns "0000:86:0.0"
local this_dev
for this_dev in `echo $1 | sed -e 's/,/ /g'`; do
get_dev_loc $this_dev
done | sort | uniq
}
function get_dev_port() {
# input should be pci_location/port-number, like 0000:86:0.0/1
echo $1 | awk -F/ '{print $2}'
}
function get_dev_desc() {
# input should be pci_location/port-number, like 0000:86:0.0/1
lspci -s $(get_dev_loc $1) | cut -d" " -f 2- | sed -s 's/ (.*$//'
}
function get_dev_netdevs() {
/bin/ls /sys/bus/pci/devices/$(get_dev_loc $1)/net
}
# Return the netdev device name for a PCI location and matching phys_port_name
# This is necessary when there are more than one netdev ports per PF
# This is also used to identify a netdev device with no actual port (use "" as the match)
# Return the netdev name. Input must be "pf_location/port_number"
function get_dev_netdev() {
local dev_pf_loc=`get_dev_loc $1`
local dev_pf_port=`get_dev_port $1`
local netdevs=(`get_dev_netdevs $dev_pf_loc`)
echo "${netdevs[$dev_pf_port]}"
}
function get_switch_id() {
# input shold be the netdev name
cat /sys/class/net/$1/phys_switch_id || return 1
}
# Return the netdev of the switchdev (representor) device
# You must provide the full device name, aka pci_location/port-id
function get_sd_netdev_name() {
local dev="$1"
local dev_loc=`get_dev_loc $dev`
local dev_port=`get_dev_port $dev`
local dev_netdev=`get_dev_netdev $dev`
local dev_sw_id=`get_switch_id $dev_netdev`
local veth_name=""
local veth_sw_id=""
local veth_port_name=""
local count=0
# search all virtual devices, looking for a switch_id that matches the
# physical port and pick the Nth match, where N = the port ID od the device
for veth_name in `/bin/ls /sys/devices/virtual/net`; do
veth_sw_id=`cat /sys/class/net/$veth_name/phys_switch_id 2>/dev/null`
if [ "$dev_sw_id" == "$veth_sw_id" ]; then
veth_phys_port_name=`cat /sys/class/net/$veth_name/phys_port_name`
#if [ $dev_port -eq $count ]; then
if [ "$veth_phys_port_name" == "pf0vf$dev_port" ]; then
echo "$veth_name"
return
fi
if [ "$veth_phys_port_name" == "pf1vf$dev_port" ]; then
echo "$veth_name"
return
fi
if [ "$veth_phys_port_name" == "$dev_port" ]; then
echo "$veth_name"
return
fi
#((count++))
fi
done
if [ "$sd_eth_name" == "" ]; then
return 1
fi
}
# Process options and arguments
opts=$(getopt -q -o i:c:t:r:m:p:M:S:C:o --longoptions "no-kill,vhost-affinity:,numa-mode:,desc-override:,vhost_devices:,pci-devices:,devices:,nr-queues:,use-ht:,overlay-network:,topology:,dataplane:,switch:,switch-mode:,testpmd-path:,dpdk-nic-kmod:,prefix:,pci-desc-override:,print-config" -n "getopt.sh" -- "$@")
if [ $? -ne 0 ]; then
printf -- "$*\n"
printf "\n"
printf "\t${benchmark_name}: you specified an invalid option\n\n"
printf "\tThe following options are available:\n\n"
# 1 2 3 4 5 6 7 8 9 0 1 2 3
# 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
printf -- "\t\t--[pci-]devices=str/port,str/port ..... Two PCI locations of Ethenret adapters to use, like:\n"
printf -- "\t\t '--devices=0000:83:00.0/0,0000:86:00.0/0'. Port numbers are optional\n"
printf -- "\t\t You can list the same PCI device twice only if the physical function has \n"
printf -- "\t\t two netdev devices\n\n"
printf -- "\t\t--device-ports=int,int ................ If a PCI device has more than 1 netdev, then you need to specify the port ID for each device. Port enumeration starts with \"0\"\n\n"
printf -- "\t\t--no-kill ............................. Don't kill all OVS sessions (however, anything process owning a DPDK device will still be killed)\n\n"
printf -- "\t\t--vhost-affinity=str .................. local [default]: Use same numa node as PCI device\n"
printf -- "\t\t remote: Use opposite numa node as PCI device\n\n"
printf -- "\t\t--nr-queues=int ....................... The number of queues per device\n\n"
printf -- "\t\t--use-ht=[y|n] ........................ y=Use both cpu-threads on HT core\n"
printf -- "\t\t n=Only use 1 cpu-thread per core\n"
printf -- "\t\t Note: Using HT has better per/core throuhgput, but not using HT has better per-queue throughput\n\n"
printf -- "\t\t--overlay-network=[none|vxlan] ........ Network overlay used, if any (not supported on all bridge types)\n\n"
printf -- "\t\t--topology=str ........................ pp: Two physical devices on same bridge\n"
printf -- "\t\t pvp or pv,vp: Two bridges, each with a phys port and a virtio port)\n\n"
printf -- "\t\t--dataplane=str ....................... dpdk, kernel, or kernel-hw-offload\n\n"
printf -- "\t\t--desc-override ....................... Override default size for descriptor size\n\n"
printf -- "\t\t--switch=str .......................... testpmd, ovs, linuxrouter, or linuxbridge\n\n"
printf -- "\t\t--switch-mode=str ..................... Mode that the selected switch operates in. Modes differ between switches\n"
printf -- "\t\t \tlinuxbridge: default\n"
printf -- "\t\t \tlinuxrouter: default\n"
printf -- "\t\t \ttestpmd: default\n"
printf -- "\t\t \tovs: default/direct-flow-rule, l2-bridge\n"
printf -- "\t\t--testpmd-path=str .................... Override the default location for the testpmd binary (${testpmd_path})\n\n"
printf -- "\t\t--dpdk-nic-kmod=str ................... Use this kernel modeule for the devices (default is $dpdk_nic_kmod)\n\n"
printf -- "\t\t--numa-mode=str ....................... strict: (default). All PMD threads for all phys and virt devices use memory and cpu only\n"
printf -- "\t\t from the numa node where the physical adapters are located.\n"
printf -- "\t\t This implies the VMs must be on the same node.\n"
printf -- "\t\t preferred: Just like 'strict', but the vswitch also has memory and in some cases\n"
printf -- "\t\t uses cpu from the non-local NUMA nodes.\n"
printf -- "\t\t cross: The PMD threads for all phys devices use memory and cpu from\n"
printf -- "\t\t the local NUMA node, but VMs are present on another NUMA node,\n"
printf -- "\t\t and so the PMD threads for those virt devices are also on\n"
printf -- "\t\t another NUMA node.\n"
exit_error ""
fi
log "opts: [$opts]"
eval set -- "$opts"
log "Processing options:"
while true; do
case "$1" in
--no-kill)
shift
no_kill=1
log "no_kill: [$no_kill]"
;;
--devices)
shift
if [ -n "$1" ]; then
for dev in `echo $1 | sed -e 's/,/ /g'`; do
if echo $dev | grep -q -- /; then
devs="$devs,$dev"
else
devs="$devs,$dev/0"
fi
done
devs=`echo $devs | sed -e s/^,//`
log "devs: [$devs]"
shift
fi
;;
--vhost-affinity)
shift
if [ -n "$1" ]; then
vhost_affinity="$1"
log "vhost_affinity: [$vhost_affinity]"
shift
fi
;;
--nr-queues)
shift
if [ -n "$1" ]; then
queues="$1"
log "nr_queues: [$queues]"
shift
fi
;;
--use-ht)
shift
if [ -n "$1" ]; then
use_ht="$1"
log "use_ht: [$use_ht]"
shift
fi
;;
--overlay-network)
shift
if [ -n "$1" ]; then
overlay_network="$1"
log "overlay_network: [$overlay_network]"
shift
fi
;;
--topology)
shift
if [ -n "$1" ]; then
topology="$1"
log "topology: [$topology]"
shift
fi
;;
--dataplane)
shift
if [ -n "$1" ]; then
dataplane="$1"
log "dataplane: [$dataplane]"
shift
fi
;;
--pci-desc-override)
shift
if [ -n "$1" ]; then
pci_desc_override="$1"
log "pci-desc-override: [$pci_desc_override]"
shift
fi
;;
--vhu-desc-override)
shift
if [ -n "$1" ]; then
vhu_desc_override="$1"
log "vhu-desc-override: [$vhu_desc_override]"
shift
fi
;;
--switch)
shift
if [ -n "$1" ]; then
switch="$1"
shift
ok=0
for i in $supported_switches; do
if [ "$switch" == "$i" ]; then
ok=1
fi
done
if [ $ok -eq 1 ]; then
log "switch: [$switch]"
else
exit_error "switch: [$switch] is not supported by this script"
fi
fi
;;
--switch-mode)
shift
if [ -n "$1" ]; then
switch_mode="$1"
shift
log "switch_mode: [$switch_mode]"
fi
;;
--testpmd-path)
shift
if [ -n "$1" ]; then
testpmd_path="$1"
shift
if [ ! -e ${testpmd_path} -o ! -x "${testpmd_path}" ]; then
exit_error "testpmd_path: [${testpmd_path}] does not exist or is not exexecutable"
fi
log "testpmd_path: [${testpmd_path}]"
fi
;;
--numa-mode)
shift
if [ -n "$1" ]; then
numa_mode="$1"
shift
log "numa_mode: [$numa_mode]"
fi
;;
--dpdk-nic-kmod)
shift
if [ -n "$1" ]; then
dpdk_nic_kmod="$1"
shift
log "dpdk_nic_kmod: [$dpdk_nic_kmod]"
fi
;;
--prefix)
shift
if [ -n "$1" ]; then
prefix="$1"
shift
log "prefix: [$prefix]"
fi
;;
--print-config)
shift
echo ""
echo "topology = $topology"
echo "queues = $queues"
echo "switch = $switch"
echo "switch_mode = $switch_mode"
echo "numa_mode = $numa_mode"
echo "overlay_network = $overlay_network"
echo "ovs_build = $ovs_build"
echo "dpdk_nic_kmod = $dpdk_nic_kmod"
echo "dataplane = $dataplane"
echo "use_ht = $use_ht"
echo "testpmd_path = $testpmd_path"
echo "supported_switches = $supported_switches"
echo "pci_descriptors = $pci_descriptors"
echo "pci_desc_override = $pci_descriptor_override"
echo "vhu_desc_override = $vhu_desc_override"
echo "cpu_usage_file = $cpu_usage_file"
echo "vhost_affinity = $vhost_affinity"
echo "no_kill = $no_kill"
echo ""
;;
--)
shift
break
;;
*)
log "[$script_name] bad option, \"$1 $2\""
break
;;
esac
done
# validate switch modes
log "Validating the switch-mode $switch_mode given the switch is $switch..."
case "${switch}" in
"linuxbridge"|"linuxrouter"|"testpmd")
case "${switch_mode}" in
"default")
;;
*)
exit_error "switch=${switch} does not support switch_mode=${switch_mode}"
;;
esac
;;
"ovs")
case "${switch_mode}" in
"default"|"direct-flow-rule"|"l2-bridge")
;;
*)
exit_error "switch=${switch} does not support switch_mode=${switch_mode}"
;;
esac
;;
esac
log "switch-mode $switch_mode is valid"
# check for software dependencies. Just make sure everything possibly needed is installed.
log "Determining if proper software tools are installed..."
all_deps="lsof lspci bc dpdk-devbind driverctl udevadm ip screen tmux brctl"
for i in $all_deps; do
if which $i >/dev/null 2>&1; then
continue
else
exit_error "You must have the following installed to run this script: '$i' Please install first"
fi
done
# only run if selinux is disabled
selinuxenabled && exit_error "disable selinux before using this script"
# either "rpm" or "src"
if [ "$ovs_build"="rpm" ]; then
ovs_bin="/usr/bin"
ovs_sbin="/usr/sbin"
ovs_run="/var/run/openvswitch"
ovs_etc="/etc/openvswitch"
log "Using OVS from RPM"
else
ovs_bin="/usr/local/bin"
ovs_sbin="/usr/local/sbin"
ovs_run="/usr/local/var/run/openvswitch"
ovs_etc="/usr/local/etc/openvswitch"
log "Using OVS that has been build locally"
fi
# Get RHEL major version. Sometimes /sysfs changes between versions
rhel_major_version=`cat /etc/redhat-release | tr -dc '0-9.'|cut -d \. -f1`
num_vfs_per_pf=1
dev_count=0
# make sure all of the pci devices used are exactly the same
# also annotate all PCI devices with a port number if not already included
prev_dev_desc=""
for this_dev in `echo $devs | sed -e 's/,/ /g'`; do
if [ "$prev_pci_desc" != "" -a "$prev_pci_desc" != "$(get_dev_desc $this_dev)" ]; then
exit_error "PCI devices are not the exact same type: $prev_pci_desc, $this_pci_desc"
fi
((dev_count++))
done
if [ $dev_count -ne 2 ]; then
exit_error "you must use 2 PCI devices, you used: $dev_count"
fi
kernel_nic_kmod=`lspci -k -s $(get_dev_loc $this_dev) | grep "Kernel modules:" | awk -F": " '{print $2}' | sed -e s/virtio_pci/virtio-pci/`
log "kernel mod: $kernel_nic_kmod"
# kill any process using the 2 devices
log "Checking for an existing process using $devs"
for this_dev in `echo $devs | sed -e 's/,/ /g'`; do
iommu_group=`readlink /sys/bus/pci/devices/$(get_dev_loc $this_dev)/iommu_group | awk -Fiommu_groups/ '{print $2}'`
pids=`lsof -n -T -X | grep -- "/dev/vfio/$iommu_group" | awk '{print $2}' | sort | uniq`
if [ ! -z "$pids" ]; then
log "killing PID $pids, which is using device $pci_dev"
kill $pids
fi
done
if [ $no_kill -ne 1 ]; then
# completely kill and remove old ovs configuration
log "stopping ovs"
killall -q -w ovs-vswitchd
killall -q -w ovsdb-server
killall -q -w ovsdb-server ovs-vswitchd
log "stopping testpmd"
killall -q -w testpmd
rm -rf $ovs_run/ovs-vswitchd.pid
rm -rf $ovs_run/ovsdb-server.pid
rm -rf $ovs_etc/*db*
rm -rf $ovs_var/*.log
fi
# for Netronome only: make sure the right firmware is in the default location
if [ "$kernel_nic_kmod" == "nfp" ]; then
log "Testing Netronome NIC"
if [ "$dataplane" == "kernel-hw-offload" ]; then
log "Testing with kernel-hw-offload feature"
nfp_firmware=flower
else
log "Testing without kernel-hw-offload feature"