src/common/packet.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 25 Aug 2008 15:21:01 -0700
changeset 3553 065488d0420c
parent 3364 8e6ac6061680
child 3738 011897c60e9c
permissions -rw-r--r--
bug 279: Packets need metadata support for printing without header checking
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2005,2006 INRIA
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "packet.h"
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
    21
#include "ns3/assert.h"
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
    22
#include "ns3/log.h"
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
    23
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
    24
NS_LOG_COMPONENT_DEFINE ("Packet");
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 9
diff changeset
    26
namespace ns3 {
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
    28
uint32_t Packet::m_globalUid = 0;
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
    29
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    30
TypeId 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    31
TagIterator::Item::GetTypeId (void) const
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    32
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    33
  return m_tid;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    34
}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    35
uint32_t 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    36
TagIterator::Item::GetStart (void) const
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    37
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    38
  return m_start;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    39
}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    40
uint32_t 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    41
TagIterator::Item::GetEnd (void) const
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    42
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    43
  return m_end;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    44
}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    45
void 
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
    46
TagIterator::Item::GetTag (Tag &tag) const
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    47
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    48
  if (tag.GetInstanceTypeId () != GetTypeId ())
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    49
    {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    50
      NS_FATAL_ERROR ("The tag you provided is not of the right type.");
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    51
    }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    52
  tag.Deserialize (m_buffer);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    53
}
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
    54
TagIterator::Item::Item (TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    55
  : m_tid (tid),
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    56
    m_start (start),
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    57
    m_end (end),
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    58
    m_buffer (buffer)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    59
{}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    60
bool 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    61
TagIterator::HasNext (void) const
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    62
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    63
  return m_current.HasNext ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    64
}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    65
TagIterator::Item 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    66
TagIterator::Next (void)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    67
{
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
    68
  TagList::Iterator::Item i = m_current.Next ();
3057
e26ab7b61c7c help return-value-optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3048
diff changeset
    69
  return TagIterator::Item (i.tid, 
e26ab7b61c7c help return-value-optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3048
diff changeset
    70
                            i.start-m_current.GetOffsetStart (), 
e26ab7b61c7c help return-value-optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3048
diff changeset
    71
                            i.end-m_current.GetOffsetStart (), 
e26ab7b61c7c help return-value-optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3048
diff changeset
    72
                            i.buf);
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    73
}
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
    74
TagIterator::TagIterator (TagList::Iterator i)
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    75
  : m_current (i)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    76
{}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    77
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
    78
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    79
void 
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    80
Packet::Ref (void) const
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    81
{
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    82
  m_refCount++;
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    83
}
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    84
void 
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    85
Packet::Unref (void) const
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    86
{
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    87
  m_refCount--;
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    88
  if (m_refCount == 0)
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    89
    {
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    90
      delete this;
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    91
    }
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    92
}
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    93
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    94
Ptr<Packet> 
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    95
Packet::Copy (void) const
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    96
{
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    97
  // we need to invoke the copy constructor directly
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    98
  // rather than calling Create because the copy constructor
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
    99
  // is private.
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   100
  return Ptr<Packet> (new Packet (*this), false);
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   101
}
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   102
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
Packet::Packet ()
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   104
  : m_buffer (),
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   105
    m_tagList (),
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   106
    m_metadata (m_globalUid, 0),
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   107
    m_refCount (1)
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   108
{
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   109
  m_globalUid++;
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   110
}
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   112
Packet::Packet (const Packet &o)
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   113
  : m_buffer (o.m_buffer),
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   114
    m_tagList (o.m_tagList),
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   115
    m_metadata (o.m_metadata),
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   116
    m_refCount (1)
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   117
{}
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   118
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   119
Packet &
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   120
Packet::operator = (const Packet &o)
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   121
{
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   122
  if (this == &o)
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   123
    {
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   124
      return *this;
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   125
    }
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   126
  m_buffer = o.m_buffer;
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   127
  m_tagList = o.m_tagList;
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   128
  m_metadata = o.m_metadata;
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   129
  return *this;
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   130
}
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   131
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
Packet::Packet (uint32_t size)
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   133
  : m_buffer (size),
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   134
    m_tagList (),
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   135
    m_metadata (m_globalUid, size),
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   136
    m_refCount (1)
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   137
{
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   138
  m_globalUid++;
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   139
}
239
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   140
Packet::Packet (uint8_t const*buffer, uint32_t size)
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   141
  : m_buffer (),
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   142
    m_tagList (),
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   143
    m_metadata (m_globalUid, size),
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   144
    m_refCount (1)
239
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   145
{
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   146
  m_globalUid++;
239
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   147
  m_buffer.AddAtStart (size);
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   148
  Buffer::Iterator i = m_buffer.Begin ();
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   149
  i.Write (buffer, size);
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   150
}
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   151
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   152
Packet::Packet (const Buffer &buffer,  const TagList &tagList, const PacketMetadata &metadata)
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   153
  : m_buffer (buffer),
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   154
    m_tagList (tagList),
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   155
    m_metadata (metadata),
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   156
    m_refCount (1)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
{}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   159
Ptr<Packet>
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   160
Packet::CreateFragment (uint32_t start, uint32_t length) const
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   162
  NS_LOG_FUNCTION (this << start << length);
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   163
  Buffer buffer = m_buffer.CreateFragment (start, length);
