Chapter6 : Delivery and Forwarding of IP packets
6.1 Delivery
The network layer supervises delivery.
The Delivery of a packet to its final destination is accomplished using two different methods of delivery : Direct and Indirect

6.2 Forwarding
Forwarding means to place the packet in its route to its destination. Forwarding requires a host or a router to have a routing table.
Forwarding techniques
- Next-hop method
- Network-specific method
- Host-specific method
- Default method
6.3 Next-hop method

Next-hop method is
- To reduce the contents of a routing table
- The routing table holds only the address of the next hop instead of information about the complete route
6.4 Network-specific method

Network-specific method is
- To reduce the routing table and simplify the searching process
- Instead of having an entry for every destination host connected to the same physical network, we have only one entry that defines the address of the destination network itself
6.5 Host-specific routing

Host-specific method is
- The destination host address is given in the routing table
- ~inverse of the network-specific method
6.6 Default Routing

Default method is
- Instead of listing all networks in the entire Internet, host A can just have one entry (0.0.0.0) called the default.
6.6 Forwarding with Classful Addressing
Each routing table has a minimum three columns

6.7 Forwarding without Subnetting (forwarding module step)
The destination address of the packet is extracted
A copy of the destination address is used to find the class of the address(shift 28bits to the right)
The result of Step 2 (class of the address) and destination address are used to extract the network address
The class of the address and destination address are used to find next-hop information (if no match is found, the default is used)
The ARP module (Chapter 7) uses the next-hop address and the interface number to find the physical address of the next router
Simplified forwarding module in classful address without subnetting
Figure 6.7

➭ Example 6.1

Figure shows an imaginary part of the Internet. Show the routing tables for router R1.
➭ Example 6.2
Router R1 receives a packet with destination address 192.16.7.14.
Show how the packet is forwarded.

[Solution]
The destination address is
11000000 00010000 00000111 00001110
A copy of the address is shifted 28 bits to the right. The result is
00000000 00000000 00000000 00001100 or 12.
The destination network is class C. The network address is extracted by
masking off the leftmost 24 bits of the destination address; the result is
192.16.7.0. The table for Class C is searched. The network address is found in the first row. The next-hop address 111.15.17.32. and the interface m0 are passed to ARP
➭ Example 6.3
Router R1 receives a packet with destination address 167.24.160.5.
Show how the packet is forwarded.

[Solution]
The destination address in binary is
10100111 00011000 10100000 00000101.
**A copy of the address is shifted 28 bits to the right. The result is
00000000 00000000 00000000 00001010 or 10.
**The class is B. The network address can be found by masking off 16 bits of the destination address, the result is 167.24.0.0. The table for Class B is searched. No matching network address is found. The packet needs to be forwarded to the default router. The next-hop address 111.30.31.18 the interface number m0 are passed to ARP.
6.8 Forwarding with Subnetting

➭ Example 6.4 : Configuration

➭ Example 6.5
The router in Example 6.4 receives a packet with destination address 145.14.32.78. Show how the packet is forwarded.
(00100000)

[Solution]
The mask is /18. After applying the mask, the subnet address is 145.14.0.0.The packet is delivered to ARP (see Chapter 8) with the next-hop address 145.14.32.78 and the outgoing interface m0.
➭ Example 6.6
A host in network 145.14.0.0 in Figure 6.11 has a packet to send
to the host with address 7.22.67.91. Show how the packet is routed.

[Solution]
The router receives the packet and applies the mask (/18). The network address is 7.22.64.0. The table is searched and the address is not found. The router uses the address of the default router (not shown in figure) and sends the packet to
that router.
6.9 Forwarding with Classless Addressing



Show the forwarding process if a packet arrives at R1 in Figure
6.13 with the destination address 180.70.65.140.
140 => (10001100)
[Solution]
The router performs the following steps:
➭ Example 6.9
Show the forwarding process if a packet arrives at R1 in Figure 6.13 with the destination address 201.4.22.35.

[Solution]
The router performs the following steps
- The first mask(/26) is applied to the destination address. The result is 201.4.22.0, which does not match the corresponding network address (row 1).
- The second mask (/25) is applied to the destination address. The result is 201.4.22.0, which does not match the corresponding network address (row2)
- The third mask (/24) is applied to the destination address. The result is 201.4.22.0, which matches the corresponding network address. The destination Address of the package and the interface number m3 are passed to ARP.


