13
SRI JAYACHAMARAJENDRA COLLEGE OF ENGINEERING MYSORE-570006 Department of Information science and Engineering Assignment - 2 802.11 Wireless Network Simulation Using NS2 Submitted by name rollno usn Upadhyay Dhananjay A P120713 4JC12SSE16 Guidance of P.M. Shivamurthy Assistant professor Dept of IS, SJCE Mysore. Affiliated to VISVESVARAYA TECHNOLOGICAL UNIVERSITY

802.11 Simulation using NS2

Embed Size (px)

DESCRIPTION

ns2 pROJECT

Citation preview

Page 1: 802.11 Simulation using NS2

SRI JAYACHAMARAJENDRA COLLEGE OF ENGINEERINGMYSORE-570006

Department of Information science and Engineering

Assignment - 2802.11 Wireless Network Simulation

Using NS2

Submitted byname rollno usn

Upadhyay Dhananjay A P120713 4JC12SSE16

Guidance ofP.M. ShivamurthyAssistant professor

Dept of IS, SJCE Mysore.

Affiliated toVISVESVARAYA TECHNOLOGICAL UNIVERSITY

Page 2: 802.11 Simulation using NS2

Contents

1 Introduction 31.1 802.11 Wireless Network . . . . . . . . . . . . . . . . . . . . . . . 31.2 802.11 in Ethernet . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 Our Goal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Why NS2? 42.1 Advantages/Disadvantages of NS2 . . . . . . . . . . . . . . . . . 52.2 Why Simulation? . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 DSDV Routing Algorithm: 6

4 Program Execution in NS2 74.1 Define optional Parameter . . . . . . . . . . . . . . . . . . . . . . 74.2 Setup a Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . 74.3 Topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.4 Configure Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.5 Configure Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . 84.6 Creating The Nodes . . . . . . . . . . . . . . . . . . . . . . . . . 84.7 Adding the source and destination . . . . . . . . . . . . . . . . . 84.8 Achived Node Structure . . . . . . . . . . . . . . . . . . . . . . . 94.9 Time to run the simulation . . . . . . . . . . . . . . . . . . . . . 9

5 How the Code Works 10

6 Conclusion and Future Enhancement 12

7 Reference 13

2

Page 3: 802.11 Simulation using NS2

1 Introduction

1.1 802.11 Wireless Network

Unfortunately, 802.11 takes acronyms to new heights, which makes the in-troduction that much more important. With 802.11, the introduction servesanother important purpose. 802.11 is superficially similar to Ethernet.

Understanding the background of Ethernet helps slightly with 802.11, butthere is a host of additional background needed to appreciate how 802.11 adaptstraditional Ethernet technology to a wireless world.

To account for the differences between wired networks and the wireless mediaused by 802.11, a number of additional management features were added. Atthe heart of 802.11 is a white lie about the meaning of media access control(MAC).

Wireless network interface cards are assigned 48-bit MAC addresses, and,for all practical purposes, they look like Ethernet network interface cards. Infact, the MAC address assignment is done from the same address pool so that802.11 cards have unique addresses even when deployed into a network withwired Ethernet stations.

1.2 802.11 in Ethernet

Relation of 802.11 wireless network in OSI mode:

3

Page 4: 802.11 Simulation using NS2

1.3 Our Goal

Our System goal is to make virtual system in which we have 5 nodes, twonode work as Agent and others works as Routers in between this agent

We have separate each node with 200m distance and connected with link of10Mbps each of it. We have to measure the Throughput of the system whiletransferring the packets from one Agent to other.

System diagram of nodes and Link

We will run this simulation for three different timing

• 80ms

• 120ms

• 160ms

The ns2 network simulator is a powerful tool, but unfortunately it does notprovide any tools for getting results. It simply simulates a network, and providesa trace file of all the events that occur.

Our TCL Program script is generating the same trace file and we will derivedthe attribute from this file for further uses.

2 Why NS2?

NS2 is an open-source event-driven simulator designed specifically for researchin computer communication networks. NS2 now contains modules for numerousnetwork components such as routing, transport layer protocol, application, etc.

Network Simulator (Version 2), widely known as NS2, is simply an event-driven simulation tool that has proved useful in studying the dynamic natureof communication networks. Simulation of wired as well as wireless networkfunctions and protocols (e.g.,routing algorithms, TCP, UDP) can be done usingNS2.

4

Page 5: 802.11 Simulation using NS2

In general, NS2 provides users with a way of specifying such network protocolsand simulating their corresponding behaviors.

