[ns] Schedule an event

2012-10-03 Thread Rafael P B Mota

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();

send(pktret,0);
  }
  else {
Packet::free(pkt);
  }
  Packet::free(pkt);
  return;
}

-- 

Rafael Perazzo B Mota
r 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)
--


[ns] Random time to send a packet

2012-10-03 Thread Rafael P B Mota

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 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)
--


Re: [ns] Random time to send a packet

2012-10-03 Thread Rafael P B Mota

Thanks for the response Christos!!

I tried the while solution with no success. Is there any way to wait, for
instance, 100ms, before the command send(pktret,0) is executed ? I guess
it's a simple issue, but until now I was not able to solve.

Does anyone can suggest something to do ?

Thanks all!!


2012/10/3 Christos Spatiotis 

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Hello , Rafael
>
> If you try to put send(pktret,0) in a "while" which run for a random
> time. I guess i do not know.
> Please let me know if you make it.
>
> On 10/03/2012 05:37 PM, Rafael P B Mota wrote:
> >
> > 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; }
> >
>
>
> - --
> ===
> Undergraduate student Spatiotis Christos
> Department of Computer Engineering & Informatics (CEID)
> University of Patras, Greece
> e-mail: spati...@ceid.upatras.gr
> website: http://spatiotis.wordpress.com
> 
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.12 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>
> iQEcBAEBAgAGBQJQbE/YAAoJEC9xXqfymW+O/uQIAIxGwtzvq/DuK9v/A2pkqm0g
> sAvwTQeoyA+w2psIVdAObud+mhuYh1GMTIBHlTEmCOt/8nSCUVnswqQlbONAOx7Y
> HecsOmhcTeDbRh1ncXqNc3iw4DKtGwS2RaiFYolfjV6pXSKz/EM0YDR29p4uZv5K
> eRAEW5TIGTTy3dYWzUf2+dexz9AiA5+UHBpP+AT9EgoTCv2u2DTyiUt3ysDl4zTd
> HgKKwZ8iBNXO0H35Eqf2ri6R6adYVtERKpSNk5fW5fxMkQuqR18szzEYcNPrfgbQ
> MjaQQmBHy7iFFbC/Hu2nVPPmL3d6o8Qn66IvX/Ap6Yy6Kwa/a/PRZOyoFV5q2U8=
> =riL2
> -END PGP SIGNATURE-
>



-- 

Rafael Perazzo B Mota
r 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)
--


Re: [ns] Random time to send a packet

2012-10-03 Thread Rafael P B Mota

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 

> 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" :
>
> 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 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 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)
--


[ns] How ???

2012-10-03 Thread Christos Spatiotis

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello, ne users

How can i give 2 data channels for transmission?
I want to send simultaneously the same data from two channels.
Anybody help me?

Thanks, all
- -- 
===
Undergraduate student Spatiotis Christos
Department of Computer Engineering & Informatics (CEID)
University of Patras, Greece
e-mail: spati...@ceid.upatras.gr
website: http://spatiotis.wordpress.com

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBAgAGBQJQbGfaAAoJEC9xXqfymW+OsMEH+gKpLhcdCEALQJoNU2sgEKhW
nRZ0djXU4T7bS7NspnNVk32dulqeOSGIiE9tHyiNnmIM0RgprNnLNc/dRG9fl1Mk
wszFoOZZAMTqf1fa3HbPEo/q9xaW0C25lvm4Iyjulfs3zvn4D7tGYZ2/GEqg2bJV
tTF7jZF2xUcWB0vAZ/YGVTr/27KDtz3ZVvdGxFr/fY+9ezcVH5BCqS3+vztqn5l7
zhXEZ9A9LbPKzzZxrMJcZhfEhG2PojyN1MWsB6qOVEvF/vAal3cZe/T9RXoGpCB6
9Xpq6s7EIh572OMRLL7FJ4leaGsN8jbSuktBw5o/38ArVf7AE0+rUx5zLft9Pyk=
=MEpM
-END PGP SIGNATURE-



[ns] How give two data channels

2012-10-03 Thread Christos Spatiotis

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello, ns users

How can i give two data channels for transmission?
I want to send simultaneously the same data from two channels.
Anybody help me?

Thanks, all

- -- 
===
Undergraduate student Spatiotis Christos
Department of Computer Engineering & Informatics (CEID)
University of Patras, Greece
e-mail: spati...@ceid.upatras.gr
website: http://spatiotis.wordpress.com

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBAgAGBQJQbGh9AAoJEC9xXqfymW+ORiQH/3FZOHiYbQnMB5nsFBsiv/DO
sV2yjc7WrV0chyItdaBm7R1at+KGETZ68Wi+dN2J6e8gL2m8t2lXwgsNfPOEJooD
0RBGKDsCtxOTiJdBbhb+zf4iKdvO5lPX07CXIGD8o7O/ZJeH6N1QaS8suKeVxKyM
ee1h4Z0F9a/IgN6AI3gqZ3yuN6Tq+cvAaKbo/LuQiZYyVQlRUR/YkCXGr/URXa7Q
+kyvLDunyianMuOBC5jDnSGG+1/HkpMKaJlH8uQTu2c3dmUiR5TEc3uE1bnxMu3j
/9lTXvMdGoAH/iE23GsmZL7RHObrt7bWoVX4OSCmI9Mlw7pS/qD0lVmX/XYHFCs=
=mv1S
-END PGP SIGNATURE-



Re: [ns] Random time to send a packet

2012-10-03 Thread Rafael P B Mota

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 

> Hey, In addition I guess the delay has to be in seconds and not in
> milliseconds.
>
>
> 03.10.2012, 22:51, "Natalya Rozhnova" :
>
> 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  value into the consol to be sure this is not a trouble.
> 03.10.2012, 22:38, "Rafael P B Mota" :
>
> 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 
>
>  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" :
>
>  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 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 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 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)
--


Re: [ns] Random time to send a packet

2012-10-03 Thread Rafael P B Mota

Hello Natalya

Thank you very much for your help. Now my agent is working properly. It
delays x random seconds.

Rafael

2012/10/3 Natalya Rozhnova 

> Hi Rafael,
>
> In order to use the Random class of ns2 you should include random.h in
> your code. I guess there are some differents distributions of random
> numbers, not only uniform.
> Normally sch.schedule (blabla) is the same function as send. So, the
> difference between send and schedule is just that the first one sends a
> packet p with no delay while the second one adds a little delay before
> sending a packet p.
> If you look a realization of the function "send" you'll find something
> like "target_->recv(p)".
> What's about "schedule": this is a timer that executes the same
> "target_->recv(p)" but in some seconds (the third parameter: a delay).
>
> Natalya
>
> 03.10.2012, 23:46, "Rafael P B Mota" :
>
> 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 
>
>  Hey, In addition I guess the delay has to be in seconds and not in
>  milliseconds.
>
>
>  03.10.2012, 22:51, "Natalya Rozhnova" :
>
>  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  value into the consol to be sure this is not a trouble.
>  03.10.2012, 22:38, "Rafael P B Mota" :
>
>  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 
>
>   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" :
>
>   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 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 afaelpera...@gmail.com
>  Web-page: https://sites.google.com/site/rafaelperazzo/
>  Doutorando em Ciência da Computação
>  Universidade de São Paulo (USP)