➭ Example 6.12
Chapter7 : Internet Protocol V4(IPv4)

7.1 Internet Protocol
7.2 Datagram

7.3 Header
1.Version(VER) : 4bits
2.Header length(HLEN, 20~60 bytes) : 4bits

3.Service type : 8bits

4.Total length : 16bits


5.Identification : 16bits
6.Flags : 3bits
7.Fragmentation offset : 13bits
Identification & Flags & Fragmentation offset are used in fragmentation
8.Time to live : 8bits
9.Protocol : 8bits

Multiplexing
10.Checksum : 16bits
•Source Adress (32 bits)
•Destination Adress (32bits)
Chapter8 : Address Resolution Protocol [ARP]
8.1 Address Mapping
8.2 Internet Addresses
Static Mapping
- Creating a table that associates a logical address with physical address
- This table is stored in each machine on the network
- Each machine knows the IP address of another machine
- It has some limitations because Physical Address may change in the following ways : (changing NIC, moving mobile Computer)
Dynamic Mapping
- Each time a machine knows one of the two addresses(Logical or Physical), it can use a protocol to find the another one
- ARP(Address Resolution Protocol)

8.3 The ARP Protocol

ARP associates an IP address with its Physical Address
On a typical Physical network, such as a LAN, each device on a link is identified by a physical or station address that is usually imprinted on the NIC
ARP accepts a Logical Address from the IP protocol, maps the address to the corresponding Physical Address and pass it to the data link layer
ARP Operation
Figure 8.2


The ARP Protocol : ARP Operation ( A → B in Figure 8.2)

Packet Format
- Hardware type : the type of network (Ethernet : 1)
- Protocol type : defining protocol (IPv4 : 080016)
- Hardware length : the length of PHY address. in bytes
- Protocol length : the length of logical address. In bytes
- Operation : type of packet-ARP request(1), ARP reply(2)
- Sender hardware address : sender PHY address
- Sender protocol address : sender Logical address
- Target hardware address : receiver PHY address
- Target protocol address : receiver Logical address

ARP Encapsulation step is
- Sender knows target IP address
- IP requests ARP to generate an ARP request message (sender Physical Address, IP Address, target IP address, Physical address)
- When delivered to the DLL, the sender address is the sender Physical address, and the target address is the PHY broadcasting address
- All hosts or routers receive frames and forward them to their ARP
- Target system sends ARP reply message including its own physical address (unicast)
- Sender receives a reply message and knows the target system's physical address
- IP datagram is encapsulated into a frame and unicast to the target

Example8.1
A host with IP address 130.23.43.20 and physical address B2:34:55:10:22:10 has a packet to send to another host with IP address 130.23.43.25 and physical address A4:6E:F4:59:83:AB. The two hosts are on the same Ethernet network. Show the ARP request and reply packets encapsulated in Ethernet frames.
[Solution]
Figure 8.6 shows the ARP request and reply packets. Note that
the ARP data field in this case is 28 bytes, and that the individual
addresses do not fit in the 4-byte boundary. That is why we do not show the regular 4-byte boundaries for these addresses. Also note that the IP addresses are shown in hexadecimal.

8.4 ARP Package
This ARP Package involves five modules
- a cache table
- Queues
- an output module
- an input module
- a cache-control module

Cache Table
- Sender sends one or more IP datagrams to one destination
- Using the ARP protocol every time a datagram is sent is very inefficient (using cache table for this)
- When a destination physical address is received, it is stored in cache for a certain period of time
- Cache information is updated continuously, and information that is not updated for a certain period of time is automatically destroyed (typically 20 minutes)
Entry of Cache Table
- State : FREE, PENDING, RESOLVED
- Hardware type, Hardware length, Protocol length, Interface number
- Queue number
- Attempt : the number of times an ARP request is sent out for this entry
- Time-out : lifetime of an entry in seconds
- Hardware address : target PHY address
- Protocol address : target IP
Queues
- Maintain one queue, for each destination, to hold the IP packets while ARP tries to resolve the PHY. Address
- Output module sends unsolved packets into the corresponding queue
- Input module removes a packets from queue and send it, with the resolved PHY. Address
Chapter9 : Internet Control Message Protocol Version 4 [ICMPv4]
1.Services provided at the source computer

