Internet Protocol, or just IP, is a TCP/IP network layer protocol for addressing and routing packets of data between hosts on a TCP/IP network. Internet Protocol (IP) is a connectionless protocol that provides best-effort delivery using packet-switching services.
How it works
IP does not guarantee delivery of data. The responsibility for guaranteeing delivery and sending acknowledgments lies with the higher transport-level protocol Transmission Control Protocol (TCP).
The structure of an IP packet is shown in the following diagram. Some of the more important header fields include
- Source IP address: The IP address of the host transmitting the packet.
- Destination IP address: The IP address of the host to which the packet is being sent, a multicast group address, or the broadcast IP address 255.255.255.255.
- Header checksum: A mathematical computation used for verifying that the packet was received intact.
- Time to Live (TTL): The number of router hops that the packet can make before being discarded.
- Fragment offset: The position of the fragment if the original IP packet has been fragmented (for example, by a router). This information enables the original packet to be reconstructed.
IP packets are routed in the following fashion:
- If IP determines that the destination IP address is a local address, it transmits the packet directly to the destination host.
- If IP determines that the destination IP address is a remote address, it examines the local routing table for a route to the destination host. If a route is found, it is used; if no route is found, IP forwards the packet to the default gateway. In either case, the packet destined for a remote address is usually sent to a router.
- At the router, the TTL is decreased by 1 or more (depending on network congestion), and the packet might be fragmented into smaller packets if necessary. The router then determines whether to forward the packet to one of the router’s local network interfaces or to another router. This process repeats until the packet arrives at the destination host or has its TTL decremented to 0 (zero) and is discarded by a router.
The basic unit of data exchange in the IP layer is the Internet Datagram. The format of an IP datagram and a short description of the most important fields are included below:
- LEN – The number of 32 bit-segments in the IP header. Without any OPTIONS, this value is 5
- TYPE OF SERVICE – Each IP datagram can be given a precedence value ranging from 0-7 showing the importance of the datagram. This is to allow out-of-band data to be routed faster than normal data. This is very important as Internet Control Message Protocol (ICMP) messages travels as the data part of an IP datagram. Even though an ICMP message is encapsulated in a IP datagram, the ICMP protocol is normally thought of as a integral part of the IP layer and not the UDP or TCP layer. Furthermore, the TYPE OF SERVICE field allows a classification of the datagram in order to specify is the service desired requires short delay time, high reliability or high throughput. However, in order for this to have any effect, the gateways must know more than one route to the remote host and as described in the Introduction, this is not the case.
- IDENT, FLAGS, and FRAGMENT OFFSET – These fields are used to describe fragmentation of a datagram. The actual length of an IP datagram is in principle independent of the length of the physical frames being transferred on the network, referred to as the network’s Maximum Transfer Unit (MTU). If a datagram is longer than the MTU then it is divided in to a set of fragments having almost the same header as the original datagram but only the amount of data that fits into a physical frame. The IDENT flag is used to identify segments belonging to the same datagram, and the FRAGMENT OFFSET is the relative position of the fragment within the original datagram. Once a datagram is fragmented it stays like that until it receives the final destination. If one or more segments are lost or erroneous the whole datagram is discarded. However, the underlying network technology is not completely hidden below the IP layer in spite of the fragmentation functionality. The reason is that the MTU can vary from 128 or less to several thousands of bytes dependent of the physical network (Ethernet has a MTU of 1500 bytes). It is hence question of efficiency when choosing the right datagram size so that fragmentation is minimized. It is recommended that gateways are capable of handling datagrams of at least 576 bytes without having to use fragmentation.
- TIME – This is the remaining Time To Live (TTL) for a datagram when it travels on the Internet. The Routing Information Protocol (RIP) specifies that at most 15 hops are allowed.
- SOURCE IP-ADDRESS and DESTINATION IP-ADDRESS – Both the source and destination address is indicated in the datagram header so that the recipient can send an answer back to the transmitting host. However, note that only the host address is specified – not the port number. This is because the IP protocol is an IMP-to-IMP protocol – it is not an end-to-end protocol. A layer more is needed to actually specify which two processes on the transmitting host and the final destination that should receive the datagrams.
- Note that the IP-datagram only leaves space for the original source IP-address and the original destination IP-address. As mentioned in the section Gateways and Routing the next hop address is specified by encapsulation. The Internet Layer passes the IP-address of the next hop address to the Network Layer. This IP-address is bound to a physical address and a new frame is formed with this address. The rest of the original frame is then encapsulated in the new frame before it is sent over the communication channel.
Note that the IP-datagram only leaves space for the original source IP-address and the original destination IP-address. As mentioned in the section Gateways and Routing the next hop address is specified by encapsulation. The Internet Layer passes the IP-address of the next hop address to the Network Layer. This IP-address is bound to a physical address and a new frame is formed with this address. The rest of the original frame is then encapsulated in the new frame before it is send over the communication channel.