24 #include "ns3/command-line.h"
25 #include "ns3/packet-metadata.h"
26 #include "ns3/packet.h"
27 #include "ns3/system-wall-clock-ms.h"
58 TypeId GetInstanceTypeId()
const override;
59 void Print(std::ostream& os)
const override;
60 uint32_t GetSerializedSize()
const override;
69 static std::string GetTypeName();
90 std::ostringstream oss;
91 oss <<
"ns3::BenchHeader<" << N <<
">";
101 .SetGroupName(
"Utils")
102 .HideFromDocumentation()
140 for (
int i = 0; i < N; i++)
142 if (
start.ReadU8() != N)
161 std::ostringstream oss;
162 oss <<
"anon::BenchTag<" << N <<
">";
174 .SetGroupName(
"Utils")
175 .HideFromDocumentation()
192 for (uint32_t i = 0; i < N; ++i)
200 for (uint32_t i = 0; i < N; ++i)
206 void Print(std::ostream& os)
const override
225 for (uint32_t i = 0; i < n; i++)
248 NS_ASSERT_MSG(
ipv4.IsOk() ==
false,
"IsOk() should be false before deserialization");
249 for (uint32_t i = 0; i < n; i++)
258 NS_ASSERT_MSG(
ipv4.IsOk() ==
true,
"IsOk() should be true after deserialization");
267 for (uint32_t i = 0; i < n; i++)
297 for (uint32_t i = 0; i < n; i++)
312 for (uint32_t i = 0; i < n; i++)
338 for (uint32_t i = 0; i < n; i++)
341 for (uint32_t j = 0; j < 100; j++)
359 uint64_t deltaMs = time.
End();
364 runBench(
void (*bench)(uint32_t), uint32_t n, uint32_t minIterations,
const char* name)
367 for (uint32_t i = 0; i < minIterations; i++)
370 minDelay =
std::min(minDelay, delay);
375 std::cout << ps <<
" packets/s"
376 <<
" (" << minDelay <<
" ms elapsed)\t" << name << std::endl;
380 main(
int argc,
char* argv[])
383 uint32_t minIterations = 1;
384 bool enablePrinting =
false;
387 cmd.Usage(
"Benchmark Packet class");
388 cmd.AddValue(
"n",
"number of iterations", n);
389 cmd.AddValue(
"min-iterations",
390 "number of subiterations to minimize iteration time over",
392 cmd.AddValue(
"enable-printing",
"enable packet printing", enablePrinting);
393 cmd.Parse(argc, argv);
397 std::cerr <<
"Error-- number of packets must be specified "
398 <<
"by command-line argument --n=(number of packets)" << std::endl;
401 std::cout <<
"Running bench-packets with n=" << n << std::endl;
402 std::cout <<
"All tests begin by adding UDP and IPv4 headers." << std::endl;
404 runBench(&
benchA, n, minIterations,
"Copy packet, remove headers");
407 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.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
void AddHeader(const Header &header)
Add header to this packet.
Ptr< Packet > Copy() const
performs a COW copy of the packet.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
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...
void Print(ComponentCarrier cc)
Every class exported by the ns3 library is enclosed in the ns3 namespace.