Computer Networks - Network Layer

Network Layer

Unit II Topics

  • Services

  • Switching Techniques:

    • Datagram Approach

    • Virtual-Circuit Approach

  • Internet Protocol: IPv4 & IPv6

  • Classful Addressing

  • Classless Addressing

  • CIDR

  • Subnetting, NAT, ICMP

  • Routing Algorithms:

    • Distance-Vector (DV) Routing

    • Link State (LS) Routing

  • Routing in Internet: RIP, OSPF, BGP

Functions of Network Layer

  • The Network Layer is the third layer of the OSI model.

  • It handles service requests from the transport layer and forwards them to the data link layer.

  • Translates logical addresses into physical addresses.

  • Determines the route from source to destination.

  • Manages traffic problems like switching and routing.

  • Controls data packet congestion.

  • Moves packets from sending host to receiving host.

Network Layer Services

  • Guaranteed delivery: Ensures packet arrival at the destination.

  • Guaranteed delivery with bounded delay: Ensures packet delivery within a specified delay.

  • In-Order packets: Ensures packets arrive in the order they were sent.

  • Guaranteed max jitter: Maintains equal time between successive transmissions and receipts.

  • Security services: Provides security using a session key between source and destination, including encryption and decryption for data integrity and authentication.

Network Layer Services (Detailed)

  • Packetizing: Encapsulating data (payload) from upper layers into a network layer packet at the source and decapsulating at the destination.

  • Routing: Moving packets to the router's output link after reaching the router's input link.

  • Logical Addressing: Implementing logical addressing to distinguish between source and destination systems, adding a header with logical addresses.

  • Internetworking: Providing logical connection between different types of networks.

  • Fragmentation: Breaking packets into smaller data units for travel through different networks.

Forwarding & Routing

  • A router forwards a packet by examining its header field.

  • The header field value indexes into the forwarding table.

  • The forwarding table's value indicates the router's outgoing interface link for packet forwarding.

Network Layer Design Issues

  • Routing: Process of moving data from one device to another, finding the best possible route.

  • Forwarding: Action applied by each router when a packet arrives at one of its interfaces.

  • Routing involves packet forwarding from an entry interface to an exit interface.

Store and Forward Packet Switching

  • The host sends the packet to the nearest router.

  • The packet is stored until fully arrived and checksum is verified.

  • It is then forwarded to the next router until destination is reached.

Services Provided to Transport Layer

  • Services must not depend on router technology.

  • The transport layer needs protection from the type, number, and topology of available routers.

  • Network addresses for the transport layer should use a uniform numbering pattern at LAN and WAN connections.

Connection-Based Services

  • Connectionless: Packets are routed and inserted into the subnet individually without added setup.

  • Connection-Oriented: Subnet offers reliable service; all packets are transmitted over a single route.

Switching Techniques

  • Circuit Switching

  • Packet Switching

  • Message Switching

Circuit Switching Techniques

  • A dedicated path is established for data transmission between sender and receiver.

  • A pre-specified route is needed, and no other data is permitted on it.

  • Circuits can be permanent or temporary.

  • Three phases:

    • Establish a circuit

    • Transfer the data

    • Disconnect the circuit

Advantages of Circuit Switching
  • Once the path is set up, the only delay is in data transmission speed.

  • No congestion or garbled message problems.

Disadvantages of Circuit Switching
  • Long setup time is required.

  • A request token must travel to the receiver and be acknowledged before transmission.

  • The line may be held up for a long time.

Message Switching Techniques

  • The whole message is treated as a data unit and is switched/transferred in its entirety.

  • A switch first receives the whole message and buffers it until resources are available to transfer it to the next hop.

  • No dedicated path is established between the sender and receiver.

  • If the next hop does not have enough resources, the message is stored, and the switch waits.

  • The destination address is appended to the message.

  • It is dynamic routing as the message is routed through intermediate nodes based on available information.

  • Each node stores the entire message and then forwards it (store and forward network).

