2010
06.20

Asterisk provides tool for reporting QoS.

It can be actived by adding fallowing rule to given context:

exten => h,1,Set(CDR(userfield)=${RTPAUDIOQOS})

In that case all metrics would be added at the end of CDR file. Default it is Master.csv located at /var/log/asterisk/cdr-csv/

Added fields look like this:
ssrc=408070608;
themssrc=12192;
lp=0;
rxjitter=0.000581;
rxcount=376;
txjitter=0.000031;
txcount=399;
rlp=0;
rtt=0.000000

Explanation of fields could be found at http://wiki.kolmisoft.com :

  • Our Receiver
    • ssrc – our synchronization source
    • rxcount – no. received packets/Received packets
    • lp – lost packets/Lost packets
    • rxjitter – our calculated jitter(rx)/Jitter
  • Our Sender
    • themssrc – their synchronization source
    • txcount – transmitted packets/Sent packet
    • rlp – remote lost packets/Lost packets
    • txjitter – reported jitter of the other end/Jitter
    • rtt – round trip time/RTT
2010
05.27

TRPR (TRace Plot Real-time) is a program which analyzes output from various sources and creates output suitable for plotting.

It can analyze output files from:

  • tcpdump
  • Network Simulator 2
  • mgen

TRPR is able to prepare IP QoS metrics such as:

  • mean rate of packets stream
  • differential interarrival packet delays
  • transmission delay
  • packet loss
  • end other

TRPR can distinguish each flow according to: source and destination IP, source and destination port, flow id and type of transmission (TCP or UDP).

Example:

./trpr latency drec input input.drc auto X,X,192.168.10.116/4000 output output.txt

  • input.drc: output file from mgen
  • 192.168.10.116/4000: destination IP and port which identifies flow
  • output.txt: file ready for plotting
  • information about other parameters can be found here.

What if I wanted to have mean values of metrics in given flow?

Linux awk tool can be used for providing metrics from output.txt.

First of all we have to remove from our file few lines from the beginning, which are used for plotting.

Awk script for getting mean value can look like (2nd column in our file is one with latencies):

BEGIN { FS = " "} {
allV = $2 + allV;
all = all+1;
} END {
mean = allV/all
print "Mean Latency: " mean
}

After executing:

awk -f script.awk output.txt

we should get mean delay of our flow.

What is important: source and destination MUST BE synchronized if metrics such as latency and interarrival time are important for us. It would be fine even if one of them would be source of time for another.

2010
05.05

Multi Generator is one of  free traffic generators.  Current release is mgen 4.2b4. Source could be downloaded here. I installed it on fresh and default Centos 5.3 (2.6.18-128.el5) linux. In order  to work mgen properly, libstdc++.so.5 must be installed:

yum install libstdc++.so.5

and after according to manual:

tar -xvf src-mgen-4.2b6.tgz
cd mgen-4.2b6/unix/
make –f Makefile.linux mgen

and add directory to PATH:

export PATH=$PATH:/path/to/mgen-4.2b6/mgen

Mgen can sent and receive traffic. That’s why one host acts as sender and other as receiver

Now we can make a test:

Create script on sender side: test_input.mgn with:

0.0 ON 1 UDP DST 192.168.10.116/4000 PERIODIC [10.0 1024] TOS 0x10
10.0 OFF 1

It says that we send to 192.168.10.116 on port 4000 PERIODIC traffic. Each packet is 1024 bytes long and in one second 10 packets are sent. What is more, we set on each packet ToS = 0×10. Notice, that 1024B includes IP header. Mgen stops sending packets after 10s.

On receiver side mgen must listen on given port. In order to do this we create script test_listen.mgn:

LISTEN UDP 4000

Please remember to allow traffic to go through your firewall! Or simply type:

service iptables stop

First we must start listening on receiver side:

mgen input test_listen.mgn output test_output.drc

In test_output.drc would be stored captured data for using with TRPR in order to provide QoS metrics.

Now we can start sending packets. We do it on sender side by:

mgen input test_input.mgn

After 10s mgen terminates itself and we can prepare other things with test_output.drc, which would be shown in next posts.

It is worth to read about other avaliable options in mgen. According to particular needs they might be very useful.

2010
04.23

