Anda di halaman 1dari 26

m 

Sung Park
Network and Embedded Systems Lab (NESL)
Electrical Engineering, UCLA
About This Tutorial

‡ Based on ns Tutorial (IX, XI) and


ns manual (Chapter 14)
 Can be obtained from
http://www.isi.edu/nsnam/ns
 Latest ns release is ns2.1b9
‡ Will not discuss installation
process
 Installation in linux machine is
straightforward
 Support for SunOS and Windows(??)
M
ns-2 overview
‡ Collection of various protocols at multiple
layers
 TCP(reno, tahoe, vegas, sack)
 MAC(802.11, 802.3, TDMA)
 Ad-hoc Routing (DSDV, DSR, AODV, TORA)
 Sensor Network (diffusion, gaf)
 Multicast protocols, Satellite protocols, and many
others
‡ Codes are contributed from multiple research
communities
 Good: Large set of simulation modules
 Bad: Level of support and documentation varies
‡ The source code and documentation is
currently maintained by VINT project at ISI
u
Introduction
‡ ns-2 is an discrete event driven simulation
 Physical activities are translated to events
 Events are queued and processed in the order of their
scheduled occurrences
 Time progresses as the events are processed

Time: 1.5 sec Time: 1.7 sec

1 2

Time: 2.0 sec Time: 1.8 sec

°
Event Driven Simulation

RX
TX Ack
Pkt Event
Event
@ 1.5sec
2.0sec Node 1
Module
Event Queue
RX
TX
RX
TX Ack
Pkt Event
Event
@ 2.0sec
1.7sec
1.8sec
1.5sec

Simulation Finished!
Node 2
Module
TX
RX Ack
Pkt Event
@ 1.8sec
1.7sec

r
ns-2 Environment
Simulation 1 2
Scenario

O O 
 

Tcl Script O   O  


O   O  

 OO    
   

C++   OO O   

 
Implementation     
!
!
"
ü
Why two languages? (Tcl & C++)

‡ C++: Detailed protocol simulations


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
‡ Tcl: Simulation of slightly varying
parameters or configurations
 quickly exploring a number of scenarios
 iteration time (change the model and re-run) is
more important

‰
Tcl or C++?

‡ Tcl
 Simple Configuration, Setup, Scenario
 If it¶s something that can be done without
modifying existing Tcl module.
‡ C++
 Anything that requires processing each
packet
 Needs to change behavior of existing
module

º
Wireless Simulation in ns-2
‡ Contributed from CMU¶s Monarch
project (Wireless extension to ns-2)
‡ Various modules were added to ns-2 to
simulate node mobility and wireless
networking
 Mobile Node
 Ad-hoc Routing(DSR, DSDV, TORA, AODV)
 MAC802.11
 Radio Propagation Model
 Channel


Mobile Node Modules

‡ Agent
 Responsible for packet generations and receptions
 Can think of it as an Application layer
 CBR(Constant Bit Rate), TCP, Sink, FTP, etc.
‡ RTagent(DSDV, TORA, AODV) or DSR
 Ad-hoc network routing protocols
 Configure multi hop routes for packets
‡ LL (Link Layer)
 Runs data link protocols
 Fragmentation and reassembly of packet
 Runs Address Resolution Protocol(ARP) to resolve
IP address to MAC address conversions

=
Mobile Node Modules (Continued)

‡ IFq (Interface Queue)


 PriQueue is implemented to give priority
to routing protocol packets
 Supports filter to remove packets
destined to specific address
‡ Mac Layer
 IEEE 802.11 protocol is implemented
 Uses RTS/CTS/DATA/ACK pattern for all
unicast pkts and DATA for broadcast pkts

==
Mobile Node Modules (Continued)

‡ NetIF (Network Interfaces)


 ´ardware interface used by mobilenode to access
the channel
 Simulates signal integrity, collision, tx error
 Mark each transmitted packet with transmission
power, wavelength etc.
‡ Radio Propagation Model
 Uses Friss-space attenuation(1/r2) at near
distance and Two ray ground (1/r4) at far distance
 Decides whether the packet can be received by
the mobilenode with given distance, transmit
power and wavelength
 Implements Omni Directional Antenna module
which has unity gain for all direction
=M
Wireless Simulation in ns-2 (Mobile Node
Diagram - DSDV)
Agent
(Src/Sink)

Demux
Port
Demux
Addr
RTagent
(DSDV)

LL ARP

IFq

