0% found this document useful (0 votes)
13 views122 pages

Computer Network

Uploaded by

Archi Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views122 pages

Computer Network

Uploaded by

Archi Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 122

Computer Network Basics

Chapter 1
1.1 INTRODUCTION

Fig.1.1 Data Communication System

“Hello world”, which is data here, needs to be transmitted from the Sender
to Receiver, this transmission of data involves some set of protocols (will be
discussed in the next chapters) and this flow of data in a system is called
“Data Communication System”.

Components of data communication system:


Sender:
One who sends data

Data:
It is a huge subject in itself, but we limit it to the context/information which
needs to be transmitted from sender to receiver (in the above diagram “Hello
World” is a data).

Medium:
Data passes through a medium which can be wireless or wired (Twisted pair,
Coaxial cable or Optical fiber etc.)

Receiver:
One who receives data.

Protocol:
Computer Network Basics

Set of rules that governs transmission of data.

Lets understand Data and Medium a bit more:


1) Data:
For transmission of data, it must be transformed into electromagnetic signals.
Chapter 1

Signal can be classified in analog and digital form.

Analog signal:
Data is represented in continuous waveforms.

Digital signal:
Data is represented in discrete form (0’s or 1’s/High or low).

Note:
Signals always varies with respect to time or frequency.
1
(time = ).
frequency

Baseband signal: Typically uses digital signals.


Broadband signal: Typically uses analog signals.

2) Medium:
Transmission medium is a channel through which data can be sent or received.
Computer Network Basics

Fig. 1.2 Flow Chart Representing Types of Transmission Medium


Chapter 1
Twisted pair:
Do you know the RJ - 45 connector?
Yes, the port on your laptop or CPU for RJ-45, it contains twisted-pair cables
for Ethernet connection. It is also known as CAT 5 cables.

Fig. 1.3 Diagram of Twisted Pair


 In twisted-pair cables, two wires twisted together in a helix fashion.
 It has low cost transmission.
 It can carry both analog and digital signals.
 More the thickness of wire, more is the bandwidth.

Why twisted wires, why not normal wires !!


Normal wires will generate the magnetic field, which interferes with the signal,

Rack Your Brain

Coaxial cable:
It has a copper wire as a core, surrounded by insulating materials, which further
surrounded by the braided outer conductor, which is further surrounded by a
plastic sheath. Computer Network Basics

Fig. 1.4 Structure of Coaxial Cable


Chapter 1

 It has better features than twisted pair because of its shielding.


 It has excellent noise immunity and high bandwidth.
 Here also, more the length of the cable, more the bandwidth.

Rack Your Brain

Fiber Optics:
 It sends information using lights instead of electrons. Light travels from the
core, a layer which surrounds the core is called cladding.
 Fiber optics consist of the light source, transmission medium and detector.
 Light pulse indicates 1 and absence of pulse indicates 0, the medium is thin,
fiberglass and detector generate electrical pulses when light falls on it.

 Error rates are less because it does not affect by electromagnetic


interference.
 It is thin and lightweight.
 Data rates are very high.
 They are good for security reasons because they are difficult to tap.

How many types of fibre exist !!


2 types are there – Single-mode fibre and multimode fibre.
Computer Network Basics

In single-mode: Light travels in Single Path,


high cost,
can be used in 10 to 100 Km,
data rates are high (in Tb/s),
In multimode: Light travels in many paths,
low cost,
can be used in 2000 metres,
data rates are low (in Gb/s).
Chapter 1
Rack Your Brain

Till now we have seen wired medium, now let us see wireless transmission
medium:

Fig. 1.5 EM Spectrum and Uses in Communication

Waves which can be used for transmitting information are radio, micro, infrared
and some portion of visible light as they can be modulated and amplified
easily. UV, X and gamma rays do not propagate through the buildings; hence
not used for transmission frequently.

Note:
Data flow can be categorized in simplex mode, half duplex mode and full
Computer Network Basics

duplex mode.
Simplex mode: Only one of the two devices can send the data, hence the
entire channel is used for transmission, example: radio station.
Chapter 1

Half-Duplex mode: Any of the two devices can send or receive the data but
not at the same time; here entire channel is used for transmission or receiving
of data, example: Walkie Talkies.
Full-Duplex mode: Both devices can send and receive data simultaneously,
hence the entire is used for two purposes simultaneously which increases
the efficiency of the channel, for example: Telephone networks.

Topologies and its types:


Link:
Device connected through link

Topology:
Many links from topology, basically it is a representation of the physical and
logical structure.
Computer Network Basics

Fig. 1.6 Structure of Topology


Chapter 1
Topology types:

Fig. 1.7 Types of Network Topology

Bus topology:
 All the nodes are connected to a shared cable.
 There will be no central node.
 One long cable act as a back-bone of this network.
 For n devices, only 1 link is required.

Advantage:
 Installation is easy, used for small networks, fewer cables are required.

Disadvantage:
 Can be used with limited nodes; cable length is also limited.

Fig. 1.8 A Bus Topology


Star topology:
 Each device has a point to point link through a central node (hub or switch)
that may act as controller.
 There is a central node which acts as an exchange medium.
Computer Network Basics

 Devices are not directly connected with each other.


 For n devices, n links are required.
Advantage:
 Easy to manage when faults occurs, installation is easy, easy to expand.
Disadvantage:
 Require more cable than the bus, if the central node gets down, then all
nodes get down.
Chapter 1

Fig. 1.9 A Star Topology

Ring Topology:
 Each device has a point to point connection only with two devices that are
on either side of a device.
 If any device fails, the entire network gets down.
 Each device in a ring has a repeater.
 Message travel in a single direction.
 If n nodes are present, then n physical links.

Advantages:
 Using token, each device gets a fair chance to send a message.
 Easy to install, good for long-distance.

Disadvantage:
 If nodes get moved, it affects the performance.
 If a node gets down, entire network gets down.
Computer Network Basics

Fig. 1.10 A Ring Topology


Chapter 1
Mesh Topology:
 Every device has a point to point link with every other device.
 Message can travel in any direction.
 If n devices are present, then (n – 1) ports must be present on each device.
 And total number of physical links is n(n–1)/2.

Advantage:
 If one node gets down, still message can flow through other paths.
 Fault detection is easy because of the dedicated link.

Disadvantage:
 Installation is not easy.
 Expensive as more number of cables is used.
 There is a possibility of a redundant path.

Fig. 1.11 A Mesh Topology Computer Network Basics

Rack Your Brain


Chapter 1

Tree Topology:
 Collection of star topology in hierarchical level.
 More devices can be added now as the network can grow by connecting
one central hub to another hub.

Advantage:
 Easy to expand, Isolation of different network is possible.

Disadvantage:
 If the central hub is down, the entire network goes down.
 Cost is high because more number of cables will be required.
Computer Network Basics

Fig. 1.12 A Tree Topology

10
Chapter 1
1.2 NETWORK TYPES

Fig. 1.13 Classification of Network

PAN (Personal Area Network):


 Range of Person, your bluetooth works in PAN.
 Works for short range.

LAN (Local Area Network):


 Range of buildings, privately owned networks.
 Wireless LAN such as WiFi.
 Wired LAN such as Ethernet.

MAN (Metropolitan Area Network):


 Ranges of cities, your cable television networks.
 Connection of Multiple LAN’s.
Computer Network Basics

WAN (Wide Area Network):


 Ranges of countries, your telephone network works in WAN.
 Works for a very large range.
Chapter 1

OSI Model:
 International Organization of Standardization (ISO): proposed an open
systems interconnection (OSI) model, which allows two systems to
communicate irrespective of their architecture.
 The aim of the OSI model: To represent how to provide communication
between the dissimilar systems without making any changes to the logic of
the underlying software and hardware.
 OSI model is a 7 layered architecture.

Protocol Layering:
A list of protocols used by the system in which one protocol is used in each
layer is called protocol layering or protocol stack.

Each layer’s boundaries are decided in such a way that there should be a
minimum flow of information between each layer.

Note:
Computer Network Basics

OSI model has been widely used but the protocols “used in OSI” have been
forgotten.

12
Chapter 1
Fig. 1.14 The OSI Model

Before discussing each layer we must keep in mind that portion of the packet
at stage x-1 contains the whole packet of stage x. Stage x – 1 thinks that the
packet which is coming from stage x is one unit. One can say it follows the
encapsulation technique.

Physical layer:
 It deals with the interface between the devices and the transmission
medium.
Computer Network Basics

13
Chapter 1

 It deals with the transmission of raw bit through transmitting media the





 Rack Your Brain





Data Link Layer:
It makes a frame move from one node to the next node.

 It makes data from the physical layer error-free and sends to the network
layer.
 It deals with framing (the process of division of data unit from network
layer into manageable streams called frames).
 It deals with physical addressing (adding a physical address i.e. MAC
address, so that frame could reach the destination network)
 If rates are mismatched between nodes, then the data link layer provides a
flow control mechanism.
 Data link layer also see whom to give access if two or more device is
Computer Network Basics

connected to a link at a given time.

Rack Your Brain

14
Chapter 1
Network layer:
It deals with the delivery of packets from source host to destination host.
 Logical addressing: Data link layer solves address issues locally, but the
network layer provides a logical address (IP address) in order to reach from
Source to destination when the packet reaches the destination network.
 Network layer do routing: Several networks is interconnected with each
other through the router, and it is the responsibility of the network layer to
route the packet to the destination.
Transport layer:
It is the responsibility of the transport layer to deliver the message from the
source process to the destination process.
 It does segmentation (splitting message from application layer into
segments) and reassembly (intact the message correctly on receiving the
destination).
 It deals with port addresses in order to reach the service of the process
called port addressing.
 Transport layer also determines service provided to the session layer, it
may be connection-oriented or connectionless services.
 Flow control: At transport layer, flow control is done from end to end.
 Error correction: It is usually done by retransmission if any error occurs.

Rack Your Brain


Computer Network Basics

Session layer:
It is the responsibility of a session layer to establish a session (dialog control
and synchronization) between sender and the receiver.

15
Chapter 1

 Dialog control: Between a link, it keeps an eye whose turn is now on the
link for sending the data.
 Synchronization: It adds a checkpoint if the sender is sending a huge file,
eg: Sending a file of 1GB, it will add a checkpoint after 100KB so that if any
file gets lost, it will be easily recovered.

Presentation layer:
It deals with compression, translation and encryption.
 Translation: It deals with the conversion of bits before sending a message.
 Encryption: it deals with an encoded messages before sending; encryption
is done for security reason.
 Compression: While sending a multimedia file, it compresses the file for
smooth transmission.

Application layer:
 It deals with a variety of protocols which is useful for common clients.
 The protocols are HTTP, FTP, DNS, SMTP. (We will discuss this in application
layer chapter.)

TCP/IP Model:
 Protocols which are associated with the OSI model are not used in today’s
world, although the OSI model is still in use as it works as a framework for
other models because of its generalized structure.
 If not OSI protocol, then whose protocols are we using now?
TCP/IP model
 Below is a diagram of the TCP/IP model, which is similar to the OSI model.
Have a look at the difference between the two.
Computer Network Basics

Fig. 1.15 Comparison Between OSI Model and TCP/IP Model

Have you noticed presentation, session and physical layer are absent in
TCP/IP?
16
Chapter 1
Key similarities between OSI and TCP model:
 For communication process both are using layered architecture and each
layer is specific to its task in both models.
 Both models follow the encapsulation, hiding the implementation details
at each layer.
 Both follow the stack independent protocol technique.
 Both model has implemented end to end communication upto the transport
layer.

