[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

TCP agent deletion



Hi,

I'm trying to learn how to delete an agent and I just cannot get it to work.
I'm redefining the done method, as I have seen in some examples, but I always
get a segmentation fault. My new done method is

$tcp0 proc done {} {
    global ns tcp0 n0
    puts [concat "TCP agent done at " [$ns now] ]
    $ns detach-agent $n0 $tcp0
    delete $tcp0
}

The timing message is output just before ns crashes. As far as I understand
tcp.cc, the finish method will not invoke the done callback till the last ACK
is received, so it's safe to delete the agent inside its done method. Do I
have to disable something else before destroying an agent?

The complete program is included below. Any help will be appreciated.

#Create a simulator object
set ns [new Simulator]

#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' procedure
proc finish {} {
        global ns nf
        $ns flush-trace
 #Close the trace file
        close $nf
 #Execute nam on the trace file
        exec nam out.nam &
        exit 0
}

#
# n0 <---- 1 Mb ----> n1
#

set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms DropTail

# TCP agent and FTP application
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
$tcp0 set fid_ 1

$ns color 1 Blue

set sink0 [new Agent/TCPSink]
$ns attach-agent $n1 $sink0

$ns connect $tcp0 $sink0
$sink0 listen

set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0

$ns at 5 "$ftp0 produce 100"

$tcp0 proc done {} {
    global ns tcp0 n0
    puts [concat "TCP agent done at " [$ns now] ]
    $ns detach-agent $n0 $tcp0
    delete $tcp0
}

$ns at 120.0 "finish"

#Run the simulation
$ns run

-- Felix Hernandez