CSCI.4220 Network Programming
Class 4, The Network Layer, IP

The purpose of the network layer is to route packets from source host to destination host. In a point-to-point network such as the Internet, there are two models; virtual circuits, in which the complete path is laid out prior to any data being transmitted, or best effort packet switching. The Internet Protocol (IP) uses the latter. Most other protocols, such as ATM or frame relay, use virtual circuits. Virtual Circuits can provide higher reliability and more stable delivery times (all packets take the same route), at the cost of bandwidth efficiency.

IP Routers

There is only one protocol running on the network layer of the Internet, IP, the Internet Protocol. The current version is version 4. This is a remarkably stable protocol; it has been around for nearly 30 years.

The intermediate nodes of the Internet are called IP Routers. An IP router has five components

The job of an IP Router is to receive packets (sometimes known as datagrams) on its input ports and forward each one onto the next hop on one of its output ports. It may have to buffer the packet briefly while it determines which output line to use. The decision about which output line to use is done by reading the destination address of the packet, and looking this address up the routing table. Once the entry is found, it passes the packet on to the next hop.

Large routers may have to process a million or more packets a second, so the routing table search cannot be linear. Large Cisco routers have 64K of content addressable memory for each input port so it can perform the lookup in constant time. Typically a router will handle packets on a First-In-First-Out (FIFO) basis, since they do not have time to process them on the basis of Type of Service or precedence.

traceroute There is a utility called traceroute which can be used to determine a route that packets take to get from your computer to any destination on the Internet. Here is the route that packets take to get from monica to the website of the Trapp Family Lodge in Stowe Vermont.

The IP Header