Key differences between OSI and TCP model:


 One major difference is between layers OSI model has 7 layers whereas
TCP/IP has 4 layers.
 In the OSI model, the transport layer provides connection-oriented services,
but the TCP/IP model transport layer can make choices between connection
or connectionless services.
Protocols used in TCP have been shown in the given diagram:

Computer Network Basics

Fig. 1.16 Protocols Used in TCP Model

17
Chapter 1

Let us see How these layer work in short (We will go deep of each layer
later but let’s have a taste)

 Transport layer receives the message and adds Ht (Transport layer header).
 The transport layer segment then passes to the network layer, and the
network layer adds a network layer header to it.

Note
a) You may ask where this header gets acknowledged?
At the received side of the transport layer.
b) Is there any name given to this message at the transport layer?
Yes, we called it as segment.

 Network layers send this datagram to the data link layer, which adds a data
link layer header. Do you think there is any name at the data link layer also!!
Frame
Computer Network Basics

18
Chapter 1
 At every layer, packet is having two fields:
1) Header field
2) Payload field

What is a Payload Field?


Payload field at layer k is the packet which is coming from k-1 layer !!
For example, at the data link layer, see the diagram below:

 From the link layer, it goes to the switch or bridges, which sees till the physical
address (MAC) of the packet and forwards it to the destination node.
 Let us say the packet is in a different network; now packet has to pass with
the router, which can see till the IP address of the packet and map to its
destination address.
 Finally, packet reaches its destination host, where each layer by seeing
their header and acknowledges the packet.

PRACTICE ǪUESTIONS

Sol:
Computer Network Basics

No. of lines are PǪ, ǪR, PR.


Each line is having 2 choices.
So, total number of topology possible is 2x2x2 = 8
10 ms for each to inspect; hence 0.08 sec. to inspect all.

19
Chapter 1

Ǫ2 One advantage and one disadvantage of layered architecture?

Sol: Advantage: Can be managed easily.


Disadvantage: Delays are more compared to single layer architecture.

Ǫ3

Sol: In message streams, packets have separate boundaries, but in byte streams,
packets is considered as a single unit.

Ǫ5 Follow up with the question in d, what if services at layer k has changed, will

Sol: We might need to modify services at upper layer because each layer is giving
services to the upper layer.

Ǫuestion
Computer Network Basics

Sol: b)
Chapter 1
Chapter summary:

 The seven-layer OSI model provides guidelines for the development of universally
compatible networking protocols:
 Network support layers : Physical, Data Link and Network Layer.
 User support layers : Session, Presentation and Application layer.
 Physical layer : Delivery of bit streams over physical layer.
 Data Link layer : Node to node delivery of data.
 Network layer : Source to destination delivery.
 Transport layer : Process to process delivery.
 Application layer : Enables user to access network.
 TCP/IP is a four- layer hierarchical protocol suite.
 Level of address used in TCP/IP.
 Data link layer uses physical address use in LAN or WAN.
 IP address uses logical address used to identify host.
 Port address identify a process on a host.

For N devices:
 1 link is required for bus topology.
 N link is required for ring topology.
 N link is required for star topology.
 N(N-1)/2 link is required in mesh topology.
 Twisted air cable, coaxial cable, and optical fiber are the most popular types of
guided media.
 Unguided media transport electromagnetic waves without the use of a physical
conductor.

Computer Network Basics

21
Physical Layer

Chapter 2
2.1 INTRODUCTION
Physical layer:
It deals with electrical, mechanical, and functional characteristics.

Note:
Physical connectivity must be there between one hop to other hop (that
connectivity may be wired or wireless).
It is responsible for the transmission of binary data through a medium.
Transmission can be analog (continuous waveform signals) or digital (discrete
binary signals).

a) Do you know why a modem is used !!


Convert analog to digital and vice versa.

Fig. 2.1 Diagrammatic Representation of Signal Conversion

b) Do you know why multiplexers are used !!


It allows multiple signals to be carried on a single transmission line.

Physical Layer

Fig. 2.2 Diagrammatic Representation of Uses of Multiplexer


Chapter 2

Baseband transmission:
 Typically it is used in local area network (LAN)
 It uses a digital signal over a single wire.
 In a baseband transmission, the entire bandwidth of the channel is used
by digital signals.

Rack Your Brain

Broadband Transmission:
 Typically, it is used in Wide Area Network (WAN).
 It uses analog signals over multiple transmission frequencies.
 In broadband transmission, multiplexing is used using Frequency Division
Technique (FDM).

Bandwidth:
 We can say maximum transmission capacity.
 It is a difference between highest and lowest frequencies contained in the
composite signal.

Bandwidth = freqH – freqL

You may ask, what are composite signals?


Signals are the composition of many waves it may be periodic or non-periodic.
 Frequency of periodic signals has a discrete value.
 Frequency of non-periodic signals has a continuous value.
Physical Layer
Chapter 2
Throughput:
How fast we can send data through a network !!
One may think throughput and bandwidth are the same, but they are different.
Let’s say preparing 10 subjects per gate cse paper is bandwidth, but babloo is
able to finish only 7 subjects in gate cse paper , So the throughput of babloo
is 7.

Latency:
It is the delay, how much time it takes to travel a message from source to
destination. When the first bit is sent out from the source to the destination.

Latency = Propagation delay + Transmission delay + Ǫueueing delay +


Processing delay

Propagation delay: It is the time duration for 1 bit to travel the link
Tp = distance between sender and receiver/velocity of the signal on the link.

Transmission delay: It is the time taken to push the entire packet bits onto
the wire.
Tt = Frame size or packet size/Bandwidth

Ǫueuing delay: It is the time taken for a packet to stay in the buffer.

Processing delay: Routers or switches take some time to process the packet
header, which is called Processing delay.

Transmission of signal:
How information can be represented in digital signal:
1 → Positive voltage
0 → Zero voltage
The diagram below has 2 signal levels; it may have 3 or more levels, depending
upon the amount of data.
Physical Layer

Fig. 2.3 Digital Signal Representation


Chapter 2

Please note here for sending information at one bit per level, we need two
levels.

Concept Building Exercise

What is the baud rate?

Encoding/Decoding techniques:

format.
 Decoding: Process of converting from specified format into actual format
(It is the reverse of encoding)
Terms used in encoding:
 Unipolar: If all the signal elements have the same sign (like all are positive
or all are negative), then the signal is unipolar.

Fig. 2.4 Unipolar Scheme

 Polar: If the signal elements have one positive and another negative sign,
then the signal is Polar.
Physical Layer

Fig. 2.5 Polar Scheme


Chapter 2
 There are different encoding schemes, but we will limit it to Manchester
and differential Manchester because it is used in IEEE 802.3.

Manchester encoding scheme:


1 → low to high transition in middle of interval.
0 → high to low transition in middle of interval.

Fig. 2.6 Diagrammatic Representation of Manchester Encoding Scheme

Differential Manchester encoding scheme:


Always inversion at the middle occur,

Fig. 2.7 Diagrammatical Representation of Differential Manchester Encoding Scheme

Physical Layer
Chapter 2

Rack Your Brain

Noise:
When a signal travels, there is a high chance that unwanted signals get attached
to the original signal, which creates bad results and is often termed noise.
There are several types of noise: Thermal, crosstalk and impulse.

Thermal noise:
It gets created by the random motion of electrons in a wire.

Cross talk:
It is an effect of radiation which is induced on other signals because of close
proximity.

Impulse:
It is spike noise which comes for a short duration due to some instant action
like lightning.

Signal to noise ratio:


SNR = Average signal power/Average noise power.

Note:
High SNR means the signal is less affected by noise, and low SNR
means signal is highly affected by noise:
SNR (in db) = 10log10SNR

Data rate depends on bandwidth, level of signal and level of noise.


Physical Layer

Fig. 2.8 Data Rate Based on Types of Channel


Chapter 2
For noiseless channel:
We calculate Nyquist formula
Maximum Bit rate = 2 * Bandwidth * log2L (L is level of signal)

PRACTICE ǪUESTIONS

If the television channels have a Bandwidth 4MHz. If 8 level digital signals are
used. How many bits per second can be sent ? Assume the channel is noiseless.

Sol: We can use Nyquist in this case:

Maximum bit rate = 2 * 4 * log82 (For 8 levels – 3 bits needed)


= 24 Mbps

Physical Layer
Chapter 2

Ǫ2

Sol: Half duplex, one at a time.

Ǫ3

Sol: The rate is doubled.

How will the rate improve if we double the SNR?

Sol:
Switching:
Why do we need switching?
When we have many devices, we can connect using point to point (as we
have seen in mesh topology) or multipoint connections (as we have seen in
star topology). But can we extend these methods when we have a very large
network!! BIG NO

Switching helps here; there are 3 types of switching see figure below:
Physical Layer

Fig. 2.9 Flow Chart Representing Types of Switching


Chapter 2
Circuit switching networks:

Fig. 2.10 Diagrammatic


Representation of Circuit
 Circuit switching needs to be handled at the Physical layer.
 There must be reservation of resources before the communication takes
place
 Resources get reserved during the set-up phase, and for the entire, duration
it gets fixed until there is a teardown phase.
 Communication happens in three phases:
Set up phase: A dedicated path needed to be established before the
transfer of data.
Data transfer phase: transfer of data takes place in this phase.
Tear down phase: A signal is sent to release the resource.
 When the path has established, there is no danger of congestion.
 Switching at the traditional telephone network uses the circuit switching.

Note:
Resource:
Physical Layer

It is nothing but channels (bandwidth in case of FDM or time in case of TDM),


buffers, ports etc.)

31
Chapter 2

Packet Switching Networks:

Note:
The message is divided into packets which are fixed or variable
sized networks.
There is no need to establish a dedicated path in advance but it
can be allocated on demand.
The allocation of resources is done on FCFS basis.
Packet contains the user data and controlled information.

Fig. 2.12 Types of Packet Switching Technique

Datagram network:
In this, each packet has no relation to the other packet.

Note:
Packet in this network are called datagram.

 It is normally done at the network layer.


 A switch in the datagram network uses a routing table which is based on
the destination address.

Physical Layer

Sometimes, it is said that these networks are connectionless, which means


the switch does not keep the information about the connection state.
 The destination address in each packet remains the same.
Chapter 2
 Packet may reach out of order as shown in the diagram.
 Switching on the internet is done using the datagram approach.

Concept Building Exercise

Can you guess whose efficiency is better? And why?

 Packets from the single message travel along the same path.
 Resource reservations can be made during the setup phase or on-demand
during the transfer phase.
 Each packet contains a Virtual Circuit Identifier (VCI).
 Again, in a virtual circuit, there are also 3 phases required to transfer the
data.

Setup Phase, transfer phase, tear down phase:


 Virtual switch networks are used in switched WAN normally at the data link
Physical Layer

layer.
Chapter 2

PRACTICE ǪUESTIONS

A path in a digital circuit-switched network has a data rate of 1 Mbps. The


exchange of 2000 bits is required for the setup and teardown phase. The
distance between the two parties is 5000 km. The propagation speed is 2

Sol: Two set up phase + 1 tear down phase, i.e 3 *(tp + tr)

Finally data transfer required ( tp + tr )


So, the total delay = 4(tp + tr)
Tp = 5 * 106 / 2*108 = 25 msec
Tt = 2000/106 = 2 msec
= 4(25 + 2)
= 4*(27) msec
= 108 msec

Ǫ2 Tick mark where you feel end to end addressing is required:

Sol:

Circuit Switched
Network  
Datagram Network 
Virtual Circut   
Physical Layer
Chapter 2
Ǫ3

