Hi , dear users
I'm writing two Agent which can be used in one host node (AgentCPU) and another 
for at least four client(AgentDISK).
And the host with traffic generator(Exponential) will send packet to client,
after a delay it will be sended to host again.
 And the information calculation will be in host.
 However, in my test.tcl (only two nodes for test packet process)
the packet received in client seems didn't send back to host.
In fact it send to client again and the host didnt receive any packet
I had tried to modyfied the saddr() and daddr() field in ip header
when I traced the received packet two field , and the value is 0 and 1
I think they are represent the two node.
So I exchange the two value so the source address and the dest address will 
exchange
and the packet will be send back to host.
But it results in Seg fault ..
Could somebody give me a hand..
Did the send function any obvious wrong?
Here I attached my code ..
                                          
#include "AgentCPU.h"
#include "packet.h"
#include "random.h"
#include "ip.h"
int hdr_task::offset_;

static class TASKHeaderClass : public PacketHeaderClass {
public:
     TASKHeaderClass()
       :PacketHeaderClass("PacketHeader/TASKHEAD",sizeof(hdr_task)) {
                bind_offset(&hdr_task::offset_);
     }
} class_task_hdr;

static class CPUClass : public TclClass {
public:
        CPUClass() : TclClass("Agent/AgentCPU") {}
        TclObject* create(int, const char*const*) {
                return (new AgentCPU());
        }
}class_cpu_agent;

AgentCPU::AgentCPU() : Agent(PT_TASK)
{
        
        npkts_=0;
        record_packet_Time_=0.0;

        bind("packetSize_",&size_);
        bind("record_packet_Time_",&record_packet_Time_);
        bind("npkt_",&npkts_);


}

void AgentCPU::sendmsg(int nbytes, const char* flags)
{

        Packet *pkt =allocpkt();

        hdr_cmn *ch = hdr_cmn::access(pkt);
        hdr_ip *iph= hdr_ip::access(pkt);
        hdr_task *task= hdr_task::access(pkt);

        task->number=Random::exponential(5000);
        task->state=0;
        task->total_time=0;
        
        target_->recv(pkt);
        idle();
}
void AgentCPU::recv(Packet* pkt, Handler*) 
{

        hdr_task *task= hdr_task::access(pkt);  
                if(task->number >2500)
                {
                        task -> total_time += 2500;
                        task -> number -=2500;
                        task -> state=0;

//                      printf("exe 2500 and the packet exe number is 
%d\n",task->number);
                        target_->recv(pkt, (Handler*)0);
                        }
                else
                {
                        task ->total_time += task->number ;
                        task ->number =0;

                        ++npkts_;
                        record_packet_Time_+= task ->total_time;
                        Tcl& tcl =Tcl::instance();
                        Packet::free(pkt);
                        }

        }
        
}

#ifndef ns_cpu_h
#define ns_cpu_h


#include <tclcl.h>
//#include <stdio.h>

#include "agent.h"
#include "config.h"
#include "packet.h"
#include "trafgen.h"


#define SAMPLERATE 8000
struct hdr_task {
//      float execute_time;     
        int total_time;

        int size_;
        int number;
        int& size() { return size_;}
        static int offset_;
        inline static int& offset() { return offset_; }
        inline static hdr_task* access (const Packet* p) {
                return (hdr_task*) p->access(offset_);
        }
};
class AgentCPU : public Agent {

public:
        
        AgentCPU();
        virtual void recv(Packet *, Handler *);
        
        virtual void sendmsg(int nbytes, const char *flags = 0);

private:
        double busy_time_;
        float execute_time_;
        float execute_time_exp;
        double record_packet_Time_;
        int npkts_;

};

#endif
#include "AgentDISK.h"
#include "packet.h"
#include "random.h"
#include "ip.h"



static class DISKClass : public TclClass {
public:
        DISKClass() : TclClass("Agent/AgentDISK") {}
        TclObject* create(int, const char*const*) {
                return (new AgentDISK());
        }
}class_cpu_agent;


AgentDISK::AgentDISK() : Agent(PT_TASK)
{

}

void AgentDISK::recv(Packet* pkt, Handler*) 
{
                hdr_ip *iph=hdr_ip::access(pkt);
//              printf("hi,here is disk\n");
                int temp = iph->saddr();
//              iph->saddr()=1;
//              iph->daddr()=0;
                hdr_task *task= hdr_task::access(pkt);
                int hold_time =Random::exponential(2000);
                task->total_time += hold_time;
                Scheduler& s =Scheduler::instance();
                double delay = Random::exponential(0.2);
                s.schedule(target_,pkt,delay);          
}
#ifndef ns_disk_h
#define ns_disk_h


#include <tclcl.h>
#include "agent.h"
#include "config.h"
#include "packet.h"
#include "timer-handler.h"
#include "app.h"

#include "trafgen.h"
#include "myAgent/AgentCPU.h"

class AgentDISK : public Agent {

public:
        AgentDISK();
        virtual void recv(Packet *, Handler *);
        

private:
        double busy_time_;
        double execute_time_;
        double execute_time_exp;
        double record_packet_Ttime_;
        double npkts_;
        
};

#endif 

Reply via email to