Using Variables for Bandwidth control


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using Variables for Bandwidth control
# 1  
Old 09-17-2008
Using Variables for Bandwidth control

Hi,

I am very new to scripting and have a question regarding variables and their use in a bandwidth monitoring script.

I have identified a few primary variables being;

Bandwidth CIR
Download=32kbits <- these match as per the script below
Bandwidth PIR Download=96kbits
Bandwidth CIR Upload=5kbits
Bandwidth PIR Upload=16kbits
ID
IP or MAC Address
packet source
packet destination.
Parent=1:0 <- match the example below

The script that limits the bandwidth is as follows

#DOWNLOAD
${TC} class add dev eth1 parent 1:1 classid 1:30 htb rate
32kbit ceil 96kbit
${TC} qdisc add dev eth1 parent 1:30 handle 30:0 sfq perturb 10

${TC} filter add dev eth1 parent 1:0 protocol ip handle 5 fw flowid 1:30
${EBTABLES} -A FORWARD -i eth2 -o eth1 -d 00:14:1C:E6:08:66 -j mark --set-mark 5 --mark-target ACCEPT
${TC} filter add dev eth1 parent 1:0 protocol ip u32 match ip dst 192.168.1.1 flowid 1:30

# UPLOAD
${TC} class add dev eth2 parent 1:1 classid 1:30 htb rate 11kbit ceil 32kbit
${TC} qdisc add dev eth2 parent 1:30 handle 30:0 sfq perturb 10
${TC} filter add dev eth2 parent 1:0 protocol ip handle 6 fw flowid 1:30
${EBTABLES} -A FORWARD -i eth1 -o eth2 -s 00:14:1C:E6:08:66 -j mark --set-mark 6 --mark-target ACCEPT
${TC} filter add dev eth2 parent 1:0 protocol ip u32 match ip src 192.168.1.1 flowid 1:30

So the idea is to have the script automatically pick the correct variables based on the IP Address detected using TC for example. At the present point we are almost on 300 clients so the script is very long.

Or just point me in the right direction if possible.
# 2  
Old 09-18-2008
Unfortunately, that's a bit of a difficult requirment to understand...
You've listed that the example of Bandwidth CIR Upload and Bandwidth PIR Upload is 5kb/s and 16kb/s but the example code seems to show 11 and 32 instead.

What I suggest you do is to list all the variables you need the script to automatically pick, give them names that will be clear to the reader but are still valid names (for example, I would call a variable that contains the Bandwidth CIR Upload "bandwidthCIRUpload").

Then change the places in your script where the variables need ot be used to the variable name preceded by a $ symbol and surrounded by {}.
eg, if your script has a line:
Code:
${TC} class add dev eth1 parent 1:1 classid 1:30 htb rate 32kbit ceil 96kbit

and you want to have the '1:1', '32', and '64' be calculated automatically, change it to:
Code:
${TC} class add dev eth1 parent ${parent} classid 1:30 htb rate ${bandwidthCIRDownload}kbit ceil ${bandwidthPIRDownload}kbit

Once you have that done, report back here with your modified code and your list of variables.
Make sure to surround your code in [ C O D E ] tags so it is easier to read.
eg
[ C O D E ]
my code here
[ / C O D E ]
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading control characters into variables

Hi, I am trying to write a shell script to help with some digital signature work currently being undertaken where we have a file that contains a number of rows ending with ^M. What I need to do is concatenate this using shell scripting and retain the control character. E.G. abc^M... (5 Replies)
Discussion started by: chris01010
5 Replies

2. Shell Programming and Scripting

control variables...

Hi. I´ve a question to a running script: i=0 #fill an Array with all files in a folder ending with .sys for Par in *.sys ; do Par2="$Par" ; i=$((i... (1 Reply)
Discussion started by: Lock3
1 Replies

3. UNIX for Dummies Questions & Answers

For loop control with two variables in csh shell

Hi All How can i control for loop with two different variables in csh shell Regards Nikhil (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

4. IP Networking

802 QOS/ Bandwidth Control

My question is such: I want to control the bandwidth of my users and cap there speed on the network. I was told by a Cisco rep that it is better to police or control the bandwidth at the switch and not via the router. It that the correct place to control bandwidth at the switch or would it be... (0 Replies)
Discussion started by: metallica1973
0 Replies

5. Shell Programming and Scripting

control click variables

I want to be able to control click (Mac) and be able to select from a context menu...run file....and have it dynamically run based on the control click. How do I get the control click absolute path of the filename? Are there different variables like directory, fullpath, extention? (0 Replies)
Discussion started by: mainegate
0 Replies

6. IP Networking

Bandwidth montor

Hi all I have been running iptraf on a linux box for a few months monitoring bandwidth utilization realtime from mac address with port mirroring. Now I want to graph these bandwidth utilization. Is MRTG the right software? Any ideas? (4 Replies)
Discussion started by: palm101
4 Replies

7. IP Networking

bandwidth

Hi, 1-What is bandewidth ? 2-How to calculate ? 3-How to measure ? Any free software to measure it ? Many thanks. (4 Replies)
Discussion started by: big123456
4 Replies

8. IP Networking

Bandwidth Regulation

Hello, I was wondering how one would go about regulating bandwidth of a server running RH Linux 8.0 and Apache. I am running a webserver, and want only one person to be able to download one file at a time. So, they can't click about 10 files and soak up lots of bandwidth. Plus, I would like to cap... (2 Replies)
Discussion started by: Phobos
2 Replies

9. IP Networking

Bandwidth Caping With PF

i have two questions actually... i need to block certain ports with openbsd and PF in a large lan, the firewall is supposed to be a router between the internet and the first lan switch. first of all, would this work at all in theory? second, i tried doing this a few days ago at a huge lan but i... (2 Replies)
Discussion started by: nocturnal
2 Replies

10. UNIX for Dummies Questions & Answers

bandwidth check?

I'm on T1, is there any way i can check my acctual bandwidth? Thank you all (3 Replies)
Discussion started by: solvman
3 Replies
Login or Register to Ask a Question