Sol:

Virtual circuit Datagram circuit

The 1st packet needs a global header


Headers are required for all
and for the remaining packet it just
packets.
needs a local header.

It is connection oriented as Resources are not reserved;


resources and bandwidth are hence datagram circuit is
reserved. connectionless.

All the packets are in order as the


May follow a different path.
same path is followed.

It is highly reliable. It is not reliable.

Cost is high. Cost is not high.

ATM uses Virtual circuits. IP networks use datagram packet.

Ǫuestion

Sol: (GATE-
Physical Layer
Physical Layer Chapter 2













Data Link Layer

Chapter 3
3.1 DATA LINK LAYER
It has two major functions:
 Data link control
 Medium access control

Data link control:


It includes framing, flow control and error control.

Medium access control:


It tells about the access control.

Data link control:


1) Framing:
We already know the physical layer provides bits synchronization (sender and
receiver use the same bits). Now, these bits have to pack into the frame, and
this is done by data link layer.
OR
Data link layer also takes packets from the network layer, and enclose them in
multiple frames and send it to the physical layer.

Frame is having 3 basic components:


 Frame header
 Payload field
 Frame trailer
Data Link Layer
Chapter 3

Fig. 3.1 Basic Components of Frame

Concept Building Exercise

 Fixed size framing


 Variable size framing

Fixed size framing:


 As the name suggests, it is of Fixed Size.
 You need not worry about the ending of the frame.
 Since Frames are of fixed length, hence no flexibility is possible.

Variable size framing:


 We need to define an end of the frame as well as beginning of the next
frame. This can be done in two ways:
i) Character stuffing
ii) Bit stuffing
Character stuffing:
 A flag is added at the beginning and at the ending of the frame, which tells
Data Link Layer

the frame has started and ended.


 Flag size is multiple of 8 bit.
 It was used when only the character as a data was exchanged at the data
link layer.
Chapter 3
Concept Building Exercise

 What would you think if you see two continuous FLAG?

 How does FLAG look like?


It has some special patterns like (1111110)2 or (0x7E)16 for HDLC protocol.

Byte stuffing:
 Add 1 extra byte whenever there is a flag or ESCAPE character in the text.
 Special byte is added to the data section of the frame when the same
pattern as that of flag is present inside the frame.
 Now frame has an extra byte called as ESCAPE(ESC).
 This adding of an extra byte is called Byte stuffing.
 But the problem comes when the escape pattern appears in the middle of
the data. The solution is add extra ESCAPE.
See figure below!!

 When there is ESC pattern in an original frame add another escape byte:

 Byte stuffing has one disadvantage, we have to use 1 byte always. So, there
is always a limitation of using 8 bit.
 We can overcome this situation using bit stuffing.

Bit stuffing:
 In this, whenever flag pattern appears in the data section of the frame,
to prevent it from looking like a pattern of the flag we add an extra bit to
Data Link Layer

break the pattern.


 Let’s say if we have taken 01111110 as Flag, so after bit stuffing, data will
become 011111010.
Chapter 3

 If we have taken 10000001 as Flag, so after bit stuffing, data will be 100000101.


01111110,
1

Note:
Real flag is not stuffed by the sender; hence no need to destuffing for
real flag at the end of the receiver.

2) Error control:
 It manages both error connection and error detection.
 Basically, it deals with the retransmission of data, and this retransmission is
based on Automatic Repeat Request (ARǪ).
 There are basically two types of error: Single bit error and Burst error.
Single bit error: Single bit get changes when data reaches to receiver,
11101010 11111010
Burst error: When 2 or more bits gets changes,
11101010 11111011
Error detecting codes:
In error detection, we can only know the packet is corrupted. Redundant bits
are added to detect error, and when the error is detected, retransmission is
used to recover from error.

Error correcting codes:


Data Link Layer

In error detection, we can also know the bit which has been corrupted.
Redundant bits are added in such a way, that it will detect and correct the
errors.
Chapter 3
Concept Building Exercise

Error detection:
 Parity checking
 Cyclic redundancy check
 Checksum
Simple parity check codes:
 It can detect an odd number of errors.
 In this k bits, data is changed into n bit code words.
 n = k + 1 (extra 1 bit is called parity bit)
In the case of even parity, if the number of 1’s are even then, we add an extra
bit by adding 0 else, if the number of 1’s is odd, then we add an extra bit of 1
to make the Code bit an even number of 1.

 1

Concept Building Exercise

Find the hamming distance of the given coding scheme?


Data Link Layer

d(1100, 1111)
Sol: 2, 2

41
Chapter 3

dmin. = 2d + 1

Let’s see below diagram and understand how simple parity bits are used in
error detection,

Fig. 3.6 Diagrammatic Representation of Simple Parity Bits Used in Detection

Here we are taking codebits as even parity:


 Databits are sent in the form of codebits by adding single parity.
 You might be thinking about how to add a parity bit?
Add all the bits, and modulo-2 will give the parity bit.
 At the receiver side, it will do modulo-2 of the codebit, and if the result,
known as syndrome, is 1, then an error is detected, and if the syndrome is
0, then there is no error.

Note:
A simple parity check code can detect odd number of errors only.

Cyclic redundancy check (CRC):


Common CRC polynomials are:
CRC–32 used in LAN, CRC–8 used in ATM header.
Data Link Layer

Some rules for generating the generator polynomial,


Rule 1: It should not be divisible by x.
This condition will ensure that all the burst error of length equal
Chapter 3
to the length of the polynomial
are detected.
Rule 2: It should be divisible by x + 1. Rack Your Brain
This condition will ensure that all
the burst error affecting an odd
number bits are detected.

CRC generator: 1101 ( It is known by both sender


as well as receiver )
Code: 1011011
Steps:
1) If CRC G has 4 bits then add 3 bit to the code
1011011000
2) Now mod-2 sum
And do the following at sender side,

The correct code which needs to be send is 1011011001.


3) Receiver will check whether the code is correct or not.

 CRC codes can detect the single bit errors, double errors, odd number
of errors and burst error.
 Fast when implemented in hardware compared to software.
 The divisor in cyclic codes are normally called generators.

Checksum:
Data Link Layer

 Checksum bits are usually placed at the end of the message with a
complement to the sum function.
 It is used on the internet but not on the data link layer.
What we are using at the data link layer then!! CRC.
Chapter 3

Let us understand by taking example,


a) Let’s say a set of numbers (10, 20, 30) needs to be sent. Then the sender
will send (10,20,30,-60) here -60 is the sum of all the numbers with
a negative sign. Now the receiver will add all the numbers, and if the
result is zero then there is no error.
b) By taking chunks of 2 bits, Explain how the checksum will work on the
sender side if data is 01110001.
We have 01 11 00 01 ( 2 bit chunks )
Now add using 1 bit compliments 01 + 11 + 00 + 01 = 101
overflow add MSB to LSB 01 + 1 = 10
Take 1 complement of result = 01
Append to the sender data bit and send it to the receiver = 0111000101
At the receiver end we have 01 + 11 + 00 + 01 + 01 = 110
Overflow add MSB to LSB = 10 + 1 = 11
Complement of result = 00
If the result is 0; hence no error, if the result is non zero then error will
be detected.

Ǫuestions:
1) In CRC, what do you think is the relationship between the size of the
divisor or remainder?
Remainder is always one bit smaller than the divisor.
2) CRC generator is x3 + x + 1, data bit are 1101, What will be the CRC which
needs to be appended at the databit?
CRC generator x3 + x + 1 = 1011, we will append 3 bit 0 to the data bit.
After doing the modulo operation, we got CRC as 010, and Codebit will
become 1101001.

3) What is the checksum value which needs to be send for the following
two data items:
0x4589 and 0xBA76?
Data Link Layer
Chapter 3
Checksum bit which needs to be sent is 0000

Ǫuestion

Ǫ. Which of the following statements is TRUE?


a) Both Ethernet frame and IP packet include checksum fields
b) Ethernet frame includes a checksum field, and IP packet
includes a CRC field
c) Ethernet frame includes a CRC field, and IP packet includes a
checksum field
d) Both Ethernet frame and IP packet include CRC fields
Sol: c) (GATE-2006)

Error correcting:
 For error detecting and correcting we will use hamming codes.
 Let us first understand relationship between data bits and redundant bits
in hamming code.
 Let us take ‘d’ as data bits and ‘t’ as a redundant bits.
 Total number of bits that has to be transmitted = d + t.
 Think how many states can the redundant bit discover?
Its d + t + 1

Note:
Above condition derives a relationship,
2t  d + t + 1

Let’s say the value of d (message to be transmitted) is 4 then t would be 3.


It would satisfy this equation 2t ≥ d + t + 1
In this case, t cannot be less than 3 i.e redundant bits cannot be less than 3.

Let us understand Hamming code by taking example:


Note: We calculate here on the basis of even parity bits.

Message: 1011
Here d = 4, now we need to add parity bits for each combination in the powers
of 2 as shown below:
Data Link Layer

t1 will take care of 1,3,5,7,... bits


t2 will take care of 2,3,6,7,… bits
Chapter 3

t4 will take care of 4,5,6,7... bits

Your ultimate goal should be to make an even number of 1’s for particular
parity, in this case, by checking position 3,5,7 we got a number of 1’s as odd,
therefore we have to put t1 = 1 in 1st position in order to make even parity.
Same we will do for t2 and t3,

Now the codebit that has to be transmitted is 1010101.


Let us assume at the receiver side one bit got corrupted, now how hamming
code will detect and correct the code.

How receiver will detect?

How receiver will correct,


Since, we got to know which position is detected error, here it is 3rd position
Now we can change the 3rd bit and make it correct.

Ǫuestion

a) 01011011010 b) 01011011011
c) 01011011101 d) 01011011100
Data Link Layer

Sol: c) (GATE-2017)
Chapter 3
Ǫuestion

01111110. 01111100101,

a) 0111110100 b) 0111110101
c) d)
Sol: b) (GATE-2014)

Delays in computer network:


Transmission delay:
(tt) Time which sender takes to transmit a frame on the link.
tt = L/B (L = length of frame, B = bandwidth of channel).

Propagation delay:
(tp) Time taken by 1 bit to travel from sender to receiver.
tp = d/v (d= distance between sender to receiver and v is transmission speed).

Ǫueuing delay:
(tq)Before processing of the frame it has to wait inside the buffer, that waiting
time is called queuing delay.

Processing delay:
(tpr) It is the time taken by a node or processor to process the frame. Basically
it depends on the speed of the processor.

Flow control:
It deals with how much data the sender can transmit so that the receiver
should not overflow.
Data Link Layer

Data link layer uses error control, framing and flow control to send data from
one node to another node.
Chapter 3

Fig. 3.2 Flow Control Protocols


For noiseless channel:
 We do not need to control errors in this channel.
 Let us assume in this channel, no packet is lost or corrupted.
 We can use simple protocol and stop and wait in this channel.
Simple protocol:
 It has no flow control and no error control.
 We assume that the direction of a packet is from sender to receiver i,e
unidirectional.
 In this, the receiver can never discard the packet.
 There is no ack from the receiver.
 Both sender and receiver are constantly running because they do not know
when an event is happening.

Note:
What do you understand about the events happening in the above point?
It means the sender does not know when the packet will come from the network
layer; it has to constantly check, and the receiver does not know when the
packet will come from the physical layer; it also has to constantly check.

Stop and Wait:


 Whenever the Receiver buffer size is full, it starts discarding the packet.
Data Link Layer

 There should be some mechanism so that sender should slow down its
