csma: use const on transmitted packets

This commit is contained in:
Tommaso Pecorella
2023-10-04 09:44:15 +02:00
parent 7fbd63e085
commit f392502d9d
4 changed files with 21 additions and 20 deletions

View File

@@ -191,7 +191,7 @@ CsmaChannel::TransmitStart(Ptr<const Packet> p, uint32_t srcId)
}
NS_LOG_LOGIC("switch to TRANSMITTING");
m_currentPkt = p->Copy();
m_currentPkt = p;
m_currentSrc = srcId;
m_state = TRANSMITTING;
return true;
@@ -234,7 +234,7 @@ CsmaChannel::TransmitEnd()
m_delay,
&CsmaNetDevice::Receive,
it->devicePtr,
m_currentPkt->Copy(),
m_currentPkt,
m_deviceList[m_currentSrc].devicePtr);
}
}

View File

@@ -325,7 +325,7 @@ class CsmaChannel : public Channel
* packet to have been transmitted on the channel if the channel is
* free.)
*/
Ptr<Packet> m_currentPkt;
Ptr<const Packet> m_currentPkt;
/**
* Device Id of the source that is currently transmitting on the

View File

@@ -695,7 +695,7 @@ CsmaNetDevice::SetReceiveErrorModel(Ptr<ErrorModel> em)
}
void
CsmaNetDevice::Receive(Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
CsmaNetDevice::Receive(Ptr<const Packet> packet, Ptr<CsmaNetDevice> senderDevice)
{
NS_LOG_FUNCTION(packet << senderDevice);
NS_LOG_LOGIC("UID is " << packet->GetUid());
@@ -724,7 +724,9 @@ CsmaNetDevice::Receive(Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
return;
}
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt(packet))
Ptr<Packet> pktCopy = packet->Copy();
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt(pktCopy))
{
NS_LOG_LOGIC("Dropping pkt due to error model ");
m_phyRxDropTrace(packet);
@@ -735,16 +737,15 @@ CsmaNetDevice::Receive(Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
// Trace sinks will expect complete packets, not packets without some of the
// headers.
//
Ptr<Packet> originalPacket = packet->Copy();
EthernetTrailer trailer;
packet->RemoveTrailer(trailer);
pktCopy->RemoveTrailer(trailer);
if (Node::ChecksumEnabled())
{
trailer.EnableFcs(true);
}
bool crcGood = trailer.CheckFcs(packet);
bool crcGood = trailer.CheckFcs(pktCopy);
if (!crcGood)
{
NS_LOG_INFO("CRC error on Packet " << packet);
@@ -753,7 +754,7 @@ CsmaNetDevice::Receive(Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
}
EthernetHeader header(false);
packet->RemoveHeader(header);
pktCopy->RemoveHeader(header);
NS_LOG_LOGIC("Pkt source is " << header.GetSource());
NS_LOG_LOGIC("Pkt destination is " << header.GetDestination());
@@ -767,16 +768,16 @@ CsmaNetDevice::Receive(Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
//
if (header.GetLengthType() <= 1500)
{
NS_ASSERT(packet->GetSize() >= header.GetLengthType());
uint32_t padlen = packet->GetSize() - header.GetLengthType();
NS_ASSERT(pktCopy->GetSize() >= header.GetLengthType());
uint32_t padlen = pktCopy->GetSize() - header.GetLengthType();
NS_ASSERT(padlen <= 46);
if (padlen > 0)
{
packet->RemoveAtEnd(padlen);
pktCopy->RemoveAtEnd(padlen);
}
LlcSnapHeader llc;
packet->RemoveHeader(llc);
pktCopy->RemoveHeader(llc);
protocol = llc.GetType();
}
else
@@ -811,12 +812,12 @@ CsmaNetDevice::Receive(Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
// hook and pass a copy up to the promiscuous callback. Pass a copy to
// make sure that nobody messes with our packet.
//
m_promiscSnifferTrace(originalPacket);
m_promiscSnifferTrace(packet);
if (!m_promiscRxCallback.IsNull())
{
m_macPromiscRxTrace(originalPacket);
m_macPromiscRxTrace(packet);
m_promiscRxCallback(this,
packet,
pktCopy,
protocol,
header.GetSource(),
header.GetDestination(),
@@ -830,9 +831,9 @@ CsmaNetDevice::Receive(Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
//
if (packetType != PACKET_OTHERHOST)
{
m_snifferTrace(originalPacket);
m_macRxTrace(originalPacket);
m_rxCallback(this, packet, protocol, header.GetSource());
m_snifferTrace(packet);
m_macRxTrace(packet);
m_rxCallback(this, pktCopy, protocol, header.GetSource());
}
}

View File

@@ -172,7 +172,7 @@ class CsmaNetDevice : public NetDevice
* \param p a reference to the received packet
* \param sender the CsmaNetDevice that transmitted the packet in the first place
*/
void Receive(Ptr<Packet> p, Ptr<CsmaNetDevice> sender);
void Receive(Ptr<const Packet> p, Ptr<CsmaNetDevice> sender);
/**
* Is the send side of the network device enabled?