Q & A

Q1: How to measure the queue length in the base station or mobile node?

A1:

1.        modify queue/priqueue.h

#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.