speed.
 Can you guess what that mechanism is?
Sending ACK or acknowledgment from the receiver to sender.
Chapter 3
How stop and wait works:
1) Sender sends a data packet and waits for acknowledgement from the
receiver.
2) Receiver receives the data packet and sends the acknowledgement to
the sender.
3) After having the acknowledgment from the receiver, the sender sends
the next packet.

Working:

The packet needs to be transmitted on a link by sender takes tt time, and


then it needs to propagate from sender to receiver takes tp time and then
at receiver side packet wait inside buffer which is tq time and after that, it
has to process which takes tpr time. Receiver will then transmit the ack on
a link, and it will take ttack time.
Now receiver will send ack to sender which takes tpack time.

Total time for sending 1 packet = tt + tp + tq + tpr + ttack + tpack

Calculation of link utilization or efficiency or sender utilization:


An assumption we made while calculating the total time of a packet.
1) Ǫueuing delay and processing delay can be ignored.
2) Transmission delay for ack can be ignored.
Total time = tt + tp + tpack
Total time = tt + 2tp (tp = tpack)
Efficiency = Useful time/total time
Useful time = tt (transmission of packet)
Data Link Layer

Total time = tt + 2tp


Efficiency = tt / (tt + 2tp)
Efficiency = 1/ (1 + 2a) (a= tp/tt)
Chapter 3

Calculation of throughput or bandwidth


utilization:
Throughput is number of the bits that
can be sent in a link per second
Throughput = Efficiency * Bandwidth
= (tt / ( tt + 2tp) ) * Bandwidth
[tt=L/B]
= L / ( tt + 2tp )
Advantage of simple stop and wait:
 Receiver always acknowledges the
sender by sending an ack packet.
 As the length of packet increases,
efficiency increases. Rack Your Brain

Limitation of simple stop and wait:


a) Do you think any other advantage
1) Bandwidth is not efficiently utilized.
of simple stop and wait.
2) If the data packet gets lost receiver will
b) What will be the effect on
wait for an infinite amount of time.
efficiency if distance increases or
3) If ack get lost sender will wait an infinite
decreases.
amount of time.
For noisy channel:
We need to do error control in this channel.
Sliding window technique is used in this
channel

Sliding window protocol:


 Sender and receiver need to deal with only
a part of the possible sequence number.
 Available sequence number  Sender
window size + Receiver window size.
Stop and wait ARǪ:
 It is 1-bit sliding window protocol
because Sender window size is 1, and
Receiver window size is 1.
 We have seen Stop and wait in the above
section, its working, advantage and
disadvantage.
 Stop and wait ARǪ working is the same
Data Link Layer

as Stop and wait but it solves the


limitation of Stop and wait for protocol
by adding ARǪ.
Chapter 3
Minimum number of Sequence number required in Stop and wait ARǪ?

Available Sequence number  Sender window Size + Receiver window


Size
Available Sequence number  1 + 1
Sequence number  2 (i.e 0,1)

Let us see how it solves the limitation of stop and wait?


a) When data packet is lost?
If the data packet is lost, both the sender and receiver may get into a deadlock.

In order to prevent this situation, after sending the data packet, the sender
starts the time out timer, to make sure the packet is transmitted in a
specified amount of time.

This will prevent from deadlock state.


How to prevent deadlock in Stop and wait?
Sender will add time out timer.
Data Link Layer

Note:
Stop and wait ARǪ = Stop and wait + Time out timer

51
Chapter 3

b) When ACK is lost?


Duplicate packet problem arises, see diagram.

If the timer goes timeout and sender does not receive any acknowledgement
from the receiver, then the sender will retransmit the packet, but packet
will be duplicated.
How to prevent duplicate packet problem in stop and wait?
Add sequence number in data packet, see, figure below.

Note:
Stop and wait, ARǪ = Stop and wait + Time out timer + Sequence Number
in data packet.
Data Link Layer

c) When does Ack gets delayed?


Duplicate acknowledgement problem arises.
Chapter 3
Fig. 3.3 Diagrammatic Representation of Duplicate Acknowledgement Problem
If the timer goes timeout and sender did not receive any acknowledgement
from the receiver, then the sender will retransmit the packet, but packet
will be duplicated this time and receiver will know that the packet is
duplicated due to the sequence number attached to the packet, and it will
resend the acknowledgement that will reach at the same time when the
first acknowledgement reached, it will create a duplicate acknowledgement
problem.

How to prevent duplicate acknowledgement problem?


Add the Sequence number to the acknowledgement.
This time if the sender sees the ack with the same sequence number, it
will get to know that acknowledgement is duplicated, see diagram below.

Data Link Layer


Chapter 3

Note:
Stop and wait ARǪ = Stop and wait + Time out timer + Sequence Number
in data packet + Sequence number in Ack Packet.

Let us understand the difference between “Stop and wait” and “Stop and
wait ARǪ.”

Stop and wait arq Stop and wait

Since the channel is noisy there Channel is noiseless hence no


is error control mechanism. error control.

Timeout timers added after


No concept of timeout timer.
sending packet.

Sequence numbers are added


No concept of sequence number
in data packet as well as in
or acknowledgement number.
acknowledgement packet.

Rack your Brain

Limitation of Stop and wait ARǪ:


Sender sends data in tt time, and then it waits for 2tp time.
This 2tp actually cause limited efficiency.

Let’s consider the given scenario:


Data Link Layer
Chapter 3
 In tt = 1 packet sends
In 1 second = 1/tt packet sends
In a time of (tt + 2 * tp) = (tt + 2 * tp)/tt
packets can be sent.
 From this we get to know we can transmit
(1 + 2a) packet for full efficiency.
But we are sending only 1 packet.
 Sender can send in 2tp time also.

PRACTICE ǪUESTIONS

Sol:

Total number of packet that needs to be sent is 13

Ǫ2

number of packets needs to be transmitted if 500 packets need to be sent?

Sol:
Data Link Layer

 1  500
500 = = 1000
 
 1 − 0.5  0.5
1000 packet needs to be transmitted.
Chapter 3

Ǫuestion

a) 160
(GATE-2015)

Let us understand with example how to increase efficiency in Stop and


wait ARǪ,
Tt = 1msec and Tp = 1.5msec
efficiency = 1/1+2a
Putting values of Tt and Tp we have efficiency = 0.25

Here, sender is transmitting for 1 msec and waiting for 3 msec.


Let’s send 3 more packet in 3 msec:
In the below diagram when the acknowledgement of packet (0) is received, we
can send a new packet (4). At this point, the sender came to know packet(0) is
received, and it makes the space for the packet (4). This is called the sliding
window technique.
Data Link Layer
Chapter 3
Note:
Until the acknowledgement of the first packet comes, sender holds the packet
in buffer, that buffer is known as the sender window.

Go Back N ARǪ:
What is N here ! Sender window size is N
Points:
 The size of the sender window must be less than 2m (where m is the size
of sequence number fields in bits), and the size of receiver window is
always 1.
 Each time the receiver receives a new frame, it starts a new acknowledgement
timer, and if the timer expires, the receiver sends the cumulative
acknowledgement for all the frames which are unacknowledged at that
moment and sometimes, it uses an independent frame if the receiver
wants to acknowledge only one frame.
It silently discards the frames if frames are corrupted.

Sender window:
 It is the sequence number of the data frames which can be in transmitted.
The maximum size of the window is 2 m – 1.
 The sender window will slide according to one or more valid
acknowledgement comes.

Receiver window size:


In Go back N, Receiver size is always 1.

Go Back N, does not accept the out of order packet.


Data Link Layer

Given diagram is a flow how packet travels in Go Back N,


Here, N = 4,
Chapter 3

Fig. 3.4 Flow of Packets in Go Back N

Why is there a need for taking sequence number N+1?


If you see the diagram above Window size is 4, but still, we have taken 5
sequence numbers (i.e 0,1,2,3,4).

In order to understand why we have taken the N+1 sequence number, we


must understand what happens when the acknowledgement gets lost in
Go Back N and when Sender window = Sequence number?
In the below diagram N = 4 and Sequence number = 4.

Here, duplicate packet problem arises.


Data Link Layer
Chapter 3
Now, let us take a situation where N = 4 but Sequence numbers are 5.

Now you get to know why we have taken.

Note:
Maximum sequence number >= Sender window Size + Receiver
window size
Maximum sequence number >= N + 1

Ǫ3

Sol: log2( N+1 )

sible Sequence number in GBN protocol?

Sol: Possible sequence number are from 0 to 2k – 1

Ǫ5
Data Link Layer
Chapter 3

Sol: If N = 4, means window size is 4, if any packet gets lost we need to retransmit
the entire window,

When the acknowledgement of the 5th packet does not reach the sender side, and there
is a timeout timer at the sender side, it will retransmit the entire window.

Note:
The 5th packet contains Sequence numbers from 5,6,7,8. It needs to
retransmit.
Now below diagram shows the scenario for remaining packet.

Total number of packet which needs to retransmit are 16.

Efficiency in Go Back N:
Efficiency = Useful time / Total time
Useful time = Sender Window Size * Transmission time (tt)
Total time = tt + tp + tp => tt + 2tp
Efficiency = N * tt / (tt + 2tp)
Data Link Layer

= N/(1 + 2a)
Chapter 3
Ǫuestion


successfully.
 At the receiver side, it starts the acknowledgement timer, and when it
expires, the receiver will send the cumulative acknowledgement for the
packet it receives in the meantime.

What do you understand by discarding a packet silently in Go back N?


This means it is not going to accept it; due to this, there will be time out at
the other end, and entire window is sent in
case of GBN.
Independent acknowledgment: Sender will Rack Your Brain
receive acknowledgement for every packet
Data Link Layer

61
Chapter 3

Selective repeat ARǪ

Points:
 The size of sender window is equal to receiver window size.
 Available Sequence number = Sender window Size + Receiver window size.
2n = 2n-1 + 2n-1 where n bits are used for sequence number
 As soon as the receiver receives the frames, it sends the acknowledgement,
and uses the independent acknowledgement.

In Go back, N, out of order packets are not accepted, which means the sender
has to send the entire window, which
leads to consumption of bandwidth and
more traffic. In noisy channels, there
are more chances of corrupted packets, Rack Your Brain
then we can use a mechanism called
Selective Repeat ARǪ. Do you think Go back N is preferred in
a noisy link !!
In Selective repeat ARǪ, only the
damaged the frame needs to be sent; it
makes efficient use of bandwidth in the noisy channel.

Note:
Receiver has to do more work in selective repeat, Think why !!

Receiver does not accept the corrupted frame and also does not discard
the frame silently, but it will use negative acknowledgement.
Due to the use of negative acknowledgement, the sender need not to wait
for timeout timer completion.
Receiver accepts out of order packets.
Efficiency in SR protocol: N/(1+2a).
Data Link Layer
Chapter 3
Ǫ6
is used _____ ?

Sol: Maximum window size = 2n-1 => which will give 16

It will be, Sender window size + receiver window size

16 + 16 = 32

Lets see how selective repeat works,

What will happen if we take window size greater than 2?


Let’s take window size as 3,

In the below diagram, when all the acknowledgements are lost, the sender will send the
frame again after the time out timer of that frame, and the receiver will accept the same
frame, but in another window, this is an error.

Data Link Layer


Data Link Layer Chapter 3
Chapter 3
If we see the above figure, after timeout, when the sender resends the
packet again, receiver will give a negative acknowledgement. This is the
reason selective repeat ARǪ we will use window size as 2 n-1.

Data Link Layer


Chapter 3

Comparison of sliding window ARǪ protocols:

