[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ns] asking for solution, please!!!!
dear ns-users,
According to example wired-cum-wireless-sim in ns.
I've tried to make my own script that seen below.
To be noticed, that i made the script to simulate TCP
performance over wireless LAN (IEEE 802.11) using
Snoop Protocol, so it could be evaluated and compared
before and after Snoop Protocol attached in Base
Station.
From what i've been read, Snoop Protocol
implemented/attached in base station.
I suspect that there is something wrong with the
script, because the program doesn't run properly / it
won't stop.
I've tried to find out what is wrong but until know i
haven't successed yet.
Can someone help me please!!!!
I don't know what should i do.... who am i supposed to
ask for the answer / the solution except from this
community that involve people who get along with ns
well.
regards,
Dade
Note; ns version: ns-allinone-2.1b7a running on Linux
Red Hat 6.2
## The script ###
Class TraceApp -superclass Application
TraceApp instproc init {args} {
$self set bytes_ 0
$self set totbytes_ 0
eval $self next $args
}
TraceApp instproc recv {byte} {
$self instvar bytes_
$self instvar totbytes_
set bytes_ [expr $bytes_ + $byte]
set totbytes_ [expr $totbytes_ + $byte]
return $totbytes_
}
proc create-base-station-node {address } {
global topo tracefd opt node node_ ns_
set ns_ [Simulator instance]
if [Simulator set mobile_ip_] {
Simulator set node_factory_ MobileNode/MIPBS
} else {
Simulator set node_factory_
Node/MobileNode/BaseStationNode
}
set node [$ns_ node $address]
set id [$node id]
$node random-motion 0 ;# disable random motion
$node topography $topo
#
# This Trace Target is used to log changes in
direction
# and velocity for the mobile node.
#
set T [new Trace/Generic]
$T target [$ns_ set nullAgent_]
$T attach $tracefd
$T set src_ $id
$node log-target $T
$node base-station [AddrParams addr2id [$node
node-addr]]
create-$opt(rp)-bs-node $node $id
Simulator set node_factory_ Node ;# default
value
return $node
}
proc create-dsdv-bs-node {node id} {
global ns_ chan prop opt node_
$node instvar regagent_ ragent_
$node add-interface $chan $prop $opt(ll2) $opt(mac) \
$opt(ifq) $opt(ifqlen) $opt(netif) \
$opt(ant)
create-$opt(rp)-routing-agent $node $id
if [info exists regagent_] {
$regagent_ ragent $ragent_
}
if { $opt(pos) == "Box" } {
#
# Box Configuration
#
set spacing 200
set maxrow 7
set col [expr ($id - 1) % $maxrow]
set row [expr ($id - 1) / $maxrow]
$node set X_ [expr $col * $spacing]
$node set Y_ [expr $row * $spacing]
$node set Z_ 0.0
$node set speed_ 0.0
$ns_ at 0.0 "$node_($id) start"
}
}
proc dsdv-create-mobile-node { id args } {
global ns ns_ chan prop topo tracefd opt node_
global chan prop tracefd topo opt
set ns_ [Simulator instance]
if [Simulator hier-addr?] {
if [Simulator set mobile_ip_] {
set node_($id) [new MobileNode/MIPMH $args]
} else {
set node_($id) [new Node/MobileNode/BaseStationNode
$args]
}
} else {
set node_($id) [new Node/MobileNode]
}
set node $node_($id)
$node random-motion 0 ;# disable random motion
$node topography $topo
# XXX Activate energy model so that we can use sleep,
etc. But put on
# a very large initial energy so it'll never run out
of it.
if [info exists opt(energy)] {
$node addenergymodel [new $opt(energy) $node 1000
0.5 0.2]
}
#
# This Trace Target is used to log changes in
direction
# and velocity for the mobile node.
#
set T [new Trace/Generic]
$T target [$ns_ set nullAgent_]
$T attach $tracefd
$T set src_ $id
$node log-target $T
$node add-interface $chan $prop $opt(ll1) $opt(mac) \
$opt(ifq) $opt(ifqlen) $opt(netif) $opt(ant)
#
# Create a Routing Agent for the Node
#
create-$opt(rp)-routing-agent $node $id
if { $opt(pos) == "Box" } {
#
# Box Configuration
#
set spacing 200
set maxrow 7
set col [expr ($id - 1) % $maxrow]
set row [expr ($id - 1) / $maxrow]
$node set X_ [expr $col * $spacing]
$node set Y_ [expr $row * $spacing]
$node set Z_ 0.0
$node set speed_ 0.0
$ns_ at 0.0 "$node_($id) start"
}
return $node
}
proc record {} {
global ns f0 f1 f2 traceapp0 traceapp1
traceapp2
set ns [Simulator instance]
set time 0.5
#How many bytes have been received by the
traffic sinks?
set bw0 [$traceapp0 set bytes_]
set bw1 [$traceapp1 set bytes_]
set bw2 [$traceapp2 set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write
it to the files
puts $f0 "$now [expr $bw0/$time*8/1000000]"
puts $f1 "$now [expr $bw1/$time*8/1000000]"
puts $f2 "$now [expr $bw2/$time*8/1000000]"
#Reset the bytes_ values on the traffic tracer
$traceapp0 set bytes_ 0
$traceapp1 set bytes_ 0
$traceapp2 set bytes_ 0
# $ns trace-all $f
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}
proc finish {} {
global ns traceapp0 traceapp1 traceapp2 tcpsrc0
tcpsrc1 tcpsrc2 f0 f1 f2
close $f0
close $f1
close $f2
#Call xgraph to display the results
exec xgraph out0.tr out1.tr out2.tr -geometry 450x250
&
#exec xgraph BW.tr Window.tr bad.tr -bb -bg white -t
results -x "time" -geometry 800x400 &
#exec xgraph BW.tr Window.tr RTT.tr bad.tr -bb -t
results -x "time" -geometry 800x400 &
# exec xgraph Bandwidth.tr cwnd.tr RTT.tr -bb
-bg white -t results -x "Time" -geometry 450x250 &
exit 0
}
### This simulation is an example of combination of
wired and wireless
### topologies.
# 0 o W1(0.0.0)
WIRED NODES
# |
# 1 o W2 (0.1.0)
# |
# 2 o W3 (0.2.0)
# |
# |
#--*--*--*--*--*-- 3 o base-stn nodes
--*-*-*-*-*-*-*-
# (1.0.0) BS
# o 5
# 4 o WL2 (1.0.2)
# (1.0.1) WL1
# o 6 (1.0.3) WIRELESS
NODES
# WL3
#
#
#===============================================================
#options
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll1) LL
set opt(ll2) LL/LLSnoop
set opt(ant) Antenna/OmniAntenna
set opt(x) 670 ;# X & Y dimension of the topography
set opt(y) 670 ;# hard wired for now...
set opt(rp) dsdv ;# available routing
proto:dsdv/dsr
set opt(ifqlen) 50 ;# max packet in ifq
set opt(tr) wired-wireless-out.tr
# Default settings
set num_wired_nodes 3
set num_bs_nodes 1
set num_wireless_nodes 3
set opt(nn) 4 ;# total number of
wireless nodes
# Other class settings
set AgentTrace ON
set RouterTrace ON
set MacTrace OFF
Queue/DropTail/PriQueue set Prefer_Routing_Protocols
1
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and
1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.5
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
# Initialize the SharedMedia interface with parameters
to make
# it work like the 914MHz Lucent WaveLAN DSSS radio
interface
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ 3.652e-10
Phy/WirelessPhy set Rb_ 2*1e6
Phy/WirelessPhy set Pt_ 0.2818
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0
# intial setup - set addressing to hierarchical
set ns [new Simulator]
$ns set-address-format hierarchical
#set namtrace [open wired-wireless-out.nam w]
#$ns namtrace-all $namtrace
#set trace [open wired-wireless-out.tr w]
#$ns trace-all $trace
AddrParams set domain_num_ 3
lappend cluster_num 3 1 1
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 1 1 4 1
AddrParams set nodes_num_ $eilastlevel
# setup the wired nodes
set temp {0.0.0 0.1.0 0.2.0}
for {set i 0} {$i < $num_wired_nodes} {incr i} {
set W($i) [$ns node [lindex $temp $i]]
}
### setup base stations & wireless nodes
if { $opt(x) == 0 || $opt(y) == 0 } {
puts "No X-Y boundary values given for wireless
topology\n"
}
set chan [new $opt(chan)]
set prop [new $opt(prop)]
set topo [new Topography]
set tracefd [open $opt(tr) w]
#setup snoop in basestation
#set ll [new LL/LLSnoop]
#$ns node-config -llType $ll
#setup topography and propagation model
$topo load_flatgrid $opt(x) $opt(y)
$prop topography $topo
# Create God
create-god $opt(nn)
# create base stations
set temp {1.0.0 1.0.1 1.0.2 1.0.3}
set BS(0) [create-base-station-node [lindex $temp 0]]
#provide some co-ord (fixed) to base stations
$BS(0) set X_ 1.0
$BS(0) set Y_ 2.0
$BS(0) set Z_ 0.0
#configure for mobilenodes
$ns node-config -wiredRouting OFF
#$ns node-config -llType $opt(ll)
#create some mobilenodes in the same domain as BS_0
for {set j 0} {$j < $num_wireless_nodes} {incr j} {
set node_($j) [ dsdv-create-mobile-node $j [lindex
$temp \
[expr $j+1]] ]
$node_($j) base-station [AddrParams addr2id
[$BS(0) node-addr]]
}
if { $opt(x) == 0 || $opt(y) == 0 } {
usage $argv0
exit 1
}
#create links between wired and BS nodes
$ns duplex-link $W(0) $BS(0) 5Mb 2ms DropTail
$ns duplex-link $W(1) $BS(0) 5Mb 2ms DropTail
$ns duplex-link $W(2) $BS(0) 5Mb 2ms DropTail
#$ns duplex-link-op $W(0) $W(1) orient down
#$ns duplex-link-op $W(1) $W(2) orient down
#$ns duplex-link-op $W(2) $BS(0) orient down
# setup TCP connections
set tcpsrc0 [new Agent/TCP]
set tcpsrc1 [new Agent/TCP]
set tcpsrc2 [new Agent/TCP]
$ns attach-agent $W(0) $tcpsrc0
$ns attach-agent $W(1) $tcpsrc1
$ns attach-agent $W(2) $tcpsrc2
# setup tcp sink (destination)
set sink0 [new Agent/TCPSink]
set sink1 [new Agent/TCPSink]
set sink2 [new Agent/TCPSink]
$ns attach-agent $BS(0) $sink0
$ns attach-agent $BS(0) $sink1
$ns attach-agent $BS(0) $sink2
# tracing application
set traceapp0 [new TraceApp]
set traceapp1 [new TraceApp]
set traceapp2 [new TraceApp]
$traceapp0 attach-agent $sink0
$traceapp1 attach-agent $sink1
$traceapp2 attach-agent $sink2
# make connection between tcp source and tcp sink
$ns connect $tcpsrc0 $sink0
# create traffic data FTP
set ftp0 [$tcpsrc0 attach-source FTP]
#open output files
set f0 [open out0.tr w]
set f1 [open out1.tr w]
set f2 [open out2.tr w]
# start up the source
$ns at 0.0 "record"
$ns at 0.0 "$ftp0 start"
$ns at 0.0 "$traceapp0 start"
$ns at 40.0 "$ftp0 stop"
$ns at 40.0 "$traceapp0 stop"
$ns at 50.0 "finish"
#running simulation
$ns run
__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com