Thursday, October 16, 2014

QoS DSCP/ToS conversion

Just a quick note on the conversion process with some examples and an explanation...

Prior to DiffServ, IPv4 networks could use the Precedence field in the TOS byte of the IPv4 header to mark priority traffic. The TOS octet and IP precedence were not widely used. The IETF agreed to reuse the TOS octet as the DS field for DiffServ networks. In order to maintain backward compatibility with network devices that still use the Precedence field, DiffServ defines the Class Selector PHB.

The Class Selector code points are of the form 'xxx000'. The first three bits are the IP precedence bits. Each IP precedence value can be mapped into a DiffServ class. CS0 equals to IP precedence 0, CS1 to IP precedence 1, and so on. If a packet is received from a non-DiffServ aware router that used IP precedence markings, the DiffServ router can still understand the encoding as a Class Selector code point.

We have the hex value of 0x80 for our ToS.

0x80 in hex = 1000 0000 in decimal, or 128 in binary.

A quick in dirty to convert this to the PHB...drop the first 2 numbers.

100000 in binary or 32 in decimal.

Now, what lets look at the first 3 bits:

000000 = CS0
001000 = CS1
010000 = CS2
011000 = CS3
100000 = CS4
101000 = CS5
110000 = CS6
111000 = CS7

Based on our DSCP value of 100000, we can infer that this is CS4.

The way that we can tell that this is a CS DSCP value versus AF (Assured Forwarding), is that the trailing 3 bits are all 0.  If we have a 1 in the remaining 3 bits, then we know that it is an AF value.
Furthermore, the first half of the number is what identifies the priority and the second half of the number identifies the drop probability.  For example, AF31 has a lower drop probability than AF33, while AF31 has a higher priority than AF11.  The priority is derived from the first 3 bits.

For example,

010010 in decimal equals 18.  We can convert this into the AF value by dividing the decimal value by 8, and the remainder by 2.  18/8= 2 with a remainder of 2, or AF21.

Inversely, if we have the AF21 already, we can convert this into the decimal value by multiplying the first digit by 8 and the second digit by 2...and then add the result:

(8*2)+(2*1)=18.

1 comment:

  1. Great informative post, thanks so much.... please visit once at http://bit.ly/215u2PG

    ReplyDelete