Stop and Wait


Go back N Selective Repeat
ARǪ

Efficiency 1/(1+2a) N/(1+2a) N/(1+2a)

Sender Window Sender window Sender window


Size = 1 size = N size = N
Window size
Receiver Receiver window Receiver window
window size = 1 size = 1 size = N

Sequence numbers
2 N+1 2×N
required

In data link control, we have seen that if there is a dedicated link between
sender and receiver how the protocol works, but the case will change if we
do not have a dedicated link.

How to manage in case of cellular networks where channels are not


dedicated?
Here comes Medium access control, which is responsible for multiple
access resolution.

Lets see categories in Medium access control,


Data Link Layer

Fig. 3.5 Flow Chart Representing Multiple Access Protocol


Chapter 3
Random access:
 It depends on the state of the medium.
 There is no proper time for the station to transmit, that is why the name is Random.
 Each station has a right to the medium without being controlled by another
medium.

So, there is collision problem.


Aloha: It was designed for radio, but it can be used on any shared medium.
It can be categorized in 2 ways.
 Pure Aloha
 Slotted Aloha

Pure Aloha:
 It will allow the station to send whenever it has data.
 After sending the data, it waits for acknowledgement from the receiver.
 If it receives the acknowledgement, then the transmission is successful.
 If it doesn’t receive the acknowledgement, then the transmission is
unsuccessful; after the timeout timer expires, it will resend the data.

Note:
Vulnerable time: This is the time when collision is possible.

Pure aloha vulnerable time = 2 * frame transmission time(Tt)

Throughput in pure Aloha:


Data Link Layer

Let us assume G = Average number of frame generated during one frame


transmitted time.
The throughput for pure ALOHA is S = G x e-2G
Chapter 3

The maximum throughput Smax = 0.184 when G =(1/2).


G = 1/2, it means when 1/2 frame is transmitted in one Tt time or in other
way 1 frame is transmitted in 2Tt time.
The maximum efficiency of Pure Aloha is very less due to the large number
of collisions.

Ǫ7
shared channel having, bandwidth of 100 kbps. Calculate the throughput if
250 frames/second is produced by the system(all station together)?

Sol: Frame transmission time = 1msec


Now station is producing 250 frames in 1 sec, that means (¼) frame in 1 msec
The throughput for pure ALOHA is S = G x e-2G which will give 0.152.
Now 250 * 0.152 = 38 frames will survive out of 250 frames.

Slotted Aloha:
 In slotted Aloha, data can be transmitted by any station at any given time
slot, but the only condition is that a station has to begin its transmission at
the start(beginning) of the time slot. A station has to wait until the starting
of the next time slot in case it misses the starting of a given slot.
 In this, no station sends the data in the middle.

Fig. 3.42 Diagrammatic Representation of


Data Transmission in Slotted Aloha
Rack Your Brain
Vulnerable time = Tt

Throughput of slotted Aloha: Consider a 100-bits frame is transmitted


The average number of successful
Data Link Layer

transmissions for slotted Aloha is S = G x


e-G. The maximum throughput S is 0.368,
max
when G = 1.
Chapter 3
Comparison between slotted aloha and pure aloha:

Pure Aloha Slotted Aloha

Station can send their data at Can transmit only at the


any time beginning of slot

Vulnerable time = 2 * Tt Vulnerable time = Tt

Throughput = G × e–2G Throughput = G × e–G

Carrier sense multiple access protocols:


 It was developed to minimize the chance of collision and increase efficiency.
 It was based on the principle “Sense before transmit”.
 The vulnerable time for CSMA is the propagation time Tp. This is the time
needed for a signal to propagate from one end of the medium to the other.
 In the given diagram station A sends its data to station D in time Tp, when,
station B wants to transmit its senses and similarly, C senses.

What should a station do when the channel is busy or idle?


There are 3 methods for this:
1-persistent method,
non persistent method,
and the p-persistent method

1-persistent method:
If the station finds the line idle, it sends its frame immediately,
If the channel is not idle, the station will continuously sense the channel.
Non persistent method:
If the station finds the channel idle, it sends its frame immediately.
Data Link Layer

Stations will wait for a random amount of time if they find the channel is busy,
and when the channel is idle, it will send the frame again.
Chapter 3

P persistent method:
In this method the station sends its frame with probability p, and it will not
transmit with probability q = 1 - p. The station waits for the beginning of the
next time slot and checks the line again. Now if the line is idle, it sends the
frame with probability p and defers with probability q.
Carrier sense multiple access with collision detection:
Carrier sense multiple access with collision detection (CSMA/CD) elongate
the CSMA to handle the collision.

Note:
Each station can sense the carrier only at its point of contact with the
carrier.

Let us understand how a station senses the channel.


Station A wants to send data to station C, and station C wants to send data
to station A.

It can be clearly observed that a collision is about to happen!! How to


prevent this?
We need a restriction on the frame size.
Each station must transmit the data packet of size whose transmission
delay is at least twice of its propagation delay.
Transmission delay >= 2 x Propagation delay
From this we can derive what will be the minimum size of the packet from
‘B’ to ‘A’.
L >= 2 * Tp * B

Collision happens here when A is about to transmit, B can detect collision


Data Link Layer

if it receives collision signal/jamming signal and it’s still transmitting data.


Tt  TP(data) + TP( jammin g)

Tt  2Tp
Chapter 3
Rack your Brain

What is the minimum packet length when Tp = 1msec and Bandwidth


= 1Mbps

Efficiency:
Useful time = Transmission delay of data packet = Tt
Total time = Time during collisions + Propagation delay of data packet + Tt
= c x 2 x Tp + Tp + Tt (where c = Number of contention slots).
Efficiency = useful time / total time
Tt /(c x 2 x Tp + Tp + Tt)
Analysis using probability gives the Average number of collisions before a
successful transmission = e
Which leads to c = e
Now Efficiency = Tt /(e x 2 x Tp + Tp + Tt )

Note:
What is the average number of collisions before successful transmission?

P(success) = nC1 × p × (1–p)n–1...1


In order to find maximum value we need to differentiate w.r.t. p
dP/dp = 0
On solving we get p = 1/n putting this value in (1) we get
Now P(success)max = (1–1/n)n–1
If there are large number of stations n –> ∞
n–1
 1 1
= Lim  1 −  =
n→  n e

Number of times that a station request before successfully transmitting


Data Link Layer

the data packet,


= 1/Pmax = 1/(1/e) = e
Efficiency of standard ethernet = 1/ (1 + 6.44a) where a = Tp / Tt

71
Chapter 3

Points:
 It is used in Wired LAN (802.3)
 Probability of successful transmission = nC1 x p x (1-p)n-1

Let us understand; what is Backoff time?


In CSMA / CD protocol, after the occurrence of a collision, the station waits
for some random backoff time and then retransmits, and this waiting time
for which the station waits before retransmitting the data is called backoff
time.
Backoff time = k * timeslot (station chooses number K and timeslot is one
round trip time).

Note:
If collision is happening for nth time then station will choose a random
number k from ( 0,2n - 1 )

Possibilities:

A B (Description)

0 0 Both station will collide

0 1 Station A will win

1 0 Station B will win

1 1 Both station will collide

Concept Building Exercise

When A = 0 and B = 1, why station A won ! How do you conclude?


1
Data Link Layer

1 1
Chapter 3
Note:
In this algorithm, Backoff time increases exponentially
And collision probability decreases exponentially
It shows a capture effect (if the host wins the collisions for one time, it is
going to win more numbers of times).

Ǫ
8
is increased to 100 Mbps by keeping the propagation delay constant?

Note:
If bandwidth increases, frame size can also increase.

Ǫuestion

1
1

a) 10000 bits b) 10000 bytes

Sol: (GATE-
Data Link Layer
Chapter 3

Previous Years’ Ǫuestion

Sol: 135 (GATE-2021)

Controlled access protocol;

In this protocol basically 3 methods are used:


 Polling
 Reservation
 Token Passing

Polling:
There is a Centralized controller which polls ‘stations’, and gives them an
opportunity to send one packet.
All the data which needs to exchange must go through the controller.

Disadvantage in polling:
There is a high overhead of polling messages.
Stations have to depend on controller.
Data Link Layer

Fig. 3.6 Data Transmission in Polling


Chapter 3
Efficiency = Useful time / total time
Useful time = Tt
Total time = Tpo + Tp + Tt
= Tt / (Tpo + Tp + Tt)

Reservation:
Station that wants to send data needs to make a reservation.
Time is divided into intervals.
In each interval, a reservation frame precedes the data frames sent in that
interval.

In the above figure there are 3 slots made if 3 stations want to send data.
In the first interval, only station 1, and station 3 made a reservation and in
the second interval.
Only station 1 made a reservation.

Token passing:
Stations are connected in the form of ring.
Access is granted through the token.
when the station receives the token, it can send a frame (if it has frame)
before it passes the token to the next station; if the station does not have
a frame simply, it will pass the token to the next station.

Fig. 3.7 Diagrammatic Representation of Token Ring


Data Link Layer

Early token reinsertion


Efficiency = 1/(1 + a/N) and
Delayed token reinsertion
Efficiency = 1/(1+{a(1 + 1/N)})
Chapter 3

Channelization protocol:
Channelization is a multiple-access method in which the available
bandwidth of a link is shared in time, frequency, or through code between
different stations.

Time division multiple access:


Time of the link is divided into fixed-size intervals called time slots or time
slices.
Each station can transmit the data in its time slot only.
Let’s say there are 3 stations A,B and C.

Fig. 3.8 Diagrammatic Representation of TDMA

Slots are given on the basis of Round


Efficiency = Useful time/ total time
Tt / (Tt +

Disadvantage:
If the station does not want to send the
frame, then also time slot has given, which
eventually leads to bad efficiency.
Rack Your Brain
Frequency division multiple access:
In FDMA, the available bandwidth of the
common channel is divided into bands that
are separated by guard bands.
Each station has an assigned separate channel.
Data Link Layer

Fig. 3.9 Diagrammatic Representation of FDMA


Chapter 3
Wired Lan: Ethernet:
Ethernet is one of the standard LAN technologies used for wired LANs and It
is defined under IEEE 802.3.
Till now we have seen Data link layer in two parts.
First one is Data Link Control, and the Second one is Medium Access Control.

But there is only one MAC sublayer in standard ethernet.


Points:
 Topology used is Bus.
 Access control method used is CSMA/CD.
 Encoding Technique used is Manchester.

Fig. 3.10 Ethernet Frame Format

Preamble:
a) It contains 7 bytes.
b) It has 0 and 1 in alternate position.
c) It is actually added at the physical layer.
d) It enables frame to synchronize between sender and receiver.

SFD:
It contains 1 byte: 10101011.
SFD tells the station that this is the last chance for synchronization. The last 2
bits are 11 and alerts the receiver that the next field is the destination address.

Destination address: It is a 6 byte field.


It contains the MAC address (physical address) of the destination.

Source address: It is a 6 byte field.


It contains the MAC address (physical address) of the source.
Data Link Layer

Length: It is a 2 byte field.


Length field describes the number of bytes in the data field.
Chapter 3

Note:
The maximum value that can be accommodated in this field = 216 – 1 = 65535
bytes, but the maximum amount of data that can be sent in an Ethernet
frame is 1500 bytes.

Note:
Minimum frame length = 64 bytes
Maximum frame length = 1518 bytes

Data: This field contains actual data also called payload field.
Minimum bytes in data field = 46 bytes.
Maximum bytes in data field = 1500 bytes. Rack Your Brain

CRC: It has 4 bytes.