819
3bae75040589 calculate the correct size of header and trailer to remove from buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 806
diff changeset
   164
  NS_ASSERT (m_buffer.GetSize () >= start + length);
3bae75040589 calculate the correct size of header and trailer to remove from buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 806
diff changeset
   165
  uint32_t end = m_buffer.GetSize () - (start + length);
888
f882ee7eaccf history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 887
diff changeset
   166
  PacketMetadata metadata = m_metadata.CreateFragment (start, end);
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   167
  // again, call the constructor directly rather than
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   168
  // through Create because it is private.
3039
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   169
  return Ptr<Packet> (new Packet (buffer, m_tagList, metadata), false);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
uint32_t 
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   173
Packet::GetSize (void) const
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   175
  return m_buffer.GetSize ();
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   178
void
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   179
Packet::AddHeader (const Header &header)
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   180
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   181
  NS_LOG_FUNCTION (this << &header);
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   182
  uint32_t size = header.GetSerializedSize ();
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   183
  uint32_t orgStart = m_buffer.GetCurrentStartOffset ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   184
  bool resized = m_buffer.AddAtStart (size);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   185
  if (resized)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   186
    {
3237
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   187
      m_tagList.AddAtStart (m_buffer.GetCurrentStartOffset () + size - orgStart,
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   188
                            m_buffer.GetCurrentStartOffset () + size);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   189
    }
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   190
  header.Serialize (m_buffer.Begin ());
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   191
  m_metadata.AddHeader (header, size);
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   192
}
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   193
uint32_t
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   194
Packet::RemoveHeader (Header &header)
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   195
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   196
  NS_LOG_FUNCTION (this << &header);
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   197
  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   198
  m_buffer.RemoveAtStart (deserialized);
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   199
  m_metadata.RemoveHeader (header, deserialized);
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   200
  return deserialized;
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   201
}
3364
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   202
uint32_t
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   203
Packet::PeekHeader (Header &header)
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   204
{
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   205
  NS_LOG_FUNCTION (this << &header);
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   206
  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   207
  return deserialized;
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   208
}
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   209
void
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   210
Packet::AddTrailer (const Trailer &trailer)
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   211
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   212
  NS_LOG_FUNCTION (this << &trailer);
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   213
  uint32_t size = trailer.GetSerializedSize ();
3237
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   214
  uint32_t orgStart = m_buffer.GetCurrentStartOffset ();
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   215
  bool resized = m_buffer.AddAtEnd (size);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   216
  if (resized)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   217
    {
3237
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   218
      m_tagList.AddAtEnd (m_buffer.GetCurrentStartOffset () - orgStart,
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   219
                          m_buffer.GetCurrentEndOffset () - size);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   220
    }
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   221
  Buffer::Iterator end = m_buffer.End ();
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   222
  trailer.Serialize (end);
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   223
  m_metadata.AddTrailer (trailer, size);
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   224
}
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   225
uint32_t
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   226
Packet::RemoveTrailer (Trailer &trailer)
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   227
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   228
  NS_LOG_FUNCTION (this << &trailer);
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   229
  uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   230
  m_buffer.RemoveAtEnd (deserialized);
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   231
  m_metadata.RemoveTrailer (trailer, deserialized);
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   232
  return deserialized;
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   233
}
3364
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   234
uint32_t
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   235
Packet::PeekTrailer (Trailer &trailer)
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   236
{
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   237
  NS_LOG_FUNCTION (this << &trailer);
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   238
  uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   239
  return deserialized;
8e6ac6061680 implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3301
diff changeset
   240
}
2663
dc5314da50aa remove template methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2660
diff changeset
   241
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
void 
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   243
Packet::AddAtEnd (Ptr<const Packet> packet)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   244
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   245
  NS_LOG_FUNCTION (this << packet);
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   246
  uint32_t aStart = m_buffer.GetCurrentStartOffset ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   247
  uint32_t bEnd = packet->m_buffer.GetCurrentEndOffset ();
2992
ba52f937610c move Packet::AddAtEnd implementation to the Buffer code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   248
  m_buffer.AddAtEnd (packet->m_buffer);
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   249
  uint32_t appendPrependOffset = m_buffer.GetCurrentEndOffset () - packet->m_buffer.GetSize ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   250
  m_tagList.AddAtEnd (m_buffer.GetCurrentStartOffset () - aStart, 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   251
                      appendPrependOffset);
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   252
  TagList copy = packet->m_tagList;
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   253
  copy.AddAtStart (m_buffer.GetCurrentEndOffset () - bEnd,
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   254
                   appendPrependOffset);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   255
  m_tagList.Add (copy);
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   256
  m_metadata.AddAtEnd (packet->m_metadata);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
}
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   258
void
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   259
Packet::AddPaddingAtEnd (uint32_t size)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   261
  NS_LOG_FUNCTION (this << size);
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   262
  uint32_t orgEnd = m_buffer.GetCurrentEndOffset ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   263
  bool resized = m_buffer.AddAtEnd (size);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   264
  if (resized)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   265
    {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   266
      m_tagList.AddAtEnd (m_buffer.GetCurrentEndOffset () - orgEnd,
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   267
                          m_buffer.GetCurrentEndOffset () - size);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   268
    }
888
f882ee7eaccf history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 887
diff changeset
   269
  m_metadata.AddPaddingAtEnd (size);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
