blob: 41b12fd8f283afd15eb9274b9dedbc7fa288a20d [file] [log] [blame]
suibin-onlab0fe99db2014-08-05 15:14:51 -07001#!/bin/bash
2'''
3This is the southbound load generator to generator topology events for tests, such as scale-out and performance testing.
4Example command: ./loadgen_SB.sh startload "1.1.1.1:6633 2.2.2.2:6633" 100 4 100 300 11 - will have 100 switches RR connection to the list of controllers. There will be 4 dataplane ports per switch; switch connection rate (aggregated) is 100 switch/second; duration is 300 seconds; "11" is used as part of the dpid to distinguish switch generated from multiple instances of this generator. Switch disconnnect will use "127.0.0.1:10000" as its connection."
5'''
6
7case "$1" in
8 addsw)
9 numsw=$2
10 ;;
11 delsw)
12 numsw=$2
13 ;;
14 startload)
15 list_ctrl=$2;numsw=$3;numport=$4;rate=$5;duration=$6;prefix_dpid=$7
16 sleeptimer=$(echo "scale=4; (1/$rate)"|bc)
17 ;;
18 chksw)
19 numsw=$2
20 ;;
21 *)
22 #echo "Enter action:"
23 #echo "addsw number_switches - addsw 200"
24 #echo "delsw number_switches - delsw 200"
25 echo "startload list of controllers numsw numportPerSW rate(#/s) duration(s) dpid_prefix - startload "1.1.1.1 2.2.2.2 3.3.3.3" 100 4 10 300 11 #switches will be evenly spread to those controllers"
26 echo "prefix_dpid is the first two octect of dpid in hex, such as "11", or "aa"."
27 echo "This command will first add numb_of_switches to OVSDB; then generate the load as configured; when finished, delete all switches from OVSDB."
28 #echo "chsw num_switches - chsw 200 #get all switches and their current controller connection"
29 exit 1
30esac
31
32add-ovs ()
33{
34 for ((i=1;i<=$numsw;i++))
35 do
36 str=$(printf '%014X' $i); dpid=$prefix_dpid$str
37 echo "adding ovs switch s$i"
38 sudo ovs-vsctl add-br "s"$i
39 sudo ovs-vsctl set bridge "s"$i other-config:datapath-id=$dpid
40
41 #echo "adding $numport dataplane ports to switch s$i ... "
42 for ((p=1; p<=$numport; p++))
43 do
44 echo "adding port $p to switch s$i ... "
45 sudo ovs-vsctl add-port "s"$i "s"$i"p"$p
46 done
47 done
48}
49
50del-ovs ()
51{
52 for ((i=1;i<=$numsw;i++))
53 do
54 #echo "deleting ovs switch s$i"
55 sudo ovs-vsctl del-br "s"$i
56 done
57}
58
59conn-ovs ()
60{
61 i=1
62 while (($i<=$numsw))
63 do
64 for ctrl_port in ${list_ctrl[@]}
65 do
66 if (($i!=0))
67 then
68 #ovsctrl="tcp:"$ctrl_port
69 #echo "s"$i
70 sudo ovs-vsctl --no-wait --no-syslog set-controller "s"$i "tcp:"$ctrl_port &
71 let i+=1
72 sleep $sleeptimer
73 fi
74 done
75 done
76}
77
78disconn-ovs ()
79{
80 i=1
81 while (($i<=$numsw))
82 do
83 ovsctrl="tcp:127.0.0.1:10000"
84 #echo "s"$i
85 sudo ovs-vsctl --no-wait set-controller "s"$i $ovsctrl &
86 let i+=1
87 sleep $sleeptimer
88 done
89}
90
91get-ovs ()
92{
93 i=$numsw
94 while (($i>0))
95 do
96 echo "s"$i
97 sudo ovs-vsctl get-controller "s"$i
98 let i-=1
99 done
100
101}
102
103loadsw ()
104{
105 echo "adding $numsw ovs switches..."
106 add-ovs
107
108 echo "starting to generate south bound load ...."
109 let "roundtime = numsw / rate"
110 #let "iter = duration / roundtime / 2 "
111 iter=1
112 echo "Running load for $duration seconds..."
113 start=$(date +%s )
114 time while [[ $(( $(date +%s) - start )) -lt $duration ]]
115 do
116 #echo "start time is: $start"
117 #echo "current time is: $(date +%s)"
118 #echo "diff is: $(($(date +%s) - $start ))"
119 time conn-ovs; echo "Number of switches connected: $numsw. Events generated: $(( ($numport + 2) * $numsw )) - each switch added generates one switch event, one default port event, and $numport dataplane port events."
120 time disconn-ovs; echo "Number of switches disconnected: $numsw. Events generated: $(( ($numport + 2) * $numsw )) - each switch added generates one switch event, one default port event, and $numport dataplane port events."
121 let "iter = iter + 1"
122 done
123 echo "Iteration is: $iter"
124 let "total = (( iter * numsw * (numport + 2))) "
125 echo "************************** "
126 echo "Total number of switches connected/disconnected: $(( iter * numsw * 2 )). Total events generated: $(( 2 * total)) - each switch added generates one switch event, one default port event, and $numport dataplane port events."
127 echo "**************************"
128 echo ""
129 echo "deleting $numsw ovs switches ..."
130 del-ovs
131}
132
133case "$1" in
134 addsw)
135 time add-ovs
136 ;;
137 delsw)
138 time del-ovs
139 ;;
140 startload)
141 echo $sleeptimer
142 time loadsw
143 ;;
144 chksw)
145 time get-ovs
146 ;;
147 #*)
148 #exit 1
149esac
150
151
152
153