src/common/packet.h
author Raj Bhattacharjea <raj.b@gatech.edu>
Mon, 14 May 2007 10:38:08 -0400
changeset 624 11cc5c692eb4
parent 464 687e2b7b5f11
child 629 1b4dd2d99313
permissions -rw-r--r--
datarate, packet, defaultvalue, object dox
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"
14
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 9
diff changeset
    29
#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
    30
#include "ns3/assert.h"
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    32
namespace ns3 {
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    34
/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    35
 * \brief network packets
80
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    36
 *
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    37
 * 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
    38
 * - 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
    39
 * 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
    40
 * 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
    41
 * 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
    42
 * 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
    43
 * - 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
    44
 * 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
    45
 * 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
    46
 * 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
    47
 * 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
    48
 * 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
    49
 * crashes at runtime.
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    50
 *
106
9b7cf31baf8c remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 104
diff changeset
    51
 * 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
    52
 * and is a matter of creating a subclass of the ns3::Header base class,
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 464
diff changeset
    53
 * and implementing the 4 pure virtual methods defined in ns3::Chunk.
106
9b7cf31baf8c remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 104
diff changeset
    54
 * 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
    55
 * it, and how to manipulate tags is shown below:
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    56
 * \include samples/main-packet.cc
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    57
 *
81
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    58
 * 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
    59
 * 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
    60
 * 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
    61
 * 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
    62
 * 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
    63
 * 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
    64
 * 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
    65
 * 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
    66
 * 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
    67
 *
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    68
 * Dirty operations:
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    69
 *   - ns3::Packet::RemoveTag
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    70
 *   - ns3::Packet::Add
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    71
 *   - both versions of ns3::Packet::AddAtEnd
84
63b3ed9ce4e4 integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 82
diff changeset
    72
 *
81
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    73
 * Non-dirty operations:
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    74
 *   - ns3::Packet::AddTag
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    75
 *   - ns3::Packet::RemoveAllTags
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    76
 *   - ns3::Packet::PeekTag
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    77
 *   - ns3::Packet::Peek
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    78
 *   - ns3::Packet::Remove
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    79
 *   - ns3::Packet::CreateFragment
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    80
 *   - ns3::Packet::RemoveAtStart
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
    81
 *   - 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
    82
 *
80856bb1e1e8 add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 80
diff changeset
    83
 * 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
    84
 * 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
    85
 * 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
    86
 * 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
    87
 * 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
    88
 */
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
class Packet {
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
public:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    91
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    92
   * 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
    93
   * by getUid).
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    94
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    95
  Packet ();
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    96
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    97
   * Create a packet with a zero-filled payload.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    98
   * The memory necessary for the payload is not allocated:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    99
   * 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
   100
   * 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
   101
   * 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
   102
   * returned by getUid).
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   103
   * 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   104
   * \param size the size of the zero-filled payload
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   105
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   106
  Packet (uint32_t size);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   107
  /**
239
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   108
   * 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
   109
   * 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
   110
   * buffer is untouched.
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   111
   *
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   112
   * \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
   113
   * \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
   114
   */
