CN MODULE 2 Network Layer
CN MODULE 2 Network Layer
NETWORK LAYER
Main features include:
Concerned with getting packets from the source all the way to the destination. Getting to
the destination require many hops at intermediate routers along the way.
Routing
Metric used is hop
o Represents number of routers used
Choose best path to route packet from source to destination.
Choose alternate route to avoid overloading.
A host with a packet to send transmits it to the nearest router, either on its own LAN or over a
point-to-point link to the carrier. The packet is stored there until it has fully arrived so the
checksum can be verified. Then it is forwarded to the next router along the path until it reaches
the destination host, where it is delivered.
2. Services Provided to the Transport Layer
The network layer provides services to the transport layer at the network layer/transport
layer interface.
The network layer services have been designed with the following goals:
2. The transport layer should be shielded from the number, type, and topology of the
routers present.
3. The network addresses made available to the transport layer should use a uniform
numbering plan, even across LANs and WANs.
1. Before sending data, a n/w layer process on the sending side must set up a connection to
its peer on the receiving side .This connection which is given a special identifier is then
used until all the data have been sent at which time it is explicitly released.
2. When a connection is set up, the two processes can enter into a negotiation about the
parameters: quality and cost of the service to be provided.
3. Communication is in both directions and packets are delivered in sequence.
4. Flow control is provided automatically to prevent a fast sender from dumping packets
into the pipe at a higher rate than the receiver can take them out, thus leading to overflow.
If connection-oriented service is used, a path from the source router to the destination
router must be established before any data packets can be sent. This connection is called a
VC (virtual circuit) and the subnet is called VC subnet.
when a connection is established, a route from the source machine to the destination
machine is chosen as part of the connection setup and stored in tables inside the routers.
The route is used for all traffic flowing over the connection, exactly the same way that
the telephone system works.
When the connection is released, the virtual circuit is also terminated.
Every router must maintains a table with one entry per open virtual circuit passing
through it.
Each packet travelling through the subnet must contain a virtual circuit number field in
its header, in addition to sequence numbers, checksums.
When a packet arrives at router, the router knows on which line it arrived and what the
virtual circuit number is.
Based on the information, the packet must be forwarded on the correct o/p line.
Example
H1 has established connection 1 with host H2. It is remembered as the first entry in each of
the routing tables. The first line of A's table says that if a packet bearing connection identifier
1 comes in from H1, it is to be sent to router C and given connection identifier 1. Similarly,
the first entry at C routes the packet to E, also with connection identifier 1. if H3 also wants
to establish a connection to H2. It chooses connection identifier 1 (because it is initiating the
connection and this is its only connection) and tells the subnet to establish the virtual circuit.
This leads to the second row in the tables.
4. Implementation of Connectionless Service
If connectionless service is offered, packets are injected into the subnet individually
and routed independently of each other. No advance setup is needed.
In connectionless service, the packets are called datagrams and the subnet is called a
datagram subnet.
Each packet sent is routed independently of its predecessor.Successive packets may
follow different routes.
They are generally more robust and adapt to failures and congestion more easily than
virtual circuit subnets.
Here routers do not have a table with one entry for each open virtual circuit
o Instead they have a table telling which outgoing line to use for each possible
destination router.
o When a packet comes in, the router look up the outgoing line to use and sends the
packet on its way.
Each datagram must contain the full destination address.
Example
Suppose that the process P1 has a long message for P2. It hands the message to the transport
layer with instructions to deliver it to process P2 on host H2. The transport layer code runs on
H1, typically within the operating system. It prepends a transport header to the front of the
message and hands the result to the network layer.
COMPARISON OF VIRTUAL-CIRCUIT AND DATAGRAM SUBNETS
[Previously asked university essay question]
ROUTING ALGORITHMS [Previously asked University Question]
The main function of the network layer is routing packets from the source machine to the
destination machine.
The routing algorithm is a part of the network layer software responsible for deciding
which output line an incoming packet should be transmitted on.
o If the subnet uses datagrams internally, this decision must be made anew for every
arriving data packet since the best route may have changed since last time.
o If the subnet uses virtual circuits internally, routing decisions are made only when
a new virtual circuit is being set up. Thereafter, data packets just follow the
previously-established route. This is called session routing because a route
remains in force for an entire user session (e.g., a login session at a terminal or a
file transfer).
Routing, which is making the decision which routes to use, and forwarding, which is
what happens when a packet arrives.
Suppose that there is enough traffic between A and A', between B and B', and between C and
C' to saturate the horizontal links. To maximize the total flow, the X to X' traffic should be
shut off altogether.
Many networks attempt to minimize the number of hops a packet must make, because
reducing the number of hops tends to improve the delay and also reduce the amount of
bandwidth consumed, which tends to improve the throughput as well.
[Difference b/w adaptive and non adaptive Previously asked University Question -4 Marks]
The set of optimal routes from all sources to a given destination form a tree rooted at the
destination. Such a tree is called a sink tree, where the distance metric is the number of hops.The
goal of all routing algorithms is to discover and use the sink trees for all routers.
The algorithm used for computing the shortest path between two nodes of a graph is known as
Dijkstra’s Algorithm.
Dijkstra’s Algorithm
Each node is labeled (in parentheses) with its distance from the source node along the
best known path.
Initially, no paths are known, so all nodes are labeled with infinity.
As the algorithm proceeds and paths are found, the labels may change, reflecting better
paths.
A label may be either tentative or permanent.
Initially, all labels are tentative.
When it is discovered that a label represents the shortest possible path from the source to
that node, it is made permanent and never changed thereafter.
Example
To find the shortest path from A to D and the Metric used is distance
Step 2: Examine each of the nodes adjacent to A (the working node), relabeling each one with the
distance to A.
Whenever a node is relabeled, also label it with the node from which the probe
was made.
After examining each of the nodes adjacent to A, Examine all the tentatively
labeled nodes in the whole graph and make the one with the smallest label
permanent. This one becomes the new working node.
If the sum of the label on B and the distance from B to the node being considered is
less than the label on that node, we have a shorter path, so the node is relabeled.
Step 4: After all the nodes adjacent to the working node have been inspected and the tentative
labels changed if possible, the entire graph is searched for the tentatively-labeled node
with the smallest value. This node is made permanent and becomes the working node for
the next round.
B C D E F G H
A 2 6
AB AG
(shortest)
B 9 4 6
ABC ABE AG
(shortest)
E 9 6 6
ABC ABEF AG
(Removed)
5
ABEG
(shortest)
G 9 6 9
ABC ABEF ABEGH
(shortest)
F 9 9
ABC ABEGH
(Removed)
9 8
ABEFC ABEFH
(Removed) (shortest)
H 9 10
ABC ABEFHD
(shortest)
C 10
ABEFHD
(shortest)
12
ABCD
D 10
ABEFHD
(shortest)
Final
Destination
Step1: At A
AB= 2
AG= 6
Shortest path AB= 2
Step 2: At B
ABC = 2 +7= 9
ABE = 2 +2= 4
AG= 6
Shortest path ABE = 4
Step 3: At E
ABEG = 5
ABEF=6
ABC=9
AG=6 //CANCELLED(To G shortest is obtained)
Shortest Path ABEG =5
Step 4: At G
ABEGH = 9
ABEF = 6
ABC = 9
Shortest Path ABEF = 6
Step 5: At F
Step 6: At H
ABEFHD =10
ABC= 9
Step 7: At C
ABEFHD=10
ABCD=12
Hence the shortest path will be through ABEFHD with distance 10 via H.
static algorithm
every incoming packet is sent out on every outgoing line except the one it arrived on
creates duplicate packets
in order to avoid duplication two methods are available:
o hop counter contained in the header of each packet, which is decremented at each
hop, with the packet being discarded when the counter reaches zero.
The hop counter should be initialized to the length of the path from source
to destination.
o keep track of which packets have been flooded, to avoid sending them out a
second time.
To achieve this goal is to have the source router put a sequence number in
each packet it receives from its hosts.
Each router then needs a list per source router telling which sequence
numbers originating at that source have already been seen.
If an incoming packet is on the list, it is not flooded.
Selective Flooding
o In this algorithm the routers do not send every incoming packet out on every line,
only on those lines that are going approximately in the right direction.
Applications
o distributed database applications,
to update all the databases concurrently
o wireless networks,
all messages transmitted by a station can be received by all other stations
within its radio range
o metric against which other routing algorithms can be compared.
Router must first add one hop to the hop count field for each advertised route.The router
should then apply the following rules to each advertised route:
1. If the advertised destination is not in the routing table,the router should add the
advertised information to the table
2. If the advertised destination is in the routing table
a. If the next hop field is same ,the router should replace the entry in the
table with the advertised one. Note that even If the advertised hop count is
larger,advertised entry should replace the entry in the table the new
information invalidates old.
b. If the next hop field is not same
i. If the advertised hop count is smaller than the one in the routing
table,the router should replace the entry in the table with the new
one.
ii. If the advertised hop count is not smaller(same or larger)the router
should do nothing.
Example
Assume that delay is used as a metric and that the router knows the delay to each of its
neighbors. Once every T msec each router sends to each neighbor a list of its estimated delays to
each destination.
Consider that CD line goes down.Using split horizon both A and B tell C that they can’t
get to D. Thus C immediately concludes that D is unreachable and reports this to both a
and B.Unfortunately A hears that B has a path of length 2 to d, so it assumes it can get to
D via B in 3 hops.Similarly, B concludes it can get to D via A in 3 hops.On the next
exchange they each set their distance to D to 4.Both of them gradually count to infinity.
When a link state packet comes in to a router for flooding, it is not queued for transmission
immediately. Instead it is first put in a holding area to wait a short while. If another link state
packet from the same source comes in before the first packet is transmitted, their sequence
numbers are compared. If they are equal, the duplicate is discarded. If they are different, the
older one is thrown out. To guard against errors on the router-router lines, all link state packets
are acknowledged. When a line goes idle, the holding area is scanned in round-robin order to
select a packet or acknowledgement to send.
The data structure used by router B for the subnet.
Distributes a picture of the router topology, from which the shortest paths are computed.
Each router announces, in its link state information, which network layer addresses it can
reach directly.
These addresses can be IP, IPX, AppleTalk, or any other addresses.
IS-IS can even support multiple network layer protocols at the same time.
2. The mobile host registers with the foreign agent, giving its home address, current data link
layer address, and some security information.
3. The foreign agent contacts the mobile host's home agent and says: One of your hosts is
over here. The message from the foreign agent to the home agent contains the foreign
agent's network address. It also includes the security information to convince the home
agent that the mobile host is really there.
4. The home agent examines the security information, which contains a timestamp, to prove
that it was generated within the past few seconds. If it is happy, it tells the foreign agent
to proceed.
5. When the foreign agent gets the acknowledgement from the home agent, it makes an entry
in its tables and informs the mobile host that it is now registered.
Routing procedure
Step 1:When a packet is sent to a mobile host, it is routed to the host's home LAN
Step 2:This packet is received by the home agent and looks up the mobile host's new (temporary)
location and finds the address of the foreign agent handling the mobile host
A multiaccess network is one that can have multiple routers on it, each of which can
directly communicate with all the others.
Requirements to be considered while designing OSPF:
o the algorithm has to be published in open literature,
o it has to support the variety of distance metrics,
o it has to be based on dynamic algorithm,
o it has to support routing based on types of services,
o it has to do load balancing, splitting the load over multiple lines,
o hierarchical routing
o security
OSPF represents the actual network as a graph and then compute the shortest path from
every router to every other router.
OSPF allows to divide ASes into numbered areas. Area is a network or a set of
contiguous networks.
Areas do not overlap but need not be exhaustive, i.e., some routers may belong to no
area. An area is a generalization of a subnet.
Every AS has a backbone area called area 0. All areas are connected to the backbone.
Each router that is connected to two or more areas is part of the backbone.
Within an area, each router has the same link state database and runs the same shortest
path algorithm.
OSPF handles different types of service routing in a different way.
During the normal operation, three kinds of routes may be needed:
o intra-area - here the source router already knows the shortest path to the
destination router,
o inter-area,
o inter AS.
Inter-area routing proceeds in three steps:
go from the source to the backbone,
go across the backbone to the destination area,
go to the destination.
OSPF distinguishes four classes of routers:
o internal routers are wholly within one area,
o area border routers connect two or more areas,
o backbone routers are on the backbone,
o AS boundary routers talk to routers in other ASes.
When a router boots, it sends HELLO messages on all of its point-to-point lines and
multicasts them on LANs to the group consisting of all other routers. From the responses,
each router learns who its neighbors are.
OSPF works by exchanging information between adjacent routers which is not the same
as between neighboring routers. On each LAN, one router is selected as designated
router. It is said to be adjacent to all other router and exchanges information with them. A
backup designated router is always kept up-to-date to easy transition should the primary
designated router crash.