void 
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   272
Packet::RemoveAtEnd (uint32_t size)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   274
  NS_LOG_FUNCTION (this << size);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   275
  m_buffer.RemoveAtEnd (size);
888
f882ee7eaccf history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 887
diff changeset
   276
  m_metadata.RemoveAtEnd (size);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
void 
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   279
Packet::RemoveAtStart (uint32_t size)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   280
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   281
  NS_LOG_FUNCTION (this << size);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   282
  m_buffer.RemoveAtStart (size);
888
f882ee7eaccf history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 887
diff changeset
   283
  m_metadata.RemoveAtStart (size);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   284
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
void 
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   287
Packet::RemoveAllTags (void)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   289
  NS_LOG_FUNCTION (this);
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   290
  m_tagList.RemoveAll ();
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   291
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   292
90
d670ba9f726e replace pointers with references
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   293
uint8_t const *
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   294
Packet::PeekData (void) const
90
d670ba9f726e replace pointers with references
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   295
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   296
  return m_buffer.PeekData ();
90
d670ba9f726e replace pointers with references
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   297
}
d670ba9f726e replace pointers with references
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   298
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   299
uint32_t 
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   300
Packet::GetUid (void) const
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   301
{
888
f882ee7eaccf history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 887
diff changeset
   302
  return m_metadata.GetUid ();
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   303
}
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   304
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   305
void 
1241
66f126692f5e add Packet::PrintTags and move tag documentation to tag.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1150
diff changeset
   306
Packet::PrintTags (std::ostream &os) const
66f126692f5e add Packet::PrintTags and move tag documentation to tag.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1150
diff changeset
   307
{
3208
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   308
  TagIterator i = GetTagIterator ();
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   309
  while (i.HasNext ())
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   310
    {
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   311
      TagIterator::Item item = i.Next ();
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   312
      os << item.GetTypeId ().GetName () << " [" << item.GetStart () << "-" << item.GetEnd () << "]";
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   313
      Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   314
      if (constructor.IsNull ())
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   315
        {
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   316
          if (i.HasNext ())
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   317
            {
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   318
              os << " ";
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   319
            }
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   320
          continue;
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   321
        }
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   322
      Tag *tag = dynamic_cast<Tag *> (constructor ());
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   323
      NS_ASSERT (tag != 0);
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   324
      os << " ";
3230
e59680767a04 bug 212: Packet::PrintTags fails
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3208
diff changeset
   325
      item.GetTag (*tag);
3208
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   326
      tag->Print (os);
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   327
      if (i.HasNext ())
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   328
        {
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   329
          os << " ";
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   330
        }
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   331
      delete tag;
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   332
    }
1241
66f126692f5e add Packet::PrintTags and move tag documentation to tag.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1150
diff changeset
   333
}
66f126692f5e add Packet::PrintTags and move tag documentation to tag.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1150
diff changeset
   334
66f126692f5e add Packet::PrintTags and move tag documentation to tag.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1150
diff changeset
   335
