#!/bin/bash # Define variables user="root" # Replace "username" with your SSH username host1="apu00" # Replace "host1.example.com" with the hostname or IP address of the first Linux computer host2="apu01" # Replace "host2.example.com" with the hostname or IP address of the second Linux computer mesh0_ip="192.168.10.10" mesh1_ip="192.168.20.10" interface1="mesh0" # Replace "eth0" with the specific interface you want to use for the measurement interface2="mesh1" # Replace "eth0" with the specific interface you want to use for the measurement measurement_time=10 # Measurement time in seconds csv_file="iperf_all_nodes.csv" echo "start" # SSH connection and iperf3 measurement ssh $user@$host1 "iperf3 -s --bind $mesh0_ip > /dev/null 2>&1 &" # Start iperf3 server in daemon mode on host1 ssh $user@$host1 "iperf3 -s --bind $mesh1_ip > /dev/null 2>&1 &" # Start iperf3 server in daemon mode on host1 # sleep $measurement_time # Wait for the measurement to complete echo "server started" sleep 2 output_file1=$(mktemp) output_file2=$(mktemp) echo "start clients" # iperf_output1=$(ssh $user@$host2 "iperf3 -c $mesh0_ip -t $measurement_time 2>&1") & # Start iperf3 client on host2, specifying the interface and measurement time, and redirect stderr to stdout # pid1=$! # iperf_output2=$(ssh $user@$host2 "iperf3 -c $mesh1_ip -t $measurement_time 2>&1") & # Start iperf3 client on host2, specifying the interface and measurement time, and redirect stderr to stdout # pid2=$! ssh $user@$host2 "iperf3 -c $mesh0_ip -t $measurement_time" > $output_file1 2>&1 & # Start iperf3 client on host2, specifying the interface and measurement time, and redirect stderr to stdout pid1=$! ssh $user@$host2 "iperf3 -c $mesh1_ip -t $measurement_time" > $output_file2 2>&1 & # Start iperf3 client on host2, specifying the interface and measurement time, and redirect stderr to stdout pid2=$! wait $pid1 wait $pid2 # Read the outputs from the temporary files iperf_output1=$(cat $output_file1) iperf_output2=$(cat $output_file2) echo "done measurement" # echo "iperf output 1:" # echo "$iperf_output1" # echo "iperf output 2:" # echo "$iperf_output2" # Extract throughput information throughput_info1=$(echo "$iperf_output1" | grep -oP '\d+\.\d+(?=\s+Mbits/sec)') throughput_info2=$(echo "$iperf_output2" | grep -oP '\d+\.\d+(?=\s+Mbits/sec)') # Extracting min, max, and average throughput min_throughput1=$(echo "$throughput_info1" | sort -n | head -n 1) max_throughput1=$(echo "$throughput_info1" | sort -n | tail -n 1) avg_throughput1=$(echo "$throughput_info1" | awk '{sum += $1} END {print sum / NR}') min_throughput2=$(echo "$throughput_info2" | sort -n | head -n 1) max_throughput2=$(echo "$throughput_info2" | sort -n | tail -n 1) avg_throughput2=$(echo "$throughput_info2" | awk '{sum += $1} END {print sum / NR}') # Display results echo "Min Throughput 1: $min_throughput1" echo "Max Throughput 1: $max_throughput1" echo "Average Throughput 1: $avg_throughput1 Mbps" echo "Min Throughput 2: $min_throughput2" echo "Max Throughput 2: $max_throughput2" echo "Average Throughput 2: $avg_throughput2 Mbps" # Write results to CSV file if [ ! -f $csv_file ]; then echo "Server,Client,Interface,Min Throughput (Mbps),Max Throughput (Mbps),Average Throughput (Mbps)" > $csv_file fi echo "$host1,$host2,$interface1,$min_throughput1,$max_throughput1,$avg_throughput1" >> $csv_file echo "$host1,$host2,$interface2,$min_throughput2,$max_throughput2,$avg_throughput2" >> $csv_file # Clean up temporary files rm -f $output_file1 $output_file2 # Kill iperf3 instances on both nodes ssh $user@$host1 "pkill iperf3" ssh $user@$host2 "pkill iperf3"