src/common/packet.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 06 Sep 2006 17:06:45 +0200
changeset 80 3706b1172ab9
parent 79 84f791c00aa5
child 81 80856bb1e1e8
permissions -rw-r--r--
start of rationale for packets
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
     1
/* -*-    Mode:C++; c-basic-offset:4; tab-width:4; indent-tabs-mode:f -*- */
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"
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include "chunk.h"
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include "tags.h"
14
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 9
diff changeset
    28
#include "ns3/callback.h"
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    30
namespace ns3 {
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    32
/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    33
 * \brief network packets
80
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    34
 *
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    35
 * Each network packet contains a byte buffer and a list of tags.
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    36
 * The byte buffer stores the serialized content of the chunks added 
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    37
 * to a packet. The serialized representation of these chunks is expected
3706b1172ab9 start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 79
diff changeset
    38
 * 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
    39
 * 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
    40
 * is expected to be that of a real packet.
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    41
 */
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
class Packet {
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
public:
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    44
    typedef Callback<void,uint8_t *,uint32_t> PacketReadWriteCallback;
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    45
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    46
	 * Create an empty packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    47
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    48
    Packet ();
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    49
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    50
	 * Create a packet with a zero-filled payload.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    51
	 * The memory necessary for the payload is not allocated:
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    52
	 * it will be allocated at any later point if you attempt
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    53
	 * to fragment this packet or to access the zero-filled
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    54
	 * bytes.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    55
	 * 
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    56
	 * \param size the size of the zero-filled payload
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    57
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    58
    Packet (uint32_t size);
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    59
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    60
	 * Create a new packet which contains a fragment of the original
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    61
	 * packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    62
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    63
	 * \param start offset from start of packet to start of fragment to create
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    64
	 * \param length length of fragment to create
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    65
	 * \returns a fragment of the original packet
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    66
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    67
    Packet createFragment (uint32_t start, uint32_t length) const;
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    68
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    69
	 * \returns the size in bytes of the packet (including the zero-filled
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    70
	 *          initial payload)
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    71
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    72
    uint32_t getSize (void) const;
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    73
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    74
	 * Add chunk to this packet. This method invokes the
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    75
	 * ns3::Chunk::addTo method to request the chunk to serialize
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    76
	 * itself in the packet buffer.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    77
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    78
	 * \param chunk a pointer to the chunk to add to this packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    79
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    80
    void add (Chunk *chunk);
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    81
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    82
	 * Deserialize chunk from this packet. This method invokes the
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    83
	 * ns3::Chunk::peekFrom method to request the chunk to deserialize
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    84
	 * itself from the packet buffer. This method does not remove
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    85
	 * the chunk from the buffer.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    86
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    87
	 * \param chunk a pointer to the chunk to deserialize from the buffer
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    88
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    89
    void peek (Chunk *chunk) const;
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    90
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    91
	 * Remove a deserialized chunk from the internal buffer.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    92
	 * This method invokes ns3::Chunk::removeFrom to complete
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    93
	 * the work initiated by Packet::peek and ns3::Chunk::peekFrom.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    94
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    95
	 * \param chunk a pointer to the chunk to remove from the internal buffer.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    96
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    97
    void remove (Chunk *chunk);
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    98
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
    99
	 * Attach a tag to this packet. The tag is fully copied
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   100
	 * in a packet-specific internal buffer. This operation 
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   101
	 * is expected to be really fast.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   102
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   103
	 * \param tag a pointer to the tag to attach to this packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   104
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   105
    template <typename T>
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   106
    void addTag (T const *tag);
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   107
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   108
	 * Remove a tag from this packet. The data stored internally
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   109
	 * for this tag is copied in the input tag if an instance
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   110
	 * of this tag type is present in the internal buffer. If this
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   111
	 * tag type is not present, the input tag is not modified. 
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   112
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   113
	 * This operation can be potentially slow and might trigger
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   114
	 * unexpectedly large memory allocations. It is thus
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   115
	 * usually a better idea to create a copy of this packet,
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   116
	 * and invoke removeAllTags on the copy to remove all 
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   117
	 * tags rather than remove the tags one by one from a packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   118
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   119
	 * \param tag a pointer to the tag to remove from this packet
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   120
	 * \returns true if an instance of this tag type is stored
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   121
	 *          in this packet, false otherwise.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   122
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   123
    template <typename T>
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   124
    bool removeTag (T *tag);
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   125
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   126
	 * Copy a tag stored internally to the input tag. If no instance
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   127
	 * of this tag is present internally, the input tag is not modified.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   128
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   129
	 * \param tag a pointer to the tag to read from this packet
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   130
	 * \returns true if an instance of this tag type is stored
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   131
	 *          in this packet, false otherwise.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   132
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   133
    template <typename T>
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   134
    bool peekTag (T *tag) const;
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   135
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   136
	 * Remove all the tags stored in this packet. This operation is
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   137
	 * much much faster than invoking removeTag n times.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   138
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   139
    void removeAllTags (void);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   140
    void write (PacketReadWriteCallback callback) const;
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   141
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   142
	 * Concatenate the input packet at the end of the current
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   143
	 * packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   144
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   145
	 * \param packet packet to concatenate
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   146
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   147
    void addAtEnd (Packet packet);
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   148
	/**
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   149
	 * Concatenate the fragment of the input packet identified
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   150
	 * by the offset and size parameters at the end of the current
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   151
	 * packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   152
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   153
	 * \param packet to concatenate
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   154
	 * \param offset offset of fragment to copy from the start of the input packet
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   155
	 * \param size size of fragment of input packet to copy.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   156
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   157
    void addAtEnd (Packet packet, uint32_t offset, uint32_t size);
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   158
	/** 
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   159
	 * Remove size bytes from the end of the current packet
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   160
	 * It is safe to remove more bytes that what is present in
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   161
	 * the packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   162
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   163
	 * \param size number of bytes from remove
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   164
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   165
    void removeAtEnd (uint32_t size);
79
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   166
	/** 
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   167
	 * Remove size bytes from the start of the current packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   168
	 * It is safe to remove more bytes that what is present in
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   169
	 * the packet.
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   170
	 *
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   171
	 * \param size number of bytes from remove
84f791c00aa5 improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 77
diff changeset
   172
	 */
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   173
    void removeAtStart (uint32_t size);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
private:
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   176
    Packet (Buffer buffer, Tags tags);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   177
    Buffer m_buffer;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   178
    Tags m_tags;
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
};
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   181
}; // namespace ns3
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
77
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   183
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   184
/**************************************************
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   185
    Start of implementation of templates defined
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   186
    above
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   187
 *************************************************/
926e17b61dfb add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 54
diff changeset
   188
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   189
namespace ns3 {
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
template <typename T>
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   192
void Packet::addTag (T const*tag)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   194
    m_tags.add (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
template <typename T>
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   197
bool Packet::removeTag (T *tag)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   199
    return m_tags.remove (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
}
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
template <typename T>
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   202
bool Packet::peekTag (T *tag) const
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   204
    return m_tags.peek (tag);
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
}
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
   206
}; // namespace ns3
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
#endif /* PACKET_H */