Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONLabTest
diff --git a/TestON/dependencies/loadgen_SB.py b/TestON/dependencies/loadgen_SB.py
new file mode 100755
index 0000000..cfd2adf
--- /dev/null
+++ b/TestON/dependencies/loadgen_SB.py
@@ -0,0 +1,117 @@
+#!/usr/bin/python
+
+"""
+This example shows how to create an empty Mininet object
+(without a topology object) and add nodes to it manually.
+"""
+import sys
+import subprocess
+import time
+from mininet.net import Mininet
+from mininet.node import Controller
+from mininet.cli import CLI
+from mininet.log import setLogLevel, info
+
+swlist = []
+hostlist= []
+count = 0 
+
+def createSwPorts(numsw, numport):
+
+    "Create an empty network and add nodes to it."
+
+    net = Mininet()
+    swlist = []
+    hostlist= []
+    print ("Starting Mininet Network....")
+    for i in range(numsw):
+        sw = net.addSwitch( 's' + str(i), dpid = ('00000000000000' + '%0d'%i))
+        print str(sw),
+        for p in range(numport):
+            host = net.addHost("s"+str(i)+"h"+str(p))
+            hostlist.append(host)
+            print str(host),
+            net.addLink(host,sw)
+        swlist.append(sw)
+
+            
+    info( '*** Starting network\n')
+    net.start()
+
+    return swlist
+
+def loadsw(urllist, swlist, addrate, delrate, duration):
+    global numport
+    urlindex = 0
+    count = 0
+    addsleeptimer = 1.000 /addrate
+    delsleeptimer = 1.000/delrate
+    print (" Add sleeptimer: " + str('%.3f' %addsleeptimer) + "; Delete sleeptimer: " + str('%.3f' %delsleeptimer))
+    print str(swlist)
+ 
+    tstart = time.time()
+    while ( (time.time() - tstart) <= duration ):
+        #print (time.time() - tstart)
+        astart = time.time()
+        for sw in swlist:
+            if urlindex < len(urllist):
+                i = urlindex
+            else:
+                i = 0
+                urlindex = 0
+        
+            ovscmd = "sudo ovs-vsctl set-controller " + str(sw) + " tcp:" + urllist[i]
+            print ("a"),
+            s = subprocess.Popen(ovscmd, shell=True )
+            time.sleep(addsleeptimer)
+            count += 1
+            urlindex += 1
+        aelapse = time.time() - astart
+        print ("Number of switches connected: " + str(len(swlist)) + " in: " + str('%.3f' %aelapse) + "seconds.")
+
+        dstart = time.time()
+        for sw in swlist:
+            ovscmd = "sudo ovs-vsctl set-controller " + str(sw) + " tcp:127.0.0.1:6633"
+            print ("d"),
+            s = subprocess.Popen(ovscmd, shell=True )
+            time.sleep(delsleeptimer)
+            count += 1
+        delapse = time.time() - dstart
+        print ("Number of switches disconnected: " + str(len(swlist)) + " in: " + str('%.3f' %delapse) + "seconds.")
+    telapse = time.time() - tstart
+    
+    return telapse, count
+def cleanMN():
+    print ("Cleaning MN switches...")
+    s = subprocess.Popen("sudo mn -c > /dev/null 2>&1", shell=True)
+    print ("Done.")
+
+def main():
+    import argparse
+    import threading
+    from threading import Thread
+
+    parser = argparse.ArgumentParser(description="less script")
+    parser.add_argument("-u", "--urls", dest="urls", default="10.128.10.1", type=str, help="a string to show urls to post intents to separated by space, ex. '10.128.10.1:6633 10.128.10.2:6633' ")
+    parser.add_argument("-s", "--switches", dest="numsw", default=100, type=int, help="number of switches use in the load generator; together with the ports per switch config, each switch generates (numport + 2) events")
+    parser.add_argument("-p", "--ports", dest="numport", default=1, type=int, help="number of ports per switches")
+    parser.add_argument("-a", "--addrate", dest="addrate", default=10, type=float, help="rate to add intents groups, groups per second")
+    parser.add_argument("-d", "--delrate", dest="delrate", default=100, type=float, help= "rate to delete intents, intents/second")
+    parser.add_argument("-l", "--testlength", dest="duration", default=0, type=int, help= "pausing time between add and delete of intents")
+    args = parser.parse_args()
+
+    urllist = args.urls.split()
+    numsw = args.numsw
+    numport = args.numport
+    addrate = args.addrate
+    delrate = args.delrate
+    duration = args.duration
+    setLogLevel( 'info' )
+    swlist = createSwPorts(numsw,numport)
+    telapse,count = loadsw(urllist, swlist, addrate, delrate, duration)
+    print ("Total number of switches connected/disconnected: " + str(count) + "; Total events generated: " + str(count * (2 + numport)) + "; Elalpse time: " + str('%.1f' %telapse))
+    print ("Effective aggregated loading is: " + str('%.1f' %((( count * (2+ numport))) / telapse ) ) + "Events/s.")
+    cleanMN()
+
+if __name__ == '__main__':
+    main()
diff --git a/TestON/dependencies/loadgen_SB.sh b/TestON/dependencies/loadgen_SB.sh
deleted file mode 100755
index 41b12fd..0000000
--- a/TestON/dependencies/loadgen_SB.sh
+++ /dev/null
@@ -1,153 +0,0 @@
-#!/bin/bash
-'''
-This is the southbound load generator to generator topology events for tests, such as scale-out and performance testing. 
-Example 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." 
-'''
-
-case "$1" in
-	addsw)
-		numsw=$2
-		;;
-	delsw)
-		numsw=$2
-        ;;
-    startload)
-		list_ctrl=$2;numsw=$3;numport=$4;rate=$5;duration=$6;prefix_dpid=$7
-        sleeptimer=$(echo "scale=4; (1/$rate)"|bc)
-        ;;
-    chksw)
-		numsw=$2
-        ;;
-    *)
-        #echo "Enter action:"
-        #echo "addsw number_switches - addsw 200"
-        #echo "delsw number_switches - delsw 200"
-        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"
-		echo "prefix_dpid is the first two octect of dpid in hex, such as "11", or "aa"."
-		echo "This command will first add numb_of_switches to OVSDB; then generate the load as configured; when finished, delete all switches from OVSDB."
-        #echo "chsw num_switches - chsw 200 #get all switches and their current controller connection"
-        exit 1
-esac
-
-add-ovs () 
-{
-	for ((i=1;i<=$numsw;i++))
-    	do      
-    		str=$(printf '%014X' $i); dpid=$prefix_dpid$str
-			echo "adding ovs switch s$i"
-        	sudo ovs-vsctl add-br "s"$i
-			sudo ovs-vsctl set bridge "s"$i other-config:datapath-id=$dpid
-            
-            #echo "adding $numport dataplane ports to switch s$i ... "
-			for ((p=1; p<=$numport; p++))
-				do
-				echo "adding port $p to switch s$i ... "
-				sudo ovs-vsctl add-port "s"$i "s"$i"p"$p
-            done
-	done
-}
-
-del-ovs () 
-{
-	for ((i=1;i<=$numsw;i++))
-        do
-                #echo "deleting ovs switch s$i"
-                sudo ovs-vsctl del-br "s"$i 
-        done
-}
-
-conn-ovs () 
-{
-	i=1
-	while (($i<=$numsw)) 
-	do 
-		for ctrl_port in ${list_ctrl[@]}
-		do
-			if (($i!=0))
-			then
-				#ovsctrl="tcp:"$ctrl_port
-				#echo  "s"$i
-				sudo ovs-vsctl --no-wait --no-syslog set-controller "s"$i "tcp:"$ctrl_port & 
-				let i+=1
-				sleep $sleeptimer
-			fi
-		done
-	done
-}
-
-disconn-ovs () 
-{
-	i=1
-    while (($i<=$numsw)) 
-    do
-		ovsctrl="tcp:127.0.0.1:10000"
-        #echo  "s"$i
-        sudo ovs-vsctl --no-wait set-controller "s"$i $ovsctrl &
-        let i+=1
-        sleep $sleeptimer
-    done
-}
-
-get-ovs ()
-{
-    i=$numsw
-    while (($i>0)) 
-    do
-        echo "s"$i
-		sudo ovs-vsctl get-controller "s"$i
-        let i-=1
-    done
-
-}
-
-loadsw ()
-{
-	echo "adding $numsw ovs switches..."
-	add-ovs
-
-	echo "starting to generate south bound load ...."
-    	let "roundtime = numsw / rate"
-	#let "iter = duration / roundtime / 2 "
-    iter=1
-	echo "Running load for $duration seconds..."
-    start=$(date +%s )
-	time while [[ $(( $(date +%s) - start )) -lt $duration ]]
-    do
-		#echo "start time is: $start"
-		#echo "current time is: $(date +%s)"
-  		#echo "diff is: $(($(date +%s) - $start ))"
-		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."
-		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."
-		let "iter = iter + 1"
-	done
-    echo "Iteration is: $iter"
-	let "total = (( iter * numsw * (numport + 2))) "
-	echo "************************** "
-    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."
-	echo "**************************"
-	echo ""
-	echo "deleting $numsw ovs switches ..."
-	del-ovs
-}
-
-case "$1" in
-    addsw)
-        time add-ovs
-        ;;
-    delsw)
-        time del-ovs
-        ;;
-    startload)
-		echo $sleeptimer
-        time loadsw
-        ;;
-    chksw)
-        time get-ovs
-        ;;
-    #*)    
-    #exit 1
-esac
-
-
-
-