Disadvantages of Message Switching
  • Every switch in the transit path needs enough storage for the entire message.

  • Message switching is very slow because of the store-and-forward technique and waits.

  • Message switching was not a solution for streaming media and real-time applications.

Advantages of Message Switching
  • Data channels are shared among communicating devices, improving bandwidth efficiency.

  • Traffic congestion is reduced because messages are temporarily stored in nodes.

  • Message priority can be used to manage the network.

  • The size of the message can be varied, supporting data of unlimited size.

Packet Switching Techniques

  • The message is divided into smaller pieces (packets) sent individually.

  • Packets are given a unique number to identify their order at the receiving end.

  • Every packet contains information in its headers, such as source address, destination address, and sequence number.

  • Packets travel across the network, taking the shortest path possible.

  • All packets are reassembled at the receiving end in the correct order.

  • If any packet is missing or corrupted, a message is sent to resend it.

  • An acknowledgment message is sent if the correct order of packets is reached.

  • Datagram Packet switching

  • Virtual Circuit Switching

Advantages of Packet Switching
  • Delay in packet delivery is less since packets are sent as soon as available.

  • Switching devices don’t require massive storage.

  • Data delivery can continue even if some parts of the network face link failure; packets can be routed via other paths.

  • It allows simultaneous usage of the same channel by multiple users.

  • It ensures better bandwidth usage as packets from multiple sources can be transferred via the same link.

Disadvantages of Packet Switching
  • They are unsuitable for applications that cannot afford delays in communication, like high-quality voice calls.

  • Packet switching has high installation costs.

  • They require complex protocols for delivery.

  • Network problems may introduce errors, delays, or loss of packets, which may lead to loss of critical information if not properly handled.

Datagram Packet Switching

  • Packets, known as datagrams, are considered independent entities.

  • Datagram Packet Switching is also known as connectionless switching.

  • Each packet contains information about the destination, which the switch uses to forward the packet.

  • Packets are reassembled at the receiving end in the correct order.

  • The path is not fixed.

  • Intermediate nodes make routing decisions to forward packets.

Virtual Circuit - Packet Switching

  • Virtual Circuit Switching is also known as connection-oriented switching.

  • A preplanned route is established before messages are sent.

  • Call request and call accept packets are used to establish the connection between sender and receiver.

  • The path is fixed for the duration of a logical connection.

Comparison of Virtual-Circuit and Datagram

Criteria

Virtual Circuit Networks

Datagram Networks

Connection Establishment

Prior to data transmission, a connection is established between sender and receiver.

No connection setup is required.

Routing

Routing decisions are made once during connection setup and remain fixed.

Routing decisions are made independently for each packet and can vary.

Flow Control

Uses explicit flow control.

Uses implicit flow control.

Congestion Control

Uses end-to-end congestion control.

Uses network-assisted congestion control.

Error Control

Provides reliable delivery of packets.

Provides unreliable delivery of packets.

Overhead

Requires less overhead per packet.

Requires more overhead per packet.

Network Layer: Logical Addressing

  • 32 bits in size.

  • Logical address is called an IP address.

  • Global addresses.

  • IPv4 (IP version 4) or IP address are 32 bits long.

  • 2322^{32} addresses can be generated.

  • IPv6 (IP version 6) are futuristic/new generation addresses, 128 bits in size.

  • 21282^{128} addresses can be generated, accommodating future needs and addressing IP address depletion issues.

IPv4 Addresses

  • Unique and Universal addresses.

  • Each address defines one and only one connection to the internet.

  • Two devices can never have the same IP address at the same time.

  • An address can be assigned to a device for some time, then taken away and assigned to some other device.

IPv4 Addresses - Notations

  • Address space is 2322^{32}

  • Binary notation: 10000000 00001011 00000011 00011111

  • Dotted decimal notation: 128.11.3.31

  • Hexadecimal notation: 80 0B 03 1F

