Übung: einen 10 GE Link zwischen 2 Switchen mittels zweier 1 GE Ports auslasten
Wenn man der blinkenden Link-Leuchte am Switch nicht traut, die behauptet einen funktionsfähigen 10 GE-Link anzuzeigen, dann kann man mittels eines Paketbeschleunigers mal testen, ob da wirklich 10GE durch gehen.
Der Trick: 20 VLANs einrichten, per Patchkabel jeweils abwechselend auf einem Switch bridgen und mit den 2 Rechnern in unterschiedlichen VLANs Traffic erzeugen
Rechner 1
ip link set dev eth0 up ip addr add 10.0.0.1/24 dev eth0
Rechner 2
ip link set dev eth0 up ip addr add 10.0.0.2/24 dev eth0
Daten empfangen
nc -l -p 1234 > /dev/null
Daten senden
cat /dev/zero | nc 10.0.0.1 1234
Portauslastung anzeigen
# Usage: -h <ip vom switch> -s <snmp communitystring> -i <interface-nr des 10GE Ports> ./snmp_bandwidth.sh -h 10.0.0.3 -s public -i 25
Ausgabe der Portauslastung
Inbound: 10501 Mbps, Outbound: 10498 Mbps, Speed: 10000 Mbps Inbound: 10452 Mbps, Outbound: 10450 Mbps, Speed: 10000 Mbps
snmp_bandwidth.sh
init () {
INTNUMBER=$interface
OUT=$(snmpget -v2c -c $community_string $hostname ifHCOutOctets.$INTNUMBER | awk '{print $4}')
IN=$(snmpget -v2c -c $community_string $hostname ifHCInOctets.$INTNUMBER | awk '{print $4}')
#SPEED=$(snmpget -v2c -c $community_string $hostname ifSpeed.$INTNUMBER | awk '{print $4}')
SPEED=10000000000
TIME=1
if [ -z "$OUT" ] || [ -z "$IN" ]; then
msg="Unable to retrieve SNMP info."
state=CRITICAL
echo $state $msg
exit 2
fi
}
check () {
#wait $TIME before running the same check, this way we can confirm how much the data has changed in two periods.
sleep $TIME
OUT2=$(snmpget -v2c -c $community_string $hostname ifHCOutOctets.$INTNUMBER | awk '{print $4}')
IN2=$(snmpget -v2c -c $community_string $hostname ifHCInOctets.$INTNUMBER | awk '{print $4}')
DELTAOUT=$(( $OUT2 - $OUT))
DELTAIN=$(( $IN2 - $IN))
#Value is in octets so will need to be divided by 8 to get bytes, this is then divided by 1024 to give kilobytes.
INPUTBW=$(((($DELTAIN)/$TIME)*8))
OUTPUTBW=$(((($DELTAOUT)/$TIME)*8))
#For percentage usage we do 100/(total possible bandwidth – current bandwidth).
percentage_use=$(echo "scale=9; $INPUTBW/$SPEED" | bc)
PRCNTIN=$(echo "scale=0; 100*$percentage_use" | bc)
percentage_use=$(echo "scale=9; $OUTPUTBW/$SPEED" | bc)
PRCNTOUT=$(echo "scale=0; 100*$percentage_use" | bc)
echo "Inbound: " $((INPUTBW/1000000)) "Mbps ($PRCNTIN% Used), Outbound: " $((OUTPUTBW/1000000)) "Mbps ($PRCNTOUT% Used), Speed: " $(($SPEED/1000000)) "Mbps"
IN=$IN2
OUT=$OUT2
}
while getopts ":i:s:h:" option
do
case $option in
i)interface=$OPTARG
;;
s)community_string=$OPTARG
;;
h)hostname=$OPTARG
;;
*) echo "Syntax is $usage -h <hostname> -s <snmpstring> -i <interface-nr>"
exit 1;;
esac
done
if [ -z "$hostname" ]; then
echo "-h) IP address required."
exit 1
elif [ -z "$community_string" ]; then
echo "-s) snmp string needs to be specified."
exit 1
elif [ -z "$interface" ]; then
echo "-i) interface number required."
exit 1
else
init
while true
do
check
done
fi