Hello,
I have developed a MANET routing protocol on NS-2.35 which I intend to simulate with a TCL script, but it's surprising that the simulation continues past the scheduled end-time on the script and has to be stopped manually. I'm surprised as to how the scheduler misses resetting the nodes on time; or is it due to some strange interleaving between scheduled events and protocol function calls? I would really appreciate some insight on the root of this problem how it can be avoided. Is it possible to plant a hack directly from within the C++ code so that the Scheduler::instance exits as soon as a pre-defined clock() value is reached? I'm presenting the TCL simulation script here for your kind perusal: if { $argc != 2 } { puts "The wireless.tcl script requires two parameters - Protocol Name & Traffic Rate to be inputed." puts "For example, ns wireless1.tcl Epidemic 1000" puts "Please try again." } else { # ====================================================================== # Define options # ====================================================================== set val(chan) Channel/WirelessChannel set val(prop) Propagation/TwoRayGround set val(netif) Phy/WirelessPhy set val(mac) Mac/802_11 set val(ifq) Queue/DropTail/PriQueue set val(ll) LL set val(ant) Antenna/OmniAntenna set val(x) 1000 ;# X dimension of the topography set val(y) 1000 ;# Y dimension of the topography set val(ifqlen) 50000 ;# max packet in ifq set val(nn) 11 ;# how many nodes are simulated set val(sc1) "ns_trace_report_Node1" set val(sc2) "ns_trace_report_Node2" set val(sc3) "ns_trace_report_Node3" set val(sc4) "ns_trace_report_Node4" set val(sc5) "ns_trace_report_Node5" set val(sc6) "ns_trace_report_Node6" set val(sc7) "ns_trace_report_Node7" set val(sc8) "ns_trace_report_Node8" set val(sc9) "ns_trace_report_Node9" set val(sc10) "ns_trace_report_Node10" set val(sc11) "ns_trace_report_Node11" #set val(sc12) "ns_trace_report_Node12" #set val(sc13) "ns_trace_report_Node13" #set val(sc14) "ns_trace_report_Node14" #set val(sc15) "ns_trace_report_Node15" #set val(sc16) "ns_trace_report_Node16" #set val(sc17) "ns_trace_report_Node17" #set val(sc18) "ns_trace_report_Node18" #set val(sc19) "ns_trace_report_Node19" #set val(sc20) "ns_trace_report_Node20" #set val(sc21) "ns_trace_report_Node21" #set val(sc22) "ns_trace_report_Node22" #set val(sc23) "ns_trace_report_Node23" #set val(sc24) "ns_trace_report_Node24" #set val(sc25) "ns_trace_report_Node25" set val(rp) [lindex $argv 0] ;# routing protocol set val(rate) [lindex $argv 1] ;#CBR packet rate set val(stop) 432000.0 ;# simulation time # ===================================================================== # 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 str0 traces/; set str1 secs; set str2 buses1BS; set str3 secpp.tr; set str4 secppnam; set str5 namtraces/; set str6 2000; set trfilename [concat $str0$val(rp)$str6$val(stop)$str1$val(nn)$str2$val(rate)$str3] #set namfilename [concat $str5$val(rp)$val(stop)$str1$val(nn)$str2$val(rate)$str4] set tracefd [open $trfilename w] #set namtrace [open $namfilename w] $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 $val(nn)] # # define how node should be created # #global node setting $ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace OFF \ -routerTrace OFF \ -macTrace OFF \ -movementTrace OFF # # Create the specified number of nodes [$val(nn)] and "attach" them # to the channel. for {set i 0} {$i < $val(nn)} {incr i} { set node_($i) [$ns node] $node_($i) random-motion 0 ;# disable random motion } # Define node movement model # #puts "Loading scenario file..." source $val(sc1) source $val(sc2) source $val(sc3) source $val(sc4) source $val(sc5) source $val(sc6) source $val(sc7) source $val(sc8) source $val(sc9) source $val(sc10) source $val(sc11) #source $val(sc12) #source $val(sc13) #source $val(sc14) #source $val(sc15) #source $val(sc16) #source $val(sc17) #source $val(sc18) #source $val(sc19) #source $val(sc20) #source $val(sc21) #source $val(sc22) #source $val(sc23) #source $val(sc24) #source $val(sc25) # Define node initial position in nam puts "Setting initial position of nodes..." for {set i 0} {$i < $val(nn)} {incr i} { $ns initial_node_pos $node_($i) 20 } # # Define traffic model # # Setup traffic flow between nodes # UDP connections for all nodes # puts "Setting up traffc agent..." for {set i 1} {$i < $val(nn)} {incr i} { set udp_($i) [new Agent/UDP] $ns attach-agent $node_($i) $udp_($i) } puts "Setting up CBR source..." # Create a CBR traffic source and attach it to udp agent for {set i 1} {$i < $val(nn)} {incr i} { set cbr_($i) [new Application/Traffic/CBR] $cbr_($i) set packetSize_ 500 $cbr_($i) set interval_ $val(rate) $cbr_($i) attach-agent $udp_($i) } #Create a Null agent (a traffic sink) and attach it to node 0 set null0 [new Agent/Null] $ns attach-agent $node_(0) $null0 #Connect the traffic sources with the traffic sink for {set i 1} {$i < $val(nn)} {incr i} { $ns connect $udp_($i) $null0 } set starttime 172900 #set starttime 100 expr srand(1741986) #Schedule events for the CBR agents for {set i 1} {$i < $val(nn)} {incr i} { $ns at [expr $starttime ] "$cbr_($i) start"; #+ [expr rand() * 100] $ns at 259200 "$cbr_($i) stop" } #for {set j 1} {$j < 172} {incr j} { # for {set i 0} {$i < $val(nn)} {incr i} { # $ns at [expr $j * 1000] "[$node_($i) agent 255] print_rtable"; # } #} # # Print Full Routing Tables of nodes when the simulation ends # #for {set i 0} {$i < $val(nn)} {incr i} { # $ns at $val(stop).0 "[$node_($i) agent 255] print_rtable"; #} # # Tell nodes when the simulation ends # puts "STOP!!!" for {set i 0} {$i < $val(nn)} {incr i} { $ns at $val(stop).1 "$node_($i) reset"; } $ns at $val(stop).1002 "puts \"NS EXITING...\" ; $ns halt" #puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(rp)" #puts $tracefd "M 0.0 sc $val(sc1) seed $val(seed)" #puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)" puts "Starting Simulation..." $ns run } I would be obliged if someone could help me on this. I'm new to NS and from what I read on the mailing list archives, such issues do happen from time to time. I would be happy to post snippets of my C++ code if required. Thanks and Regards, Dhrubo. -- Dhrubojyoti Roy PhD Student (2nd year) Department of Computer Science and Engineering, The Ohio State University, 2015 Neil Avenue, Columbus, OH-43210. +1-740-417-5890