utils/bench-packets.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 13 Mar 2008 12:56:49 -0700
changeset 2602 d9262bff6df2
parent 1869 9e5d8b4893b2
child 2643 2a3324f4dabe
permissions -rw-r--r--
add back support for introspected doxygen.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2006 INRIA
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 * All rights reserved.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * GNU General Public License for more details.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    21
#include "ns3/system-wall-clock-ms.h"
14
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    22
#include "ns3/packet.h"
882
777fcfabc1c8 rename packet-history.h to packet-metadata.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 881
diff changeset
    23
#include "ns3/packet-metadata.h"
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <iostream>
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    25
#include <sstream>
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    27
using namespace ns3;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    29
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    30
class BenchHeader : public Header
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    31
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    32
public:
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    33
  BenchHeader ();
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    34
  bool IsOk (void) const;
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    35
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    36
  static uint32_t GetUid (void);
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    37
1323
08174b13d76f avoid allocating strings all the time.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1322
diff changeset
    38
  static std::string GetName (void);
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    39
  void Print (std::ostream &os) const;
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    40
  uint32_t GetSerializedSize (void) const;
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    41
  void Serialize (Buffer::Iterator start) const;
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    42
  uint32_t Deserialize (Buffer::Iterator start);
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    43
private:
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    44
  bool m_ok;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    45
};
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    46
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    47
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    48
BenchHeader<N>::BenchHeader ()
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    49
  : m_ok (false)
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    50
{}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    51
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    52
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    53
bool 
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    54
BenchHeader<N>::IsOk (void) const
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    55
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    56
  return m_ok;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    57
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    58
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    59
template <int N>
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    60
uint32_t 
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    61
BenchHeader<N>::GetUid (void)
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    62
{
1323
08174b13d76f avoid allocating strings all the time.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1322
diff changeset
    63
  static uint32_t uid = AllocateUid<BenchHeader<N> > (GetName ());
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    64
  return uid;
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    65
}
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    66
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    67
template <int N>
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    68
std::string 
1323
08174b13d76f avoid allocating strings all the time.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1322
diff changeset
    69
BenchHeader<N>::GetName (void)
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    70
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    71
  std::ostringstream oss;
1323
08174b13d76f avoid allocating strings all the time.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1322
diff changeset
    72
  oss << "BenchHeader" << N;
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    73
  return oss.str ();
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    74
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    75
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    76
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    77
void 
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    78
BenchHeader<N>::Print (std::ostream &os) const
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    79
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    80
  NS_ASSERT (false);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    81
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    82
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    83
uint32_t 
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    84
BenchHeader<N>::GetSerializedSize (void) const
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    85
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    86
  return N;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    87
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    88
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    89
void 
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    90
BenchHeader<N>::Serialize (Buffer::Iterator start) const
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    91
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    92
  start.WriteU8 (N, N);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    93
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    94
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    95
uint32_t
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
    96
