Skip to content

UsingIMQ

imq edited this page Nov 30, 2014 · 5 revisions

IMQ Multi Queue

As from kernel 2.6.35 imq supports multi-queue. Thanks to Jussi Kivilinna.

For multi-queue try this script for loading the module or use this command:

modprobe imq numqueues=<NUMBER_OF_CPU>

Loading kernel module

Note: If you compiled IMQ driver into the kernel (opposed to as a loadable module), you can skip this section. You should load the IMQ driver with this command:

modprobe imq

If you need more devices than you configured at compile time (eg. 8 such devices), you should use:

modprobe imq numdevs=8

Bringing IMQ device up

Now you have one or more IMQ devices. They're called imq0, imq1, imq2, ...

Before you can do anything useful with them, you must "bring them up":

ip link set imq0 up

ip link set imq1 up

ip link set imq2 up

Attaching a qdisc (possibly with classes and filters)

Now you can attach qdiscs (queueing disciplines) to the IMQ devices, as if they were ordinary network devices.

You must use egress qdiscs, even for ingress traffic. (Perhaps that's just why you use IMQ.:-)

We don't recommend CBQ as qdisc (it won't work well with IMQ, because of CBQ design issues), use HTB instead. (BTW, generally speaking, HTB is superior to CBQ.) Example of usage:

ip link set imq0 up

tc qdisc add dev imq0 root handle 1: htb default 2

tc class add dev imq0 parent 1: classid 1:1 htb rate 80000Kbit

tc class add dev imq0 parent 1: classid 1:2 htb rate 80000Kbit

tc class add dev imq0 parent 1:1 classid 1:10 htb rate 256kbit ceil 384kbit

tc class add dev imq0 parent 1:1 classid 1:20 htb rate 512kbit ceil 648kbit

tc filter add dev imq0 parent 1: protocol ip prio 1 u32 match ip dst aaa.aaa.aaa.aaa/bb match ip src ccc.ccc.ccc.ccc/dd flowid 1:10

tc filter add dev imq0 parent 1: protocol ip prio 1 u32 match ip dst ddd.ddd.ddd.ddd/ee match ip src fff.fff.fff.fff/gg flowid 1:20

iptables -t mangle -A PREROUTING -i ppp0 -j IMQ --todev 0

iptables -t mangle -A PREROUTING -i ppp1 -j IMQ --todev 0

ip link set imq1 up

tc qdisc add dev imq1 root handle 2: htb default 2

tc class add dev imq1 parent 2: classid 2:1 htb rate 80000Kbit

tc class add dev imq1 parent 2: classid 2:2 htb rate 80000Kbit

tc class add dev imq1 parent 2:1 classid 2:10 htb rate 256kbit ceil 384kbit

tc class add dev imq1 parent 2:1 classid 2:20 htb rate 512kbit ceil 648kbit

tc filter add dev imq1 parent 2: protocol ip prio 1 u32 match ip dst ccc.ccc.ccc.ccc/dd match ip src aaa.aaa.aaa.aaa/bb flowid 2:10

tc filter add dev imq1 parent 2: protocol ip prio 1 u32 match ip dst fff.fff.fff.fff/gg match ip src ddd.ddd.ddd.ddd/ee flowid 2:20

iptables -t mangle -A POSTROUTING -o ppp0 -j IMQ --todev 1

iptables -t mangle -A POSTROUTING -o ppp1 -j IMQ --todev 1

Setting up rules for classifying packets

Everything is set up now, let's make certain packets enter the IMQ device:

For incoming packets:

iptables -t mangle -A PREROUTING [conditions] -j IMQ --todev 0 # these packets will enter imq0

iptables -t mangle -A PREROUTING [conditions] -j IMQ --todev 1 # these packets will enter imq1

iptables -t mangle -A PREROUTING [conditions] -j IMQ --todev 2 # these packets will enter imq2

For outgoing packets:

iptables -t mangle -A POSTROUTING [conditions] -j IMQ --todev 0 # these packets will enter imq0

iptables -t mangle -A POSTROUTING [conditions] -j IMQ --todev 1 # these packets will enter imq1

iptables -t mangle -A POSTROUTING [conditions] -j IMQ --todev 2 # these packets will enter imq2

As you may have noticed, you can use the "usual" iptables conditions (eg. incoming interface, outgoing interface, etc.) allowed in the mangle table's chains. IMQ is just an iptables target here.

Setting up rules for packets to enter IMQ

You can use iptables MARK target (valid only in the mangle table)to mark packets, then you can use these marks either in the iptables rules with IMQ target, or in the filters of the qdisc attached to the IMQ device (or both). But you can get away without using MARK. It's just useful, but not mandatory.