Wednesday, April 13, 2011

IPv6 header, IPv4 to IPv6 conversion, IPv6 addressing, zero compression & leading zero compression

Slowly but sure, there is a migration from IPv4 to IPv6 because of the shortage of IP address. There has been previous tricks being done to avoid this migration such as doing NAT and DHCP, but as the number of devices that needs IP addresses increases and to provide a more secure network, migration to IPv6 is necessary. The major difference in IPv4 and IPv6 is that IPv6 has more addresses available then IPv4. IPv4 uses 32 bits that is divided into 4x8bits. IPv6 uses 128 bits that is divided into 8x16bits hexadecimal. An example of IPv4 is 123.145.167.189 where an example of IPv4 is 1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0. IPv6 has several important uses such as Mobile IP, which is usually found on GPS, that allows devices to move without losing its connectivity and IPSec which is a protocol suite to secure IP communications.

IPv4 and IPv6 have different header fields (bits) with the comparison as below:

IPv4 (160 bits) = Version(4), IHL(4), Type of Service(8), Total Length(16), Identification(16), Flags(4), Fragment Offset(12), Time to Live(8), Protocol(8), Header Checksum(16), Source Address(32) and Destination Address(32).

IPv6 (320 bits)=Version(4), Traffic Class(8), Flow Label(20), Payload Length(16), Next Header(8), Hop Limit(8), Source Address(128), Destination Address(128)

In total, 3 fields are still the same (Version, Source Address and Destination Address), 5 fields removed from IPv4 to IPv6 (IHL, Identification, Flags, Fragment Offset, Header Checksum), 1 new field in IPv6 (Flow Label) and 4 fields has modified names but almost the same function (Type of Service = Traffic Class, Total Length = Payload Length, Protocol = Next Header, TTL = Hop Limit)

IPv4 uses a range from 0-255 decimal from binary octets, whereas IPv6 has a range of 0000-FFFF hexadecimal. To convert IPv4 compatible adresses, each 2 hexadecimal numbers in IPv6 represent an octet in IPv4. The formula for converting IPv6 into IPv4 is (first digit*16)+second digit. To convert back from IPv4 to IPv6 divide the IPv4 number by 16 (first digit) and the remaining value as the second digit.

For example:

IPv4 to IPv6: 123.145.167.189 = (7*16)+11 - (9*16)+1 - (10*16)+7 - (11*16)+13 = 7B91:A7BD

IPv6 to IPv4 : 65AB:4F23 = (6*16)+5 - (10*16)+11 - (4*16)+15 - (2*16)+3 = 101.171.79.35

IPv6 has 128 bits which are considered very long. There are 2 methods to shorten IPv6 address which are leading zero compression and zero compression. In leading zero compression, all zeros leading in a field can be omitted, but if there are 4 hexadecimal zeros on the field, one zero must be still left. In zero compression, several fields that has only zeros, can be joined together with the symbol :: However, zero compression can only be applied ONCE in an IPv6 address, whereas leading zero compression can be implemented multiple times.

For example:

12AB:0000:0000:0000:0012:023F:0000:FAF8 can be written as below:

Using leading zero compression ==> 12AB:0:0:0:12:0:FAF8

Using zero compression ==> 12AB::12:0:FAF8

There are several addresses with the following initial bits to remember which are:

001 (starting with 0010 hex = 2 decimal or 0011 hex = 3 decimal) = global address

1111 1111 (FF00::/8 hex) = multicast (in IPv4 = 224.0.0.0 – 239.255.255.255)

1111 1110 1 (FEXX) = private address

1111 1110 1100 (FEC0) = site local

1111 1110 1000 (FE80) = link local

::x.x.x.x = IPv4 compatible address

0:0:0:0:0:0:0:1 or ::1 = loopback address (in IPv4 = 127.0.0.1)

0:0:0:0:0:0:0:0 or ::/128 = unspecified address

::/0 = default route

-- 13 April 2011 --

No comments:

Post a Comment