bug 1776: improve Csma CRC performance
This commit is contained in:
@@ -700,7 +700,6 @@ CsmaNetDevice::Receive (Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
|
||||
trailer.EnableFcs (true);
|
||||
}
|
||||
|
||||
trailer.CheckFcs (packet);
|
||||
bool crcGood = trailer.CheckFcs (packet);
|
||||
if (!crcGood)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/trailer.h"
|
||||
#include "ethernet-trailer.h"
|
||||
#include "crc32.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("EthernetTrailer");
|
||||
|
||||
@@ -59,7 +60,7 @@ EthernetTrailer::CheckFcs (Ptr<const Packet> p) const
|
||||
|
||||
buffer = new uint8_t[len];
|
||||
p->CopyData (buffer, len);
|
||||
crc = DoCalcFcs (buffer, len);
|
||||
crc = CRC32Calculate (buffer, len);
|
||||
delete[] buffer;
|
||||
return (m_fcs == crc);
|
||||
}
|
||||
@@ -78,7 +79,7 @@ EthernetTrailer::CalcFcs (Ptr<const Packet> p)
|
||||
|
||||
buffer = new uint8_t[len];
|
||||
p->CopyData (buffer, len);
|
||||
m_fcs = DoCalcFcs (buffer, len);
|
||||
m_fcs = CRC32Calculate (buffer, len);
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
@@ -152,24 +153,4 @@ EthernetTrailer::Deserialize (Buffer::Iterator end)
|
||||
return size;
|
||||
}
|
||||
|
||||
// This code is copied from /lib/crc32.c in the linux kernel.
|
||||
// It assumes little endian ordering.
|
||||
uint32_t
|
||||
EthernetTrailer::DoCalcFcs (uint8_t const *buffer, size_t len) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this << &buffer << len);
|
||||
uint32_t crc = 0xffffffff;
|
||||
int i;
|
||||
|
||||
while (len--)
|
||||
{
|
||||
crc ^= *buffer++;
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
|
||||
}
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -104,8 +104,6 @@ private:
|
||||
bool m_calcFcs;
|
||||
uint32_t m_fcs; /// Value of the fcs contained in the trailer
|
||||
|
||||
uint32_t DoCalcFcs (uint8_t const *buffer, size_t len) const;
|
||||
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -25,6 +25,7 @@ def build(bld):
|
||||
'model/trailer.cc',
|
||||
'utils/address-utils.cc',
|
||||
'utils/ascii-file.cc',
|
||||
'utils/crc32.cc',
|
||||
'utils/data-rate.cc',
|
||||
'utils/drop-tail-queue.cc',
|
||||
'utils/error-model.cc',
|
||||
@@ -102,6 +103,7 @@ def build(bld):
|
||||
'utils/address-utils.h',
|
||||
'utils/ascii-file.h',
|
||||
'utils/ascii-test.h',
|
||||
'utils/crc32.h',
|
||||
'utils/data-rate.h',
|
||||
'utils/drop-tail-queue.h',
|
||||
'utils/error-model.h',
|
||||
|
||||
Reference in New Issue
Block a user