Binary and Dotted Decimal Notations

  • Example:

    • 1st Octet: 00111111

    • 2nd Octet: 10101011

    • 3rd Octet: 11101010

    • 4th Octet: 10101011

  • Dotted Decimal Notation: 63.171.234.171

IPv4: Header

  • IPv4 (Internet Protocol Version 4) is the fourth version of the Internet Protocol (IP).

  • IP is responsible for delivering data packets from the source host to the destination host.

  • This delivery is solely based on the IP Addresses in the packet headers.

  • IPv4 is the first major version of IP.

  • IPv4 is a connectionless protocol for use on packet-switched networks.

IPv4 Header Fields

  • Version: 4 bits, indicates the IP version used (value is 4).

  • Type Of Service: 8 bits, used for Quality of Service (QoS).

  • Total Length: 16 bits, total length of the datagram in bytes (Header length + Payload length).

    • Minimum total length: 20 bytes.

    • Maximum total length: 65535 bytes.

  • Header Length: 4 bits, ranges from 20 to 60 bytes.

    • Minimum length: 5 rows * 4 bytes = 20 bytes.

    • Maximum length: 20 bytes + 40 bytes (Options field) = 60 bytes.

    • Scaling factor of 4 is used: Header length = Header length field value * 4 bytes.

  • Identification: 16 bits, used for the identification of the fragments of an original IP datagram; each fragmented datagram is assigned the same identification number.

  • DF Bit: Do Not Fragment bit (0 or 1). When set to 0, fragmentation is allowed; when set to 1, fragmentation is not allowed.

  • MF Bit: More Fragments bit (0 or 1). When set to 0, the current datagram is the last fragment or the only fragment; when set to 1, more fragments are following.

  • Fragment Offset: 13 bits. It indicates the position of a fragmented datagram. Value = Fragment Offset / 8.

  • Time To Live: 8 bits. It indicates the maximum number of hops. Prevents datagrams from looping forever in a routing loop, decremented by 1 at each hop. If the value of TTLTTL becomes zero, the datagram is discarded.

  • Protocol: 8 bits. It tells the network layer at the destination host to which protocol the IP datagram belongs to (ICMP is 1, IGMP is 2, TCP is 6, and UDP is 17).

  • Header Checksum: 16 bits. It contains the checksum value of the entire header; used for error checking of the header. If mismatched, the datagram is discarded.

  • Source IP Address: 32 bits. It contains the logical address of the sender.

  • Destination IP Address: 32 bits. It contains the logical address of the receiver.

  • Options: Variable size (0 to 40 bytes). Used for purposes such as record route, source routing, and padding.

IPv4 Addresses - Classful Addressing

  • Address space is divided into classes A, B, C, D, and E.

  • Becoming obsolete but important to understand classless addressing.

Classful Addressing

  • Class A: 0-127.

  • Class B: 128-191.

  • Class C: 192-223.

  • Class D: 224-239.

  • Class E: 240-255.

Host ID and Net ID

  • Class A: 1 byte for Net ID, 3 bytes for Host ID.

  • Class B: 2 bytes for Net ID, 2 bytes for Host ID.

  • Class C: 3 bytes for Net ID, 1 byte for Host ID.

  • Class D: Multicast Address.

  • Class E: Reserved.

Before 1993:

  • 128 networks with 16 million hosts

  • 16,384 networks with up to 65,536 hosts

  • 2 million networks and 256 hosts

Special IP Addresses

  • 0.0.0.0: This host.

  • {Network}.0: A host on this Network.

  • 255.255.255.255: Broadcast on the local network.

  • {Network}.255: Broadcast on a distant network.

  • 127.x.x.x: Loopback.

Special IP Addresses: Local Host

  • 0.0.0.0/32

  • Single address with all 32 bits as zero.

  • The host is not connected to the TC/IP network.

  • Sends a request packet to the DHCP server to get connected to the internet.

