Hello Natalya,

I tryed the solution:

          srand(time(NULL));
          int tempo = rand() % 400 + 100;
          Scheduler& sch = Scheduler::instance();
          sch.schedule(target_,pktret,tempo);
          //send(pktret,0);

But the packet is not sent.
If I uncomment the line send(pktret,0) I get an error like this: Scheduler:
Event UID not valid!

What should I do ?

2012/10/3 Natalya Rozhnova <rojnovanatha...@yandex.ru>

> Hi,
>
> There are two ways to do it. Try this way for example:
>
> Scheduler& sch = Scheduler::instance();
> sch.schedule(target_, [packet you want to send], [delay in ms]);
>
> The second way I don't remember exactly but it consists in using the
> function reschedule. You can read about these functions in detail in ns2
> manual.
>
> Hope it helps you,
> --
> Cordialement,
> Natalya Rozhnova
>
> 03.10.2012, 21:44, "Rafael P B Mota" <rafaelpera...@gmail.com>:
>
> Hello,
>
> I am trying to use a random delay (in receiver) before the packet is sent
> back to the sender agent. For example:
>
> 1) the receiver agent receive the sender packet
> 2) the receiver sets up a response packet
> 3) Wait for a random time (in ms)
> 4) sends the packet.
>
> I don't know how to do the step 3.
>
> I am pasting the code bellow: Somebody can help me ?
>
> void MyAgent::recv(Packet* pkt, Handler*)
> {
>   hdr_ip* hdrip = hdr_ip::access(pkt);
>   hdr_rfidPacket* hdr = hdr_rfidPacket::access(pkt);
>   if (hdr->tipo_==1) {
>   Packet* pktret = allocpkt();
>      hdr_rfidPacket* hdrTag = hdr_rfidPacket::access(pktret);
>      hdr_ip* hdrIp = hdr_ip::access(pktret);
>      hdrTag->tagEPC_ = tagEPC_;
>   hdrTag->id_ = hdr->id_;
>      hdrTag->tipo_ = 0;
>      hdrIp->daddr() = IP_BROADCAST;
>      hdrIp->dport() = hdrip->sport();
>      *//HOWTO WAIT A RANDOM TIME (in miliseconds) before send back the
> packet ??*
>
>           send(pktret,0);
>   }
>   else {
> Packet::free(pkt);
>   }
>   Packet::free(pkt);
>   return;
> }
>
> --
>
> ----------------------------------------------------------------------------------------------------------------
> Rafael Perazzo B Mota
> r <pera...@ime.usp.br>afaelpera...@gmail.com
>
> Web-page: https://sites.google.com/site/rafaelperazzo/
> Doutorando em Ciência da Computação
> Universidade de São Paulo (USP)
> Campus da Capital
> Instituto de Matemática e estatística (IME)
>
> ------------------------------------------------------------------------------------------------------------------
>
>


-- 
----------------------------------------------------------------------------------------------------------------
Rafael Perazzo B Mota
r <pera...@ime.usp.br>afaelpera...@gmail.com
Web-page: https://sites.google.com/site/rafaelperazzo/
Doutorando em Ciência da Computação
Universidade de São Paulo (USP)
Campus da Capital
Instituto de Matemática e estatística (IME)
------------------------------------------------------------------------------------------------------------------

Reply via email to