Professional Documents
Culture Documents
Algorithm
Sriram Narayanan
BE- Electronics
Final Year
2002-03
CONTENTS
3.1 Graph 5
5.1 Structure 14
5.2 Flowchart (Dijkstra) 15
5.3 Network 16, 17
6.3 Flowchart for Implementation 22, 23
7 Physical Network 28, 32
Graphical Representation 29, 30, 31, 33
Of Shortest Path
Back to top
ABSTRACT
The complete network of large number of interconnected autonomous system, each of which
consists of a distinct domain, needs to communicate to different nodes to forward the
information. There are various means of communications between these systems. Routing is one
of them. Routing refers to the overall network wide process that determines end to end paths that
datagram will take from source to destinations. There are different routing algorithms available
such as BELLMAN FORD ALGORITHM which is decentralized routing algorithm and
DIJKSTRA ALGORITHM which is a global routing algorithm. In global routing algorithm,
each router has a complete view of the network, whereas in a decentralized routing algorithm
each router has a local view consisting of its directly attached neighbours. Out of this Dijkstra
Algorithm is mostly preferred as it is faster as compared to any other algorithm and its
implementation is easier. In this algorithm, router based information that has been collected from
other routers, builds a graph of the network which shows the locations & links of routers within
themselves & in the network. These links are labeled with a number called weight or cost. If
there are two links between a node and destination, the router chooses the link with the lowest
weight.
One of the chief advantages of Dijkstra Algorithm is that router computes routes
independently using the same original status data; they do not depend on the computation of
intermediate machines. Because link status messages propagate unchanged, it is easy to debug
problems. Because routers perform the route computation locally, it is guaranteed to converge.
Finally, because link status messages only carry information about the direct connections from a
single router, the size does not depend on the number of networks in the networks in the internet.
Thus, Dijkstra Algorithms scale better than distance vector algorithms. We have implemented
Dijkstra Algorithm for routing purpose.
Back to top
CHAPTER 1
INTRODUCTION
The Internet is one of the 20th century's greatest communications developments. It allows people
around the world to send E-Mail to one another in a matter of seconds. But none of these parts
would ever make it to our computer without a piece of the Internet that we've probably never
seen. In fact, most people have never stood "face to machine" with the technology most
responsible for allowing the Internet to exist at all: The Router. In order to transfer data from a
source host to the destination host, the network must determine the path or the route links
between source and destination. This can be achieved by using routers. The routers in a network
are responsible for receiving and forwarding packets through the interconnected set of networks.
In particular, the router must avoid the portion of network that has failed or has too much
congestion. At the heart of the router there is an algorithm which takes the dynamic decisions
and directs the datagrams from source to the destination. This is better known as Routing
Algorithm. Routing Algorithms are classified depending upon the technique they employ to
calculate the shortest path. Dijkstra Routing Algorithm is one of them.
Back to top
19.2america CHAPTER 2
LITERATURE SURVEY
A Literature Survey was conducted to study the advancement made in the development of
Routing Algorithms.
Routing can be compared to the process of building graphs and directing the
datagrams from source to destination[12].To make such dynamic routing decisions router
exchange information using a special algorithm known as Routing Algorithm[10]. The Network
Graphs used in simulations are constructed by using the approach given in [1]. The Routing
Techniques can be sub-divided into following categories:
1) Fixed/Deterministic
2) Adaptive
3) Flooding
4) Multicasting
5) Hierarchical
6) Random
2.1 Fixed/Deterministic:
Practical multi-computers use Deterministic Routing [2]. Fixed Routing has been
widely used in practice due to its simplicity. However, message cannot take advantage of
alternative paths to avoid congested network regions. Dimension-Ordered Routing [3], [4] is a
typical example of deterministic routing where messages visit network dimensions in a
predefined order.
2.2 Adaptive:
2.3 Flooding:
Flooding is a Static type of routing in which every incoming packet is sent out on
every outgoing line except the one it arrived on [10]. Flooding is not practical in most
applications, but it does have some uses. For example, in military applications, where large
number of routers may be blown to bits at any instant, the tremendous robustness of flooding is
highly desirable.
2.4 Multicasting:
As Networks grow in size, the router’s routing tables grow proportionally. Not
only is router memory is consumed, but more CPU time is needed to scan them and more
bandwidth is needed to send status reports. This problem can be overcome by using Hierarchical
Routing [10], where the routers are divided into regions, with each router knowing all the details
about how to route packets to destinations within its own region, but knowing nothing about the
other region.
2.6 Random:
In case of Random Routing, a node selects only one outgoing path for retransmission
of an incoming packet. The outgoing link is chosen at random, excluding the link on which the
packet arrived [12]. It is further sub-divided into two categories: Distance Vector Routing
Algorithm and Link State Routing Algorithm [10], [12]. Bellman-Ford Routing Algorithm [10],
[12] is an example of the former while Dijkstra Routing Algorithm [10], [12], [13] belongs to
the latter. In the latter case the router has a complete view of the network, whereas for the former
each router only has a local view consisting of its directly attached neighbors.
It is the Dijkstra Routing Algorithm that we have implemented.
Currently research is going on for Routing Algorithms for Mobile Hosts where a user
wants to plug into a network at any time and any place [10].
Back to top
10.3 sugar CHAPTER 3
ROUTING
The term “Routing” refers to the overall, network wide process that determines end-to-end paths
that datagrams will take from source to destination. Using a driving analogy, we can think of
routing as the process of building maps and giving directions from source to destination. When
an end-to-end logical connection, consisting of a sequence of logical connections is to be set up,
each intermediate system in the sequence must make a routing decision that determines the next
hop in the sequence.
Back to top
3.1 Need for Routing:
NODE NODE
D E
Back to top
3.2 Routing Principle:
11.1 sugar
In order to transfer packets from source host to the destination host, the network layer must
determine the path, or route, that the packets are to follow. Whether the network layer provides
the datagram service (in which case different packets between a given source–destination pair
may take different route) or a virtual circuits service (in which case all packets between a given
source and destination will take the same path). In the above network node A may route a packet
addressed to Y to either node B or to node D. The selection of which node to route the packet to
is the routing decision. The routing decision is made by an algorithm incorporated in the packet
switching exchange (PSE) software of node A. The performance of routing algorithms may be
expressed in terms of various criteria.
Back to top
10.4sugar CHAPTER 4
ROUTING ALGORITHM
Routing algorithm is the algorithm used to make a routing decision for a particular datagram
based on current routing information. Routing information is nothing but the information about
the topology and delays of the network.
An important requirement for any Routing Algorithm is to ensure deadlock freedom;
deadlock situation occur when no message can advance towards its destination because of filled
queues. Back to top
4.1 Characteristics:
Correctness
Simplicity
Robustness
Stability
Fairness
Optimality
Efficiency
The first two items one the list is self-explanatory. Robustness has to do with the ability of the
network to deliver packets via some route in the face of localized failures and overloads. Ideally,
the network can react to such contingencies without the loss of packets or the breaking of virtual
circuits. The designer who seeks robustness must cope with the competing requirement for
stability. Techniques that react to changing condition have an unfortunate tendency to react too
slowly to events or to experience unstable swings from one extreme to another. For example, the
network may react to congestion in one area by shifting most of the load to a second area. Now
the second area is overloaded and the first is underutilized, causing a second shift. During these
shifts, packets may travel in loop through the network.
A tradeoff also exists between fairness and optimality. Some performance criteria may
give higher priority to the exchange of packets between near by station compare to an exchange
between distant stations. This policy may maximize average throughput but will appear unfair to
the station that primarily needs to communicate with distant station.
Finally, any routing technique involves some processing overhead at each node and often
a transmission overhead as well, both of which impair network efficiency. The penalty of such
overhead needs to be less than the benefit accrued based on some reasonable metric, such as
increased robustness or fairness. Back to top
Back to top
4.3 Classification of Routing Algorithms:
Routing algorithms determine an efficient path from one source to its destination through the
chain of Routers and servers. One way in which we can classify as routing algorithms is
according to whether they are Global or Decentralized.
• A Global Routing Algorithm computes the shortest path between a source &
destination using complete, global knowledge about the network i.e. the algorithm takes the
connectivity between all nodes & all link costs as inputs. The calculation can be run at one site (a
centralized global routing algorithm) or replicated at multiple sites. In practice, algorithms with
global state information are often referred to as Link State Algorithm.
• In Static Routing Algorithm, routes change very slowly over time, often as a result of
human intervention (for example, a human manually editing a router’s forwarding table).
• Dynamic Routing Algorithms change the routing paths as the network traffic loads for
topology change. While dynamic algorithms are more responsive to network
changes, they are also more susceptible to problem such as routing loops and oscillations in
route.
Routing Algorithms can be grouped into two major classes: Non-adaptive and Adaptive.
• Non-Adaptive Algorithms do not base their routing decisions on measurements or
estimates of the current traffic and topology. Instead, the choice of the route to use is computed
in advance, off-line and downloaded to the routers when the network is booted
• Adaptive Algorithms, in contrast, change their routing decisions to reflect changes in
the topology and usually the traffic as well. They differ in where they get their information (e.g.,
locally, from adjacent routers, or from all routers), when they change the routes.
Back to top
A large number of routing strategies have evolved for dealing with the routing requirements
of packet-switching networks. Many have these strategies are also applied to internetworking
routing. In the section, we survey three key strategies: Fixed, Flooding, and Random.
a) Fixed Routing:
For fixed routing, a single, a permanent route is configured for each source-destination pair
of nodes in the network. The routes are fixed, or at least only change when there is a change in
the topology of the network. Thus, the link cost used in designing routes cannot be based on any
dynamic variable such as traffic. They could, however, be based on expected traffic or capacity.
b) Flooding:
c) Multicast Routing:
d) Hierarchical Routing:
When Hierarchical Routing is used, the routers are divided into what we call
regions, with each router knowing all the details about how to route packets to
destinations within its own region, but knowing nothing about the internal structure of other
regions. When different networks are connected together, it is natural to regard each one as a
separate region in order to free the routers in one network from having to know the topological
structure of the other ones.
e) Random Routing:
Random routing has the simplicity and robustness of flooding with far less traffic load. With
random routing, a node selects only one outgoing path for retransmission of an incoming packet.
The outgoing link is chosen at random, excluding the link on which the packet arrived. If all
links are equally likely to be chosen, then a node may simply utilize outgoing links in round-
robin fashion.
Back to top
13.1 sugar
4.5 Types of Routing Algorithms:
There are mainly two types of routing algorithms, The Bellman Ford Algorithm which is a
decentralized algorithm and Dijkstra Algorithm which is a global routing algorithm. In the
latter case the router has a complete view of the network. Whereas for the former each router
only has a local view consisting of its directly attached neighbors.
Dijkstra algorithm requires that any link cost change be broadcasted to the entire network.
Bellman-Ford algorithm is subject to the problems of routing loop and slow convergence due to
the lack of a complete network view. Routing in practice is actually hierarchical. RIP and OSPF
are the two main Intra-AS routing protocol. RIF is based on Bellman-Ford algorithm, while
OSPF is based on Dijkstra algorithm.
CHAPTER 5
DIJKSTRA ALGORITHM
Dijkstra Algorithm is one of the more common shortest path algorithms and can be applied to
network routing. This Algorithm is an iterative process that works through a graph or a set of
vertices & paths to calculate the shortest path from any one source node to every other node in
the set. Back to top
5.1 Algorithm:
The router builds a graph of the network and identifies source and destination nodes, as V1
and V2 for example. Then it builds a matrix, called the "adjacency matrix." In this matrix, a
coordinate indicates weight. For example, [i, j] is the weight of a link between Vi and Vj. If there
is no direct link between Vi and Vj, this weight is identified as "infinity."
1. The router builds a status record set for every node on the network. The record
contains three fields:
• Length field - The second field shows the sum of the weights from the source to
that node.
• Label field - The last field shows the status of node. Each node can have one
status mode: "permanent" or "tentative."
2. The router initializes the parameters of the status record set (for all nodes) and sets
their length to "infinity" and their label to "tentative."
3. The router sets a T-node. For example, if V1 is to be the source T-node, the router
changes V1's label to "permanent." When a label changes to "permanent," it never changes again.
A T-node is an agent and nothing more.
4. The router updates the status record set for all tentative nodes that are directly linked to
the source T-node.
5. The router looks at all of the tentative nodes and chooses the one whose weight to V1 is
lowest. That node is then the destination T-node.
6. If this node is not V2 (the intended destination), the router goes back to step 5.
7. If this node is V2, the router extracts its previous node from the status record set and does
this until it arrives at V1. This list of nodes shows the best route from V1 to V2.
Back to top
5.2 Flowchart:
14.1 sugar
These steps are shown below as a flowchart.
START
Set V1 as T-node
Is T-Node is V2?
END
Back to top
5.3 Example:
Here we want to find the best route between A and E (see below). You can see that there are
six possible routes between A and E (ABE, ACE, ABDE, ACDE, ABDCE, ACDBE), and it's
obvious that ABDE is the best route because its weight is the lowest. But life is not always so
easy, and there are some complicated cases in which we have to use algorithms to find the best
route.
1. As you see in the image below, the source node (A) has been chosen as T-node, and so its
label is permanent (we show permanent nodes with filled circles and T-nodes with the -->
symbol).
Now we can have an adjacency matrix of the network. If there is no direct link between two
nodes, then assuming the weight is infinite.
A B C D E
A 0 1 5 INFINITE INFINITE
B 1 0 INFINITE 2 4
C 5 INFINITE 0 2 3
D INFINITE 2 2 0 1
E INFINITE 4 3 1 0
2. In this step, you see that the status record set of tentative nodes directly linked to T- node
(B, C) has been changed. Also, since B has less weight, it has been chosen as T-node and its
label has changed to permanent (see below)
3. In this step, like in step 2, the status record set of tentative nodes that have a direct link to
T-node (D, E), has been changed. Also, since D has less weight, it has been chosen as T-node
and its label has changed to permanent (see below).
4. In this step, we don't have any tentative nodes, so we just identify the next T-node. Since E
has the least weight, it has been chosen as T-node.
We are at end! Now we have to identify the route. The previous node of E is D, and the
previous node of D is B, and B's previous node is A. So the best route is (ABDE). In this case,
the total weigh is 4 (1+2+1).
Alternative roots are:-
(ABE) 1+ 4=5
(ACE) 5 +3=8
(ACDE) 5+2+1=8 Back to top
CHAPTER 6
PROBLEM ANALYSIS AND IMPLEMENTATION
The complete project work has been divided into following modules:
• Problem Analysis
• Technique Used
• Flowchart
• Pseudo Code
Back to top
33.8america
6.1 Problem Analysis:
Back to top
33.2america
6.2 Technique Used:
1. Construction of Network:
The Network to be processed is constructed depending upon the number of Nodes and the
Activities between the nodes as specified by the user. The activities are stored in a Matrix where
the intersection of particular row and column gives the activity between the corresponding nodes.
In the network the nodes having activity less than infinity between them are connected to give
the complete architecture.
A separate Structure for each Node is generated containing two Arrays. One of the arrays
includes the information of those nodes, which are connected to that particular node, and the
other array stores the corresponding activity. The array of nodes is sorted in increasing order
with respect to activities.
Starting from Destination Node, the node at the Shortest Distance is identified. If this node is
Source then we have the Optimum Path here itself. Otherwise the node is saved in the Route
Array and it is locked to avoid Recursion. Now the next node, which is at the shortest distance
from the current node, is identified and saved in the route array till the source node is found.
Simultaneously the activities are added up to get the total activity on the corresponding path.
This way all the possible routes are calculated and sorted in increasing order with total activities
on the path.
4. Graphics Display:
The Shortest Path between Source and Destination is shown in text showing all the
Intermediate hops along with total number of activities. The same is displayed Graphically by
connecting the intermediate nodes. All the other links of the original network are hidden.
It gives the next path available for the datagram to move from source to destination. The
alternate path is given depending upon the activities on that path as compared to the Optimum
Path and the other available paths. Similarly the subsequent alternate paths are provided.
We can change the Destination Node within the same Network and find out its Optimum
Path as well as the Alternate Paths from the Source Node. This way we can check the Shortest
Path for any Node in the Network from the Source.
Suppose a link fails, then the datagram can not move through that link. This changes the
whole configuration of the Network and the available paths between Source and Destination. It
provides the Shortest Path and the Alternate Paths after the link failure. Thus we don’t have to
run the program all over again to get the Optimum Path.
The following features of ‘C’ Language have been extensively used in the
implementation:
Structures
Arrays
Graphics
Back to top
6.3Flowchart:
Start
End
Back to top
6.4 Pseudo Code:
Node 0
2
10
Node 1 Node 2
3
1 1
1
Node 3 Node 4
Physical Connectivity
Press Any Key For Shortest Path
Number of Activities :4
Node 0
2
10
Node 1 Node 2
3
1 1
1
Node 3 Node 4
SHORTEST PATH
Press Any Key To Continue
Number of Activities :5
Node 0
2
10
Node 1 Node 2
3
1 1
1
Node 3 Node 4
Number of Activities :3
Node 0
2
10
Node 1 Node 2
3
1 1
1
Node 3 Node 4
Shortest Path
Press Any Key To Continue
Node 0
2
10
Node 1 Node 2
3
1
Node 3 Node 4
Physical Connectivity
Press Any Key To Continue
Screen 10 : Activity Matrix And Physical Network After Deleting The Link
The Shortest Path From Node 0 To Node 4 :
0 => 2 => 4
Number of Activities :5
Node 0
2
10
Node 1 Node 2
3
1
Node 3 Node 4
SHORTEST PATH
Press Any Key To Continue
Back to top
CHAPTER 8
CONCLUSION AND SUGGESTIONS
Generally, under normal circumstances after we have determined the optimum path
for a datagram in a network using Dijkstra Algorithm, if a link failure occurs then the complete
network topology changes including the path that the datagram was following. Hence in case of a
link failure we have to run the algorithm all over again to provide the shortest path to the
datagram. However, we have implemented the Dijkstra Algorithm in such a way that under the
context of link failure it will provide the next shortest path from the available alternate paths that
has been calculated along with the Optimum Path itself. As a result there is no need to execute
the algorithm again.
Back to top
CHAPTER 9
REFERENCE
URL’S
15. http://www.soi.wide.ad.ip/soi_asia/pkg2/03/6.html
16. http://www.eell70.ee.uts.edu.all/~rob/48750/book/node123.htm
Back to top