ay in h Implementation of BFS on Network using Ns2
Priyanka Kumari
Department of Information Technology
Poornima Institute of Engg. & Tech.
Jaipur, India
priyankapiet504@poornima.org
Abstract—
We have extended Breadth First Search algorithm to use
it for detection of data which has been taken by us randomly and we have to implement it through the simulator that is called NS2. We verify our detection algorithm on the data which we are making ,means that for the implementation of BFS we uses the simulator called as NS2,first we created the nodes and then connected the node and then the packets are linked for the implementation. We will take many input data and perform its implementation and get the analysis of the result.
Keywords—
I. INTRODUCTION
Instead of searching “deeply” along one path, BFS tries to search all paths at the same time
Makes use of a data structure – queue
BFS pseudo code
while queue not empty
dequeue the first vertex u from queue
for each vertex v directly reachable from u
if v is unvisited
enqueue v to queue
mark v as visited
• Initially all vertices except the start vertex are marked as unvisited and the queue contains the start vertex only
HOW BFS WORKS OF BFS
• Shortest paths finding
• Flood-fill (can also be handled by DFS)
BFS start at level 0,which is vertex s.At first we have to visit all the vertex that distance of one edge away.when it is visited it is called or painted as visited., The vertices adjacent to start vertex s,it is placed into level 1.And now we have to visit the new vertices we can reach at the distance of two edges away from the source vertex s.The new vertices which is adjacent to the level 1 vertices and not previously assigned to the level,are then placed into the level 2 and the process goes on.The traversal of BFS terminates when every vertex has to be visited.
Based upon the BFS, there are O(V + E)-time algorithms for the following problems:
– Testing whether graph is connected.
– Computing a spanning forest of graph.
– Computing, for every vertex in graph, a path with the minimum number of edges between start vertex and current vertex or reporting that no such path exists.
– Computing a cycle in graph or reporting that no such cycle exists.
We will use BFS in the following:
– Prim's MST algorithm.
– Dijkstra's single source shortest path algorithm.
CONCEPT
BFS uses the idea of a frontier that separates the visited nodes from unvisited nodes. The frontier holds the nodes of the recently visited level and is used to find the next set of nodes to be visited. On every step of BFS, the current frontier is used to identify the next frontier from the set of unvisited nodes.
BFS Spanning Tree
The tree is defined by the parent pointers; it will only be a BFS tree if the network is synchronous. Otherwise, it can be any tree rooted at the start node.
Min-weight spanning tree
Minimize total weight of all edges in the tree. We will show a synchronous algorithm first, then a much more complex asynchronous algorithm.
Assume: G=(V,E) undirected; weights on edges are known by adjacent processes; processes have UID’s; n (size of graph) is known
Each node will decide which of its adjacent edges is or is not in the tree.
PROPERTIES
Notation
Gs: connected component of s
Property 1
BFS(G, s) visits all the vertices and edges of Gs
Property 2
The discovery edges labeled by BFS(G, s) form a spanning tree Ts of Gs
Property 3
For each vertex v in Li
The path of Ts from s to v has i edges
Every path from s to v in Gs has at least i edges.
ANALYSIS
Setting/getting a vertex/edge label takes O(1) time
Each vertex is labeled twice
– once as UNEXPLORED
– once as VISITED
Each edge is labeled twice
– once as UNEXPLORED
– once as DISCOVERY or CROSS
Each vertex is inserted once into a sequence Li
Method incident Edges is called once for each vertex
BFS runs in O(n + m) time provided the graph is represented by the adjacency list structure
We know that that Sv deg(v) = 2m.
II.TECHNOLOGY SPECIFICATION
1. TCL script:
Tcl is a string-based command language. The language has only a few fundamental constructs and relatively little syntax, which makes it easy to learn. The Tcl syntax is meant to be simple. Tcl is designed to be a glue that assembles software building blocks into applications. A simpler glue makes the job easier. In addition, Tcl is interpreted when the application runs. The interpreter makes it easy to build and refine your application in an interactive manner.
2. C++:
Detailed protocol simulation require systems programming language
– Byte manipulation,packet processing,algorithm implementation.
– Run time speed is important
– Turn around time (run simulation, find bug, fix bug, recompile, re-run) is slower.
3 OTCL:
– Simulation scenario configurations
– Periodic or triggered action
– Manipulating existing C++ objects
– fast to write and change
4. IEEE 802.11 wireless network is a set of media access control (MAC) and physical layer (PHY) specifications for implementing wireless local area network (WLAN) computer communication in the 2.4, 3.6, 5, and 60 GHz frequency bands. They are created and maintained by the IEEE LAN/MAN Standards Committee (IEEE 802). The base version of the standard was released in 1997, and has had subsequent amendments. The standard and amendments provide the basis for wireless network products using the Wi-Fi brand
III. TOOLS
NETWORK SIMULATOR-2: Network Simulator (Version 2) is a discrete event driven network simulation tool for studying the dynamic nature of communication networks. ns-2 provides a highly modular platform for wired and wireless simulations supporting different network elements, protocols, traffic and routing types. In general, ns-2 provides users with a way of specifying network protocols and simulating their behavior. The results of the simulation are stored in a trace file that records data about all events that occurred during the simulation process. In the master thesis we have used ns-2 to simulate the end user performance of the wireless network consisting of two APs and five nodes for variable throughput and transmission rate for the nodes.
Network simulation is a technique where a program models the behavior of a network either by calculating the interaction between the different network entities (hosts/packets, etc.) using mathematical formulas, or actually capturing and playing back observations from a production network. The behavior of the network and the various applications and services it supports can then be observed in a test lab; various attributes of the environment can also be modified in a controlled manner to assess how the network would behave under different conditions..
IV COMPONENT
NS – Simulator
NAM – Network AniMator
– visual demonstration of NS output
Preprocessing
– Handwritten TCL or
– Topology generator
Post analysis
– Trace analysis using Perl/TCL/AWK/MATLAB
ns-2, the simulator itself
– Specify simulation, generate traces
– Depends on Tcl/Tk, OTcl, TclCL
Nam, the network animator
– Animate traces from simulation
– GUI for constructing simple simulations
Using NS
.
1. Create simulation
– Describe network, protocols, sources, sinks
– Interface via OTcl which controls C++
2. Execute simulation
– Simulator maintains event list (packet list), executes next event (packet), repeats until done
– Events happen instantly in virtual time but could take arbitrarily long real time
– Single thread of control, no locking, races, etc
3. Post-process results
– Scripts (awk, perl, python) to process text output
– No standard library but some available on web.
FROM NETWORK TO SIMULATION
NODES
Addressable entity built from classifiers
– Distributes incoming data to agents
– Distributes outgoing data to links
Simplest unicast case has address and port classifiers, others may have more.
Nodes , LanNodes derived from the parents nodes.
NS2 ENVIRONMENT
.
Setting of nodes
set ns_ [new Simulator]
set node_(0) [$ns_ node]
set node_(1) [$ns_ node]
CODE OF SIMPLE TOPOLOGY
1. Creating a Simulator Object
– set ns [new Simulator]
2. Setting up files for trace & NAM
– set trace_nam [open out.nam w]
– set trace_all [open all.tr w]
3. Tracing files using their commands
– $ns namtrace-all $trace_nam
$ns trace-all $trace_all
• Closing trace file and starting NAM
proc finish { } {
– global ns trace_nam trace_all
– $ns flush-trace
– close $trace_nam
– close $trace_all
– exec nam out.nam &
– exit 0
}
• Creating LINK & NODE topology
Creating NODES
– set n1 [$ns node]
– set n2 [$ns node]
– set n3 [$ns node]
– set n4 [$ns node]
– set r1 [$ns node]
– set r2 [$ns node]
• Creating LINKS
– $ns duplex-link $N1 $R1 2Mb 5ms DropTail
– set DuplexLink0 [$ns link $N1 $R1]
– $ns duplex-link $N2 $R1 2Mb 5ms DropTail
– set DuplexLink1 [$ns link $N2 $R1]
– $ns duplex-link $R1 $R2 1Mb 10ms DropTail
– set DuplexLink2 [$ns link $R1 $R2]
– $ns duplex-link $R2 $N3 2Mb 5ms DropTail
– set DuplexLink3 [$ns link $R2 $N3]
– $ns duplex-link $R2 $N4 2Mb 5ms DropTail
– set DuplexLink4 [$ns link $R2 $N4]
• Orientation of links
– $ns duplex-link-op $N1 $R1 orient right-down
– $ns duplex-link-op $N2 $R1 orient right-up
– $ns duplex-link-op $R1 $R2 orient right
– $ns duplex-link-op $R2 $N3 orient right-up
– $ns duplex-link-op $R2 $N4 orient right-down.
TOPOLOGY GENERATED
SET UP
– set ns [new Simulator]
– set topo [new Topography]
– $topo load_flatgrid <length> <width>
NODE COORDINATES
– $mnode set X_ <x>
– $mnode set Y_ <y>
– $mnode set Z_ 0
NODE MOVEMENT
– Disable random motion
$mnode random-motion 0
– Specified
$ns at 1.0 “$mnode setdest <x> <y> <speed>”
– Random
$ns at 1.0 “$mnode start”
NS ARCHITECTURE
IV RESULT
V REFERENCES
• Tcl/Tk – http://www.tcl.tk/software/tcltk/
• Nsnam web pages – http://www.isi.edu/nsnam/
• NS by example – http://nile.wpi.edu/NS/
• Tutorial – Marc Greis's tutorial
• Discrete event simulation software-
• http://www.topology.org/soft/sim.html
• A.S Tanenbaum computer network,3rd ed.Prentice Hall,1996.
• R.E “Introduction to the art and science of simulation” in Proc of the 30th conference on winter simulation.
• R.G Ingalls,”Introduction to simulation: Introduction to simulation”in WSC ’02;procedding of the 34th conference on winter simulation.
• W.H Tranter,et,at..principles of communication system simulation. Prentice Hall,2004
• http://www.cs.sunysb.edu/~samir/cse590/ns2-lecture.ppt
ere…