pktgen.sh 5.43 KB
Newer Older
1
2
3
4
5
6
#! /bin/bash

SIMBRICKS_DIR="/DS/endhost-networking/work/sim/hejing/simbricks"
RUN_DIR="/tmp/hejing-work/pktgen"
NUM_HOST=$1
ALL_PIDS=""
Hejing Li's avatar
Hejing Li committed
7
PKTGEN_PIDS=""
Hejing Li's avatar
Hejing Li committed
8
SWITCH_PIDS=""
9
10
11
12
# -inst num
run_pktgen(){
    echo "starting host $1"
    PKTGEN_EXE=/DS/endhost-networking/work/sim/hejing/simbricks/sims/net/pktgen/pktgen
Hejing Li's avatar
Hejing Li committed
13
    $PKTGEN_EXE -m 0 -S 500 -E 500 -n $1 -h $RUN_DIR/eth.$1 &
14
15
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
Hejing Li's avatar
Hejing Li committed
16
    PKTGEN_PIDS="$PKTGEN_PIDS $pid"
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
    return $pid
}

# -num host connected
run_switch(){
    echo "Starting switch"
    SWITCH_EXE=/DS/endhost-networking/work/sim/hejing/simbricks/sims/net/switch/net_switch
    args=""
    iface=0
    while [ $iface -lt $1 ]
    do
        args="$args -s $RUN_DIR/eth.$iface"
        ((iface++))
    done
    $SWITCH_EXE -m 0 -S 500 -E 500 \
    $args > $RUN_DIR/log.switch &

    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    return $pid
}

Hejing Li's avatar
Hejing Li committed
39
# - number of hosts
Hejing Li's avatar
Hejing Li committed
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
run_switch_dumbbell(){
    echo "Starting switch dumbbell"
    SWITCH_EXE=/DS/endhost-networking/work/sim/hejing/simbricks/sims/net/switch/net_switch
    args_0=""
    args_1=""
    iface=0
    half=$(($1/2))
    while [ $iface -lt $half ]
    do
        args_0="$args_0 -s $RUN_DIR/eth.$iface"
        #((iface+=2))
        ((iface+=1))
    done

    #iface=1

    #num_inc=$(($1+1))
    #while [ $iface -lt $num_inc ]
    while [ $iface -lt $1 ]
    do
        args_1="$args_1 -s $RUN_DIR/eth.$iface"
        #((iface+=2))
        ((iface+=1))
    done
    $SWITCH_EXE -m 0 -S 500 -E 500 \
    $args_0 -h $RUN_DIR/s0eth > $RUN_DIR/log.switch &

    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    SWITCH_PIDS="$SWITCH_PIDS $pid"
    sleep 1

    $SWITCH_EXE -m 0 -S 500 -E 500 \
    $args_1 -s $RUN_DIR/s0eth > $RUN_DIR/log.switch &
    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    SWITCH_PIDS="$SWITCH_PIDS $pid"

    return $pid
}

Hejing Li's avatar
Hejing Li committed
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
# - number of hosts
# - number of middle switch
run_switch_chain(){
    echo "Starting switch chain"
    SWITCH_EXE=/DS/endhost-networking/work/sim/hejing/simbricks/sims/net/switch/net_switch
    args_0=""
    args_1=""
    iface=0
    half=$(($1/2))
    while [ $iface -lt $half ]
    do
        args_0="$args_0 -s $RUN_DIR/eth.$iface"
        #((iface+=2))
        ((iface+=1))
    done

    #iface=1

    #num_inc=$(($1+1))
    #while [ $iface -lt $num_inc ]
    while [ $iface -lt $1 ]
    do
        args_1="$args_1 -s $RUN_DIR/eth.$iface"
        #((iface+=2))
        ((iface+=1))
    done

    nswitch=0
    nums_dec=$(($2-1))
    
    while [ $nswitch -lt $2 ]
    do
        pswitch=$(($nswitch-1))
        #the first 
        if [ $nswitch -eq 0 ]
        then
            $SWITCH_EXE -m 0 -S 500 -E 500 \
            $args_0 -h $RUN_DIR/s0eth > $RUN_DIR/switch_${nswitch}.log &

            pid=$!
            ALL_PIDS="$ALL_PIDS $pid"
            SWITCH_PIDS="$SWITCH_PIDS $pid"
            sleep 1
        #the last
        elif [ $nswitch -eq $nums_dec ]      
        then
            $SWITCH_EXE -m 0 -S 500 -E 500 \
            $args_1 -s $RUN_DIR/s${pswitch}eth > $RUN_DIR/switch_${nswitch}.log &
            pid=$!
            ALL_PIDS="$ALL_PIDS $pid"
            SWITCH_PIDS="$SWITCH_PIDS $pid"
        else
            $SWITCH_EXE -m 0 -S 500 -E 500 \
            -s $RUN_DIR/s${pswitch}eth -h $RUN_DIR/s${nswitch}eth > $RUN_DIR/switch_${nswitch}.log &
            pid=$!
            ALL_PIDS="$ALL_PIDS $pid"
            SWITCH_PIDS="$SWITCH_PIDS $pid"
            sleep 1
        fi

        ((nswitch++))
    done

    return
}

