sir,
  I am working on  Max-min kelly control  but in which mkc-queue.cc
file   and  mkc-queue.h
  does not  work  properly  .In which something missing  but i am not
understand  where is the  fault  in this file.


----------------------------------mkc-queue.cc------------------------------------------------------------------------
/*
 * Author: Yueping Zhang, Internet Research Lab (IRL), Texas A&M University
 * Email: yuep...@cs.tamu.edu
 * File Name: mkc_queue.cc
 * Functionality: implementation of mkc router
 * Last modified on Nov. 14, 2005
 */
#include <math.h>
#include <sys/types.h>
#include "config.h"
#include "template.h"
#include "random.h"
#include "flags.h"
#include "delay.h"
#include "mkc-queue.h"

/*
 * Delare the class of the MKC router
 */
static class MKCQueueClass : public TclClass {
public:
        MKCQueueClass() : TclClass("Queue/MKCQueue") {}
        TclObject* create(int, const char*const*) {
                return (new MKCQueue);
        }
} class_MKC_queue;

/*
 * Constructor of the MKC router class
 */
MKCQueue::MKCQueue()
{
        double now = Scheduler::instance().clock();
        q_ = new PacketQueue();// underlying queue
        


        bind("bytes", &bytes_ );
        bind("setbit", &setbit_);
        bind("C",       &C_);      // capacity
        bind("T",       &delta_);  // sampling interval
        bind("rid",     &rid_);    // router ID
        
        MKCp_.rcv_rate = 0;
        MKCp_.pkt_loss = 2;
        MKCp_.volume = 0;
        MKCp_.pkt_loss_seqno = -1;

        // start the timer
        tFinish_ = now + delta_;
        tStart_ = now;
        duration_ = delta_;
        
        isFirstPkt = 1;
}

/*
 * Receive function, called upon each packet arrival
 */
void MKCQueue::recv(Packet* p, Handler* h){
        double now = Scheduler::instance().clock();
        hdr_cmn* ch = hdr_cmn::access(p);

        if(ch->ptype() == PT_MKC)  // check if the incoming packet is an
MKC data packet
        {
                if(isFirstPkt){
                        // record the starting time of the current sampling 
interval
                        tStart_ = now;
                        tFinish_=tStart_ + delta_;
                        isFirstPkt = 0;
                }

                q_->enque(p);
                p = q_->deque();
                
                // if the current sampling interval ends, we proceed to 
synthesis the feedback
                compute_ack(p);

                // write ACK in the packet header
                do_on_packet_arrival(p);
                
                if(p != 0){
                Queue::recv(p,h);
                }
        // if the incoming packet is an MKC ACK, forward it immediately
        }
        else if (ch->ptype()==PT_MKC_ACK)
        {
                if(p != 0){
                        Queue::recv(p,h);                       
                }
        }
}

/*
 * Return the top packet in the queue
 */
Packet* MKCQueue::deque()
{
        Packet *p = q_->deque();
        return (p);
}

/*
 * Place the packet at the tail of the queue
 */
void MKCQueue::enque(Packet* pkt)
{
        q_ -> enque(pkt);
}

/*
 * Write feedback information in the packet header
 */
void MKCQueue::do_on_packet_arrival(Packet *p)
{
        hdr_mkc* header_mkc;
        header_mkc = hdr_mkc::access(p);

        MKCp_.volume += header_mkc->psize;

        // if the local packet loss is computed, override the packet header
if the packet loss carried in
        // header is less than the local packet loss, or the current router
is the first router for the packet
        if ((header_mkc->flost < MKCp_.pkt_loss|| header_mkc->is_changed ==
0) && MKCp_.pkt_loss != 2)
        {
                header_mkc->flost = MKCp_.pkt_loss;
                header_mkc->rid = rid_;
                header_mkc->delta = duration_;
                header_mkc->loss_seqno = MKCp_.pkt_loss_seqno;
                header_mkc->is_changed = 1;
        }
        // if the packet loss is not ready, mark the ACK invalid
        else if (MKCp_.pkt_loss == 2)
        {
                header_mkc->flost = 2;
                header_mkc->is_changed = 1;
        }
}

/*
 * Compute the feedback information, called upon each timer expiration
 */
void MKCQueue::compute_ack(Packet *p)
{
        hdr_mkc* header_mkc;
        header_mkc = hdr_mkc::access(p);
        double now = Scheduler::instance().clock();
        if(now >= tFinish_ && now > tStart_)
        {               
                duration_ = now - tStart_; // duration of the delta interval

                // increment packet loss seqence number by one
                MKCp_.pkt_loss_seqno++;

                // calculate the incoming rate during the last interval delta_
                MKCp_.rcv_rate=(double)MKCp_.volume/duration_;

                // calculate the packet loss
                if (MKCp_.rcv_rate != 0)
                        MKCp_.pkt_loss = (double)(MKCp_.rcv_rate - C_) / 
MKCp_.rcv_rate;
                else
                        MKCp_.pkt_loss = 2;

                tStart_ = now;
                tFinish_ = tStart_ + delta_;   // reset the timer

                // the current incoming packet should be counted in the 
previous interval
                MKCp_.volume = 0;
                MKCp_.rcv_rate = 0;                     
        }
        else if (now <= tStart_)
        {
                tStart_=now;
                tFinish_=tStart_+delta_;
        }
}











---------------------------------------------mkc-queue.h----------------------------------------------------------------------



/*
 * Author: Yueping Zhang, Internet Research Lab (IRL), Texas A&M University
 * Email: yuep...@cs.tamu.edu
 * File Name: mkc_queue.h
 * Functionality: header file of mkc router
 * Last modified on Nov 14, 2005
 */
#include "queue.h"
#include "trace.h"
#include <stdlib.h>
#include "agent.h"
#include "mkc-source.h"
#include "connector.h"
#include "random.h"
#include "config.h"

class MKCQueue;

/*
 * MKC parameters, supplied by user
 */
struct MKCp {
        int             pkt_loss_seqno;         // packet loss sequence number
        double  volume;                 // the total size of packets during the
current interval
        double  rcv_rate;               // computed rate of incoming traffic
        double  pkt_loss;               // packet loss computed based on 
incoming traffic
};

/*
 * Class of the MKC router
 */
class MKCQueue : public Queue {
public: 
                MKCQueue(); // constructor

protected:
                Packet*         deque();                                        
        // return the packet on top of the queue
                void            enque(Packet* pkt);             // enque the 
current packet
                void            recv(Packet* p, Handler*);          // receive 
function
                void            do_on_packet_arrival(Packet*);  // writeACK in 
the packet
header upon arrival
                void            compute_ack(Packet*);               // examine 
whether new ACK is ready
to compute

                PacketQueue     *q_;                                            
        /* underlying FIFO queue */             
                MKCp            MKCp_;                                          
        // local parameters
                double          C_;                                             
                // capacity of the out-going link
                double          delta_;                                         
        // time interval to calculate the incoming
rate and packet loss
                int                     rid_;   

                int bytes_ ;
                int setbit_;                                            // 
router ID
                double          duration_;                                      
        // duration of the current sampling interval
                double          tStart_;                                        
        // start time of the current sampling interval
                double          tFinish_;                                       
        // finish time of the current sampling interval
                int                     isFirstPkt;                             
                // whether the first packet has arrived
};





kindly  check  above   file  where is the  fault:--  attached file
also  here  available



thank you

Reply via email to