Recently I’ve installed the newest  Asterisk 1.6.2.6.  I dealt  with Asterisk few times in past but never focused on QoS capability. What I found interesting is that in sip.conf there are fields for setting ToS field (with default values provided):

  • tos_sip=cs3   (SIP signalling messages)
  • tos_audio=ef    (RTP audio)
  • tos_video=af41    (RTP video)
  • tos_text=af41    (RTP text)

Settings are also avaliable for other protocols:

Even those parameters are named ToS they actually set DSCP. It might be misleading, because ToS it is full byte, whilst DSCP is a 6-bits part of ToS field.

2010
04.15

It is possible to set ToS using iptables. The pity is that only 5 values are valid: iptables -m tos -h

  • Minimize-Delay 16 (0×10)
  • Maximize-Throughput 8 (0×08)
  • Maximize-Reliability 4 (0×04)
  • Minimize-Cost 2 (0×02)
  • Normal-Service 0 (0×00)

As you noticed, only one of 4 bits (11, 12, 13, 14) from ToS octet can be set Sample firewall rules:

iptables -t mangle -N mark-tos
iptables -t mangle -A OUTPUT -j mark-tos
iptables -t mangle -A mark-tos -p icmp -j TOS --set-tos 16

In example only icmp packets are marked. Setting ToS using iptables isn’t so useful as setting DSCP.

2010
04.13

Below is example of setting two classes for:

  • signaling
  • media

It was created for SIP and H.323. There is many differences between them and it seems that SIP is becoming much more popular nowadays thanks to its simplicity.

Both have got signaling and media layer. Usually network ports that are used for these purposes are:

1.For SIP:

  • signaling: TCP/UDP 5060, TCP 5061 (secure TCP)
  • media: UDP, depends on configuration

2. For H.323

As example was based on Avaya solution in which there are Communication Manager and Gateway/Gatekeeper.

  • signaling: TCP/UDP 1719, TCP/UDP 1720
  • media: UDP, depends on configuration

For signaling we ascribed DSCP class CS4 , whilst for media EF.

Iptables should look more or less like this

MEDIA:

#out
iptables -t mangle -A mark-media -p udp -s $IP_1 -d $IP_2 --dport $RTP_RANGE -j DSCP --set-dscp-class ef
#in
iptables -t mangle -A mark-media -p udp -s $IP_2 -d $IP_1 --sport $RTP_RANGE -j DSCP --set-dscp-class ef

where:

IP_1 and IP_2 – IP’s ranges of endpoints

RTP_RANGE – UDP ports ranges for RTP

SIGNALING:

#out
iptables -t mangle -A mark-signaling-sip -p tcp -s $SIP_ENDPOINT_IP -d $SIP_GW_IP --dport 5060:5061 -j DSCP --set-dscp-class cs4
#in
iptables -t mangle -A mark-signaling-sip -p tcp -s $SIP_GW_IP --sport 5060:5061 -d $SIP_ENDPOINT_IP -j DSCP --set-dscp-class cs4

where:

SIP_ENDPOINT_IP – SIP endpoint

SIP_GW_IP – SIP Proxy/Registrar
#out
iptables -t mangle -A mark-signaling-h323 -p tcp -s $AVAYA_ENDPOINT_IP -d $AVAYA_CM_IP --dport 1719:1720 -j DSCP --set-dscp-class cs4
iptables -t mangle -A mark-signaling-h323 -p udp -s $AVAYA_ENDPOINT_IP -d $AVAYA_GW_IP --dport 1719:1720 -j DSCP --set-dscp-class cs4
#in
iptables -t mangle -A mark-signaling-h323 -p tcp -s $AVAYA_CM_IP --sport 1719:1720 -d $AVAYA_ENDPOINT_IP -j DSCP --set-dscp-class cs4
iptables -t mangle -A mark-signaling-h323 -p udp -s $AVAYA_GW_IP --sport 1719:1720 -d $AVAYA_ENDPOINT_IP -j DSCP --set-dscp-class cs4

where:

AVAYA_ENDPOINT_IP – H.323 endpoint

AVAYA_CM_IP – Avaya Comunication Manager

AVAYA_GW_IP – Avaya Gateway/H.323 Gatekeeper

In example we assumed that there is proper FILTER chain in iptables configured allowing transmission over above TCP/UDP ports

Chains: mark-media, mark-signaling-sip, mark-signaling-h323 should be added to PREROUTING chain in mangle table:

