c++ - 运行 ns2 模拟器时出错:-无法读取“ns_03”:-没有此类变量
问题描述
这是我在 UNIX 14.04 上的 ns2 上的第一个程序。我正在尝试建立一个三节点点对点网络,它们之间具有双工链路。设置队列大小、改变带宽并查找丢弃的数据包数。
这是我的代码:-
**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
实验室1.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);
}
错误
can't read "ns_o3": no such variable
while executing
"set ns[new Simulator]"
(file "prg1.tcl" line 1)
解决方案
您的错误是由程序的第 1 行引起的:
set ns[new Simulator]
您在变量名ns
和命令之间缺少空格[new Simulator]
它看起来像[new Simulator]
return _o3
,所以解释器将运行这个命令:
set ns_o3
set
只有一个参数的 Tcl命令将返回给定变量名的值。在这种情况下,没有名为 的变量ns_o3
,所以这是您的错误。
程序的其余部分也在[]
括号中的命令之前缺少空格。你为什么这么做?
推荐阅读
- ruby-on-rails - 访问模型内的参数 + rails 5
- javascript - 使用javascript从URL发布文件数据的多部分/表单数据?
- python - 表达式中的正则表达式“AND”提取这个和那个
- sql-server - SQL 到 Excel - 最大每张工作表
- python - 即使在scrapy中使用代理轮换,也无法摆脱有问题的页面
- r - 是否可以在 R 中的 h2o.xgboost 中强制执行特征交互约束
- blazor - Blazor:验证复杂类型
- javascript - 如何在浏览器中上传和下载任何文件?
- apache-flink - Apache Flink 从文件加载 ML 模型
- python - 解析从 Azure 数据湖下载的 json 文件