Hello Natalya, I found a problem in my random number generator. The number generated was to high. I tried to use your solution (Random::uniform(0,1)) but the compiler was unable to find the function and class Random. What library should I include to use Random::uniform ?
Another question: If I use sch:schedule(target_,packet,time) there's no need to use the function send(packet) ? Thank you very much for your help!!! Rafael 2012/10/3 Natalya Rozhnova <rojnovanatha...@yandex.ru> > Hey, In addition I guess the delay has to be in seconds and not in > milliseconds. > > > 03.10.2012, 22:51, "Natalya Rozhnova" <rojnovanatha...@yandex.ru>: > > It's strange... I use exactly the same idea. (I guess you are working on > information-centric networking :-) ). Here is a piece of my code I'm using > in my server agent: > > rtt_alea = Random::uniform(0,1); > Scheduler& sch = Scheduler::instance(); > sch.schedule(target_, Chunk, rtt_alea); > > You don't need the function send using this realization. > or me everything works well... Try to print your delay value, may be it is > not computed correctly and probably it's very large. > Print your <tempo> value into the consol to be sure this is not a trouble. > 03.10.2012, 22:38, "Rafael P B Mota" <rafaelpera...@gmail.com>: > > 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) > > ------------------------------------------------------------------------------------------------------------------ > > -- ---------------------------------------------------------------------------------------------------------------- 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) ------------------------------------------------------------------------------------------------------------------