#include "trace.h"
class PriQueue : public DropTail {
public:
         PriQueue();
        int     command(int argc, const  char*const* argv);
        void    recv(Packet *p, Handler *h);
        void    recvHighPriority(Packet *, Handler  *);
        // insert packet at front of queue
        void filter(PacketFilter  filter, void * data);
        // apply filter to each packet in queue, 
        // - if filter returns 0 leave packet in queue
        // - if filter returns 1 remove packet from queue
        Packet* filter(nsaddr_t id);
   void   Terminate(void);
   //added  by smallko
   Tcl_Channel tchan_;      /* place to write trace records */
   TracedInt curq_;   /* current qlen seen by arrivals */
   void trace(TracedVar*); /* routine to write trace  records */
…………………….
1.        modify 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) {
    ……………………………
}
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; 
}
2.       modify tcl/lib/ns-default.tcl
add “Queue/DropTail/PriQueue set curq_ 0“
3.        make clean ; make 
4.        modify the tcl script file (I use a simple example to demonstrate how to measure the queue  length in the base station.)
............................................................................................
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(adhocRouting)   DSDV                       ;# routing protocol
set opt(x)               500               ;# X dimension of the topography
set opt(y)               500               ;# Y dimension of the topography
............................................................................................
set chan      [new $opt(chan)]
set topo       [new Topography]
$topo load_flatgrid  $opt(x) $opt(y)
$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  ON \
                 -agentTrace OFF \
                 -routerTrace OFF \
                 -macTrace OFF    \
                 -movementTrace  OFF
set BS(0) [$ns node 1.0.0]
$BS(0) random-motion 0
set bs_ifq  [$BS(0) set ifq_(0)]
set queuechan  [open qlen.tr w]
$bs_ifq trace curq_
$bs_ifq attach $queuechan
............................................................................................
5.        After simulation, you will find a file “qlen.tr”. In it, you can observe the queue length variation.............................................................................................
Reference : Smallko
getting error with respect to the line:
ReplyDelete$bs_ifq attach $queuechan
Run this code using ns-allinone-2.27, under cygwin...that means the OS is window XP. I tried to run this code under Ubuntu before, but error appeared..
DeleteSo are you saying that if I run the code using ns2 on the cygwin platform(Windows), I wouldnt get the error related to $bs_ifq attach $queuechan?
Deletehi,i am new to ns2...i am trying to find queue length in a .cc file and each time i call length() function from queue.cc i get the length as zero...is there anyway to get queue length?
ReplyDeleteHi, does this work on wired network? And how can i get the current link queue size in a variable so i can use it in a condition, on my TCL script?
ReplyDeleteHi. i want to get queue length n tried this code. but, when i execute step 3, i.e. running 'make' command, it give error that sheduler is not declared in this scope. how can i solve this problem. please help
ReplyDeletehello mam i have made the modification in priqueue.h and priqueue.cc as mentioned in above code. when i execute make in terminal i'm getting error as (queue/priqueue.cc: In member function ‘virtual void PriQueue::trace(TracedVar*)’:
ReplyDeletequeue/priqueue.cc:113: error: invalid conversion from ‘const char*’ to ‘char*’
make: *** [queue/priqueue.o] Error 1) please help me as soon as possible .i have modified all the 3 files mentioned
i have to modify AODV protocol so as to consider delay of path using queue length of path, so pleace tell me how i can get the queue length of node during route discovery procedure.
ReplyDelete