Вы находитесь на странице: 1из 79

Meivazhi Salai Andavargal

EC1354 Networks Lab

The ns2 Tutorial


Prepared by

V. Salai Selvam
Assistant Professor & HOD
Department of Electronics & Communication Engineering
Sriram Engineering College, Perumalpattu 602 024

Procedure (default) to open x-desktop for ns2 simulation


Select StartCygwinCygwin bash shell
Type at cygwin bash shell startx and press <enter> to open x-desktop
Type at x bash shell CD<sp>/usr/local/ns* and
Press <enter> to move to ns2 installation folder

Procedure (default) to create and save your TCL simulation scripts


Open notepad
Write your TCL simulation scripts
Select Save as from File menu
Select All Files for Save as type from pop-up dialog
Select ANSI for Encoding
Type a name for the script file with .tcl extension
Select Save

Command to run a simulation scripts


#Command to run a simulation script
ns <scriptfilename>.tcl
scriptfilename

Name of the simulation script file

Steps to write a simulation script for ns2


@ Create a simulator object
@ [Set nam or other tracing]
@ Add nodes
@ [Set node parameters]
@ Add links
@ [Set link parameters]
@ Add agents
@ [Set agent parameters]
@ Create connections
@ [Set connection parameters]
@ Add traffics
@ [Set traffic parameters]
@ [Insert errors, network dynamics, routing]
@ Set up event scheduling
@ [Create control loops or procedures]
@ Run simulation

Steps to write a simulation script for ns2 (contd)


Please remember, in a TCL script,
Anything that follows the symbol # in a line is a comment
Anything that is written in this color is a keyword
Anything that is written in this color is a user-defined pointer variable
Anything that is written in this color & inside < > is an option

Create a simulator object


#Create a simulator object
set nsptr [new Simulator]
nsptr

Pointer to simulator object

Related commands
$nsptr version

- Returns ns version

$nsptr now

- Returns present time

$nsptr halt

- Stop/pause simulation

$nsptr cancel

<event> - Cancels event event

$nsptr flush-trace Flushes all trace buffers in respective trace files


$nsptr after <dly> <event> Schedule <event> after a delay <dly>
$nsptr is-started - Returns true if simulator has started to run
nsptr

Pointer to simulator object

Set nam or other tracing


#Set nam tracing
#Open nam trace file
set ntfptr [open ntfname.nam <permission>]
#Set trace type
$nsptr <namtracetype> $ntfptr
ntfptr
ntfname
nsptr
<permission>

<namtracetype>

Pointer to nam trace file ntfname created


Name of nam trace file
Pointer to simulator object created
r

Read Only

Read & Write

namtrace-all

Trace all traffic

namtrace-queue $src $dst

Trace traffic between src & dst


nodes; hence declare only after
declaring link between src & dst

10

Set nam or other tracing (contd)


#Set other tracing
#Open other trace file
set tfptr [open tfname.tr <permission>]
#Set trace type
$nsptr <tracetype> $tfptr
tfptr
tfname
nsptr
<permission>

<tracetype>

Pointer to trace file tfname created


Name of trace file
Pointer to simulator object created
r

Read Only

Read & Write

trace-all

Trace all traffic

trace-queue $src $dst

Trace traffic between src & dst nodes;


hence declare only after declaring link
between src & dst

11

Add nodes
#Add nodes
set ndh [$nsptr node]
ndh

Handle to node created

nsptr

Pointer to simulator object

12

Set node parameters


#Set node parameters
$ndh <param> <val>
ndh
<param>

<val>

Handle to node
color

Color of node

shape

Shape of node

red
blue
green

And more for color

circle
box
hexagon

And more for shape

13

Set node parameters (contd)


#Set node parameters
#Add label from specified time
$nsptr at <time> $ndh label \<text>\
nsptr

Pointer to simulator object

ndh

Handle to node

<time>

<num_double>

<text>

<anytext>

Schedule time in secs


Any text as label

14

Add links
#Add links
$nsptr <ltype> $fnd $snd <bw> <dly> <qtype>
nsptr
fnd, snd

Pointer to simulator object


Handles to pair of nodes to be linked

<ltype>

simplex-link
duplex-link

Link type: simplex-link, unidirectional link;


duplex-link, bidirectional link

<bw>