void 
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   336
Packet::Print (std::ostream &os) const
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 463
diff changeset
   337
{
2660
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   338
  PacketMetadata::ItemIterator i = m_metadata.BeginItem (m_buffer);
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   339
  while (i.HasNext ())
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   340
    {
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   341
      PacketMetadata::Item item = i.Next ();
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   342
      if (item.isFragment)
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   343
        {
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   344
          switch (item.type) {
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   345
          case PacketMetadata::Item::PAYLOAD:
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   346
            os << "Payload";
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   347
            break;
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   348
          case PacketMetadata::Item::HEADER:
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   349
          case PacketMetadata::Item::TRAILER:
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   350
            os << item.tid.GetName ();
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   351
            break;
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   352
          }
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   353
          os << " Fragment [" << item.currentTrimedFromStart<<":"
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   354
             << (item.currentTrimedFromStart + item.currentSize) << "]";
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   355
        }
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   356
      else
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   357
        {
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   358
          switch (item.type) {
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   359
          case PacketMetadata::Item::PAYLOAD:
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   360
            os << "Payload (size=" << item.currentSize << ")";
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   361
            break;
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   362
          case PacketMetadata::Item::HEADER:
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   363
          case PacketMetadata::Item::TRAILER:
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   364
            os << item.tid.GetName () << " (";
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   365
            {
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   366
              NS_ASSERT (item.tid.HasConstructor ());
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   367
              Callback<ObjectBase *> constructor = item.tid.GetConstructor ();
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   368
              NS_ASSERT (!constructor.IsNull ());
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   369
              ObjectBase *instance = constructor ();
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   370
              NS_ASSERT (instance != 0);
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   371
              Chunk *chunk = dynamic_cast<Chunk *> (instance);
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   372
              NS_ASSERT (chunk != 0);
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   373
              chunk->Deserialize (item.current);
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   374
              chunk->Print (os);
2790
29e10e971644 delete a packet chunk after deserializing it from a packet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   375
              delete chunk;
2660
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   376
            }
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   377
            os << ")";
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   378
            break;
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   379
          }          
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   380
        }
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   381
      if (i.HasNext ())
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   382
        {
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   383
          os << " ";
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   384
        }
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   385
    }
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   386
#if 0
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   387
  // The code below will work only if headers and trailers
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   388
  // define the right attributes which is not the case for
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   389
  // now. So, as a temporary measure, we use the 
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   390
  // headers' and trailers' Print method as shown above.
2647
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   391
  PacketMetadata::ItemIterator i = m_metadata.BeginItem (m_buffer);
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   392
  while (i.HasNext ())
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   393
    {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   394
      PacketMetadata::Item item = i.Next ();
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   395
      if (item.isFragment)
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   396
        {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   397
          switch (item.type) {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   398
          case PacketMetadata::Item::PAYLOAD:
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   399
            os << "Payload";
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   400
            break;
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   401
          case PacketMetadata::Item::HEADER:
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   402
          case PacketMetadata::Item::TRAILER:
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   403
            os << item.tid.GetName ();
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   404
            break;
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   405
          }
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   406
          os << " Fragment [" << item.currentTrimedFromStart<<":"
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   407
             << (item.currentTrimedFromStart + item.currentSize) << "]";
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   408
        }
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   409
      else
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   410
        {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   411
          switch (item.type) {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   412
          case PacketMetadata::Item::PAYLOAD:
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   413
            os << "Payload (size=" << item.currentSize << ")";
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   414
            break;
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   415
          case PacketMetadata::Item::HEADER:
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   416
          case PacketMetadata::Item::TRAILER:
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   417
            os << item.tid.GetName () << "(";
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   418
            {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   419
              NS_ASSERT (item.tid.HasConstructor ());
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   420
              Callback<ObjectBase *> constructor = item.tid.GetConstructor ();
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   421
              NS_ASSERT (constructor.IsNull ());
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   422
              ObjectBase *instance = constructor ();
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   423
              NS_ASSERT (instance != 0);
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   424
              Chunk *chunk = dynamic_cast<Chunk *> (instance);
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   425
              NS_ASSERT (chunk != 0);
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   426
              chunk->Deserialize (item.current);
2693
56e28e34e109 TypeId::GetAttributeListN -> TypeId::GetAttributeN
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2663
diff changeset
   427
              for (uint32_t j = 0; j < item.tid.GetAttributeN (); j++)
2647
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   428
                {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   429
                  std::string attrName = item.tid.GetAttributeName (j);
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   430
                  std::string value;
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   431
                  bool ok = chunk->GetAttribute (attrName, value);
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   432
                  NS_ASSERT (ok);
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   433
                  os << attrName << "=" << value;
2693
56e28e34e109 TypeId::GetAttributeListN -> TypeId::GetAttributeN
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2663
diff changeset
   434
                  if ((j + 1) < item.tid.GetAttributeN ())
2647
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   435
                    {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   436
                      os << ",";
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   437
                    }
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   438
                }
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   439
            }
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   440
            os << ")";
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   441
            break;
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   442
          }          
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   443
        }
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   444
      if (i.HasNext ())
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   445
        {
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   446
          os << " ";
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   447
        }
3e9474e1d77b implement Packet::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2640
diff changeset
   448
    }
2660
1d54065d728a convert Packet::Print to use Chunk::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2647
diff changeset
   449
#endif   
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 463
diff changeset
   450
}
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   451
2639
588221b7f892 replace PacketPrinter with an iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1865
diff changeset
   452
PacketMetadata::ItemIterator 
588221b7f892 replace PacketPrinter with an iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1865
diff changeset
   453
Packet::BeginItem (void) const
806
0190f1b49dc8 re-implement PacketHistory to use the PacketPrinter and work on ItemList::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 790
diff changeset
   454
{
2639
588221b7f892 replace PacketPrinter with an iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1865
diff changeset
   455
  return m_metadata.BeginItem (m_buffer);
806
0190f1b49dc8 re-implement PacketHistory to use the PacketPrinter and work on ItemList::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 790
diff changeset
   456
}
0190f1b49dc8 re-implement PacketHistory to use the PacketPrinter and work on ItemList::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 790
diff changeset
   457
875
4ebee6ceebb5 rename History::Enable to Packet::EnableMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 824
diff changeset
   458
void
4ebee6ceebb5 rename History::Enable to Packet::EnableMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 824
diff changeset
   459
Packet::EnableMetadata (void)
4ebee6ceebb5 rename History::Enable to Packet::EnableMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 824
diff changeset
   460
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   461
  NS_LOG_FUNCTION_NOARGS ();
3553
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   462
  EnableChecking ();
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   463
}
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   464
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   465
void
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   466
Packet::EnablePrinting (void)
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   467
{
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   468
  NS_LOG_FUNCTION_NOARGS ();
883
4d2da35c09b0 PacketHistory -> PacketMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 875
diff changeset
   469
  PacketMetadata::Enable ();
875
4ebee6ceebb5 rename History::Enable to Packet::EnableMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 824
diff changeset
   470
}
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   471
3553
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   472
void
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   473
Packet::EnableChecking (void)
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   474
{
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   475
  NS_LOG_FUNCTION_NOARGS ();
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   476
  PacketMetadata::EnableChecking ();
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   477
}
065488d0420c bug 279: Packets need metadata support for printing without header checking
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3364
diff changeset
   478
1138
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   479
Buffer 
1142
ff8f4a2efc6b add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1141
diff changeset
   480
Packet::Serialize (void) const
1138
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   481
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   482
  NS_LOG_FUNCTION (this);
1144
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   483
  Buffer buffer;
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   484
  uint32_t reserve;
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   485
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   486
  // write metadata
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   487
  reserve = m_metadata.GetSerializedSize ();
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   488
  buffer.AddAtStart (reserve);
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   489
  m_metadata.Serialize (buffer.Begin (), reserve);
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   490
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   491
  // write tags