Special IP Addresses: Broadcast Address

  • 225.225.225.225/32

  • All 32 bits of IPv4 address are 1'1'.

  • Last address in IPv4 address space (Limited Broadcast Address).

  • If a host wants to send a message to every other host, it uses this address.

  • Packets are broadcasted in local network only.

Special IP Addresses: Loopback Addresses

  • 127.0.0.0/8

  • 2328=224=167772162^{32-8} = 2^{24} = 16777216 addresses.

  • Can only be the destination address of a packet.

  • The packet never leaves the machine; it returns back to the source.

Special IP Addresses: Multicast Addresses

  • 224.0.0.0/4

  • 2324=228=2684354562^{32-4} = 2^{28} = 268435456 Addresses used for multicast communication.

  • Assigned to a group of hosts instead of a single host.

  • The packet sent to the multicast address is delivered to all hosts in that group.

Special IP Addresses: Private Addresses

  • Never used globally; not routed on the internet.

  • Configured by the network administrator.

  • Devices on the same network use private IP addresses to communicate with each other.

  • They translate private IP addresses into public IP addresses using NAT when communicating outside their network.

Special Addresses Reserved in Each Block

  • Network Address: The first address of the block, not allocated to any host.

  • Direct Broadcast Address: The last address of the block, used as the destination address in IPv4 packets.

Internet Protocol: IPv4 - Address Space

  • When calculating hosts' IP addresses, 2 IP addresses are decreased because they cannot be assigned to hosts.

  • The first IP of a network is a network number.

  • The last IP is reserved for Broadcast IP.

Classes and Blocks:

Class

Number of Blocks

Block Size

Application

A

128

16,777,216

Unicast

B

16,384

65,536

Unicast

C

2,097,152

256

Unicast

D

1

268,435,456

Multicast

E

1

268,435,456

Reserved

Internet Protocol: IPv4 - Classful Addressing

  • Address space: 4,294,967,296 addresses

  • Class A: 50%, Class B: 25%, Class C: 12.5%, Class D: 6.25%, Class E: 6.25%

  • Class Prefixes:

    • Class A: 0, Prefix = 0 to 127

    • Class B: 10, Prefix = 128 to 191

    • Class C: 110, Prefix = 192 to 223

    • Class D: 1110, Multicast addresses, Prefix = 224 to 239

    • Class E: 1111, Reserved for future use, Prefix = 240 to 255

Class A Address
  • The first bit of the first octet is always set to 0.

  • The first octet ranges from 1–127 (excluding 127.x.x.x, which is reserved for loopback IP addresses).

  • The default subnet mask is 255.0.0.0. 126 networks (272^7) and 16777214 hosts (22422^{24} - 2).

    • Format: 0NNNNNNN.HHHHHHHH.HHHHHHHH.HHHHHHHH

Class B Address
  • The first two bits in the first octet are set to 10.

  • IP Addresses range from 128.0.x.x to 191.255.x.x.

  • The default subnet mask for Class B is 255.255.x.x. 16384 Network addresses (2142^{14}) and 65534 (21622^{16} - 2) Host addresses.

  • Format: 10NNNNNN.NNNNNNNN.HHHHHHHH.HHHHHHHH

Class C Address
  • The first 3 bits of the first octet are set to 110.

  • IP addresses range from 192.0.0.x to 223.255.255.x.

  • The default subnet mask is 255.255.255.x. 2097152 Network addresses (2212^{21}) and 254 Host addresses (2822^8 - 2).

  • Format: 110NNNNN.NNNNNNNN.NNNNNNNN.HHHHHHHH

Class D Address
  • The first four bits of the first octet are set to 1110.

  • IP addresses range from 224.0.0.0 to 239.255.255.255.

  • Reserved for Multicasting; no need to extract host address, no subnet mask.

Class E Address
  • Reserved for experimental purposes only.

  • IP addresses range from 240.0.0.0 to 255.255.255.254.

  • Like Class D, no subnet mask.

