need help on creating this new protocol

View: New views
2 Messages — Rating Filter:   Alert me  

need help on creating this new protocol

by JCJC :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi guys, I tried several days on this one, but stuck at somewhere, please help.

I want to design an agent with a timer, when get attached to a CBR and CBR start, send out only one request packet to the other side.  when timer expires, the agent send out 2 packets reset the timer, then timer expires, send out 4 packets.... next time 8 packets until 2^x packets.

I set up a control variable repcount, my idea is when expire event triggers repcount++, send out packets then reset the timer, but I found out the timer scheduled once successfully, but failed to reset later on. And for some reason in function timeout(int ) the repcount is not added up. And when I check the timer status(), it became x. So I think my ultimate question is, how can the variable member be operated correctly in an agent and what happened to my timer? Thank you so much.

By the way, on NS2, I set the packet interval time to a very large number, so only one sendmsg signal should be sent to the agent during the process.

PRO.h is like

#ifndef __PRO_h__

#define __PRO_h__



#include "PRO_pkt.h"

#include <agent.h>

#include <packet.h>

#include <timer-handler.h>

#include <trace.h>

#include <random.h>
#include <tclcl.h>



#define PRO_ACK_TO 0

#define T 0.5



class PRO;



/* Timer */

class PRO_PktTimer : public TimerHandler {

public:

   PRO_PktTimer(PRO* agent) : TimerHandler() {

        agent_ = agent;

    }

protected:
        virtual void expire(Event* e);
        PRO*   agent_;

};




/* Agent */



class PRO : public Agent {

        /* Friends */

        friend class PRO_PktTimer;



        /* Private members */
private:
        int reqno;
        char pkttype;

        int repcount; //j
        double J;
        int initialsent;
       
protected:

        Trace* logtarget_;
        PRO_PktTimer pkt_timer_;

       
       

public:

        PRO();

        void sendmsg(int nbytes, const char*);
        void sendreq();
        void PRO_send();
        void succeed();
        EventTrace *et_;
        void trace_event(char* eventtype);
        void timeout(int tno);

};


#endif


my cc file is like

#include "PRO.h"

#include "PRO_pkt.h"

#include <iostream>
#include <math.h>





int hdr_PRO_pkt::offset_;

static class PROHeaderClass : public PacketHeaderClass {

public:

        PROHeaderClass() : PacketHeaderClass("PacketHeader/PRO", sizeof(hdr_PRO_pkt)) {

                bind_offset(&hdr_PRO_pkt::offset_);

        }

} class_PROhdr;



static class PROClass : public TclClass {

public:

        PROClass() : TclClass("Agent/PRO") {}

        TclObject* create(int argc, const char*const* argv) {

                return (new PRO());

        }

} class_PRO;




void PRO_PktTimer::expire(Event*)
{
       
agent_->timeout(0);

}



PRO::PRO(): Agent(PT_PRO), pkt_timer_(this),ack_rcv(0),initialsent(0),reqno(0)
{
        J = 10;
        bind("packetSize_", &size_);
        repcount=0;

}



void

PRO::sendmsg(int nbytes, const char* ) {
        sendreq();
}

void
PRO::sendreq(){
        PRO_send();
        if (!(pkt_timer_.status() == TIMER_PENDING)||(repcount>=1))
                {

                        pkt_timer_.resched(T);
                }
               
}

void
PRO::PRO_send() {
        int j;
        int actcount;
        actcount = (repcount == 0)?1:(2*actcount);
        for (j=0;j<=actcount;j++)
        {
               
                Packet* pkt = allocpkt();

                struct hdr_PRO_pkt* hdr = HDR_PRO_PKT(pkt);

                hdr->pkt_req()=1;
                hdr->pkt_seq()=repcount;
                hdr->pkt_ack()=0;
                hdr->pkt_dack()=0;
                hdr->ctime()=Scheduler::instance().clock();

                target_->recv(pkt);
               
        }
       
}

void PRO::succeed()
{
        return;
}

void PRO::timeout(int tno)
{
        repcount++;
       
        if (repcount<=J) {
               
                PRO_send();
                pkt_timer_.sched(T);
        }
        else {
                return;
        }
       
}


Re: need help on creating this new protocol

by JCJC :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think I figure it out.