25 #include "ns3/command-line.h"
26 #include "ns3/system-wall-clock-ms.h"
27 #include "ns3/packet.h"
28 #include "ns3/packet-metadata.h"
51 bool IsOk (
void)
const;
57 static TypeId GetTypeId (
void);
58 virtual TypeId GetInstanceTypeId (
void)
const;
59 virtual void Print (std::ostream &os)
const;
60 virtual uint32_t GetSerializedSize (
void)
const;
68 static std::string GetTypeName (
void);
88 std::ostringstream oss;
89 oss <<
"ns3::BenchHeader<" << N <<
">";
99 .SetGroupName (
"Utils")
100 .HideFromDocumentation ()
128 start.WriteU8 (N, N);
135 for (
int i = 0; i < N; i++)
137 if (
start.ReadU8 () != N)
155 std::ostringstream oss;
156 oss <<
"anon::BenchTag<" << N <<
">";
166 .SetGroupName (
"Utils")
167 .HideFromDocumentation ()
179 for (uint32_t i = 0; i < N; ++i)
185 for (uint32_t i = 0; i < N; ++i)
190 virtual void Print (std::ostream &os)
const {
206 for (uint32_t i = 0; i < n; i++) {
230 NS_ASSERT_MSG (ipv4.
IsOk () ==
false,
"IsOk() should be false before deserialization");
231 for (uint32_t i = 0; i < n; i++) {
239 NS_ASSERT_MSG (ipv4.
IsOk () ==
true,
"IsOk() should be true after deserialization");
248 for (uint32_t i = 0; i < n; i++) {
277 for (uint32_t i = 0; i < n; i++) {
291 for (uint32_t i= 0; i < n; i++) {
316 for (uint32_t i = 0; i < n; i++)
319 for (uint32_t j = 0; j < 100; j++)
337 uint64_t deltaMs = time.
End ();
343 runBench (
void (*bench) (uint32_t), uint32_t n, uint32_t minIterations,
char const *name)
346 for (uint32_t i = 0; i < minIterations; i++)
349 minDelay =
std::min(minDelay, delay);
354 std::cout << ps <<
" packets/s"
355 <<
" (" << minDelay <<
" ms elapsed)\t"
360 int main (
int argc,
char *argv[])
363 uint32_t minIterations = 1;
364 bool enablePrinting =
false;
367 cmd.Usage (
"Benchmark Packet class");
368 cmd.AddValue (
"n",
"number of iterations", n);
369 cmd.AddValue (
"min-iterations",
"number of subiterations to minimize iteration time over", minIterations);
370 cmd.AddValue (
"enable-printing",
"enable packet printing", enablePrinting);
371 cmd.Parse (argc, argv);
375 std::cerr <<
"Error-- number of packets must be specified " <<
376 "by command-line argument --n=(number of packets)" << std::endl;
379 std::cout <<
"Running bench-packets with n=" << n << std::endl;
380 std::cout <<
"All tests begin by adding UDP and IPv4 headers." << std::endl;
382 runBench (&
benchA, n, minIterations,
"Copy packet, remove headers");
385 runBench (&
benchD, n, minIterations,
"Intermixed add/remove headers and tags");
static void benchB(uint32_t n)
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 runBench(void(*bench)(uint32_t), uint32_t n, uint32_t minIterations, char const *name)
static void C1(Ptr< Packet > p)
static void C2(Ptr< Packet > p)
BenchTag class used for benchmarking packet serialization/deserialization.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual void Print(std::ostream &os) const
virtual uint32_t GetSerializedSize(void) const
static std::string GetName(void)
Get the bench tag name.
static TypeId GetTypeId(void)
Register this type.
virtual void Deserialize(TagBuffer buf)
virtual void Serialize(TagBuffer buf) const
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.
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.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Measure elapsed wall clock time in milliseconds.
void Start(void)
Start a measure.
int64_t End(void)
Stop measuring the time since Start() was called.
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
TAG_BUFFER_INLINE uint8_t ReadU8(void)
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.