[ns] Res: Create a new Agent class

Alex Leal Ginatto alginatto at yahoo.com.br
Wed Dec 5 17:59:18 PST 2007


Hi all!
I have the same problem as Riccardo, but in my case, I´m implementing a new filter class...
The message I receive is the same. 
Can anyone help us?
Thanks in advance.
Alex

----- Mensagem original ----
De: Bassoli Riccardo <bassoli.riccardo.45765 at unimore.it>
Para: ns-users at ISI.EDU
Enviadas: Quarta-feira, 5 de Dezembro de 2007 21:49:52
Assunto: [ns] Create a new Agent class


Hi!

I've created a new Agent to impement a core node. I've written the 2 
files .h and .cc in this way:

AgCore.h
-----------------
#ifndef ns_AgCore_h
#define ns_AgCore_h

#include "tclcl.h"
#include "packet.h"
#include "agent.h"


class AgCore : public Agent {
  
   public:
    AgCore();
    virtual void recv(Packet* pkt, Handler*);          
    int command(int argc, const char*const* argv);         

   protected:
    int Bu;                        
    double ti;                        
    long payload;                        
    long slotDel;                          
    double Tburst;                       


};

#endif

-----------------------
AgCore.cc
-----------------------
#include "AgCore.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>

static class AgCoreclass : public TclClass {

   public:
       AgCoreclass() : TclClass("Agent/Core") {}
       TclObject* create(int, const char*const*) {
           return (new AgCore());
       }

} class_agcore;


AgCore::AgCore()
   : Agent(PT_SLOT),
   Bu(0), ti(0), payload(0), slotDel(0), Tburst(0)

{
   bind("Bu_", &Bu);                   
}


void AgCore::recv(Packet *pkt, Handler*)
{
   double t = Scheduler::instance().clock();      
   payload = hdr_cmn::access(pkt)->size();           
      

   if(ti < t < ti+Tburst) {
      
       Packet::free(pkt);               
       slotDel = slotDel + 1;

   } else {

       ti = t;
       Tburst = payload/Bu;               
       send(pkt, 0);                       

       }

}

int AgCore::command(int argc, const char* const* argv)
{
   if (strcmp(argv[1], "MisureLB") == 0) {              
  
       std::cout << "Burst persi = " << slotDel << "\n";
       return TCL_OK;
   }
   return (Agent::command(argc, argv));
}

-------------------
I've followed the tutorial about new PingAgent class to write my new
 Agent but when 
I write in my tcl script

set ac [new Agent/Core]
$ac set Bu_ $Bu
$ns attach-agent $Core $ac
$ns at $SIM_TIME "$ns detach-agent $Core $ac"

the simulation watch this error:

invalid command name "Agent/Core"
   while executing
"Agent/Core create _o147 "
   invoked from within
"catch "$className create $o $args" msg"
   invoked from within
"if [catch "$className create $o $args" msg] {
if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
delete $o
return ""
}
global errorInfo
error "class $..."
   (procedure "new" line 3)
   invoked from within
"new Agent/Core"
   invoked from within
"set ac [new Agent/Core]"
   (file "mio-mixed.tcl" line 199)


Can someone help me to solve this problem?

Please help me because I have to solve this problem...

Thank you.

Riccardo








      Abra sua conta no Yahoo! Mail, o único sem limite de espaço para armazenamento!
http://br.mail.yahoo.com/


More information about the Ns-users mailing list