I'm writing a script in TCL using NS and NAM.
What is the statement question I'm trying to solve? Here it is:
Following is the TCL script I have written to solve the above problem. I'm using NS2 and NAM packages in Ubuntu 20.04. I'm tasked to create 8 nodes, link them using duplex-link (of any capacity), apply TCP Agent on node 0 & 1 and apply UDP on node 2.
Then, I need to connect the TCP Agent(s) with CBR source and UDP agent with FTP source. Following is my code:
set val(stop) 10.0;
set ns [new Simulator]
#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
#===================================
# Nodes Definition
#===================================
#Create 8 nodes
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]
set n7 [$ns node]
$ns duplex-link $n0 $n3 20.0Mb 10ms DropTail
$ns duplex-link $n1 $n3 20.0Mb 10ms DropTail
$ns duplex-link $n3 $n2 20.0Mb 10ms DropTail
$ns duplex-link $n3 $n4 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n6 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n5 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n7 20.0Mb 10ms DropTail
$ns duplex-link-op $n0 $n3 orient right-down
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n3 $n2 orient left-down
$ns duplex-link-op $n3 $n4 orient right
$ns duplex-link-op $n4 $n6 orient right
$ns duplex-link-op $n4 $n5 orient right-up
$ns duplex-link-op $n4 $n7 orient right-down
#===================================
# Agents Definition
#===================================
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
$ns attach-agent $n1 $tcp
set udp [new Agent/UDP]
$ns attach-agent $n2 $udp
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $tcp
$cbr set packet_size_ 1500
set ftp [new Application/FTP]
$ftp attach-agent $udp
$ftp set type_ FTP
# null & sink
set null [new Agent/Null]
$ns attach-agent $n6 $null
$ns connect $udp $null
set sink [new Agent/TCPSink]
$ns attach-agent $n6 $sink
$ns connect $tcp $sink
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at 0.5 "$ftp start"
$ns at 5.0 "$ftp stop"
$ns at 6.0 "finish"
$ns run
When I run this code using ns file.tcl - I get the following error:
Error: sendmsg() for UDP should not be -1
ns: _o180 stop:
(_o177 cmd line 1)
invoked from within
"_o177 cmd advance 0"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o177" line 2)
(SplitObject unknown line 2)
invoked from within
"[$self agent] advance 0"
(procedure "_o180" line 2)
(Application/FTP stop line 2)
invoked from within
"_o180 stop"