Why 65535 bytes is not allowed in
This field is used for error detection.
ethernet frame?
Addressing in ethernet:
Each station has NIC (Network interface card) which has its own physical
address.

We already know physical address has 6 bytes.


It is written in hexadecimal code with colon between bytes.
There are 3 types of addresses:
 Unicast
 Multicast
 Broadcast address

Note:
The least significant bit of the first byte defines the type of address. If the bit
is 0, the address is unicast; otherwise, it is multicast.
Data Link Layer
Chapter 3
Source address is always unicast.
Destination address can be unicast, multicast or broadcast
The broadcast destination address is a special case of the multicast address
in which all bits are 1.

Data Link Layer


Chapter 3

Connecting devices:
 Operate at physical layer: Active Hub or repeater
 Operate at physical and data link layer:
bridges or 2 layer switches
 Operate at physical, data link layer and
etwork layer: Routers or 3 layer switches
Operate at all five layer: Gateways

Repeater:
 It receives the signal at physical layer
and before the signal becomes too weak
it regenerates the original bit pattern
 A repeater regenerates the signal. It
does not amplify signal.
Data Link Layer
 A repeater connects two segments of LAN.
 A repeater forwards every frame, it has no filtering capability (Collision
domain remain).

fig 3.11 Regeneration of Signal Using Repeater

Rack your Brain


Note:
A repeater is not used for connecting two Difference between repeater and
LANs of different protocols. amplifier.
Active hub:
It is a multiport repeater.
Hubs can also be used to create multiple levels of hierarchy.
Hubs cannot filter data (collision domain remain same).

Bridges:
It works at the physical layer and data link layer.
At the physical layer, it regenerates the signal.

Chapter 3
At the data link layer, it can check the MAC address contained in the frame.
It has filtering capability (because it can check the destination MAC address
and decide whether the frame has to forward or drop).

Router:
Three layer switch:
 A three-layer switch is a router, which is faster and more sophisticated.
 The switching fabric in a three-layer switch allows faster table lookup and
forwarding.
 It can separate broadcast domain.

Data Link Layer


Chapter 3
How does a communication through a router happens?
Router can inspect through network layer:

Gateway:
 A gateway is normally a computer that operates in all five layers of the
Internet or seven layers of OSI model.
 Gateways can provide security.
 It is used to filter unwanted application-layer messages.

Concept Building Exercise

1
Data Link Layer
Chapter 3

Ǫuestion

Sol: (GATE-

Chapter summary:

 Data link layer: Two major function


1) Data Link Control
2) Medium Access Control
 Data Link Control performs Framing, Error Control, Flow Control.
 Medium Access Control performs Access Control and Physical Addressing.
 There are two types of framing
1) Fixed Size Framing
2) Variable Size Framing
 Error detection can be done by Parity checking, CRC and Checksum.
 Some rules for generating the generator polynomial
Rule 1: It should not be divisible by x.
Rule 2: It should be divisible by x+1.
 Flow control:
Set of procedures used to restrict the amount of data that the sender can send
before waiting for an acknowledgement.
Flow control can be done in Noiseless channels and noisy channel.
In Noiseless channel: Stop and Wait
In Noisy channel: Stop and Wait ARǪ
Go back N ARǪ
Selective repeat ARǪ
 Available Sequence number >= Sender window Size + Receiver window Size
Data Link Layer







Data Link Layer Chapter 3


Network Layer

Chapter 4
4.1 NETWORK LAYER
Across multiple links, the network layer is responsible for source to
destination delivery. Is the data link layer not enough? No, as it works on
the same links.

Logical addressing:
Now for implementation, logical address is IP addresses having 32 bit
number which is globally unique, and physical address are MAC address
having 48 bit which is also globally unique.

Let’s talk about IPV4 address: Rack Your Brain


It is 32 bit long and unique
What do you understand by unique here!
This means two devices on the internet can
Can MAC be used as Logical Address?
never have the same address at the same
time.
Note:
For N bit, there can be 2N values.
Network Layer

For 32 bit address, we have 232 address space (4,294,967,296).


Chapter 4

Notation:
Binary notation – 10000001.10000011.10000
010.00000010 Rack Your Brain
Dotted decimal notation – 129 . 131 . 130 . 2

Classful addressing:
In classful addressing, the address space is
0001.00000011.00001011.10101101
divided into five classes: A, B, C, D and E.
a) How each class is distributed when it is
represented in Binary?
When the address is given in binary
notation, the first few bits can signify

Rack Your Brain

class? 00000001.00000011.00001011.10

b) How each class distributed when it is represented in dotted decimal?


When the address is given in decimal–dotted notation, the first byte
defines the class.

Rack Your Brain


Network Layer
Chapter 4
Now we will see what Net ID and Host ID are!
In IP address, each of 4 bytes is called octets, where each octet has 8
bits. The octets are divided into 2 components – Net ID and Host ID.
Class A, B and C have Net ID and Host ID, class D, and; class E does not
have Net ID and Host ID.

Note:
Net ID: Network IDs are IP addresses of the network and are used to
identify the network.
Host ID: Host IDs are the IP address of the host and is used to identify the
host within the network.

In Class A, 1 byte denotes Net ID and remaining 3 bytes are Host IDs.
In Class B, 2 bytes denote Net ID and remaining 2 bytes are Host IDs.
In Class C, 3 bytes denote Net ID and remaining 1 bytes are Host IDs.
In Class D, there is no Net ID and Host ID.
In Class E, there is no Net ID and Host ID.
Let’s take a look at individual class.
Class A:

Rack Your Brain

 Total number of possible IP addresses available in this class is number


of networks * possible number of address in single network.
126 * (224) = 2113929216
 Total number of networks available in this class is 27–2.
 Total number of hosts available in each network in this class is 224–2.

Why did we subtract 2 from 27?


IP address 0.0.0.0 is reserved for broadcasting requirements and IP address
127.0.0.1 is reserved for loopback address used for software testing.
Class B:

Rack Your Brain


Network Layer
Chapter 4

 Total number of possible IP addresses available in this class is 230.


 Total number of networks available in this class is 214.
 Total number of hosts available in each network in this class is 216–2.

Class C:

 Total number of possible IP addresses available in this class is 229.


 Total number of networks available in this class is 221.
 Total number of hosts available in each network in this class is 28–2.

Class D:

1110

 Total number of possible IP addresses available in this class is 228.


 Class D is reserved for multicasting and there is no need to extract the
host address from the IP address in multicasting.

Class E:

1111

 Total number of possible IP addresses available in this class is 228.


 Class E is reserved for future purposes.

Mask:
It is a 32 bit number made of contiguous 1 followed by contiguous 0. It will
help to find the Net ID and Host ID.

Let’s say the mask for a class A address has eight 1’s, which means the
first 8 bits of any address in class A define the Net ID, and the next 24 bits
define the Host ID.
Network Layer

Default masks for classes A, B and C are given in table.


Chapter 4
Summary of what we have read till now is given in table below:

Class of IP Total Number Number of Host Per Default Subnet


Address of IP Addresses Networks Available Network Mask

Class A 126 * (224) 27–2 224–2 255.0.0.0

Class B 230 214 216–2 255.255.0.0

Class C 229 221 28–2 255.255.255.0

Class D 228

Class E 228

Note:
Blank spaces are not defined.

Concept Building Exercise

1
1
Network Layer

91
Chapter 4

Concept Building Exercise

a) 191.2.255.255 b) 127.0.0.1

Ans. d)
Sol: a) 191.2.255.255 is DBA

Note:
In classful addressing, class A, B and C are used for reserved addresses, class D is used for
multicast, and class E is used for future purpose addresses.

Limitation of classful addressing:


In classful addressing, we are using fixed
classes for special purposes which is not
efficient in today’s scenario like Class C is
used for the midsize organization, but it is
Rack Your Brain
not effective as the only Host available per
network is 28. For the given IP address 191.5.26.7 what

Classless addressing:
 Classless addressing is used now, and
classful has become obsolete.
 In classless addressing, ISP (Internet service provider) grants IP
addresses based on requirement on the number of customers needed.
 It is an improved version of classful addressing and is also known as
CIDR (classless interdomain routing).
Network Layer
Chapter 4
How ISP grants IP addresses?
There are 3 rules for CIDR block creation:
Rule 1: All the IP addresses must be contiguous in a block.
Rule 2: A block must be in power of 2 ( 1,2,4,8….).
Rule 3: The first address is evenly divisible with number of address.

PRACTICE ǪUESTIONS
Block of 4 addresses can be assigned to an organisation having an IP

Sol: According to CIDR,


Rule 1: All the IP addresses must be contiguous in a block.

205.26.24.8, 205.26.24.9, 205.26.24.10, 205.26.24.11

Rule 2: A block must be in the power of 2.


Yes, 4 is power of 2
Rule 3: The first address is evenly divisible by a number of address.
First address is 205.26.24.8 which is divisible by 4 (block size).

Ǫ2 What does a CIDR IP address look like?

Sol: p.q.r.s/t
t is used as identifier for network Rack Your Brain
bits.
32-t bits used as identifier for Host Ǫ) What is the block address of
bits. 2.2.3.4/5?

Ǫ3

Sol: Let’s first write it in binary.


Network Layer

11000000. 00000100. 00000101. 00000110/16


Chapter 4

First 16 bits represents network id.


11000000. 00000100. 0. 0 (Network ID)
As you see, we got the network address by keeping 16 bits as it is and making 32 -
16 bits 0.
Remaining 16 bits are used for the identification of the Host id, in which one of the
host is given IP address i.e 192.4.5.6.

Given a CIDR representation 122.10.5.8 / 29. Find the range of an IP addresses in


CIDR representation?

Ǫ5 Following IP addresses are given, can you apply CIDR aggregation?

Sol: 188.67.00000100.0 / 24
188.67.4.0 Number of hosts possible in one network is 28
Rule 1: Is the given block contiguous ! Yes.
Rule 2: Is the size of the block is in power of 2 !! yes.
Total number of host possible is 28 + 28 + 28 + 28 = 210
Which is in the power of 10
Rule 3: The address of the first
block is evenly divisible by the size
Rack Your Brain
of the block !!!
188 .67.00000100.0 when divided by
210 last 10 significant bits are 0.
Hence yes given block can follow
CIDR aggregation.
Network Layer
Chapter 4
Note:
The first address in a block is normally
not assigned to any device, it is used as
the network address that represents the
organization to the rest of the world.

Subnetting:
An organisation that is generated a large
block of address may need to break into
small networks (Subnets) On a higher level
i.e. from outside the organisation, it works
as a signal network, but internally, it may
have many networks.

Subnetting is the process of dividing a


network into multiple sub networks.

We can divide subnetting into two parts:


Rack Your Brain
Classful Subnetting (Fixed length subnetting)
Ǫ) Can you guess the advantages of
Classless Subnetting (Variable length subnetting.
subnetting)

Lets see the difference between Classful


subnetting and classless subnetting.

Classful Subnetting Classless Subnetting

Same size subnets Different size subnet

Subnets have equal number of host Unequal number of host

All the subnet have same mask Each subnet have different mask

Table 4.1 Classful Subnetting vs Classless Subnetting


Network Layer

Lets say we have a single big network having


IP 2.0.0.0.
Chapter 4

We have to make 2 subnet?


Take one bit from the host id, from one bit we can make two subnet.

 Lets see inside First Subnet i.e Subnet 1.


Subnet Id of Subnet 1 = 2.0.0.0, this is the Net ID of the Big network also.
DBA of subnet 1 = 2.127.255.255
LBA of subnet 1 = 255.255.255.255
 Total number of IP addresses possible in Subnet 1 = 223. Why have we