The next three fields deal with fragmentation. Each link has a Maximum Transmission Unit (MTU), the maximum size of the payload of a frame. It is 1500 for Ethernet but may be larger or smaller for other protocols. If a packet is too big to be sent over a particular physical layer, it is fragmented, that is, divided into smaller chunks. These are reassembled at the destination.
  • TTLTime to Live. Initially set to a value such as 30, decremented by 1 by each Router. If this reaches zero, the packet must be dropped. This prevents packets from traveling endlessly around the network if a routing table is misconfigured to create a cycle.
  • ProtocolThe protocol of the transport layer (TCP is 6, UDP is 17).
  • Header checksum Calculated at each hop to make sure that the header was not corrupted.
  • Source IP address
  • Destination IP address

    There are a number of possible IP options. These are mostly used for debugging and network tracing.

    Here are some options.

    Here is a link to a description of the fields of the IP header

    And here is another one

    Classes of IP addresses

    An IP address is 32 bits, so there are potentially more than 4 billion hosts on the Internet. In fact, there are far fewer than this, but nonetheless, current estimates put the number of hosts at somewhere around 230 million. Clearly, routing tables cannot be this large.

    A 32 bit IP address is divided into two parts, a network part and a host part. All routing except at the destination network is done on the basis of the network only. For example, the IP address of every host on the RPI network starts with 128.113. The first sixteen bits are the network field and the last 16 are the host field. Outside of RPI, routers only look at the network field. Routers know that when the network field is 128.113, they need to send the packet to the RPI network. But they know nothing about the hosts inside the RPI network.

    This also solves another problem. Suppose an RPI network engineer adds another host to the RPI network and runs a web server on this machine. The host is assigned the IP address 128,113.67.21. Immediately, any web browser on the entire planet could connect to this server (if it somehow knew of its existence). None of the millions of intermediate network routers need to be updated. They just need to know that this is on the RPI network. Once the packet gets to the RPI network, a router somewhere inside RPI needs to know where this machine is, but this is entirely a local RPI problem (see the section in the prior class on ARP.).

    When the Internet was first started, there were a number of classes of network addresses. Different classes divided the network field from the host field in different places.

    A class A address had a zero in the first bit, the next seven bits were the network field, and the remaining 24 bits were the host field. Thus, there could only be 128 Class A networks on the planet, but each of these could have 224 or more than 16 million hosts. These were given out only to the largest organizations (Even today, no one organization would have a need for this many hosts).

    A class B address had the first two bits set to 10. The next 14 bits represented the network field, and the last 16 bits represented the host field. Thus there were potentially 214 class B networks (16,384), and each of these could have up to 64K hosts on it. RPI has a class B network, and in fact the computer science department has its own class B network 128.213.

    Class 0001020304050607 0809101112131415 1617181920212223 2425262728293031
    A 0 Network bits Host bits
    B 1 0 Network bits Host bits
    C 1 1 0 Network bits Host bits
    D 1 1 1 0 Multicast group
    E 1 1 1 1 0 Reserved

    This system worked pretty well for a while, but as the Internet grew, it started to break down. There are still plenty of unused IP addresses, but most organizations have been assigned many more addresses than they need. It is wasteful to give the RPI Computer Science Department 64K of IP addresses (although our lab staff doesn't think so).

    The solution is Classless InterDomain Routing (CIDR). The basic idea is to assign a particular organization only enough IP addresses for their immediate needs. If they grow, they can be assigned more addresses. This can be done by appending another field to the IP address (delimited by a slash) indicating the size of the network prefix.

    For example, a particular organization might be assigned this block
    204.13.18.0/23
    This organization has 512 host IP addresses available on their network (32 - 23 = 9; 29 = 512) (actually 510 because 000000000 and 111111111 are not available).

    CIDR addressing allows much finer address assignment. An ISP can be issued a large block of addresses, say 204.28.16.0/20 (which has 4096 addresses), and then allocated them to a number of customers in blocks of varying sizes. The first customer received a block of 512, the next one could be given 200.23.18.0/24 (256 addresses) etc.

    CIDR makes routing more difficult. An IP router has a routing table, where each entry consists of a network address and an output line. As packets arrive, the router examines the destination address, extracts the network field, looks it up in the routing table, and sends the packet on its way on the appropriate output line.

    With CIDR, the routing tables now need to contain a network mask for each entry as well.

    As long as the assignment of IP blocks is strictly hierarchical (i.e. a large block is assigned to an ISP, and this ISP breaks it up into smaller blocks for its own customers), routing is fairly straightforward. Each Tier 1 Router would have an entry for the large block in its routing table, and would forward all packets to that ISP. However, it can happen that a small block is assigned to a different ISP. This would mean that a particular network address would match more than one entry in the routing table. If this is the case, the rule is that the longer match would take precedence. Here is an example.

    Here is a link to a web site which explains classful and classless routing

    Subnetting A large organization like Rensselaer would divide its network into subnets. To the outside world, Rensselaer has just one IP address, the network address 128.113.xxx.xxx. However, it could have as many as 64K hosts, which is far too big for a single router. The least significant 16 bits, which represent the individual hosts within Rensselaer, can be divided into two parts, the network part and the host part. Suppose the first 6 bits are the network part. Rensselaer can now have 64 separate subnets, each with up to 1K of hosts. Each subnet has its own router. This means that the master router only needs to have at most 64 entries in its routing table, one for each of the up to 64 subnets. Each department (subnet) has its own router, which can have up to 1K entries.

    Here is a web site which discusses subnetting along with classful and classless routing

    DHCP In a traditional network, IP addresses were assigned on a long term basis to a particular computer by the network administrator, based on the subnet. However, subnetting is hard to implement if students are walking around with laptops and plugging them into various subnets all over campus. Rensselaer and most other organizations solve this problem by dynamically assigning IP addresses. Whenever a student plugs their laptop into an ethernet port or establishes an association with a wireless base station, it is assigned a temporary IP address from a pool of IP addresses assigned to that subnet. The protocol that does this is Dynamic Host Configuration Protocol (DHCP). This means that a computer's IP address changes as the student walks around campus.

    DHCP is a client server protocol. When a client connects to a new network, it sends out a DHCP discovery message in order to find out if there is DHCP server on the network. This is broadcast to the the network on port 67. If there is a DHCP server on the network, it returns a DHCP offer message. This contains the proposed IP address of the new client, the network mask, and a lease time. The new client then sends an acknowledgment. There may be several DHCP servers on a network; in this case the client may get several offers, and it chooses one of them. Here is a somewhat sketchy description of DHCP

    Network Address Translation (NAT) Even with CIDR, we are running out of IP addresses. One solution to this problem. is NAT (Network Address Translation), in which a single IP address is assigned to an organization (or home) and a NAT Box translates IP addresses and ports. Within the organization, each host can be assigned an IP address; this IP address is unique in the organization, but not unique on the planet.

    A NAT server sits between the organizations network and the rest of the Internet, often combined with a firewall. Suppose the external IP address of this organization is 213.13.18.10. Note that a single IP address is used for the entire network; However, within the organization, hosts are assigned IP addresses in the 192.168.0.0 to 192.168.255.255 range (they could theoretically use any IP addresses they want, but this range is often used for NAT).

    Suppose a host inside the NAT with address 192.168.10.105 wants to send an HTTP query to a far away server on address 152.63.29.217. The query goes through the NAT server, which performs the following translation.

    The packet from the original host looks like this

    Source address 192.168.10.105 Port 3456
    Destination address 152.63.29.217 Port 80

    When this reaches the NAT, the NAT server translates the Addresses as follows

    Source address 213.13.18.10 Port 4321
    Destination address 152.63.29.217 Port 80

    It keeps a record of this in its table. When the server sends a reply, the packet that comes in to the NAT server from the outside is

    213.13.18.10 Port 4321

    The NAT server looks this address up in its table and translates the address of the packet to

    192.168.10.105 Port 3456.

    Here is a web site on Network Address Translation

    ICMP - The Internet Control Message Protocol

    The Internet Control Message Protocol (ICMP) is a required part of IP, and must be a part of every installation, it sends error messages to other hosts and routers

    It only communicates with the original source. This is because IP has no info about intermediate sources, even if that is where the problem lies).

    The ICMP message format

    8 bit message TYPE
    8 bit CODE
    16 bit checksum

    Examples of ICMP control messages include

    Required Reading

    Here is a link to a description of the fields of the IP header

    Here is a link to a web site which explains classful and classless routing

    Here is a web site which discusses subnetting along with classful and classless routing

    I could not find a good description of NAT; this is as good as any