# priority service and altq



## maslakyavuz (Dec 20, 2011)

Hello,

I use Freebsd FreeBSD 8.2-amd.

I have a fiber line whose capacity is 10 mbps. A server will be video streaming to the internet. Also I have 2 computers.  They generally use ftp and internet browsing. I don't want these machines to overload the internet using ftp or other downloads. That's to say streaming is first priority. I want altq to do this. I reconfigured the kernel. 

Could you give me an example about that? Any advice?


----------



## SirDice (Dec 20, 2011)

Handbook: 31.4 The OpenBSD Packet Filter (PF) and ALTQ


----------



## maslakyavuz (Dec 20, 2011)

I had read the link you gave

Do you mind if could you give an example about my case?


----------



## SirDice (Dec 20, 2011)

http://www.openbsd.org/faq/pf/queueing.html#example1


----------



## bbzz (Dec 20, 2011)

I suggest HFSC, not priority queue, with uplink of 10Mbps.
Google for explanation on this scheduler.

In short, it's a CBQ with Priority queuing which allows you to split bandwidth and priorities and not starve any single traffic due to higher priorities. CBQ just doesn't do right job.


----------



## maslakyavuz (Dec 21, 2011)

Thank you but I have a problem. As you know, ftp uses different ports during downloads. I have to say that I don't use NAT in my case. How can I add ftp into pipe?


----------



## SirDice (Dec 21, 2011)

http://www.openbsd.org/faq/pf/queueing.html#example2


----------



## maslakyavuz (Dec 21, 2011)

Ok  But my machines doesn't need nat in my case. The machine first used dst port 21 and then use dst port 31834. it is downloading via ftp. They will use new destination connection port in a new ftp connection.

What can I do?


----------



## bbzz (Dec 21, 2011)

Don't match specifically for ftp. Rather put it in "bulk" group, the one that matches everything else not specifically matched ( tcp_acks, ssh, im, voip, whatever needs specific treatment). ftp doesn't need any kind of specific treatment. 

Also, you need to differentiate queuing on your external and your internal interface. Your media server is streaming to internet so queuing on external interface needs to reflect that. On the other hand, you are downloading ftp, so queuing for that needs to be on your internal interface.

You really need to read up the whole link SirDice sent you, both for queuing and pf.


----------



## maslakyavuz (Dec 21, 2011)

Thank you

I also want to limit bandwidth for my every client IP addresses. Because sometimes it is not enough to limit according to ports or services. For instance, my IP block 192.168.9.0/24. lest every IP in this blok passes pre-specified bandwidth limit. 

How can I do that?


----------



## gkontos (Dec 21, 2011)

@maslakyavuz,

http://www.openbsd.org/faq/pf/queueing.html#example2

Start reading the examples they gave you!


----------



## maslakyavuz (Dec 21, 2011)

Thanks I read the pages but I don't understand a thing. As far as I can see that the examples on the page, are defined some ip blocks but they don't show how I can define an upper bandwidth limit to a queue for every ip address in a block separately. As you know, a pc can consume all bandwidth using tcp service which use all machines. Therefore I want to put an upper bandwidth limit for my all ip addresses.

Is there a command for that?


----------



## gkontos (Dec 21, 2011)

Thinking out loudly:


```
queue loosers_net bandwidth 1Kb
loosers_net = "192.168.9.0/24"
pass out on em0 from loosers_net queue loosers_net
```


----------



## maslakyavuz (Dec 22, 2011)

I tried but it doesn't work. The bandwidth I put covers the entire /24. I want to limit all inbound traffic to 1 Mbit/s for each host on my network (192.168.9.0/24). Also how can I do this with dummynet or altq?


----------



## Abriel (Dec 22, 2011)

pf don't support dummynet so you can use IPFW for bandwidth limit.

Example for ip: 192.168.9.2

```
/sbin/ipfw add pipe 2 ip from any to 192.168.9.2 in 
/sbin/ipfw pipe 2 config bw 1024kbit/s
```

You can add all your ips one by one, or you can write simple script to read all of them from file/mysql.


----------



## maslakyavuz (Dec 22, 2011)

Many lines but mysql is reasonable. Could you give me a script for ipfw - mysql connection? I can't find enough info about hfsc on altq. How can I get some document about hfsc (Hierarchical Packet Scheduler)?


----------