taken 23 not 24 bits? one bit is used for subnetting from host part.
 Total number of hosts that can be configured = 223 – 2.
 Subnet Mask of this subnet = 255.128.0.0
 Range of subnet 1 = 2.0.0.0 to 2.127.255.255 !! Why have we stopped at
127 not 255.
 Since subnet 1 as taken 0 bit on MSB see binary notation of last octet.
00000010.0000000.0000000.0000000 to 00000010.01111111.11111111.11111111

Lets see inside Subnet 2.


 Subnet Id of Subnet 2 = 2.128.0.0
 DBA of subnet 2 = 2.255.255.255. this is the DBA of entire network also.
LBA of subnet 2 = 255.255.255.255
 Total number of IP addresses possible in Subnet 2 = 2 23. Why have we
taken 23 not 24 bits? One bit is used for subnetting from host part.
 Total number of hosts that can be configured = 223 - 2.
 Subnet Mask of this subnet = 255.128.0.0
 Range of subnet 2 = 2.128.0.0 to
2.255.255.255. Rack Your Brain
 Since subnet 2 as taken 1 bit on MSB
Network Layer

see binary notation of last octet.


00000010.1000000.0000000.0000000
to 0000010.1111111.11111111.11111111
Chapter 4
We want, to divide this big network having IP address into 3 small networks!
Lets see

3 Subnet having Possible IP address using,

Case 1:
2.0.0.0

2.64.0.0
Network Layer

2.128.0.0
Chapter 4

Case 2:
2.0.0.0
2.128.0.0
2.192.0.0

Ǫuestion

i) 202.61.84.0/21 ii) (202.61.104.0/21


iv) 202.61.144.0/21

Sol: b) (GATE-2020)

Let’s see how address allocation is done?


Responsibility of address allocation is taken care by ICANA (Internet
Corporation for Assigned Names and Addresses). ICANA gives a block of
addresses to ISP; Now it is the responsibility of ISP to divide the block of
address into sub-blocks;
Standard example of subnetting in CIDR

Example 1: Suppose ISP grants a block of address starting with 180.200.0.0/16


to Unacademy. Now Unacademy wants to distribute this address into two
teams, the names of the teams are NEET. GATE.
I) NEET has 32 teams and each team needs 128 address.
II) GATE has 64 teams and each team needs 64 address.

Sol:
Network Layer
Chapter 4
Ǫ6 How many possible Host addresses does the Unacademy block have?

Sol: 16 bits are available for address; therefore, 216 addresses are possible but first
and the last IP should not be assigned to any host therefore 2 16 - 2 Hosts can be
configured.
Since the NEET team wants 212 and the GATE team wants 212.
combinedly need 213 address. i.e 8192 address.
Total Available address are 216
S0, Available can satisfy the Needs of two teams.
given,
180.200.0.0/16
make, two subnets by borrowing a single bit from HID part 16 bits.
180.200.0/1 0000000.00000000
Suppose NEET team
180.200.00000000.00000000/17 ® start
180.200.01111111.11111111/17 ® end
it has 32 teams each with 128 address requirements.
for 32 teams take 5 bits.
180.200.0xxxxx00.00000000/22
180.200.00000000.00000000/22 -starts
180.200.01111100.00000000/22 -End
suppose GATE team.
180.200.10000000.00000000/17 -- start
180.200.11111111.11111111/17 --end
it has 64 teams with each 64-address requirement.
for 64 teams take 6 bits.
180.200.1xxxxxx0.00000000/23 Rack Your Brain
180.200.10000000.00000000/23 –starts
Network Layer

180.200.11111110.00000000/23 --ends
Chapter 4

Example 2: A subnet mask 255.255.192.0.0 belongs to class B.


How to find the number of subnets in this subnet mask.

How to find the number of hosts in each Subnet?


Example 3: A subnet mask 255.255.0.0 belongs to class A.
How to find number of subnets in this subnet mask.
Class A net id has 8 bits.

Given Subnet mask has 16 nits.


Number of subnet bit = 16 - 8 = 8 bits (see below figure for more information).

How to find the number of subnets if subnet mask 255.255.0.0 belongs to class B.
Network Layer
Chapter 4
How to find the number of subnets if subnet mask 255.255.0.0 belongs to
class C.

Why is the subnet not possible in the above case!!


For Subnet Mask for class C (255.255.255.0), all 1’s cover the given subnet
mask (255.255.0.0). Hence there are no extra 1’s which can be used in
subnetting therefore, subnet is not possible.

Supernetting:
Combination of multiple networks into one single network by following
some rules is Supernetting.
Rules for Supernetting:
Rule 1: All the IP addresses must be contiguous in a block.
Rule 2: A block must be in power of 2 (1,2,4,8….)
Rule 3: The first address is evenly divisible with number of address.

Concept Building Exercise

200.100.10.0
200.100.12.0
200.100.15.0
200.100.17.0

200.100.10.0
200.100.11.0
200.100.12.0
200.100.13.0
Network Layer

101
Chapter 4

Network address translation:


a) With a shortage of available IP, there is
a need for translation of addresses. Rack Your Brain
NAT comes as a solution for this
problem.
b) In the given diagram, IP 1 is used inside
the organisation, while outside the
organization it can be treated as IP2, IP3
depending upon the situation.
c) Inside the organization, IP1, is called as Private IP.
d) Outside the organization, IP2, IP3, IP4 and IP5 are called public IP.

How does a host get to know that a particular IP coming from the internet
is it’s or not?
Answer: It is the NAT table. A NAT table is responsible for mapping each
private IP to its corresponding public IP.

The Internet authorities have reserved three sets of addresses as private


addresses.

Range Total

10.0.0.0 to 10.255.255.255 224

172.16.0.0 to 172.31.255.255 220

192.168.0.0 to 192.168.255.255 216


Table 4.2 Range of Private IP Addresses
Network Layer

Lets understand the NAT working:

102
Chapter 4
Step 1: Client send an IP packet to access point:

Step 2: Now the modem or access point sends the IP packet with a different
IP address to the server. In addition to this, it records the mapping of the
incoming and outgoing packet

Step 3: Now, when the web server responds it responds with the same
public IP address.

Step 4: Access point gives back packet to the client.


Network Layer

103
Chapter 4

Concept Building Exercise

Ǫ.10 How will NAT use this mapping when the packet has source IP 192.168.22.1 returns

NAT Table:

Source Destination Source Destination NAT


IP IP Port Port Port

192.168.22.1 200.200.1.1 2456 80 4000

192.168.11.2 201.102.1.1 1245 21 5000

Source IP 200.200.1.1
Destination IP 192.168.22.1

Note: Rack Your Brain


Despite having NAT, the depletion of IP
address is not yet solved.
IPv4 does not provide better security
features on its own.
By maintaining the basic functionality of IP
addressing, IPV6 comes into the picture.
Let’s discuss IPv6 addressing.

Points:
1) It is 128 bit long, hence a larger address
space (IPV4 is 32 bit long).
2) IPv6 can be written in hexadecimal and
binary notation.
Network Layer
Chapter 4
a) In Binary we denote IPv6 something like this

Now if write IPv6 in binary every time, it would be long, hence we can use
hexadecimal notation also.
b) In hexagonal notation, IPv6 looks like:

There are 8 octets in hexadecimal notation, each octets is having 2 byte in


length

1) Abbreviations in IPv6:
The need for abbreviations in IPv6 is that if we write in hexadecimals, then
also there are some zeros which can be shortened. Hence we come up with
rules which can reduce the size of hexadecimal notation illustrated below.

Points from above illustration:


a) Leading zeros can be eliminated.
b) Lets say 0017 can be written as 17.
c) If there are consecutive zeros that can
be replaced by a double colon. Rack Your Brain
d) Only leading zeros can be removed not
Network Layer

the trailing zeros like 4120 cannot be Expand: 13:: 123: FFFF: ABCD: 1AC0
written as 412.

105
Chapter 4

e) With a larger number of IP addresses, end to end connectivity can be easily done.
f) No broadcasting in IPv6, though multicast is there to communicate multiple host.
g) IPv6 has different types of addressing modes UNICAST, MULTICAST and ANYCAST.

UNICAST:
 It is based on one source and one destination.
 In unicasting, the router forwards the received packet through only one of its interfaces.
 Forwarding a packet is done only one of its interfaces.
 Its a type of one one communication.

A multicast packet starts from S1 and sends it to groups D2 at all interfaces.


In multicasting, the router may forward the received packet through several of its interfaces.

MULTICAST:


Network Layer

106
Chapter 4
Concept Building Exercise:

Sol: NO,

1
1

Note:
1) In order to find the Subnet ID or number of Subnet, We have to know
class ID or NID.
2) Even without knowing the class of network, we can find HID.

107
Network Layer
Chapter 4

Example 1: Subnet mask = 255.255.255.128


and it is from class A. Ǫuestion
Sol:
We know NID + SID = Total number of 1 Ǫ) Every host in an IPv4 network has a
HID = No of Zeros 1–second resolution real–time clock
with battery backup. Each host
Number of 1’s is 25 needs to generate up to 1000 unique
NID in class A = 8 bits identifiers per second. Assume that
SID = 17 each host has a globally unique IPv4
Number of Subnet = 217 address. Design a 50–bit globally
unique ID for this purpose. After
Number of 0’s = 6 what period (in seconds) will the
IP address = 26 identifiers generated by a host wrap
Possible Host = 26 - 2 around?
Sol: 256 (GATE-2014)
Example 2: What should be the value of n in
a.b.c.d/n, when we want a block size as 215?

Sol: It should be 32 - 15 = 17
NID = 17 bits

Example 3: Can you mention all the IP


addresses present in 10.1.5.0/30 block ?

Sol: It has 4 IP addresses


10.1.5.0/30

10.1.5.1/30

10.1.5.2/30

10.1.5.3/30

Note:
In above solution only 2 IP can be used as
Host ID.
Network Layer

108
Chapter 4
Special IP address chart and their meaning:

NID HID Description

  Valid IP Address

 0’S Network IP

 1’S Directed Broadcast

1’S 1’S LImited Broadcast

1’S 0’S Subnet Mask

0’S  Host within N/w

0’S 0’S Host dont know IP

127  Loop Back address

Need for network layer:


Since the data link layer was responsible
for Hop to Hop delivery, there needs a
mechanism which will take care of host to
host delivery through routers.

You may think Host to Host delivery can


also be done through a data link layer!
yes, possible only when these two hosts
share a single network. What if they share
a different network? Network layer takes
care of this situation.

Note:
Internet uses datagram approach in Rack Your Brain
packet switching.

Internet protocol version 4 is used by TCP/


Network Layer

IP model.
Look where IPv4 is placed at TCP/IP suite.

109
Chapter 4

IPv4 has no error control and no flow control, IP relies on TCP in order to
take care of error and flow control.

What are we called packets at IPv4? Datagram packets.


IPv4 datagram format:

Fig. 4.1 IPV4 Header Format


Network Layer

Version: It has 4 bit,


 IPv4 uses version 4 whereas IPv6 uses version 6.

110
Chapter 4
 Binary 0100 can be written in this field.

Header length:
 It has 4 bit.
 It defines length of IP header.

Note:
What is the minimum and maximum length
of the IP header? Grey Matter Alert!
Minimum length = 20 Bytes, How? number
of essential rows * size of each rows i.e 5  We have minimum and maximum
* 4 bytes. length as 20 and 60 bytes
Maximum length = 60 bytes, How? respectively.
Maximum size of options are 40 bytes  But at header length we have only
20 + 40 = 60 bytes. 4 bits i.e using 4 bits maximum we
can go upto 15 bytes.
Example: If IPv4 has a binary pattern starting
 It leads to the concept of scaling
