Problem with SetReceiveCallback on NetDevice

130 views
Skip to first unread message

Nikos Stathopoulos

unread,
Jul 23, 2014, 7:48:59 AM7/23/14
to ns-3-...@googlegroups.com
Hello,

I've been trying to do a simulation of a wireless network, where the one of the nodes runs a UdpClient and and the other node has a UdpServer. My purpose is to do some modifications to the TxPower whenever a packet is received. So, I created a callback function and set it on the corresponding NetDevice, using SetReceiveCallback. However, when I run the script without the commands that sets the callback, the node is connected to the other one, but when I add this command, nothing happens at all. Can anyone help?

Thanks in advance,
Nikos

Code:
/*The callback function*/

bool OnReceive(Ptr<NetDevice> dev, Ptr<const Packet> packet, uint16_t protocol,  const Address & receiveAddr){//
//doStuff();
    return true;
    }  

int main(){
...
...
...
 staDevices.Get(0)-> SetReceiveCallback(MakeCallback(&OnReceive));

}



Tommaso Pecorella

unread,
Jul 24, 2014, 2:38:36 AM7/24/14
to ns-3-...@googlegroups.com
Hi,

you shouldn't do that. What you did (basically) is to detach the NetDevice from the IP layer. The NetDevice can send, but the received packets will be consumed by your function instead of the intended handler.

Try using one of the traces instead.

Cheers,

T.

Nikos Stathopoulos

unread,
Jul 28, 2014, 6:18:51 AM7/28/14
to ns-3-...@googlegroups.com
Hello, 

Thank you for your response. I understood what you said. However, there is not any trace source in NetDevice class, in order to do what I need to do. While searching, I found that there are some trace sources available in WifiPhy Class. How can I refer to this trace(what is the string that points to a source that belongs to WifiPhy)? Moreover, I need to modify txpower of the netdevice on runtime, how will that be possible?

Tommaso Pecorella

unread,
Jul 28, 2014, 3:21:40 PM7/28/14
to ns-3-...@googlegroups.com
Hi,

please refer to the documentation (or the sources) for the list of all the available traces. There are really many to choose from.
About changing the power at runtime, search the group, it has been discussed recently.

Cheers,

T

Nikos Stathopoulos

unread,
Jul 29, 2014, 2:43:57 AM7/29/14
to ns-3-...@googlegroups.com
Hello,

Well, after searching I found out that I had to create my own trace source in order to gain access to the PHY layer on runtime, and so did I.
Thank you for your help. 

Cheers,
Nikos

Mahfuz

unread,
Dec 28, 2016, 1:29:25 PM12/28/16
to ns-3-users
I want to send a packet to a network device. Please see the below codes. I am not understanding how can I use the call back function of NetDevice in line 3 and return to my own function to make further processing. 

Ptr<Node> a=ns3::NodeList::GetNode (2);

Ptr< NetDevice > enbNetDevice=a->GetDevice (0);

enbNetDevice->SetReceiveCallback(Callback<bool,Ptr<NetDevice>,Ptr<const Packet>,uint16_t,const Address &>);

if(enbNetDevice->Send (packet, enbNetDevice->GetAddress (), NetDevice::PACKET_HOST))

Tommaso Pecorella

unread,
Jan 2, 2017, 9:23:19 PM1/2/17
to ns-3-users
Hi,

please read the posting guidelines:
1) This is a 2.5 years old thread
2) Your problem description is incomplete and vague, and
3) Line 3 is not even a valid C++ code.

If you have issues with callbacks, please read the ns-3 manual as a first step.


T.

Mohammad Afrashteh

unread,
Sep 29, 2017, 2:55:48 PM9/29/17
to ns-3-users
Hi Tommaso,

My scenario is about VANET emergency messages broadcasting that doesn't use IP layer. Can I use NetDevice->SetReceiveCallback? If not, please explain its reasons.
Reply all
Reply to author
Forward
0 new messages