BenchHeader<N>::Deserialize (Buffer::Iterator start)
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    97
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    98
  m_ok = true;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    99
  for (int i = 0; i < N; i++)
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   100
    {
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   101
      if (start.ReadU8 () != N)
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   102
        {
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   103
          m_ok = false;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   104
        }
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   105
    }
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   106
  return N;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   107
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   108
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   109
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   110
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
static void 
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   112
benchPtrA (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   114
  BenchHeader<25> ipv4;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   115
  BenchHeader<8> udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   117
  for (uint32_t i = 0; i < n; i++) {
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   118
    Ptr<Packet> p = Create<Packet> (2000);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   119
    p->AddHeader (udp);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   120
    p->AddHeader (ipv4);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   121
    Ptr<Packet> o = p->Copy ();
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   122
    o->RemoveHeader (ipv4);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   123
    o->RemoveHeader (udp);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   124
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
static void 
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   128
benchPtrB (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   130
  BenchHeader<25> ipv4;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   131
  BenchHeader<8> udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   133
  for (uint32_t i = 0; i < n; i++) {
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   134
    Ptr<Packet> p = Create<Packet> (2000);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   135
    p->AddHeader (udp);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   136
    p->AddHeader (ipv4);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   137
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
static void
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   141
ptrC2 (Ptr<Packet> p)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   143
  BenchHeader<8> udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   145
  p->RemoveHeader (udp);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
static void 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   149
ptrC1 (Ptr<Packet> p)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   151
  BenchHeader<25> ipv4;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   152
  p->RemoveHeader (ipv4);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   153
  ptrC2 (p);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
static void
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   157
benchPtrC (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   159
  BenchHeader<25> ipv4;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   160
  BenchHeader<8> udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   162
  for (uint32_t i = 0; i < n; i++) {
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   163
    Ptr<Packet> p = Create<Packet> (2000);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   164
    p->AddHeader (udp);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   165
    p->AddHeader (ipv4);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   166
    ptrC1 (p);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   167
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
   170
#if 0
884
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   171
static void
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   172
benchPrint (uint32_t n)
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   173
{
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   174
  PacketPrinter printer;
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   175
  BenchHeader<25> ipv4;
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   176
  BenchHeader<8> udp;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   177
  Ptr<Packet> p = Create<Packet> (2000);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   178
  p->AddHeader (udp);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   179
  p->AddHeader (ipv4);
884
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   180
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   181
  for (uint32_t i = 0; i < n; i++) 
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   182
    {
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1323
diff changeset
   183
      p->Print (std::cerr, printer);
884
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   184
    }  
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   185
}
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
   186
#endif
884
f3836277079e fix uleb128 reading bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 883
diff changeset
   187
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
static void
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   190
runBench (void (*bench) (uint32_t), uint32_t n, char const *name)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   192
  SystemWallClockMs time;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   193
  time.Start ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   194
  (*bench) (n);
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   195
  unsigned long long deltaMs = time.End ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   196
  double ps = n;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   197
  ps *= 1000;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   198
  ps /= deltaMs;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   199
  std::cout << name<<"=" << ps << " packets/s" << std::endl;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   202
int main (int argc, char *argv[])
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   204
  uint32_t n = 0;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   205
  while (argc > 0) {
833
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   206
      if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) 
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   207
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   208
          char const *nAscii = argv[0] + strlen ("--n=");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   209
          n = atoi (nAscii);
833
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   210
        }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   211
      argc--;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   212
      argv++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   213
  }
1814
21c9c4dd9768 update bench-packets.cc program
Tom Henderson <tomh@tomh.org>
parents: 1323
diff changeset
   214
  if (n == 0)
21c9c4dd9768 update bench-packets.cc program
Tom Henderson <tomh@tomh.org>
parents: 1323
diff changeset
   215
    {
21c9c4dd9768 update bench-packets.cc program
Tom Henderson <tomh@tomh.org>
parents: 1323
diff changeset
   216
      std::cerr << "Error-- number of packets must be specified " <<
21c9c4dd9768 update bench-packets.cc program
Tom Henderson <tomh@tomh.org>
parents: 1323
diff changeset
   217
        "by command-line argument --n=(number of packets)" << std::endl;
21c9c4dd9768 update bench-packets.cc program
Tom Henderson <tomh@tomh.org>
parents: 1323
diff changeset
   218
      exit (1);
21c9c4dd9768 update bench-packets.cc program
Tom Henderson <tomh@tomh.org>
parents: 1323
diff changeset
   219
    }
21c9c4dd9768 update bench-packets.cc program
Tom Henderson <tomh@tomh.org>
parents: 1323
diff changeset
   220
  std::cout << "Running bench-packets with n=" << n << std::endl;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
1814
21c9c4dd9768 update bench-packets.cc program
Tom Henderson <tomh@tomh.org>
parents: 1323
diff changeset
   222
  Packet::EnableMetadata ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   223
  runBench (&benchPtrA, n, "a");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   224
  runBench (&benchPtrB, n, "b");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   225
  runBench (&benchPtrC, n, "c");
894
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   226
1322
b6a4885a92df re-enable packet benchmarking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 894
diff changeset
   227
  //runBench (&benchPrint, n, "print");
894
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   228
  PacketMetadata::SetOptOne (false);
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   229
  runBench (&benchPtrA, n, "meta-a");
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   230
  runBench (&benchPtrB, n, "meta-b");
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   231
  runBench (&benchPtrC, n, "meta-c");
883
4d2da35c09b0 PacketHistory -> PacketMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 882
diff changeset
   232
  PacketMetadata::SetOptOne (true);
894
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   233
  runBench (&benchPtrA, n, "meta-a-opt");
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   234
  runBench (&benchPtrB, n, "meta-b-opt");
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   235
  runBench (&benchPtrC, n, "meta-c-opt");
d6715af78f7e update packet benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 884
diff changeset
   236
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   238
  return 0;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   239
}