[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

filter probs



I am trying to control the bandwidth of a connection to particular host
and port combinations. The script I use is a subset of example 2 from
Linux - Advanced Networking Overview 
(http://qos.ittc.ukans.edu/howto/index.html). 

The following is what I am trying to setup:

All connections to 192.4.20.232 are restricted to a 5Mbit bandwidth. If
connecting to ports 6010 or 6011, the bandwith is further restricted to
4Mbit and 1Mbit respectively.

Using netperf, I can get about 6.5-7 Mbps of throughput WITHOUT any
setting up. Then once I set things up as described above, my throughput is
around 5Mbps (as expected). The only problem is that even connecting to
those ports gives a 5Mbps throughput! If I have 2 simultaneous connections
(one to port 6010 and one to 6011), then the throughput of each is roughly
half of 5Mbps. 

I am including my script below... Can anyone tell me what I am doing
wrong?


#! /bin/sh

# Armando L. Caro Jr.
# 6/8/2000.12:45
#
# Purpose: To test and understand diffserv installation more thorougly.


TC=/usr/local/sbin/tc
IP=/usr/local/sbin/ip

HOME_IP=192.4.20.232

# Kauchik's machine
HOST_A_IP=192.4.20.222
HOST_A_PORT1=0x177a      # port 6010
HOST_A_PORT2=0x177b      # port 6011

initialize()
{
   # Attaching the Qdisc to the eth0 device.  The maximum available bandwidth is
   # 100Mbit.  
   #
   $TC qdisc add dev eth0 root handle 1: cbq bandwidth 100Mbit allot 1514 \
      cell 8 avpkt 1000 mpu 64


   # Adding the root class to the queuing discipline. The root has the complete 
   # 100 Mbit bandwidth.
   #
   $TC class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 100Mbit \
      rate 100Mbit allot 1514 cell 8 weight 10Mbit prio 8 maxburst 20 avpkt 1000


   # Traffic to host A. The priority is 3 and the allocation is 6 Mbit. Note
   # that it is set to bounded because of the strict link sharing rules.
   #
   $TC class add dev eth0 parent 1:1 classid 1:2 cbq bandwidth 100Mbit \
      rate 5Mbit allot 1514 cell 8 weight 500Kbit prio 3 maxburst 20 \
      avpkt 1000 bounded


   # Attaching another CBQ to the traffic to host A. This is meant for further 
   # classification. 
   #
   $TC qdisc add dev eth0 parent 1:2 handle 2: cbq bandwidth 5Mbit allot 1514 \
      cell 8 avpkt 1000 mpu 64


   # Setting up the classes for the traffic to host A appropriately.
   #
   $TC class add dev eth0 parent 2:0 classid 2:1 cbq bandwidth 5Mbit \
      rate 5Mbit allot 1514 cell 8 weight 500Kbit prio 3 maxburst 20 avpkt 1000

   $TC class add dev eth0 parent 2:1 classid 2:2 cbq bandwidth 5Mbit \
      rate 4Mbit allot 1514 cell 8 weight 400Kbit prio 1 maxburst 20 avpkt 1000 \
      bounded

   $TC class add dev eth0 parent 2:1 classid 2:3 cbq bandwidth 5Mbit \
      rate 1Mbit allot 1514 cell 8 weight 100Kbit prio 1 maxburst 20 avpkt 1000 \
      bounded


   # Installing a route classifier on device eth0.  
   #
   $TC filter add dev eth0 parent 1:0 protocol ip prio 100 route


   # Map each flowid to a realm
   #
   $TC filter add dev eth0 parent 1:0 protocol ip prio 100 route to 1 flowid 1:2


   # Setting up the routes their rules for traffic. 
   #
   $IP route add $HOST_A_IP via $HOME_IP realm 1


   # Installing a u32 classifier for the traffic to host A
   #
   $TC filter add dev eth0 parent 2:0 prio 3 protocol ip u32

   # Creating  hash tables for classification of the packets to host A
   #
   $TC filter add dev eth0 parent 2:0 prio 3 handle 1: u32 divisor 256
   $TC filter add dev eth0 parent 2:0 prio 3 handle 2: u32 divisor 256


   # Configuring the 6th slot of the hash table 1 to select packets with
   # destination set to $HOST_A_IP:$HOST_A_PORT1 and direct these to class 2:2
   # (which was just set up).  
   #
   $TC filter add dev eth0 parent 2:0 prio 3 u32 ht 1:6: \
      match ip dst $HOST_A_IP match tcp dst $HOST_A_PORT1 0xffff flowid 2:2


   # Configuring the 6th slot of the hash table 2 to select packets with
   # destination set to $HOST_A_IP:$HOST_A_PORT2 direct these to class 2:3
   # (which was just set up).
   #
   $TC filter add dev eth0 parent 2:0 prio 3 u32 ht 2:6: \
      match ip dst $HOST_A_IP match tcp dst $HOST_A_PORT2 0xffff flowid 2:3


   # Lookup hash table and it it is not fragmented, use the protocol as the hash
   # key.
   #
   $TC filter add dev eth0 parent 2:0 prio 3 handle ::1 u32 ht 800:: match ip \
      nofrag offset mask 0x0F00 shift 6 hashkey mask 0x00ff0000 at 8 link 1:

   $TC filter add dev eth0 parent 2:0 prio 3 handle ::1 u32 ht 800:: match ip \
      nofrag offset mask 0x0F00 shift 6 hashkey mask 0x00ff0000 at 8 link 2:
}

take_down()
{
   # Detaching the Qdisc from the eth0 device.
   #
   $TC qdisc del dev eth0 root handle 1: cbq bandwidth 100Mbit allot 1514 \
      cell 8 avpkt 1000 mpu 64

   $IP route del $HOST_A_IP via $HOME_IP 
}

# See how we were called.
case "$1" in
   start)
      printf "Initializing... "
      initialize
      ./status success
      ;;
   stop)
      printf "Deleting all entries..."
      take_down
      ./status success
      ;;
   restart)
      printf "Restarting... \n"
      printf "   Stopping..."
      take_down
      ./status success
      printf "   Starting..."
      initialize
      ./status success
      ;;
   *)
      printf "Usage: $0 {start|stop|restart} \n"
      exit 1
esac