CN4 NOTES Converted 796c356e 4937 4d06 Ba7e C8c2a69b7aec
CN4 NOTES Converted 796c356e 4937 4d06 Ba7e C8c2a69b7aec
Ch -4
Network Layer
o The Network Layer is the third layer of the OSI model.
o It handles the service requests from the transport layer and further
forwards the service request to the data link layer.
o The network layer translates the logical addresses into physical addresses
o It determines the route from the source to the destination and also
manages the traffic problems such as switching, routing and controls the
congestion of data packets.
o The main role of the network layer is to move the packets from sending
host to the receiving host.
The main functions performed by the network layer are:
o Routing: When a packet reaches the router's input link, the router will
move the packets to the router's output link. For example, a packet from
S1 to R1 must be forwarded to the next router on the path to S2.
o Logical Addressing: The data link layer implements the physical
addressing and network layer implements the logical addressing. Logical
addressing is also used to distinguish between source and destination
system. The network layer adds a header to the packet which includes the
logical addresses of both the sender and the receiver.
o Internetworking: This is the main role of the network layer that it
provides the logical connection between different types of networks.
o Fragmentation: The fragmentation is a process of breaking the packets
into the smallest individual data units that travel through different
networks
In this Routing, routing takes place In this Routing, routing takes place
within an autonomous network. between the autonomous networks.
• Routing tables are prepared total (n-1) times if there are n routers in the
given network.
• This is because shortest path between any 2 nodes contains at most n-1
edges if there are n nodes in the graph.
Step-01:
Each router prepares its routing table. By their local knowledge. each router
knows about-
• All the routers present in the network
• Distance to its neighboring routers
Step-02:
Each router exchanges its distance vector with its neighboring routers.
• Each router prepares a new routing table using the distance vectors it
has obtained from its neighbors.
• This step is repeated for (n-2) times if there are n routers in the network.
• After this, routing tables converge / become stable.
Step-01:
Each router prepares its routing table using its local knowledge.
Routing table prepared by each router is shown below-
At Router A-
Destination Distance Next Hop
A 0 A
B 2 B
C ∞ –
D 1 D
At Router B-
Destination Distance Next Hop
A 2 A
B 0 B
C 3 C
D 7 D
At Router C-
Destination Distance Next Hop
A ∞ –
B 3 B
C 0 C
D 11 D
At Router D-
A 1 A
B 7 B
C 11 C
D 0 D
Step-02:
• Each router exchanges its distance vector obtained in Step-01 with its
neighbors.
• After exchanging the distance vectors, each router prepares a new
routing table.
At Router A-
• Router A receives distance vectors from its neighbors B and D.
• Router A prepares a new routing table as-
• Router A can reach the destination router B via its neighbor B or neighbor D.
• It chooses the path which gives the minimum cost.
• Cost of reaching router B from router A via neighbor B = Cost (A→B) + Cost
(B→B)= 2 + 0 = 2
• Cost of reaching router B from router A via neighbor D = Cost (A→D) + Cost
(D→B) = 1 + 7 = 8
• Since the cost is minimum via neighbor B, so router A chooses the path via B.
• It creates an entry (2, B) for destination B in its new routing table.
• Similarly, we calculate the shortest path distance to each destination router at
every router.
A 0 A
B 2 B
C 5 B
D 1 D
At Router B-
A 2 A
B 0 B
C 3 C
D 3 A
At Router C-
• Router C receives distance vectors from its neighbors B and D.
• Router C prepares a new routing table as-
A 5 B
B 3 B
C 0 C
D 10 B
At Router D-
A 1 A
B 3 A
C 10 B
D 0 D
Step-03:
• Each router exchanges its distance vector obtained in Step-02 with its
neighboring routers.
• After exchanging the distance vectors, each router prepares a new
routing table.
At Router A-
A 0 A
B 2 B
C 5 B
D 1 D
At Router B-
A 2 A
B 0 B
C 3 C
D 3 A
At Router C-
A 5 B
B 3 B
C 0 C
D 6 B
At Router D-
A 1 A
B 3 A
C 6 A
D 0 D
If the link between B and C is disconnected, then B will know that it can no
longer get to C via that link and will remove it from its table. Before it can send
any updates it’s possible that it will receive an update from A which will be
advertising that it can get to C at a cost of 2. B can get to A at a cost of 1, so it
will update a route to C via A at a cost of 3. A will then receive updates from B
later and update its cost to 4. They will then go on feeding each other bad
information toward infinity which is called as Count to Infinity problem.
RIP Protocol
RIP stands for Routing Information Protocol. RIP is an intra-domain routing
protocol used within an autonomous system. Here, intra-domain means routing
the packets in a defined domain, for example, web browsing within an
institutional area. To understand the RIP protocol, our main focus is to know the
structure of the packet, how many fields it contains, and how these fields
determine the routing table.
o RIP is based on the distance vector-based strategy, so we consider the
entire structure as a graph where nodes are the routers, and the links are
the networks.
o In a routing table, the first column is the destination, or we can say that it
is a network address.
o The cost metric is the number of hops to reach the destination. The
number of hops available in a network would be the cost. The hop count
is the number of networks required to reach the destination.
o In RIP, infinity is defined as 16, which means that the RIP is useful for
smaller networks or small autonomous systems. The maximum number
of hops that RIP can contain is 15 hops, i.e., it should not have more than
15 hops as 16 is infinity.
o The next column contains the address of the router to which the packet
is to be sent to reach the destination.
Features of RIP :
1. Updates of the network are exchanged periodically.
2. Updates (routing information) are always broadcast.
3. Full routing tables are sent in updates.
4. Routers always trust routing information received from neighbor
routers. This is also known as Routing on rumours.
How is hop count determined?
Hop count:-
Hop count is the number of routers occurring in between the source and
destination network. The path with the lowest hop count is considered as the
best route to reach a network and therefore placed in the routing table.
When the router sends the packet to the network segment, then it is counted
as a single hop.
In the above figure, when the router 1 forwards the packet to the router 2 then
it will count as 1 hop count. Similarly, when the router 2 forwards the packet to
the router 3 then it will count as 2 hop count, and when the router 3 forwards
the packet to router 4, it will count as 3 hop count. In the same way, RIP
can support maximum upto 15 hops, which means that the 16 routers can be
configured in a RIP.
10.3M
172Triggers in SQL (Hindi)
RIP Message Format
Now, we look at the structure of the RIP message format. The message format
is used to share information among different routers. The RIP contains the
following fields in a message:
o Command: It is an 8-bit field that is used for request or reply. The value of
the request is 1, and the value of the reply is 2.
o Version: Here, version means that which version of the protocol we are
using. Suppose we are using the protocol of version1, then we put the 1
in this field.
o Reserved: This is a reserved field, so it is filled with zeroes.
o Family: It is a 16-bit field. As we are using the TCP/IP family, so we put 2
value in this field.
o Network Address: It is defined as 14 bytes field. If we use the IPv4 version,
then we use 4 bytes, and the other 10 bytes are all zeroes.
o Distance: The distance field specifies the hop count, i.e., the number of
hops used to reach the destination.
How does the RIP work?
If there are 8 routers in a network where Router 1 wants to send the data to
Router 3. If the network is configured with RIP, it will choose the route which
has the least number of hops. There are three routes in the above network, i.e.,
Route 1, Route 2, and Route 3. The Route 2 contains the least number of hops,
i.e., 2 where Route 1 contains 3 hops, and Route 3 contains 4 hops, so RIP will
choose Route 2.
Let's look at another example.
Suppose R1 wants to send the data to R4. There are two possible routes to send
data from r1 to r2. As both the routes contain the same number of hops, i.e., 3,
so RIP will send the data to both the routes simultaneously. This way, it manages
the load balancing, and data reach the destination a bit faster.
Disadvantages of RIP
• It is only based on hop count. So, if there is a better route available
with better bandwidth then it will not select that route.
Example: Suppose we have two routes, the first route has a bandwidth
of 100 Kbps(Kilobits per second) and is there is high traffic in this route
whereas the second route has a bandwidth of 100 Mbps (Megabits per
second) and is free. Now the RIP will select route 1 though it has high traffic
its bandwidth is much less than the bandwidth of route 2. This is one of the
biggest disadvantages of RIP.
Multicast at FF02::9
(RIPng can only run
Broadcast at on IPv6 networks)
255.255.255.255 Multicast at 224.0.0.9
Classless
protocolupdated Classless updates are
Classful routing protocol supports classful sent
Dijkstra's algorithm:
Each node uses Dijkstra's algorithm on the graph to calculate the optimal routes
to all nodes.
o The Link state routing algorithm is also known as Dijkstra's algorithm
which is used to find the shortest path from one node to every other node
in the network.
o The Dijkstra's algorithm is an iterative, and it has the property that after
kth iteration of the algorithm, the least cost paths are well known for k
destination nodes.
o Algorithm
1) Create a set sptSet (shortest path tree set) that keeps track of
vertices included in the shortest-path tree, i.e., whose minimum
distance from the source is calculated and finalized. Initially, this set is
empty.
2) Assign a distance value to all vertices in the input graph. Initialize all
distance values as INFINITE. Assign distance value as 0 for the source
vertex so that it is picked first.
3) While sptSet doesn’t include all vertices
….a) Pick a vertex u which is not there in sptSet and has a minimum
distance value.
….b) Include u to sptSet.
….c) Update distance value of all adjacent vertices of u. To update the
distance values, iterate through all adjacent vertices. For every
adjacent vertex v, if the sum of distance value of u (from source) and
weight of edge u-v, is less than the distance value of v, then update the
distance value of v.
example:
o The set sptSet is initially empty and distances assigned to vertices are
{0, INF, INF, INF, INF, INF, INF, INF} where INF indicates infinite. Now
pick the vertex with a minimum distance value. The vertex 0 is picked,
include it in sptSet. So sptSet becomes {0}. After including 0 to sptSet,
update distance values of its adjacent vertices. Adjacent vertices of 0
are 1 and 7. The distance values of 1 and 7 are updated as 4 and 8. The
following subgraph shows vertices and their distance values, only the
vertices with finite distance values are shown. The vertices included in
SPT are shown in green colour.
o
o Pick the vertex with minimum distance value and not already included
in SPT (not in sptSET). The vertex 1 is picked and added to sptSet. So
sptSet now becomes {0, 1}. Update the distance values of adjacent
vertices of 1. The distance value of vertex 2 becomes 12.
o
o Pick the vertex with minimum distance value and not already included
in SPT (not in sptSET). Vertex 7 is picked. So sptSet now becomes {0, 1,
7}. Update the distance values of adjacent vertices of 7. The distance
value of vertex 6 and 8 becomes finite (15 and 9 respectively).
o Pick the vertex with minimum distance value and not already included
in SPT (not in sptSET). Vertex 6 is picked. So sptSet now becomes {0, 1,
7, 6}. Update the distance values of adjacent vertices of 6. The distance
value of vertex 5 and 8 are updated.
o We repeat the above steps until sptSet includes all vertices of the given
graph. Finally, we get the following Shortest Path Tree (SPT).
Dijkstra doesn’t work for Graphs with negative weight cycle, Bellman-Ford
works for such graphs. Bellman-Ford is also simpler than Dijkstra and suites
well for distributed systems. But time complexity of Bellman-Ford is O(VE),
which is more than Dijkstra.
Example
Let us understand the algorithm with following example graph. The images
are taken from this source.
Let the given source vertex be 0. Initialize all distances as infinite, except the
distance to the source itself. Total number of vertices in the graph is 5, so all
edges must be processed 4 times.
Let all edges are processed in the following order: (B, E), (D, B), (B, D), (A, B),
(A, C), (D, C), (B, C), (E, D). We get the following distances when all edges are
processed the first time. The first row shows initial distances. The second row
shows distances when edges (B, E), (D, B), (B, D) and (A, B) are processed. The
third row shows distances when (A, C) is processed. The fourth row shows
when (D, C), (B, C) and (E, D) are processed.
The first iteration guarantees to give all shortest paths which are at most 1
edge long. We get the following distances when all edges are processed
second time (The last row shows final values).
The second iteration guarantees to give all shortest paths which are at most 2
edges long. The algorithm processes all edges 2 more times. The distances are
minimized after the second iteration, so third and fourth iterations don’t
update the distances.
OSPF Protocol
The OSPF stands for Open Shortest Path First. It is a widely used and supported
routing protocol. It is an intradomain protocol, which means that it is used
within an area or a network. It is an interior gateway protocol that has been
designed within a single autonomous system. It is based on a link-state routing
algorithm in which each router contains the information of every domain, and
based on this information, it determines the shortest path. The goal of routing
is to learn routes. The OSPF achieves by learning about every router and subnet
within the entire network. Every router contains the same information about
the network. The way the router learns this information by sending LSA (Link
State Advertisements). These LSAs contain information about every router,
subnet, and other networking information. Once the LSAs have been flooded,
the OSPF stores the information in a link-state database known as LSDB. The
main goal is to have the same information about every router in an LSDBs.
OSPF Areas
How does
OSPF work?
There are three steps that can explain the working of OSPF:
Step 1: The first step is to become OSPF neighbors. The two connecting routers
running OSPF on the same link creates a neighbor relationship.
Step 2: The second step is to exchange database information. After becoming
the neighbors, the two routers exchange the LSDB information with each other.
Step 3: The third step is to choose the best route. Once the LSDB information
has been exchanged with each other, the router chooses the best route to be
added to a routing table based on the calculation of SPF.
OSPF Message Format
The following are the fields in an OSPF message format:
It is a Distance Vector
protocol and it uses the It is a link state protocol and it
distance or hops count to analyzes different sources like the
determine the transmission speed, cost and path congestion
path. while identifying the shortest path.
Classful Addressing
The 32 bit IP address is divided into five sub-classes. These are:
• Class A
• Class B
• Class C
• Class D
• Class E
Each of these classes has a valid range of IP addresses. Classes D and E are
reserved for multicast and experimental purposes respectively. The order of
bits in the first octet determine the classes of IP address.
IPv4 address is divided into two parts:
• Network ID
• Host ID
The class of IP address is used to determine the bits used for network ID and
host ID and the number of total networks and hosts possible in that particular
class. Each ISP or network administrator assigns IP address to each device that
is connected to its network.
Note: IP addresses are globally managed by Internet Assigned Numbers
Authority(IANA) and regional Internet registries(RIR).
Note: While finding the total number of host IP addresses, 2 IP addresses are
not counted and are therefore, decreased from the total count because the
first IP address of any network is the network number and whereas the last IP
address is reserved for broadcast IP.
Class A:
IP address belonging to class A are assigned to the networks that contain a
large number of hosts.
• The network ID is 8 bits long.
• The host ID is 24 bits long.
The higher order bit of the first octet in class A is always set to 0. The
remaining 7 bits in first octet are used to determine network ID. The 24 bits of
host ID are used to determine the host in any network. The default subnet
mask for class A is 255.x.x.x. Therefore, class A has a total of:
• 2^7-2= 126 network ID(Here 2 address is subtracted because 0.0.0.0
and 127.x.y.z are special address. )
• 2^24 – 2 = 16,777,214 host ID
IP addresses belonging to class A ranges from 1.x.x.x – 126.x.x.x
Class B:
IP address belonging to class B are assigned to the networks that ranges from
medium-sized to large-sized networks.
• The network ID is 16 bits long.
• The host ID is 16 bits long.
The higher order bits of the first octet of IP addresses of class B are always set
to 10. The remaining 14 bits are used to determine network ID. The 16 bits of
host ID is used to determine the host in any network. The default sub-net mask
for class B is 255.255.x.x. Class B has a total of:
• 2^14 = 16384 network address
• 2^16 – 2 = 65534 host address
IP addresses belonging to class B ranges from 128.0.x.x – 191.255.x.x.
Class C:
IP address belonging to class C are assigned to small-sized networks.
• The network ID is 24 bits long.
• The host ID is 8 bits long.
The higher order bits of the first octet of IP addresses of class C are always set
to 110. The remaining 21 bits are used to determine network ID. The 8 bits of
host ID is used to determine the host in any network. The default sub-net mask
for class C is 255.255.255.x. Class C has a total of:
• 2^21 = 2097152 network address
• 2^8 – 2 = 254 host address
IP addresses belonging to class C ranges from 192.0.0.x – 223.255.255.x.
Class D:
IP address belonging to class D are reserved for multi-casting. The higher order
bits of the first octet of IP addresses belonging to class D are always set to
1110. The remaining bits are for the address that interested hosts recognize.
Class D does not posses any sub-net mask. IP addresses belonging to class D
ranges from 224.0.0.0 – 239.255.255.255.
Class E:
IP addresses belonging to class E are reserved for experimental and research
purposes. IP addresses of class E ranges from 240.0.0.0 – 255.255.255.254. This
class doesn’t have any sub-net mask. The higher order bits of first octet of class
E are always set to 1111.
1. Version-
3. Type Of Service-
• Type of service is a 8 bit field that is used for Quality of Service (QoS).
• The datagram is marked for giving a certain treatment using this field.
4. Total Length-
• Total length is a 16 bit field that contains the total length of the
datagram (in bytes).
• Total length = Header length + Payload length
5. Identification-
• Identification is a 16 bit field.
• It is used for the identification of the fragments of an original IP
datagram.
6. DF Bit-
• DF bit stands for Do Not Fragment bit.
• Its value may be 0 or 1.
7. MF Bit-
• MF bit stands for More Fragments bit.
• Its value may be 0 or 1.
• If is 0 It indicates to the receiver that the current datagram is either the
last fragment in the set or that it is the only fragment
• If is 1 It indicates to the receiver that the current datagram is a fragment
of some larger datagram.
8. Fragment Offset-
• Fragment Offset is a 13 bit field.
• It indicates the position of a fragmented datagram in the original
unfragmented IP datagram.
• The first fragmented datagram has a fragment offset of zero.
9. Time To Live-
• Time to live (TTL) is a 8 bit field.
• It indicates the maximum number of hops a datagram can take to reach
the destination.
• The main purpose of TTL is to prevent the IP datagrams from looping
around forever in a routing loop.
.
10. Protocol-
• Protocol is a 8 bit field.
• It tells the network layer at the destination host to which protocol the IP
datagram belongs to.
• In other words, it tells the next level protocol to the network layer at the
destination side.
• Protocol number of ICMP is 1, IGMP is 2, TCP is 6 and UDP is 17.
14. Options-
• Options is a field whose size vary from 0 bytes to 40 bytes.
• This field is used for several purposes such as-
1. Record route
2. Source routing
3. Padding
1. Record Route-
• A record route option is used to record the IP Address of the routers
through which the datagram passes on its way.
• When record route option is set in the options field, IP Address of the
router gets recorded in the Options field.
2. Source Routing-
• A source routing option is used to specify the route that the datagram
must take to reach the destination.
• This option is generally used to check whether a certain path is working
fine or not.
• Source routing may be loose or strict.
3. Padding-
• Addition of dummy data to fill up unused space in the transmission unit
and make it conform to the standard size is called as padding.
• Options field is used for padding.
Subnetting
Subnetting is the practice of dividing a network into two or smaller networks.
It increases routing efficiency, which helps to enhance the security of the
network and reduces the size of the broadcast domain.
IP Subnetting designates high-order bits from the host as part of the network
prefix. This method divides a network into smaller subnets.
It also helps you to reduce the size of the routing tables, which is stored in
routers. This method also helps you to extend the existing IP address base &
restructures the IP address.
To access the Internet, one public IP address is needed, but we can use a private
IP address in our private network. The idea of NAT is to allow multiple devices
to access the Internet through a single public address. To achieve this, the
translation of a private IP address to a public IP address is required. Network
Address Translation (NAT) is a process in which one or more local IP address is
translated into one or more Global IP address and vice versa in order to provide
Internet access to the local hosts. Also, it does the translation of port numbers
i.e. masks the port number of the host with another port number, in the packet
that will be routed to the destination. It then makes the corresponding entries
of IP address and port number in the NAT table. NAT generally operates on a
router or firewall.
If NAT runs out of addresses, i.e., no address is left in the pool configured
then the packets will be dropped and an Internet Control Message Protocol
(ICMP) host unreachable packet to the destination is sent.
• Outside global address – This is the outside host as seen from the
outside network. It is the IP address of the outside destination host
before translation.
Advantages of NAT –
Disadvantage of NAT –
2. Multicast Address –
Multicast Address is used by multiple hosts, called as Group, acquires a
multicast destination address. These hosts need not be geographically
together. If any packet is sent to this multicast address, it will be distributed
to all interfaces corresponding to that multicast address.
3. Anycast Address –
Anycast Address is assigned to a group of interfaces. Any packet sent to an
anycast address will be delivered to only one member interface (mostly
nearest host possible).
Note: In IPv6, all 0’s and all 1’s can be assigned to any host, there is not any
restriction like IPv4.
Global routing prefix: Global routing prefix contains all the details of Latitude
and Longitude. As of now, it is not being used. In Geography-based Unicast
address routing will be based on location.
Interface Id: In IPv6, instead of using Host Id, we use the term Interface Id.
Some special addresses:
Unspecified –
IP version 6 is the new version of Internet Protocol, which is way better than
IP version 4 in terms of complexity and efficiency. Let’s look at the header of
IP version 6 and understand how it is different from the IPv4 header.
Version (4-bits): Indicates version of Internet Protocol which contains bit
sequence 0110.
Traffic Class (8-bits): The Traffic Class field indicates class or priority of IPv6
packet which is similar to Service Field in IPv4 packet. It helps routers to
handle the traffic based on the priority of the packet. If congestion occurs on
the router then packets with the least priority will be discarded.
As of now, only 4-bits are being used (and the remaining bits are under
research), in which 0 to 7 are assigned to Congestion controlled traffic and 8
to 15 are assigned to Uncontrolled traffic.
Flow Label (20-bits): Flow Label field is used by a source to label the packets
belonging to the same flow in order to request special handling by
intermediate IPv6 routers, such as non-default quality of service or real-time
service. In order to distinguish the flow, an intermediate router can use the
source address, a destination address, and flow label of the packets. Between
a source and destination, multiple flows may exist because many processes
might be running at the same time. Routers or Host that does not support the
functionality of flow label field and for default router handling, flow label
field is set to 0. While setting up the flow label, the source is also supposed to
specify the lifetime of the flow.
Next Header (8-bits): Next Header indicates the type of extension header(if
present) immediately following the IPv6 header. Whereas In some cases it
indicates the protocols contained within upper-layer packets, such as TCP,
UDP.
Hop Limit (8-bits): Hop Limit field is the same as TTL in IPv4 packets. It
indicates the maximum number of intermediate nodes IPv6 packet is allowed
to travel. Its value gets decremented by one, by each node that forwards the
packet and the packet is discarded if the value decrements to 0. This is used
to discard the packets that are stuck in an infinite loop because of some
routing error.
Source Address (128-bits): Source Address is the 128-bit IPv6 address of the
original source of the packet.
Extension Headers: In order to rectify the limitations of the IPv4 Option Field,
Extension Headers are introduced in IP version 6. The extension header
mechanism is a very important part of the IPv6 architecture. The next Header
field of IPv6 fixed header points to the first Extension Header and this first
extension header points to the second extension header and so on.
IPv4 IPv6
IPv4 has a 32-bit address length IPv6 has a 128-bit address length