xref: /mOS-networking-stack/setup.sh (revision 91df013f)
1#! /bin/bash
2
3############################ Common Utilities ################################
4FL_PCAP=1
5FL_DPDK=2
6FL_NETMAP=3
7
8# vercomp returns 0 (=), 1 (>), or 2 (<)
9vercomp () {
10    if [[ $1 == $2 ]]
11    then
12        return 0
13    fi
14    local IFS=.
15    local i ver1=($1) ver2=($2)
16    # fill empty fields in ver1 with zeros
17    for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
18    do
19        ver1[i]=0
20    done
21    for ((i=0; i<${#ver1[@]}; i++))
22    do
23        if [[ -z ${ver2[i]} ]]
24        then
25            # fill empty fields in ver2 with zeros
26            ver2[i]=0
27        fi
28        if ((10#${ver1[i]} > 10#${ver2[i]}))
29        then
30            return 1
31        fi
32        if ((10#${ver1[i]} < 10#${ver2[i]}))
33        then
34            return 2
35        fi
36    done
37    return 0
38}
39
40# valid_ip_addr returns 1 for valid ip address
41valid_ip_addr()
42{
43    local  ip=$1
44    local  stat=1
45
46    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
47        OIFS=$IFS
48        IFS='.'
49        ip=($ip)
50        IFS=$OIFS
51        [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
52            && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
53        stat=$?
54    fi
55    return $stat
56}
57
58# Create a mos.conf file
59create_config()
60{
61    cd $CUR_DIR
62    mkdir -p $2
63    CONF_FILE=$2/mos.conf
64    CONF_MASTER_FILE=$2/mos-master.conf
65    CONF_SLAVE_FILE=$2/mos-slave.conf
66
67    echo
68    echo "----------------------------------------"
69    echo "Creating mos.conf file in $2"
70    echo "----------------------------------------"
71
72    if [ -f $CONF_FILE ]; then
73	echo
74	echo "The config file $2/mos.conf already exists."
75	echo "Skip writing a new config file.."
76	return
77    fi
78
79    # Get the number of CPUs and translate it into CPU mask
80    let "z=2**$(nproc)-1"
81    CPU_MASK=$(printf '0x%04X\n' $z)
82
83    # Get # of CPU sockets
84    let "sockets=$(cat /proc/cpuinfo | grep "physical id" | awk '{print $4}' | sort -ur | head -n 1) + 1"
85
86    # Get the number of memory channels
87    command -v dmidecode >/dev/null &&
88    let "NUM_MEMCH=($(sudo dmidecode -t 17 | grep -c 'Size:')-$(sudo dmidecode -t 17 | grep -c 'Size: No Module'))/$sockets" ||
89    { echo "dmidecode command not found. setting num_mem_ch = 4"; let "NUM_MEMCH=4"; }
90
91    # Get the number of interfaces
92    counter=0
93    if [[ $1 == $FL_DPDK ]]; then
94	cd /sys/module/igb_uio/drivers/pci:igb_uio/
95	DEV_NAME="dpdk"
96    elif [[ ( $1 != $FL_PCAP ) && ( $1 != $FL_NETMAP ) ]]; then
97	echo "invalid function call 1"
98	exit 1
99    fi
100    for i in *
101    do
102	if [[ $i == *":"* ]]
103	then
104	    let "counter=$counter + 1"
105	fi
106    done
107    cd $CUR_DIR
108
109    # Write up a new configuration file
110    if [[ $1 == $FL_PCAP ]]; then
111	cat .standalone-template.conf > $CONF_FILE
112	DEVLIST=`ifconfig -s | grep -Eo '^[^ ]+' | tail -n+2`
113	for dev in $DEVLIST; do
114	    printf "Found $dev. Press y to select [y/N]: "
115	    read option
116	    if [[ "$option" == y* ]]; then
117		DEVICE="\n\t\t$dev"
118		DEVICEMASK="__coremask__devicemask"
119		FMT=$(printf 's/__devicemask/%s %s/g' $DEVICE $DEVICEMASK)
120		sed -i -e "$FMT" $CONF_FILE
121
122		DEVICE="$dev""__devicelist"
123		FMT=$(printf 's/__devicelist/ %s/g' $DEVICE)
124		sed -i -e "$FMT" $CONF_FILE
125	    fi
126	done
127	sed -i -e 's/__devicemask//g' $CONF_FILE
128	sed -i -e 's/__devicelist//g' $CONF_FILE
129	sed -i -e 's/__coremask/0x0001/g' $CONF_FILE
130	sed -i -e 's/__num_memch//g' $CONF_FILE
131	sed -i -e 's/__forward/1/g' $CONF_FILE
132	sed -i -e 's/__multiprocess//g' $CONF_FILE
133
134    elif [[ $1 == $FL_NETMAP ]]; then
135	if [ "$3" = "epserver" ] || [ "$3" = "epwget" ] ; then
136	    cat .end-template.conf > $CONF_FILE
137	else
138	    cat .standalone-template.conf > $CONF_FILE
139	fi
140
141	DEVLIST=`ifconfig -s | grep -Eo '^[^ ]+' | tail -n+2`
142	for dev in $DEVLIST; do
143	    printf "Found $dev. Press y to select [y/N]: "
144	    read option
145	    if [[ "$option" == y* ]]; then
146		DEVICE="\n\t\t$dev"
147		DEVICEMASK="__coremask__devicemask"
148		FMT=$(printf 's/__devicemask/%s %s/g' $DEVICE $DEVICEMASK)
149		sed -i -e "$FMT" $CONF_FILE
150
151		DEVICE="$dev""__devicelist"
152		FMT=$(printf 's/__devicelist/ %s/g' $DEVICE)
153		sed -i -e "$FMT" $CONF_FILE
154	    fi
155	done
156	sed -i -e 's/__devicemask//g' $CONF_FILE
157	sed -i -e 's/__devicelist//g' $CONF_FILE
158	sed -i -e 's/__coremask/'$CPU_MASK'/g' $CONF_FILE
159	sed -i -e 's/__num_memch//g' $CONF_FILE
160	sed -i -e 's/__forward/1/g' $CONF_FILE
161	sed -i -e 's/__app/'$3'/g' $CONF_FILE
162	sed -i -e 's/__multiprocess//g' $CONF_FILE
163
164	if [ "$3" = "nat" ] ; then
165	    sed -i -e 's/\# tcp_tw_interval = 30/tcp_tw_interval = 30/g' $CONF_FILE
166	fi
167    else
168	if [ "$3" = "epserver" ] || [ "$3" = "epwget" ] ; then
169	    cat .end-template.conf > $CONF_FILE
170	    cat .end-template.conf > $CONF_MASTER_FILE
171	    cat .end-template.conf > $CONF_SLAVE_FILE
172	else
173	    cat .standalone-template.conf > $CONF_FILE
174	fi
175	start=0
176	while [ $start -lt $counter ]
177	do
178	    DEVICE="\n\t\t$DEV_NAME$(($start))"
179	    DEVICEMASK="__coremask__devicemask"
180	    FMT=$(printf 's/__devicemask/%s %s/g' $DEVICE $DEVICEMASK)
181	    sed -i -e "$FMT" $CONF_FILE
182
183	    DEVICE="$DEV_NAME$(($start))__devicelist"
184	    FMT=$(printf 's/__devicelist/ %s/g' $DEVICE)
185	    sed -i -e "$FMT" $CONF_FILE
186
187	    let "start=$start + 1"
188	done
189	sed -i -e 's/__devicemask//g' $CONF_FILE
190	sed -i -e 's/__devicelist//g' $CONF_FILE
191	sed -i -e 's/__coremask/'$CPU_MASK'/g' $CONF_FILE
192	sed -i -e 's/__forward/1/g' $CONF_FILE
193	sed -i -e 's/__app/'$3'/g' $CONF_FILE
194
195	if [ "$3" = "nat" ] ; then
196	    sed -i -e 's/\# tcp_tw_interval = 30/tcp_tw_interval = 30/g' $CONF_FILE
197	fi
198
199	if [[ $1 == $FL_DPDK ]]; then
200	    FMT=$(printf 's/__num_memch/%snb_mem_channels = %d%s/g' '# number of memory channels per socket [mandatory for DPDK]\n\t' $NUM_MEMCH '\n')
201	    sed -i -e "$FMT" $CONF_FILE
202	if [ "$3" = "epserver" ] || [ "$3" = "epwget" ] ; then
203	    cp $CONF_FILE $CONF_MASTER_FILE
204	    cp $CONF_FILE $CONF_SLAVE_FILE
205	    sed -i -e 's/__multiprocess/multiprocess = 0 master/g' $CONF_MASTER_FILE
206	    sed -i -e 's/__multiprocess/multiprocess = slave/g' $CONF_SLAVE_FILE
207	fi
208	else
209	    echo "invalid function call 2"
210	    exit 1
211	fi
212
213	sed -i -e 's/__multiprocess//g' $CONF_FILE
214    fi
215    echo
216    cat $CONF_FILE
217}
218
219create_makefile()
220{
221    cd $CUR_DIR/samples
222    for d in * ; do
223	if [ -f $CUR_DIR/samples/$d/Makefile.in ]; then
224	    cp $CUR_DIR/samples/$d/Makefile.in $CUR_DIR/samples/$d/Makefile
225	    if [[ $1 == $FL_DPDK ]]; then
226		FMT=$(printf 's/__IO_LIB_ARGS/LIBS    += -m64 -g -pthread -lrt -march=native -Wl,-export-dynamic -L..\/..\/drivers\/dpdk\/lib -Wl,-lnuma -Wl,-lmtcp -Wl,-lpthread -Wl,-lrt -Wl,-ldl -Wl,$(shell cat ..\/..\/drivers\/dpdk\/lib\/ldflags.txt)/g')
227	    elif [[ $1 == $FL_PCAP ]]; then
228		FMT=$(printf 's/__IO_LIB_ARGS/GCC_OPT += -D__thread="" -DBE_RESILIENT_TO_PACKET_DROP\\nINC += -DENABLE_PCAP\\nLIBS += -lpcap/g')
229	    elif [[ $1 == $FL_NETMAP ]]; then
230		FMT=$(printf 's/__IO_LIB_ARGS/GCC_OPT += -DENABLE_NETMAP/g')
231	    fi
232	    sed -i -e "$FMT" $CUR_DIR/samples/$d/Makefile
233	fi
234    done
235}
236
237# Setup MOS library
238setup_mos_library() {
239    echo "Start building up the MOS library"
240    cd $CUR_DIR
241
242    if [[ $1 == $FL_DPDK ]]; then
243	mkdir -p $DPDK_DIR
244	rmdir $DPDK_DIR/include $DPDK_DIR/lib 2> /dev/null
245	rm $DPDK_DIR/include $DPDK_DIR/lib 2> /dev/null
246	ln -s $CUR_DIR/$RTE_SDK/$RTE_TARGET/include $DPDK_DIR/include
247	ln -s $CUR_DIR/$RTE_SDK/$RTE_TARGET/lib $DPDK_DIR/lib
248    	cd $CUR_DIR/scripts/
249	./configure --enable-dpdk
250    elif [[ $1 == $FL_PCAP ]]; then
251    	cd $CUR_DIR/scripts/
252	./configure --enable-pcap
253    elif [[ $1 == $FL_NETMAP ]]; then
254    	cd $CUR_DIR/scripts/
255	./configure --enable-netmap
256    fi
257    cd $CUR_DIR/core/src
258    make clean;make
259    cd $CUR_DIR
260    create_makefile $1
261    echo
262    echo "----------------------------------------------------------"
263    echo "Done with MOS library setup"
264    echo "----------------------------------------------------------"
265    echo
266}
267
268#############################################################################
269
270############################### DPDK Utilities ##############################
271# Creates hugepage filesystem.
272create_mnt_huge()
273{
274    echo "Creating /mnt/huge and mounting as hugetlbfs"
275    sudo mkdir -p /mnt/huge
276
277    grep -s '/mnt/huge' /proc/mounts > /dev/null
278    if [ $? -ne 0 ] ; then
279	sudo mount -t hugetlbfs nodev /mnt/huge
280    fi
281}
282
283# Removes hugepage filesystem.
284remove_mnt_huge()
285{
286    echo "Unmounting /mnt/huge and removing directory"
287    grep -s '/mnt/huge' /proc/mounts > /dev/null
288    if [ $? -eq 0 ] ; then
289	sudo umount /mnt/huge
290    fi
291
292    if [ -d /mnt/huge ] ; then
293	sudo rm -R /mnt/huge
294    fi
295}
296
297# Unloads igb_uio.ko.
298remove_igb_uio_module()
299{
300    echo "Unloading any existing DPDK UIO module"
301    /sbin/lsmod | grep -s igb_uio > /dev/null
302    if [ $? -eq 0 ] ; then
303	sudo /sbin/rmmod igb_uio
304    fi
305}
306
307# Loads new igb_uio.ko (and uio module if needed).
308load_igb_uio_module()
309{
310    if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko ];then
311	echo "## ERROR: Target does not have the DPDK UIO Kernel Module."
312	echo "       To fix, please try to rebuild target."
313	return
314    fi
315
316    remove_igb_uio_module
317
318    /sbin/lsmod | grep -s uio > /dev/null
319    if [ $? -ne 0 ] ; then
320	modinfo uio > /dev/null
321	if [ $? -eq 0 ]; then
322	    echo "Loading uio module"
323	    sudo /sbin/modprobe uio
324	fi
325    fi
326
327    # UIO may be compiled into kernel, so it may not be an error if it can't
328    # be loaded.
329    echo "Loading DPDK UIO module"
330    sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko
331    if [ $? -ne 0 ] ; then
332	echo "## ERROR: Could not load kmod/igb_uio.ko."
333	quit
334    fi
335}
336
337# Removes all reserved hugepages.
338clear_numa_pages()
339{
340    echo > .echo_tmp
341    for d in /sys/devices/system/node/node? ; do
342	echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
343    done
344    echo "Removing currently reserved hugepages"
345    sudo sh .echo_tmp
346    rm -f .echo_tmp
347
348    remove_mnt_huge
349}
350# Removes all reserved hugepages.
351clear_non_numa_pages()
352{
353    echo > .echo_tmp
354	echo "echo 0 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp
355    echo "Removing currently reserved hugepages"
356    sudo sh .echo_tmp
357    rm -f .echo_tmp
358    remove_mnt_huge
359}
360
361#
362# Creates hugepages.
363#
364set_non_numa_pages_default()
365{
366	clear_non_numa_pages
367    echo > .echo_tmp
368	echo "Number of pages : 1024"
369
370	Pages=1024
371	echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
372
373    echo "Reserving hugepages"
374    sudo sh .echo_tmp
375    rm -f .echo_tmp
376
377    create_mnt_huge
378}
379
380#
381# Creates hugepages.
382#
383set_non_numa_pages()
384{
385
386	clear_non_numa_pages
387
388	echo ""
389	echo "  Input the number of 2MB pages"
390	echo "  Example: to have 128MB of hugepages available, enter '64' to"
391	echo "  reserve 64 * 2MB pages"
392	echo -n "Number of pages: "
393	read Pages
394
395	echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp
396
397	echo "Reserving hugepages"
398	sudo sh .echo_tmp
399	rm -f .echo_tmp
400
401	create_mnt_huge
402
403}
404
405# Creates hugepages on specific NUMA nodes.
406set_numa_pages_default()
407{
408	clear_numa_pages
409    echo > .echo_tmp
410    for d in /sys/devices/system/node/node? ; do
411	node=$(basename $d)
412	echo "Number of pages for $node: 1024"
413	Pages=1024
414	echo "echo $Pages > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
415    done
416    echo "Reserving hugepages"
417    sudo sh .echo_tmp
418    rm -f .echo_tmp
419
420    create_mnt_huge
421}
422
423# Creates hugepages on specific NUMA nodes.
424set_numa_pages()
425{
426	clear_numa_pages
427    echo ""
428    echo "  Input the number of 2MB pages for each node"
429    echo "  Example: to have 128MB of hugepages available per node,"
430    echo "  enter '64' to reserve 64 * 2MB pages on each node"
431
432    echo > .echo_tmp
433    for d in /sys/devices/system/node/node? ; do
434	node=$(basename $d)
435	echo -n "Number of pages for $node: "
436	read Pages
437	echo "echo $Pages > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
438    done
439    echo "Reserving hugepages"
440    sudo sh .echo_tmp
441    rm -f .echo_tmp
442
443    create_mnt_huge
444}
445
446# Uses dpdk-devbind.py to move devices to work with igb_uio
447bind_nics_to_igb_uio()
448{
449    if  /sbin/lsmod  | grep -q igb_uio ; then
450	${RTE_SDK}/tools/dpdk-devbind.py --status
451	echo ""
452	echo "Enter PCI address of device(s) to bind to IGB UIO driver (e.g., \"04:00.0 04:00.1\")."
453	echo -n "> "
454	read PCI_PATH
455
456
457	sudo ${RTE_SDK}/tools/dpdk-devbind.py -b igb_uio $PCI_PATH && echo "OK"
458    else
459	echo "# Please load the 'igb_uio' kernel module before querying or "
460	echo "# adjusting NIC device bindings"
461    fi
462}
463
464#
465# Uses dpdk-devbind.py to move devices to work with kernel drivers again
466#
467unbind_nics()
468{
469    DEVLIST=`ifconfig -s | grep -Eo '^[^ ]+' | tail -n+2`
470    for dev in $DEVLIST
471    do
472	echo $dev
473	if [[ "$dev" == dpdk* ]]; then
474	    sudo ifconfig $dev down
475	fi
476    done
477
478    ${RTE_SDK}/tools/dpdk-devbind.py --status
479    echo ""
480    echo -n "Enter PCI address of device to unbind: "
481    read PCI_PATH
482    echo ""
483    echo -n "Enter name of kernel driver to bind the device to: "
484    read DRV
485    sudo ${RTE_SDK}/tools/dpdk-devbind.py -b $DRV $PCI_PATH && echo "OK"
486}
487
488# Brings up the interface of DPDK devices up
489setup_iface_dpdk()
490{
491    # Create & configure /dev/dpdk-iface
492    sudo rm -rf /dev/dpdk-iface
493    sudo mknod /dev/dpdk-iface c 1110 0
494    sudo chmod 666 /dev/dpdk-iface
495
496    # First check whether igb_uio module is already loaded
497    MODULE="igb_uio"
498
499    if sudo lsmod | grep "$MODULE" &> /dev/null ; then
500	echo "$MODULE is loaded!"
501    else
502	echo "$MODULE is not loaded!"
503	exit 1
504    fi
505
506    # Next check how many devices are there in the system
507    counter=0
508    cd /sys/module/igb_uio/drivers/pci:igb_uio/
509    for i in *
510    do
511	if [[ $i == *":"* ]]
512	then
513	    let "counter=$counter + 1"
514	fi
515    done
516    cd $CUR_DIR
517
518    iter=0
519    # Configure each device (single-process version)
520    while [ $iter -lt $counter ]
521    do
522	while [ 1 ]; do
523	    echo
524	    echo "[dpdk$(($iter))] enter IP address[/mask] (e.g., 10.0.$iter.9[/24])"
525	    echo -n "> "
526	    read line
527	    ip_addr=`echo $line | awk -F '/' '{print $1}'`
528	    mask=`echo $line | awk -F '/' '{print $2}'`
529	    valid_ip_addr $ip_addr
530	    if [ $? -eq 0 ]; then
531		break
532	    fi
533	    echo "invalid IP address!" # continue
534	done
535	if [ "$mask" == "" ];then
536	    echo "sudo /sbin/ifconfig dpdk$(($iter)) $ip_addr up"
537	    sudo /sbin/ifconfig dpdk$(($iter)) $ip_addr up
538	else
539	    echo "sudo /sbin/ifconfig dpdk$(($iter)) $ip_addr/$mask up"
540	    sudo /sbin/ifconfig dpdk$(($iter)) $ip_addr/$mask up
541	fi
542	let "iter=$iter + 1"
543    done
544}
545#############################################################################
546
547############################### DPDK ########################################
548step0_func_dpdk()
549{
550	if [ -d "/sys/devices/system/node" ]; then
551		set_numa_pages_default
552	else
553		set_non_numa_pages_default
554	fi
555
556    step2_func_dpdk
557    step3_func_dpdk
558    step4_func_dpdk
559}
560step1_func_dpdk()
561{
562	if [ -d "/sys/devices/system/node" ]; then
563		set_numa_pages
564	else
565		set_non_numa_pages
566	fi
567}
568step2_func_dpdk()
569{
570    load_igb_uio_module
571    bind_nics_to_igb_uio
572}
573step3_func_dpdk()
574{
575    setup_iface_dpdk $last_octet
576}
577step4_func_dpdk()
578{
579    cd $CUR_DIR/samples
580    for d in * ; do
581	create_config $FL_DPDK "samples/$d/config" $d
582    done
583    echo
584    echo "------------------------------------------------"
585    echo "Done with configuration file setup."
586    echo "Use the arp command to add static ARP entries"
587    echo "------------------------------------------------"
588}
589step5_func_dpdk()
590{
591    unbind_nics
592}
593step6_func_dpdk()
594{
595    echo
596    exit 1
597}
598#############################################################################
599
600############################### PCAP ########################################
601step0_func_pcap()
602{
603    cd $CUR_DIR/samples
604    for d in * ; do
605	if [ -d $CUR_DIR/samples/$d/config ]; then
606	    create_config $FL_PCAP "samples/$d/config" $d
607	fi
608    done
609    echo
610    echo "------------------------------------------------"
611    echo "Done with configuration file setup."
612    echo "Use the arp command to add static ARP entries"
613    echo "------------------------------------------------"
614    exit 1
615}
616#############################################################################
617
618############################## NETMAP #######################################
619step0_func_netmap()
620{
621    cd $CUR_DIR/samples
622    for d in * ; do
623	if [ -d $CUR_DIR/samples/$d/config ]; then
624	    create_config $FL_NETMAP "samples/$d/config" $d
625	fi
626    done
627    echo
628    echo "------------------------------------------------"
629    echo "Done with configuration file setup."
630    echo "Use the arp command to add static ARP entries"
631    echo "------------------------------------------------"
632    exit 1
633}
634#############################################################################
635
636############################# Main Script ###################################
637export CUR_DIR=$PWD
638kerver=$(uname -r)
639
640if [ "$1" == "--compile-dpdk" ]; then
641    vercomp $kerver "2.6.33"
642    # if kernel version < 2.6.33
643    if [ "$?" == "2" ]; then
644	echo "[note] current kerner version ("$kerver") does not support DPDK"
645	exit 1
646    fi
647    # Build and install DPDK library
648    export DPDK_DIR="drivers/dpdk"
649    export RTE_SDK="drivers/dpdk-16.11"
650    export RTE_TARGET="x86_64-native-linuxapp-gcc"
651    export DESTDIR="."
652    echo
653    echo "Selected DPDK library to be used for MOS"
654    echo "----------------------------------------------------------"
655    echo " RTE_SDK exported as $RTE_SDK"
656    echo " RTE_TARGET exported as $RTE_TARGET"
657    echo "----------------------------------------------------------"
658    echo
659    echo -n "Press enter to continue ..."; read
660    cd $RTE_SDK
661    make install T=$RTE_TARGET
662    echo
663    echo -n "Done with DPDK setup. Press enter to start MOS setup ..."; read
664    # Build and compile MOS library
665    setup_mos_library $FL_DPDK
666
667elif [ "$1" == "--compile-pcap" ]; then
668    setup_mos_library $FL_PCAP
669
670elif [ "$1" == "--compile-netmap" ]; then
671    setup_mos_library $FL_NETMAP
672
673elif [ "$1" == "--run-dpdk" ]; then
674    export DPDK_DIR="drivers/dpdk"
675    export RTE_SDK="drivers/dpdk-16.11"
676    export RTE_TARGET="x86_64-native-linuxapp-gcc"
677    while [ 1 ]; do
678	clear
679	echo
680	echo "----------------------------------------------------------"
681	echo " Full setup (from start)"
682	echo "----------------------------------------------------------"
683	echo "[0] Full setup for running mOS with DPDK"
684	echo
685	echo "----------------------------------------------------------"
686	echo " Step-by-step setup for running mOS with DPDK"
687	echo "----------------------------------------------------------"
688	echo "[1] Setup hugepage mappings"
689	echo "[2] Load and bind Ethernet devices to IGB_UIO module"
690	echo "[3] Bring the interfaces up (DPDK devices)"
691	echo "[4] Create new MOS configuration files for sample apps"
692	echo "[5] Unbind dpdk-registered NICs"
693	echo
694	echo "[6] Exit script"
695	echo
696	echo -n "Option: "
697	read entry
698	if [ "$entry" ]; then
699	    step"$entry"_func_dpdk
700	    echo
701	    echo -n "Press enter to continue ..."; read
702	fi
703    done
704
705elif [ "$1" == "--run-pcap" ]; then
706    while [ 1 ]; do
707	clear
708	echo
709	echo "----------------------------------------------------------"
710	echo " Full setup (from start)"
711	echo "----------------------------------------------------------"
712	step0_func_pcap
713	echo
714	echo -n "Press enter to continue ..."; read
715    done
716
717elif [ "$1" == "--run-netmap" ]; then
718    while [ 1 ]; do
719	clear
720	echo
721	echo "----------------------------------------------------------"
722	echo " Full setup (from start)"
723	echo "----------------------------------------------------------"
724	step0_func_netmap
725	echo
726	echo -n "Press enter to continue ..."; read
727    done
728
729elif [ "$1" == "--cleanup" ]; then
730    find | grep mos.conf | xargs rm -f
731    find | grep log__* | xargs rm -f
732
733    for d in $CUR_DIR/samples/* ; do
734	cd $d
735	make clean > /dev/null 2> /dev/null
736	cd ..
737    done
738    cd ..
739    cd core/src
740    make clean > /dev/null 2> /dev/null
741    cd bpf
742    rm -rf *.o
743    cd ..
744    rm -rf .*.d
745    rm Makefile
746    cd ../..
747    find ./samples/ -name 'Makefile' | xargs rm -f
748    rm -f scripts/config.log scripts/config.status
749else
750    echo "[error] please specify one of the following options"
751    echo "--compile-dpdk   : compile and build mOS library with dpdk"
752    echo "--compile-pcap   : compile and build mOS library with pcap"
753    echo "--compile-netmap : compile and build mOS library with netmap"
754    echo "--run-dpdk       : setup environments and configurations for running applications with dpdk"
755    echo "--run-pcap       : setup environments and configurations for running applications with pcap"
756    echo "--run-netmap     : setup environments and configurations for running applications with netmap"
757    echo "--cleanup        : delete all binaries, config and Makefiles"
758fi
759