The Internet Protocol

1. Purpose

- the Internet Protocol (IP) provides a uniform method for hosts on an
  internet to communicate

2. Packet Format

    0                   1                   2                   3   
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |Version|  IHL  |Type of Service|          Total Length         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |         Identification        |Flags|      Fragment Offset    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |  Time to Live |    Protocol   |         Header Checksum       |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                       Source Address                          |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Destination Address                        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Options                    |    Padding    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
                    Example Internet Datagram Header

Version
- current version is IPv4
- there are specifications for IPv6 and some implementations exist and/or
  are being worked on, but it's still unclear when or if it will be
  deployed in the Internet (5 was taken by another protocol)
- different versions can have totally different formats after the version
- about 5 versions taken; 7 unassigned; 1 in use on the net (1994)
IHL
- length of Internet Header in multiples for 32 bits
- used to figure out where the data starts

Type of Service (ToS)
- theoretically allow the specification of precidence, delay, throughput,
  and reliability
- in practice, not implemented

Total Length
- length including header and data in octets (bytes)
- field space allows for packets of up to 65535 octets (64k)
- hosts must be able to accept packets of at least 576 octets
- typical packet lengths are bounded by level 1/2 medium? 
  ethernet: 1500, fddi: 4352, slip: 1006

Identification, Flags, Fragment Offset
- used for fragmentation & reassembly

Time to Live (TTL)
- indicates how long packet should live in seconds (sort of)
- the packet shoud be discarded if TTL is zero
- each router must decrement the TTL by at least one,
- very important for preventing a packet from looping infinitely

Protocol
- describes the protocol of the data carried in the IP packet
- about 100 taken, 150 unassigned
- TCP (6) and UDP (17) most common; ICMP (1), IGMP (2), IP in IP (4),
  RSVP (46), OSPFIGP (89) can also be found

Header Checksum
- computed on the header only, to guard against corruption
- must be redone at every router since some fields (notably TTL) change
-     The checksum field is the 16 bit one's complement of the one's
      complement sum of all 16 bit words in the header.  For purposes of
      computing the checksum, the value of the checksum field is zero.
- you want this to be fast! (write code in such a way that it will get
  really optimized, write it in assembly, cheat and assume TTL going down
  by one is only change)

Source Address, Destination Address
- 32 bits = 2^32 = 4.3 billion addresses

Options
- variable length
- options are: Security, Loose Source Routing, Strict Source Routing,
  Record Route, Stream ID, Internet Timestamp.
- of these, only LSR and SSR are really useful/work on the Internet
- they let you specify the route for your packet to take - useful for
  debugging and exploring

Fragmentation & Reassembly
- allows IP packets to be larger than a L2 net on the path can handle
- don't fragment bit says to discard it instead of fragmenting
- id field will be the same for all fragments of the same packet
- fragment offset tells you how to reassmble
- flag is true as long as there are more fragments
- fragmented packets will take the slow path in routers, so it's usually a
  good idea to avoid them
- ways to avoid: use TCP or some other transport protocol that deals with this
  for you, keep packets below typical minimum MTU (1500 bytes) (ethernet),
  handle splitting long messages up in your protocol design
- path MTU discovery (RFC1191) helps: set don't fragment bit and assume path 
  MTU is MTU of first hop; reduce transmit size if packet gets dropped

Host Functions 


Router Functions






References

RFC791