2.Processing at each router

3.Processing at the destination computer

9.1 Internet Protocol

Internet Protocol is
- The Internet Protocol (IP) is the transmission mechanism used by the TCP/IP protocols
- IP is an unreliable and connectionless datagram protocol (a best-effort delivery service)
➭ IP Datagram Figure

Datagram is
- Packets in the IP layer are called a Datagrams
- A datagram is a variable-length packet consisting of two pares : header(20~60 bytes, for routing and delivery) and data
The error detection method used by most TCP/IP protocols is called the checksum
9.2 Introduction

Lacks of IP
- Unreliable and connectionless datagram delivery
- Best-effort delivery service
- Lack of error control
- No error-reporting and error-correcting mechanism
- Lacks of mechanism for host and management queries
[ICMP has been designed to compensate for the above deficiencies]

The value of the protocol field in IP datagram is 1 to indicate that the IP data is an ICMP message
9.2 Message
➭ Table 9.1 ICMP messages


Message format
- Type : message type (8 bit)
- Code : specify the reason for the particular message
- Checksum : 16 bit
An ICMP message has an 8-byte header and a variable-size data section. Although the general format of the header is different for each message type, the first 4 bytes are common to all
⚙ ICMP always reports error messages to the original source➭ ICMP common field and message Type

Error-reporting messages
[important points about ICMP error messages]
No ICMP error message for a datagram carrying an ICMP error message
No ICMP error message for a fragmented datagram that is not the first fragment
No ICMP error message for a datagram having a multicast address
No ICMP error message for a datagram with a special address such as 127.0.0.0 or 0.0.0.0
Contents of data field for the error message
Figure 9.5

Contents of data field for error messages
The first 8 bytes provide information about the port numbers (UDP and TCP) and sequence number (TCP)
Destination-unreachable format
Figure 9.6

Destination unreachable



⚙ A Parameter-Problem Message can be created by a router or the destination hostParameter problem is
- Code 0 : Main header Problem
- Code 1 : Problem in the option field


Redirection is
- When a host send a datagram, which is destined for another network, to the wrong router, the router that receives the datagram will forward the datagram to the correct route, However, to update the routing table of host, it send a redirection message to host.
⚙ A redirection message is sent from a router to a host on the same Local Network.Codes
- Code 0: N
- Code 1: Host specific
- Code 2: Network specific (specified service)
- Code 3: Host specific (specified service)
Query

Query messages
- Diagnose some network problems

Timestamp Request and Reply
- The timestamp-request and timestamp-reply messages can be used to synchronize two clocks in two machines if the exact one-way time duration is known
- Timestamp-request and timestamp-reply messages can be used to calculate the round-trip time between a source and a destination machine even if their clocks are not synchronized
- Each field is represented by the unit of Milliseconds from midnight in Universal Time

Steps
- Sender create a timestamp-request message
- Inset the sending time to Original timestamp field
- Other 2 fields is 0
- Receiver create the timestamp to same field
- Copy the value of the original timestamp to same field
- Insert the receiving time of the request message to the receive timestamp
- Insert the sending time of the reply message to the transmit timestamp
Timestamp Request and Reply

⚙ Timestamp-request and timestamp-reply messages can be used to calculate the round-trip time between a source and a destination machine even if their clocks are not synchronizedFormulas of Round-trip time
- Sending time = receive timestamp - original timestamp
- Receiving time = packet return time - transmit timestamp
- Round-trip time = sending time + receiving time
➭Example
1.ㅤGiven the following information
2.ㅤWe can calculate
3.ㅤWe have
Checksum
“In ICMP the checksum is calculated over the entire message (header and data)”
Checksum Calculation
The Sender uses a conservative operation of 1 to perform the following steps
Checksum Testing
Receiver performs the next step using a conservative operation of 1
Obtain the sum of 16-bit words for header and data
calculate the remuneration of the sum
If the result of the previous step is 16 zeros, the message is accepted, otherwise refusal
Example 9.1
Figure 9.14