<num_double>

Link bandwidth in bps: add Mb for Mbps

<dly>

<num_double>

Link delay in secs: add ms for milli secs

<qtype>

DropTail
FQ
SFQ
DRR
CBQ
RED

Queue type: Drop Tail, Fair Queue,


Stochastic Fair Queue, Deficit Round
Robin, CBQ, Random Early Discard

15

Related commands
#Return instance variable head_ of link between fnd and snd
[$nsptr link $fnd $snd] head
#Return instance variable link_ of link between fnd and snd
[$nsptr link $fnd $snd] link
#Return instance variable queue_ of link between fnd and snd
[$nsptr link $fnd $snd] queue
nsptr
fnd, snd

Pointer to simulator object


Handles to link nodes

16

Set link parameters


#Set link parameters
$nsptr <ltype>-op $fnd $snd <param> <val>
nsptr
fnd, snd
<ltype>

<param>

Pointer to simulator object


Handles to link nodes
simplex-link
duplex-link
color

Color of link

label

Label for link

queuePos

<val>

Link type: simplex-link, unidirectional link;


duplex-link, bidirectional link

red
blue
green
anytext
<num_double>

Queue position
And more for color
Any text as label
Number for queuePos

17

Set link parameters (contd)


<param>

orient

<val>

right
Left
up
down
right-up
right-down
left-up
left-down
up-right
down-right
up-left
down-left
<deg_double>

Setting node position for animation


Orient second node to right of first node
Orient second node to left of first node
Orient second node straight up first node
Orient second node straight down first node
Orient second node to right of first node and up
Orient second node to right of first node and down
Orient second node to left of first node and up
Orient second node to left of first node and down
Orient second node up first node and right
Orient second node down first node and right
Orient second node up first node and left
Orient second node down first node and left
Orient second node at deg_double to left of first node

18

Set link parameters (contd)


#Set queue size of link
$nsptr queue-limit $fnd $snd <limit>
nsptr
fnd, snd
<limit>

Pointer to simulator object


Handles to link nodes
<num_int>

Queue size in packets

19

Set link parameters (contd)


#Set queue parameters of link
set qptr [[$nsptr link $fnd $snd] queue]
$qptr set <param> <val>
nsptr

Pointer to simulator object

fnd, snd

Handles to link nodes

qptr

Pointer to queue of link between fnd & snd

For all queue types


<param>

<val>

limit_
Queue size in packets
blocked_
Enabling/disabling queue block
unblock_on_resume_ Enabling/disabling automatic queue unblock
<num_int>
true, false
true, false

Number of packets
If true, queue is blocked; unable to sent packet to link
If true, queue is unblocked after last pkt is txed.

20

Set link parameters (contd)


For Fair Queue (FQ)
<param>

secsPerByte_

<val>

<num_double>

Seconds per byte

For Stochastic Fair Queue (SFQ)


<param>

maxqueue_
buckets_

<val>

<num_int>
<num_int>

Maximum queue in packets


Number of buckets used for hashing of flow

For Deficit Round Robin (DRR)


<param>

buckets_
blimit_
quantum_
mask_

<val>

<num_int>
<num_int>
<num_int>
true, false

Number of buckets used for hashing of flow


Shared buffer size in bytes
Flow rate in bytes
If true, flow consists of packets with same node id

21

Set link parameters (contd)


For Random Early Discard (RED)
bytes_
queue-in-bytes_
thresh_
maxthresh_
mean_pktsize_
<param>
q_weight_
wait_
linterm_
setbit_
drop-tail_

<val>

true, false
true, false
<num_double>
<num_double>
<num_int>
<num_double>
true, false
<num_double>
true, false
true, false

If true, byte-mode RED is enabled


If true, average queue size is measured in bytes
Minimum threshold for average queue size in packets
Maximum threshold for average queue size in packets
Rough estimate of average packet size in bytes
Queue weight, used for calculating average queue size
If true, interval between dropped pkts is maintained
Packet dropping probability varies bet 0 and (1/linterm)
If true,
If true, drop-tail is used when queue overflows

22

Add agents
#Add agents
#Create desired agent
set agptr [new Agent/<agent>]
#Attach agent to desired node
$nsptr attach-agent $ndh $agptr
agptr

Pointer to agent created

nsptr

Pointer to simulator object

