This is my very first program on ns2 on UNIX 14.04. I am trying to build a three nodes point – to – point network with duplex links between them. Set the queue size, vary the bandwidth and find the number of packets dropped.
This is my Code:-
**prgrm1.tcl**
set ns[new Simulator]
set nf[open prg1.nam w]
$ns namtrace-all $nf
set tf[open lab1.tr w]
$ns trace-all $tf
proc finish{} {
gobal ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam prg1.nam &
exit 0
}
set n0[$ns node]
set n1[$ns node]
set n2[$ns mode]
set n3[$ns node]
$ns duplex-link $n0 $n2 200Mb 10ms DropTail
$ns duplex-link $n1 $n2 100Mb 5ms DropTail
$ns duplex-link $n2 $n3 1Mb 1000ms DropTail
$ns queue-limit $n0 $n2 10
$ns queue-limit $n1 $n2 10
set udp0[new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0[new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $n1 $udp1
set cbr1[new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
set upd2[new Agent/UDP]
$ns attach-agent $n2 $udp2
set cbr2[new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
set null0[new Agent/Null]
$ns attach-agent $n3 $null0
$ns connect $udp0 $null0
$ns connect $udp1 $null0
$ns at 0.1 "$cbr0 start"
$ns at 0.2 "$cbr1 start"
$ns at 1.0 "finish"
$ns run
lab1.awk
BEGIN{
c=0;
}
{
if($1=="d")
{
c++;
printf("%s\t%s\n",$5,$11);
}
}
END{
printf("The no of packets dropped = %d\n",c);
}
Error
can't read "ns_o3": no such variable
while executing
"set ns[new Simulator]"
(file "prg1.tcl" line 1)
Your error is caused by line 1 of your program:
set ns[new Simulator]
You're missing a space between the variable name ns
and the command [new Simulator]
It looks like [new Simulator]
returns _o3
, so the interpreter is going to run this command:
set ns_o3
The Tcl set
command with only one argument will return the value of the given variable name. In this case, there is no variable named ns_o3
, so that's your error.
The rest of your program is also missing spaces before commands in []
brackets. Why did you do this?