3039
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   492
  //XXX
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   493
  //reserve = m_tags.GetSerializedSize ();
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   494
  //buffer.AddAtStart (reserve);
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   495
  //m_tags.Serialize (buffer.Begin (), reserve);
1144
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   496
  
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   497
  // aggregate byte buffer, metadata, and tags
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   498
  Buffer tmp = m_buffer.CreateFullCopy ();
3039
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   499
  tmp.AddAtEnd (buffer);
1144
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   500
  
1150
fcdda7ef3cee fix packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1144
diff changeset
   501
  // write byte buffer size.
3039
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   502
  tmp.AddAtStart (4);
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   503
  tmp.Begin ().WriteU32 (m_buffer.GetSize ());
1144
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   504
3039
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   505
  return tmp;
1138
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   506
}
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   507
void 
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   508
Packet::Deserialize (Buffer buffer)
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   509
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   510
  NS_LOG_FUNCTION (this);
1138
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   511
  Buffer buf = buffer;
1144
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   512
  // read size
1138
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   513
  uint32_t packetSize = buf.Begin ().ReadU32 ();
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   514
  buf.RemoveAtStart (4);
1144
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   515
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   516
  // read buffer.
1150
fcdda7ef3cee fix packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1144
diff changeset
   517
  buf.RemoveAtEnd (buf.GetSize () - packetSize);
1138
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   518
  m_buffer = buf;
3039
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   519
  buffer.RemoveAtStart (4 + packetSize);
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   520
1144
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   521
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   522
  // read tags
3039
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   523
  //XXX
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   524
  //uint32_t tagsDeserialized = m_tags.Deserialize (buffer.Begin ());
722cf749a9e3 remove now-unused Tags class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3035
diff changeset
   525
  //buffer.RemoveAtStart (tagsDeserialized);
1144
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   526
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   527
  // read metadata
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   528
  uint32_t metadataDeserialized = 
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   529
    m_metadata.Deserialize (buffer.Begin ());
6442e000420b finish packet serialization/deserialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1142
diff changeset
   530
  buffer.RemoveAtStart (metadataDeserialized);
1138
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   531
}
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   532
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   533
void 
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   534
Packet::AddTag (const Tag &tag) const
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   535
{
3158
2a4305eeca93 add logging
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3057
diff changeset
   536
  NS_LOG_FUNCTION (this << &tag);
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   537
  TagList *list = const_cast<TagList *> (&m_tagList);
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   538
  TagBuffer buffer = list->Add (tag.GetInstanceTypeId (), tag.GetSerializedSize (), 
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   539
                                 m_buffer.GetCurrentStartOffset (),
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   540
                                 m_buffer.GetCurrentEndOffset ());
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   541
  tag.Serialize (buffer);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   542
}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   543
TagIterator 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   544
Packet::GetTagIterator (void) const
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   545
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   546
  return TagIterator (m_tagList.Begin (m_buffer.GetCurrentStartOffset (), m_buffer.GetCurrentEndOffset ()));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   547
}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   548
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   549
bool 
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   550
Packet::FindFirstMatchingTag (Tag &tag) const
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   551
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   552
  TypeId tid = tag.GetInstanceTypeId ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   553
  TagIterator i = GetTagIterator ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   554
  while (i.HasNext ())
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   555
    {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   556
      TagIterator::Item item = i.Next ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   557
      if (tid == item.GetTypeId ())
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   558
        {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   559
          item.GetTag (tag);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   560
          return true;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   561
        }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   562
    }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   563
  return false;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   564
}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   565
1360
7686e996bd1d add operator << for Packet and TraceContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1241
diff changeset
   566
std::ostream& operator<< (std::ostream& os, const Packet &packet)
7686e996bd1d add operator << for Packet and TraceContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1241
diff changeset
   567
{
7686e996bd1d add operator << for Packet and TraceContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1241
diff changeset
   568
  packet.Print (os);
7686e996bd1d add operator << for Packet and TraceContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1241
diff changeset
   569
  return os;
7686e996bd1d add operator << for Packet and TraceContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1241
diff changeset
   570
}
7686e996bd1d add operator << for Packet and TraceContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1241
diff changeset
   571
1138
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   572
27245d50e5e0 use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 896
diff changeset
   573
} // namespace ns3
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   574
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   575
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   576
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   577
#ifdef RUN_SELF_TESTS
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   578
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   579
#include "ns3/test.h"
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   580
#include <string>
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   581
#include <stdarg.h>
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   582
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   583
using namespace ns3;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   584
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   585
namespace {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   586
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   587
class ATestTagBase : public Tag
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   588
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   589
public:
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   590
  ATestTagBase () : m_error (false) {}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   591
  bool m_error;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   592
};
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   593
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   594
template <int N>
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   595
class ATestTag : public ATestTagBase
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   596
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   597
public:
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   598
  static TypeId GetTypeId (void) {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   599
    std::ostringstream oss;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   600
    oss << "anon::ATestTag<" << N << ">";
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   601
    static TypeId tid = TypeId (oss.str ().c_str ())
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   602
      .SetParent<Tag> ()
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   603
      .AddConstructor<ATestTag<N> > ()
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   604
      .HideFromDocumentation ()
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   605
      ;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   606
    return tid;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   607
  }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   608
  virtual TypeId GetInstanceTypeId (void) const {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   609
    return GetTypeId ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   610
  }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   611
  virtual uint32_t GetSerializedSize (void) const {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   612
    return N;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   613
  }
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   614
  virtual void Serialize (TagBuffer buf) const {
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   615
    for (uint32_t i = 0; i < N; ++i)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   616
      {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   617
        buf.WriteU8 (N);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   618
      }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   619
  }
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   620
  virtual void Deserialize (TagBuffer buf) {
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   621
    for (uint32_t i = 0; i < N; ++i)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   622
      {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   623
        uint8_t v = buf.ReadU8 ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   624
        if (v != N)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   625
          {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   626
            m_error = true;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   627
          }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   628
      }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   629
  }
