Appendix II
The input script for ns-2 used in Video traffic analysis.
##############################################################
#Test_Video.tcl
#
#This script will take the number of nodes with video traffic
# as a parameter. The video.dat is a binary file already created
# which contains the trace information to be used from the
# Jurassic Park h.263 video
#
#
###############################################################
#check input parameters
if {$argc != 1} {
puts
""
puts "Wrong Number of Arguments! Enter the number of nodes
with video traffic"
puts "Syntax: ns test-be.tcl nbMNs"
puts
""
exit
1
}
# set global variables
set nb_mn [lindex $argv 0]
# max number of mobile node
set output_file mpg_ugs.$nb_mn.tr
set output_dir .
set traffic_start 30
set traffic_stop 500
set simulation_stop 700
set diuc 7 ;#modulation for MNs
#define debug values
Mac/802_16 set debug_ 0
Mac/802_16 set rtg_ 20
Mac/802_16 set ttg_ 20
Mac/802_16 set frame_duration_ 0.005
Mac/802_16 set ITU_PDP_ 2
Phy/WirelessPhy/OFDMA set g_ 0.25
#define coverage area for base station
81
# 200 mw for MS specified in standard, we use the same for all nodes
for the time being
Phy/WirelessPhy set Pt_ 0.2
Phy/WirelessPhy set RXThresh_ 1.90546e-16
Phy/WirelessPhy set CSThresh_ [expr 0.9*[Phy/WirelessPhy set
RXThresh_]]
# set it to 1 if using OFDMA propagation model.
Phy/WirelessPhy set OFDMA_ 1
# Parameter for wireless nodes
set opt(chan) Channel/WirelessChannel ;# channel type
set opt(prop) Propagation/OFDMA ;# radio-
propagation model
set opt(netif) Phy/WirelessPhy/OFDMA ;# network
interface type
set opt(mac) Mac/802_16/BS ;# 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(adhocRouting) DSDV ;# routing
protocol
set opt(x)
1100
;# X dimension of the
topography
set opt(y)
1100
;# Y dimension of the
topography
Mac/802_16 set fbandwidth_ 20e+6 ;# frequency bandwidth
(MHz)
Mac/802_16/BS set dlratio_ .4
Mac/802_16/SS set dlratio_ .4
#defines function for flushing and closing files
proc finish {} {
global ns tf output_dir output_file nb_mn
$ns flush-trace
close $tf
exit
0
}
#create the simulator
set ns [new Simulator]
#$ns use-newtrace
#create the topography
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
82
#puts "Topology created"
#open file for trace
set tf [open $output_dir/$output_file w]
$ns trace-all $tf
#puts "Output file configured"
# set up for hierarchical routing (needed for routing over a
basestation)
#puts "start hierarchical addressing"
$ns node-config -addressType hierarchical
AddrParams set domain_num_ 2
;# domain
number
lappend cluster_num 1 1
;# cluster number
for each domain
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 [expr ($nb_mn+1)]
;# number of nodes
for each cluster (1 for sink and one for mobile nodes + base station
AddrParams set nodes_num_ $eilastlevel
puts "Configuration of hierarchical addressing done"
# Create God
create-god [expr ($nb_mn + 2)]
;# nb_mn + 2
(base station and sink node)
#puts "God node created"
#creates the sink node in first addressing space.
set sinkNode [$ns node 0.0.0]
#provide some co-ord (fixed) to base station node
$sinkNode set X_ 50.0
$sinkNode set Y_ 50.0
$sinkNode set Z_ 0.0
#puts "sink node created"
#creates the Access Point (Base station)
$ns node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType Mac/802_16/BS \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channel [new $opt(chan)] \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace OFF \
-routerTrace OFF \
-macTrace ON \
-movementTrace OFF
#puts "Configuration of base station"
#setup channel model
set prop_inst [$ns set propInstance_]
$prop_inst ITU_PDP PED_A
puts "after set pPDP"
83
#Calculate the separateion angle
set Pi 3.14159
set SS_SeparationAngle [expr 2*$Pi / $nb_mn]
set SS_RingRadius 150
set bstation [$ns node 1.0.0]
;# create the BS
$bstation random-motion 0 ;#turn off random motion
set BS_xloc 300
set BS_yloc 400
$bstation set X_ $BS_xloc
$bstation set Y_ $BS_yloc
$bstation set Z_ 0.0
set tfile [new Tracefile]
#The video.dat file is a binary file containing the packet size and
time information
$tfile filename video.dat
Agent/UDP set tracevar_ true
[$bstation set mac_(0)] set-channel 0
set rv3 [new RandomVariable/Empirical]
$rv3 loadCDF fratecdf
# creation of the mobile nodes
$ns node-config -macType Mac/802_16/SS \
-wiredRouting OFF \
-macTrace ON
;# Mobile
nodes cannot do routing.
for {set i 0} {$i < $nb_mn} {incr i} {
set wl_node_ra($i) [$ns node 1.0.[expr $i + 1]]
;#
create the node with given @.
$wl_node_ra($i)
random-motion
0
;#
disable
random motion
$wl_node_ra($i) base-station [AddrParams addr2id [$bstation
node-addr]] ;#attach mn to basestation
#compute position of the node. They wiil be placed in a
circle around the BS at same angle
$wl_node_ra($i) set X_ [expr $BS_xloc +
sin(($i)*$SS_SeparationAngle)*$SS_RingRadius]
$wl_node_ra($i) set Y_ [expr $BS_yloc +
cos(($i)*$SS_SeparationAngle)*$SS_RingRadius]
$wl_node_ra($i) set Z_ 0.0
#$ns at 0 "$wl_node_ra($i) setdest 1060.0 550.0 1.0"
puts "wireless node $i created ..."
;# debug
info
[$wl_node_ra($i) set mac_(0)] set-channel 0
[$wl_node_ra($i) set mac_(0)] set-diuc $diuc
[$wl_node_ra($i) set mac_(0)] setflow UL 1000 UGS 700 2 0
0.05 15 1 0 0 0 0 0 0 0 0 0 0 ;# setting up static flows
84
#create source traffic
#Create a UDP agent and attach it to node n0
set udp_($i) [new Agent/UDP]
$udp_($i) set packetSize_ 1500
$ns attach-agent $wl_node_ra($i) $udp_($i)
# Create a CBR traffic source and attach it to udp0
set cbr_($i) [new Application/Traffic/Trace]
$cbr_($i) attach-tracefile $tfile
$cbr_($i) attach-agent $udp_($i)
#create an sink into the sink node
# Create the Null agent to sink traffic
set null_($i) [new Agent/Null]
$ns attach-agent $sinkNode $null_($i)
# Attach the 2 agents
$ns connect $udp_($i) $null_($i)
}
# create the link between sink node and base station
$ns duplex-link $sinkNode $bstation 100Mb 1ms DropTail
# Traffic scenario: if all the nodes start talking at the same
# time, we may see packet loss due to bandwidth request collision
set diff 1
set voip_start $traffic_start
for {set i 0} {$i < $nb_mn} {incr i} {
$ns at [expr $traffic_start+$i*$diff] "$cbr_($i) start"
$ns at [expr $traffic_start+500] "$cbr_($i) stop"
}
}
$ns at $simulation_stop "finish"
# Run the simulation
puts "Running simulation for $nb_mn mobile nodes..."
$ns run
puts "Simulation done."
85
Do'stlaringiz bilan baham: |