[Click] Using Click while adding random packet delay

Francis Bogsanyi fbogsany at metabunny.com
Sat Mar 20 12:24:47 EST 2004


There's a memory leak: static_expire_packet() should delete the 
PacketTimerPair after expiring the packet.

Francis.

On 20-Mar-04, at 5:03 AM, Fran wrote:

>  I have created a new element that add a random packet delay to each 
> packet before send it to the interface.
>
>  This is the code. I hope this could help you!!!
>
>         Fran.
>
>  .hh file
>  --------------------------
> #ifndef CLICK_MMARPWAITRANDOM_HH
>  #define CLICK_MMARPWAITRANDOM_HH
>  #include <click/element.hh>
>  #include <elements/mmarp/mmarp.hh>
>  #include <click/timer.hh>
>
>  CLICK_DECLS
>
>  class MMARPWaitRandom : public Element { public:
>   
>    MMARPWaitRandom();
>    ~MMARPWaitRandom();
>
>   
>    const char *class_name() const        { return "MMARPWaitRandom"; }
>    const char *processing() const        { return AGNOSTIC; }
>    MMARPWaitRandom *clone() const        { return new MMARPWaitRandom; 
> }
>    int configure(Vector<String> &, ErrorHandler *);
>    int initialize(ErrorHandler *);
>   
>    Packet *simple_action(Packet *);
>
>  private:
>
>    struct PacketTimerPair {
>        MMARPWaitRandom *obj;
>        Packet *p;
>
>        PacketTimerPair(MMARPWaitRandom *o) : obj(o) { }
>
>      private:
>        PacketTimerPair() { }
>    };
>
>    static void static_expire_packet(Timer *, void *v)
>    { ((PacketTimerPair *) v)->obj->expire_packet(*((PacketTimerPair *) 
> v)->p); }
>    void expire_packet(Packet &);
>
>    Timer *t;
>    PacketTimerPair *ptp;
>
>    unsigned long _wait; 
>  };
>
>  CLICK_ENDDECLS
>  #endif
> ---------------------------------------------
>  .cc file
>  ---------------------------------------------
> /*
>   * mmarpwaitrandom.{cc,hh} --
>   *
>   */
>
>  #include <click/config.h>
>  #include "mmarpwaitrandom.hh"
>  #include <click/timer.hh>
>  #include <time.h>
>  #include <click/confparse.hh>
>
>  CLICK_DECLS
>
>  MMARPWaitRandom::MMARPWaitRandom()
>    : Element(1, 1)
>  {
>    MOD_INC_USE_COUNT;
>  }
>
>  MMARPWaitRandom::~MMARPWaitRandom()
>  {
>    MOD_DEC_USE_COUNT;
>  }
>
>  int
>  MMARPWaitRandom::initialize(ErrorHandler *)
>  {
>      srand(time(NULL));
>
>      return 0;
>  }
>  int
>  MMARPWaitRandom::configure(Vector<String> &conf, ErrorHandler *errh)
>  {
>          return cp_va_parse(conf, this, errh,
>                          cpUnsigned, "limit ms to wait", &_wait,
>                          0);
>  }
>
>  void
>  MMARPWaitRandom::expire_packet(Packet &p){
>    t->unschedule();
>    output(0).push(&p);
>  }
>
>  Packet *
>  MMARPWaitRandom::simple_action(Packet *p)
>  {
>    ptp = new PacketTimerPair(this);
>    ptp->p = p;
>    t = new Timer(static_expire_packet, (void *) ptp);
>    t->initialize(this);
>
>    uint32_t micros = _wait * 1000;
>    uint32_t num = (uint32_t)((double)micros * rand()/(RAND_MAX+1.0));
>    double d = (double)num / 1000.0;
>    t->schedule_after_ms(d);
>
>    return 0;
>  }
>
>  CLICK_ENDDECLS
>  EXPORT_ELEMENT(MMARPWaitRandom)
>  ELEMENT_MT_SAFE(MMARPWaitRandom)
>
> ----------------------------------------------
>
>  At 14:18 19/03/2004 -0600, you wrote:
>
>
> I am wondering how I could use your software router to add a random
>  packet delay to each packet that the router sends. (Maybe do some code
>  modifications? But where?). Any information to do this would greatly 
> be
>  appreciated.
>
>  Thanks,
>
>  Anthony G Persaud
>  ironstar at iastate.edu
>
>
>
>
>  _______________________________________________
>  click mailing list
>  click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click



More information about the click mailing list