e194d619534b add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   115
  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
   116
  /**
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   117
   * 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
   118
   * 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
   119
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   120
   * \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
   121
   * \param length length of fragment to create
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   122
   * \returns a fragment of the original packet
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   123
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   124
  Packet CreateFragment (uint32_t start, uint32_t length) const;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   125
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   126
   * \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
   127
   *          initial payload)
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   128
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   129
  uint32_t GetSize (void) const;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   130
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   131
   * Add header to this packet. This method invokes the
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   132
   * ns3::Chunk::GetSerializedSize and ns3::Chunk::SerializeTo 
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   133
   * 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
   134
   * header to serialize itself in the packet buffer.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   135
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   136
   * \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
   137
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   138
  template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   139
  void AddHeader (T const &header);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   140
  /**
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   141
   * Deserialize and remove the header from the internal buffer.
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   142
   * This method invokes ns3::Chunk::DeserializeFrom.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   143
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   144
   * \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
   145
   * \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
   146
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   147
  template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   148
  uint32_t RemoveHeader (T &header);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   149
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   150
   * Add trailer to this packet. This method invokes the
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   151
   * ns3::Chunk::GetSerializedSize and ns3::Trailer::serializeTo 
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   152
   * 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
   153
   * to serialize itself in the packet buffer.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   154
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   155
   * \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
   156
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   157
  template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   158
  void AddTrailer (T const &trailer);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   159
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   160
   * Remove a deserialized trailer 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
   161
   * This method invokes the ns3::Chunk::DeserializeFrom method.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   162
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   163
   * \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
   164
   * \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
   165
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   166
  template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   167
  uint32_t RemoveTrailer (T &trailer);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   168
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   169
   * 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
   170
   * in a packet-specific internal buffer. This operation 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   171
   * is expected to be really fast.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   172
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   173
   * \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
   174
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   175
  template <typename T>
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   176
  void AddTag (T const &tag);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   177
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   178
   * 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
   179
   * 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
   180
   * 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
   181
   * 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
   182
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   183
   * This operation can be potentially slow and might trigger
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   184
   * unexpectedly large memory allocations. It is thus
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   185
   * 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
   186
   * and invoke removeAllTags on the copy to remove all 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   187
   * 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
   188
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   189
   * \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
   190
   * \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
   191
   *          in this packet, false otherwise.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   192
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   193
  template <typename T>
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   194
  bool RemoveTag (T &tag);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   195
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   196
   * 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
   197
   * 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
   198
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   199
   * \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
   200
   * \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
   201
   *          in this packet, false otherwise.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   202
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   203
  template <typename T>
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   204
  bool PeekTag (T &tag) const;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   205
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   206
   * 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
   207
   * much much faster than invoking removeTag n times.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   208
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   209
  void RemoveAllTags (void);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   210
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   211
   * 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
   212
   * 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
   213
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   214
   * \param packet packet to concatenate
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   215
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   216
  void AddAtEnd (Packet packet);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   217
  /**
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   218
   * \param size number of padding bytes to add.
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   219
   */
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   220
  void AddPaddingAtEnd (uint32_t size);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   221
  /** 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   222
   * 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
   223
   * 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
   224
   * the packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   225
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   226
   * \param size number of bytes from remove
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   227
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   228
  void RemoveAtEnd (uint32_t size);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   229
  /** 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   230
   * 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
   231
   * 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
   232
   * the packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   233
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   234
   * \param size number of bytes from remove
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   235
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   236
  void RemoveAtStart (uint32_t size);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   237
  
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
   * 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
   240
   * returned by this method, you will die.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   241
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   242
   * \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
   243
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   244
  uint8_t const *PeekData (void) const;
91
8066ef8d9274 add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 90
diff changeset
   245
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   246
  /**
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   247
   * 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
   248
   * empty or with zero-filled payload.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   249
   *
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   250
   * \returns an integer identifier which uniquely
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   251
   *          identifies this packet.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   252
   */
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   253
  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
   254
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   255
  void Print (std::ostream &os) const;
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
private:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   257
  Packet (Buffer buffer, Tags tags, uint32_t uid);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   258
  Buffer m_buffer;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   259
  Tags m_tags;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   260
  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
   261
  static uint32_t m_globalUid;
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
};
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   264
}; // namespace ns3
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
77
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   266
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   267
/**************************************************
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   268
  Start of implementation of templates defined
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   269
  above
77
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   270
 *************************************************/
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   271
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   272
namespace ns3 {
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
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
   275
void
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   276
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
   277
{
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   278
  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
   279
                 "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
   280
  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
   281
  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
   282
  header.Serialize (m_buffer.Begin ());
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   283
}
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   284
template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   285
uint32_t
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   286
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
   287
{
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   288
  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
   289
                 "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
   290
  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
   291
  m_buffer.RemoveAtStart (deserialized);
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   292
  return deserialized;
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   293
}
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   294
template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   295
void
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   296
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
   297
{
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   298
  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
   299
                 "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
   300
  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
   301
  m_buffer.AddAtEnd (size);
464
687e2b7b5f11 make sure that the code matches the documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 463
diff changeset
   302
  Buffer::Iterator end = m_buffer.End ();
687e2b7b5f11 make sure that the code matches the documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 463
diff changeset
   303
  trailer.Serialize (end);
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   304
}
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   305
template <typename T>
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   306
uint32_t
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   307
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
   308
{
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   309
  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
   310
                 "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
   311
  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
   312
  m_buffer.RemoveAtEnd (deserialized);
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   313
  return deserialized;
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
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   316
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 239
diff changeset
   317
template <typename T>
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   318
void Packet::AddTag (T const& tag)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   320
  m_tags.Add (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   321
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   322
template <typename T>
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   323
bool Packet::RemoveTag (T & tag)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   324
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   325
  return m_tags.Remove (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   327
template <typename T>
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 111
diff changeset
   328
bool Packet::PeekTag (T & tag) const
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   330
  return m_tags.Peek (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
}
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   332
}; // namespace ns3
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
#endif /* PACKET_H */