20 #include "ns3/command-line.h"
21 #include "ns3/system-wall-clock-ms.h"
22 #include "ns3/packet.h"
23 #include "ns3/packet-metadata.h"
38 bool IsOk (
void)
const;
44 static TypeId GetTypeId (
void);
45 virtual TypeId GetInstanceTypeId (
void)
const;
46 virtual void Print (std::ostream &os)
const;
47 virtual uint32_t GetSerializedSize (
void)
const;
51 static std::string GetTypeName (
void);
71 std::ostringstream oss;
72 oss <<
"ns3::BenchHeader<" << N <<
">";
82 .SetGroupName (
"Utils")
83 .HideFromDocumentation ()
118 for (
int i = 0; i < N; i++)
133 std::ostringstream oss;
134 oss <<
"anon::BenchTag<" << N <<
">";
144 .SetGroupName (
"Utils")
145 .HideFromDocumentation ()
157 for (uint32_t i = 0; i < N; ++i)
163 for (uint32_t i = 0; i < N; ++i)
168 virtual void Print (std::ostream &os)
const {
184 for (uint32_t i = 0; i < n; i++) {
206 for (uint32_t i = 0; i < n; i++) {
222 for (uint32_t i = 0; i < n; i++) {
251 for (uint32_t i = 0; i < n; i++) {
265 for (uint32_t i= 0; i < n; i++) {
290 for (uint32_t i = 0; i < n; i++)
293 for (uint32_t j = 0; j < 100; j++)
311 uint64_t deltaMs = time.
End ();
317 runBench (
void (*bench) (uint32_t), uint32_t n, uint32_t minIterations,
char const *name)
320 for (uint32_t i = 0; i < minIterations; i++)
323 minDelay =
std::min(minDelay, delay);
328 std::cout << ps <<
" packets/s"
329 <<
" (" << minDelay <<
" ms elapsed)\t"
334 int main (
int argc,
char *argv[])
337 uint32_t minIterations = 1;
338 bool enablePrinting =
false;
341 cmd.
Usage (
"Benchmark Packet class");
342 cmd.
AddValue (
"n",
"number of iterations", n);
343 cmd.
AddValue (
"min-iterations",
"number of subiterations to minimize iteration time over", minIterations);
344 cmd.
AddValue (
"enable-printing",
"enable packet printing", enablePrinting);
345 cmd.
Parse (argc, argv);
349 std::cerr <<
"Error-- number of packets must be specified " <<
350 "by command-line argument --n=(number of packets)" << std::endl;
353 std::cout <<
"Running bench-packets with n=" << n << std::endl;
354 std::cout <<
"All tests begin by adding UDP and IPv4 headers." << std::endl;
356 runBench (&
benchA, n, minIterations,
"Copy packet, remove headers");
359 runBench (&
benchD, n, minIterations,
"Intermixed add/remove headers and tags");
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
static void C1(Ptr< Packet > p)
static void benchFragment(uint32_t n)
static void benchByteTags(uint32_t n)
void AddPacketTag(const Tag &tag) const
Add a packet tag.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static std::string GetName(void)
TAG_BUFFER_INLINE uint8_t ReadU8(void)
iterator in a Buffer instance
void Usage(const std::string usage)
Supply the program usage and documentation.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Measure elapsed wall clock time in milliseconds.
static void benchA(uint32_t n)
virtual uint32_t GetSerializedSize(void) const
void Start(void)
Start a measure.
static uint64_t runBenchOneIteration(void(*bench)(uint32_t), uint32_t n)
static void benchD(uint32_t n)
Parse command-line arguments.
static void benchB(uint32_t n)
static TypeId GetTypeId(void)
Register this type.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
tag a set of bytes in a packet
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual void Serialize(TagBuffer buf) const
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
static void runBench(void(*bench)(uint32_t), uint32_t n, uint32_t minIterations, char const *name)
void WriteU8(uint8_t data)
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
virtual void Print(std::ostream &os) const
void Parse(int argc, char *argv[])
Parse the program arguments.
static void C2(Ptr< Packet > p)
static void benchC(uint32_t n)
int64_t End(void)
Stop measuring the time since Start() was called.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void AddHeader(const Header &header)
Add header to this packet.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
virtual void Deserialize(TagBuffer buf)