Send Packet (Ack) after receiving a packet inside SetReceivedPacket callbak

509 views
Skip to first unread message

Sérgio Sousa

unread,
Feb 9, 2011, 2:02:02 PM2/9/11
to ns-3-users
Hello,

i'm trying to implement a ACK mechanism, using SetReceivePacket
Callback. When a node that have the callback defined receive a data
packet, i would like it to send a smaller packet to the source node of
the first packet (send it an Ack). For that i use this code to define
the callback:

TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> recvSink = Socket::CreateSocket (wifiStaNodes.Get (i),
tid);
InetSocketAddress local = InetSocketAddress (interfaces.GetAddress(i),
9);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));



And inside the callback method (ReceivePacket) i do this:

OnOffHelper onoffd ("ns3::UdpSocketFactory",Address (InetSocketAddress
(ipv4From, 9)));
onoffd.SetAttribute ("OnTime", RandomVariableValue
(ConstantVariable(1)));
onoffd.SetAttribute ("OffTime", RandomVariableValue
(ConstantVariable(0)));
onoffd.SetAttribute ("PacketSize", StringValue("10"));
onoffd.SetAttribute ("MaxBytes", UintegerValue (10));

Ptr<Node> appSource = NodeList::GetNode (buf_to[3]-1);
ApplicationContainer appsd;
appsd = onoffd.Install (appSource);
appsd.Start (Simulator::Now());
appsd.Stop (ns3::Seconds (1.005));


The weird thing is that if I DON'T use these two lines:

"appsd.Start (Simulator::Now());
appsd.Stop (ns3::Seconds (1.005));"

the packets ARE SENT ANYWAY, and i don't want that because i need to
control the start and the end of sending.
If i use this to lines, it looks like it overlaps the sending that
supposelly happens without these lines, and everything fails, the
wireless medium does not check for iddle moments to transmit and the
packets are sent very late in the simulation.

I can tell that the line that makes the sending the happen without the
start method is:
"appsd = onoffd.Install (appSource);"

but that does not start any sending when i use this same methodology
earlier in the simulation (to send the first packet), with the only
difference that is not used inside the callback method and that way
everything works just fine.

I would really appreciate a help here.

Best Regards
Sérgio Sousa

Chris Dennett

unread,
Feb 9, 2011, 3:25:44 PM2/9/11
to ns-3-...@googlegroups.com
Hi Sérgio, are you using the constructor in your application for sending? This should be avoided, as it is only for setting properties and such in this case. You should instead implement the StartApplication function in ns3::Application. This is called at the time specified.

Cheers,
Chris

2011/2/9 Sérgio Sousa <spvs...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.


Sérgio Sousa

unread,
Feb 10, 2011, 6:11:01 AM2/10/11
to ns-3-users
Hello Chris,

thanks for the quick reply.
No i am not using a constructor, i just created an instance of the
object and used it.
Anyway can you be more specific about your suggestion?

Best Regards
Sérgio


On Feb 9, 8:25 pm, Chris Dennett <dessima...@gmail.com> wrote:
> Hi Sérgio, are you using the constructor in your application for sending?
> This should be avoided, as it is only for setting properties and such in
> this case. You should instead implement the StartApplication function in
> ns3::Application. This is called at the time specified.
>
> Cheers,
> Chris
>
> 2011/2/9 Sérgio Sousa <spvso...@gmail.com>
Reply all
Reply to author
Forward
0 new messages