point-to-point: (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 08:10:44 -07:00
parent 8a395dc05a
commit 7eab0b51c9
4 changed files with 6 additions and 6 deletions

View File

@@ -85,7 +85,7 @@ PointToPointChannel::Attach (Ptr<PointToPointNetDevice> device)
bool
PointToPointChannel::TransmitStart (
Ptr<Packet> p,
Ptr<const Packet> p,
Ptr<PointToPointNetDevice> src,
Time txTime)
{
@@ -99,7 +99,7 @@ PointToPointChannel::TransmitStart (
Simulator::ScheduleWithContext (m_link[wire].m_dst->GetNode ()->GetId (),
txTime + m_delay, &PointToPointNetDevice::Receive,
m_link[wire].m_dst, p);
m_link[wire].m_dst, p->Copy ());
// Call the tx anim callback on the net device
m_txrxPointToPoint (p, src, m_link[wire].m_dst, txTime, txTime + m_delay);

View File

@@ -78,7 +78,7 @@ public:
* \param txTime Transmit time to apply
* \returns true if successful (currently always true)
*/
virtual bool TransmitStart (Ptr<Packet> p, Ptr<PointToPointNetDevice> src, Time txTime);
virtual bool TransmitStart (Ptr<const Packet> p, Ptr<PointToPointNetDevice> src, Time txTime);
/**
* \brief Get number of devices on this channel

View File

@@ -55,7 +55,7 @@ PointToPointRemoteChannel::~PointToPointRemoteChannel ()
bool
PointToPointRemoteChannel::TransmitStart (
Ptr<Packet> p,
Ptr<const Packet> p,
Ptr<PointToPointNetDevice> src,
Time txTime)
{
@@ -70,7 +70,7 @@ PointToPointRemoteChannel::TransmitStart (
#ifdef NS3_MPI
// Calculate the rxTime (absolute)
Time rxTime = Simulator::Now () + txTime + GetDelay ();
MpiInterface::SendPacket (p, rxTime, dst->GetNode ()->GetId (), dst->GetIfIndex ());
MpiInterface::SendPacket (p->Copy (), rxTime, dst->GetNode ()->GetId (), dst->GetIfIndex ());
#else
NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
#endif

View File

@@ -66,7 +66,7 @@ public:
* \param txTime Transmit time to apply
* \returns true if successful (currently always true)
*/
virtual bool TransmitStart (Ptr<Packet> p, Ptr<PointToPointNetDevice> src,
virtual bool TransmitStart (Ptr<const Packet> p, Ptr<PointToPointNetDevice> src,
Time txTime);
};