Hejing Li's avatar
Hejing Li committed
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

# - number of hosts
# - number of layers should >= 2
run_switch_hierarchy(){
    echo "Starting switch hierarchy"
    SWITCH_EXE=/DS/endhost-networking/work/sim/hejing/simbricks/sims/net/switch/net_switch
    
    
    layer=1
    #leave switch
    iface=0
    
    while [ $iface -lt $1 ]
    do
        $SWITCH_EXE -m 0 -S 500 -E 500 \
        -h $RUN_DIR/s${layer}.$iface -s $RUN_DIR/eth.${iface}> $RUN_DIR/s${layer}.${iface}.log &
            
        pid=$!
        ALL_PIDS="$ALL_PIDS $pid"
        SWITCH_PIDS="$SWITCH_PIDS $pid"
        ((iface++))
    done 

    ((layer++))
    sleep 2
    #node switch
    while [ $layer -lt $2 ]
    do
        iface=0
        layer_dec=$(($layer-1))
        while [ $iface -lt $1 ]
        do
            $SWITCH_EXE -m 0 -S 500 -E 500 \
            -s $RUN_DIR/s${layer_dec}.$iface -h  $RUN_DIR/s${layer}.$iface > $RUN_DIR/s${layer}.${iface}.log &
            
            pid=$!
            ALL_PIDS="$ALL_PIDS $pid"
            SWITCH_PIDS="$SWITCH_PIDS $pid"
            ((iface++))
        done

        ((layer++))
        sleep 2
    done
    #root switch
    args=""
    iface=0
    layer_dec=$(($layer-1))
    while [ $iface -lt $1 ]
    do
        args="$args -s $RUN_DIR/s${layer_dec}.$iface"
        ((iface++))
    done
    $SWITCH_EXE -m 0 -S 500 -E 500 \
    $args > $RUN_DIR/root_switch.log &

    pid=$!
    ALL_PIDS="$ALL_PIDS $pid"
    SWITCH_PIDS="$SWITCH_PIDS $pid"
}

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
cleanup() {
    echo "Cleaning up"

    for p in $ALL_PIDS ; do
        kill -KILL $p &>/dev/null
    done
    date
}

sighandler(){
    echo "caught Interrup, aborting..."
    cleanup
    date
    exit 1
}

trap "sighandler" SIGINT
Hejing Li's avatar
Hejing Li committed
225
226
227

echo -n "start: "
date +%s
228
229
230
231
232
233
234
235
236
237
rm -rf $RUN_DIR
mkdir -p $RUN_DIR
r=0
while [ $r -lt $1 ]
do
    run_pktgen $r
    ((r++))
done

sleep 2
Hejing Li's avatar
Hejing Li committed
238
239
#run_switch $1
#SWITCH_PID=$!
Hejing Li's avatar
Hejing Li committed
240
241
242
#run_switch_dumbbell $1
#run_switch_chain $1 $2
run_switch_hierarchy $1 $2
Hejing Li's avatar
Hejing Li committed
243
244
245
246
247

for p in $PKTGEN_PIDS ; do
    wait $p
done

Hejing Li's avatar
Hejing Li committed
248
249
250
251
252
253
echo "Pktgen Done, kill switch"
#kill -9 $SWITCH_PID

for p in $SWITCH_PIDS ; do
    kill -9 $p
done
Hejing Li's avatar
Hejing Li committed
254
255
echo -n "end: "
date +%s