ptables -t mangle -A PREROUTING -j mark-signaling-sip
iptables -t mangle -A PREROUTING -j mark-signaling-h323
iptables -t mangle -A PREROUTING -j mark-media

Now we are able to distinguish media and signaling for VoIP in our network and we can start dealing with queueing disciplines

2010
04.08

If our hardware/software (i.e. IP Phone, gateway) doesn’t set proper DSCP value it can be done using iptables in the nearest linux machine. In scenario there are two hosts:

  • Ping Request is a linux (CentOS 5.3, 2.6.18-128.e15) with iptables v1.3.5
  • Ping Response is Windows 7 with Wireshark on board

In example, just for simplification, all traffic from Ping Request host is mark with DSCP value 46 (Critical).

Changes in firewall were done after fresh install (default iptables rules):

iptables -t mangle -N wawit-mark-dscp-46
iptables -t mangle -A POSTROUTING -j wawit-mark-dscp-46
iptables -t mangle -A wawit-mark -j DSCP --set-dscp 46

After ping command on Ping Response host we captured:

DSCP value 0×2e in hex is equal to 46 in decimal.

Example is trivial. Of course we should set DSCP value in packets according to available criteria, i.e. src/dst IP address, port, protocol etc.

After having proper DSCP values we can implement QoS mechanism in our network nodes according to them.

2010
03.31

In order to provide Quality of Service, there should be a way to distinguish priority of each arriving packet according to DiffServ Architecture.

In IP packet header there is special group of 8 bits (from 8th to 15th respectively in header) dedicated for that purpose. They are called Type of Service.

In Precedence could be one of fallowing values, which informs about packet type :

  • 000 – routine
  • 001 – priority
  • 010 – immediate
  • 011 – flash
  • 100 – flash-override
  • 101 – critical
  • 110 – internetwork control
  • 111 – network

Other bits inform that :

  • 11 – packet is delay sensitive (D)
  • 12 – packet wants high rate (T)
  • 13 – packet wants high reliability (R)
  • 14 – mainly unsued
  • 15 – mainly unsued

In DiffServ architecture there was defined Differentiated Services Code Point in ToS field.

It allows to define 64 different classes. The mapping between IP Precendence and DSCP is as fallows:

First 3 bits from DSCP agrees with IP Precedence.

Thanks to ToS and DSCP we know packets service requirements.

2010
03.26

Weighted Fair Queueing

Weighted Fair Queueing (WFQ) is one of the most important among all scheduling mechanism. Every arrived packet has it’s SN (Sequence Number), which determines, when packet should be served.

where:

  • SN(i) – current SN
  • SNprevious(i) – previous SN
  • weight(i) – weight assigned to flow
  • lengthpacket(i) – packet length
  • “i” – flow number

Now we are sure, that packets (with their different sizes) from many flows are served fairly. None of flows occupies output link more that it’s configured value.

There are no explicite formula how to count weight and there might be small differences between implementations.

2010
03.22

Weighted Round Robin

Weighted Round Robin serves packets from every non empty queue in cycle manner. Number of packets, that WRR algorithm takes in cycle, is based on configured weight, which is normalised to unity.

Supposing, normalised weights of depicted above queues are respectively 3 and 2, then number of packets taken in one cycle is 5. First, 3 packets are taken from Class #1 and after 2 from Class #2.

But, one could ask, what if there is no packets for serving in the queue? WRR simply jumps to next queue and pretends that it has already served previous queue. WRR is example of non-work-conserving scheduler, meaning, that it doesn’t waste time for unproductive work. There is no such situation, that there is at least one packet in the queue and output link is idle.

Weighted Round Robin is pretty good scheduling mechanism. And it becomes better if packets sizes are constant – in real networks it is impossibile! If sizes of packets in Class #1 queue were 200B and 1000B in Class #2, and if configured weights were these same (3/2), then real bandwith would be shared in proportion 3/10. It happens, because time of service from Class #2 is 5 times longer than from Class #1.

There are two modifications of Round Robin mechanism:

  • Deficit Round Robin – more fair taking into consideration packets sizes
  • Shared Round Robin – very similar to WRR, but in one cycle it can visit every queue many times, according to weigth (=number of packets, that it must take in the cycle). Another words: packets are mixed on Output link.

As you noticed, Round Robin mechanisms aren’t so trivial and it is better to know what mechanism we are using and what for.