src/common/packet-metadata-test.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 01 Oct 2007 14:15:56 +0200
changeset 1866 e7dbcc4df546
parent 1482 367eb4599901
child 2639 588221b7f892
permissions -rw-r--r--
do not use Packet objects directly. Use Ptr<Packet> instead
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2006,2007 INRIA
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#ifdef RUN_SELF_TESTS
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include <stdarg.h>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include <iostream>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <sstream>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#include "ns3/test.h"
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include "header.h"
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include "trailer.h"
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include "packet.h"
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
#include "packet-metadata.h"
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
#include "packet-printer.h"
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
namespace ns3 {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
class HistoryHeader : public Header
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
public:
1151
527d7b7e25af force users to register their header/trailer uid strings by hand rather than do lazy uid allocation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1148
diff changeset
    38
  static uint32_t GetUid (void);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
  HistoryHeader ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
  bool IsOk (void) const;
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    41
  std::string GetName (void) const;
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    42
  void Print (std::ostream &os) const;
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    43
  uint32_t GetSerializedSize (void) const;
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    44
  void Serialize (Buffer::Iterator start) const;
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    45
  uint32_t Deserialize (Buffer::Iterator start);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
private:
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
  bool m_ok;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
};
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
template <int N>
1151
527d7b7e25af force users to register their header/trailer uid strings by hand rather than do lazy uid allocation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1148
diff changeset
    51
uint32_t
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
HistoryHeader<N>::GetUid (void)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
  std::ostringstream oss;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
  oss << N << "HistoryHeader.ns3";
1234
ca195a6a7e1e Trailer::Register -> Trailer::AllocateUid and Header::Register -> Header::AllocateUid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1232
diff changeset
    56
  static uint32_t uid = AllocateUid<HistoryHeader<N> > (oss.str());
1151
527d7b7e25af force users to register their header/trailer uid strings by hand rather than do lazy uid allocation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1148
diff changeset
    57
  return uid;
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
HistoryHeader<N>::HistoryHeader ()
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
  : m_ok (false)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
{}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
bool 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
HistoryHeader<N>::IsOk (void) const
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
  return m_ok;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
std::string 
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    74
HistoryHeader<N>::GetName (void) const
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
  std::ostringstream oss;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  oss << N;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
  return oss.str ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
void 
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    83
HistoryHeader<N>::Print (std::ostream &os) const
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
  NS_ASSERT (false);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
uint32_t 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
HistoryHeader<N>::GetSerializedSize (void) const
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
  return N;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
void 
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    95
HistoryHeader<N>::Serialize (Buffer::Iterator start) const
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
  start.WriteU8 (N, N);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
uint32_t
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   101
HistoryHeader<N>::Deserialize (Buffer::Iterator start)
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
  m_ok = true;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
  for (int i = 0; i < N; i++)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
      if (start.ReadU8 () != N)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
        {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
          m_ok = false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
        }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
  return N;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
class HistoryTrailer : public Trailer
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
public:
1151
527d7b7e25af force users to register their header/trailer uid strings by hand rather than do lazy uid allocation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1148
diff changeset
   118
  static uint32_t GetUid (void);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
  HistoryTrailer ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
  bool IsOk (void) const;
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   121
  std::string GetName (void) const;
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   122
  void Print (std::ostream &os) const;
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   123
  uint32_t GetSerializedSize (void) const;
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   124
  void Serialize (Buffer::Iterator start) const;
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   125
  uint32_t Deserialize (Buffer::Iterator start);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
private:
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
  bool m_ok;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
};
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
template <int N>
1151
527d7b7e25af force users to register their header/trailer uid strings by hand rather than do lazy uid allocation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1148
diff changeset
   131
uint32_t
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
HistoryTrailer<N>::GetUid (void)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
  std::ostringstream oss;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
  oss << N << "HistoryTrailer.ns3";
1234
ca195a6a7e1e Trailer::Register -> Trailer::AllocateUid and Header::Register -> Header::AllocateUid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1232
diff changeset
   136
  static uint32_t uid = AllocateUid<HistoryTrailer<N> > (oss.str ());
