Unit-3 CN
Unit-3 CN
ALGORITHMS
•The routing algorithm is that part of the network layer
software responsible for deciding which output line an
incoming packet should be transmitted on. If the
network uses datagrams internally, this decision must
be made anew for every arriving data packet since the
best route may have changed since last time.
•In most networks, packets will require multiple hops to
make the journey.
•The algorithms that choose the routes and the data
structures that they use are a major area of network
layer design.
• Routing algorithms can be grouped into two major classes:
• Nonadaptive and
• Adaptive.
• Nonadaptive algorithms do not base their routing decisions on any
measurements or estimates of the current topology and traffic.
Instead, the choice of the route to use to get from I to J (for all I and
J) is computed in advance, offline, and downloaded to the routers
when the network is booted. This procedure is sometimes called
static routing.
• Adaptive algorithms, in contrast, change their routing decisions to
reflect changes in the topology, and sometimes changes in the traffic
as well. These dynamic routing algorithms differ in where they get
their information (e.g., locally, from adjacent routers, or from all
routers), when they change the routes (e.g., when the topology
changes, or every ΔT seconds as the load changes), and what metric
is used for optimization (e.g., distance, number of hops, or estimated
transit time).
The Optimality Principle
• Before we get into specific algorithms, it may be helpful to note that
one can make a general statement about optimal routes without
regard to network topology or traffic. This statement is known as the
optimality principle (Bellman, 1957).
• It states that if router J is on the optimal path from router I to router K,
then the optimal path from J to K also falls along the same route.
• To see this, call the part of the route from I to J r 1 and the rest of the
route r 2. If a route better than r 2 existed from J to K, it could be
concatenated with r 1 to improve the route from I to K, contradicting
our statement that r 1r 2 is optimal.
• As a direct consequence of the optimality principle, we can see that
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.
Shortest Path Algorithm
• One way of measuring path length is the number of hops. Using
this metric, the paths ABC and ABE in Figure are equally long
• Another metric is the geographic distance in kilometers, in
which case ABC is clearly much longer than ABE (assuming the
figure is drawn to scale).
• However, many other metrics besides hops and physical
distance are also possible. For example, each edge could be
labeled with the mean delay of a standard test packet, as
measured by hourly runs. With this graph labeling, the shortest
path is the fastest path rather than the path with the fewest
edges or kilometers.
• Each node is labeled (in parentheses) with its distance from the
source node along the best known path.
Flooding
• When a routing algorithm is implemented, each router must make
decisions based on local knowledge, not the complete picture of the
network. A simple local technique is flooding, in which every incoming
packet is sent out on every outgoing line except the one it arrived on.
• Flooding obviously generates vast numbers of duplicate packets, in
fact, an infinite number unless some measures are taken to damp the
process.
• One such measure is to have a hop counter contained in the header
of each packet that is decremented at each hop, with the packet
being discarded when the counter reaches zero.
• Ideally, the hop counter should be initialized to the length of the path
from source to destination. If the sender does not know how long the
path is, it can initialize the counter to the worst case, namely, the full
diameter of the network.
•Flooding is not practical for sending most packets, but it
does have some important uses.
•First, it ensures that a packet is delivered to every node
in the network. This may be wasteful if there is a single
destination that needs the packet, but it is effective for
broadcasting information. In wireless networks, all
messages transmitted by a station can be received by
all other stations within its radio range, which is, in fact,
flooding, and some algorithms utilize this property.
•Second, flooding is tremendously robust. Even if large
numbers of routers are blown to bits (e.g., in a military
network located in a war zone), flooding will find a path
if one exists, to get a packet to its destination.
Distance Vector Routing
• A distance vector routing algorithm operates by having each
router maintain a table (i.e., a vector) giving the best known
distance to each destination and which link to use to get there.
These tables are updated by exchanging information with the
neighbors. Eventually, every router knows the best link to reach
each destination.
• The distance vector routing algorithm is sometimes called by
other names, most commonly the distributed Bellman-Ford
routing algorithm, after the researchers who developed it
(Bellman, 1957; and Ford and Fulkerson, 1962). It was the
original ARPANET routing algorithm and was also used in the
Internet under the name RIP.
• This updating process is illustrated in Fig. 5-9. Part (a) shows a
network. The first four columns of part (b) show the delay
vectors received from the neighbors of router J. A claims to
have a 12-msec delay to B, a 25-msec delay to C, a 40- msec
delay to D, etc. Suppose that J has measured or estimated its
delay to its neighbors, A, I, H, and K, as 8, 10, 12, and 6 msec,
respectively.
• Consider how J computes its new route to router G. It knows
that it can get to A in 8 msec, and furthermore A claims to be
able to get to G in 18 msec, so J knows it can count on a delay
of 26 msec to G if it forwards packets bound for G to A.
Similarly, it computes the delay to G via I, H, and K as 41 (31 +
10), 18 (6 + 12), and 37 (31 + 6) msec, respectively. The best of
these values is 18, so it makes an entry in its routing table that
the delay to G is 18 msec and that the route to use is via H.
The Count-to-Infinity Problem
• Distance vector routing is useful as a simple technique by which
routers can collectively compute shortest paths, but it has a serious
drawback in practice: although it converges to the correct answer, it
may do so slowly.
• In particular, it reacts rapidly to good news, but leisurely to bad news.
Consider a router whose best route to destination X is long. If, on the
next exchange, neighbor A suddenly reports a short delay to X, the
router just switches over to using the line to A to send traffic to X. In
one vector exchange, the good news is processed.
• To see how fast good news propagates, consider the five-node
(linear) network of Fig. 5-10, where the delay metric is the number of
hops. Suppose A is down initially and all the other routers know this.
In other words, they have all recorded the delay to A as infinity.
• When A comes up, the other routers learn about it via the vector
exchanges. For simplicity, we will assume that there is a
gigantic gong somewhere that is struck periodically to initiate a
vector exchange at all routers simultaneously. At the time of the
first exchange, B learns that its left-hand neighbor has zero
delay to A. B now makes an entry in its routing table indicating
that A is one hop away to the left. All the other routers still think
that A is down. At this point, the routing table entries for A are as
shown in the second row of Fig. 5-10(a).
• On the next exchange, C learns that B has a path of length 1 to
A, so it updates its routing table to indicate a path of length 2,
but D and E do not hear the good news until later. Clearly, the
good news is spreading at the rate of one hop per exchange. In
a network whose longest path is of length N hops, within N
exchanges everyone will know about newly revived links and
routers.
• exchange, C learns that B has a path of length 1 to A, so it updates its
routing table to indicate a path of length 2, but D and E do not hear the
good news until later. Clearly, the good news is spreading at the rate of one
hop per exchange. In a network whose longest path is of length N hops,
within N exchanges everyone will know about newly revived links and
routers.
• At the first packet exchange, B does not hear anything from A. Fortunately,
C says ‘‘Do not worry; I have a path to A of length 2.’’ Little does B suspect
that C’s path runs through B itself. For all B knows, C might have ten links
all with separate paths to A of length 2. As a result, B thinks it can reach A
via C, with a path length of 3. D and E do not update their entries for A on
the first exchange.
• On the second exchange, C notices that each of its neighbors claims to
have a path to A of length 3. It picks one of them at random and makes its
new distance to A 4, as shown in the third row of Fig. 5-10(b). Subsequent
exchanges produce the history shown in the rest of Fig. 5-10(b).
• From this figure, it should be clear why bad news travels slowly: no router
ever has a value more than one higher than the minimum of all its
neighbors. Gradually, all routers work their way up to infinity, but the
number of exchanges required depends on the numerical value used for
infinity. For this reason, it is wise to set infinity to the longest path plus 1.
Link State Routing
•The idea behind link state routing is fairly simple
and can be stated as five parts. Each router must
do the following things to make it work:
•Discover its neighbors and learn their network
addresses.
•Set the distance or cost metric to each of its
neighbors.
•Construct a packet telling all it has just learned.
•Send this packet to and receive packets from all
other routers.
•Compute the shortest path to every other router.
Learning about the Neighbors
• When a router is booted, its first task is
to learn who its neighbors are. It
accomplishes this goal by sending a
special HELLO packet on each
point-to-point line. The router on the
other end is expected to send back a
reply giving its name. These names must
be globally unique because when a
distant router later hears that three
routers are all connected to F, it is
essential that it can determine whether
all three mean the same F.
• A better way to model the LAN is to
consider it as a node itself, as shown in
Fig. 5-11(b). Here, we have introduced a
new, artificial node, N, to which A, C, and
F are connected.
Building Link State Packet
•Once the information needed for the exchange has
been collected, the next step is for each router to build a
packet containing all the data. The packet starts with the
identity of the sender, followed by a sequence number
and age and a list of neighbors. The cost to each
neighbor is also given.
•Building the link state packets is easy. The hard part is
determining when to build them. One possibility is to
build them periodically, that is, at regular intervals.
Another possibility is to build them when some
significant event occurs, such as a line or neighbor
going down or coming back up again or changing its
properties appreciably.
Hierarchical Routing
• As networks grow in size, the router routing tables grow
proportionally. Not only is router memory consumed by
ever-increasing tables, but more CPU time is needed to scan them
and more bandwidth is needed to send status reports about them. At
a certain point, the network may grow to the point where it is no
longer feasible for every router to have an entry for every other
router, so the routing will have to be done hierarchically, as it is in the
telephone network.
• When hierarchical routing is used, the routers are divided into what
we will call regions. Each router knows all the details about how to
route packets to destinations within its own region but knows nothing
about the internal structure of other regions.
• For huge networks, a two-level hierarchy may be insufficient; it may
be necessary to group the regions into clusters, the clusters into
zones, the zones into groups, and so on, until we run out of names
for aggregations.
Hierarchical Routing
• Figure 5-14 gives a quantitative example of routing in a
two-level hierarchy with five regions. The full routing table for
router 1A has 17 entries, as shown in Fig. 5-14(b). When routing
is done hierarchically, as in Fig. 5-14(c), there are entries for all
the local routers, as before, but all other regions are condensed
into a single router, so all traffic for region 2 goes via the 1B-2A
line, but the rest of the remote traffic goes via the 1C-3B line.
Hierarchical routing has reduced the table from 17 to 7 entries.
• Unfortunately, these gains in space are not free. There is a
penalty to be paid: increased path length. For example, the best
route from 1A to 5C is via region 2, but with hierarchical routing
all traffic to region 5 goes via region 3, because that is better for
most destinations in region 5.
Broadcast Routing
• One broadcasting method that requires no special features from the
network is for the source to simply send a distinct packet to each
destination. Not only is the method wasteful of bandwidth and slow,
but it also requires the source to have a complete list of all
destinations. This method is not desirable in practice, even though it
is widely applicable.
• An improvement is multidestination routing, in which each packet
contains either a list of destinations or a bit map indicating the
desired destinations. When a packet arrives at a router, the router
checks all the destinations to determine the set of output lines that
will be needed. (An output line is needed if it is the best route to at
least one of the destinations.) The router generates a new copy of
the packet for each output line to be used and includes in each
packet only those destinations that are to use the line. In effect, the
destination set is partitioned among the output lines. After a sufficient
number of hops, each packet will carry only one destination like a
normal packet.
• An example of reverse path forwarding is shown in Fig. 5-15. Part (a)
shows a network, part (b) shows a sink tree for router I of that
network, and part (c) shows how the reverse path algorithm works.
• On the first hop, I sends packets to F, H, J, and N, as indicated by the
second row of the tree. Each of these packets arrives on the
preferred path to I (assuming that the preferred path falls along the
sink tree) and is so indicated by a circle around the letter.
• On the second hop eight packets are generated, two by each of the
routers that received a packet on the first hop. As it turns out, all eight
of these arrive at previously unvisited routers, and five of these arrive
along the preferred line.
• Of the six packets generated on the third hop, only three arrive on the
preferred path (at C, E, and K); the others are duplicates.
• After five hops and 24 packets, the broadcasting terminates,
compared with four hops and 14 packets had the sink tree been
followed exactly.
ADDRESS MAPPING
Mapping Logical to Physical Address: ARP
• The host or the router sends an ARP query packet. The packet
includes the physical and IP addresses of the sender and the IP
address of the receiver. Because the sender does not know the
physical address of the receiver, the query is broadcast over the
network.
• Every host or router on the network receives and processes the
ARP query packet, but only the intended recipient recognizes its
IP address and sends back an ARP response packet. The
response packet contains the recipient's IP and physical
addresses.
ARP packet
• Hardware type. This is a 16-bit field defining the type of the network on which ARP is running. Each LAN
has been assigned an integer based on its type. For example, Ethernet is given type 1. ARP can be used
on any physical network.
• Protocol type. This is a 16-bit field defining the protocol. For example, the value of this field for the IPv4
protocol is 080016, ARP can be used with any higher-level protocol.
• Hardware length. This is an 8-bit field defining the length of the physical address in bytes. For example,
for Ethernet the value is 6.
• Protocol length. This is an 8-bit field defining the length of the logical address in bytes. For example, for
the IPv4 protocol the value is 4.
• Operation. This is a 16-bit field defining the type of packet. Two packet types are defined: ARP request
(1) and ARP reply (2).
• Sender hardware address. This is a variable-length field defining the physical address of the sender.
For example, for Ethernet this field is 6 bytes long.
• Sender protocol address. This is a variable-length field defining the logical (for example, IP) address of
the sender. For the IP protocol, this field is 4 bytes long.
• Target hardware address. This is a variable-length field defining the physical address of the target. For
example, for Ethernet this field is 6 bytes long. For an ARP request message, this field is alIOs because
the sender does not know the physical address of the target.
• Target protocol address. This is a variable-length field defining the logical (for example, IP) address of
the target. For the IPv4 protocol, this field is 4 bytes long.
• An ARP packet is encapsulated directly into a data link
frame. For example, in Figure an ARP packet is
Encapsulation encapsulated in an Ethernet frame. Note that the type
field indicates that the data carried by the frame are an
ARP packet.
Operation
• Let us see how ARP functions on a typical internet. First we describe the steps involved. Then
we discuss the four cases in which a host or router needs to use ARP. These are the steps
involved in an ARP process:
• The sender knows the IP address of the target. We will see how the sender obtains this
shortly.
• IP asks ARP to create an ARP request message, filling in the sender physical address, the
sender IP address, and the target IP address. The target physical address field is filled with
Os.
• The message is passed to the data link layer where it is encapsulated in a frame by using the
physical address of the sender as the source address and the physical broadcast address as
the destination address.
• Every host or router receives the frame. Because the frame contains a broadcast destination
address, all stations remove the message and pass it to ARP. All machines except the one
targeted drop the packet. The target machine recognizes its IP address.
• The target machine replies with an ARP reply message that contains its physical address. The
message is unicast.
• The sender receives the reply message. It now knows the physical address of the target
machine.
• The IP datagram, which carries data for the target machine, is now encapsulated in a frame
and is unicast to the destination.
Four Different Cases
• The sender is a host and wants to send a packet to another host on the same
network. In this case, the logical address that must be mapped to a physical
address is the destination IP address in the datagram header.
• The sender is a host and wants to send a packet to another host on another
network. In this case, the host looks at its routing table and finds the IP
address of the next hop (router) for this destination. Ifit does not have a
routing table, it looks for the IP address of the default router. The IP address of
the router becomes the logical address that must be mapped to a physical
address.
• The sender is a router that has received a datagram destined for a host on
another network. It checks its routing table and finds the IP address of the
next router. The IP address of the next router becomes the logical address
that must be mapped to a physical address.
• The sender is a router that has received a datagram destined for a host on the
same network. The destination IP address of the datagram becomes the
logical address that must be mapped to a physical address.
Four cases
using ARP
Mapping Physical to Logical Address: RARP,
BOOTP, and DHCP
There are occasions in which a host knows its physical address but
needs to know its logical address. This may happen in two cases:
1. A diskless station is just booted. The station can find its physical
address by checking its interface, but it does not know its IP
address.
2. An organization does not have enough IP addresses to assign to
each station; it needs to assign IP addresses on demand. The
station can send its physical address and ask for a short time
lease.
RARP
• Reverse Address Resolution Protocol (RARP) finds the logical address
for a machine that knows only its physical address. Each host or router
is assigned one or more logical (IP) addresses, which are unique and
independent of the physical (hardware) address of the machine. To
create an IP datagram, a host or a router needs to know its own IP
address or addresses. The IP address of a machine is usually read from
its configuration file stored on a disk file.
• However, a diskless machine is usually booted from ROM, which has
minimum booting information. The ROM is installed by the
manufacturer. It cannot include the IP address because the IP
addresses on a network are assigned by the network administrator.
• The machine can get its physical address (by reading its NIC, for
example), which is unique locally. It can then use the physical address
to get the logical address by using the RARP protocol. A RARP request
is created and broadcast on the local network. Another machine on the
local network that knows all the IP addresses will respond with a RARP
reply.
BOOTP
• The Bootstrap Protocol (BOOTP) is a client/server protocol
designed to provide physical address to logical address mapping.
BOOTP is an application layer protocol. The administrator may put
the client and the server on the same network or on different
networks, as shown in Figure. BOOTP messages are encapsulated
in a UDP packet, and the UDP packet itself is encapsulated in an
IP packet.
• The reader may ask how a client can send an IP datagram when it
knows neither its own IP address (the source address) nor the
server's IP address (the destination address). The client simply
uses all as 0s the source address and all 1s as the destination
address.
DHCP
• BOOTP is not a dynamic configuration protocol. When a client
requests its IP address, the BOOTP server consults a table that
matches the physical address of the client with its IP address. This
implies that the binding between the physical address and the IP
address of the client already exists. The binding is predetermined.
• However, what if a host moves from one physical network to
another? What if a host wants a temporary IP address? BOOTP
cannot handle these situations because the binding between the
physical and IP addresses is static and fixed in a table until
changed by the administrator. BOOTP is a static configuration
protocol.
• The Dynamic Host Configuration Protocol (DHCP) has been
devised to provide static and dynamic address allocation that can
be manual or automatic.
DHCP provides static and dynamic address allocation that can
be manual or automatic.
• Static Address Allocation In this capacity DHCP acts as BOOTP
does. It is backward compatible with BOOTP, which means a host
running the BOOTP client can request a static address from a
DHCP server. A DHCP server has a database that statically binds
physical addresses to IP addresses.
• Dynamic Address Allocation DHCP has a second database with
a pool of available IP addresses. This second database makes
DHCP dynamic. When a DHCP client requests a temporary IP
address, the DHCP server goes to the pool of available (unused) IP
addresses and assigns an IP address for a negotiable period of
time.
ICMP
• The IP protocol has no error-reporting or error-correcting
mechanism.
• The IP protocol also lacks a mechanism for host and
management queries. A host sometimes needs to
determine if a router or another host is alive. And
sometimes a network administrator needs information
from another host or router.
• The Internet Control Message Protocol (ICMP) has been
designed to compensate for the above two deficiencies. It
is a companion to the IP protoco1.
Types of Messages
• ICMP messages are divided into two broad categories:
error-reporting messages and query messages.
• The error-reporting messages report problems that a
router or a host (destination) may encounter when it
processes an IP packet.
• The query messages, which occur in pairs, help a host or
a network manager get specific information from a router
or another host. For example, nodes can discover their
neighbors. Also, hosts can discover and learn about
routers on their network, and routers can help a node
redirect its messages.
Message • An ICMP message has an 8-byte header and a variable-size
data section. Although the general format of the header is
Format different for each message type, the first 4 bytes are
common to all. As Figure 21.8 shows, the first field, ICMP
type, defines the type of message. The code field specifies
the reason for the particular message type. The last
common field is the checksum field. The rest of the header
is specific for each message type.
• ICMP always reports error messages to
Error Reporting the original source.
The following are important points about ICMP error messages:
• No ICMP error message will be generated in
response to a datagram carrying an ICMP error
message.
• No ICMP error message will be generated for a
fragmented datagram that is not the first fragment.
• No IeMP error message will be generated for a
datagram having a multicast address.
• No ICMP error message will be generated for a
datagram having a special address such as
127.0.0.0 or 0.0.0.0.
Destination Unreachable