Skip to content

Instantly share code, notes, and snippets.

@deathbeam
Last active October 25, 2016 11:32
Show Gist options
  • Select an option

  • Save deathbeam/dd898b467a37e6ed8b6c9e80daefb901 to your computer and use it in GitHub Desktop.

Select an option

Save deathbeam/dd898b467a37e6ed8b6c9e80daefb901 to your computer and use it in GitHub Desktop.
Performance testing script using Openflowplugin Bulk-O-Matic to test 3 different paths for adding flows
#!/bin/bash
# Helper function that will convert seconds to hours, minutes and seconds
convertsecs() {
((h=${1}/3600))
((m=(${1}%3600)/60))
((s=${1}%60))
printf "%02d:%02d:%02d\n" $h $m $s
}
# Default values and constants
firstflownumber=500
loopdelay=10
numruns=10
userflows=1000
controllerip="127.0.0.1:8181"
dosendflows=true
logfilepath="distribution/karaf/target/assembly/data/log/karaf.log"
flowtype="NORMAL"
while getopts ":hf:c:r:w:p:t:s" opt; do
case $opt in
h)
echo "Usage:"
echo -e "\t-h\t\t show this message"
echo -e "\t-s\t\t skip adding flows, only process logs"
echo -e "\t-t <flow_type>\t flow type used for performance tests, can be NORMAL/DIRECT/RAW (NORMAL)"
echo -e "\t-p <log_path>\t path to karaf log file (distribution/karaf/target/assembly/data/log/karaf.log)"
echo -e "\t-f <num_flows>\t total number of flows added per loop (1000)"
echo -e "\t-r <num_runs>\t how many runs should test do, higher is better for accuracy (10)"
echo -e "\t-c <address>\t address of controller (127.0.0.1:8181)"
echo -e "\t-w <wait_time>\t how many seconds should test wait between each run (30)"
exit 1
;;
p)
logfilepath="$OPTARG"
;;
t)
flowtype="$OPTARG"
;;
s)
dosendflows=false
;;
w)
loopdelay="$OPTARG"
;;
r)
numruns="$OPTARG"
;;
c)
controllerip="$OPTARG"
;;
f)
userflows="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
testdur=$(($numruns * $loopdelay))
if [[ $dosendflows = true ]]; then
echo "> Adding $userflows $flowtype flows $numruns times"
bulk_json="{\"input\":{\"sal-bulk-flow:type\":\"$flowtype\",\"sal-bulk-flow:flow-count\":\"$userflows\",\"sal-bulk-flow:rpc-batch-size\":\"$userflows\"}}"
for i in $(seq 1 $numruns); do
echo " Run $i of $numruns"
restresult=$(curl -H "Content-Type: application/json" -H "Accept: application/json" -u "admin:admin" -m "30" -v -d "$bulk_json" "$controllerip/restconf/operations/sal-bulk-flow:flow-rpc-add-multiple" 2>&1 | grep "< HTTP")
echo " ${restresult:2}"
echo " $(convertsecs $testdur) remaining"
testdur=$((testdur - $loopdelay))
sleep "$loopdelay"
done
fi
echo "> Processing '$logfilepath'"
# Find ID of last flow
lastflowid=$(expr $firstflownumber + $userflows)
# Create temporary file with only relevant log data
cat "$logfilepath" | grep -E '(FlowWriterDirectOFRpc)|(SalFlowServiceImpl)' > temp.log
# Find all relevant data
flowstartdata="$(cat "temp.log" | grep "FlowWriterDirectOFRpc" | grep "FlowRPCTaskHandler $flowtype")"
flowenddata="$(cat "temp.log" | grep "SalFlowServiceImpl" | grep "$flowtype flow add with id=$lastflowid")"
linenums="$(echo "$flowstartdata" | wc -l)"
datematcher="[0-9-]+ [0-9:,]+"
numflows=0
totalflows=0
# Loop over each line in each data output
echo -e " run #\tdur"
for i in $(seq 1 $linenums); do
flowstartline=$(echo "$flowstartdata" | sed -n "$i"p)
flowendline=$(echo "$flowenddata" | sed -n "$i"p)
startdate=""
enddate=""
if [[ "$flowstartline" =~ $datematcher ]]; then
startdate="${BASH_REMATCH[0]}"
fi
if [[ "$flowendline" =~ $datematcher ]]; then
enddate="${BASH_REMATCH[0]}"
fi
datemillis=$(($(($(date -d "$enddate" "+%s%N") - $(date -d "$startdate" "+%s%N"))) / 1000000))
if [[ $i -gt 1 ]]; then
numflows=$(expr $numflows + 1)
totalflows=$(expr $totalflows + $datemillis)
echo -e " $i\t$datemillis"
else
echo -e " $i\t$datemillis\t(warmup)"
fi
done
# Compute some sane numbers from results
avgflows=$(expr $totalflows / $numflows)
echo ""
echo " total: $totalflows"
echo " average: $avgflows"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment