ns network simulator - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

ns network simulator

Description:

set opt(prop) Propagation/TwoRayGround ;# radio-propagation ... d -t 1500.000000000 -Hs 5 -Hd 16777216 -Ni 5 -Nx 2.00 -Ny 1500.00 -Nz 0.00 -Ne ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 26
Provided by: edwi78
Category:
Tags: hd | ip | network | radio | simulator | trace

less

Transcript and Presenter's Notes

Title: ns network simulator


1
ns network simulator
  • Edwin Hernandez
  • January 19th, 2001
  • Harris Lab Seminar



2
Background on ns
  • Whats ns
  • The VINT project Virtual InterNet Testbed
  • UC Berkeley, Lawrence Berkeley National Lab,
    USC/ISI, Xerox PARC, ATT Research
  • http//www.isi.edu/nsnam/ns
  • Download the full version, Linux, Solaris,
    current snapshots, there is a Win32 version.
  • Languages used C, Otcl and TCL/TK
  • Current release ns 2.1b7a, Harris Lab ns2.1b6

3
Characteristics of ns
  • By using C/Otcl, the network simulator is
    complete Object-oriented.
  • C is used for data per packet events
  • Otcl is used for periodic or triggered events
  • The TCL interpreter TclCL is the language used
    to provide a linkage between C and Otcl

4
Installation process for ns
  • Takes time to compile and configure!
  • Be careful with ./configure you must try to
  • ./configure --with-tclcl../tclcl_dir
    with-otcl../
  • Provide ../configure --help
  • make clean make install (i.e. root in linux)
  • Required ns-2, otcl, tclcl, tcl/tk8.0., nam
    (network animator)

5
The starting point
  • Lets create a two node simulation
  • First we proceed to create the scheduler
  • set ns_ new Simulator
  • The scheduler requires a set of events to
    process
  • ns_ at lttimegt lteventgt
  • Where event is anything in ns/tcl commands.
  • For example puts Hello World\n
  • To start a simulation we can just execute
  • ns_ run

6
A test script for ns
  • Type in pico or vi.
  • Test it with ns script.tcl
  • Will return Hello World

set ns_ new Simulator ns_ at 1 puts \hello
world\ ns_ at 1.5 exit ns_ run
7
Creating the network nodes
  • Nodes
  • set n0 ns_ node
  • set n1 ns_ node
  • Links Queuing
  • ns duplex-link n0 n1 ltbandwidthgt ltdelaygt
    ltqueue_typegt
  • ltqueue_typegt DropTail, RED, CBQ, FQ, SFQ, DRR
  • Once we have the network configuration we can
    create some traffic.

8
Creating TCP traffic
  • Agent/TCP
  • set tcp new Agent/TCP
  • We need a source of traffic
  • set tcpsink new Agent/TCPSink
  • We need a sink for this traffic
  • ns attach-agent n0 tcp
  • We attach the TCP agents to the node source
  • ns attach-agent n1 tcpsink
  • We attach the TCPSink Agent to the node
    destination
  • ns connect tcp tcpsink
  • We connect both end points

9
Creating TCP Traffic
  • Application FTP
  • set ftp new Application/FTP
  • ftp attach-agent tcp
  • ns at lttimegt ftp start
  • Application Telnet
  • set telnet new Application/Telnet
  • telnet attach-agent tcp
  • Application HTTP
  • Client set client new HTTP/Client ns_ n0
  • client connect server
  • Serverset server new HTTP/Server ns_ n1
  • server set-page-generator pgp
  • For further details check chp. 34 of the ns manual

10
Creating UDP traffic
  • Agent/UDP is required
  • set udp new Agent/UDP
  • set null new Agent/NULL or
  • set lossMonitor new Agent/LossMonitor
  • ns_ attach-agent n0 udp
  • ns_ attach-agent n1 null
  • ns_ connect udp null or
  • ns_ connect udp lossMonitor
  • The Agent/LossMonitor can monitor number of
    packets transferred, as well as packets lost.
  • A procedure can be scheduled to poll the
    LossMonitor every T seconds and obtain throughput
    information.

11
Polling the LossMonitor
proc record sink global fthrput
fpcklost Get an instance of the
simulator set ns Simulator instance
Set the time for polling set
time 0.25 How many bytes have been
received by the traffic set bw1 sink set
bytes_ set lpkts sink set nlost_
set now ns now puts
fthrput "now expr bw1/time8"
puts fpcklost "now lpkts"
Reset the bytes_ values on the traffic sinks
sink set bytes_ 0 sink
set nlost_ 0 Re-schedule the record
function ns at expr nowtime
"record sink"
12
Creating UDP traffic
  • CBR Constant Bit Rate, back-to-back transfers.
  • set cbr new Application/Traffic/CBR
  • cbr_ set packetSize_ 512
  • cbr_ set interval_ 0.1
  • cbr_ set random_ 1
  • cbr_ set maxpkts_ 1000000
  • cbr_ attach-agent udp
  • ns_ connect udp lossMonitor
  • Exponential or Pareto on-off
  • set src new Application/Traffic/Exponential
  • set src new Application/Traffic/Pareto

13
Creating UDP traffic
  • Trace driven
  • set tfile new Tracefile
  • tfile filename ltfilegt
  • set traceSrc new Application/Traffic/Trace
  • traceSrc attach-tracefile tfile
  • ltfilegt
  • Binary format
  • inter-packet time (msec) and packet size (byte)
  • We need also to schedule the traffic with, ns_ at
    cbr start

