[ns] building simulator using MAC 802_15_4! help needed!
new2ns08
siu06btk at reading.ac.uk
Thu Nov 27 17:24:53 PST 2008
Dear all,
As my name implies i am new to both ns and tcl. I am trying to develop a WSN
simulator using zigbee protocol instead of MAC 802.11 as my final year
project. I was trying to give the user of the simulator to choose to enter
the number of nodes so before getting my hands dirty with all the coding i
decided to run a code which has been written by someone else. I have been
told that the code does work however while running it i kept getting the
following error message
siu06btk at sie59a:~/Documents$ ns wireless1-orig1.tcl
num_nodes is set 1
INITIALIZE THE LIST xListHead
Agent/TCP B0 with pktsize 1500 flows from Node0 to Node0
Starting Simulation...
Segmentation fault
I would really really appreciate all the help i can get as i need to get
this code working which means i will understand what i am doing or supposed
to be doing. For your reference and subsequent correction or comment or
explanation here i have attached the code.
http://www.nabble.com/file/p20722366/wireless1-orig1.tcl wireless1-orig1.tcl
if there is gonna be an error to open here it is again:
#==============================================
# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy/802_15_4 ;#network interface
type
set val(mac) Mac/802_15_4
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(x) 670 ;# X dimension of the topography
set val(y) 670 ;# Y dimension of the topography
set val(ifqlen) 2000 ;# max packet in ifq
set val(seed) 0.0
set val(adhocRouting) AODV
set val(traffic) cbr ;# cbr/poisson/ftp
#set val(nn) 10 ;# how many nodes are simulated
#set val(cp) "../Documents/scene/cbr-3-test"
#set val(sc) "../Documents/scene/scen-3-test"
set opt(stop) 50.0 ;# simulation time
set num_nodes [lindex $argv 0]
puts "$num_nodes";
set nodes [expr $num_nodes + 1]
set epsilon 0.00005
set ppktsize 160
set pinterval 0.020
set pktsize 1500
set transport both
set sink 0
set vsrc 1
Phy/WirelessPhy set CSThresh_ 3.981e-13; #carrier sensing threshold
Phy/WirelessPhy set RXThresh_ 3.981e-13; #receiver threshold
Phy/WirelessPhy set CPThresh_ 10; #capture threshold
Phy/WirelessPhy set freq_ 2.4e+9; #Operating Freq
Phy/WirelessPhy set L_ 1.0; #System loss factor
Phy/WirelessPhy set pt_ 0.001;
#=======================================================================
# Main Program
# ======================================================================
#
# Initialize Global Variables
#
# create simulator instance
set ns_ [new Simulator]
# setup topography object
set topo [new Topography]
# create trace object for ns and nam
set tracefd [open wireless1-out.tr w] ; #opens the file out.tr
set namtrace [open wireless1-out.nam w] ; #opens the file out.nam
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# define topology
$topo load_flatgrid $val(x) $val(y)
# Create God
set god_ [create-god $nodes]
# define how node should be created
set chan_1_ [new $val(chan)]
#==================================================
#Global node setting
#==================================================
$ns_ node-config -adhocRouting $val(adhocRouting) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan_1_ \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON
# Create the specified number of nodes [$val(nn)] and "attach" them
# to the channel.
for {set i 0} {$i < $nodes } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
$node_($i) shape hexagon
$node_($i) color red
}
for {set i 1} {$i < $nodes} {incr i} {
set P [new Application/Traffic/CBR]
set P_src [new Agent/UDP]
set P_sink [new Agent/UDP]
$P set random_ 0
$P set packetSize_ $ppktsize
$P set interval_ $pinterval
$P_src set packetSize_ $ppktsize
$P_src set class_ [expr $i + 1]
# $P_src set prio_ $pri
if {[expr $i % 2] == 0} {
set node_src $i
set node_sink 0
} else {
set node_src 0
set node_sink $i
}
$ns_ attach-agent $node_($node_src) $P_src
$ns_ attach-agent $node_($node_sink) $P_sink
$ns_ connect $P_src $P_sink
$P attach-agent $P_src
puts "P$i with pktsize $ppktsize flows from Node$node_src to Node$node_sink
every $pinterval"
# $ns_ at [expr 3.0 * $i] "$P start"
# $ns_ at [expr 3.0 * ($i + $num_nodes) + $soaktime - 6] "$P stop"
$ns_ at 0.0 "$P start"
$ns_ at $val(stop) "$P stop"
}
# Define node movement model
#puts "Loading connection pattern..."
#source $val(cp)
# Define traffic model
#puts "Loading scenario file..."
#source $val(sc)
# Define node initial position in nam
# 20 defines the node size in nam, must adjust it according to your scenario
# The function must be called after mobility model is defined
for {set i 0} {$i < $nodes} {incr i} {
$ns_ initial_node_pos $node_($i) 20
}
for {set i 0} {$i < $nodes/2 } {incr i} {
$node_($i) set X_ 750.0
$node_($i) set Y_ [expr $i*20+5]
$node_($i) set Z_ 0.0
}
for {set i $nodes/2} {$i < $nodes } {incr i} {
$node_($i) set X_ 250.0
$node_($i) set Y_ [expr ($i-10)*250+5]
$node_($i) set Z_ 0.0
}
#set udp [new Agent/UDP]
#$udp set fid_ 2
#set sink [new Agent/Null]
#$ns_ attach-agent $node_(1) $udp
#$ns_ attach-agent $node_(6) $sink
#$ns_ connect $udp $sink
# TCP connections between node_(0) and node_(1) and also between node_(2)
and node_(3)
for {set i 0} {$i < $nodes} {incr i} {
set agent_src Agent/TCP
set agent_sink Agent/TCPSink/DelAck
set B [new Application/FTP]
set B_src [new $agent_src]
set B_sink [new $agent_sink]
$B_src set packetSize_ $pktsize
$B_src set class_ [expr $i + 1]
if { $i%2 == 0} {
set sink $i
set src 0
} else {
set src $i
set sink 0
}
$ns_ attach-agent $node_($src) $B_src
$ns_ attach-agent $node_($sink) $B_sink
$ns_ connect $B_src $B_sink
$B attach-agent $B_src
puts "$agent_src B$i with pktsize $pktsize flows from Node$src to
Node$sink"
$ns_ at 0.0 "$B start"
$ns_ at $opt(stop) "$B stop"
}
#for {set i 0} {$i < $nodes } {incr i} {
#set cbr [new Application/Traffic/CBR]
#$cbr attach-agent $tcp
#$cbr set type_ CBR
#$cbr set packet_size_ 100
#$cbr set rate_ 10kb
#$cbr set random_ false
#$ns_ at 10.0 "$cbr start"
#$ns_ at 300.0 "$cbr stop"
#}
#informative headers for the CMUTrace file
puts $tracefd "M 0.0 nn $nodes x $val(x) y $val(y) rp $val(adhocRouting)"
#puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"
#==========================================================
#End of simulation
#==========================================================
#Tell nodes when the simulation ends
for {set i 0} {$i < $nodes } {incr i} {
$ns_ at 600.0 "$node_($i) reset";
}
$ns_ at 600.001 "stop"
$ns_ at 600.01 "puts \"NS EXITING...\" ; $ns_ halt"
#Creates the stop procedure to close the nam and trace files opened
proc stop {} {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close $namtrace
exec nam wireless1-out.nam &
}
proc do_halt {} {
global ns_
puts "NS EXITING..."
$ns_halt
}
puts "Starting Simulation..."
$ns_ run
#======================================================================
#THE END
#======================================================================
Looking forward for your kind and positive reply, I would like to thank you
all in advance.
Best regards,
new2ns
--
View this message in context: http://www.nabble.com/building-simulator-using-MAC-802_15_4%21-help-needed%21-tp20722366p20722366.html
Sent from the ns-users mailing list archive at Nabble.com.
More information about the Ns-users
mailing list