3208
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   630
  virtual void Print (std::ostream &os) const {
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   631
    os << N;
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3158
diff changeset
   632
  }
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   633
  ATestTag ()
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   634
    : ATestTagBase () {}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   635
};
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   636
3048
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   637
class ATestHeaderBase : public Header
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   638
{
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   639
public:
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   640
  ATestHeaderBase () : Header (), m_error (false) {}
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   641
  bool m_error;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   642
};
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   643
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   644
template <int N>
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   645
class ATestHeader : public ATestHeaderBase
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   646
{
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   647
public:
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   648
  static TypeId GetTypeId (void) {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   649
    std::ostringstream oss;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   650
    oss << "anon::ATestHeader<" << N << ">";
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   651
    static TypeId tid = TypeId (oss.str ().c_str ())
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   652
      .SetParent<Header> ()
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   653
      .AddConstructor<ATestHeader<N> > ()
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   654
      .HideFromDocumentation ()
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   655
      ;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   656
    return tid;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   657
  }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   658
  virtual TypeId GetInstanceTypeId (void) const {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   659
    return GetTypeId ();
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   660
  }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   661
  virtual uint32_t GetSerializedSize (void) const {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   662
    return N;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   663
  }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   664
  virtual void Serialize (Buffer::Iterator iter) const {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   665
    for (uint32_t i = 0; i < N; ++i)
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   666
      {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   667
        iter.WriteU8 (N);
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   668
      }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   669
  }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   670
  virtual uint32_t Deserialize (Buffer::Iterator iter) {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   671
    for (uint32_t i = 0; i < N; ++i)
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   672
      {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   673
        uint8_t v = iter.ReadU8 ();
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   674
        if (v != N)
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   675
          {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   676
            m_error = true;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   677
          }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   678
      }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   679
    return N;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   680
  }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   681
  virtual void Print (std::ostream &os) const {
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   682
  }
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   683
  ATestHeader ()
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   684
    : ATestHeaderBase () {}
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   685
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   686
};
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   687
3237
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   688
class ATestTrailerBase : public Trailer
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   689
{
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   690
public:
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   691
  ATestTrailerBase () : Trailer (), m_error (false) {}
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   692
  bool m_error;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   693
};
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   694
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   695
template <int N>
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   696
class ATestTrailer : public ATestTrailerBase
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   697
{
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   698
public:
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   699
  static TypeId GetTypeId (void) {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   700
    std::ostringstream oss;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   701
    oss << "anon::ATestTrailer<" << N << ">";
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   702
    static TypeId tid = TypeId (oss.str ().c_str ())
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   703
      .SetParent<Header> ()
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   704
      .AddConstructor<ATestTrailer<N> > ()
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   705
      .HideFromDocumentation ()
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   706
      ;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   707
    return tid;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   708
  }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   709
  virtual TypeId GetInstanceTypeId (void) const {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   710
    return GetTypeId ();
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   711
  }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   712
  virtual uint32_t GetSerializedSize (void) const {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   713
    return N;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   714
  }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   715
  virtual void Serialize (Buffer::Iterator iter) const {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   716
    iter.Prev (N);
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   717
    for (uint32_t i = 0; i < N; ++i)
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   718
      {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   719
        iter.WriteU8 (N);
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   720
      }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   721
  }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   722
  virtual uint32_t Deserialize (Buffer::Iterator iter) {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   723
    iter.Prev (N);
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   724
    for (uint32_t i = 0; i < N; ++i)
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   725
      {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   726
        uint8_t v = iter.ReadU8 ();
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   727
        if (v != N)
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   728
          {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   729
            m_error = true;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   730
          }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   731
      }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   732
    return N;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   733
  }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   734
  virtual void Print (std::ostream &os) const {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   735
  }
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   736
  ATestTrailer ()
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   737
    : ATestTrailerBase () {}
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   738
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   739
};
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   740
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   741
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   742
struct Expected
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   743
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   744
  Expected (uint32_t n_, uint32_t start_, uint32_t end_)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   745
    : n (n_), start (start_), end (end_) {}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   746
  
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   747
  uint32_t n;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   748
  uint32_t start;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   749
  uint32_t end;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   750
};
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   751
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   752
}
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   753
3237
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   754
// tag name, start, end
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   755
#define E(a,b,c) a,b,c
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   756
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   757
#define CHECK(p, n, ...)                                \
3300
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   758
  NS_TEST_ASSERT (DoCheck (p, __FILE__, __LINE__, n, __VA_ARGS__))
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   759
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   760
namespace ns3 {
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   761
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   762
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   763
class PacketTest: public Test 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   764
{
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   765
public:
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   766
  PacketTest ();
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   767
  virtual bool RunTests (void);
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   768
private:
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   769
  bool DoCheck (Ptr<const Packet> p, const char *file, int line, uint32_t n, ...);
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   770
};
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   771
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   773
PacketTest::PacketTest ()
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   774
  : Test ("Packet") {}
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   775
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   776
bool
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   777
PacketTest::DoCheck (Ptr<const Packet> p, const char *file, int line, uint32_t n, ...)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   778
{
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   779
  bool result = true;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   780
  std::vector<struct Expected> expected;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   781
  va_list ap;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   782
  va_start (ap, n);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   783
  for (uint32_t k = 0; k < n; ++k)
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   784
    {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   785
      uint32_t N = va_arg (ap, uint32_t);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   786
      uint32_t start = va_arg (ap, uint32_t);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   787
      uint32_t end = va_arg (ap, uint32_t);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   788
      expected.push_back (Expected (N, start, end));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   789
    }
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   790
  va_end (ap);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   791
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   792
  TagIterator i = p->GetTagIterator ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   793
  uint32_t j = 0;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   794
  while (i.HasNext () && j < expected.size ())
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   795
    {
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   796
      TagIterator::Item item = i.Next ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   797
      struct Expected e = expected[j];
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   798
      std::ostringstream oss;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   799
      oss << "anon::ATestTag<" << e.n << ">";
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   800
      NS_TEST_ASSERT_EQUAL_FILELINE (item.GetTypeId ().GetName (), oss.str (), file, line);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   801
      NS_TEST_ASSERT_EQUAL_FILELINE (item.GetStart (), e.start, file, line);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   802
      NS_TEST_ASSERT_EQUAL_FILELINE (item.GetEnd (), e.end, file, line);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   803
      ATestTagBase *tag = dynamic_cast<ATestTagBase *> (item.GetTypeId ().GetConstructor () ());
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   804
      NS_TEST_ASSERT (tag != 0);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   805
      item.GetTag (*tag);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   806
      NS_TEST_ASSERT (!tag->m_error);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   807
      delete tag;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   808
      j++;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   809
    }
3300
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   810
  NS_TEST_ASSERT (!i.HasNext ());
3298
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   811
  NS_TEST_ASSERT_EQUAL (j, expected.size ());
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   812
  return result;
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   813
}
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   814
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   815
bool
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   816
PacketTest::RunTests (void)
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   817
{
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   818
  bool result = true;
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   819
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   820
  Ptr<Packet> pkt1 = Create<Packet> (reinterpret_cast<const uint8_t*> ("hello"), 5);
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   821
  Ptr<Packet> pkt2 = Create<Packet> (reinterpret_cast<const uint8_t*> (" world"), 6);
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   822
  Ptr<Packet> packet = Create<Packet> ();
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   823
  packet->AddAtEnd (pkt1);
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   824
  packet->AddAtEnd (pkt2);
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   825
  
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   826
  NS_TEST_ASSERT_EQUAL (packet->GetSize (), 11);
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   827
1865
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   828
  std::string msg = std::string (reinterpret_cast<const char *>(packet->PeekData ()),
829dc1815014 add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1493
diff changeset
   829
                                 packet->GetSize ());
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   830
  NS_TEST_ASSERT_EQUAL (msg, "hello world");
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   831
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   832
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   833
  Ptr<const Packet> p = Create<Packet> (1000);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   834
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   835
  p->AddTag (ATestTag<1> ());
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   836
  CHECK (p, 1, E (1, 0, 1000));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   837
  Ptr<const Packet> copy = p->Copy ();
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   838
  CHECK (copy, 1, E (1, 0, 1000));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   839
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   840
  p->AddTag (ATestTag<2> ());
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   841
  CHECK (p, 2, E (1, 0, 1000), E(2, 0, 1000));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   842
  CHECK (copy, 1, E (1, 0, 1000));
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   843
3046
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   844
  {
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   845
    Packet c0 = *copy;
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   846
    Packet c1 = *copy;
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   847
    c0 = c1;
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   848
    CHECK (&c0, 1, E (1, 0, 1000));
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   849
    CHECK (&c1, 1, E (1, 0, 1000));
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   850
    CHECK (copy, 1, E (1, 0, 1000));
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   851
    c0.AddTag (ATestTag<10> ());
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   852
    CHECK (&c0, 2, E (1, 0, 1000), E (10, 0, 1000));
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   853
    CHECK (&c1, 1, E (1, 0, 1000));
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   854
    CHECK (copy, 1, E (1, 0, 1000));
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   855
  }
a03270ebc161 test self-assignment of packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3040
diff changeset
   856
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   857
  Ptr<Packet> frag0 = p->CreateFragment (0, 10);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   858
  Ptr<Packet> frag1 = p->CreateFragment (10, 90);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   859
  Ptr<const Packet> frag2 = p->CreateFragment (100, 900);
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   860
  frag0->AddTag (ATestTag<3> ());
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   861
  CHECK (frag0, 3, E (1, 0, 10), E(2, 0, 10), E (3, 0, 10));
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   862
  frag1->AddTag (ATestTag<4> ());
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   863
  CHECK (frag1, 3, E (1, 0, 90), E(2, 0, 90), E (4, 0, 90));
3040
e11e106c7c19 Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3039
diff changeset
   864
  frag2->AddTag (ATestTag<5> ());
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   865
  CHECK (frag2, 3, E (1, 0, 900), E(2, 0, 900), E (5, 0, 900));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   866
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   867
  frag1->AddAtEnd (frag2);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   868
  CHECK (frag1, 6, E (1, 0, 90), E(2, 0, 90), E (4, 0, 90), E (1, 90, 990), E(2, 90, 990), E (5, 90, 990));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   869
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   870
  CHECK (frag0, 3, E (1, 0, 10), E(2, 0, 10), E (3, 0, 10));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   871
  frag0->AddAtEnd (frag1);
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   872
  CHECK (frag0, 9, 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   873
         E (1, 0, 10), E(2, 0, 10), E (3, 0, 10),
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   874
         E (1, 10, 100), E(2, 10, 100), E (4, 10, 100), 
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   875
         E (1, 100, 1000), E(2, 100, 1000), E (5, 100, 1000));
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   876
3048
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   877
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   878
  // force caching a buffer of the right size.
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   879
  frag0 = Create<Packet> (1000);
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   880
  frag0->AddHeader (ATestHeader<10> ());
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   881
  frag0 = 0;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   882
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   883
  p = Create<Packet> (1000);
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   884
  p->AddTag (ATestTag<20> ());
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   885
  CHECK (p, 1, E (20, 0, 1000));
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   886
  frag0 = p->CreateFragment (10, 90);
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   887
  CHECK (p, 1, E (20, 0, 1000));
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   888
  CHECK (frag0, 1, E (20, 0, 90));
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   889
  p = 0;
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   890
  frag0->AddHeader (ATestHeader<10> ());
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   891
  CHECK (frag0, 1, E (20, 10, 100));
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   892
3237
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   893
  {
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   894
    Ptr<Packet> tmp = Create<Packet> (100);
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   895
    tmp->AddTag (ATestTag<20> ());
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   896
    CHECK (tmp, 1, E (20, 0, 100));
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   897
    tmp->AddHeader (ATestHeader<10> ());
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   898
    CHECK (tmp, 1, E (20, 10, 110));
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   899
    ATestHeader<10> h;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   900
    tmp->RemoveHeader (h);
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   901
    CHECK (tmp, 1, E (20, 0, 100));
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   902
    tmp->AddHeader (ATestHeader<10> ());
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   903
    CHECK (tmp, 1, E (20, 10, 110));
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   904
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   905
    tmp = Create<Packet> (100);
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   906
    tmp->AddTag (ATestTag<20> ());
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   907
    CHECK (tmp, 1, E (20, 0, 100));
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   908
    tmp->AddTrailer (ATestTrailer<10> ());
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   909
    CHECK (tmp, 1, E (20, 0, 100));
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   910
    ATestTrailer<10> t;
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   911
    tmp->RemoveTrailer (t);
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   912
    CHECK (tmp, 1, E (20, 0, 100));
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   913
    tmp->AddTrailer (ATestTrailer<10> ());
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   914
    CHECK (tmp, 1, E (20, 0, 100));
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   915
    
57d9fc10f15d a few new testcases, bug fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3230
diff changeset
   916
  }
3298
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   917
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   918
  {
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   919
    Ptr<Packet> tmp = Create<Packet> (0);
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   920
    tmp->AddHeader (ATestHeader<156> ());
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   921
    tmp->AddTag (ATestTag<20> ());
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   922
    CHECK (tmp, 1, E (20, 0, 156));
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   923
    tmp->RemoveAtStart (120);
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   924
    CHECK (tmp, 1, E (20, 0, 36));
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   925
    Ptr<Packet> a = Create<Packet> (0);
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   926
    a->AddAtEnd (tmp);
f7839ed0ce9d bug 217: add failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3237
diff changeset
   927
    CHECK (a, 1, E (20, 0, 36));
3300
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   928
  }
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   929
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   930
  {
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   931
    Ptr<Packet> tmp = Create<Packet> (0);
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   932
    tmp->AddTag (ATestTag<20> ());
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   933
    CHECK (tmp, 0, E (20, 0, 0));
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   934
  }
3301
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   935
  {
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   936
    Ptr<Packet> tmp = Create<Packet> (1000);
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   937
    tmp->AddTag (ATestTag<20> ());
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   938
    CHECK (tmp, 1, E (20, 0, 1000));
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   939
    tmp->RemoveAtStart (1000);
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   940
    CHECK (tmp, 0,  E (0,0,0));
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   941
    Ptr<Packet> a = Create<Packet> (10);
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   942
    a->AddTag (ATestTag<10> ());
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   943
    CHECK (a, 1, E (10, 0, 10));
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   944
    tmp->AddAtEnd (a);
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   945
    CHECK (tmp, 1, E (10, 0, 10));
60edfd1060ff bug 217: yet another testcase: make sure we handle degenerate testcases with tags which refer to non-existant data.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3300
diff changeset
   946
  }
3300
c8011a2a0c60 another testcase for bug 217. Make sure we do not report tags outside of the current range
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3298
diff changeset
   947
  
3048
0c66462c3406 a couple more tests.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3046
diff changeset
   948
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   949
  return result;
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   950
}
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   951
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   952
3035
644bfc099992 a new tag implementation: Mtag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2992
diff changeset
   953
static PacketTest g_packetTest;
772
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   954
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   955
}; // namespace ns3
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   956
1e4fde8c1249 Add a Packet::AddAtEnd unit test.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 463
diff changeset
   957
#endif /* RUN_SELF_TESTS */