ndh

Handle to node to be attached with agent

<agent>

TCP
TCP/Reno
TCP/Newreno
TCP/Sack1
TCP/Fack

TCP senders

23

Add agents (contd)

<agent>

TCP/FullTcp
TCP/Vegas
TCP/Vegas/RBP
TCP/Reno/RBP
TCP/Asym
TCP/Reno/Asym
TCP/Newreno/Asym

TCP senders

TCPSink
TCPSink/DelAck
TCPSink/Asym
TCPSink/Sack1
TCPSink/Sack1/DelAck

TCP receivers

UDP

UDP sender

Null

Null receiver that simply discards received packets

RTP

RTP sender/receiver

24

Add agents (contd)


LossMonitor

<agent>

Packet sink which checks for losses

IVS/Source

IVS sender

IVS/Receiver

IVS receiver

CrtMcast/Encap

Centralized multicast encapsulator

CrtMcast/Decap

Centralized multicast de-encapsulator

Message

Protocol to carry text messages

Message/Prune

Processes multicast prune messages

SRM

SRM agent with non-adaptive timers

SRM/Adaptive
Tap
rtProto/DV

SRM agent with adaptive timers


Agent to interface simulator to live network
Distance vector routing protocol agent

25

Add agents (contd)

26

Add agents (contd)

27

Add agents (contd)

28

Set agent parameters


#Set agent parameters
#For configurable parameters
$agptr set <parameter> <value>
#For read only parameters
set pptr $agptr <parameter>
agptr

Pointer to agent created

pptr

Pointer to parameter read

<parameter> Configuration parameters common for all agents


fid_
prio_
agent_addr_
agent_port_
dst_addr_
dst_port_

An integer as flow ID
An integer as priority
An integer as address of this agent
Port no of this agent in integer
Destination address of this agent in integer
Destination port of this agent in integer

<parameter> Configuration parameters common for all source agents


packetSize_

Packet size in bytes

29

Set agent parameters (contd)


<parameter> Configuration parameters for all source TCP agents
window_
maxcwnd_
windowInit_
windowOption_
maxburst_
MSW

Upper bound on advertised window for TCP connection in packets


Upper bound on congestion window in packets-Set to 0 to ignore
Initial congestion window size in packets
Algorithm to handle congestion window (0 to 8)
Maximum no of packets to send in response to single ACK
Maximum window size in packets for TCP-window_ <=MSW-1

<parameter> State variables (read only) for all source TCP agents
dupacks_
seqno_
t_seqno_
ack_

No of duplicate acks seen since new data was acknowledged


Highest sequence no for data from data source to TCP
Current transmit sequence no
Highest ack seen from receiver

<parameter> Configuration parameters for only TCP-DelAck agents


interval_

Delay in secs before generating ACK

<parameter> State variables (read only) for only Null agent


sport_
dport_

Port of source agent


Port of destination agent

30

Set agent parameters (contd)


<parameter> State variables (read only) for only LossMonitor agent
nlost_
npkts_
bytes_
lastPktTime_
expected_

Number of packets lost


Number of packets received
Number of bytes received
Time at which last packet was received
Expected sequence number of the next packet

#Set flow color for agents


$nsptr color <fid_> <val>
nsptr

Pointer to simulator object

<fid_>

<num_int>

<val>

red
blue
green

Flow ID of agent considered


And more as flow color

31

Create connection
#Create connection
$nsptr connect $srcag $dstag
nsptr

Pointer to simulator object

srcag

Pointer to desired source agent

dstag

Pointer to desired destination agent

32

Add agents & Create connection-alternate


#Create desired agent, attach it to desired src node, connect it to desired dst
#node and returns ptr to src node created
set agptr [$nsptr create-connection <srcag> $srcndh <dstag> $dstndh
<pktclass>]
nsptr

Pointer to simulator object created

<srcag>

Source agent

<dstag>

Destination agent

srcndh

Pointer to source node

dstndh

Pointer to destination node

agptr

Pointer to source agent created

33

Add agents & Create connection-alternate (contd)


#Create desired agent, attach it to desired src node, connect it to desired dst
#node and returns list of ptrs to src & dst nodes created
set agptrl [$nsptr create-connection-list <srcag> $srcndh <dstag> $dstndh
<pktclass>]
set sagptr [lindex $agptrl 0]
set dagptr [lindex $agptrl 1]
nsptr

