From a3f979febf0a3ff63feea95a47cae71e35da3c84 Mon Sep 17 00:00:00 2001 From: Piotr Jurkiewicz Date: Tue, 19 Nov 2013 06:36:55 -0800 Subject: [PATCH] bug 1776: improve Csma CRC performance --- src/csma/model/csma-net-device.cc | 1 - src/network/utils/ethernet-trailer.cc | 25 +++---------------------- src/network/utils/ethernet-trailer.h | 2 -- src/network/wscript | 2 ++ 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/csma/model/csma-net-device.cc b/src/csma/model/csma-net-device.cc index 5a4bcc93c..f98d0686e 100644 --- a/src/csma/model/csma-net-device.cc +++ b/src/csma/model/csma-net-device.cc @@ -700,7 +700,6 @@ CsmaNetDevice::Receive (Ptr packet, Ptr senderDevice) trailer.EnableFcs (true); } - trailer.CheckFcs (packet); bool crcGood = trailer.CheckFcs (packet); if (!crcGood) { diff --git a/src/network/utils/ethernet-trailer.cc b/src/network/utils/ethernet-trailer.cc index df769f832..ed5e50e66 100644 --- a/src/network/utils/ethernet-trailer.cc +++ b/src/network/utils/ethernet-trailer.cc @@ -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 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 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 diff --git a/src/network/utils/ethernet-trailer.h b/src/network/utils/ethernet-trailer.h index c7de33fc5..f523744e9 100644 --- a/src/network/utils/ethernet-trailer.h +++ b/src/network/utils/ethernet-trailer.h @@ -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 diff --git a/src/network/wscript b/src/network/wscript index 850aab833..2d96f8853 100644 --- a/src/network/wscript +++ b/src/network/wscript @@ -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',