utils/bench-packets.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 07 Jun 2007 11:38:06 +0200
changeset 874 85c528e8eb0b
parent 833 224bfad58818
child 875 4ebee6ceebb5
permissions -rw-r--r--
remove dead code
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"
833
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
    23
#include "ns3/packet-history.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;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    35
private:
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    36
  virtual std::string DoGetName (void) const;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    37
  virtual void PrintTo (std::ostream &os) const;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    38
  virtual uint32_t GetSerializedSize (void) const;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    39
  virtual void SerializeTo (Buffer::Iterator start) const;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    40
  virtual uint32_t DeserializeFrom (Buffer::Iterator start);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    41
  bool m_ok;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    42
};
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    43
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    44
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    45
BenchHeader<N>::BenchHeader ()
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    46
  : m_ok (false)
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    47
{}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    48
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    49
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    50
bool 
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    51
BenchHeader<N>::IsOk (void) const
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    52
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    53
  return m_ok;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    54
}
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
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    57
std::string 
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    58
BenchHeader<N>::DoGetName (void) const
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    59
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    60
  std::ostringstream oss;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    61
  oss << N;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    62
  return oss.str ();
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    63
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    64
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    65
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    66
void 
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    67
BenchHeader<N>::PrintTo (std::ostream &os) const
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    68
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    69
  NS_ASSERT (false);
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
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    72
uint32_t 
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    73
BenchHeader<N>::GetSerializedSize (void) const
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
  return N;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    76
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    77
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    78
void 
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    79
BenchHeader<N>::SerializeTo (Buffer::Iterator start) const
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    80
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    81
  start.WriteU8 (N, N);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    82
}
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    83
template <int N>
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    84
uint32_t
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    85
BenchHeader<N>::DeserializeFrom (Buffer::Iterator start)
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    86
{
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    87
  m_ok = true;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    88
  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
    89
    {
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    90
      if (start.ReadU8 () != N)
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
          m_ok = false;
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
    }
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    95
  return N;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    96
}
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
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    99
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
static void 
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   101
benchPtrA (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   103
  BenchHeader<25> ipv4;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   104
  BenchHeader<8> udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   106
  for (uint32_t i = 0; i < n; i++) {
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   107
      Packet p (2000);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   108
      p.AddHeader (udp);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   109
      p.AddHeader (ipv4);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   110
      Packet o = p;
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   111
      o.RemoveHeader (ipv4);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   112
      o.RemoveHeader (udp);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   113
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
static void 
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   117
benchPtrB (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   119
  BenchHeader<25> ipv4;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   120
  BenchHeader<8> udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   122
  for (uint32_t i = 0; i < n; i++) {
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   123
      Packet p (2000);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   124
      p.AddHeader (udp);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   125
      p.AddHeader (ipv4);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   126
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
static void
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   130
ptrC2 (Packet p)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   132
  BenchHeader<8> udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   134
  p.RemoveHeader (udp);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
static void 
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   138
ptrC1 (Packet p)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   140
  BenchHeader<25> ipv4;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   141
  p.RemoveHeader (ipv4);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   142
  ptrC2 (p);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
static void
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   146
benchPtrC (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   148
  BenchHeader<25> ipv4;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   149
  BenchHeader<8> udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   151
  for (uint32_t i = 0; i < n; i++) {
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   152
      Packet p (2000);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   153
      p.AddHeader (udp);
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   154
      p.AddHeader (ipv4);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   155
      ptrC1 (p);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   156
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
static void
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   161
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
   162
{
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   163
  SystemWallClockMs time;
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   164
  time.Start ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   165
  (*bench) (n);
832
3d1243d770d9 fix the packet benchmark and enable it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   166
  unsigned long long deltaMs = time.End ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   167
  double ps = n;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   168
  ps *= 1000;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   169
  ps /= deltaMs;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   170
  std::cout << name<<"=" << ps << " packets/s" << std::endl;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
int main (int argc, char *argv[])
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   175
  uint32_t n = 0;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   176
  while (argc > 0) {
833
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   177
      if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) 
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   178
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   179
          char const *nAscii = argv[0] + strlen ("--n=");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   180
          n = atoi (nAscii);
833
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   181
        }
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   182
      if (strncmp ("--enable-history", argv[0], strlen ("--enable-history")) == 0)
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   183
        {
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   184
          PacketHistory::Enable ();          
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   185
        }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   186
      argc--;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   187
      argv++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   188
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
833
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   190
224bfad58818 a bunch of optimizations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 832
diff changeset
   191
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   192
  runBench (&benchPtrA, n, "a");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   193
  runBench (&benchPtrB, n, "b");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   194
  runBench (&benchPtrC, n, "c");
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   196
  return 0;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
}