Pointer to simulator object

<srcag>

Source agent

<dstag>

Destination agent

srcndh

Pointer to source node

dstndh

Pointer to destination node

agptrl

List of pointers to source and destination agents created

sagptr

Pointer to source agent created

dagptr

Pointer to destination agent created

34

Add traffics
#Add traffic
#Create traffic
set trptr [new Application/<traffic>]
#Attach it to desired agent
$trptr attach-agent $agptr
trptr

Pointer to traffic created

agptr

Pointer to desired agent


FTP
Telnet

<traffic>

Traffic/CBR
Traffic/Exponential
Traffic/Pareto

FTP traffic for TCP agent


Telnet traffic for TCP agent
CBR traffic for UDP agent
Exponential traffic for UDP agent
Pareto traffic for UDP agent

35

Set traffic parameters


#Set traffic parameters
$trptr set <param> <val>
trptr

Pointer to traffic created

For all traffic


<param>

packetSize_
rate_

<val>

<num_int>
<num_double>

Packet size in bytes


Traffic rate in bps

For CBR traffic


<param>

random_
maxpkts_

<val>

true, false
<num_double>

If true, random noise is introduced in traffic


Maximum number of packets

36

Set traffic parameters (contd)


For Exponential traffic
<param>

burst_time_
idle_time_

<val>

<num_double>
<num_double>

Length of burst (on-time) in secs


Length of off-time in secs

For Pareto traffic


<param>

burst_time_
idle_time_
shape_

<val>

<num_double>
<num_double>
<num_double>

Length of burst (on-time) in secs


Length of off-time in secs
Pareto shape parameter

37

Set up event scheduling


#Set up event scheduling
$nsptr at <time> <event>
nsptr
<time>

Pointer to simulator object


<num_double>

<event> <tcl_command>

Schedule time in secs


Any valid TCL command

38

Set up event scheduling (contd)


#Selecting event scheduler before any event schedule
$nsptr use-scheduler <shdlr>
nsptr

Pointer to simulator object

List
Heap
<shdlr>
Calendar
ReatTime

Scheduler using a simple linked-list structure


Scheduler using a heap structure
Scheduler using a data structure analogous to year desk calendar
Scheduler using real time

39

Set up event scheduling (contd)


#Some important event schedules
#Start traffic trptr at time
$nsptr at <time> $trptr start
#Stop traffic trptr at time
$nsptr at <time> $trptr stop
nsptr

Pointer to simulator object

trptr

Pointer to desired traffic

<time>

<num_double>

Schedule time in secs

40

Set up event scheduling (contd)


#Annotating
$nsptr at <time> $nsptr trace-annotate \<text>\
#Set nam animation rate
$nsptr at <time> $nsptr set-animation-rate <rate>
#Finishing simulation
$nsptr at <time> finish
nsptr

Pointer to simulator object

finish

User-defined finish procedure; Refer to finish procedure

<time>

<num_double>

Schedule time in secs

<text>

<anytext>

Any text as annotation

<rate>

<num_double>

Animation rate in secs

41

Run simulation
#Run simulation
$nsptr run
nsptr

Pointer to simulator object

42

Creating procedures
#Creating procedures
proc pname {parg1 parg2 } {pbody}
pname
parg1, parg2
pbody

Procedure name by which it is called


Procedure arguments
Procedure body i.e., list of TCL commands to be executed

43

Creating procedures (contd)


#finish procedure-a custom way to finish your simulation
proc finish {} {
#declaring nsptr, ntfptr as global variables
global nsptr ntfptr
#flush trace buffers to respective files
$nsptr flush-trace
#close all files
close $ntfptr
#open animation for this simulation
exec nam <ntfname>.nam &
#exit procedure normally
exit 0
}
nsptr

Pointer to simulator object

ntfptr

Pointer to nam trace file ntfname

ntfname

Name of nam trace file

44

Insert error model


#Create error model
set errmod [new <errormodel>]
#Set errmodel parameters
$errmod set <param> <val>
#Set target for droped packets
$errmod drop-target [new Agent/Null]
errmod

Pointer to error model created

<errormodel>

ErrorModel
ErrorModel/Periodic
ErrorModel/Uniform
SelectErrorModel
ErrorModel/List

