Question Simulation doesn't run for the determined 10 seconds and NAM doesn't start automatically

yaser_aramesh

Junior Member
Feb 3, 2020
1
0
6
This simulation in NS2 is set to work for 10 seconds but stops at 4.5 when the FTP is supposed to start sending packets. would you please help me fix it? I have been working with NS2 for 3 hours. I am a hell of a noob right now.
Code:
#Creating a simulator object
set ns [new Simulator]
global $ns
set traceFile [open output.tr w]
$ns trace-all $traceFile
set namFile [open output.nam w]
$ns namtrace-all $namFile

#Defining the finish procedure
proc finish {} {
  global ns namFile traceFile fert
  $ns flush-trace

  close $namFile
  close $traceFile

  exec nam output.nam &
  exit 0
}

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
#for {set i 0} {$i<5} {incr i} {
#set n($i) [$ns node]
#}

#Creating the links
$ns duplex-link $n0 $n1 1Mb 20ms DropTail
$ns duplex-link $n0 $n2 1Mb 20ms DropTail
$ns duplex-link $n1 $n3 1Mb 20ms DropTail
$ns duplex-link $n2 $n3 1Mb 20ms DropTail
$ns duplex-link $n2 $n4 1Mb 20ms DropTail
$ns duplex-link $n2 $n6 1Mb 20ms DropTail
$ns duplex-link $n4 $n6 1Mb 20ms DropTail
$ns duplex-link $n4 $n5 1Mb 20ms DropTail

#Topology
$ns duplex-link-op $n0 $n1 orient down
$ns duplex-link-op $n0 $n2 orient right 
$ns duplex-link-op $n1 $n3 orient right 
$ns duplex-link-op $n2 $n3 orient down
$ns duplex-link-op $n2 $n4 orient right
$ns duplex-link-op $n2 $n6 orient right-down
$ns duplex-link-op $n4 $n5 orient right-down
$ns duplex-link-op $n4 $n6 orient down

#Agents - Attach Agents - SInk and Null connetions
set udp0 [new Agent/UDP]
set tcp3 [new Agent/TCP]
set null4 [new Agent/Null]
set sink5 [new Agent/TCPSink]
$ns attach-agent $n0 $udp0
$ns attach-agent $n3 $tcp3
$ns attach-agent $n4 $null4
$ns connect $udp0 $null4
$ns connect $tcp3 $sink5


#CBR over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set type_ CBR
$cbr0 set packet_size_ 1500
$cbr0 set rate_ 830kb


#FTP over TCP connection
set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3
$ftp3 set type_ FTP

#Queue Limit of n2-n4 and n4-n5
$ns queue-limit $n2 $n4 30
$ns queue-limit $n4 $n5 20

#Assigning a link variable for the link between n4 and n5



#Monitoring
set mon [open "mon.txt" w]
set qmon [$ns monitor-queue $n2 $n4 $mon 0.01]
[$ns link $n2 $n4] queue-sample-timeout
#set qmon24 [$ns monitor-queue $n2 $n4 "" 0.01]

#............................................
    set link01 [$ns link $n2 $n3]
# Create monitor
    set fmonitor [$ns makeflowmon Fid]
    $ns attach-fmon $link01 $fmonitor
        set drop_count [$fmonitor set parrivals_]

#............................................
proc mon { } {
global ns qmon
set t [$ns now]
puts "$t [$qmon set pkts_]"

$ns at [expr $t + 0.5] "mon"
}

#Link Down and Up at 5.0 and 7.0

        $ns rtmodel-at 5.0 down $n2 $n4
        $ns rtmodel-at 7.0 up $n2 $n4

#$ns rtproto LS

$ns at 0 "mon"

$ns color cbr "red"


$ns at 2.0 "$cbr0 start"
$ns at 4.5 "$ftp3 start"
$ns at 8.0 "$cbr0 stop"
$ns at 9.0 "$ftp3 stop"

$ns at 10.0 "finish"

$ns run

oh and one more thing. The Nam doesn't start automatically and I get this:

Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) --- _o21: no target for slot 4294967295 _o21 type: Classifier/Hash/Dest

content dump: classifier _o21 0 offset 0 shift 1073741823 mask 1 slots slot 3: _o196 (Classifier/Port) -1 default