±H¥óªÌ: ¦¬¥óªÌ: ¥D¦®: A Bug of Q&A Q5 -- From Huang Lin ¤é´Á: 2006¦~8¤ë11¤é ¤U¤È 08:43 Hi, Mr. Ke. I have read your Q&A part of your website. It is quite useful. Yet it seems that you missed a part in question 5 -- a modification of command function. I put my supplyment and my tcl file below. It is ok when I test this tcl file. 2.­×§ïqueue/ priqueue.cc PriQueue::PriQueue() : DropTail() { bind("curq_",&curq_); tchan_=0; bind("Prefer_Routing_Protocols", &Prefer_Routing_Protocols); LIST_INSERT_HEAD(&prhead, this, link); } void PriQueue::recv(Packet *p, Handler *h) { struct hdr_cmn *ch = HDR_CMN(p); curq_ = q_->length(); if(Prefer_Routing_Protocols) { ¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­ } //add by Huang Lin, 2006-8-9,21:59 int PriQueue::command(int argc, const char*const* argv) { if (argc == 2 && strcasecmp(argv[1], "reset") == 0) { Terminate(); //FALL-THROUGH to give parents a chance to reset } else if(argc == 3 &&strcmp(argv[1], "attach") == 0) { int mode; const char* id = argv[2]; Tcl& tcl = Tcl::instance(); tchan_ = Tcl_GetChannel(tcl.interp(), (char*)id, &mode); if (tchan_ == 0) { tcl.resultf("trace: can't attach %s for writing", id); return (TCL_ERROR); } return (TCL_OK); } return DropTail::command(argc, argv); } void PriQueue::trace(TracedVar* v) { char wrk[500], *p; if (((p = strstr(v->name(), "curq")) == NULL) ) { fprintf(stderr, "PriQueue:unknown trace var %s\n", v->name()); return; } if (tchan_) { int n; double t = Scheduler::instance().clock(); if (strstr(v->name(), "curq") != NULL) { sprintf(wrk, "Q %g %d", t, int(*((TracedInt*) v))); } n = strlen(wrk); wrk[n] = '\n'; wrk[n+1] = 0; (void)Tcl_Write(tchan_, wrk, n+1); } return; } 5. Huang LinµÄtcl™n°¸ # globals and flags set ns [new Simulator] debug 1 #number of nodes set num_mobile_nodes 3 # Parameter for wireless nodes set opt(chan) Channel/WirelessChannel ;# channel type set opt(prop) Propagation/TwoRayGround ;# radio-propagation model set opt(netif) Phy/WirelessPhy ;# network interface type set opt(mac) Mac/802_11 ;# MAC type set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type set opt(ifqlen) 50 set opt(ll) LL ;# link layer type set opt(ant) Antenna/OmniAntenna ;# antenna model set opt(ifqlen) 50 ;# max packet in ifq set opt(adhocRouting) DumbAgent ;# routing protocol set opt(x) 670 ;# X dimension of the topography set opt(y) 670 ;# Y dimension of the topography #smallko add the following two lines Mac/802_11 set dataRate_ 1Mb Mac/802_11 set basicRate_ 1Mb set ntr [open out_rc_3.tr w] $ns trace-all $ntr set chan [new $opt(chan)] set topo [new Topography] $topo load_flatgrid $opt(x) $opt(y) # Create God create-god $num_mobile_nodes # config node $ns node-config -adhocRouting $opt(adhocRouting) \ -llType $opt(ll) \ -macType $opt(mac) \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \ -antType $opt(ant) \ -propType $opt(prop) \ -phyType $opt(netif) \ -channel $chan \ -topoInstance $topo \ -wiredRouting OFF \ -agentTrace ON \ -routerTrace OFF \ -macTrace OFF \ -movementTrace OFF # creating mobile nodes Mac/802_11 set RTSThreshold_ 3000 for {set i 0} {$i < $num_mobile_nodes} {incr i} { set wl_node_($i) [$ns node] $wl_node_($i) random-motion 0 ;# disable random motion puts "wireless node $i created ..." $wl_node_($i) set X_ [expr $i * 10.0] $wl_node_($i) set Y_ [expr $i * 10.0] $wl_node_($i) set Z_ 0.0 } set wl_ifq [$wl_node_(0) set ifq_(0)] set queuechan [open qlen.tr w] $wl_ifq trace curq_ $wl_ifq attach $queuechan for {set i 0} {$i < $num_mobile_nodes} {incr i} { set src_udp_($i) [new Agent/UDP] $src_udp_($i) set class_ $i set dst_udp_($i) [new Agent/Null] $ns attach-agent $wl_node_($i) $src_udp_($i) $ns attach-agent $wl_node_([expr ($i+1)%($num_mobile_nodes)]) $dst_udp_($i) set app_($i) [new Application/Traffic/CBR] $app_($i) set packetSize_ 1025 $app_($i) set interval_ 0.005 $app_($i) attach-agent $src_udp_($i) $ns connect $src_udp_($i) $dst_udp_($i) $ns set fid_ $i $ns at 0.$i "$app_($i) start" } # Define node initial position in nam for {set i 0} {$i < $num_mobile_nodes} {incr i} { $ns initial_node_pos $wl_node_($i) 20 } # Tell nodes when the simulation ends for {set i 0} {$i < $num_mobile_nodes } {incr i} { $ns at 10.0 "$wl_node_($i) reset"; } for {set i 0} {$i < $num_mobile_nodes} {incr i} { $ns at 100.0 "$app_($i) stop" } $ns at 110.0 "puts \"NS EXITING...\" ; $ns halt" proc stop {} { global ns ntr queuechan close $ntr close $queuechan } # run the simulation $ns run If convenient, please send me your solution, check my method and update the website. Best wishes. Huang Lin