From a6c8a118815e93b620cf7fcc50e30235a10e3960 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sat, 2 Jun 2007 19:10:35 +0200 Subject: [PATCH] fix the packet benchmark and enable it --- SConstruct | 4 +- utils/bench-packets.cc | 140 ++++++++++++++++++++++++++++------------- 2 files changed, 99 insertions(+), 45 deletions(-) diff --git a/SConstruct b/SConstruct index e882b64b1..4cf009bf1 100644 --- a/SConstruct +++ b/SConstruct @@ -368,9 +368,9 @@ run_tests.add_deps(['core', 'simulator', 'common']) run_tests.add_source('run-tests.cc') bench_packets = build.Ns3Module('bench-packets', 'utils') -#ns3.add(bench_packets) +ns3.add(bench_packets) bench_packets.set_executable() -bench_packets.add_dep('core') +bench_packets.add_deps (['core', 'common']) bench_packets.add_source('bench-packets.cc') bench_simu = build.Ns3Module('bench-simulator', 'utils') diff --git a/utils/bench-packets.cc b/utils/bench-packets.cc index b99274b94..9d44a557f 100644 --- a/utils/bench-packets.cc +++ b/utils/bench-packets.cc @@ -18,85 +18,139 @@ * * Author: Mathieu Lacage */ -#include "ns3/wall-clock-ms.h" +#include "ns3/system-wall-clock-ms.h" #include "ns3/packet.h" -#include "ns3/chunk-constant-data.h" -#include "ns3/chunk-udp.h" -#include "ns3/chunk-ipv4.h" #include +#include using namespace ns3; +template +class BenchHeader : public Header +{ +public: + BenchHeader (); + bool IsOk (void) const; +private: + virtual std::string DoGetName (void) const; + virtual void PrintTo (std::ostream &os) const; + virtual uint32_t GetSerializedSize (void) const; + virtual void SerializeTo (Buffer::Iterator start) const; + virtual uint32_t DeserializeFrom (Buffer::Iterator start); + bool m_ok; +}; + +template +BenchHeader::BenchHeader () + : m_ok (false) +{} + +template +bool +BenchHeader::IsOk (void) const +{ + return m_ok; +} + +template +std::string +BenchHeader::DoGetName (void) const +{ + std::ostringstream oss; + oss << N; + return oss.str (); +} + +template +void +BenchHeader::PrintTo (std::ostream &os) const +{ + NS_ASSERT (false); +} +template +uint32_t +BenchHeader::GetSerializedSize (void) const +{ + return N; +} +template +void +BenchHeader::SerializeTo (Buffer::Iterator start) const +{ + start.WriteU8 (N, N); +} +template +uint32_t +BenchHeader::DeserializeFrom (Buffer::Iterator start) +{ + m_ok = true; + for (int i = 0; i < N; i++) + { + if (start.ReadU8 () != N) + { + m_ok = false; + } + } + return N; +} + + + static void benchPtrA (uint32_t n) { - ChunkConstantData data = ChunkConstantData (2000, 1); - ChunkUdp udp; - ChunkIpv4 ipv4; + BenchHeader<25> ipv4; + BenchHeader<8> udp; for (uint32_t i = 0; i < n; i++) { - Packet p; - p.add (&data); - p.add (&udp); - p.add (&ipv4); + Packet p (2000); + p.AddHeader (udp); + p.AddHeader (ipv4); Packet o = p; - o.peek (&ipv4); - o.remove (&ipv4); - o.peek (&udp); - o.remove (&udp); - o.peek (&data); - o.remove (&data); + o.RemoveHeader (ipv4); + o.RemoveHeader (udp); } } static void benchPtrB (uint32_t n) { - ChunkConstantData data = ChunkConstantData (2000, 1); - ChunkUdp udp; - ChunkIpv4 ipv4; + BenchHeader<25> ipv4; + BenchHeader<8> udp; for (uint32_t i = 0; i < n; i++) { - Packet p; - p.add (&data); - p.add (&udp); - p.add (&ipv4); + Packet p (2000); + p.AddHeader (udp); + p.AddHeader (ipv4); } } static void ptrC2 (Packet p) { - ChunkConstantData data = ChunkConstantData (2000, 1); - ChunkUdp udp; + BenchHeader<8> udp; - p.peek (&udp); - p.remove (&udp); - p.peek (&data); - p.remove (&data); + p.RemoveHeader (udp); } static void ptrC1 (Packet p) { - ChunkIpv4 ipv4; - p.peek (&ipv4); - p.remove (&ipv4); + BenchHeader<25> ipv4; + p.RemoveHeader (ipv4); ptrC2 (p); } static void benchPtrC (uint32_t n) { - ChunkConstantData data = ChunkConstantData (2000, 1); - ChunkUdp udp; - ChunkIpv4 ipv4; + BenchHeader<25> ipv4; + BenchHeader<8> udp; for (uint32_t i = 0; i < n; i++) { - Packet p; - p.add (&data); - p.add (&udp); - p.add (&ipv4); + Packet p (2000); + p.AddHeader (udp); + p.AddHeader (ipv4); ptrC1 (p); } } @@ -105,10 +159,10 @@ benchPtrC (uint32_t n) static void runBench (void (*bench) (uint32_t), uint32_t n, char const *name) { - WallClockMs time; - time.start (); + SystemWallClockMs time; + time.Start (); (*bench) (n); - unsigned long long deltaMs = time.end (); + unsigned long long deltaMs = time.End (); double ps = n; ps *= 1000; ps /= deltaMs;