NS2 provides a large number of built-in C++ objects. It is advisable to usethese C++ objects to set up a simulation using a Tcl simulation script.However,advance users may find these objects insufficient. They need to develop theirown C++ objects, and use a OTcl configuration interface to put together theseobjects.

After simulation, NS2 outputs either text-based or animation-based simula-tion results. To interpret these results graphically and interactively, tools suchas NAM (Network AniMator) and XGraph are used. To analyze a particularbehavior of the network, users can extract a relevant subset of text-based dataand transform it to a more conceivable presentation.

2.1 Advantages/Disadvantages of NS2

Advantages:

• sometimes cheaper

• find bugs (in design) in advance

• generality: over analytic/numerical techniques

• detail: can simulate system details at arbitrary level

Disadvantages:

• caution: does model reflect reality

• large scale systems: lots of resources to simulate (especially accuratelysimulate)

• may be slow (computationally expensive 1 min real time could be hoursof simulated time)

• art: determining right level of model complexity

• statistical uncertainty in results

2.2 Why Simulation?

Whenever real-system not available,or system is complex/costly or dangerous(eg: space simulations, flight simulations to build we can use the simulation ondesign network.

5

Page 6: 802.11 Simulation using NS2

The time duration is very sort then we can not build the original system. Byquickly evaluate design alternatives (eg: different system configurations) we canmanege.

We can evaluate complex functions for which closed form formulas or numer-ical techniques not available.

3 DSDV Routing Algorithm:

Destination sequenced distance vector routing (DSDV) is adapted from theconventional Routing Information Protocol (RIP) to ad hoc networks routing.It adds a new attribute, sequence number, to each route table entry of theconventional RIP.

Using the newly added sequence number, the mobile nodes can distinguishstale route information from the new and thus prevent the formation of routingloops.

In DSDV, each mobile node of an ad hoc network maintains a routing table,which lists all available destinations, the metric and next hop to each destinationand a sequence number generated by the destination node.

Using such routing table stored in each mobile node, the packets are trans-mitted between the nodes of an ad hoc network.

Each node of the ad hoc network updates the routing table with advertisementperiodically or when significant new information is available to maintain theconsistency of the routing table with the dynamically changing topology of thead hoc network.

Ftp transfers the data packet from one node to other(From one Agent toother).

6

Page 7: 802.11 Simulation using NS2

4 Program Execution in NS2

4.1 Define optional Parameter

set val(chan) Channel/WirelessChannel ;# channel type

set val(prop) Propagation/TwoRayGround ;# radio-propagation model

set val(ant) Antenna/OmniAntenna ;# Antenna type

set val(ll) LL ;# Link layer type

set val(ifq) Queue/DropTail/PriQueue ;# Interface queue type

set val(ifqlen) 50 ;# max packet in ifq

set val(netif) Phy/WirelessPhy ;# network interface type

set val(mac) Mac/802_11 ;# MAC type

set val(rp) DSDV ;# ad-hoc routing protocol

set val(nn) 5 ;# number of mobilenodes

4.2 Setup a Simulator

# Creating the simulator

set ns_ [new Simulator]

# Set up trace file

$ns_ use-newtrace

set tracefd [open simple.tr w]

$ns_ trace-all $tracefd

# Create the "general operations director"

# Used internally by MAC layer: must create!

create-god $val(nn)

4.3 Topology

# Create and configure topography (used for mobile scenarios)

set topo [new Topography]

# 1000x1000m terrain

$topo load_flatgrid 1000 1000

4.4 Configure Nodes

$ns_ node-config -adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-phyType $val(netif) \

-channel [new $val(chan)] \

-topoInstance $topo \

7

Page 8: 802.11 Simulation using NS2

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-movementTrace OFF

4.5 Configure Nodes

$ns_ node-config -adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-phyType $val(netif) \

-channel [new $val(chan)] \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-movementTrace OFF

4.6 Creating The Nodes

# Setting the node and distance

for {set i 0} {$i < $val(nn) } {incr i} {

set node_($i) [$ns_ node]

$node_($i) random-motion 0 ;# disable random motion

$node_($i) set Y_ 0.0

$node_($i) set Z_ 0.0

}

$node_(0) set X_ 0.0

$node_(1) set X_ 200.0

$node_(2) set X_ 400.0

$node_(3) set X_ 600.0

$node_(4) set X_ 800.0

4.7 Adding the source and destination

# 1500 - 20 byte IP header - 40 byte TCP header = 1440 bytes

Agent/TCP set packetSize_ 1440 ;# This size EXCLUDES the TCP header

set agent [new Agent/TCP]

set app [new Application/FTP]

set sink [new Agent/TCPSink]

8

Page 9: 802.11 Simulation using NS2

$app attach-agent $agent

$ns_ attach-agent $node_(0) $agent

$ns_ attach-agent $node_(4) $sink

$ns_ connect $agent $sink

4.8 Achived Node Structure

Agent node containing the TCP, Node containing routing algorithm andQueue. Link is connected with other node with TCP Sink

4.9 Time to run the simulation

# 30 seconds of warmup time for routing

$ns_ at 0.0 "$app start"

# 60 seconds of running the simulation time

$ns_ at 120.0 "$ns_ halt"

$ns_ run

$ns_ flush-trace

close $tracefd

9

Page 10: 802.11 Simulation using NS2

5 How the Code Works

The flow of code work can be analyzed based on the flow of the program fromthe of optional parameter where we define the 802.11 Mac and DSDV routingprotocol, then we define the trace file name in which we want to write the outputof our program.

Then we setting up the simulator, without this it is not possible to generatecorrect output. After setting the simulator we define the topology which weused in the system

On each node we have to configure the protocol and Tracing information whichshows in Trace file. After configure the node we have created logical 5 nodewhich are 200m apart from each.We have created the Source and destination,source as Agent destination as Agent and intermediate nodes works as router

Result Analysis

TRACE FILE OUT PUT:

1. s -t 0.000000000 -Hs 0 -Hd -2 -Ni 0 -Nx 0.00 -Ny 0.00 -Nz 0.00 -Ne -1.000000-Nl AGT -Nw — -Ma 0 -Md 0 -Ms 0 -Mt 0 -Is 0.0 -Id 4.0 -It tcp -Il 40 -If 0 -Ii0 -Iv 32 -Pn tcp -Ps 0 -Pa 0 -Pf 0 -Po 0

2. r -t 0.000000000 -Hs 0 -Hd -2 -Ni 0 -Nx 0.00 -Ny 0.00 -Nz 0.00 -Ne -1.000000-Nl RTR -Nw — -Ma 0 -Md 0 -Ms 0 -Mt 0 -Is 0.0 -Id 4.0 -It tcp -Il 40 -If 0 -Ii0 -Iv 32 -Pn tcp -Ps 0 -Pa 0 -Pf 0 -Po 0

3. s -t 0.031538939 -Hs 1 -Hd -1 -Ni 1 -Nx 200.00 -Ny 0.00 -Nz 0.00 -Ne-1.000000 -Nl RTR -Nw — -Ma 0 -Md 0 -Ms 0 -Mt 0 -Is 1.255 -Id -1.255 -Itmessage -Il 32 -If 0 -Ii 1 -Iv 32

4. r -t 0.032599606 -Hs 0 -Hd -1 -Ni 0 -Nx 0.00 -Ny 0.00 -Nz 0.00 -Ne -1.000000-Nl RTR -Nw — -Ma 0 -Md ffffffff -Ms 1 -Mt 800 -Is 1.255 -Id -1.255 -It message-Il 32 -If 0 -Ii 1 -Iv 32

5. r -t 0.032599606 -Hs 2 -Hd -1 -Ni 2 -Nx 400.00 -Ny 0.00 -Nz 0.00 -Ne-1.000000 -Nl RTR -Nw — -Ma 0 -Md ffffffff -Ms 1 -Mt 800 -Is 1.255 -Id -1.255-It message -Il 32 -If 0 -Ii 1 -Iv 32

10

Page 11: 802.11 Simulation using NS2

Each line represents a message being transferred

Common fields:

• Event type (s = send, r = received, d = drop)

• Time stamp

• Source and destination

• XYZ co-ordinates of the node

• Network layer (AGT = agent, RTR = router, )

• many many others

11

Page 12: 802.11 Simulation using NS2

6 Conclusion and Future Enhancement

By Running the simulation of wireless network without random motion of therouter, it easily shows us the clear output in trace file. We can use this trace filein various manner for the system.We can use same topology in Wired networkfor throughput, as we know that Wired network are more expensive. We canbuild the logical network in ns2 and simulate it.

This can be further enhanced for Intera Network organization(EducationsInstitute and Offices) to check the packet simulation

12

Page 13: 802.11 Simulation using NS2

7 Reference

http://ns2-experience.blogspot.in/2008/01/why-ns2.html

http://en.wikipedia.org/wiki/IEEE802.11

pages.cs.wisc.edu/ akella/CS740/S07/notes/nstut.ppt

www.winlab.rutgers.edu/ zhibinwu/html/networksimulator2.html

en.wikipedia.org/.../Destination-SequencedDistanceV ectorrouting

www.cs.caltech.edu/ weixl/technical/ns2linux/index.html

13