# Bandwidth squeeze dummynet



## boys21 (Apr 7, 2012)

hi,

I am new to FreeBSD. I am using Dummynet shaper. Can someone give me an idea how to squeeze and release bandwidth over time? For example: total experimentation time is 10 seconds. close bandwidth at 2 seconds and release after  4 seconds to 10 seconds. *A*ny shell script with ipfw commands will do it?

I had an idea of an algorithm like this:

1. start script at time 't'.
2. create a pipe using ipfw from source to destination with a bandwith of 1Mbit/s.
3. after 2 seconds of script starting close bandwidth i.e, 0 bit/s.
4. restore the bandwidth after 4 seconds (back to 1Mbit/s).
5. after 10 seconds exit from the script.

Am *I* going in a right way? *O*r can anyone suggest a better algorithm than this?

Thanks in advance.

br,
boys21


----------



## varda (Apr 8, 2012)

You may create and manipulate on pipes and/or queues accordingly to your need:


```
ipfw pipe 1 config bw 1Mbits
ipfw add 100 pipe 1 all from any to any
sleep 2
ipfw pipe 1 config bw 32Kbits
sleep 2
ipfw pipe 1 config bw 1Mbits
sleep 10
ipfw delete 100
ipfw pipe 1 delete
```

May be starting control scripts on cron basis.


----------



## boys21 (Apr 8, 2012)

Thank you very much. That was really helpful.

I have a doubt in the implementation, when *I* say sleep for 2 seconds do the incoming packets form a queue in the pipe until the 2 seconds are finished?

*U*sing cron will it be possible to control the script in seconds or milliseconds resolution?

br,
boys21


----------



## varda (Apr 10, 2012)

> I have a doubt in the implementation, when I say sleep for 2 seconds do the incoming packets form a queue in the pipe until the 2 seconds are finished?



Since firewall is independent subsystem then it will keep pipe width until you change bandwidth with corresponding command besides 'sleep'.



> Using cron will it be possible to control the script in seconds or milliseconds resolution?



Just refer to man pages for 'sleep' (sleep(1)) and 'cron' (cron(8)) for exact information. Also you can use other scripting/programming languages for your purpose. For example PHP has 'usleep' function. Also there was 'millisleep' program in ports collection.


----------



## boys21 (Apr 10, 2012)

Thank you very much. I*'*ll give a try on this! *A*nd let you know the result.

br,
boys21


----------