Figure 9.14 shows an example of checksum calculation for a simple echo-request message. We randomly chose the identifier to be 1 and the sequence number to be 9. The message is divided into 16-bit (2-byte) words. The words are added together added together and the sum is complemented. Now the sender can put this value in the checksum field.
Chapter10-11 : MIP & Routing
Mobile IP
“The main problem that must be solved in providing mobile communication using the IP Protocol is addressing”
A. Stationary Host
Assume that the host with the original IP address is connected to a particular network and in a quiesced state
B. Mobile host
If a host moves from one network to another, the IP address structure must also change
Mobile hosts Address

Data transfer

Send a packet with your own address as the source address and your home address as the destination address
Home Agent to Foreign Agent (route 2)
After receiving a packet, receive the packet and send it to a foreign agent using the tunneling concept
Out-of-town agent to mobile host (route 3)
Extract the original packet, refer to the registration table, and find the address of the mobile host's trust
From mobile host to remote host (route 4)
Send as normal
Ex. Routing protocol Dijkstra’s algorithm

Chapter13 : Introduction to the Transport Layer
13.1 Transport-Layer Services
The transport layer is located between the network layer and the application layer.

The transport layer is responsible for providing services to the application layer; it receives services from the network layer.
As a network-layer protocol, IP can deliver the message only to the destination computer
The message still needs to be handed to the correct process
Port Numbers :: Figure 13.2

[Local host, Local Process, Remote host, Remote Process]

The combination of an IP address and a port number is called a Socket Address
The IP header contains the IP addresses
UDP needs two identifiers, the IP address and the port number
The UDP header contains the port numbers
Pushing or Pulling :: Figure 13.8
Flow Control
- The balance between the production rate and the consumption rate between the information producer and the consumer is important
- The method of transferring information from the producer to the consumer is as follows :
- Pushing: delivered by the producer without a consumer request.
- Pulling: Forward only if requested by the consumer.
Flow Control can be implemented normally by using two buffers

Error Control at the Transport Layer is responsible to
Error Control
Sequence number is
acknowledgment (ACK)
is a signal that is passed between communicating processes, computers or devices to signify acknowledgment, or receipt of message, as part of a communication protocol.
The negative-acknowledgement (NAK or NACK)
is a signal that is sent to reject a previously received message or to indicate some kind of error. Acknowledgments and negative acknowledgments inform a sender of the receiver's state so that it can adjust its own state accordingly.
⚙ For error control, the sequence numbers are modulo 2^m, where m is the size of the sequence number field in bits.

13.2 Congestion Control

Congestion Control is
~refers to the mechanisms and techniques to control the congestion and keep the load below the capacity
⚙ **NEED of Congestion Control:**A. Open-Loop Congestion Control
(Open loop congestion control policies are applied to prevent congestion before it happens)
B. Closed-Loop Congestion Control
(Closed loop congestion control techniques are used to treat or alleviate congestion after it happens)
Connection-Oriented vs Connectionless Service
| S. No | Comparison Parameter | Connection-oriented Service | Connection Less Service |
|---|---|---|---|
| 1. | Related System | It is designed and developed based on the telephone system. | It is service based on the postal system. |
| 2. | Definition | It is used to create an end to end connection between the senders to the receiver before transmitting the data over the same or different network. | It is used to transfer the data packets between senders to the receiver without creating any connection. |
| 3. | Virtual path | It creates a virtual path between the sender and the receiver. | It does not create any virtual connection or path between the sender and the receiver. |
| 4. | Authentication | It requires authentication before transmitting the data packets to the receiver. | It does not require authentication before transferring data packets. |
| 5. | Data Packets Path | All data packets are received in the same order as those sent by the sender. | Not all data packets are received in the same order as those sent by the sender. |
| 6. | Bandwidth Requirement | It requires a higher bandwidth to transfer the data packets. | It requires low bandwidth to transfer the data packets. |
| 7. | Data Reliability | It is a more reliable connection service because it guarantees data packets transfer from one end to the other end with a connection. | It is not a reliable connection service because it does not guarantee the transfer of data packets from one end to another for establishing a connection. |
| 8. | Congestion | There is no congestion as it provides an end-to-end connection between sender and receiver during transmission of data. | There may be congestion due to not providing an end-to-end connection between the source and receiver to transmit of data packets. |
| 9. | Examples | Transmission Control Protocol (TCP) is an example of a connection-oriented service. | User Datagram Protocol (UDP), Internet Protocol (IP), and Internet Control Message Protocol (ICMP) are examples of connectionless service. |


