---
# System prepended metadata

title: 50.012 Lecture 13

---

# 50.012 Lecture 13
Textbook references: Section 5.1, 5.2
# Internet Protocol
![](https://i.imgur.com/2eiM9Ke.png)
IP protocol is one of the most important protocols for the Internet and it lies in the network layer. 

## IP Datagram
![](https://i.imgur.com/gtN35Kt.png)

IP header ranges from the start to the options section. If TCP is used, the TCP header follows the IP header (it lies in the payload section).

TTL: when the packet runs out of number of hops, ICMP protocol will be the one that handles signaling.

### IP Fragmentation, Assembly
![](https://i.imgur.com/JsKdnjQ.png)

When a packet is sent out of a host, it needs to travel across multiple links. Every link might have different link-layer protocol (some might support larger packets, some support smaller packets). 

When the router receives a large packet and it is about to send to the outgoing link, it will notice that the outgoing link has a smaller MTU (Max transfer size). The design of IPv4 is to allow the router to fragment this datagram into smaller datagram, and send them separately. 

Each smaller datagram has enough information to reassemble. Each contains the original IP header.

Reassembly is only done at the final destination. 
Cons of reassembly before the final destination:
* There is an additional overhead cost of reassembly  on the routers. This means the router will have to wait for the entire packet to arrive, reassemble it, and forward it to the next router.
* Splitting it will create multiple duplicate headers (larger size).

Pros of reassembly before the final destination:
* Less cost on the end host.
* Smaller size.

![](https://i.imgur.com/2pC70lu.png)

$offset=\frac{(length-header\_length)}{8}$
The reason why the offset is divided by 8 is to save space (space provided is 13 bits).

A router can do a second layer fragmentation (fragmenting a fragment of IP datagram). 

Retransmission is handled by the upper layers (e.g. Transport or Application layer).

## IP Addressing

![](https://i.imgur.com/0Tyxe1W.png)

An IP Address is a 32-bit identifier for host, router interface. Each IPv4 address is assigned to an interface (so that the interface is addressable). It can be a host / router interface. 

An interface is a connection between host/router and physical link. Routers typically have multiple interfaces, whereas hosts typically have 1-2 interfaces (e.g. Wired Ethernet, wireless 802.1).

Ethernet interfaces are connected by Ethernet switches, whereas wireless WiFi interfaces are connected by WiFi base stations. 


### Subnets
In IP Address, subnet part refers to the high order bits, whereas host part refers to the low order bits.

From the figure above, the router in the middle is connected to 3 different subnets. The purpose is for the router to physically reach each other without intervening router. 

If 2 hosts are in the same subnet, they have the same prefix.
The length of the subnet part is variable. It depends on the network mask of the subnet.

![](https://i.imgur.com/N91y2AZ.png)

In order to determine the subnets, detach each interface from its host or router, creating islands of isolated networks.
From here, we can determine the subnets.

![](https://i.imgur.com/cvEgN9l.png)

How do we distinguish between the subnet part and the host part?

### IP Addressing: CIDR
Classless InterDomain Routing (CIDR) is the usbnet portion of adderess of arbitrary length.

The address format: a.b.c.d/x, where x is the number of bits in the subnet portion of address.
![](https://i.imgur.com/3EJSgho.png)
This means the first 23 bits are used for the subnet part, whereas the remaining 9 bits are used for the host part (less number of hosts).

### In-class Activity
![](https://i.imgur.com/LSfF39S.png)

![](https://i.imgur.com/ZqmC4jZ.png)

Another possible solution:
![](https://i.imgur.com/tFAOvr6.png)

## DHCP
Motivation: How does a host get IP address?
* hard-coded by system admin in a file
* Dynamic Host Configuration Protocol (DHCP): dynamically get address from a server (more common).

### Goal of DHCP
DHCP is run on the application layer. It allows host to dynamically obtain its IP Address from network server when it joins network.
* It can renew its lease on address in use.
* Allows reuse of address (only hold address while connected "/on")
* Support for mobile users who want to join network.

### DHCP Overview (DORA)
* Host broadcasts "DHCP **d**iscovered" msg. (optional)
* DHCP server responds with "DHCP **o**ffer" msg. (optional)
* Host requests IP address: "DHCP **r**equest" msg.
* DHCP server sends address: "DHCP **a**ck" msg.

For each network that runs DHCP, there will be a DHCP server which maintains a list of IP Addresses.
When a new host comes in, it will need an address in the network. The server will look up the allocation table and find which IP address has yet to be allocated.


### Example Client-Server Scenario

![](https://i.imgur.com/qACasHD.png)
![](https://i.imgur.com/HaoQjOx.png)

1. Arriving client doesn't have the IP Address of the DHCP Server. It will send a DHCP Discover broadcast to find the IP Address of the server. Broadcast is done by setting all bits into 1 (i.e.255.255.255.255). Since the client has yet to have an IP Address, src will be set to a temporary address 0.0.0.0. DHCP is run on top of UDP: port 67 is designated to be the destination port, and port 68 the src port.
2. Upon receiving the "discover", it will send a broadcast reply (since client doesn't have an IP Address yet). Transaction ID is there to identify the client (and for the client to identify the offer). yiaddress is the allocated IP Address that the client can use. Lifetime refers to the amount of lease time for the client to use the IP Address. 
3. Client will then send the DHCP Request to inform the server that the client will be using the yiaddress that the server provided.
4. Server will send the DHCP ACK to acknowledge that the client will be using the assigned IP Address.

At the offer packet, although the server has already determined the designated IP Address for the new client, why does it still broadcast the offer packet instead of sending it to the designated IP Address?

* It is good to broadcast so that all clients in the network receive that information.
* In the case where there are 2 DHCP servers, and both offer the incoming client at the same time, the client could choose one to accept. When the server offers, we cannot assume that the client will definitely take the offer.

Similarly, DHCP request is also broadcast to everyone:
* To notify everyone in the network that the client wants to take up the particular offer that they're broadcasting (and implying that they reject the other offers).

### Other functions of DHCP
DHCP an return more than just allocated IP Address on subnet:
* Address of first-hop router for the client. 
* Name and IP Address of DNS Server.
* Network Mask (indicating network vs. host portion of address). This is so that the incoming client can communicate with others from different subnet.

### DHCP Example
![](https://i.imgur.com/5z50rcO.png)

### DHCP for Network
![](https://i.imgur.com/lBr36Qp.png)

When an organization subscribes to a particular ISP, they will be granted an allocated portion of the provider ISP's address space, depending on the number of addresses required by the organization.

## Hierarchical Addressing: Route Aggregation
![](https://i.imgur.com/5g9dUad.png)
ISP A and ISP B are autonomous, meaning that they could decide their addresses without informing each other. There will be a router at each ISP. When the request from any of the organization reaches the ISP, the ISP will aggregate the addresses requested by each organization and announce the aggregated block to the Internet. This is important since it will reduce the number of entries from 8 to 1.

![](https://i.imgur.com/HdEmoZU.png)

Consider the case where Organization 1 changes from ISP A to ISP B, but still keeping the same IP Address.
When ISP B admits Organization 1, it will add the prefix of Organization 1 to the announcement. Since Longest Prefix Matching is used, ISP A doesn't have to change the announcement since it has a less specific prefix compared to the one sent by ISP B.

Note: An organization can be served by multiple ISPs (Multi-homing).


## Network Address Translation
Motivation: How to support all users when number of active users >> number of IP Addresses?
![](https://i.imgur.com/LiXEl9u.png)

In this example, 10.0.0.4 is called the private IP Address, which is not unique. In other networks, there can be other hosts with the same private IP Address. 
However, 138.76.29.7 is a public IP address, which is unique across the whole Internet. Within the internal network, a device can communicate with one another using the private IP Address. 

### Benefits of NAT
Local network can use just one IP Address as far as outside world is concerned:
* Range of addresses not needed from ISP: just one IP Address for all devices.
* Can change addresses of devices in local network without notifying outside world.
* Can change ISP without changing addresses of devices in local network
* Devices inside local network are not explicitly addressable, visible by outside world (a security plus)

### Implementation of NAT
The local IP addresses are determined by the router using DHCP.
Steps taken by the NAT Router (Gateway):
* Replace `(source IP Address, port #)` of every outgoing datagram to `(NAT IP Address, new port #)`. Changing the port number is a violation of the layering, since port number belongs to the Transport layer and not Network layer. However, it's needed to use a single router with multiple hosts behind it. If we can't change the port number, there might be a collision when 2 hosts use the same ports.
* Remember (in NAT translation table) every `(source IP Address, port #)` to `(NAT IP Address, new port #)` translation pair. This is so that the router can map back the response sent from the outside world back to the source IP Address and port number.
* Replace `(NAT IP Address, new port #)` in destination fields of every incoming datagram with corresponding `(source IP Address, port #)` stored in NAT table (Reverse Translation).

![](https://i.imgur.com/PLHlShV.png)
![](https://i.imgur.com/VflVXrv.png)
![](https://i.imgur.com/6Rj89Ag.png)
![](https://i.imgur.com/kXLf0EM.png)

### More Details about NAT
16-bit port-number field: Each WAN-side address can support 60,000+ simultaneous connections.

NAT is controversial:
* Routers should only process up to layer 3.
* Address shortage should be solved by IPv6
* Violates end-to-end argument
    * NAT possibility must be taken into account by app designers, e.g. P2P applications: need to be aware of the existence of NAT and how to deal with NAT.
* NAT traversal: What if client wants to connect to a server behind NAT?

## IPv6
Motivation: 32-bit address space will soon be completely allocated.
Additional motivation:
* Header format helps speed processing/forwarding
* Header changes to facilitate QoS

### IPv6 datagram format:
* Fixed-length 40 byte header
* No fragmentation allowed
![](https://i.imgur.com/5US9lMp.png)
priority: to identify traffic class
flow label: to identify datagrams in the same "flow"
next header: to identify upper layer protocol for data


### IPv6 vs IPv4
![](https://i.imgur.com/O3t5Wtd.png)
* In IPv4, header checksum is changed whenever the TTL is changed. Removing it will reduce processing time.
* Fragmentation is not allowed also due to the performance overhead.
* IPv6 does not allow for `options` anymore. Instead, it uses `next header` that will point to an address in data that will act as "options".

### Transition from IPv4 to IPv6

Not all routers can be upgraded simultaneously. This brings in the idea of tunneling to help with the transition.


### Tunneling
![](https://i.imgur.com/P2c3XPx.png)

Tunneling: IPv6 datagram encapsulated in an IPv4 datagram as a payload among IPv4 routers.

![](https://i.imgur.com/LOCuUMq.png)
