In testing and validation is common to generate traffic between Azure VMs. The article shows few methods to generate traffic between two Azure VMs, vm1 and vm2, connected to the the same Azure subnet. The methods to generate traffic can be used between private and/or public IPs.
Note
Before spinning up the ARM template you should edit the file vms.ps1 and set:
- your Azure subscription name in the variable $subscriptionName
- the administrator username and password of the Azure VMs in the variables $adminUsername, $adminPassword
Iperf3 works in Linux and Windows (see: iperf3)
To install iperf3 in Linux VM:
yum -y iperf3
To run iperf3 as server in vm2:
iperf3 -s -p 6001
where -p specifices the listening TCP port
To run iperf3 as client in vm2:
iperf3 -c 10.0.2.10 -P 20 -p 6001 -i 1 -f M
where: -P: total number of simultaneos TCP flows -p: TCP port -M: formatting the output in Mbps
In Linux VMs traffic can be generated by netcat and urandom (the random number function in the linux kernel).
Install netcat (nc) in vm1 and vm2:
yum -y install nmap-ncat
Write down two bash scripts: one for the server (traffic receiver) and one for the client (traffic sender).
file in vm1: server.sh
#!/bin/bash
#
val=true
while [ $val ]
do
nc -l -p 9000 > /dev/null 2>&1
wait
done
file in vm2: client.sh
#!/bin/bash
#
for i in {1..10};
do
dd if=/dev/urandom bs=1M count=100 | nc 10.0.2.10 9000
sleep 2
done
To send traffic from vm2 to vm1 run:
[root@vm1 ~]# ./server.sh
[root@vm2 ~]# ./client.sh
By tcpdump check the traffic:
[root@vm1 ~]# tcpdump -nqttt -i eth0 host 10.0.1.10 and host 10.0.1.20
In Linux there are many tools to monitor the network traffic; nload is one you can use:
yum install epel-release
yum -y install nload
Apache Bench tool is used to do simple load testing. Apache Bench is contained in the httpd-tools package.
yum install httpd-tools
ab -n 500 -c 20 10.0.1.10
where: n: total number of requests c: number of concurrent requests
Run the bash command:
for i in `seq 1 20`; do curl http://10.0.2.10; done
To run HTTP queries in parallel, it can be used GNU parallel. In CentOS GNU parallel is in EPEL repository:
yum -y install epel-release
yum -y install parallel
vi client.sh
#!/bin/bash
#redirect stdout to the device /dev/null
mycurl() {
START=$(date +%s)
curl -s "http://some_url_here/"$1 1>/dev/null
END=$(date +%s)
DIFF=$(( $END - $START ))
echo "It took $DIFF seconds"
}
export -f mycurl
seq 100000 | parallel -j0 mycurl
- Replace the "some_url_here" with the IP address of web server.
- -s option is for silent or quiet mode.
Same command with easier option:
seq 5000 | parallel -n0 -j5 curl http://10.0.1.10/
it runs the command 5000 times, at 5 a time.
$ipServer="10.0.2.10:80"
$url = "http://$ipServer"
while ($true) {
try {
[net.httpWebRequest]
$req = [net.webRequest]::create($url)
$req.method = "GET"
$req.ContentType = "application/x-www-form-urlencoded"
$req.TimeOut = 60000
$start = get-date
[net.httpWebResponse] $res = $req.getResponse()
$timetaken = ((get-date) - $start).TotalMilliseconds
Write-Output $res.Content
Write-Output ("{0} {1} {2}" -f (get-date), $res.StatusCode.value__, $timetaken)
$req = $null
$res.Close()
$res = $null
} catch [Exception] {
Write-Output ("{0} {1}" -f (get-date), $_.ToString())
}
$req = $null
# uncomment the line below and change the wait time to add a pause between requests
#Start-Sleep -Seconds 1
}
Traffic counters in the VMs we can track by a tool like iftop:
#yum -y install libpcap libpcap-devel ncurses ncurses-devel
#yum -y install epel-release
#yum -y install iftop
Install Apache:
yum -y install httpd
systemctl enable httpd
systemctl start httpd
systemctl status httpd
curl 27.0.0.1
In CentOS nginx is available in EPEL repository:
yum install epel-release
yum -y install nginx
systemctl enable nginx
systemctl start nginx
systemctl status nginx
curl 127.0.0.1