Sample Examples

  • Question 1: Given the network address 17.0.0.0, find the class, the block, and the range of the addresses.

  • Solution: Class A, block has a netid of 17, addresses range from 17.0.0.0 to 17.255.255.255.

  • Question 2: Given the network address 132.21.0.0, find the class, the block, and the range of the addresses.

  • Solution: Class B, block has a netid of 132.21, addresses range from 132.21.0.0 to 132.21.255.255.

  • Question 3: Given the network address 220.34.76.0, find the class, the block, and the range of the addresses.

  • Solution: Class C, block has a netid of 220.34.76, addresses range from 220.34.76.0 to 220.34.76.255.

Mask

  • The mask helps to find the netid and hostid.

  • In class A, the first 8 bits define the netid; the next 24 bits hostid, hence in this first 8 are 1s.

  • /n (e.g., 8, 16, or 24) shows the mask for each class. This /n notation is called Classless Interdomain Routing (CIDR).

Default masks for classful addressing

Class

Binary

Dotted-Decimal

CIDR

A

11111111 00000000 00000000 00000000

255.0.0.0

/8

B

11111111 11111111 00000000 00000000

255.255.0.0

/16

C

11111111 11111111 11111111 00000000

255.255.255.0

/24

Classless Addressing

  • An improved IP Addressing system, more efficient allocation of IP Addresses.

  • Replaces the older classful addressing system.

  • Also known as Classless Inter Domain Routing (CIDR).

Why Classless?
  • To overcome address depletion.

  • Give access to the Internet to more organizations.

  • No classes, but addresses are still granted in blocks.

Classless Addressing Details
  • The entire address space is partitioned into blocks of varying lengths.

  • An address's prefix designates the block (network); its suffix designates the node (device).

  • Capable of having a block of 20,21,22,,2322^0, 2^1, 2^2, …, 2^{32} addresses, theoretically.

  • A block of addresses must have a power of two addresses and one address block may be given to an organization.

Prefix Lengths
  • Prefix lengths that vary from 00 to 3232 are possible.

  • The length of the prefix has an inverse relationship with network size: smaller networks have large prefixes; larger ones have small prefixes.

  • Classless addressing is a specific instance of classful addressing. An address in class A can be considered as a classless address with a prefix length of 8. Class B addresses can be viewed as classless addresses with the prefix 16

Classless Address Notation
  • The prefix length is to be provided because it is not a property of the address.

  • A classless address does not automatically define the block or network to which it belongs.

  • The address is inserted, followed by a slash, and the prefix length, nn.

Calculations for a given address in a block
  • the number of addresses in the block,

  • the start address in the block,

  • the last address.

Formulas
  • The block has N=232nN = 2^{32-n} addresses.

  • The nn leftmost bits are kept, and the (32n)(32 - n) rightmost bits are all set to zeroes to determine the first address.

  • The nn leftmost bits are kept, while the (32n)(32 - n) rightmost bits are all set to 1s to determine the last address.

Example

  • Problem: For the given classless address 167.199.170.82/27 find the number of addresses in the block, the start address in the block, and the last address.

  • Solution: There are 232n=25=322^{32-n} = 2^5 = 32 addresses in all.

  • The first 2727 bits are kept while the remaining bits are converted to 0s0s to determine the first address.

  • Keeping the first 2727 bits and turning the remaining bits to 1s1s will allow you to determine the last address.

Network Address and Mask

  • Network address:

    • Identifies a network on the internet.

    • Using this, we can find range of addresses in the network and total possible number of hosts in the network.

  • Mask:

    • It is a 32-bit binary number that gives the network address in the address block when bitwise AND operation is applied on the mask and any IP address of the block.

  • In IPv4 addressing, a block of addresses can be defined as x.y.z.t / n

    • Ex. 192.168.1.1/28

    • Where x.y.z.t defines one of the addresses and /n defines the mask.

Subnetting
  • Dividing a large block of addresses into several contiguous sub-blocks and assigning these sub-blocks to different smaller networks.

  • A practice that is widely used when classless addressing is done.

