csma: (fixes #2556) Avoid modification of transmitted packets

Packets sent to channel may later be modified by calling device.  Possible
solutions are to copy before or after sending the packet to the channel.
Adopted solution similar to YansWifiChannel; a Ptr<const Packet> is instead
passed to the channel object, and channel object is responsible for copy.
This commit is contained in:
Tom Henderson
2017-06-03 07:59:20 -07:00
parent 222b2778aa
commit 8a395dc05a
2 changed files with 3 additions and 3 deletions

View File

@@ -170,7 +170,7 @@ CsmaChannel::Detach (Ptr<CsmaNetDevice> device)
}
bool
CsmaChannel::TransmitStart (Ptr<Packet> p, uint32_t srcId)
CsmaChannel::TransmitStart (Ptr<const Packet> p, uint32_t srcId)
{
NS_LOG_FUNCTION (this << p << srcId);
NS_LOG_INFO ("UID is " << p->GetUid () << ")");
@@ -188,7 +188,7 @@ CsmaChannel::TransmitStart (Ptr<Packet> p, uint32_t srcId)
}
NS_LOG_LOGIC ("switch to TRANSMITTING");
m_currentPkt = p;
m_currentPkt = p->Copy ();
m_currentSrc = srcId;
m_state = TRANSMITTING;
return true;

View File

@@ -184,7 +184,7 @@ public:
* \return True if the channel is not busy and the transmitting net
* device is currently active.
*/
bool TransmitStart (Ptr<Packet> p, uint32_t srcId);
bool TransmitStart (Ptr<const Packet> p, uint32_t srcId);
/**
* \brief Indicates that the net device has finished transmitting