Previous

Content  

Next


3.1. Edge1

 

Google
The example's script is as follows:

#!/bin/bash

####################### Ingress side ########################

iptables -t mangle -A FORWARD -i eth2 -s 10.2.0.0/24 -j MARK --set-mark 3
iptables -t mangle -A FORWARD -i eth2 -s 10.2.0.24 -j MARK --set-mark 1
iptables -t mangle -A FORWARD -i eth2 -s 10.2.0.3 -j MARK --set-mark 2

######################## Egress side ########################

tc qdisc add dev eth1 handle 1:0 root dsmark indices 64 set_tc_index

tc class change dev eth1 classid 1:1 dsmark mask 0x3 value 0xb8
tc class change dev eth1 classid 1:2 dsmark mask 0x3 value 0x28
tc class change dev eth1 classid 1:3 dsmark mask 0x3 value 0x48

tc filter add dev eth1 parent 1:0 protocol ip prio 4 handle 1 fw classid 1:1
tc filter add dev eth1 parent 1:0 protocol ip prio 4 handle 2 fw classid 1:2
tc filter add dev eth1 parent 1:0 protocol ip prio 4 handle 3 fw classid 1:3

Here we are trying to implement a very simple DS edge router. The interface eth2 faces to outside of the domain. The interface eth1 faces to inside of the domain.
First thing to be noted here is the use of iptables instead of ipchains. In the original example they use ipchains -A input, but in our implementation we use iptables -A FORWARD because we are trying to implement a router. Packets, then, are not going to enter the router to the upper layers, but instead they will be forwarded directly from interface eth2 to interface eth1. In the FORWARD's iptables chain, every packet coming from the network selected will be marked (not the packet itself, but the fw field in the packet's buffer) as 1, 2 or 3 to indicate its origin. iptables rules are treated in the same sequence as they were included. Then, first command marks all packets from network 10.2/24 as fw 3; second command picks just packets from host 10.2.0.24 and mark them as fw 1; and third command picks just packets from host 10.2.0.3 and mark them as fw 2.
 
In the eth1 output interface a DSMARK queuing discipline is configured. When a packet enters this discipline its DS field value is copied onto the skb->tc_index field. This is not really necessary in this case because the final class selection will be done using the fw classifier, not the tcindex classifier. This example then goes fine by omitting set_tc_index in the DSMARK's command.
 
To continue, the fw classifier is invoked now. This classifier reads the fw field on the packet's buffer and depending of its value (1, 2, or 3), returns classes 1, 2, or 3 to the dsmark queuing discipline respectively, which in turn sets the skb->tc_index value as 1, 2 or 3 respectively. This because according to the filter commands above, the fw value was set the same as the minor part of the classid value.
 
Let's explain this very clearly, the command:  ...handle 1 fw classid 1:1, returns the classid 1:1, which dsmark uses to set the skb->tc_index field as 1 for packets whose fw field value is 1. But, we could have written:  ...handle 1 fw classid 1:2, and then the classid 1:2 will be returned, which dsmark will use to set the skb->tc_index field as 2 for packets whose fw field value is 1. Be very careful with this.
 
Well, being here our assignment has been fulfilled; i.e., skb->tc_index field value is set according to the packet's source network. This means, any packet from host 10.2.0.24 has its skb->tc_index field set to 1, any packet from host 10.2.0.3 has its skb->tc_index field set to 2, and rest of packets from network 10.2/24 have their skb->tc_index field set to 3.
 
Final work is done by the DSMARK queuing discipline classes. Packets having marked their skb->tc_index field as 1, 2, or 3 will be placed in the corresponding dsmark classes 1:1, 1:2, or 1:3 respectively. Being in the classes, when they leave the dsmark queuing discipline, their DS field will be set to 0xb8, 0x28, or 0x48, respectively (but preserving the ecn bits), which will correspond to differentiated service classes EF, AF11 and AF21, again, respectively.
 
   

 

This edge router then assigns differentiated service classes as follows:
  Traffic coming from host 10.2.0.24 will be aggregated to differentiated service EF class.
  Traffic coming from host 10.2.0.3 will be aggregated to differentiated service AF11 class.
  Rest of traffic coming from network 10.2/24 will be aggregated to differentiated service AF21 class.
Packets from these traffics will start their travel through our domain already marked as is indicated above. That's all folks, at least for this simple and funny example.

   


Previous

Content  

Next