Simple error model


Modeling periodic packet drop
Uniform error model
For selective packet drop
Dropping specified list of packets

45

Insert error model (contd)


For all error models
<param>
<val>

unit_ Error unit in pkts, bytes or time


pkts,
bytes,
time

For ErrorModel

<param>

enable_
rate_
delay_
bandwidth_
markecn_
delay_pkt_

<val>

true or false
<num_double>
<num_in_secs>
<num_in_bps>
true or false
true or false

True if this error module is turned on


Uniform error rate in pkt or byte
Time to delay packet
Bandwidth of the link
If true, ecn is marked instead of dropping on corruption
If true, packet is delayed instead of dropping

46

Insert error model (contd)


For ErrorModel/Periodic
<param>

period_
offset_
burstlen_
default_drop_

<val>

<num_double>
<num_double>
<num_double>
true or false

Drop period in secs


Drop offset in secs
Drop length in secs
All pkts are dropped except last in period_ if true (1)

47

Insert error model (contd)


For SelectErrorModel

<param>

enable_
rate_
delay_
bandwidth_
markecn_
delay_pkt_
pkt_type_
drop_cycle_
drop_offset_

<val>

true, false
<num_double>
<num_double>
<num_double>
true, false
true, false
0, 1 or 2
<no_of_pkts>
<no_of_pkts>

True if this error module is turned on


Uniform error rate in pkt or byte
Time to delay packet
Bandwidth of the link
Mark ecn instead of dropping on corruption?
Delay packet instead of dropping?
0,1 or 2 (TCP, UDP or CBR packet)
Drop pkts after every drop_cycle_
No of pkts to be dropped

48

Insert error model (contd)


For ErrorModel/List
<param>

cnt_
droplist_
dropcnt_
cur_

<val>

<num_int>
<num_int_list>
<num_int>
<num_int>

Count of pkts/bytes we've seen


Array of pkt/byte numbers to affect
Number of entries in droplist_ total
Current index into droplist_

49

Insert error model (contd)


#Optional: Set random variable before setting drop-target
$errmod ranvar [new RandomVariable/<ranvar>]
errmod

Pointer to error model created

ranvar

Pointer to random variable created

<ranvar>

Uniform, Exponential, Pareto,


ParetoII, Constant,
HyperExponential, Empirical,
Normal, LogNormal, Weibull

Random variable type for random


generator

50

Insert error model (contd)


#Place error model on simple link just before the queue
$nsptr lossmodel $errmod $srcndh $dstndh
or
#Place error model on simple link just after the queue
$nsptr link-lossmodel $errmod $srcndh $dstndh
errmod

Pointer to error model created

nsptr

Pointer to simulator object created

srcndh, dstndh

Node handles to desired node pair

51

Insert error model (contd)


#Generate random variable using desired distribution with desired parameters
set rng [new RNG]
$rng seed <seedvalue>
set ranvar [new RandomVariable/<ranvar>]
$ranvar set <param> <val>
$ranvar use-rng $rng
rng
ranvar

Pointer to random generator created


Pointer to random variable created

<seedvalue>

<num_double>

Seed value for random generator

<ranvar>

Uniform, Exponential, Pareto,


ParetoII, Constant,
HyperExponential, Empirical,
Normal, LogNormal, Weibull

Random variable type for random


generator

52

Insert error model (contd)


<param> & <val> Configurable parameters & their values for Uniform
min_
max_

<num_double>
<num_double>

Start value for distribution


End value for distribution

<param> & <val> Configurable parameters & their values for Exponential
avg_

<num_double>

Average value for distribution

<param> & <val> Configurable parameters & their values for Pareto & ParetoII
avg_
shape_

<num_double>
<num_double>

Average value for distribution


Shape value for distribution

<param> & <val> Configurable parameters & their values for Constant
val_

<num_double>

Value for distribution

<param> & <val> Configurable parameters & their values for HyperExponential
avg_
cov_

<num_double>
<num_double>

Average value for distribution


Covariance value for distribution

53

Insert error model (contd)


<param> & <val> Configurable parameters & their values for Normal &
LogNormal
avg_
<num_double>
Average value for distribution
std_

<num_double>

Standard deviation value for distribution