13.3 Transport-Layer Protocols
To better understand the behavior of transport-layer protocols,

Simple Protocol is
- Connection Less Protocol
- No Flow Control and Error Control
The design of the simplest protocol with no flow or Error Control
⚙ The simple protocol is a ConnectionLess Protocol that provides neither flow nor Error Control
Stop-And-Wait Protocol
- It is Connection-Oriented Protocol
- ~uses both Flow and Error Control

Only one packet and one acknowledgement can be in the channels at any time
Sequence Number
Acknowledgement number
➭Example 13.5


Go-Back-N Protocol is
- ~can send several packets before receiving acknowledgments
- but the receiver only buffer one packets
Sequence Numbers
Acknowledgement Numbers
In the Go-Back-N protocol, the acknowledgment number is cumulative and defines the sequence number of the next packet expected to arrive
Send window for Go-Back-N :: Figure 13.23

Send Window
- The send window is an abstract concept defining an imaginary box of maximum size = 2^m-1 with three variables : Sf, Sn, and Ssize.
- The send window can slide one or more slots when an error-free ACK with ackNo between Sf and Sn (in modular arithmetic) arrives.

Receive Window is
- The receive window is an abstract concept defining an imaginary box of size 1 with one single variable Rn. The window slides when a correct packet has arrived; sliding occurs one slot at a time.
[Timers]
[Resending Packets]
On a time-out, the machine goes back N locations and resends all packets
Send window size for Go-Back-N :: Figure 13.27
Send Window Size is
- In the Go-Back-N Protocol, the size of the send window must be less than 2^m; the size of the receive window is always 1.


Chapter14 : User Datagram Protocol [UDP]
14.1 Introduction
UDP lies between the application layer and the IP layer and, like TCP, serves as the intermediary between the application programs and the network operations
- UDP create a process-to-process communication
- UDP is called a connectionless, unreliable transport protocol
- It performs very limited error checking
- UDP is a very simple protocol using a minimum of overhead
- If a process wants to send a small message and does not care much about reliability, it can use UDP
14.2 User Datagram

UDP Services
- Process-to-Process Communication
- Connectionless Service
- Flow Control
- Error Control
- Congestion Control
- Encapsulation and Decapsulation
- Queuing
- Multiplexing and Demultiplexing
- Comparison between UDP and Generic Simple Protocol
[1] Process-to-Process Communication

Connectionless Service Flow, Error and Congestion Control
Connectionless Service
- UDP provides a connectionless service
- ~ means that each user datagram sent by UDP is an independent datagram
- ~ means that each user datagram can travel on a different path
Flow and Error Control
- UDP is a very simple, unreliable transport protocol
- There is no flow control, and hence no window mechanism
- The receiver may overflow with incoming messages
- There is no error control mechanism in UDP except for the checksum
- When the receiver detects an error through the checksum, the user datagram is silently discarded
Congestion Control
- UDP is a connectionless protocol
- It does not provide congestion control



Queues in UDP Multiplexing and Demultiplexing 
UDP Applications
UDP meets almost none of the criteria for a reliable transport-layer protocol, UDP is preferable for some application
Chapter15 : Transmission Control Protocol [TCP]
TCP Services
TCP lies between the application layer and network layer, and serves as the intermediary between the application programs and the network operations
Stream Delivery
Sending and Receiving Buffers
- TCP is a Stream-Oriented Protocol
- TCP allows the sending process to deliver data as a stream of bytes
- allows the receiving process to obtain data as a stream of bytes
Stream Delivery Service
Sending and Receiving Buffers

Sending and Receiving Buffers
TCP segments
Figure 15.4
Segments
- The IP layer needs to send data in packets, not as a stream of bytes
- At the transport layer, TCP groups a number of bytes together into a packet called a segment
TCP Services
TCP vs UDP Communication

TCP has several features
- Numbering System
- Flow Control
- Error Control
- Congestion Control
Numbering System
Acknowledgement Number
⚙ The value of the acknowledgment field in a segment defines the number of the next byte a party expects to receive. The acknowledgement number is cumulative.