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;
385 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)
virtual void Print(std::ostream &os) const
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
static void benchFragment(uint32_t n)
static void benchByteTags(uint32_t n)
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
#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)
Get the bench tag name.
TAG_BUFFER_INLINE uint8_t ReadU8(void)
iterator in a Buffer instance
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)
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.
tag a set of bytes in a packet
virtual uint32_t GetSerializedSize(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void Serialize(TagBuffer buf) const
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
static void runBench(void(*bench)(uint32_t), uint32_t n, uint32_t minIterations, char const *name)
BenchTag class used for benchmarking packet serialization/deserialization.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
void Print(ComponentCarrier cc)
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 AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
void AddHeader(const Header &header)
Add header to this packet.
virtual void Deserialize(TagBuffer buf)