Default Mask vs Subnet Mask
  • Example: 192 = 11000000

  • 72 = 01001000

  • Bitwise AND = 01000000 = 64

Subnetting Details
  • To reduce the wastage of IP addresses in a block, we use subnetting.

  • Some of the Host id bits are used as net id bits of a classful IP address.

  • We give the IP address and define the number of bits for the mask along with it (usually followed by a / symbol), like, 192.168.1.1/28.

    • Subnet mask is found by putting the given number of bits out of 32 as 1.

  • Ex: In the given address, we need to put 28 out of 32 bits as 1 and the rest as 0, and so, the subnet mask would be 255.255.255.240.

Subnetting Calculations
  • Number of subnets : Given bits for mask – No. of bits in default mask

  • Subnet address : AND result of subnet mask and the given IP address

  • Broadcast address : By putting the host bits as 1 and retaining the network bits as in the IP address

  • Number of hosts per subnet : 2(32Givenbitsformask)22^{(32 - Given bits for mask)} - 2

  • First Host ID : Subnet address + 1 (adding one to the binary representation of the subnet address)

  • Last Host ID : Subnet address + Number of Hosts

Another Subnetting Method
  • The first address in the block can be found out by setting the rightmost 32-nn bits to 0s0s

  • The last address in the block can be found out by setting the rightmost 32-nn bits to 1s1s

  • Ex: A block of addresses is granted to a small organization. One of the address is 205.16.37.39/28. What is first and last address?

  • Solution: Binary representation of the given address: 11001101 00010000 00100101 00100111

  • Binary representation of mask: 11111111 11111111 11111111 11110000

  • First address : 11001101 00010000 00100101 00100000 = 205.16.37.32

  • Last address : 11001101 00010000 00100101 00101111 = 205.16.37.47

  • No. of addresses = 23228=24=162^{32 -28} = 2^4 = 16

Subnetting - Alternate Method

  • Ex: A block of addresses is granted to a small organization. One of the addresses is 205.16.37.39/28. What is first and last address?

  • Binary representation of given address: 11001101 00010000 00100101 00100111

  • Binary representation of mask: 11111111 11111111 11111111 11110000

  • First address : Bitwise AND operation of given address and mask = 205.16.37.32

  • Last address : Take compliment of the mask and do bitwise OR operation.

  • Given address: 11001101 00010000 00100101 00100111

  • Compliment of the mask: 000000000 00000000 00000000 00001111 = 205.16.37.47

  • No. of addresses : Compliment of the mask + 1=000000000000000000000000000001111+1=161 = 000000000 00000000 00000000 00001111 + 1 = 16

Subnetting Example (Problem)
  • An Organization is given a block 17.12.14.0/26, which contains 64 addresses. The organization has 3 offices and needs to divide the addresses into 3 subblocks of 32,1632, 16 and 1616.

  • How will the subnetting be performed?

Subnetting Solution
  • Mask for Subnet 1: 2(32n1)=32<br>ewlinen1=272^{(32-n1)} = 32 <br>ewline n1 = 27

  • Mask for Subnet 2: 2(32n2)=16<br>ewlinen2=282^{(32-n2)} = 16 <br>ewline n2 = 28

  • Mask for Subnet 3: 2(32n3)=16<br>ewlinen3=282^{(32-n3)} = 16 <br>ewline n3 = 28

  • We must have masks 27, 28 and 28 with the organization mask being 26.

First and Last Addresses

Subnet 1

  • Block 1 = 32 addresses.

  • The mask for Subnet 1 is n1=27n1 = 27

  • Mask is /27 = 11111111 11111111 11111111 11100000

  • First Address: 00010001 00001100 00001110 00000000 = 17.12.14.0

  • Last Address: 00010001 00001100 00001110 00011111 = 17.12.14.31

Subnet 2

  • Block 2 = 1616 addresses.

  • Given Addresses: 17.12.14.0 = 00010001 00001100 00001110 0