<param> & <val> Configurable parameters & their values for Empirical
minCDF_
maxCDF_
interpolation_
maxEntry_

<num_double>
<num_double>
0, 1 or 2
<num_int>

Min CDF value


Max CDF value
Interpolation method;
Size of CDF table

<param> & <val> Configurable parameters & their values for Weibull
shape_
scale_

<num_double>
<num_double>

Shape for distribution


Scale for distribution

54

Insert network dynamics


#Set network dynamics
$nsptr rtmodel <rtmodel> <ts> $src $dst
or
$nsptr rtmodel-at <time> <lnkst> $src $dst
nsptr
src, dst

Pointer to simulator object


Handles to src & dst nodes of link

<rtmodel>

Trace
Exponential
Deterministic
Manual

<ts>

$tracefile
{<stt> <upp> <dnp> <fin>}
{<stt> <upp> <dnp> <fin>}
<time> <lnkst>

Up/down the link as per a trace file tracefile


Up/down the link exponentially as per <ts>
Up/down the link deterministically as per <ts>
Up/down the link manually <ts>
Trace file already opened
Time schedule, all in secs
Time schedule, all in secs
Schedule time in secs and link status

55

Insert network dynamics (contd)


<stt>, <upp>,
<dnp>, <fin>

<num_double>

stt-start time; upp-link-up interval; dnp-linkdown interval; fin-stop time

<time>

<num_double>

Schedule time in secs

<lnkst>

up or down

Up or down the link

56

Insert network dynamics (contd)


#Simply upping and downing a link e.g., link srcdst
#Getting link_ for link of interest
set lin [$nsptr link $src $dst]
#Setting link srcdst as dynamic
$lin dynamic
#Scheduling link dynamics for link srcdst
$nsptr at <time> $lin <lnkst>
lin
nsptr
src, dst

Pointer to link srcdst


Pointer to simulator object
Handles to nodes on link srcdst

<lnkst>

up or down

<time>

<num_double>

Up or down the link


Schedule time in secs

57

Insert routing
#Select routing protocol
$nsptr rtproto <rtprotcol> <$nodelist>
nsptr

Pointer to simulator object

<rtprotcol>

<$nodelist>

Static
Session
DV
LS
Manual
hierarchical

Static or Shortest Path routing algorithm


Session routing algorithm
Distance Vector routing algorithm
Link State routing algorithm
Manual
Hierarchical routing algorithm

$n0 $n1 ...

Selected routing algorithm applied to selected list


of nodes; if not specified, selected algorithm
applies to all nodes

58

Insert routing (contd)


#Steps for manual routing
#Enable manual routing with rtproto
$nsptr rtproto Manual <$nodelist>
#Set default routes for all pairs of src and dst that are linked in given
#topology, if srcdst is simplex-link, as
[$src get-module Manual] add-route-to-adj-node -default $dst
#or if srcdst is duplex-link, add default route for reverse link also as
[$dst get-module Manual] add-route-to-adj-node -default $src
nsptr
src, dst

Pointer to simulator object


Pair of nodes that are linked in given topology

<$nodelist>

$n0 $n1 ...

Selected routing algorithm applied to selected list


of nodes; if not specified, selected algorithm
applies to all nodes

59

Insert routing (contd)


#Set actual route for a pair of src and dst if desired path between them is
#e.g., srcimn1 and imn1dst, if srcimn1 & imn1dst are simplex-link, as
[$src get-module Manual] add-route-to-adj-node $imn1
[$imn1 get-module Manual] add-route-to-adj-node $dst
#or if srcimn1 & imn1dst are duplex-link, set reverse path
#dstimn1 & imn1src also as
[$dst get-module Manual] add-route-to-adj-node $imn1
[$imn1 get-module Manual] add-route-to-adj-node $src
src, dst, imn1

Nodes that are linked in given topology

60

Creating LAN
#Steps to create a LAN
#Step 1: Create new simulator object
#Step 2: Set NAM tracing
#Step 3: Add nodes
#Step 4: Add links if required
#Step 5: Create LAN including all or some nodes created
#Step 6: Add agents & Add traffics
#Step 7: Set event scheduling
#Step 8: Run simulation
61

Creating LAN (contd)


