2006-11-01 13:11:30 +01:00
|
|
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
2006-08-29 17:47:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006 INRIA
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
|
|
|
|
*/
|
2007-06-02 19:10:35 +02:00
|
|
|
#include "ns3/system-wall-clock-ms.h"
|
2006-08-29 17:51:04 +02:00
|
|
|
#include "ns3/packet.h"
|
2007-06-07 12:48:52 +02:00
|
|
|
#include "ns3/packet-metadata.h"
|
2006-08-29 17:47:17 +02:00
|
|
|
#include <iostream>
|
2007-06-02 19:10:35 +02:00
|
|
|
#include <sstream>
|
2008-05-07 15:01:45 -07:00
|
|
|
#include <string>
|
2006-08-29 17:47:17 +02:00
|
|
|
|
2006-08-29 17:55:34 +02:00
|
|
|
using namespace ns3;
|
2006-08-29 17:47:17 +02:00
|
|
|
|
2007-06-02 19:10:35 +02:00
|
|
|
template <int N>
|
|
|
|
|
class BenchHeader : public Header
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BenchHeader ();
|
|
|
|
|
bool IsOk (void) const;
|
2007-09-11 08:27:27 +02:00
|
|
|
|
2008-03-17 13:12:17 -07:00
|
|
|
static TypeId GetTypeId (void);
|
|
|
|
|
virtual TypeId GetInstanceTypeId (void) const;
|
2008-03-17 14:49:52 -07:00
|
|
|
virtual void Print (std::ostream &os) const;
|
2008-03-17 13:12:17 -07:00
|
|
|
virtual uint32_t GetSerializedSize (void) const;
|
|
|
|
|
virtual void Serialize (Buffer::Iterator start) const;
|
|
|
|
|
virtual uint32_t Deserialize (Buffer::Iterator start);
|
2007-06-02 19:10:35 +02:00
|
|
|
private:
|
2008-05-07 15:01:45 -07:00
|
|
|
static std::string GetTypeName (void);
|
2007-06-02 19:10:35 +02:00
|
|
|
bool m_ok;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <int N>
|
|
|
|
|
BenchHeader<N>::BenchHeader ()
|
|
|
|
|
: m_ok (false)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
template <int N>
|
|
|
|
|
bool
|
|
|
|
|
BenchHeader<N>::IsOk (void) const
|
|
|
|
|
{
|
|
|
|
|
return m_ok;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-07 15:01:45 -07:00
|
|
|
template <int N>
|
|
|
|
|
std::string
|
|
|
|
|
BenchHeader<N>::GetTypeName (void)
|
|
|
|
|
{
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
oss << "ns3::BenchHeader<" << N << ">";
|
|
|
|
|
return oss.str ();
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-17 13:12:17 -07:00
|
|
|
template <int N>
|
|
|
|
|
TypeId
|
|
|
|
|
BenchHeader<N>::GetTypeId (void)
|
|
|
|
|
{
|
2008-05-07 15:01:45 -07:00
|
|
|
static TypeId tid = TypeId (GetTypeName ().c_str ())
|
2008-03-17 13:12:17 -07:00
|
|
|
.SetParent<Header> ()
|
|
|
|
|
;
|
|
|
|
|
return tid;
|
|
|
|
|
}
|
|
|
|
|
template <int N>
|
|
|
|
|
TypeId
|
|
|
|
|
BenchHeader<N>::GetInstanceTypeId (void) const
|
|
|
|
|
{
|
|
|
|
|
return GetTypeId ();
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-02 19:10:35 +02:00
|
|
|
template <int N>
|
|
|
|
|
void
|
2007-09-11 08:27:27 +02:00
|
|
|
BenchHeader<N>::Print (std::ostream &os) const
|
2007-06-02 19:10:35 +02:00
|
|
|
{
|
|
|
|
|
NS_ASSERT (false);
|
|
|
|
|
}
|
|
|
|
|
template <int N>
|
|
|
|
|
uint32_t
|
|
|
|
|
BenchHeader<N>::GetSerializedSize (void) const
|
|
|
|
|
{
|
|
|
|
|
return N;
|
|
|
|
|
}
|
|
|
|
|
template <int N>
|
|
|
|
|
void
|
2007-09-11 08:27:27 +02:00
|
|
|
BenchHeader<N>::Serialize (Buffer::Iterator start) const
|
2007-06-02 19:10:35 +02:00
|
|
|
{
|
|
|
|
|
start.WriteU8 (N, N);
|
|
|
|
|
}
|
|
|
|
|
template <int N>
|
|
|
|
|
uint32_t
|
2007-09-11 08:27:27 +02:00
|
|
|
BenchHeader<N>::Deserialize (Buffer::Iterator start)
|
2007-06-02 19:10:35 +02:00
|
|
|
{
|
|
|
|
|
m_ok = true;
|
|
|
|
|
for (int i = 0; i < N; i++)
|
|
|
|
|
{
|
|
|
|
|
if (start.ReadU8 () != N)
|
|
|
|
|
{
|
|
|
|
|
m_ok = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return N;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-08 11:23:22 -07:00
|
|
|
template <int N>
|
|
|
|
|
class BenchTag : public Tag
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static std::string GetName (void) {
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
oss << "anon::BenchTag<" << N << ">";
|
|
|
|
|
return oss.str ();
|
|
|
|
|
}
|
|
|
|
|
static TypeId GetTypeId (void) {
|
|
|
|
|
static TypeId tid = TypeId (GetName ().c_str ())
|
|
|
|
|
.SetParent<Tag> ()
|
|
|
|
|
.AddConstructor<BenchTag > ()
|
|
|
|
|
.HideFromDocumentation ()
|
|
|
|
|
;
|
|
|
|
|
return tid;
|
|
|
|
|
}
|
|
|
|
|
virtual TypeId GetInstanceTypeId (void) const {
|
|
|
|
|
return GetTypeId ();
|
|
|
|
|
}
|
|
|
|
|
virtual uint32_t GetSerializedSize (void) const {
|
|
|
|
|
return N;
|
|
|
|
|
}
|
|
|
|
|
virtual void Serialize (TagBuffer buf) const {
|
|
|
|
|
for (uint32_t i = 0; i < N; ++i)
|
|
|
|
|
{
|
|
|
|
|
buf.WriteU8 (N);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
virtual void Deserialize (TagBuffer buf) {
|
|
|
|
|
for (uint32_t i = 0; i < N; ++i)
|
|
|
|
|
{
|
|
|
|
|
buf.ReadU8 ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BenchTag ()
|
|
|
|
|
: Tag () {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
benchD (uint32_t n)
|
|
|
|
|
{
|
|
|
|
|
BenchHeader<25> ipv4;
|
|
|
|
|
BenchHeader<8> udp;
|
|
|
|
|
BenchTag<16> tag1;
|
|
|
|
|
BenchTag<17> tag2;
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < n; i++) {
|
|
|
|
|
Ptr<Packet> p = Create<Packet> (2000);
|
|
|
|
|
p->AddTag (tag1);
|
|
|
|
|
p->AddHeader (udp);
|
|
|
|
|
p->FindFirstMatchingTag (tag1);
|
|
|
|
|
p->AddTag (tag2);
|
|
|
|
|
p->AddHeader (ipv4);
|
|
|
|
|
Ptr<Packet> o = p->Copy ();
|
|
|
|
|
o->RemoveHeader (ipv4);
|
|
|
|
|
p->FindFirstMatchingTag (tag2);
|
|
|
|
|
o->RemoveHeader (udp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-02 19:10:35 +02:00
|
|
|
|
|
|
|
|
|
2006-08-29 17:47:17 +02:00
|
|
|
static void
|
2008-05-08 11:23:22 -07:00
|
|
|
benchA (uint32_t n)
|
2006-08-29 17:47:17 +02:00
|
|
|
{
|
2007-06-02 19:10:35 +02:00
|
|
|
BenchHeader<25> ipv4;
|
|
|
|
|
BenchHeader<8> udp;
|
2006-08-29 17:47:17 +02:00
|
|
|
|
2006-11-01 13:11:30 +01:00
|
|
|
for (uint32_t i = 0; i < n; i++) {
|
2007-10-01 14:15:56 +02:00
|
|
|
Ptr<Packet> p = Create<Packet> (2000);
|
|
|
|
|
p->AddHeader (udp);
|
|
|
|
|
p->AddHeader (ipv4);
|
|
|
|
|
Ptr<Packet> o = p->Copy ();
|
|
|
|
|
o->RemoveHeader (ipv4);
|
|
|
|
|
o->RemoveHeader (udp);
|
2006-11-01 13:11:30 +01:00
|
|
|
}
|
2006-08-29 17:47:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-05-08 11:23:22 -07:00
|
|
|
benchB (uint32_t n)
|
2006-08-29 17:47:17 +02:00
|
|
|
{
|
2007-06-02 19:10:35 +02:00
|
|
|
BenchHeader<25> ipv4;
|
|
|
|
|
BenchHeader<8> udp;
|
2006-08-29 17:47:17 +02:00
|
|
|
|
2006-11-01 13:11:30 +01:00
|
|
|
for (uint32_t i = 0; i < n; i++) {
|
2007-10-01 14:15:56 +02:00
|
|
|
Ptr<Packet> p = Create<Packet> (2000);
|
|
|
|
|
p->AddHeader (udp);
|
|
|
|
|
p->AddHeader (ipv4);
|
2006-11-01 13:11:30 +01:00
|
|
|
}
|
2006-08-29 17:47:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-05-08 11:23:22 -07:00
|
|
|
C2 (Ptr<Packet> p)
|
2006-08-29 17:47:17 +02:00
|
|
|
{
|
2007-06-02 19:10:35 +02:00
|
|
|
BenchHeader<8> udp;
|
2006-08-29 17:47:17 +02:00
|
|
|
|
2007-10-01 14:15:56 +02:00
|
|
|
p->RemoveHeader (udp);
|
2006-08-29 17:47:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-05-08 11:23:22 -07:00
|
|
|
C1 (Ptr<Packet> p)
|
2006-08-29 17:47:17 +02:00
|
|
|
{
|
2007-06-02 19:10:35 +02:00
|
|
|
BenchHeader<25> ipv4;
|
2007-10-01 14:15:56 +02:00
|
|
|
p->RemoveHeader (ipv4);
|
2008-05-08 11:23:22 -07:00
|
|
|
C2 (p);
|
2006-08-29 17:47:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-05-08 11:23:22 -07:00
|
|
|
benchC (uint32_t n)
|
2006-08-29 17:47:17 +02:00
|
|
|
{
|
2007-06-02 19:10:35 +02:00
|
|
|
BenchHeader<25> ipv4;
|
|
|
|
|
BenchHeader<8> udp;
|
2006-08-29 17:47:17 +02:00
|
|
|
|
2006-11-01 13:11:30 +01:00
|
|
|
for (uint32_t i = 0; i < n; i++) {
|
2007-10-01 14:15:56 +02:00
|
|
|
Ptr<Packet> p = Create<Packet> (2000);
|
|
|
|
|
p->AddHeader (udp);
|
|
|
|
|
p->AddHeader (ipv4);
|
2008-05-08 11:23:22 -07:00
|
|
|
C1 (p);
|
2006-11-01 13:11:30 +01:00
|
|
|
}
|
2006-08-29 17:47:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-09-05 13:13:39 +02:00
|
|
|
runBench (void (*bench) (uint32_t), uint32_t n, char const *name)
|
2006-08-29 17:47:17 +02:00
|
|
|
{
|
2007-06-02 19:10:35 +02:00
|
|
|
SystemWallClockMs time;
|
|
|
|
|
time.Start ();
|
2006-11-01 13:11:30 +01:00
|
|
|
(*bench) (n);
|
2007-06-02 19:10:35 +02:00
|
|
|
unsigned long long deltaMs = time.End ();
|
2006-11-01 13:11:30 +01:00
|
|
|
double ps = n;
|
|
|
|
|
ps *= 1000;
|
|
|
|
|
ps /= deltaMs;
|
|
|
|
|
std::cout << name<<"=" << ps << " packets/s" << std::endl;
|
2006-08-29 17:47:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
|
{
|
2006-11-01 13:11:30 +01:00
|
|
|
uint32_t n = 0;
|
|
|
|
|
while (argc > 0) {
|
2007-06-03 20:09:56 +02:00
|
|
|
if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0)
|
|
|
|
|
{
|
2006-11-01 13:11:30 +01:00
|
|
|
char const *nAscii = argv[0] + strlen ("--n=");
|
|
|
|
|
n = atoi (nAscii);
|
2007-06-03 20:09:56 +02:00
|
|
|
}
|
2006-11-01 13:11:30 +01:00
|
|
|
argc--;
|
|
|
|
|
argv++;
|
|
|
|
|
}
|
2007-11-06 15:45:05 -08:00
|
|
|
if (n == 0)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "Error-- number of packets must be specified " <<
|
|
|
|
|
"by command-line argument --n=(number of packets)" << std::endl;
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
std::cout << "Running bench-packets with n=" << n << std::endl;
|
2006-08-29 17:47:17 +02:00
|
|
|
|
2008-05-08 11:23:22 -07:00
|
|
|
runBench (&benchA, n, "a");
|
|
|
|
|
runBench (&benchB, n, "b");
|
|
|
|
|
runBench (&benchC, n, "c");
|
|
|
|
|
runBench (&benchD, n, "d");
|
2007-06-13 00:10:40 +02:00
|
|
|
|
2008-05-07 15:23:46 -07:00
|
|
|
Packet::EnableMetadata ();
|
2008-05-08 11:23:22 -07:00
|
|
|
runBench (&benchA, n, "meta-a");
|
|
|
|
|
runBench (&benchB, n, "meta-b");
|
|
|
|
|
runBench (&benchC, n, "meta-c");
|
|
|
|
|
runBench (&benchD, n, "meta-d");
|
2007-06-13 00:10:40 +02:00
|
|
|
|
2006-08-29 17:47:17 +02:00
|
|
|
|
2008-05-07 15:23:46 -07:00
|
|
|
|
2006-11-01 13:11:30 +01:00
|
|
|
return 0;
|
2006-08-29 17:47:17 +02:00
|
|
|
}
|