MAC

Radio
Propagation NetIF
Model

Channel

=u
Wireless Simulation in ns-2 (Mobile Node
Diagram - DSR)
Agen
  nk)

emux
Po
 

 AP



AC


  o
Popaga on Ne
oe

Channe


Running a simulation-Scenario
500m

TCP TCP TCPsink TCPsink


TCPsink
500m

node_(0) node_(0) node_(1) node_(1)


node_(1)

=r
Setting Up Variables
U 
U 

U 

      

   U   



      U    ! 

    "  #!"   U"   

   $$ U$%  

  &'  ' U(  & 

  & )* U! + % &

    

 U %   



  ! , -*./00 U," 

  12 U     

  . U!3!3 



Setting Up Variables
Instantiate simulator object

 
/41! 5

Setup Trace File



   4
! 7 5
6
/   6  

Create Topography

  4 5
6   / )**)**

Create Object God


  6 


Configuring Mobilenode
U

6
/   6 8
6  8
! 6 ! 8
&6 &8
&$6 & 8
 6   8
6 8
6  8
(
6 8
  6  8
  #98
  #98
!  #::8
! !  #::
;
 *<;6=6 <;<;

 /646
/5
6/6 ! ! *U
3  !! 
<

Configuring Movement
Configure Initial Position
6/*
 A/)7*
6/*
 B/.7*
6/*
 C/*7*
6/0
 A/D@*7*
6/0
 B/D-)7*
6/0
 C/*7*

Create Movement
U9/0

 !   
/*
6
/ )*7*>6/0
 
.)7*.*7*0)7*>
6
/ 0*7*>6/*
 
.*7*0-7*07*>
U9/0 

 !   !/*
6
/ 0**7*>6/0
 
?@*7*?-*7*0)7*>

=
Setup traffic flow

  4" 5
6 
 

/.
 
%4" 1%5
6
/   6/*
6 6
/   6/0
6
%6
/ 6 
6
%
  4"  :5
6    6 6
/ 0*7*>6 
 >

FTP

TCP Sink

node_(0) node_(1)
M
Set Stop Time and Start Simulation
Set Simulation Stop Time
;
 *<;6=6 <;<;
6
/ 0)*7*>6/6
 >
<
6
/ 0)*7***0>
>
6
/ 0)*7***.>
8>91EA((97778>
6
/ >
;<; 3 
/   
6  <

Finally, Start The Simulation



>1  1! 777>
6
/

M=
Running the Script

‡The file ³simple-wireless.tcl´ is under


<NSRoot>/ns-allinone2.1b9/ns-
tutorial/examples/simple-wireless.tcl
‡ cd into the directory and type ³ns
simple-wireless.tcl´ to run the
simulation
‡The simulation will generate a trace file
named ³simple.tr´

MM
Trace File
0**7D-0@@F?FF/0/" -. 0*G*40D 0*-**5
4*H*0H*D.054D.*50*

:receive event, = =:time stamps,


=node 1,
:trace generated by agent,
:event(pkt) id,  : tcp packet,
= :packet size,
=
expected duration of pkt transmission (not working),
=sender mac id, :transmitter mac id,
 :pkt type IP (806 for ARP),  : sender address:port#
= : receiver address:port#, : TTL
=: next hop address,   TCP sequence #, ack #

Mu
SensorViz:GUI based Scenario
Generation Tool

http://nesl.ee.ucla.edu/projects/sensorsim/


Using SensorViz output
SensorViz output may look like the following
U!3
 .
U!
+ .****
U!
 .****
U  
!

  D***7*


U3  ?
6/*
 A/0.?0)7?)-@DF0@-*GF
6/*
 B/00G0.7@*D..)-*G?)
6/*
 C/*7*
6/0
 A/F-F?7D@G0D).G)F*0
6/0
 B/-)-)7G*F@?*??GG?@
6/0
 C/*7*

Simply include the file by using ³Source´


command in your main tcl scpript

I  !J

Mr
Tips on using ns-2
‡ Requires a good knowledge of C++
‡ Good idea to start with the existing tcl script
‡ Make sure to configure the position of all the
nodes that you create
‡ If you want to find a filename with a specific
term, use ³find´ command
find . ±name ³*tcp*´ ±print
‡ ns has support for basestation setting wireless
network. gaf and diffusion codes are included
‡ If it¶s possible, use the existing trace file for
your analysis. Otherwise, you can use cout or
(printf) to output your results