DawnMage77
DawnMage77

Reputation: 75

Throttling Bandwidth on Ethernet Port

I'm writing an application to run on a server where I need to be able to set the maximum bandwidth for each Ethernet port (there will be up to 6 ports).

Obviously I can throttle the bandwidth that my application uses but I haven't yet found any information about throttling the actual Ethernet port bandwidth on the computer.

Would this need to be done by creating a driver to monitor all of the ports? Could anyone point me in the right direction?

Upvotes: 5

Views: 877

Answers (3)

Waqas
Waqas

Reputation: 3853

If you have access to a Linux box, its easy-peasy to do such a thing. In fact you can add all sorts of network impairments to make it interesting.

Just install two network cards and set-up netem to intermediate the traffic. (i.e. a netem blip in the wire, adding up impairments like delay, jitter, bandwidth rate etc.)

Here is the script I use to test the performance of my Android audio streaming apps by passing the android traffic through the Linux box (with a wifi AP connected to one of the interfaces).

Added: By testing the performance of my App, I mean how would the App behave on a 4G network while driving (i.e. a lot of Jitter). Or a use case in home with Wi-Fi; what if everyone in the home decides to stream HD videos simultaneously (i.e. bandwidth contention, with a lot of packet loss).

#!/bin/bash

ORIGINAL_PATH=$PATH

#echo $ORIGINAL_PATH

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/game"

#echo $PATH 
CTOSINTERFACE=eth1  # EGRESS interface on Bridge, facing the SERVER
STOCINTERFACE=eth0  # EGGRES interface on Bridge, facing the CLIENT

# Client To Server
CDELAY=$1   
CJITTER=$2
CLOSS=$3
CDUPLICATE=$4
CCORRUPT=$5
CREORDER=$6

# Server to Client
SDELAY=$7
SJITTER=$8
SLOSS=$9
SDUPLICATE=$10
SCORRUPT=$11
SREORDER=$12

# Clear Latency/Loss/Jitter
/sbin/tc qdisc del root dev $CTOSINTERFACE 2>/dev/null
/sbin/tc qdisc del root dev $STOCINTERFACE 2>/dev/null


# Client to Server Impairments (on Bridge)
qdisc add dev $CTOSINTERFACE root netem delay ${CDELAY}ms ${CJITTER}ms loss $CLOSS% duplicate ${CDUPLICATE}% corrupt ${CCORRUPT} reorder ${CREORDER}% limit 10000000 2>&1 >/dev/null
qdisc add dev $STOCINTERFACE root netem delay ${SDELAY}ms ${SJITTER}ms loss $SLOSS% duplicate ${SDUPLICATE}% corrupt ${SCORRUPT} reorder ${SREORDER}% limit 10000000 2>&1 >/dev/null

#$PATH=$ORIGINAL_PATH
export PATH=$ORIGINAL_PATH
#echo $PATH

and call the script as

#sudo impare_network.sh 100 20 30 0 0 0 0 0 0 0 0 0 0

This would - on the up-link (client to server)- add delay of 100ms, a jitter of 20% (using normal distribution), Loss of 30% packets.

Upvotes: 1

TomTom
TomTom

Reputation: 62101

In wndows it is generally not possible to do that on an OS level without additional software - the use case is simply seen as not really important, and seriously: this is quite correct. If I need network limits, I can enforce them in the switch.

Only exception is in Hyper-V where the newwest version (in 2012 R2) can limit outgoing bandwidth.

Generally - you will need third party software do to that on windows, but the use case is REALLY edgy, because generally it is a much better place to put that limit in place in the next higher switch.

Upvotes: 0

Alex
Alex

Reputation: 2382

I think the easiest thing would be to create an output device that you can compose with your actual sender that would throttle the output itself rather than messing with the ethernet port.

Upvotes: 0

Related Questions