13#include "ns3/command-line.h"
14#include "ns3/packet-metadata.h"
15#include "ns3/packet.h"
16#include "ns3/system-wall-clock-ms.h"
48 void Print(std::ostream& os)
const override;
79 std::ostringstream oss;
80 oss <<
"ns3::BenchHeader<" << N <<
">";
90 .SetGroupName(
"Utils")
91 .HideFromDocumentation()
129 for (
int i = 0; i < N; i++)
131 if (start.ReadU8() != N)
150 std::ostringstream oss;
151 oss <<
"anon::BenchTag<" << N <<
">";
163 .SetGroupName(
"Utils")
164 .HideFromDocumentation()
195 void Print(std::ostream& os)
const override
217 p->AddPacketTag(tag1);
219 p->RemovePacketTag(tag1);
220 p->AddPacketTag(tag2);
223 o->RemoveHeader(ipv4);
224 p->RemovePacketTag(tag2);
225 o->RemoveHeader(udp);
237 NS_ASSERT_MSG(ipv4.IsOk() ==
false,
"IsOk() should be false before deserialization");
244 o->RemoveHeader(ipv4);
245 o->RemoveHeader(udp);
247 NS_ASSERT_MSG(ipv4.IsOk() ==
true,
"IsOk() should be true after deserialization");
269 p->RemoveHeader(udp);
276 p->RemoveHeader(ipv4);
314 frag2->AddAtEnd(frag3);
315 frag4->AddAtEnd(frag1);
316 frag2->AddAtEnd(frag4);
317 frag0->AddAtEnd(frag2);
319 frag0->RemoveHeader(ipv4);
320 frag0->RemoveHeader(udp);
348 uint64_t deltaMs = time.
End();
355 uint64_t minDelay = std::numeric_limits<uint64_t>::max();
356 for (
uint32_t i = 0; i < minIterations; i++)
359 minDelay = std::min(minDelay, delay);
364 std::cout << ps <<
" packets/s"
365 <<
" (" << minDelay <<
" ms elapsed)\t" << name << std::endl;
369main(
int argc,
char* argv[])
373 bool enablePrinting =
false;
376 cmd.Usage(
"Benchmark Packet class");
377 cmd.AddValue(
"n",
"number of iterations", n);
378 cmd.AddValue(
"min-iterations",
379 "number of subiterations to minimize iteration time over",
381 cmd.AddValue(
"enable-printing",
"enable packet printing", enablePrinting);
382 cmd.Parse(argc, argv);
386 std::cerr <<
"Error-- number of packets must be specified "
387 <<
"by command-line argument --n=(number of packets)" << std::endl;
390 std::cout <<
"Running bench-packets with n=" << n << std::endl;
391 std::cout <<
"All tests begin by adding UDP and IPv4 headers." << std::endl;
393 runBench(&
benchA, n, minIterations,
"Copy packet, remove headers");
396 runBench(&
benchD, n, minIterations,
"Intermixed add/remove headers and tags");
static void benchB(uint32_t n)
static void runBench(void(*bench)(uint32_t), uint32_t n, uint32_t minIterations, const char *name)
static uint64_t runBenchOneIteration(void(*bench)(uint32_t), uint32_t n)
static void benchC(uint32_t n)
static void benchD(uint32_t n)
static void benchFragment(uint32_t n)
static void benchByteTags(uint32_t n)
static void benchA(uint32_t n)
static void C1(Ptr< Packet > p)
static void C2(Ptr< Packet > p)
BenchTag class used for benchmarking packet serialization/deserialization.
void Serialize(TagBuffer buf) const override
void Deserialize(TagBuffer buf) override
static TypeId GetTypeId()
Register this type.
uint32_t GetSerializedSize() const override
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static std::string GetName()
Get the bench tag name.
iterator in a Buffer instance
Parse command-line arguments.
Smart pointer class similar to boost::intrusive_ptr.
Measure elapsed wall clock time in milliseconds.
int64_t End()
Stop measuring the time since Start() was called.
void Start()
Start a measure.
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
TAG_BUFFER_INLINE uint8_t ReadU8()
tag a set of bytes in a packet
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.