> For the complete documentation index, see [llms.txt](https://sliu583.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sliu583.gitbook.io/blog/networking/index/computer-networking-a-top-down-approach/stanford-cs144/chapter-1/1.3-the-ip-service-model.md).

# 1.3 The IP Service Model

![](/files/-MgWsfF-9IbpHlYhR5Ab)

![](/files/-MgWsoWZk7Q4ZEGUmoF5)

* IP&#x20;
  * Datagram service: packet routed according to the header&#x20;
    * Each router contains a forwarding table (where to send the packets next), use destination address to index in the table to forward&#x20;
  * Unreliable
  * Best effort: won't drop datagrams arbitrarily, only drop if necessary&#x20;
    * E.x. congestion (drop), or duplicated by mistakes&#x20;
  * Connectionless&#x20;
    * Each datagram individually, independently&#x20;
* Why so simple?&#x20;
  * Simple, dumb, minimal: faster, more streamlined and lower cost to build and maintain
  * The end-to-end principle: where possible, implement features in the end hosts&#x20;
  * Allows a variety of reliable (or unreliable) services to be built on top&#x20;
    * E.x. some times there's no need to re-transmit (video services)&#x20;
  * Works over any link layer: makes very few assumptions about the link layer below&#x20;

#### IP Service Model (Details)

1. **Tries to prevent packets looping forever**&#x20;
   1. Likely to happen when forwarding table is changing
   2. Hop-count field (TTL field): decremented by every router it passes through, if reaches 0, then IP concludes that it must be stuck in the loop, delete the datagram
2. **Will fragment packets if they are too long**
   1. Ethernet: carry shorter than 1500 bytes packet &#x20;
   2. IP provides header field to help the router fragment the datagram into two self-contained IP datagrams&#x20;
3. **Uses a header checksum to reduce the chances of delivering datagram to wrong destination**&#x20;
4. **Allows for new versions of IP**&#x20;
   1. Currently IPv4 with 32 bit addresses&#x20;
   2. And IPv6 with 128 bit addresses&#x20;
5. **Allows for new options to be added to header**&#x20;

#### IPv4 Datagram&#x20;

* Protocol ID: what's inside the data field. Allows the destination end host to demultiplex arriving packets, sending them the correct code to process the packet&#x20;
  * E.x. 6: TCP segment --> TCP code --> parse the segment&#x20;
  * Total 140 values (representing different transport protocol)&#x20;
* Total packet length: up to 64k bytes&#x20;
* TTL: prevent looping. Decrement by router. If 0, router drops the packet.&#x20;
* Packet ID, flags, fragment offset: help router to fragment&#x20;
* Type of service: hint to routers of how important this packet is&#x20;
* Header length: how big the header is&#x20;
* Checksum: whole header, just in case the header is corrupted, we are not likely to deliver a packet to the wrong destination by mistake&#x20;

![](/files/-MgXAQ5oouyx-WSyTvFN)

#### Summary&#x20;

* Use IP every time we send and receive datagrams&#x20;
* IP provides deliberately simple service:
  * Datagram
  * Unreliable&#x20;
  * Best-effort&#x20;
  * Connectionless&#x20;
