fix the packet benchmark and enable it
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -18,85 +18,139 @@
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#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 <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
template <int N>
|
||||
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 <int N>
|
||||
BenchHeader<N>::BenchHeader ()
|
||||
: m_ok (false)
|
||||
{}
|
||||
|
||||
template <int N>
|
||||
bool
|
||||
BenchHeader<N>::IsOk (void) const
|
||||
{
|
||||
return m_ok;
|
||||
}
|
||||
|
||||
template <int N>
|
||||
std::string
|
||||
BenchHeader<N>::DoGetName (void) const
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << N;
|
||||
return oss.str ();
|
||||
}
|
||||
|
||||
template <int N>
|
||||
void
|
||||
BenchHeader<N>::PrintTo (std::ostream &os) const
|
||||
{
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
template <int N>
|
||||
uint32_t
|
||||
BenchHeader<N>::GetSerializedSize (void) const
|
||||
{
|
||||
return N;
|
||||
}
|
||||
template <int N>
|
||||
void
|
||||
BenchHeader<N>::SerializeTo (Buffer::Iterator start) const
|
||||
{
|
||||
start.WriteU8 (N, N);
|
||||
}
|
||||
template <int N>
|
||||
uint32_t
|
||||
BenchHeader<N>::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;
|
||||
|
||||
Reference in New Issue
Block a user