#Step 5: Creating LAN and adding all or some nodes created
$nsptr make-lan <nodelist> <bw> <dly> <LL> <ifq> <MAC> <chan> <phy>
or
set lanptr [$nsptr newLan <nodelist> <bw> <dly> <LL> <ifq> <MAC> <chan>
<phy>]
nsptr

Pointer to simulator object

<nodelist>

$ndh1 $ndh2

List of nodes to connected in the LAN

<bw>

<num_double>

Bandwidth in bps

<dly>

<num_double>

Delay in secs

<LL>

LL

<ifq>

Queue/DropTail

<MAC>

Mac/Csma/Cd
Mac/Csma/Ca

(Data) Link Layer


Interface queue type
CSMA/CD LAN protocol
CSMA/CA LAN protocol

62

Creating LAN (contd)


<MAC>

Mac/802_3
Mac/802_11

10Mbps LAN connectivity


Wireless LAN protocol

<chan>

Channel
WirelessChannel

Channel type for wired LAN


Channel type for wireless LAN

<phy>

Phy/WiredPhy
Phy/WirelessPhy

Network interface for wired LAN


Network interface for wireless LAN

63

Creating mobile network


#Steps to create a mobile network
#Step 1: Set mobile net options
#Step 2: Set parameters for selected mobile net options
#Step 3: Create new simulator object
#Step 4: Set nam and other tracings
#Step 5: Create topography and GOD for mobile net
#Step 6: Set mobile node configurations
#Step 7: Create nodes as many as nmn
#Step 8: Set initial positions and sizes for mobile nodes
#Step 9: Set scheduled or random movements for mobile nodes
#Step 10: Add agents, Connect them and Add traffics
#Step 11: Set event scheduling for traffics
#Step 12: Reset nodes when simulation ends
#Step 13: Stop nam when simulation ends
#Step 14: Call finish to finish

64

Creating mobile network (contd)


#Step 1: Define mobile net options
set opt(chan) <chan>
set opt(prop) <prop>
set opt(phy) <phy>
set opt(mac) <mac>
set opt(ifq) <ifq>
set opt(ll) <ll>
set opt(ant) <ant>
set opt(ifqlen) <ifqlen>
set opt(nmn) <nmn>
set opt(rtp) <rtp>
set opt(x) <x>
set opt(y) <y>
set opt(seed) <seed>
set opt(stp) <stp>

65

Creating mobile network (contd)


opt()
<chan>
<prop>

Array to options
Channel/WirelessChannel

Channel type

Propagation/TwoRayGround Radio-propagation model

<phy>

Phy/WirelessPhy

Network interface type

<mac>

Mac/802_11

<ifq>

Queue/DropTail/PriQueue
CMUPriQueue

<ll>

LL

Link layer type

<ant>

Antenna/OmniAntenna

Antenna type

<ifqlen>

<num_int>

Maximum queue length in packets

<nmn>

<num_int>

Number of mobile nodes

Mac type
Interface queue type for dsdv
Interface queue for dsr

66

Creating mobile network (contd)


<rtp>

DSDV
DSR
TORA
AODV

<x>

<num_double>

X dimension of topography

<y>

<num_double>

Y dimension of topography

<seed>

<num_double>

Seed for random num generation

<stp>

<num_double>

Simulation end time in secs

Destination Sequence Distance Vector


Dynamic Source Routing
Temporally ordered Routing Algorithm
Adhoc On-demand Distance Vector

67

Creating mobile network (contd)


#Step 2: Set Phy/WirelessPhy parameters
Phy/WirelessPhy set <param> <val>

<param>

CPThresh_
CSThresh_
RXThresh_
Pt_
freq_
L_

<val>

<num_double>
<num_double>
<num_double>
<num_double>
<num_double>
<num_double>

Capture threshold in dB
Carrier sense threshold in watts
Receive power threshold in watts
Transmitted signal power in watts
Frequency in Hz
System loss factor

68

Creating mobile network (contd)


#Step 2: Set LL parameters
LL set <param> <val>
<param>

mindelay_
delay_
bandwith_

<val>

<num_double>
<num_double>
<num_double>

Minimum delay in secs


Delay in secs
Bandwith in bps

69

Creating mobile network (contd)


#Step 2: Set Antenna/OmniAntenna parameters
Antenna/OmniAntenna set <param> <val>

<param>

X_
Y_
Z_
Gt_
Gr_