with 0100010.. What does this mean?
factor in this case it is 4 bytes.
This means packet has version 4 and header
 Header length = Header length field
length is 2 * 4 = 8 bytes.
value * 4 bytes. If header length
Example: If IPv4 has a binary pattern starting field contains decimal value 6
with 01001111.. What does this mean? (represented as 0110), then-Header
This means packet has version 4 and header length = 6 x 4 = 24 bytes.
length is 15 * 4 = 60 bytes.
Service: It has 8 bit fields.

 Precedence bits are never used.


 Types of bits are used for various
purposes depending on the protocol for Rack Your Brain
Network Layer

ICMP and BOOTP it uses 0000 bits at


Type of services.
Chapter 4

Total length: It has 16 bit fields.


What is the minimum and maximum total length?
Minimum total length = Header length + Payload length

20 + 0 = 20 bytes

Maximum total length = > with 16 bits we can go upto (2 16 - 1) bytes = 65535
bytes.

Example: In IPV4 packet HLEN is 7, value of total length field is 0x0033,


How many
bytes of data are being carried?
HLEN = 7, number of bytes in header = 28 bytes (1 byte from the option)
Total length = 51 bytes
Packet carrying data = 51 - 28 = 23 bytes

Identification: It has a 16 bit field.


 From datagram packets, this field is responsible for the identification
of fragments.
 Let’s say there are n fragments; then each fragment are assigned the
same identification number.
 Why is the identification number given to each fragment? So that during
reassembly router can identify which IP datagram the fragments belong
to.

Flags:
There are 3 bits, one bit uses do not fragment bit; one bit uses more
fragment bits, and one bit is reserved.

Do not fragment bit: The value of this field can be 0 (do fragment if required)
or 1 (do not fragment).
Network Layer

More fragment bit: It may be 0 (last fragment or only fragment) or 1 (more


fragments are present behind this packet).
Chapter 4
Fragment offset: It is has 13 bit.
It is equal to number of bytes ahead of it.

Note:
total length field = 16 bits = > 65535 Bytes.
Fragment offset = > 13 bits which will give 213 - 1 bytes = 8191 Bytes.
Scaling is done because fragment offset cannot represent sequence of
bytes greater than 8191.
Scaling factor in fragment offset = 216 / 213 = 23
Fragment offset field value = fragment offset/8

Time to live: It is a 8 bit field.


 Purpose of TTL is to prevent from looping.
 Devices which is having network layer decreases TTL by 1.
 At destination, value of TTL must be 0 or greater than 0 then the
datagram packet will be accepted.
 At, the intermediate the value of TTL must be greater than 0; otherwise
packet will be discarded.

Protocol: It is a 8 bit field.

Protocol values

Value Protocol

1 ICMP

2 IGMP

6 TCP

17 UDP

89 OSPF

Which protocol IP datagram belongs depending on the value inside the


protocol field.
Network Layer
Chapter 4

These numbers will eventually decide the router when the traffic becomes
heavy which packet to discard.

The sequence of discarding the packet at routers is ICMP > IGMP > UDP
>TCP

Means, TCP is the least discarded.

Header checksum: It is a 16 bit field


Checksum value stored in this field

At every router, checksum is calculated if


it is not matched with the value present in
the header, then the packet is discarded.

What are the fields that may be modified at


every router?
TTL, Fragment offset, Header length,
Datagram length, Options

Source IP address:
 It is a 32 bit fields.
 It is having IPv4 address of the source.

Note:
IPv4 address must not change until packet reaches destination.

Destination IP address:
Network Layer

 It is a 32 bit fields.
 It is having IPv4 address of the destination.

114
Chapter 4
Note:
IPv4 address must not change until packet reaches source.

Options: It has 0 to 40 bytes


 They are not mandatory but can be used for testing.
 Mainly it is used for source routing, record route and padding.

Record route:
When this option is set in the options field, the IP address of the router gets
recorded in the options field.

Source routing: This field is used in order to check if the path is working
or not.
It may

Padding: Addition of dummy data to fill up space and make it a standard


size is called padding, usually done through options only.
Options are actually used for testing and debugging.
Let us understand fragmentation through example.

Example: A packet has arrived with an M bit value of 0. Is this the first
fragment, the last fragment, or a middle fragment? Give your view about
fragmented packets?

Sol: Since M bit = 0,


This may be the last fragment but since we don’t know about the
fragmentation offset, we cannot say about the fragmented packet is the
first, last or middle.
Network Layer
Chapter 4

MF Fragment Offset Description

0 0 Invalid

0 !0 Last packet

1 0 First packet

1 !0 Intermediate packet

Ǫuestion

Sol:

Fragmentation:
When the datagram is divided inorder to pass through other networks, this
is called fragmentation.
Let us see the below scenario,
Network Layer

116
Chapter 4
How we can limit fragmentation at the sender side!!

When TL segments the data in such way, that size of data can easily be
taken by the network layer as well as in the data link layer.

Now, who will do fragmentation?

Sender and router, but keep in mind sender can limit the fragmentation by
proper implementation.

Note:
MTU (Maximum Transmission Unit) is the maximum length that
can be encapsulated in a frame.

Points for fragmentation:


It increases the datagram overhead because after fragmentation, IP header
needs to be attached at every packet.
1) Total overhead = (Total number of fragmented datagram -1 ) * size of IP
header.
2) Efficiency = Useful Bytes transferred / Total Byte transferred.
3) Bandwidth utilization or throughput = Efficiency * Bandwidth.
Understand Fragmentation using Example.

There are two networks, A and B. Network A has MTU 1020 Bytes and
Network B has MTU 500 Bytes.
Host P wants to send the message to Host Ǫ.
See the figure below,
Network Layer

Fig. 4.2 Diagrammatic Representation of the Process of Fragmentation

117
Chapter 4

Explanation how fragmentation will occur at router:

Step 1:
When Router receives the datagram packet having a Total size = 1020B, and
if the DF flag is 0, now it can do fragmentation.

Step 2:
It will check if the network B MTU can accommodate the packet or not!
If not, then it will start fragmentation according to the MTU size of network
B.

Step 3:
Here, MTU network B is 500 Bytes.
Out of 500 Bytes 20 Bytes will be the header, and 480 Bytes will be payload.
Maximum amount of data that can be sent at each fragment = 480.

Note:
Payload at each fragment must be multiple of 8 except the last fragment
i.e. last packet may or may not have a multiple of 8 data byte.

See diagram below,

Lets see the header information of Ist fragment.


Total length = 500
Fragment offset = 0
Header checksum will be calculated again.
MF bit = 1
Identification number = same to all fragments.

Information for IInd fragment.


Total length = 500
Network Layer

Fragment offset = 480/8 = 60

118
Chapter 4
Header checksum will be calculated again.
MF bit = 1

Identification number = same to all fragments.


Information for IIIrd fragment.
Total length = 500
Fragment offset = (480 + 480)/8 = 120
Header checksum will be calculated again.
MF bit = 0
Identification number = same to all fragments.

Receiver will take all the three segments and reassembly algorithms applied

119
Network Layer
Chapter 4

Router 2 will receive a datagram of 500B, but it can’t forward directly,


because MTU of next network Z is 200B.

Router 2 will perform fragmentation for the Ist datagram.

Router 2 will perform fragmentation for IInd datagram.

Router 2 will not perform any fragmentation for IIIrd datagram.

Note:
We have taken 176 byte in I.a,I.b, II.a and II.b because datagram
byte must be divisible by 8.

Reassembly algorithm:
Receiver applies the following steps:
I) Identifies whether datagram fragmented or not using MF bits and
fragments offset bits.
Network Layer

II) Using Identification fields, it identifies all the fragments belonging to


the same packet or not.

120
Chapter 4
III) Fragment with offset field 0 is first fragment.
IV) identifies subsequent fragments using total length, header length and
fragment offset.
V) Repeats step IV until MF = 0

IPv6 header:

Fig. 4.3 IPV4 Header

Version: It will tell version of IP i.e 0110

Traffic class: It has 8 bits.


 The Most Significant 6 bits are used for Type of Service.
 The Last 2 bits are used for Explicit Congestion Notification.

Flow label: It has 20 bits.


 It is used for sequential flow of packet.
 It will help to avoid in re-ordering of packet.
 It is used for real time service.

Payload length: It has 16 bits.


 It tells how much information is present in the payload.

Next header: It has 8 bits.


 It is used for extension Header, if Extension Header is not present than
it will inform Upper layer PDU.

Hop limit: It has 8 bits.


 It stop packets Loop to infinity.
 The value of Hop limit field decreases every time it crosses router.

Source address: It has 128 Bits.


 It indicates the address of originator.
Network Layer

Destination address: It has 128 bits.


 It indicates the address of indented destination.
Chapter 4

Ǫ7

Sol: Since the option is not given header length is 20 bytes,


Total length field is Header length + Data bytes
512 + 20 = 532 bytes

Ǫ8

In binary 1100

Ǫ9

Sol:

Ǫ10

Sol: Since MTU is 1500 Byte it will be,


Network Layer

After fragmentation packet will look like see below.

122
Chapter 4
Let’s see 1st fragment:
 Length field has 1500 bytes which include 20 bytes of header and 1480
bytes of payload.
 MF field is 1 because more fragments are followed.
 Identification number will be the same for all the fragments.
 Offset field store scaled value, here it is 0 as before this fragment no
data bytes are there.

Let’s see 2nd fragment:


 Length field has 1500 bytes which include 20 bytes of header and 1480
bytes of payload.
 MF field is 1 because more fragments are followed.
 Identification number will be the same for all the fragments.
 Offset field store scaled value, here it is 185 as before this fragment
fragment 1 is present which is having 1480 byte of data, scaled value of
1480/8 = 185.

Let’s see 3rd fragment:


 Length field has 1500 bytes which include 20 bytes of header and 1480
bytes of payload.
 MF field is 1 because more fragments are followed.
 Identification number will be the same for all the fragments.
 Offset field store scaled value, here it is 370 as before this fragment
1 and fragment 2 is present which is having 1480 + 1480 byte of data,
scaled value of 1480 *2/8 = 370.

Let’s see 4th fragment:


 Length field has 1500 bytes which include 20 bytes of header and 1480
bytes of payload.
 MF field is 1 because more fragments are followed.
 Identification number will be the same for all the fragments.
 Offset field store scaled value, here it is 555 as before this fragment
fragment 1, fragment 2 and fragment 3 is present which is having 1480
+ 1480 + 1480 byte of data, scaled value of 1480 *3/8 = 555.

Let’s see 5th fragment:


 Length field has 1080 bytes which include 20 bytes of header and 1060
bytes of payload, Why 1040? 7000 - 4 * 1480.
 MF field is 0 because no more fragments are followed.
Network Layer

123
Chapter 4

 Identification number will be the same for all the fragments.


 Offset field store scaled value, here it is 740 as before this fragment
fragment 1, fragment 2, fragment 3 and fragment 4 is present which
is having 1480 + 1480 + 1480 + 1480 byte of data, the scaled value of
1480 *4/8 = 740.

Previous Years’ Ǫuestion

1500 bytes (i.e. MTU = 1500 bytes). Size of the UDP header is 8 bytes,

a) 6 and 925 b) 6 and 7400


c) 7 and 1110 d) 7 and 8880
Sol: c) (GATE - 2015)
Network Layer

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy