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