NS2 仿真出错 extra switch pattern.compile with no body

1245人阅读
在ns2.31(2.33)下实现MFlood泛洪协议
大部分内容转载自:http://blog.chinaunix.net/u1/42672/showart_973304.html 本人也根据实践经历稍加修改和增加内容。
这是《NS与网络模拟》第七章的一个例子,展示了安装路由协议的一般流程,不过书上的步骤是针对ns2.26的,在ns2.31下安装需要有些修改。下面根据网上搜索到的信息和实际操作总结如下:首先确认已经获得下列文件(随书光盘里有,或者在网上搜索):mflood源码:mflood.cc,mflood.h,mflood-seqtable.cc,mflood-seqtable.h,mflood-packet.h。mflood测试代码:cbr-50n-30c-1p,scene-50n-0p-40s-400t-,getNodeRecv.awk,getRatio.awk,mflood-3nodes.tcl,mflood-scene.tcl。1、在ns-2.31目录下建立mflood文件夹,把上述文件统统放进去。2、修改ns-lib.tcl(在ns2.31/tcl/lib/):(红色表示添加部分)OMNIMCAST {&&& eval $node addr $args &&& set ragent [$self create-omnimcast-agent $node] } MFlood { &&& set ragent [$self create-mflood-agent $node]&}&DumbAgent { &&& set ragent [$self create-dumb-agent $node] } 另外在空白处加入:Simulator instproc create-tora-agent { node } { &&& set ragent [new Agent/TORA [$node id]] &&& $node set ragent_ $ragent &&& return $ragent } Simulator instproc create-mflood-agent {node} { &&& set ragent [new Agent/MFlood [$node id]] &&& $node set ragent_ $ragent &&& return $ragent&}3、修改ns-packet.tcl(在ns2.31/tcl/lib/):foreach prot {&&&& ...&&& MFlood &&& AODV&&& ...} 4、修改packet.h(在ns2.31/common/):enum packet_t {&&&& ?? &&& PT_AODV, &&& PT_MFLOOD, &&& ?? }(在更高的版本2.33中应该为 static const packet_t PT_MFLOOD = 61,其中不一定是“61”,只要为一个不与别人重复的编号就行) p_info() { &&& ?? &&& name_[PT_AODV]= "AODV"; &&& name_[PT_MFLOOD]="MFlood"; &&& ?? } 5、修改Makefile(在ns2.31/)在OBJ_CC中增加一行:mflood/mflood.o mflood/mflood-seqtable.o /&6、在mflood.cc(在刚建立的文件加ns2.31/mflood/)中加入:&&&&&&& ...&&&&&&& uptarget_ = (NsObject*)TclObject::lookup(argv[2]);&&&&&&&& if (uptarget_ == 0) {&&&&&&&&&&&& tcl.resultf("no such object %s", argv[2]);&&&&&&&&&&&& return (TCL_ERROR);&&&&&&&& }&&&&&&&& return (TCL_OK);&&&&&&&& }
&&&&&&& else if (strcasecmp (argv[1], "port-dmux") == 0) {&&&&&&&&&&&& TclObject *&&&&&&&&&&&& port_dmux_ = (NsObject *)&&&&&&&&&&&& return TCL_OK;&&&&&&&& }&&& }&&&& return Agent::command(argc, argv); } 并且修改:MFlood::MFlood(nsaddr_t id) : Agent(PT_MFLOOD), port_dmux_(0) {&&&&&index_ = &&& logtarget = 0; &&& myseq_ = 0; }
7、修改mflood.h(在ns2.31/mflood/):NsObject *uptarget_; NsObject *port_dmux_; 8、在ns2.31/下make,可能会有一些warning,不用去管它。9、测试:(进入mflood/)a)测试mflood-3nodes.tclns mflood-3nodes.tcl输出:num_nodes is set 3INITIALIZE THE LIST xListHeadStarting Simulation ...channel.cc:sendUp - Calc highestAntennaZ_ and distCST_highestAntennaZ_ = 1.5, distCST_ = 550.0SORTING LISTS ...DONE!NS EXITING ...b)测试mflood-sceen.tcl首先修改mflood-sceen.tcl文件:(将文件名改成同目录下的scene-50n-0p-40s-400t-)#set val(sc)&&&&&&&&&&&& "../scene-50n-0p-2s-400t-"set val(sc)&&&&&&&&&&&& "scene-50n-0p-40s-400t-"#set val(sc)&&"../scene/jscene-50n-0p-2s-400t-"然后输入:ns mflood-sceen.tcl输出类似上面的,会生成57兆左右的trace文件。其他的数据分析应该没什么问题了。---------------------------------------------------------至于很多人遇到的这个问题(我本人也被它烦了很久):错误代码是:extra switch pattern with no body while executing
"switch -exact $routingAgent_ {
set ragent [$self create-dsdv-agent $node]
$self at 0.0 "$node start-dsr"
set ragent [$self cre..."
(procedure "_o3" line 11)
(Simulator create-wireless-node line 11)
invoked from within
"_o3 create-wireless-node"
("eval" body line 1)
invoked from within
"eval $self create-wireless-node $args"
(procedure "_o3" line 23)
(Simulator node line 23)
invoked from within
"$ns_ node"
("for" body line 2)
invoked from within
"for {set i 0} {$i & $val(nn) } {incr i} {
能否给我分析一下错误的原因应该是你在修改tcl或者packet.h的时候出了问题,例如{}前后或之间的空格或tab键的个数多或少了。此外,你再看看你的ns-lib.tcl文件中约680行左右中的语句段中是否多加了一条类似$routingAgent_ == "MFlood"的语句,如果是,则删之。如下面注释。
& & & & if {$routingAgent_ == "DIFFUSION/RATE" ||
& && && && &$routingAgent_ == "DIFFUSION/PROB" ||
& && && && &$routingAgent_ == "FLOODING" ||
& && && && &$routingAgent_ == "OMNIMCAST" ||
& && && && & $routingAgent_ == "MFlood" ||//这条语句没必要,不要加,加了就可能会出现上面的错误。
& & & && &&&$routingAgent_ == "Directed_Diffusion" } {
& & & & & & & & $ragent port-dmux [$node demux]
& & & & & & & & $node instvar ll_
& & & & & & & & $ragent add-ll $ll_(0)
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:140006次
积分:1871
积分:1871
排名:第8080名
原创:33篇
转载:157篇
评论:21条
(6)(7)(14)(2)(7)(1)(3)(3)(2)(5)(9)(1)(1)(9)(11)(9)(4)(18)(1)(2)(4)(2)(2)(15)(6)(19)(27)

我要回帖

更多关于 conversionpattern 的文章

 

随机推荐