1151
527d7b7e25af force users to register their header/trailer uid strings by hand rather than do lazy uid allocation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1148
diff changeset
   137
  return uid;
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
HistoryTrailer<N>::HistoryTrailer ()
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
  : m_ok (false)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
{}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
bool
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
HistoryTrailer<N>::IsOk (void) const
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
  return m_ok;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   152
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
std::string 
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   155
HistoryTrailer<N>::GetName (void) const
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
  std::ostringstream oss;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
  oss << N;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
  return oss.str ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
void 
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   163
HistoryTrailer<N>::Print (std::ostream &os) const
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
  NS_ASSERT (false);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
uint32_t 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
HistoryTrailer<N>::GetSerializedSize (void) const
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
  return N;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
void 
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   175
HistoryTrailer<N>::Serialize (Buffer::Iterator start) const
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
  start.Prev (N);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
  start.WriteU8 (N, N);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
uint32_t
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
   182
HistoryTrailer<N>::Deserialize (Buffer::Iterator start)
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
  m_ok = true;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
  start.Prev (N);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
  for (int i = 0; i < N; i++)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
      if (start.ReadU8 () != N)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
        {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
          m_ok = false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
        }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
  return N;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
class PacketMetadataTest : public Test {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
public:
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
  PacketMetadataTest ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
  virtual ~PacketMetadataTest ();
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   202
  bool CheckHistory (Ptr<Packet> p, const char *file, int line, uint32_t n, ...);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
  virtual bool RunTests (void);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
private:
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
  template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
  void PrintHeader (std::ostream &os, uint32_t packetUid, uint32_t size, const HistoryHeader<N> *header);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
  template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
  void PrintTrailer (std::ostream &os, uint32_t packetUid, uint32_t size, const HistoryTrailer<N> *trailer);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
  void PrintFragment (std::ostream &os,uint32_t packetUid,
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
                      uint32_t size,std::string & name, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
                      struct PacketPrinter::FragmentInformation info);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
  void PrintPayload (std::ostream &os,uint32_t packetUid,
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
                     uint32_t size,
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
                     struct PacketPrinter::FragmentInformation info);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
  template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
  void RegisterHeader (void);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
  template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
  void RegisterTrailer (void);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
  void CleanupPrints (void);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   220
  Ptr<Packet> DoAddHeader (Ptr<Packet> p);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
  bool Check (const char *file, int line, std::list<int> expected);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
  bool m_headerError;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
  bool m_trailerError;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
  std::list<int> m_prints;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
  PacketPrinter m_printer;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
};
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
PacketMetadataTest::PacketMetadataTest ()
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
  : Test ("PacketMetadata")
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   232
{
1141
a75fc1741700 rework the PacketPrinter API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1134
diff changeset
   233
  m_printer.SetPayloadPrinter (MakeCallback (&PacketMetadataTest::PrintPayload, this));
1260
b24477e66df7 avoid output of spurious whitespaces during testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1234
diff changeset
   234
  m_printer.SetSeparator ("");
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
PacketMetadataTest::~PacketMetadataTest ()
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
{}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   239
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   240
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   241
void 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
PacketMetadataTest::RegisterHeader (void)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   244
  static bool registered = false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   245
  if (!registered)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   246
    {
1141
a75fc1741700 rework the PacketPrinter API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1134
diff changeset
   247
      m_printer.SetHeaderPrinter (MakeCallback (&PacketMetadataTest::PrintHeader<N>, this),
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
                                  MakeCallback (&PacketMetadataTest::PrintFragment, this));
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
      registered = true;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
void 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
PacketMetadataTest::RegisterTrailer (void)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
  static bool registered = false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   258
  if (!registered)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
    {
1141
a75fc1741700 rework the PacketPrinter API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1134
diff changeset
   260
      m_printer.SetTrailerPrinter (MakeCallback (&PacketMetadataTest::PrintTrailer<N>, this),
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
                                   MakeCallback (&PacketMetadataTest::PrintFragment, this));
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
      registered = true;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
void 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
PacketMetadataTest::PrintHeader (std::ostream &os, uint32_t packetUid, uint32_t size, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
                                const HistoryHeader<N> *header)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
  if (!header->IsOk ())
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
      m_headerError = true;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
  m_prints.push_back (N);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   279
template <int N>
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   280
void 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   281
PacketMetadataTest::PrintTrailer (std::ostream &os, uint32_t packetUid, uint32_t size, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   282
                                 const HistoryTrailer<N> *trailer)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   283
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   284
  if (!trailer->IsOk ())
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
      m_trailerError = true;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
  m_prints.push_back (N);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   290
void 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   291
PacketMetadataTest::PrintFragment (std::ostream &os,uint32_t packetUid,
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   292
                                  uint32_t size,std::string & name, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   293
                                  struct PacketPrinter::FragmentInformation info)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   294
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
  m_prints.push_back (size - (info.end + info.start));
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   296
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   297
void 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   298
PacketMetadataTest::PrintPayload (std::ostream &os,uint32_t packetUid,
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   299
                                 uint32_t size,
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
                                 struct PacketPrinter::FragmentInformation info)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
  m_prints.push_back (size - (info.end + info.start));
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   304
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   306
void 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
PacketMetadataTest::CleanupPrints (void)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   308
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
  m_prints.clear ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
bool
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
PacketMetadataTest::Check (const char *file, int line, std::list<int> expected)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
  if (m_headerError)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   317
      Failure () << "PacketMetadata header error. file=" << file 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
                << ", line=" << line << std::endl;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
      return false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   320
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   321
  if (m_trailerError)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   322
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   323
      Failure () << "PacketMetadata trailer error. file=" << file 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   324
                << ", line=" << line << std::endl;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   325
      return false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   327
  if (expected.size () != m_prints.size ())
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   328
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
      goto error;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   330
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
  for (std::list<int>::iterator i = m_prints.begin (),
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   332
         j = expected.begin (); 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   333
       i != m_prints.end (); i++, j++)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   335
      NS_ASSERT (j != expected.end ());
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   336
      if (*j != *i)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
        {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   338
          goto error;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   339
        }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   340
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   341
  return true;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   342
 error:
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   343
  Failure () << "PacketMetadata error. file="<< file 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   344
            << ", line=" << line << ", got:\"";
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   345
  for (std::list<int>::iterator i = m_prints.begin (); 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   346
       i != m_prints.end (); i++)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   347
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   348
      Failure () << *i << ", ";
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   349
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   350
  Failure () << "\", expected: \"";
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   351
  for (std::list<int>::iterator j = expected.begin ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   352
       j != expected.end (); j++)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   353
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   354
      Failure () << *j << ", ";
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   355
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   356
  Failure () << "\"" << std::endl;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   357
  return false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   358
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   359
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   360
bool 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   361
PacketMetadataTest::CheckHistory (Ptr<Packet> p, const char *file, int line, uint32_t n, ...)
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   362
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   363
  m_headerError = false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   364
  m_trailerError = false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   365
  std::list<int> expected;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   366
  va_list ap;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   367
  va_start (ap, n);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   368
  for (uint32_t j = 0; j < n; j++)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   369
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   370
      int v = va_arg (ap, int);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   371
      expected.push_back (v);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   372
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   373
  va_end (ap);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   374
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   375
  m_printer.PrintForward ();
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   376
  p->Print (Failure (), m_printer);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   377
  bool ok = Check (file, line, expected);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   378
  CleanupPrints ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   379
  if (!ok)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   380
    {
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   381
      return false;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   382
    }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   383
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   384
  m_printer.PrintBackward ();
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   385
  p->Print (Failure (), m_printer);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   386
  expected.reverse ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   387
  ok = Check (file, line, expected);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   388
  CleanupPrints ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   389
  return ok;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   390
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   391
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   392
#define ADD_HEADER(p, n)                        \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   393
  {                                             \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   394
    HistoryHeader<n> header;                    \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   395
    RegisterHeader<n> ();                       \
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   396
    p->AddHeader (header);                      \
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   397
  }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   398
#define ADD_TRAILER(p, n)                       \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   399
  {                                             \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   400
    HistoryTrailer<n> trailer;                  \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   401
    RegisterTrailer<n> ();                      \
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   402
    p->AddTrailer (trailer);                    \
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   403
  }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   404
#define REM_HEADER(p, n)                        \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   405
  {                                             \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   406
    HistoryHeader<n> header;                    \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   407
    RegisterHeader<n> ();                       \
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   408
    p->RemoveHeader (header);                   \
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   409
  }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   410
#define REM_TRAILER(p, n)                       \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   411
  {                                             \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   412
    HistoryTrailer<n> trailer;                  \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   413
    RegisterTrailer<n> ();                      \
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   414
    p->RemoveTrailer (trailer);                 \
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   415
  }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   416
#define CHECK_HISTORY(p, ...)                   \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   417
  {                                             \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   418
    if (!CheckHistory (p, __FILE__,             \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   419
                      __LINE__, __VA_ARGS__))   \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   420
      {                                         \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   421
        ok = false;                             \
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   422
      }                                         \
1148
a5a767daca79 test packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1141
diff changeset
   423
    Buffer buffer;                              \
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   424
    buffer = p->Serialize ();                   \
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   425
    Ptr<Packet> otherPacket = Create<Packet> ();\
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   426
    otherPacket->Deserialize  (buffer);         \
1148
a5a767daca79 test packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1141
diff changeset
   427
    if (!CheckHistory (otherPacket, __FILE__,   \
a5a767daca79 test packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1141
diff changeset
   428
                      __LINE__, __VA_ARGS__))   \
a5a767daca79 test packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1141
diff changeset
   429
      {                                         \
a5a767daca79 test packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1141
diff changeset
   430
        ok = false;                             \
a5a767daca79 test packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1141
diff changeset
   431
      }                                         \
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   432
  }
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   433
1312
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   434
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   435
Ptr<Packet>
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   436
PacketMetadataTest::DoAddHeader (Ptr<Packet> p)
1312
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   437
{
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   438
  ADD_HEADER (p, 10);
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   439
  return p;
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   440
}
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   441
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   442
bool
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   443
PacketMetadataTest::RunTests (void)
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   444
{
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   445
  bool ok = true;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   446
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   447
  PacketMetadata::Enable ();
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   448
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   449
  Ptr<Packet> p = Create<Packet> (0);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   450
  Ptr<Packet> p1 = Create<Packet> (0);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   451
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   452
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   453
  ADD_TRAILER (p, 100);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   454
  CHECK_HISTORY (p, 2, 10, 100);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   455
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   456
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   457
  ADD_HEADER (p, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   458
  ADD_HEADER (p, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   459
  ADD_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   460
  CHECK_HISTORY (p, 4, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   461
                 3, 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   462
  ADD_HEADER (p, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   463
  CHECK_HISTORY (p, 5, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   464
                 5, 3, 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   465
  ADD_HEADER (p, 6);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   466
  CHECK_HISTORY (p, 6, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   467
                 6, 5, 3, 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   468
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   469
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   470
  ADD_HEADER (p, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   471
  ADD_HEADER (p, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   472
  ADD_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   473
  REM_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   474
  CHECK_HISTORY (p, 3, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   475
                 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   476
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   477
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   478
  ADD_HEADER (p, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   479
  ADD_HEADER (p, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   480
  ADD_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   481
  REM_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   482
  REM_HEADER (p, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   483
  CHECK_HISTORY (p, 2, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   484
                 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   485
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   486
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   487
  ADD_HEADER (p, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   488
  ADD_HEADER (p, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   489
  ADD_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   490
  REM_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   491
  REM_HEADER (p, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   492
  REM_HEADER (p, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   493
  CHECK_HISTORY (p, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   494
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   495
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   496
  ADD_HEADER (p, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   497
  ADD_HEADER (p, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   498
  ADD_HEADER (p, 3);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   499
  p1 = p->Copy ();
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   500
  REM_HEADER (p1, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   501
  REM_HEADER (p1, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   502
  REM_HEADER (p1, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   503
  CHECK_HISTORY (p1, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   504
  CHECK_HISTORY (p, 4, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   505
                 3, 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   506
  ADD_HEADER (p1, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   507
  ADD_HEADER (p1, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   508
  CHECK_HISTORY (p1, 3, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   509
                 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   510
  CHECK_HISTORY (p, 4, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   511
                 3, 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   512
  ADD_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   513
  CHECK_HISTORY (p, 5, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   514
                 3, 3, 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   515
  ADD_TRAILER (p, 4);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   516
  CHECK_HISTORY (p, 6, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   517
                 3, 3, 2, 1, 10, 4);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   518
  ADD_TRAILER (p, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   519
  CHECK_HISTORY (p, 7, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   520
                 3, 3, 2, 1, 10, 4, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   521
  REM_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   522
  CHECK_HISTORY (p, 6, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   523
                 3, 2, 1, 10, 4, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   524
  REM_TRAILER (p, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   525
  CHECK_HISTORY (p, 5, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   526
                 3, 2, 1, 10, 4);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   527
  p1 = p->Copy ();
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   528
  REM_TRAILER (p, 4);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   529
  CHECK_HISTORY (p, 4, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   530
                 3, 2, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   531
  CHECK_HISTORY (p1, 5, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   532
                 3, 2, 1, 10, 4);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   533
  p1->RemoveAtStart (3);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   534
  CHECK_HISTORY (p1, 4, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   535
                 2, 1, 10, 4);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   536
  p1->RemoveAtStart (1);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   537
  CHECK_HISTORY (p1, 4, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   538
                 1, 1, 10, 4);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   539
  p1->RemoveAtStart (1);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   540
  CHECK_HISTORY (p1, 3, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   541
                 1, 10, 4);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   542
  p1->RemoveAtEnd (4);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   543
  CHECK_HISTORY (p1, 2, 
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   544
                 1, 10);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   545
  p1->RemoveAtStart (1);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   546
  CHECK_HISTORY (p1, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   547
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   548
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   549
  ADD_HEADER (p, 8);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   550
  ADD_TRAILER (p, 8);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   551
  ADD_TRAILER (p, 8);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   552
  p->RemoveAtStart (8+10+8);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   553
  CHECK_HISTORY (p, 1, 8);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   554
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   555
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   556
  ADD_HEADER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   557
  ADD_HEADER (p, 8);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   558
  ADD_TRAILER (p, 6);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   559
  ADD_TRAILER (p, 7);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   560
  ADD_TRAILER (p, 9);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   561
  p->RemoveAtStart (5);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   562
  p->RemoveAtEnd (12);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   563
  CHECK_HISTORY (p, 5, 3, 10, 10, 6, 4);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   564
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   565
  p = Create<Packet> (10);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   566
  ADD_HEADER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   567
  ADD_TRAILER (p, 6);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   568
  p->RemoveAtEnd (18);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   569
  ADD_TRAILER (p, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   570
  ADD_HEADER (p, 3);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   571
  CHECK_HISTORY (p, 3, 3, 8, 5);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   572
  p->RemoveAtStart (12);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   573
  CHECK_HISTORY (p, 1, 4);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   574
  p->RemoveAtEnd (2);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   575
  CHECK_HISTORY (p, 1, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   576
  ADD_HEADER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   577
  CHECK_HISTORY (p, 2, 10, 2);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   578
  p->RemoveAtEnd (5);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   579
  CHECK_HISTORY (p, 1, 7);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   580
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   581
  Ptr<Packet> p2 = Create<Packet> (0);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   582
  Ptr<Packet> p3 = Create<Packet> (0);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   583
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   584
  p = Create<Packet> (40);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   585
  ADD_HEADER (p, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   586
  ADD_HEADER (p, 8);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   587
  CHECK_HISTORY (p, 3, 8, 5, 40);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   588
  p1 = p->CreateFragment (0, 5);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   589
  p2 = p->CreateFragment (5, 5);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   590
  p3 = p->CreateFragment (10, 43);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   591
  CHECK_HISTORY (p1, 1, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   592
  CHECK_HISTORY (p2, 2, 3, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   593
  CHECK_HISTORY (p3, 2, 3, 40);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   594
  p1->AddAtEnd (p2);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   595
  CHECK_HISTORY (p1, 2, 8, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   596
  CHECK_HISTORY (p2, 2, 3, 2);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   597
  p1->AddAtEnd (p3);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   598
  CHECK_HISTORY (p1, 3, 8, 5, 40);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   599
  CHECK_HISTORY (p2, 2, 3, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   600
  CHECK_HISTORY (p3, 2, 3, 40);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   601
  p1 = p->CreateFragment (0, 5);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   602
  CHECK_HISTORY (p1, 1, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   603
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   604
  p3 = Create<Packet> (50);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   605
  ADD_HEADER (p3, 8);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   606
  CHECK_HISTORY (p3, 2, 8, 50);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   607
  CHECK_HISTORY (p1, 1, 5);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   608
  p1->AddAtEnd (p3);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   609
  CHECK_HISTORY (p1, 3, 5, 8, 50);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   610
  ADD_HEADER (p1, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   611
  CHECK_HISTORY (p1, 4, 5, 5, 8, 50);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   612
  ADD_TRAILER (p1, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   613
  CHECK_HISTORY (p1, 5, 5, 5, 8, 50, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   614
  REM_HEADER (p1, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   615
  CHECK_HISTORY (p1, 4, 5, 8, 50, 2);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   616
  p1->RemoveAtEnd (60);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   617
  CHECK_HISTORY (p1, 1, 5);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   618
  p1->AddAtEnd (p2);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   619
  CHECK_HISTORY (p1, 2, 8, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   620
  CHECK_HISTORY (p2, 2, 3, 2);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   621
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   622
  p3 = Create<Packet> (40);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   623
  ADD_HEADER (p3, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   624
  ADD_HEADER (p3, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   625
  CHECK_HISTORY (p3, 3, 5, 5, 40);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   626
  p1 = p3->CreateFragment (0, 5);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   627
  p2 = p3->CreateFragment (5, 5);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   628
  CHECK_HISTORY (p1, 1, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   629
  CHECK_HISTORY (p2, 1, 5);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   630
  p1->AddAtEnd (p2);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   631
  CHECK_HISTORY (p1, 2, 5, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   632
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   633
  p = Create<Packet> (0);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   634
  CHECK_HISTORY (p, 0);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   635
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   636
  p3 = Create<Packet> (0);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   637
  ADD_HEADER (p3, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   638
  ADD_HEADER (p3, 5);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   639
  CHECK_HISTORY (p3, 2, 5, 5);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   640
  p1 = p3->CreateFragment (0, 4);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   641
  p2 = p3->CreateFragment (9, 1);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   642
  CHECK_HISTORY (p1, 1, 4);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   643
  CHECK_HISTORY (p2, 1, 1);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   644
  p1->AddAtEnd (p2);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   645
  CHECK_HISTORY (p1, 2, 4, 1);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   646
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   647
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   648
  p = Create<Packet> (2000);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   649
  CHECK_HISTORY (p, 1, 2000);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   650
  
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   651
  p = Create<Packet> ();
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   652
  ADD_TRAILER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   653
  ADD_HEADER (p, 5);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   654
  p1 = p->CreateFragment (0, 8);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   655
  p2 = p->CreateFragment (8, 7);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   656
  p1->AddAtEnd (p2);
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   657
  CHECK_HISTORY (p, 2, 5, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   658
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   659
  p = Create<Packet> ();
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   660
  ADD_TRAILER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   661
  REM_TRAILER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   662
  ADD_TRAILER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   663
  CHECK_HISTORY (p, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   664
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   665
  p = Create<Packet> ();
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   666
  ADD_HEADER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   667
  REM_HEADER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   668
  ADD_HEADER (p, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   669
  CHECK_HISTORY (p, 1, 10);
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   670
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   671
  p = Create<Packet> ();
1312
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   672
  ADD_HEADER (p, 10);
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   673
  p = DoAddHeader (p);
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   674
  CHECK_HISTORY (p, 2, 10, 10);
8bc3f26344b9 add failing test and fix for assignment to self
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1260
diff changeset
   675
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   676
  p = Create<Packet> (10);
1482
367eb4599901 we handle gustavo's testcase now. Fix for bug 72
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1312
diff changeset
   677
  ADD_HEADER (p, 8);
367eb4599901 we handle gustavo's testcase now. Fix for bug 72
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1312
diff changeset
   678
  ADD_TRAILER (p, 8);
367eb4599901 we handle gustavo's testcase now. Fix for bug 72
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1312
diff changeset
   679
  ADD_TRAILER (p, 8);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1482
diff changeset
   680
  p->RemoveAtStart (8+10+8);
1482
367eb4599901 we handle gustavo's testcase now. Fix for bug 72
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1312
diff changeset
   681
  CHECK_HISTORY (p, 1, 8);
367eb4599901 we handle gustavo's testcase now. Fix for bug 72
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1312
diff changeset
   682
1134
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   683
  return ok;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   684
}
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   685
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   686
static PacketMetadataTest g_packetHistoryTest;
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   687
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   688
}//namespace ns3
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   689
5f5d33e01eb9 split test code out of the main PacketMetadata code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   690
#endif /* RUN_SELF_TESTS */