<val>

<num_double>
<num_double>
<num_double>
<num_double>
<num_double>

X position of antenna
Y position of antenna
Z position of antenna
Transmitting gain of antenna in dB
Receiving gain of antenna in dB

70

Creating mobile network (contd)


#Step 4: Set nam & other tracings
set ntfptr [open ntfname.tr <permission>]
$nsptr namtrace-all-wireless $ntfptr $opt(x) $opt(y)
ntfptr
ntfname
nsptr
opt(val)
<permission>

Pointer to nam trace file ntfname


Name of nam trace file
Pointer to simulator object
Respective opt array element
r
w

Read only
Read/write or create

71

Creating mobile network (contd)


#Step 5: Create topography & GOD for mobile net
set topo [new Topography]
$topo load-flatgrid $opt(x) $opt(y)
create-god $opt(nmn)
topo
opt(val)

Pointer to new topography created


Respective opt array element

72

Creating mobile network (contd)


#Step 6: Set mobile node configurations
$nsptr node-config <param> $<opt>

<param>

-addressingType
-adhocRouting
-llType
-macType
-propType
-ifqType
-ifqLen
-phyType
-antType
-channelType
-topoInstance
-wiredRouting
-mobileIP
-energyModel

<opt>

opt(val)

usually flat or hierarchical used for wireless topologies


Adhoc rotuing protocol like DSDV, DSR, TORA, AODV etc
LinkLayer
MAC type like Mac/802_11
Propagation model like Propagation/TwoRayGround
Interface queue type like Queue/DropTail/PriQueue
Interface queue length like 50
Network inteface type like Phy/WirelessPhy
Antenna type like Antenna/OmniAntenna
Channel type like Channel/WirelessChannel
Topography instance
Turning wired routing ON or OFF
Setting the flag for mobileIP ON or OFF
EnergyModel type
Respective opt array element already defined

73

Creating mobile network (contd)

<param>

initialEnergy
rxPower
txPower
agentTrace
routerTrace
macTrace
movementTrace

<opt>

opt(val)

Specified in Joules
Specified in W
Specified in W
Tracing at agent level turned ON or OFF
Tracing at router level turned ON or OFF
Tracing at mac level turned ON or OFF
Mobilenode movement logging turned ON or OFF
Respective opt array element already defined

74

Creating mobile network (contd)


#Step 8: Set initial positions and sizes for mobile nodes
$ndh set <pos> <val>
$nsptr initial_node_pos $ndh <size>
ndh

Handle to node

nsptr

Pointer to simulator object

<pos>

X_
Y_
Z_

<val>

<num_double>

X coordinate
Y coordinate
Z coordinate

75

Creating mobile network (contd)


#Step 9: Set scheduled or random movements for mobile nodes
#For scheduled movements
#Set random-motion false for scheduled motions to take place
$ndh random-motion 0
$nsptr at <time> $ndh setdest <x> <y> <speed>
<time>

<num_double>

Schedule time in secs

<x>, <y>

<num_double>

X and Y coordinates for new position

<speed>

<num_double>

Speed of movement in m/s

#For random movements


$ndh random-motion <arg>
$nsptr at <time> $ndh start
<time>

<num_double>

<arg>

true or false
0 or 1

Schedule time in secs


Random motion of node ndh is enabled if true or 1

76

Creating mobile network (contd)


#Step 12: Reset nodes when simulation ends
$nsptr at $opt(stp) $ndh reset
nsptr

Pointer to simulator object

ndh

Handle to node

opt(val)

Respective opt array element

77

Creating mobile network (contd)


#Step 13: Stop nam when simulation ends
$nsptr at $opt(stp) $ndh nam-end-wireless $opt(stp)
nsptr

Pointer to simulator object

ndh

Handle to node

opt(val)

Respective opt array element

78

Creating mobile network (contd)


# Step 14: Call finish to finish
$nsptr at <time> finish
proc finish {} {
#declaring nsptr, ntfptr as global variables
global nsptr ntfptr
#flush trace buffers to respective files
$nsptr flush-trace
#close all files
close $ntfptr
#stop simulation-not necessary if step 13 is used
$nsptr halt
#open animation for this simulation
exec nam <ntfname>.nam &
exit 0
}

79

Вам также может понравиться