14
Wireless extensions
  • IEEE 802.11 can be simulated, Mobile-IP, and
    adhoc protocols such as DSR, TORA, DSDV and AODV.
  • CMU provides tools to create traffic patterns and
    scenario files.
  • Special trace-file format for wireless packets,
    very detailed. Drawback Files are extremely big.
    (100s of Mbytes for 1000 sec of simulation)

15
Simulation of two wireless nodes
  • A simple simulation for two nodes and no
    infrastructure we need to configure the nodes
    first (in ns2.1b7).
  • ns_ node-config -adhocRouting opt(rp) \
  • -llType opt(ll) \
  • -macType opt(mac) \
  • -ifqType opt(ifq) \
  • -ifqLen opt(ifqlen) \
  • -antType opt(ant) \
  • -propType opt(prop) \
  • -phyType val(netif) \
  • -channelType chan \
  • -topoInstance topo \
  • -agentTrace ON \
  • -routerTrace OFF \
  • -macTrace OFF

16
Simple wireless simulation
  • Array opt( )
  • set opt(chan) Channel/WirelessChannel
    channel type
  • set opt(prop) Propagation/TwoRayGround
    radio-propagation
  • set opt(netif) Phy/WirelessPhy
    network interface
  • set opt(mac) Mac/802_11 MAC
    type
  • set opt(ifq) Queue/DropTail/PriQueue
    interface queue type
  • set opt(ll) LL link
    layer type
  • set opt(ant) Antenna/OmniAntenna
    antenna model
  • set opt(ifqlen) 50 max
    packet in ifq
  • set opt(rp) DSDV
    routing protocol

17
Configuring the wireless/phy
  • Phy/WirelessPhy set CPThresh_ 10.0
  • Phy/WirelessPhy set CSThresh_ 1.559e-11
  • Phy/WirelessPhy set RXThresh_ 3.652e-10
  • Phy/WirelessPhy set Rb_ 21e6
  • Phy/WirelessPhy set Pt_ 0.2818
  • Phy/WirelessPhy set freq_ 914e6

18
Important initialization variables
  • set topo new Topography
  • topo load_flatgrid opt(x) opt(y)
  • opt(x) and opt(y) are the dimensions of the
    simulation area
  • set chan new opt(chan)
  • Create-god Number_of_entities

19
Creating the mobile nodes
  • Set mobile node
  • set Mnode dsdv-create-mobile-node ltnode_idgt
  • Or set Mnode ns_ node ltnode_idgt
  • Attach it to the topography
  • node topography topo
  • Determine the motion pattern and initial position
  • node random-motion 0 no random
  • node set Z_ 0.000000
  • node set Y_ 100.0000
  • node set X_ 2.000000

20
Adding movement to the nodes
  • Random set to 0
  • ns at lttimegt node setdest ltxgt ltygt ltspeedgt
  • Random set to 1
  • ns at lttimegt node start

21
Tracing the node movement and traffic information
  • Trace packets on all links (Old Trace format)
  • ns_ trace-all open test.out w
  • lteventgt lttimegt ltfromgt lttogt ltpktgt ltsizegt--ltflowidgt
    ltsrcgt ltdstgt ltseqnogt ltaseqnogt
  • 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0
  • - 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0
  • r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0
  • Trace packets on all links in nam-1 format
  • ns_ namtrace-all open test.nam w
  • Due the size of trace files, ns_ trace-all
    open gzip c gt out.tr.gz w
  • Or ns_ trace-all open awk f awkScript gt
    output.tr w

22
New trace format
  • Activating trace/nam files
  • ns_ trace-all tracefd
  • ns_ namtrace-all-wireless namtrace opt(x)
    opt(y)
  • ns_ use-newtrace
  • New trace file sample
  • r 1499.998807 5 4 cbr 532 ------- 0 1.0.1.2
    0.0.0.2 163975 235152
  • d -t 1500.000000000 -Hs 5 -Hd 16777216 -Ni 5 -Nx
    2.00 -Ny 1500.00 -Nz 0.00 -Ne -1.000000 -Nl IFQ
    -Nw END -Ma a2 -Md 5 -Ms 5 -Mt 800 -Is 16777216.0
    -Id 4194305.0 -It udp -Il 92 -If 0 -Ii 198410 -Iv
    32
  • S send, r received, d dropped, -t lttimegt, -Is
    node source, -Id destination, -Ii packet ID,
    -Nl cause of dropped Nw cause of dropped Nx
    position in x, - Ny positon in y. etc. More
    details in Chp. 16 of the NS manual.

23
We can visualize the trace/nam files
Network animator screenshots of an ad-hoc network
simulation (courtesy of S. Shah)
24
ns-2 can be modified
  • Any modification to the source code of NS can be
    followed by a make distclean make all command to
    make effective all the changes.
  • We can modify the propagation model by making
    changes to tworayground.cc and tworayground.h

class TwoRayGround public Propagation
public TwoRayGround() virtual double
Pr(PacketStamp tx, PacketStamp rx,
WirelessPhy ifp) protected double
TwoRay(double Pt, double Gt, double Gr, double
ht, double hr, double L double last_hr,
last_ht double crossover_dist
25
For more internals and how to modify ns
  • Check the NS manual http//www.isi.edu/nsnam/ns/d
    oc/ns_doc.pdf
  • Tutorial by Marc Greis http//www.isi.edu/nsnam/
    ns/tutorial/index.html
  • This tutorial is very good for ns internals
  • http//www.isi.edu/nsnam/dist/ns-workshop00/
Write a Comment
User Comments (0)
About PowerShow.com