src/common/packet.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 29 May 2007 16:09:20 +0200
changeset 789 1e19322e9012
parent 629 1b4dd2d99313
child 806 0190f1b49dc8
permissions -rw-r--r--
merge unfinished packet history code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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
 * All rights reserved.
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * 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
     7
 * 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
     8
 * published by the Free Software Foundation;
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * 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
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * GNU General Public License for more details.
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#ifndef PACKET_H
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#define PACKET_H
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <stdint.h>
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#include "buffer.h"
104
3006f1b350ae add header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 92
diff changeset
    26
#include "header.h"
107
2cbaa2a1b116 add trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 106
diff changeset
    27
#include "trailer.h"
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include "tags.h"
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
    29
#include "packet-history.h"
14
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 9
diff changeset
    30
#include "ns3/callback.h"
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
    31
#include "ns3/assert.h"
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    33
namespace ns3 {
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    35
/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    36
 * \brief network packets
80
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    37
 *
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    38
 * Each network packet contains a byte buffer and a list of tags.
106
9b7cf31baf8c remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 104
diff changeset
    39
 * - The byte buffer stores the serialized content of the headers and trailers 
9b7cf31baf8c remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 104
diff changeset
    40
 * added to a packet. The serialized representation of these headers is expected
80
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    41
 * to match that of real network packets bit for bit (although nothing
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    42
 * forces you to do this) which means that the content of a packet buffer
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    43
 * is expected to be that of a real packet.
81
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    44
 * - The list of tags stores an arbitrarily large set of arbitrary 
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    45
 * user-provided data structures in the packet: only one instance of
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    46
 * each type of data structure is allowed in a list of tags. 
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    47
 * These tags typically contain per-packet cross-layer information or 
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    48
 * flow identifiers. Each tag stored in the tag list can be at most
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    49
 * 16 bytes big. Trying to attach bigger data structures will trigger
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    50
 * crashes at runtime.
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    51
 *
106
9b7cf31baf8c remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 104
diff changeset
    52
 * Implementing a new type of Header for a new protocol is pretty easy
9b7cf31baf8c remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 104
diff changeset
    53
 * and is a matter of creating a subclass of the ns3::Header base class,
629
1b4dd2d99313 remove references to Chunk and replace them with references to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
    54
 * and implementing the 4 pure virtual methods defined in ns3::Header.
106
9b7cf31baf8c remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 104
diff changeset
    55
 * Sample code which shows how to create such a new Header, how to use
84
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    56
 * it, and how to manipulate tags is shown below:
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    57
 * \include samples/main-packet.cc
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    58
 *
81
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    59
 * The current implementation of the byte buffers and tag list is based
84
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    60
 * on COW (Copy On Write. An introduction to COW can be found in Scott 
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    61
 * Meyer's "More Effective C++", items 17 and 29). What this means is that
81
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    62
 * copying packets without modifying them is very cheap (in terms of cpu
84
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    63
 * and memory usage) and modifying them can be also very cheap. What is 
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    64
 * key for proper COW implementations is being
81
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    65
 * able to detect when a given modification of the state of a packet triggers
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    66
 * a full copy of the data prior to the modification: COW systems need
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    67
 * to detect when an operation is "dirty".
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    68
 *
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    69
 * Dirty operations:
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    70
 *   - ns3::Packet::RemoveTag
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    71
 *   - ns3::Packet::Add
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    72
 *   - both versions of ns3::Packet::AddAtEnd
84
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    73
 *
81
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    74
 * Non-dirty operations:
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    75
 *   - ns3::Packet::AddTag
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    76
 *   - ns3::Packet::RemoveAllTags
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    77
 *   - ns3::Packet::PeekTag
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    78
 *   - ns3::Packet::Peek
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    79
 *   - ns3::Packet::Remove
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    80
 *   - ns3::Packet::CreateFragment
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    81
 *   - ns3::Packet::RemoveAtStart
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    82
 *   - ns3::Packet::RemoveAtEnd
81
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    83
 *
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    84
 * Dirty operations will always be slower than non-dirty operations,
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    85
 * sometimes by several orders of magnitude. However, even the
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    86
 * dirty operations have been optimized for common use-cases which
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    87
 * means that most of the time, these operations will not trigger
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    88
 * data copies and will thus be still very fast.
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    89
 */
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
class Packet {
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
public:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    92
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    93
   * Create an empty packet with a new uid (as returned
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    94
   * by getUid).
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    95
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    96
  Packet ();
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    97
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    98
   * Create a packet with a zero-filled payload.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    99
   * The memory necessary for the payload is not allocated:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   100
   * it will be allocated at any later point if you attempt
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   101
   * to fragment this packet or to access the zero-filled
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   102
   * bytes. The packet is allocated with a new uid (as 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   103
   * returned by getUid).
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   104
   * 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   105
   * \param size the size of the zero-filled payload
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   106
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   107
  Packet (uint32_t size);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   108
  /**
239
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   109
   * Create a packet with payload filled with the content
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   110
   * of this buffer. The input data is copied: the input
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   111
   * buffer is untouched.
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   112
   *
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   113
   * \param buffer the data to store in the packet.
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   114
   * \param size the size of the input buffer.
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   115
   */
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   116
  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
   117
  /**
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   118
   * Create a new packet which contains a fragment of the original
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   119
   * packet. The returned packet shares the same uid as this packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   120
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   121
   * \param start offset from start of packet to start of fragment to create
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   122
   * \param length length of fragment to create
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   123
   * \returns a fragment of the original packet
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   124
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   125
  Packet CreateFragment (uint32_t start, uint32_t length) const;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   126
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   127
   * \returns the size in bytes of the packet (including the zero-filled
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   128
   *          initial payload)
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   129
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   130
  uint32_t GetSize (void) const;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   131
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   132
   * Add header to this packet. This method invokes the
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   133
   * ns3::Chunk::GetSerializedSize and ns3::Chunk::SerializeTo 
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   134
   * methods to reserve space in the buffer and request the 
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   135
   * header to serialize itself in the packet buffer.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   136
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   137
   * \param header a reference to the header to add to this packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   138
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   139
  template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   140
  void AddHeader (T const &header);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   141
  /**
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   142
   * Deserialize and remove the header from the internal buffer.
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   143
   * This method invokes ns3::Chunk::DeserializeFrom.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   144
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   145
   * \param header a reference to the header to remove from the internal buffer.
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   146
   * \returns the number of bytes removed from the packet.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   147
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   148
  template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   149
  uint32_t RemoveHeader (T &header);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   150
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   151
   * Add trailer to this packet. This method invokes the
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   152
   * ns3::Chunk::GetSerializedSize and ns3::Trailer::serializeTo 
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   153
   * methods to reserve space in the buffer and request the trailer 
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   154
   * to serialize itself in the packet buffer.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   155
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   156
   * \param trailer a reference to the trailer to add to this packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   157
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   158
  template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   159
  void AddTrailer (T const &trailer);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   160
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   161
   * Remove a deserialized trailer from the internal buffer.
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   162
   * This method invokes the ns3::Chunk::DeserializeFrom method.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   163
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   164
   * \param trailer a reference to the trailer to remove from the internal buffer.
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   165
   * \returns the number of bytes removed from the end of the packet.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   166
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   167
  template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   168
  uint32_t RemoveTrailer (T &trailer);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   169
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   170
   * Attach a tag to this packet. The tag is fully copied
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   171
   * in a packet-specific internal buffer. This operation 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   172
   * is expected to be really fast.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   173
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   174
   * \param tag a pointer to the tag to attach to this packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   175
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   176
  template <typename T>
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   177
  void AddTag (T const &tag);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   178
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   179
   * Remove a tag from this packet. The data stored internally
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   180
   * for this tag is copied in the input tag if an instance
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   181
   * of this tag type is present in the internal buffer. If this
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   182
   * tag type is not present, the input tag is not modified. 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   183
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   184
   * This operation can be potentially slow and might trigger
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   185
   * unexpectedly large memory allocations. It is thus
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   186
   * usually a better idea to create a copy of this packet,
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   187
   * and invoke removeAllTags on the copy to remove all 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   188
   * tags rather than remove the tags one by one from a packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   189
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   190
   * \param tag a pointer to the tag to remove from this packet
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   191
   * \returns true if an instance of this tag type is stored
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   192
   *          in this packet, false otherwise.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   193
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   194
  template <typename T>
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   195
  bool RemoveTag (T &tag);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   196
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   197
   * Copy a tag stored internally to the input tag. If no instance
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   198
   * of this tag is present internally, the input tag is not modified.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   199
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   200
   * \param tag a pointer to the tag to read from this packet
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   201
   * \returns true if an instance of this tag type is stored
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   202
   *          in this packet, false otherwise.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   203
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   204
  template <typename T>
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   205
  bool PeekTag (T &tag) const;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   206
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   207
   * Remove all the tags stored in this packet. This operation is
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   208
   * much much faster than invoking removeTag n times.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   209
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   210
  void RemoveAllTags (void);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   211
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   212
   * Concatenate the input packet at the end of the current
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   213
   * packet. This does not alter the uid of either packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   214
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   215
   * \param packet packet to concatenate
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   216
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   217
  void AddAtEnd (Packet packet);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   218
  /**
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   219
   * \param size number of padding bytes to add.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   220
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   221
  void AddPaddingAtEnd (uint32_t size);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   222
  /** 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   223
   * Remove size bytes from the end of the current packet
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   224
   * It is safe to remove more bytes that what is present in
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   225
   * the packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   226
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   227
   * \param size number of bytes from remove
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   228
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   229
  void RemoveAtEnd (uint32_t size);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   230
  /** 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   231
   * Remove size bytes from the start of the current packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   232
   * It is safe to remove more bytes that what is present in
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   233
   * the packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   234
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   235
   * \param size number of bytes from remove
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   236
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   237
  void RemoveAtStart (uint32_t size);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   238
  
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   239
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   240
   * If you try to change the content of the buffer
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   241
   * returned by this method, you will die.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   242
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   243
   * \returns a pointer to the internal buffer of the packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   244
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   245
  uint8_t const *PeekData (void) const;
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   246
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   247
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   248
   * A packet is allocated a new uid when it is created
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   249
   * empty or with zero-filled payload.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   250
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   251
   * \returns an integer identifier which uniquely
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   252
   *          identifies this packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   253
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   254
  uint32_t GetUid (void) const;
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   255
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   256
  void Print (std::ostream &os) const;
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
private:
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   258
  Packet (Buffer buffer, Tags tags, PacketHistory history, uint32_t uid);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   259
  Buffer m_buffer;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   260
  Tags m_tags;
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   261
  PacketHistory m_history;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   262
  uint32_t m_uid;
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   263
  static uint32_t m_globalUid;
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
};
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   266
}; // namespace ns3
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
77
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   268
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   269
/**************************************************
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   270
  Start of implementation of templates defined
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   271
  above
77
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   272
 *************************************************/
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   273
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   274
namespace ns3 {
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
template <typename T>
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   277
void
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   278
Packet::AddHeader (T const &header)
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   279
{
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   280
  NS_ASSERT_MSG (dynamic_cast<Header const *> (&header) != 0, 
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   281
                 "Must pass Header subclass to Packet::AddHeader");
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   282
  uint32_t size = header.GetSize ();
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   283
  m_buffer.AddAtStart (size);
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   284
  header.Serialize (m_buffer.Begin ());
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   285
  m_history.AddHeader (header, size);
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   286
}
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   287
template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   288
uint32_t
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   289
Packet::RemoveHeader (T &header)
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   290
{
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   291
  NS_ASSERT_MSG (dynamic_cast<Header const *> (&header) != 0, 
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   292
                 "Must pass Header subclass to Packet::RemoveHeader");
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   293
  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   294
  m_buffer.RemoveAtStart (deserialized);
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   295
  m_history.RemoveHeader (header, deserialized);
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   296
  return deserialized;
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   297
}
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   298
template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   299
void
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   300
Packet::AddTrailer (T const &trailer)
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   301
{
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   302
  NS_ASSERT_MSG (dynamic_cast<Trailer const *> (&trailer) != 0, 
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   303
                 "Must pass Trailer subclass to Packet::AddTrailer");
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   304
  uint32_t size = trailer.GetSize ();
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   305
  m_buffer.AddAtEnd (size);
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   306
  Buffer::Iterator start = m_buffer.End ();
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   307
  start.Prev (size);
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   308
  trailer.Serialize (start);
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   309
  m_history.AddTrailer (trailer, size);
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   310
}
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   311
template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   312
uint32_t
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   313
Packet::RemoveTrailer (T &trailer)
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   314
{
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   315
  NS_ASSERT_MSG (dynamic_cast<Trailer const *> (&trailer) != 0, 
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   316
                 "Must pass Trailer subclass to Packet::RemoveTrailer");
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   317
  uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   318
  m_buffer.RemoveAtEnd (deserialized);
789
1e19322e9012 merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 629
diff changeset
   319
  m_history.RemoveTrailer (trailer, deserialized);
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   320
  return deserialized;
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   321
}
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   322
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   323
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   324
template <typename T>
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   325
void Packet::AddTag (T const& tag)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   327
  m_tags.Add (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   328
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
template <typename T>
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   330
bool Packet::RemoveTag (T & tag)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   332
  return m_tags.Remove (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   333
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
template <typename T>
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   335
bool Packet::PeekTag (T & tag) const
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   336
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   337
  return m_tags.Peek (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   338
}
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   339
}; // namespace ns3
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   340
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   341
#endif /* PACKET_H */