How to trigger transmit event once csma channel is idle

26 views
Skip to first unread message

Osman Malik

unread,
Dec 20, 2016, 4:29:26 PM12/20/16
to ns-3-users
Hi,

I am relatively new to advanced c++ so forgive me for my lack of understanding.

My problem is that I want to implement a turn taking csma protocol in ns3. Having looked at csma-net-device.cc and csma-channel.cc, I want to schedule a custom event CsmaNetDevice::allReceivedEvent from CsmaChannel::PropagationCompleteEvent using
Simulator::Schedule (delay_allReceivedCallBack, &CsmaNetDevice::TransmitReadyEvent, this);

However, I receive an error message 'within this context' upon compilation. Can someone please let me understand what is going wrong and how I should trigger a transmit event in CsmaNetDevice once CsmaChannel has set the channel to be idle?

Thanks in advance.

Tommaso Pecorella

unread,
Dec 26, 2016, 7:29:55 PM12/26/16
to ns-3-users
Hi,

you're looking at the wrong part of the function.
  Simulator::Schedule (m_delay, &CsmaChannel::PropagationCompleteEvent, this);
is only changing the channel status to idle.

If you want to signal the nodes (i.e., the CsmaNetDevice) that the channel is idle, then you should use an iterator, i.e., something similar to:
  std::vector<CsmaDeviceRec>::iterator it;
 
for (it = m_deviceList.begin (); it < m_deviceList.end (); it++)
    {
     
if (it->IsActive ())
       
{
         
// schedule reception events
         
Simulator::ScheduleWithContext (it->devicePtr->GetNode ()->GetId (),
                                          m_delay
,
                                         
&CsmaNetDevice::Receive, it->devicePtr,
                                          m_currentPkt
->Copy (), m_deviceList[m_currentSrc].devicePtr);
       
}
   
}

However, this is actually not really necessary. When CsmaNetDevice::Receive is called, you know that the channel is going be idle "soon".

Hope this helps,

T.
Reply all
Reply to author
Forward
0 new messages