src/node/packetbb.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu Nov 12 13:01:01 2009 +0100 (2009-11-12)
changeset 5505 c0ac392289c3
parent 5263 a0283279fddd
child 5943 afda15a818fa
permissions -rw-r--r--
replace RefCountBase with SimpleRefCount<> to avoid duplicate refcounting implementations.
tom5760@4775
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
tom5760@4776
     2
/* vim: set ts=2 sw=2 sta expandtab ai si cin: */
tom5760@4775
     3
/* 
tom5760@4775
     4
 * Copyright (c) 2009 Drexel University
tom5760@4775
     5
 * 
tom5760@4775
     6
 * This program is free software; you can redistribute it and/or modify
tom5760@4775
     7
 * it under the terms of the GNU General Public License version 2 as
tom5760@4775
     8
 * published by the Free Software Foundation;
tom5760@4775
     9
 *
tom5760@4775
    10
 * This program is distributed in the hope that it will be useful,
tom5760@4775
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
tom5760@4775
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
tom5760@4775
    13
 * GNU General Public License for more details.
tom5760@4775
    14
 *
tom5760@4775
    15
 * You should have received a copy of the GNU General Public License
tom5760@4775
    16
 * along with this program; if not, write to the Free Software
tom5760@4775
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
tom5760@4775
    18
 * 
tom5760@4775
    19
 * Author: Tom Wambold <tom5760@gmail.com>
tom5760@4775
    20
 */
tom5760@4775
    21
/* These classes implement RFC 5444 - The Generalized Mobile Ad Hoc Network
tom5760@4782
    22
 * (MANET) Packet/PbbMessage Format
tom5760@4775
    23
 * See: http://tools.ietf.org/html/rfc5444 for details */
tom5760@4775
    24
tom5760@4775
    25
#ifndef PACKETBB_H
tom5760@4775
    26
#define PACKETBB_H
tom5760@4775
    27
tom5760@4775
    28
#include <list>
tom5760@4775
    29
tom5760@4775
    30
#include "ns3/ptr.h"
tom5760@4775
    31
#include "ns3/address.h"
tom5760@4775
    32
#include "ns3/header.h"
tom5760@4775
    33
#include "ns3/buffer.h"
mathieu@5505
    34
#include "ns3/simple-ref-count.h"
tom5760@4775
    35
tom5760@4775
    36
namespace ns3 {
tom5760@4775
    37
tom5760@4775
    38
/* Forward declare objects */
tom5760@4782
    39
class PbbMessage;
tom5760@4782
    40
class PbbAddressBlock;
tom5760@4782
    41
class PbbTlv;
tom5760@4782
    42
class PbbAddressTlv;
tom5760@4775
    43
tom5760@4784
    44
/** Used in Messages to determine whether it contains IPv4 or IPv6 addresses */
tom5760@4783
    45
enum PbbAddressLength {
tom5760@4775
    46
  IPV4 = 3,
tom5760@4775
    47
  IPV6 = 15,
tom5760@4775
    48
};
tom5760@4775
    49
tom5760@4779
    50
/**
tom5760@4787
    51
 * \brief A block of packet or message TLVs (PbbTlv).
tom5760@4779
    52
 *
tom5760@4779
    53
 * Acts similar to a C++ STL container.  Should not be used for Address TLVs.
tom5760@4779
    54
 */
tom5760@4782
    55
class PbbTlvBlock
tom5760@4775
    56
{
tom5760@4775
    57
public:
tom5760@4782
    58
  typedef std::list< Ptr<PbbTlv> >::iterator Iterator;
tom5760@4782
    59
  typedef std::list< Ptr<PbbTlv> >::const_iterator ConstIterator;
tom5760@4775
    60
tom5760@5263
    61
  PbbTlvBlock (void);
tom5760@5263
    62
  ~PbbTlvBlock (void);
tom5760@5263
    63
tom5760@4784
    64
  /**
tom5760@4784
    65
   * \return an iterator to the first TLV in this block.
tom5760@4784
    66
   */
tom5760@4775
    67
  Iterator Begin (void);
tom5760@4784
    68
tom5760@4784
    69
  /**
tom5760@4784
    70
   * \return a const iterator to the first TLV in this block.
tom5760@4784
    71
   */
tom5760@4775
    72
  ConstIterator Begin (void) const;
tom5760@4784
    73
tom5760@4784
    74
  /**
tom5760@4784
    75
   * \return an iterator to the past-the-end element in this block.
tom5760@4784
    76
   */
tom5760@4775
    77
  Iterator End (void);
tom5760@4784
    78
tom5760@4784
    79
  /**
tom5760@4784
    80
   * \return a const iterator to the past-the-end element in this block.
tom5760@4784
    81
   */
tom5760@4775
    82
  ConstIterator End (void) const;
tom5760@4775
    83
tom5760@4784
    84
  /**
tom5760@4784
    85
   * \return the number of TLVs in this block.
tom5760@4784
    86
   */
tom5760@4775
    87
  int Size (void) const;
tom5760@4784
    88
tom5760@4784
    89
  /**
tom5760@4784
    90
   * \return true if there are no TLVs in this block, false otherwise.
tom5760@4784
    91
   */
tom5760@4775
    92
  bool Empty (void) const;
tom5760@4775
    93
tom5760@4784
    94
  /**
tom5760@4784
    95
   * \return a smart pointer to the first TLV in this block.
tom5760@4784
    96
   */
tom5760@4782
    97
  Ptr<PbbTlv> Front (void) const;
tom5760@4784
    98
tom5760@4784
    99
  /**
tom5760@4784
   100
   * \return a smart pointer to the last TLV in this block.
tom5760@4784
   101
   */
tom5760@4782
   102
  Ptr<PbbTlv> Back (void) const;
tom5760@4775
   103
tom5760@4784
   104
  /**
tom5760@4784
   105
   * \brief Prepends a TLV to the front of this block.
tom5760@4784
   106
   * \param tlv a smart pointer to the TLV to prepend.
tom5760@4784
   107
   */
tom5760@4782
   108
  void PushFront (Ptr<PbbTlv> tlv);
tom5760@4784
   109
tom5760@4784
   110
  /**
tom5760@4784
   111
   * \brief Removes a TLV from the front of this block.
tom5760@4784
   112
   */
tom5760@4775
   113
  void PopFront (void);
tom5760@4775
   114
tom5760@4784
   115
  /**
tom5760@4784
   116
   * \brief Appends a TLV to the back of this block.
tom5760@4784
   117
   * \param tlv a smart pointer to the TLV to append.
tom5760@4784
   118
   */
tom5760@4782
   119
  void PushBack (Ptr<PbbTlv> tlv);
tom5760@4784
   120
tom5760@4784
   121
  /**
tom5760@4784
   122
   * \brief Removes a TLV from the back of this block.
tom5760@4784
   123
   */
tom5760@4775
   124
  void PopBack (void);
tom5760@4775
   125
tom5760@4784
   126
  /**
tom5760@4784
   127
   * \brief Inserts a TLV at the specified position in this block.
tom5760@4784
   128
   * \param position an Iterator pointing to the position in this block to
tom5760@4784
   129
   *        insert the TLV.
tom5760@4784
   130
   * \param tlv a smart pointer to the TLV to insert.
tom5760@4784
   131
   * \return An iterator pointing to the newly inserted TLV.
tom5760@4784
   132
   */
tom5760@4782
   133
  Iterator Insert (Iterator position, const Ptr<PbbTlv> tlv);
tom5760@4775
   134
tom5760@4784
   135
  /**
tom5760@4784
   136
   * \brief Removes the TLV at the specified position.
tom5760@4784
   137
   * \param position an Iterator pointing to the TLV to erase.
tom5760@4784
   138
   * \return an iterator pointing to the next TLV in the block.
tom5760@4784
   139
   */
tom5760@4775
   140
  Iterator Erase (Iterator position);
tom5760@4784
   141
tom5760@4784
   142
  /**
tom5760@4784
   143
   * \brief Removes all TLVs from [first, last) (includes first, not includes
tom5760@4784
   144
   *        last).
tom5760@4784
   145
   * \param first an Iterator pointing to the first TLV to erase (inclusive).
tom5760@4784
   146
   * \param last an Iterator pointing to the element past the last TLV to erase.
tom5760@4784
   147
   * \return an iterator pointing to the next TLV in the block.
tom5760@4784
   148
   */
tom5760@4775
   149
  Iterator Erase (Iterator first, Iterator last);
tom5760@4775
   150
tom5760@4784
   151
  /**
tom5760@4784
   152
   * \brief Removes all TLVs from this block.
tom5760@4784
   153
   */
tom5760@4775
   154
  void Clear (void);
tom5760@4775
   155
tom5760@4784
   156
  /**
tom5760@4784
   157
   * \return The size (in bytes) needed to serialize this block.
tom5760@4784
   158
   */
tom5760@4775
   159
  uint32_t GetSerializedSize (void) const;
tom5760@4784
   160
tom5760@4784
   161
  /**
tom5760@4784
   162
   * \brief Serializes this block into the specified buffer.
tom5760@4784
   163
   * \param start a reference to the point in a buffer to begin serializing.
tom5760@4784
   164
   *
tom5760@4784
   165
   * Users should not need to call this.  Blocks will be serialized by their
tom5760@4784
   166
   * containing packet.
tom5760@4784
   167
   */
tom5760@4775
   168
  void Serialize (Buffer::Iterator &start) const;
tom5760@4784
   169
tom5760@4784
   170
  /**
tom5760@4784
   171
   * \brief Deserializes a block from the specified buffer.
tom5760@4784
   172
   * \param start a reference to the point in a buffer to begin deserializing.
tom5760@4784
   173
   *
tom5760@4784
   174
   * Users should not need to call this.  Blocks will be deserialized by their
tom5760@4784
   175
   * containing packet.
tom5760@4784
   176
   */
tom5760@4775
   177
  void Deserialize (Buffer::Iterator &start);
tom5760@4784
   178
tom5760@4784
   179
  /**
tom5760@4784
   180
   * \brief Pretty-prints the contents of this block.
tom5760@4784
   181
   * \param os a stream object to print to.
tom5760@4784
   182
   */
tom5760@4775
   183
  void Print (std::ostream &os) const;
tom5760@4784
   184
tom5760@4784
   185
  /**
tom5760@4784
   186
   * \brief Pretty-prints the contents of this block, with specified indentation.
tom5760@4784
   187
   * \param os a stream object to print to.
tom5760@4784
   188
   * \param level level of indentation.
tom5760@4784
   189
   *
tom5760@4784
   190
   * This probably never needs to be called by users.  This is used when
tom5760@4784
   191
   * recursively printing sub-objects.
tom5760@4784
   192
   */
tom5760@4775
   193
  void Print (std::ostream &os, int level) const;
tom5760@4775
   194
tom5760@4782
   195
  bool operator== (const PbbTlvBlock &other) const;
tom5760@4782
   196
  bool operator!= (const PbbTlvBlock &other) const;
tom5760@4775
   197
tom5760@4775
   198
private:
tom5760@4782
   199
  std::list< Ptr<PbbTlv> > m_tlvList;
tom5760@4775
   200
};
tom5760@4775
   201
tom5760@4779
   202
/**
tom5760@4787
   203
 * \brief A block of Address TLVs (PbbAddressTlv).
tom5760@4779
   204
 *
tom5760@4779
   205
 * Acts similar to a C++ STL container.
tom5760@4779
   206
 */
tom5760@4782
   207
class PbbAddressTlvBlock
tom5760@4775
   208
{
tom5760@4775
   209
public:
tom5760@4782
   210
  typedef std::list< Ptr<PbbAddressTlv> >::iterator Iterator;
tom5760@4782
   211
  typedef std::list< Ptr<PbbAddressTlv> >::const_iterator ConstIterator;
tom5760@4775
   212
tom5760@5263
   213
  PbbAddressTlvBlock (void);
tom5760@5263
   214
  ~PbbAddressTlvBlock (void);
tom5760@5263
   215
tom5760@4784
   216
  /**
tom5760@4784
   217
   * \return an iterator to the first Address TLV in this block.
tom5760@4784
   218
   */
tom5760@4775
   219
  Iterator Begin (void);
tom5760@4784
   220
tom5760@4784
   221
  /**
tom5760@4784
   222
   * \return a const iterator to the first Address TLV in this block.
tom5760@4784
   223
   */
tom5760@4775
   224
  ConstIterator Begin (void) const;
tom5760@4784
   225
tom5760@4784
   226
  /**
tom5760@4784
   227
   * \return an iterator to the past-the-end element in this block.
tom5760@4784
   228
   */
tom5760@4775
   229
  Iterator End (void);
tom5760@4784
   230
tom5760@4784
   231
  /**
tom5760@4784
   232
   * \return a const iterator to the past-the-end element in this block.
tom5760@4784
   233
   */
tom5760@4775
   234
  ConstIterator End (void) const;
tom5760@4775
   235
tom5760@4784
   236
  /**
tom5760@4784
   237
   * \return the number of Address TLVs in this block.
tom5760@4784
   238
   */
tom5760@4775
   239
  int Size (void) const;
tom5760@4784
   240
tom5760@4784
   241
  /**
tom5760@4784
   242
   * \return true if there are no Address TLVs in this block, false otherwise.
tom5760@4784
   243
   */
tom5760@4775
   244
  bool Empty (void) const;
tom5760@4775
   245
tom5760@4784
   246
  /**
tom5760@4784
   247
   * \return the first Address TLV in this block.
tom5760@4784
   248
   */
tom5760@4782
   249
  Ptr<PbbAddressTlv> Front (void) const;
tom5760@4784
   250
tom5760@4784
   251
  /**
tom5760@4784
   252
   * \return the last AddressTLV in this block.
tom5760@4784
   253
   */
tom5760@4782
   254
  Ptr<PbbAddressTlv> Back (void) const;
tom5760@4775
   255
tom5760@4784
   256
  /**
tom5760@4784
   257
   * \brief Prepends an Address TLV to the front of this block.
tom5760@4784
   258
   * \param tlv a smart pointer to the Address TLV to prepend.
tom5760@4784
   259
   */
tom5760@4782
   260
  void PushFront (Ptr<PbbAddressTlv> tlv);
tom5760@4784
   261
tom5760@4784
   262
  /**
tom5760@4784
   263
   * \brief Removes an AddressTLV from the front of this block.
tom5760@4784
   264
   */
tom5760@4775
   265
  void PopFront (void);
tom5760@4775
   266
tom5760@4784
   267
  /**
tom5760@4784
   268
   * \brief Appends an Address TLV to the back of this block.
tom5760@4784
   269
   * \param tlv a smart pointer to the Address TLV to append.
tom5760@4784
   270
   */
tom5760@4782
   271
  void PushBack (Ptr<PbbAddressTlv> tlv);
tom5760@4784
   272
tom5760@4784
   273
  /**
tom5760@4784
   274
   * \brief Removes an Address TLV from the back of this block.
tom5760@4784
   275
   */
tom5760@4775
   276
  void PopBack (void);
tom5760@4775
   277
tom5760@4784
   278
  /**
tom5760@4784
   279
   * \brief Inserts an Address TLV at the specified position in this block.
tom5760@4784
   280
   * \param position an Iterator pointing to the position in this block to
tom5760@4784
   281
   *        insert the Address TLV.
tom5760@4784
   282
   * \param tlv a smart pointer to the Address TLV to insert.
tom5760@4784
   283
   * \return An iterator pointing to the newly inserted Address TLV.
tom5760@4784
   284
   */
tom5760@4782
   285
  Iterator Insert (Iterator position, const Ptr<PbbAddressTlv> tlv);
tom5760@4775
   286
tom5760@4784
   287
  /**
tom5760@4784
   288
   * \brief Removes the Address TLV at the specified position.
tom5760@4784
   289
   * \param position an Iterator pointing to the Address TLV to erase.
tom5760@4784
   290
   * \return an iterator pointing to the next Address TLV in the block.
tom5760@4784
   291
   */
tom5760@4775
   292
  Iterator Erase (Iterator position);
tom5760@4784
   293
tom5760@4784
   294
  /**
tom5760@4784
   295
   * \brief Removes all Address TLVs from [first, last) (includes first, not
tom5760@4784
   296
   *        includes last).
tom5760@4784
   297
   * \param first an Iterator pointing to the first Address TLV to erase
tom5760@4784
   298
   *        (inclusive).
tom5760@4784
   299
   * \param last an Iterator pointing to the element past the last Address TLV
tom5760@4784
   300
   *        to erase.
tom5760@4784
   301
   * \return an iterator pointing to the next Address TLV in the block.
tom5760@4784
   302
   */
tom5760@4775
   303
  Iterator Erase (Iterator first, Iterator last);
tom5760@4775
   304
tom5760@4784
   305
  /**
tom5760@4784
   306
   * \brief Removes all Address TLVs from this block.
tom5760@4784
   307
   */
tom5760@4775
   308
  void Clear (void);
tom5760@4775
   309
tom5760@4784
   310
  /**
tom5760@4784
   311
   * \return The size (in bytes) needed to serialize this block.
tom5760@4784
   312
   */
tom5760@4775
   313
  uint32_t GetSerializedSize (void) const;
tom5760@4784
   314
tom5760@4784
   315
  /**
tom5760@4784
   316
   * \brief Serializes this block into the specified buffer.
tom5760@4784
   317
   * \param start a reference to the point in a buffer to begin serializing.
tom5760@4784
   318
   *
tom5760@4784
   319
   * Users should not need to call this.  Blocks will be serialized by their
tom5760@4784
   320
   * containing packet.
tom5760@4784
   321
   */
tom5760@4775
   322
  void Serialize (Buffer::Iterator &start) const;
tom5760@4784
   323
tom5760@4784
   324
  /**
tom5760@4784
   325
   * \brief Deserializes a block from the specified buffer.
tom5760@4784
   326
   * \param start a reference to the point in a buffer to begin deserializing.
tom5760@4784
   327
   *
tom5760@4784
   328
   * Users should not need to call this.  Blocks will be deserialized by their
tom5760@4784
   329
   * containing packet.
tom5760@4784
   330
   */
tom5760@4775
   331
  void Deserialize (Buffer::Iterator &start);
tom5760@4784
   332
tom5760@4784
   333
  /**
tom5760@4784
   334
   * \brief Pretty-prints the contents of this block.
tom5760@4784
   335
   * \param os a stream object to print to.
tom5760@4784
   336
   */
tom5760@4775
   337
  void Print (std::ostream &os) const;
tom5760@4784
   338
tom5760@4784
   339
  /**
tom5760@4784
   340
   * \brief Pretty-prints the contents of this block, with specified indentation.
tom5760@4784
   341
   * \param os a stream object to print to.
tom5760@4784
   342
   * \param level level of indentation.
tom5760@4784
   343
   *
tom5760@4784
   344
   * This probably never needs to be called by users.  This is used when
tom5760@4784
   345
   * recursively printing sub-objects.
tom5760@4784
   346
   */
tom5760@4775
   347
  void Print (std::ostream &os, int level) const;
tom5760@4775
   348
tom5760@4782
   349
  bool operator== (const PbbAddressTlvBlock &other) const;
tom5760@4782
   350
  bool operator!= (const PbbAddressTlvBlock &other) const;
tom5760@4775
   351
tom5760@4775
   352
private:
tom5760@4782
   353
  std::list< Ptr<PbbAddressTlv> > m_tlvList;
tom5760@4775
   354
};
tom5760@4775
   355
tom5760@4779
   356
/**
tom5760@4784
   357
 * \brief Main PacketBB Packet object.
tom5760@4784
   358
 *
tom5760@4787
   359
 * A PacketBB packet is made up of zero or more packet TLVs (PbbTlv), and zero
tom5760@4787
   360
 * or more messages (PbbMessage).
tom5760@4787
   361
 *
tom5760@4784
   362
 * See: http://tools.ietf.org/html/rfc5444 for details.
tom5760@4779
   363
 */
mathieu@5505
   364
class PbbPacket : public SimpleRefCount<PbbPacket,Header>
tom5760@4775
   365
{
tom5760@4775
   366
public:
tom5760@4782
   367
  typedef std::list< Ptr<PbbTlv> >::iterator TlvIterator;
tom5760@4782
   368
  typedef std::list< Ptr<PbbTlv> >::const_iterator ConstTlvIterator;
tom5760@4782
   369
  typedef std::list< Ptr<PbbMessage> >::iterator MessageIterator;
tom5760@4782
   370
  typedef std::list< Ptr<PbbMessage> >::const_iterator ConstMessageIterator;
tom5760@4775
   371
tom5760@4782
   372
  PbbPacket (void);
tom5760@5263
   373
  ~PbbPacket (void);
tom5760@4775
   374
tom5760@4784
   375
  /**
tom5760@4784
   376
   * \return the version of PacketBB that constructed this packet.
tom5760@4784
   377
   *
tom5760@4784
   378
   * This will always return 0 for packets constructed using this API.
tom5760@4784
   379
   */
tom5760@4775
   380
  uint8_t GetVersion (void) const;
tom5760@4775
   381
tom5760@4784
   382
  /**
tom5760@4784
   383
   * \brief Sets the sequence number of this packet.
tom5760@4784
   384
   * \param number the sequence number.
tom5760@4784
   385
   */
tom5760@4775
   386
  void SetSequenceNumber (uint16_t number);
tom5760@4784
   387
tom5760@4779
   388
  /**
tom5760@4784
   389
   * \return the sequence number of this packet.
tom5760@4779
   390
   *
tom5760@4779
   391
   * Calling this while HasSequenceNumber is False is undefined.  Make sure you
tom5760@4780
   392
   * check it first.  This will be checked by an assert in debug builds.
tom5760@4779
   393
   */
tom5760@4776
   394
  uint16_t GetSequenceNumber (void) const;
tom5760@4784
   395
tom5760@4784
   396
  /**
tom5760@4784
   397
   * \brief Tests whether or not this packet has a sequence number.
tom5760@4784
   398
   * \return true if this packet has a sequence number, false otherwise.
tom5760@4784
   399
   *
tom5760@4784
   400
   * This should be called before calling GetSequenceNumber to make sure there
tom5760@4784
   401
   * actually is one.
tom5760@4784
   402
   */
tom5760@4775
   403
  bool HasSequenceNumber (void) const;
tom5760@4775
   404
tom5760@4775
   405
  /* Manipulating Packet TLVs */
tom5760@4775
   406
tom5760@4784
   407
  /**
tom5760@4784
   408
   * \return an iterator to the first Packet TLV in this packet.
tom5760@4784
   409
   */
tom5760@4775
   410
  TlvIterator TlvBegin (void);
tom5760@4784
   411
tom5760@4784
   412
  /**
tom5760@4784
   413
   * \return a const iterator to the first Packet TLV in this packet.
tom5760@4784
   414
   */
tom5760@4775
   415
  ConstTlvIterator TlvBegin (void) const;
tom5760@4784
   416
tom5760@4784
   417
  /**
tom5760@4784
   418
   * \return an iterator to the past-the-end element in this packet TLV block.
tom5760@4784
   419
   */
tom5760@4775
   420
  TlvIterator TlvEnd (void);
tom5760@4784
   421
tom5760@4784
   422
  /**
tom5760@4784
   423
   * \return a const iterator to the past-the-end element in this packet TLV
tom5760@4784
   424
   *         block.
tom5760@4784
   425
   */
tom5760@4775
   426
  ConstTlvIterator TlvEnd (void) const;
tom5760@4775
   427
tom5760@4784
   428
  /**
tom5760@4784
   429
   * \return the number of packet TLVs in this packet.
tom5760@4784
   430
   */
tom5760@4775
   431
  int TlvSize (void) const;
tom5760@4784
   432
tom5760@4784
   433
  /**
tom5760@4784
   434
   * \return true if there are no packet TLVs in this packet, false otherwise.
tom5760@4784
   435
   */
tom5760@4775
   436
  bool TlvEmpty (void) const;
tom5760@4775
   437
tom5760@4784
   438
  /**
tom5760@4784
   439
   * \return a smart pointer to the first packet TLV in this packet.
tom5760@4784
   440
   */
tom5760@4782
   441
  Ptr<PbbTlv> TlvFront (void);
tom5760@4784
   442
tom5760@4784
   443
  /**
tom5760@4784
   444
   * \return a const smart pointer to the first packet TLV in this packet.
tom5760@4784
   445
   */
tom5760@4782
   446
  const Ptr<PbbTlv> TlvFront (void) const;
tom5760@4784
   447
tom5760@4784
   448
  /**
tom5760@4784
   449
   * \return a smart pointer to the last packet TLV in this packet.
tom5760@4784
   450
   */
tom5760@4782
   451
  Ptr<PbbTlv> TlvBack (void);
tom5760@4784
   452
tom5760@4784
   453
  /**
tom5760@4784
   454
   * \return a const smart pointer to the last packet TLV in this packet.
tom5760@4784
   455
   */
tom5760@4782
   456
  const Ptr<PbbTlv> TlvBack (void) const;
tom5760@4775
   457
tom5760@4784
   458
  /**
tom5760@4784
   459
   * \brief Prepends a packet TLV to the front of this packet.
tom5760@4784
   460
   * \param tlv a smart pointer to the packet TLV to prepend.
tom5760@4784
   461
   */
tom5760@4784
   462
  void TlvPushFront (Ptr<PbbTlv> tlv);
tom5760@4784
   463
tom5760@4784
   464
  /**
tom5760@4784
   465
   * \brief Removes a packet TLV from the front of this packet.
tom5760@4784
   466
   */
tom5760@4775
   467
  void TlvPopFront (void);
tom5760@4784
   468
tom5760@4784
   469
  /**
tom5760@4784
   470
   * \brief Appends a packet TLV to the back of this packet.
tom5760@4784
   471
   * \param tlv a smart pointer to the packet TLV to append.
tom5760@4784
   472
   */
tom5760@4784
   473
  void TlvPushBack (Ptr<PbbTlv> tlv);
tom5760@4784
   474
tom5760@4784
   475
  /**
tom5760@4784
   476
   * \brief Removes a packet TLV from the back of this block.
tom5760@4784
   477
   */
tom5760@4775
   478
  void TlvPopBack (void);
tom5760@4775
   479
tom5760@4784
   480
  /**
tom5760@4784
   481
   * \brief Removes the packet TLV at the specified position.
tom5760@4784
   482
   * \param position an Iterator pointing to the packet TLV to erase.
tom5760@4784
   483
   * \return an iterator pointing to the next packet TLV in the block.
tom5760@4784
   484
   */
tom5760@4775
   485
  TlvIterator Erase (TlvIterator position);
tom5760@4784
   486
tom5760@4784
   487
  /**
tom5760@4784
   488
   * \brief Removes all packet TLVs from [first, last) (includes first, not
tom5760@4784
   489
   *        includes last).
tom5760@4784
   490
   * \param first an Iterator pointing to the first packet TLV to erase
tom5760@4784
   491
   *        (inclusive).
tom5760@4784
   492
   * \param last an Iterator pointing to the element past the last packet TLV
tom5760@4784
   493
   *        to erase.
tom5760@4784
   494
   * \return an iterator pointing to the next packet TLV in the block.
tom5760@4784
   495
   */
tom5760@4775
   496
  TlvIterator Erase (TlvIterator first, TlvIterator last);
tom5760@4784
   497
tom5760@4784
   498
  /**
tom5760@4784
   499
   * \brief Removes all packet TLVs from this packet.
tom5760@4784
   500
   */
tom5760@4775
   501
  void TlvClear (void);
tom5760@4775
   502
tom5760@4775
   503
  /* Manipulating Packet Messages */
tom5760@4775
   504
tom5760@4784
   505
  /**
tom5760@4784
   506
   * \return an iterator to the first message in this packet.
tom5760@4784
   507
   */
tom5760@4775
   508
  MessageIterator MessageBegin (void);
tom5760@4784
   509
tom5760@4784
   510
  /**
tom5760@4784
   511
   * \return a const iterator to the first message in this packet.
tom5760@4784
   512
   */
tom5760@4775
   513
  ConstMessageIterator MessageBegin (void) const;
tom5760@4784
   514
tom5760@4784
   515
  /**
tom5760@4784
   516
   * \return an iterator to the past-the-end element in this message block.
tom5760@4784
   517
   */
tom5760@4775
   518
  MessageIterator MessageEnd (void);
tom5760@4784
   519
tom5760@4784
   520
  /**
tom5760@4784
   521
   * \return a const iterator to the past-the-end element in this message
tom5760@4784
   522
   *         block.
tom5760@4784
   523
   */
tom5760@4775
   524
  ConstMessageIterator MessageEnd (void) const;
tom5760@4775
   525
tom5760@4784
   526
  /**
tom5760@4784
   527
   * \return the number of messages in this packet.
tom5760@4784
   528
   */
tom5760@4775
   529
  int MessageSize (void) const;
tom5760@4784
   530
tom5760@4784
   531
  /**
tom5760@4784
   532
   * \return true if there are no messages in this packet, false otherwise.
tom5760@4784
   533
   */
tom5760@4775
   534
  bool MessageEmpty (void) const;
tom5760@4775
   535
tom5760@4784
   536
  /**
tom5760@4784
   537
   * \return a smart pointer to the first message in this packet.
tom5760@4784
   538
   */
tom5760@4782
   539
  Ptr<PbbMessage> MessageFront (void);
tom5760@4784
   540
tom5760@4784
   541
  /**
tom5760@4784
   542
   * \return a cosnt smart pointer to the first message in this packet.
tom5760@4784
   543
   */
tom5760@4782
   544
  const Ptr<PbbMessage> MessageFront (void) const;
tom5760@4784
   545
tom5760@4784
   546
  /**
tom5760@4784
   547
   * \return a smart pointer to the last message in this packet.
tom5760@4784
   548
   */
tom5760@4782
   549
  Ptr<PbbMessage> MessageBack (void);
tom5760@4784
   550
tom5760@4784
   551
  /**
tom5760@4784
   552
   * \return a cosnt smart pointer to the last message in this packet.
tom5760@4784
   553
   */
tom5760@4782
   554
  const Ptr<PbbMessage> MessageBack (void) const;
tom5760@4775
   555
tom5760@4784
   556
  /**
tom5760@4784
   557
   * \brief Prepends a message to the front of this packet.
tom5760@4784
   558
   * \param message a smart pointer to the message to prepend.
tom5760@4784
   559
   */
tom5760@4782
   560
  void MessagePushFront (Ptr<PbbMessage> message);
tom5760@4784
   561
tom5760@4784
   562
  /**
tom5760@4784
   563
   * \brief Removes a message from the front of this packet.
tom5760@4784
   564
   */
tom5760@4775
   565
  void MessagePopFront (void);
tom5760@4784
   566
tom5760@4784
   567
  /**
tom5760@4784
   568
   * \brief Appends a message to the back of this packet.
tom5760@4784
   569
   * \param message a smart pointer to the message to append.
tom5760@4784
   570
   */
tom5760@4782
   571
  void MessagePushBack (Ptr<PbbMessage> message);
tom5760@4784
   572
tom5760@4784
   573
  /**
tom5760@4784
   574
   * \brief Removes a message from the back of this packet.
tom5760@4784
   575
   */
tom5760@4775
   576
  void MessagePopBack (void);
tom5760@4775
   577
tom5760@4784
   578
  /**
tom5760@4784
   579
   * \brief Removes the message at the specified position.
tom5760@4784
   580
   * \param position an Iterator pointing to the message to erase.
tom5760@4784
   581
   * \return an iterator pointing to the next message in the packet.
tom5760@4784
   582
   */
tom5760@4775
   583
  MessageIterator Erase (MessageIterator position);
tom5760@4784
   584
tom5760@4784
   585
  /**
tom5760@4784
   586
   * \brief Removes all messages from [first, last) (includes first, not
tom5760@4784
   587
   *        includes last).
tom5760@4784
   588
   * \param first an Iterator pointing to the first message to erase (inclusive).
tom5760@4784
   589
   * \param last an Iterator pointing to the element past the last message to erase.
tom5760@4784
   590
   * \return an iterator pointing to the next message in the block.
tom5760@4784
   591
   */
tom5760@4775
   592
  MessageIterator Erase (MessageIterator first, MessageIterator last);
tom5760@4784
   593
tom5760@4784
   594
  /**
tom5760@4784
   595
   * \brief Removes all messages from this packet.
tom5760@4784
   596
   */
tom5760@4775
   597
  void MessageClear (void);
tom5760@4775
   598
tom5760@4775
   599
  /* Methods implemented by all headers */
tom5760@4775
   600
  static TypeId GetTypeId (void);
tom5760@4775
   601
  virtual TypeId GetInstanceTypeId (void) const;
tom5760@4784
   602
tom5760@4784
   603
  /**
tom5760@4784
   604
   * \return The size (in bytes) needed to serialize this packet.
tom5760@4784
   605
   */
tom5760@4775
   606
  virtual uint32_t GetSerializedSize (void) const;
tom5760@4784
   607
tom5760@4784
   608
  /**
tom5760@4784
   609
   * \brief Serializes this packet into the specified buffer.
tom5760@4784
   610
   * \param start a reference to the point in a buffer to begin serializing.
tom5760@4784
   611
   */
tom5760@4775
   612
  virtual void Serialize (Buffer::Iterator start) const;
tom5760@4784
   613
tom5760@4779
   614
  /**
tom5760@4784
   615
   * \brief Deserializes a packet from the specified buffer.
vincent@5227
   616
   * \param start start offset
tom5760@4784
   617
   * \return the number of bytes deserialized
tom5760@4779
   618
   *
tom5760@4779
   619
   * If this returns a number smaller than the total number of bytes in the
tom5760@4779
   620
   * buffer, there was an error.
tom5760@4779
   621
   */
tom5760@4775
   622
  virtual uint32_t Deserialize (Buffer::Iterator start);
tom5760@4784
   623
tom5760@4784
   624
  /**
tom5760@4784
   625
   * \brief Pretty-prints the contents of this block.
tom5760@4784
   626
   * \param os a stream object to print to.
tom5760@4784
   627
   */
tom5760@4775
   628
  virtual void Print (std::ostream &os) const;
tom5760@4775
   629
tom5760@4782
   630
  bool operator== (const PbbPacket &other) const;
tom5760@4782
   631
  bool operator!= (const PbbPacket &other) const;
tom5760@4775
   632
tom5760@4775
   633
protected:
tom5760@4775
   634
  void SerializePacketTlv (Buffer::Iterator &start) const;
tom5760@4775
   635
tom5760@4775
   636
private:
tom5760@4782
   637
  PbbTlvBlock m_tlvList;
tom5760@4782
   638
  std::list< Ptr<PbbMessage> > m_messageList;
tom5760@4775
   639
tom5760@4775
   640
  uint8_t m_version;
tom5760@4775
   641
tom5760@4775
   642
  bool m_hasseqnum;
tom5760@4775
   643
  uint16_t m_seqnum;
tom5760@4775
   644
};
tom5760@4775
   645
tom5760@4779
   646
/**
tom5760@4782
   647
 * \brief A message within a PbbPacket packet.
tom5760@4779
   648
 *
tom5760@4787
   649
 * There may be any number of messages in one packet packet.  This is a pure
tom5760@4788
   650
 * virtual base class, when creating a message, you should instantiate either
tom5760@4787
   651
 * PbbMessageIpv4 or PbbMessageIpv6.
tom5760@4779
   652
 */
mathieu@5505
   653
class PbbMessage : public SimpleRefCount<PbbMessage>
tom5760@4775
   654
{
tom5760@4775
   655
public:
tom5760@4782
   656
  typedef std::list< Ptr<PbbTlv> >::iterator TlvIterator;
tom5760@4782
   657
  typedef std::list< Ptr<PbbTlv> >::const_iterator ConstTlvIterator;
tom5760@4782
   658
  typedef std::list< Ptr<PbbAddressBlock> >::iterator AddressBlockIterator;
tom5760@4782
   659
  typedef std::list< Ptr<PbbAddressBlock> >::const_iterator ConstAddressBlockIterator;
tom5760@4775
   660
craigdo@4790
   661
  PbbMessage ();
craigdo@4790
   662
  virtual ~PbbMessage ();
tom5760@4775
   663
tom5760@4784
   664
  /**
tom5760@4784
   665
   * \brief Sets the type for this message.
tom5760@4784
   666
   * \param type the type to set.
tom5760@4784
   667
   */
tom5760@4775
   668
  void SetType (uint8_t type);
tom5760@4784
   669
tom5760@4784
   670
  /**
tom5760@4784
   671
   * \return the type assigned to this packet
tom5760@4784
   672
   */
tom5760@4775
   673
  uint8_t GetType (void) const;
tom5760@4775
   674
tom5760@4784
   675
  /**
tom5760@4784
   676
   * \brief Sets the address for the node that created this packet.
tom5760@4784
   677
   * \param address the originator address.
tom5760@4784
   678
   */
tom5760@4775
   679
  void SetOriginatorAddress (Address address);
tom5760@4784
   680
tom5760@4779
   681
  /**
tom5760@4784
   682
   * \return the address of the node that created this packet.
tom5760@4779
   683
   *
tom5760@4779
   684
   * Calling this while HasOriginatorAddress is False is undefined.  Make sure
tom5760@4780
   685
   * you check it first.  This will be checked by an assert in debug builds.
tom5760@4779
   686
   */
tom5760@4776
   687
  Address GetOriginatorAddress (void) const;
tom5760@4784
   688
tom5760@4784
   689
  /**
tom5760@4784
   690
   * \brief Tests whether or not this message has an originator address.
tom5760@4784
   691
   * \return true if this message has an originator address, false otherwise.
tom5760@4784
   692
   */
tom5760@4775
   693
  bool HasOriginatorAddress (void) const;
tom5760@4775
   694
tom5760@4784
   695
  /**
tom5760@4784
   696
   * \brief Sets the maximum number of hops this message should travel
tom5760@4784
   697
   * \param hoplimit the limit to set
tom5760@4784
   698
   */
tom5760@4775
   699
  void SetHopLimit (uint8_t hoplimit);
tom5760@4784
   700
tom5760@4779
   701
  /**
tom5760@4784
   702
   * \return the maximum number of hops this message should travel.
tom5760@4779
   703
   *
tom5760@4779
   704
   * Calling this while HasHopLimit is False is undefined.  Make sure you check
tom5760@4780
   705
   * it first.  This will be checked by an assert in debug builds.
tom5760@4779
   706
   */
tom5760@4776
   707
  uint8_t GetHopLimit (void) const;
tom5760@4784
   708
tom5760@4784
   709
  /**
tom5760@4784
   710
   * \brief Tests whether or not this message has a hop limit.
tom5760@4784
   711
   * \return true if this message has a hop limit, false otherwise.
tom5760@4784
   712
   *
tom5760@4784
   713
   * If this is set, messages should not hop further than this limit.
tom5760@4784
   714
   */
tom5760@4775
   715
  bool HasHopLimit (void) const;
tom5760@4775
   716
tom5760@4784
   717
  /**
tom5760@4784
   718
   * \brief Sets the current number of hops this message has traveled.
tom5760@4784
   719
   * \param hopcount the current number of hops
tom5760@4784
   720
   */
tom5760@4775
   721
  void SetHopCount (uint8_t hopcount);
tom5760@4784
   722
tom5760@4779
   723
  /**
tom5760@4784
   724
   * \return the current number of hops this message has traveled.
tom5760@4779
   725
   *
tom5760@4779
   726
   * Calling this while HasHopCount is False is undefined.  Make sure you check
tom5760@4780
   727
   * it first.  This will be checked by an assert in debug builds.
tom5760@4779
   728
   */
tom5760@4776
   729
  uint8_t GetHopCount (void) const;
tom5760@4784
   730
tom5760@4784
   731
  /**
tom5760@4784
   732
   * \brief Tests whether or not this message has a hop count.
tom5760@4784
   733
   * \return true if this message has a hop limit, false otherwise.
tom5760@4784
   734
   */
tom5760@4775
   735
  bool HasHopCount (void) const;
tom5760@4775
   736
tom5760@4784
   737
  /**
tom5760@4784
   738
   * \brief Sets the sequence number of this message.
tom5760@4784
   739
   * \param seqnum the sequence number to set.
tom5760@4784
   740
   */
tom5760@4775
   741
  void SetSequenceNumber (uint16_t seqnum);
tom5760@4784
   742
tom5760@4779
   743
  /**
tom5760@4784
   744
   * \return the sequence number of this message.
tom5760@4779
   745
   *
tom5760@4779
   746
   * Calling this while HasSequenceNumber is False is undefined.  Make sure you
tom5760@4780
   747
   * check it first.  This will be checked by an assert in debug builds.
tom5760@4779
   748
   */
tom5760@4776
   749
  uint16_t GetSequenceNumber (void) const;
tom5760@4784
   750
tom5760@4784
   751
  /**
tom5760@4784
   752
   * \brief Tests whether or not this message has a sequence number.
tom5760@4784
   753
   * \return true if this message has a sequence number, false otherwise.
tom5760@4784
   754
   */
tom5760@4775
   755
  bool HasSequenceNumber (void) const;
tom5760@4775
   756
tom5760@4782
   757
  /* Manipulating PbbMessage TLVs */
tom5760@4775
   758
tom5760@4784
   759
  /**
tom5760@4784
   760
   * \return an iterator to the first message TLV in this message.
tom5760@4784
   761
   */
tom5760@4775
   762
  TlvIterator TlvBegin ();
tom5760@4784
   763
tom5760@4784
   764
  /**
tom5760@4784
   765
   * \return a const iterator to the first message TLV in this message.
tom5760@4784
   766
   */
tom5760@4775
   767
  ConstTlvIterator TlvBegin () const;
tom5760@4784
   768
tom5760@4784
   769
  /**
tom5760@4784
   770
   * \return an iterator to the past-the-end message TLV element in this
tom5760@4784
   771
   *         message.
tom5760@4784
   772
   */
tom5760@4775
   773
  TlvIterator TlvEnd ();
tom5760@4784
   774
tom5760@4784
   775
  /**
tom5760@4784
   776
   * \return a const iterator to the past-the-end message TLV element in this
tom5760@4784
   777
   *         message.
tom5760@4784
   778
   */
tom5760@4775
   779
  ConstTlvIterator TlvEnd () const;
tom5760@4775
   780
tom5760@4784
   781
  /**
tom5760@4784
   782
   * \return the number of message TLVs in this message.
tom5760@4784
   783
   */
tom5760@4775
   784
  int TlvSize (void) const;
tom5760@4784
   785
tom5760@4784
   786
  /**
tom5760@4784
   787
   * \return true if there are no message TLVs in this message, false otherwise.
tom5760@4784
   788
   */
tom5760@4775
   789
  bool TlvEmpty (void) const;
tom5760@4775
   790
tom5760@4784
   791
  /**
tom5760@4784
   792
   * \return a smart pointer to the first message TLV in this message.
tom5760@4784
   793
   */
tom5760@4782
   794
  Ptr<PbbTlv> TlvFront (void);
tom5760@4784
   795
tom5760@4784
   796
  /**
tom5760@4784
   797
   * \return a const smart pointer to the first message TLV in this message.
tom5760@4784
   798
   */
tom5760@4782
   799
  const Ptr<PbbTlv> TlvFront (void) const;
tom5760@4784
   800
tom5760@4784
   801
  /**
tom5760@4784
   802
   * \return a smart pointer to the last message TLV in this message.
tom5760@4784
   803
   */
tom5760@4782
   804
  Ptr<PbbTlv> TlvBack (void);
tom5760@4784
   805
tom5760@4784
   806
  /**
tom5760@4784
   807
   * \return a const smart pointer to the last message TLV in this message.
tom5760@4784
   808
   */
tom5760@4782
   809
  const Ptr<PbbTlv> TlvBack (void) const;
tom5760@4775
   810
tom5760@4784
   811
  /**
tom5760@4784
   812
   * \brief Prepends a message TLV to the front of this message.
tom5760@4784
   813
   * \param tlv a smart pointer to the message TLV to prepend.
tom5760@4784
   814
   */
tom5760@4782
   815
  void TlvPushFront (Ptr<PbbTlv> tlv);
tom5760@4784
   816
tom5760@4784
   817
  /**
tom5760@4784
   818
   * \brief Removes a message TLV from the front of this message.
tom5760@4784
   819
   */
tom5760@4775
   820
  void TlvPopFront (void);
tom5760@4784
   821
tom5760@4784
   822
  /**
tom5760@4784
   823
   * \brief Appends a message TLV to the back of this message.
tom5760@4784
   824
   * \param tlv a smart pointer to the message TLV to append.
tom5760@4784
   825
   */
tom5760@4782
   826
  void TlvPushBack (Ptr<PbbTlv> tlv);
tom5760@4784
   827
tom5760@4784
   828
  /**
tom5760@4784
   829
   * \brief Removes a message TLV from the back of this message.
tom5760@4784
   830
   */
tom5760@4775
   831
  void TlvPopBack (void);
tom5760@4775
   832
tom5760@4784
   833
  /**
tom5760@4784
   834
   * \brief Removes the message TLV at the specified position.
tom5760@4784
   835
   * \param position an Iterator pointing to the message TLV to erase.
tom5760@4784
   836
   * \return an iterator pointing to the next TLV in the block.
tom5760@4784
   837
   */
tom5760@4775
   838
  TlvIterator TlvErase (TlvIterator position);
tom5760@4784
   839
tom5760@4784
   840
  /**
tom5760@4784
   841
   * \brief Removes all message TLVs from [first, last) (includes first, not
tom5760@4784
   842
   *        includes last).
tom5760@4784
   843
   * \param first an Iterator pointing to the first message TLV to erase
tom5760@4784
   844
   *        (inclusive).
tom5760@4784
   845
   * \param last an Iterator pointing to the element past the last message TLV
tom5760@4784
   846
   *        to erase.
tom5760@4784
   847
   * \return an iterator pointing to the next message TLV in the message.
tom5760@4784
   848
   */
tom5760@4775
   849
  TlvIterator TlvErase (TlvIterator first, TlvIterator last);
tom5760@4784
   850
tom5760@4784
   851
  /**
tom5760@4784
   852
   * \brief Removes all message TLVs from this block.
tom5760@4784
   853
   */
tom5760@4775
   854
  void TlvClear (void);
tom5760@4775
   855
tom5760@4775
   856
  /* Manipulating Address Block and Address TLV pairs */
tom5760@4775
   857
tom5760@4784
   858
  /**
tom5760@4784
   859
   * \return an iterator to the first address block in this message.
tom5760@4784
   860
   */
tom5760@4775
   861
  AddressBlockIterator AddressBlockBegin ();
tom5760@4784
   862
tom5760@4784
   863
  /**
tom5760@4784
   864
   * \return a const iterator to the first address block in this message.
tom5760@4784
   865
   */
tom5760@4775
   866
  ConstAddressBlockIterator AddressBlockBegin () const;
tom5760@4784
   867
tom5760@4784
   868
  /**
tom5760@4784
   869
   * \return an iterator to the past-the-end address block element in this
tom5760@4784
   870
   *         message.
tom5760@4784
   871
   */
tom5760@4775
   872
  AddressBlockIterator AddressBlockEnd ();
tom5760@4784
   873
tom5760@4784
   874
  /**
tom5760@4784
   875
   * \return a const iterator to the past-the-end address block element in this
tom5760@4784
   876
   *         message.
tom5760@4784
   877
   */
tom5760@4775
   878
  ConstAddressBlockIterator AddressBlockEnd () const;
tom5760@4775
   879
tom5760@4784
   880
  /**
tom5760@4784
   881
   * \return the number of address blocks in this message.
tom5760@4784
   882
   */
tom5760@4775
   883
  int AddressBlockSize (void) const;
tom5760@4784
   884
tom5760@4784
   885
  /**
tom5760@4784
   886
   * \return true if there are no address blocks in this message, false
tom5760@4784
   887
   *         otherwise.
tom5760@4784
   888
   */
tom5760@4775
   889
  bool AddressBlockEmpty (void) const;
tom5760@4775
   890
tom5760@4784
   891
  /**
tom5760@4784
   892
   * \return a smart pointer to the first address block in this message.
tom5760@4784
   893
   */
tom5760@4782
   894
  Ptr<PbbAddressBlock> AddressBlockFront (void);
tom5760@4784
   895
tom5760@4784
   896
  /**
tom5760@4784
   897
   * \return a const smart pointer to the first address block in this message.
tom5760@4784
   898
   */
tom5760@4782
   899
  const Ptr<PbbAddressBlock> AddressBlockFront (void) const;
tom5760@4784
   900
tom5760@4784
   901
  /**
tom5760@4784
   902
   * \return a smart pointer to the last address block in this message.
tom5760@4784
   903
   */
tom5760@4782
   904
  Ptr<PbbAddressBlock> AddressBlockBack (void);
tom5760@4784
   905
tom5760@4784
   906
  /**
tom5760@4784
   907
   * \return a const smart pointer to the last address block in this message.
tom5760@4784
   908
   */
tom5760@4782
   909
  const Ptr<PbbAddressBlock> AddressBlockBack (void) const;
tom5760@4775
   910
tom5760@4784
   911
  /**
tom5760@4784
   912
   * \brief Prepends an address block to the front of this message.
tom5760@4784
   913
   * \param block a smart pointer to the address block to prepend.
tom5760@4784
   914
   */
tom5760@4782
   915
  void AddressBlockPushFront (Ptr<PbbAddressBlock> block);
tom5760@4784
   916
tom5760@4784
   917
  /**
tom5760@4784
   918
   * \brief Removes an address block from the front of this message.
tom5760@4784
   919
   */
tom5760@4775
   920
  void AddressBlockPopFront (void);
tom5760@4784
   921
tom5760@4784
   922
  /**
tom5760@4784
   923
   * \brief Appends an address block to the front of this message.
tom5760@4784
   924
   * \param block a smart pointer to the address block to append.
tom5760@4784
   925
   */
tom5760@4782
   926
  void AddressBlockPushBack (Ptr<PbbAddressBlock> block);
tom5760@4784
   927
tom5760@4784
   928
  /**
tom5760@4784
   929
   * \brief Removes an address block from the back of this message.
tom5760@4784
   930
   */
tom5760@4775
   931
  void AddressBlockPopBack (void);
tom5760@4775
   932
tom5760@4784
   933
  /**
tom5760@4784
   934
   * \brief Removes the address block at the specified position.
tom5760@4784
   935
   * \param position an Iterator pointing to the address block to erase.
tom5760@4784
   936
   * \return an iterator pointing to the next address block in the message.
tom5760@4784
   937
   */
tom5760@4775
   938
  AddressBlockIterator AddressBlockErase (AddressBlockIterator position);
tom5760@4784
   939
tom5760@4784
   940
  /**
tom5760@4784
   941
   * \brief Removes all address blocks from [first, last) (includes first, not
tom5760@4784
   942
   *        includes last).
tom5760@4784
   943
   * \param first an Iterator pointing to the first address block to erase
tom5760@4784
   944
   *        (inclusive).
tom5760@4784
   945
   * \param last an Iterator pointing to the element past the last address
tom5760@4784
   946
   *        block to erase.
tom5760@4784
   947
   * \return an iterator pointing to the next address block in the message.
tom5760@4784
   948
   */
tom5760@4775
   949
  AddressBlockIterator AddressBlockErase (AddressBlockIterator first,
tom5760@4775
   950
      AddressBlockIterator last);
tom5760@4784
   951
tom5760@4784
   952
  /**
tom5760@4784
   953
   * \brief Removes all address blocks from this message.
tom5760@4784
   954
   */
tom5760@4775
   955
  void AddressBlockClear (void);
tom5760@4775
   956
tom5760@4784
   957
  /**
tom5760@4784
   958
   * \brief Deserializes a message, returning the correct object depending on
tom5760@4784
   959
   *        whether it is an IPv4 message or an IPv6 message.
tom5760@4784
   960
   * \param start a reference to the point in a buffer to begin deserializing.
tom5760@4784
   961
   * \return A pointer to the deserialized message, or 0 on error.
tom5760@4784
   962
   *
tom5760@4784
   963
   * Users should not need to call this.  Blocks will be deserialized by their
tom5760@4784
   964
   * containing packet.
tom5760@4784
   965
   */
tom5760@4782
   966
  static Ptr<PbbMessage> DeserializeMessage (Buffer::Iterator &start);
tom5760@4784
   967
tom5760@4784
   968
  /**
tom5760@4784
   969
   * \return The size (in bytes) needed to serialize this message.
tom5760@4784
   970
   */
tom5760@4775
   971
  uint32_t GetSerializedSize (void) const;
tom5760@4784
   972
tom5760@4784
   973
  /**
tom5760@4784
   974
   * \brief Serializes this message into the specified buffer.
tom5760@4784
   975
   * \param start a reference to the point in a buffer to begin serializing.
tom5760@4784
   976
   *
tom5760@4784
   977
   * Users should not need to call this.  Blocks will be deserialized by their
tom5760@4784
   978
   * containing packet.
tom5760@4784
   979
   */
tom5760@4775
   980
  void Serialize (Buffer::Iterator &start) const;
tom5760@4784
   981
tom5760@4784
   982
  /**
tom5760@4784
   983
   * \brief Deserializes a message from the specified buffer.
tom5760@4784
   984
   * \param start a reference to the point in a buffer to begin deserializing.
tom5760@4784
   985
   *
tom5760@4784
   986
   * Users should not need to call this.  Blocks will be deserialized by their
tom5760@4784
   987
   * containing packet.
tom5760@4784
   988
   */
tom5760@4775
   989
  void Deserialize (Buffer::Iterator &start);
tom5760@4784
   990
tom5760@4784
   991
  /**
tom5760@4784
   992
   * \brief Pretty-prints the contents of this message.
tom5760@4784
   993
   * \param os a stream object to print to.
tom5760@4784
   994
   */
tom5760@4775
   995
  void Print (std::ostream &os) const;
tom5760@4784
   996
tom5760@4784
   997
  /**
tom5760@4784
   998
   * \brief Pretty-prints the contents of this message, with specified
tom5760@4784
   999
   *        indentation.
tom5760@4784
  1000
   * \param os a stream object to print to.
tom5760@4784
  1001
   * \param level level of indentation.
tom5760@4784
  1002
   *
tom5760@4784
  1003
   * This probably never needs to be called by users.  This is used when
tom5760@4784
  1004
   * recursively printing sub-objects.
tom5760@4784
  1005
   */
tom5760@4775
  1006
  void Print (std::ostream &os, int level) const;
tom5760@4775
  1007
tom5760@4782
  1008
  bool operator== (const PbbMessage &other) const;
tom5760@4782
  1009
  bool operator!= (const PbbMessage &other) const;
tom5760@4775
  1010
tom5760@4775
  1011
protected:
tom5760@4782
  1012
  /* PbbMessage size in bytes - 1.
tom5760@4775
  1013
   *
tom5760@4775
  1014
   * IPv4 = 4 - 1 = 3, IPv6 = 16 - 1 = 15
tom5760@4775
  1015
   */
tom5760@4783
  1016
  virtual PbbAddressLength GetAddressLength (void) const = 0;
tom5760@4775
  1017
tom5760@4775
  1018
  virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const = 0;
tom5760@4775
  1019
  virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const = 0;
tom5760@4775
  1020
  virtual void PrintOriginatorAddress (std::ostream &os) const = 0;
tom5760@4775
  1021
tom5760@4782
  1022
  virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const = 0;
tom5760@4775
  1023
tom5760@4775
  1024
private:
tom5760@4782
  1025
  PbbTlvBlock m_tlvList;
tom5760@4782
  1026
  std::list< Ptr<PbbAddressBlock> > m_addressBlockList;
tom5760@4775
  1027
tom5760@4775
  1028
  uint8_t m_type;
tom5760@4783
  1029
  PbbAddressLength m_addrSize;
tom5760@4775
  1030
tom5760@4775
  1031
  bool m_hasOriginatorAddress;
tom5760@4775
  1032
  Address m_originatorAddress;
tom5760@4775
  1033
tom5760@4775
  1034
  bool m_hasHopLimit;
tom5760@4775
  1035
  uint8_t m_hopLimit;
tom5760@4775
  1036
tom5760@4775
  1037
  bool m_hasHopCount;
tom5760@4775
  1038
  uint8_t m_hopCount;
tom5760@4775
  1039
tom5760@4775
  1040
  bool m_hasSequenceNumber;
tom5760@4775
  1041
  uint16_t m_sequenceNumber;
tom5760@4775
  1042
};
tom5760@4775
  1043
tom5760@4779
  1044
/**
tom5760@4782
  1045
 * \brief Concrete IPv4 specific PbbMessage.
tom5760@4779
  1046
 *
tom5760@4779
  1047
 * This message will only contain IPv4 addresses.
tom5760@4779
  1048
 */
tom5760@4782
  1049
class PbbMessageIpv4 : public PbbMessage {
craigdo@4790
  1050
public:
craigdo@4790
  1051
  PbbMessageIpv4 ();
craigdo@4790
  1052
  virtual ~PbbMessageIpv4 ();
craigdo@4790
  1053
tom5760@4775
  1054
protected:
tom5760@4783
  1055
  virtual PbbAddressLength GetAddressLength (void) const;
tom5760@4775
  1056
tom5760@4775
  1057
  virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const;
tom5760@4775
  1058
  virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const;
tom5760@4775
  1059
  virtual void PrintOriginatorAddress (std::ostream &os) const;
tom5760@4775
  1060
tom5760@4782
  1061
  virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const;
tom5760@4775
  1062
};
tom5760@4775
  1063
tom5760@4779
  1064
/**
tom5760@4782
  1065
 * \brief Concrete IPv6 specific PbbMessage class.
tom5760@4779
  1066
 *
tom5760@4779
  1067
 * This message will only contain IPv6 addresses.
tom5760@4779
  1068
 */
tom5760@4782
  1069
class PbbMessageIpv6 : public PbbMessage {
craigdo@4790
  1070
public:
craigdo@4790
  1071
  PbbMessageIpv6 ();
craigdo@4790
  1072
  virtual ~PbbMessageIpv6 ();
craigdo@4790
  1073
tom5760@4775
  1074
protected:
tom5760@4783
  1075
  virtual PbbAddressLength GetAddressLength (void) const;
tom5760@4775
  1076
tom5760@4775
  1077
  virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const;
tom5760@4775
  1078
  virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const;
tom5760@4775
  1079
  virtual void PrintOriginatorAddress (std::ostream &os) const;
tom5760@4775
  1080
tom5760@4782
  1081
  virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const;
tom5760@4775
  1082
};
tom5760@4775
  1083
tom5760@4779
  1084
/**
tom5760@4779
  1085
 * \brief An Address Block and its associated Address TLV Blocks.
tom5760@4779
  1086
 *
tom5760@4787
  1087
 * This is a pure virtual base class, when creating address blocks, you should
tom5760@4787
  1088
 * instantiate either PbbAddressBlockIpv4 or PbbAddressBlockIpv6.
tom5760@4779
  1089
 */
mathieu@5505
  1090
class PbbAddressBlock : public SimpleRefCount<PbbAddressBlock>
tom5760@4775
  1091
{
tom5760@4775
  1092
public:
tom5760@4775
  1093
  typedef std::list< Address >::iterator AddressIterator;
tom5760@4775
  1094
  typedef std::list< Address >::const_iterator ConstAddressIterator;
tom5760@4775
  1095
tom5760@4775
  1096
  typedef std::list<uint8_t>::iterator PrefixIterator;
tom5760@4775
  1097
  typedef std::list<uint8_t>::const_iterator ConstPrefixIterator;
tom5760@4775
  1098
tom5760@4782
  1099
  typedef PbbAddressTlvBlock::Iterator TlvIterator;
tom5760@4782
  1100
  typedef PbbAddressTlvBlock::ConstIterator ConstTlvIterator;
tom5760@4775
  1101
craigdo@4790
  1102
  PbbAddressBlock ();
craigdo@4790
  1103
  virtual ~PbbAddressBlock ();
tom5760@4775
  1104
tom5760@4775
  1105
  /* Manipulating the address block */
tom5760@4775
  1106
tom5760@4784
  1107
  /**
tom5760@4784
  1108
   * \return an iterator to the first address in this block.
tom5760@4784
  1109
   */
tom5760@4775
  1110
  AddressIterator AddressBegin (void);
tom5760@4784
  1111
tom5760@4784
  1112
  /**
tom5760@4784
  1113
   * \return a const iterator to the first address in this block.
tom5760@4784
  1114
   */
tom5760@4775
  1115
  ConstAddressIterator AddressBegin (void) const;
tom5760@4784
  1116
tom5760@4784
  1117
  /**
tom5760@4784
  1118
   * \return an iterator to the last address in this block.
tom5760@4784
  1119
   */
tom5760@4775
  1120
  AddressIterator AddressEnd (void);
tom5760@4784
  1121
tom5760@4784
  1122
  /**
tom5760@4784
  1123
   * \return a const iterator to the last address in this block.
tom5760@4784
  1124
   */
tom5760@4775
  1125
  ConstAddressIterator AddressEnd (void) const;
tom5760@4775
  1126
tom5760@4784
  1127
  /**
tom5760@4784
  1128
   * \return the number of addresses in this block.
tom5760@4784
  1129
   */
tom5760@4775
  1130
  int AddressSize (void) const;
tom5760@4784
  1131
tom5760@4784
  1132
  /**
tom5760@4784
  1133
   * \return true if there are no addresses in this block, false otherwise.
tom5760@4784
  1134
   */
tom5760@4775
  1135
  bool AddressEmpty (void) const;
tom5760@4775
  1136
tom5760@4784
  1137
  /**
tom5760@4784
  1138
   * \return the first address in this block.
tom5760@4784
  1139
   */
tom5760@4775
  1140
  Address AddressFront (void) const;
tom5760@4784
  1141
tom5760@4784
  1142
  /**
tom5760@4784
  1143
   * \return the last address in this block.
tom5760@4784
  1144
   */
tom5760@4775
  1145
  Address AddressBack (void) const;
tom5760@4775
  1146
tom5760@4784
  1147
  /**
tom5760@4784
  1148
   * \brief Prepends an address to the front of this block.
tom5760@4784
  1149
   * \param address the address to prepend.
tom5760@4784
  1150
   */
tom5760@4775
  1151
  void AddressPushFront (Address address);
tom5760@4784
  1152
tom5760@4784
  1153
  /**
tom5760@4784
  1154
   * \brief Removes an address from the front of this block.
tom5760@4784
  1155
   */
tom5760@4775
  1156
  void AddressPopFront (void);
tom5760@4775
  1157
tom5760@4784
  1158
  /**
tom5760@4784
  1159
   * \brief Appends an address to the back of this block.
tom5760@4784
  1160
   * \param address the address to append.
tom5760@4784
  1161
   */
tom5760@4775
  1162
  void AddressPushBack (Address address);
tom5760@4784
  1163
tom5760@4784
  1164
  /**
tom5760@4784
  1165
   * \brief Removes an address from the back of this block.
tom5760@4784
  1166
   */
tom5760@4775
  1167
  void AddressPopBack (void);
tom5760@4775
  1168
tom5760@4784
  1169
  /**
tom5760@4784
  1170
   * \brief Inserts an address at the specified position in this block.
tom5760@4784
  1171
   * \param position an Iterator pointing to the position in this block to
tom5760@4784
  1172
   *        insert the address.
tom5760@4784
  1173
   * \param value the address to insert.
tom5760@4784
  1174
   * \return An iterator pointing to the newly inserted address.
tom5760@4784
  1175
   */
tom5760@4775
  1176
  AddressIterator AddressInsert (AddressIterator position,
tom5760@4775
  1177
      const Address value);
tom5760@4775
  1178
tom5760@4784
  1179
  /**
tom5760@4784
  1180
   * \brief Removes the address at the specified position.
tom5760@4784
  1181
   * \param position an Iterator pointing to the address to erase.
tom5760@4784
  1182
   * \return an iterator pointing to the next address in the block.
tom5760@4784
  1183
   */
tom5760@4775
  1184
  AddressIterator AddressErase (AddressIterator position);
tom5760@4784
  1185
tom5760@4784
  1186
  /**
tom5760@4784
  1187
   * \brief Removes all addresses from [first, last) (includes first, not
tom5760@4784
  1188
   *        includes last).
tom5760@4784
  1189
   * \param first an Iterator pointing to the first address to erase
tom5760@4784
  1190
   *        (inclusive).
tom5760@4784
  1191
   * \param last an Iterator pointing to the element past the last address to
tom5760@4784
  1192
   *        erase.
tom5760@4784
  1193
   * \return an iterator pointing to the next address in the block.
tom5760@4784
  1194
   */
tom5760@4775
  1195
  AddressIterator AddressErase (AddressIterator first, AddressIterator last);
tom5760@4775
  1196
tom5760@4784
  1197
  /**
tom5760@4784
  1198
   * \brief Removes all addresses from this block.
tom5760@4784
  1199
   */
tom5760@4775
  1200
  void AddressClear (void);
tom5760@4775
  1201
tom5760@4775
  1202
  /* Prefix methods */
tom5760@4784
  1203
tom5760@4784
  1204
  /**
tom5760@4784
  1205
   * \return an iterator to the first prefix in this block.
tom5760@4784
  1206
   */
tom5760@4775
  1207
  PrefixIterator PrefixBegin (void);
tom5760@4784
  1208
tom5760@4784
  1209
  /**
tom5760@4784
  1210
   * \return a const iterator to the first prefix in this block.
tom5760@4784
  1211
   */
tom5760@4775
  1212
  ConstPrefixIterator PrefixBegin (void) const;
tom5760@4784
  1213
tom5760@4784
  1214
  /**
tom5760@4784
  1215
   * \return an iterator to the last prefix in this block.
tom5760@4784
  1216
   */
tom5760@4775
  1217
  PrefixIterator PrefixEnd (void);
tom5760@4784
  1218
tom5760@4784
  1219
  /**
tom5760@4784
  1220
   * \return a const iterator to the last prefix in this block.
tom5760@4784
  1221
   */
tom5760@4775
  1222
  ConstPrefixIterator PrefixEnd (void) const;
tom5760@4775
  1223
tom5760@4784
  1224
  /**
tom5760@4784
  1225
   * \return the number of prefixes in this block.
tom5760@4784
  1226
   */
tom5760@4775
  1227
  int PrefixSize (void) const;
tom5760@4784
  1228
tom5760@4784
  1229
  /**
tom5760@4784
  1230
   * \return true if there are no prefixes in this block, false otherwise.
tom5760@4784
  1231
   */
tom5760@4775
  1232
  bool PrefixEmpty (void) const;
tom5760@4775
  1233
tom5760@4784
  1234
  /**
tom5760@4784
  1235
   * \return the first prefix in this block.
tom5760@4784
  1236
   */
tom5760@4775
  1237
  uint8_t PrefixFront (void) const;
tom5760@4784
  1238
tom5760@4784
  1239
  /**
tom5760@4784
  1240
   * \return the last prefix in this block.
tom5760@4784
  1241
   */
tom5760@4775
  1242
  uint8_t PrefixBack (void) const;
tom5760@4775
  1243
tom5760@4784
  1244
  /**
tom5760@4784
  1245
   * \brief Prepends a prefix to the front of this block.
tom5760@4784
  1246
   * \param prefix the prefix to prepend.
tom5760@4784
  1247
   */
tom5760@4775
  1248
  void PrefixPushFront (uint8_t prefix);
tom5760@4784
  1249
tom5760@4784
  1250
  /**
tom5760@4784
  1251
   * \brief Removes a prefix from the front of this block.
tom5760@4784
  1252
   */
tom5760@4775
  1253
  void PrefixPopFront (void);
tom5760@4775
  1254
tom5760@4784
  1255
  /**
tom5760@4784
  1256
   * \brief Appends a prefix to the back of this block.
tom5760@4784
  1257
   * \param prefix the prefix to append.
tom5760@4784
  1258
   */
tom5760@4775
  1259
  void PrefixPushBack (uint8_t prefix);
tom5760@4784
  1260
tom5760@4784
  1261
  /**
tom5760@4784
  1262
   * \brief Removes a prefix from the back of this block.
tom5760@4784
  1263
   */
tom5760@4775
  1264
  void PrefixPopBack (void);
tom5760@4775
  1265
tom5760@4784
  1266
  /**
tom5760@4784
  1267
   * \brief Inserts a prefix at the specified position in this block.
tom5760@4784
  1268
   * \param position an Iterator pointing to the position in this block to
tom5760@4784
  1269
   *        insert the prefix.
tom5760@4784
  1270
   * \param value the prefix to insert.
tom5760@4784
  1271
   * \return An iterator pointing to the newly inserted prefix.
tom5760@4784
  1272
   */
tom5760@4775
  1273
  PrefixIterator PrefixInsert (PrefixIterator position, const uint8_t value);
tom5760@4775
  1274
tom5760@4784
  1275
  /**
tom5760@4784
  1276
   * \brief Removes the prefix at the specified position.
tom5760@4784
  1277
   * \param position an Iterator pointing to the prefix to erase.
tom5760@4784
  1278
   * \return an iterator pointing to the next prefix in the block.
tom5760@4784
  1279
   */
tom5760@4775
  1280
  PrefixIterator PrefixErase (PrefixIterator position);
tom5760@4784
  1281
tom5760@4784
  1282
  /**
tom5760@4784
  1283
   * \brief Removes all prefixes from [first, last) (includes first, not
tom5760@4784
  1284
   *        includes last).
tom5760@4784
  1285
   * \param first an Iterator pointing to the first prefix to erase
tom5760@4784
  1286
   *        (inclusive).
tom5760@4784
  1287
   * \param last an Iterator pointing to the element past the last prefix to
tom5760@4784
  1288
   *        erase.
tom5760@4784
  1289
   * \return an iterator pointing to the next prefix in the block.
tom5760@4784
  1290
   */
tom5760@4775
  1291
  PrefixIterator PrefixErase (PrefixIterator first, PrefixIterator last);
tom5760@4775
  1292
tom5760@4784
  1293
  /**
tom5760@4784
  1294
   * \brief Removes all prefixes from this block.
tom5760@4784
  1295
   */
tom5760@4775
  1296
  void PrefixClear (void);
tom5760@4775
  1297
tom5760@4775
  1298
  /* Manipulating the TLV block */
tom5760@4784
  1299
tom5760@4784
  1300
  /**
tom5760@4784
  1301
   * \return an iterator to the first address TLV in this block.
tom5760@4784
  1302
   */
tom5760@4775
  1303
  TlvIterator TlvBegin (void);
tom5760@4784
  1304
tom5760@4784
  1305
  /**
tom5760@4784
  1306
   * \return a const iterator to the first address TLV in this block.
tom5760@4784
  1307
   */
tom5760@4775
  1308
  ConstTlvIterator TlvBegin (void) const;
tom5760@4784
  1309
tom5760@4784
  1310
  /**
tom5760@4784
  1311
   * \return an iterator to the last address TLV in this block.
tom5760@4784
  1312
   */
tom5760@4775
  1313
  TlvIterator TlvEnd (void);
tom5760@4784
  1314
tom5760@4784
  1315
  /**
tom5760@4784
  1316
   * \return a const iterator to the last address TLV in this block.
tom5760@4784
  1317
   */
tom5760@4775
  1318
  ConstTlvIterator TlvEnd (void) const;
tom5760@4775
  1319
tom5760@4784
  1320
  /**
tom5760@4784
  1321
   * \return the number of address TLVs in this block.
tom5760@4784
  1322
   */
tom5760@4775
  1323
  int TlvSize (void) const;
tom5760@4784
  1324
tom5760@4784
  1325
  /**
tom5760@4784
  1326
   * \return true if there are no address TLVs in this block, false otherwise.
tom5760@4784
  1327
   */
tom5760@4775
  1328
  bool TlvEmpty (void) const;
tom5760@4775
  1329
tom5760@4784
  1330
  /**
tom5760@4784
  1331
   * \return a smart pointer to the first address TLV in this block.
tom5760@4784
  1332
   */
tom5760@4782
  1333
  Ptr<PbbAddressTlv> TlvFront (void);
tom5760@4784
  1334
tom5760@4784
  1335
  /**
tom5760@4784
  1336
   * \return a const smart pointer to the first address TLV in this message.
tom5760@4784
  1337
   */
tom5760@4782
  1338
  const Ptr<PbbAddressTlv> TlvFront (void) const;
tom5760@4784
  1339
tom5760@4784
  1340
  /**
tom5760@4784
  1341
   * \return a smart pointer to the last address TLV in this message.
tom5760@4784
  1342
   */
tom5760@4782
  1343
  Ptr<PbbAddressTlv> TlvBack (void);
tom5760@4784
  1344
tom5760@4784
  1345
  /**
tom5760@4784
  1346
   * \return a const smart pointer to the last address TLV in this message.
tom5760@4784
  1347
   */
tom5760@4782
  1348
  const Ptr<PbbAddressTlv> TlvBack (void) const;
tom5760@4775
  1349
tom5760@4784
  1350
  /**
tom5760@4784
  1351
   * \brief Prepends an address TLV to the front of this message.
tom5760@4784
  1352
   * \param address a smart pointer to the address TLV to prepend.
tom5760@4784
  1353
   */
tom5760@4782
  1354
  void TlvPushFront (Ptr<PbbAddressTlv> address);
tom5760@4784
  1355
tom5760@4784
  1356
  /**
tom5760@4784
  1357
   * \brief Removes an address TLV from the front of this message.
tom5760@4784
  1358
   */
tom5760@4775
  1359
  void TlvPopFront (void);
tom5760@4775
  1360
tom5760@4784
  1361
  /**
tom5760@4784
  1362
   * \brief Appends an address TLV to the back of this message.
tom5760@4784
  1363
   * \param address a smart pointer to the address TLV to append.
tom5760@4784
  1364
   */
tom5760@4782
  1365
  void TlvPushBack (Ptr<PbbAddressTlv> address);
tom5760@4784
  1366
tom5760@4784
  1367
  /**
tom5760@4784
  1368
   * \brief Removes an address TLV from the back of this message.
tom5760@4784
  1369
   */
tom5760@4775
  1370
  void TlvPopBack (void);
tom5760@4775
  1371
tom5760@4784
  1372
  /**
tom5760@4784
  1373
   * \brief Inserts an address TLV at the specified position in this block.
tom5760@4784
  1374
   * \param position an Iterator pointing to the position in this block to
tom5760@4784
  1375
   *        insert the address TLV.
tom5760@4784
  1376
   * \param value the prefix to insert.
tom5760@4784
  1377
   * \return An iterator pointing to the newly inserted address TLV.
tom5760@4784
  1378
   */
tom5760@4782
  1379
  TlvIterator TlvInsert (TlvIterator position, const Ptr<PbbTlv> value);
tom5760@4775
  1380
tom5760@4784
  1381
  /**
tom5760@4784
  1382
   * \brief Removes the address TLV at the specified position.
tom5760@4784
  1383
   * \param position an Iterator pointing to the address TLV to erase.
tom5760@4784
  1384
   * \return an iterator pointing to the next address TLV in the block.
tom5760@4784
  1385
   */
tom5760@4775
  1386
  TlvIterator TlvErase (TlvIterator position);
tom5760@4784
  1387
tom5760@4784
  1388
  /**
tom5760@4784
  1389
   * \brief Removes all address TLVs from [first, last) (includes first, not
tom5760@4784
  1390
   *        includes last).
tom5760@4784
  1391
   * \param first an Iterator pointing to the first address TLV to erase
tom5760@4784
  1392
   *        (inclusive).
tom5760@4784
  1393
   * \param last an Iterator pointing to the element past the last address TLV
tom5760@4784
  1394
   *        to erase.
tom5760@4784
  1395
   * \return an iterator pointing to the next address TLV in the message.
tom5760@4784
  1396
   */
tom5760@4775
  1397
  TlvIterator TlvErase (TlvIterator first, TlvIterator last);
tom5760@4775
  1398
tom5760@4784
  1399
  /**
tom5760@4784
  1400
   * \brief Removes all address TLVs from this block.
tom5760@4784
  1401
   */
tom5760@4775
  1402
  void TlvClear (void);
tom5760@4775
  1403
tom5760@4784
  1404
  /**
tom5760@4784
  1405
   * \return The size (in bytes) needed to serialize this address block.
tom5760@4784
  1406
   */
tom5760@4775
  1407
  uint32_t GetSerializedSize (void) const;
tom5760@4784
  1408
tom5760@4784
  1409
  /**
tom5760@4784
  1410
   * \brief Serializes this address block into the specified buffer.
tom5760@4784
  1411
   * \param start a reference to the point in a buffer to begin serializing.
tom5760@4784
  1412
   *
tom5760@4784
  1413
   * Users should not need to call this.  Blocks will be deserialized by their
tom5760@4784
  1414
   * containing packet.
tom5760@4784
  1415
   */
tom5760@4775
  1416
  void Serialize (Buffer::Iterator &start) const;
tom5760@4784
  1417
tom5760@4784
  1418
  /**
tom5760@4784
  1419
   * \brief Deserializes an address block from the specified buffer.
tom5760@4784
  1420
   * \param start a reference to the point in a buffer to begin deserializing.
tom5760@4784
  1421
   *
tom5760@4784
  1422
   * Users should not need to call this.  Blocks will be deserialized by their
tom5760@4784
  1423
   * containing packet.
tom5760@4784
  1424
   */
tom5760@4775
  1425
  void Deserialize (Buffer::Iterator &start);
tom5760@4784
  1426
tom5760@4784
  1427
  /**
tom5760@4784
  1428
   * \brief Pretty-prints the contents of this address block.
tom5760@4784
  1429
   * \param os a stream object to print to.
tom5760@4784
  1430
   */
tom5760@4775
  1431
  void Print (std::ostream &os) const;
tom5760@4784
  1432
tom5760@4784
  1433
  /**
tom5760@4784
  1434
   * \brief Pretty-prints the contents of this address block, with specified
tom5760@4784
  1435
   *        indentation.
tom5760@4784
  1436
   * \param os a stream object to print to.
tom5760@4784
  1437
   * \param level level of indentation.
tom5760@4784
  1438
   *
tom5760@4784
  1439
   * This probably never needs to be called by users.  This is used when
tom5760@4784
  1440
   * recursively printing sub-objects.
tom5760@4784
  1441
   */
tom5760@4775
  1442
  void Print (std::ostream &os, int level) const;
tom5760@4775
  1443
tom5760@4782
  1444
  bool operator== (const PbbAddressBlock &other) const;
tom5760@4782
  1445
  bool operator!= (const PbbAddressBlock &other) const;
tom5760@4775
  1446
tom5760@4775
  1447
protected:
tom5760@4775
  1448
  virtual uint8_t GetAddressLength (void) const = 0;
tom5760@4775
  1449
tom5760@4775
  1450
  virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const = 0;
tom5760@4775
  1451
  virtual Address DeserializeAddress (uint8_t *buffer) const = 0;
tom5760@4775
  1452
  virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const = 0;
tom5760@4775
  1453
tom5760@4775
  1454
private:
tom5760@4775
  1455
  uint8_t GetPrefixFlags (void) const;
tom5760@4775
  1456
  void GetHeadTail (uint8_t *head, uint8_t &headlen,
tom5760@4775
  1457
      uint8_t *tail, uint8_t &taillen) const;
tom5760@4775
  1458
  bool HasZeroTail (const uint8_t *tail, uint8_t taillen) const;
tom5760@4775
  1459
tom5760@4775
  1460
  std::list<Address> m_addressList;
tom5760@4775
  1461
  std::list<uint8_t> m_prefixList;
tom5760@4782
  1462
  PbbAddressTlvBlock m_addressTlvList;
tom5760@4775
  1463
};
tom5760@4775
  1464
tom5760@4779
  1465
/**
tom5760@4782
  1466
 * \brief Concrete IPv4 specific PbbAddressBlock.
tom5760@4779
  1467
 *
tom5760@4779
  1468
 * This address block will only contain IPv4 addresses.
tom5760@4779
  1469
 */
tom5760@4782
  1470
class PbbAddressBlockIpv4 : public PbbAddressBlock
tom5760@4775
  1471
{
craigdo@4790
  1472
public:
craigdo@4790
  1473
  PbbAddressBlockIpv4 ();
craigdo@4790
  1474
  virtual ~PbbAddressBlockIpv4 ();
craigdo@4790
  1475
tom5760@4775
  1476
protected:
tom5760@4775
  1477
  virtual uint8_t GetAddressLength (void) const;
tom5760@4775
  1478
tom5760@4775
  1479
  virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const;
tom5760@4775
  1480
  virtual Address DeserializeAddress (uint8_t *buffer) const;
tom5760@4775
  1481
  virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const;
tom5760@4775
  1482
};
tom5760@4775
  1483
tom5760@4779
  1484
/**
tom5760@4782
  1485
 * \brief Concrete IPv6 specific PbbAddressBlock.
tom5760@4779
  1486
 *
tom5760@4779
  1487
 * This address block will only contain IPv6 addresses.
tom5760@4779
  1488
 */
tom5760@4782
  1489
class PbbAddressBlockIpv6 : public PbbAddressBlock
tom5760@4775
  1490
{
craigdo@4790
  1491
public:
craigdo@4790
  1492
  PbbAddressBlockIpv6 ();
craigdo@4790
  1493
  virtual ~PbbAddressBlockIpv6 ();
craigdo@4790
  1494
tom5760@4775
  1495
protected:
tom5760@4775
  1496
  virtual uint8_t GetAddressLength (void) const;
tom5760@4775
  1497
tom5760@4775
  1498
  virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const;
tom5760@4775
  1499
  virtual Address DeserializeAddress (uint8_t *buffer) const;
tom5760@4775
  1500
  virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const;
tom5760@4775
  1501
};
tom5760@4775
  1502
tom5760@4779
  1503
/**
tom5760@4779
  1504
 * \brief A packet or message TLV
tom5760@4779
  1505
 */
mathieu@5505
  1506
class PbbTlv : public SimpleRefCount<PbbTlv>
tom5760@4775
  1507
{
tom5760@4775
  1508
public:
tom5760@4782
  1509
  PbbTlv (void);
mathieu@5505
  1510
  virtual ~PbbTlv (void);
tom5760@4775
  1511
tom5760@4784
  1512
  /**
tom5760@4784
  1513
   * \brief Sets the type of this TLV.
tom5760@4784
  1514
   * \param type the type value to set.
tom5760@4784
  1515
   */
tom5760@4775
  1516
  void SetType (uint8_t type);
tom5760@4784
  1517
tom5760@4784
  1518
  /**
tom5760@4784
  1519
   * \return the type of this TLV.
tom5760@4784
  1520
   */
tom5760@4775
  1521
  uint8_t GetType (void) const;
tom5760@4775
  1522
tom5760@4784
  1523
  /**
tom5760@4784
  1524
   * \brief Sets the type extension of this TLV.
tom5760@4784
  1525
   * \param type the type extension value to set.
tom5760@4784
  1526
   *
tom5760@4784
  1527
   * The type extension is like a sub-type used to further distinguish between
tom5760@4784
  1528
   * TLVs of the same type.
tom5760@4784
  1529
   */
tom5760@4775
  1530
  void SetTypeExt (uint8_t type);
tom5760@4784
  1531
tom5760@4779
  1532
  /**
tom5760@4784
  1533
   * \return the type extension for this TLV.
tom5760@4779
  1534
   *
tom5760@4779
  1535
   * Calling this while HasTypeExt is False is undefined.  Make sure you check
tom5760@4780
  1536
   * it first.  This will be checked by an assert in debug builds.
tom5760@4779
  1537
   */
tom5760@4776
  1538
  uint8_t GetTypeExt (void) const;
tom5760@4784
  1539
tom5760@4784
  1540
  /**
tom5760@4784
  1541
   * \brief Tests whether or not this TLV has a type extension.
tom5760@4784
  1542
   * \return true if this TLV has a type extension, false otherwise.
tom5760@4784
  1543
   *
tom5760@4784
  1544
   * This should be called before calling GetTypeExt to make sure there
tom5760@4784
  1545
   * actually is one.
tom5760@4784
  1546
   */
tom5760@4775
  1547
  bool HasTypeExt (void) const;
tom5760@4775
  1548
tom5760@4784
  1549
  /**
tom5760@4784
  1550
   * \brief Sets the value of this message to the specified buffer.
tom5760@4784
  1551
   * \param start a buffer instance.
tom5760@4784
  1552
   *
tom5760@4784
  1553
   * The buffer is _not_ copied until this TLV is serialized.  You should not
tom5760@4784
  1554
   * change the contents of the buffer you pass in to this function.
tom5760@4784
  1555
   */
tom5760@4775
  1556
  void SetValue (Buffer start);
tom5760@4784
  1557
tom5760@4784
  1558
  /**
tom5760@4784
  1559
   * \brief Sets the value of this message to a buffer with the specified data.
tom5760@4784
  1560
   * \param buffer a pointer to data to put in the TLVs buffer.
tom5760@4784
  1561
   * \param size the size of the buffer.
tom5760@4784
  1562
   *
tom5760@4784
  1563
   * The buffer *is copied* into a *new buffer instance*.  You can free the
tom5760@4784
  1564
   * data in the buffer provided anytime you wish.
tom5760@4784
  1565
   */
tom5760@4775
  1566
  void SetValue (const uint8_t * buffer, uint32_t size);
tom5760@4784
  1567
tom5760@4779
  1568
  /**
tom5760@4784
  1569
   * \return a Buffer pointing to the value of this TLV.
tom5760@4779
  1570
   *
tom5760@4779
  1571
   * Calling this while HasValue is False is undefined.  Make sure you check it
tom5760@4780
  1572
   * first.  This will be checked by an assert in debug builds.
tom5760@4779
  1573
   */
tom5760@4776
  1574
  Buffer GetValue (void) const;
tom5760@4784
  1575
tom5760@4784
  1576
  /**
tom5760@4784
  1577
   * \brief Tests whether or not this TLV has a value.
tom5760@4784
  1578
   * \return true if this tlv has a TLV, false otherwise.
tom5760@4784
  1579
   *
tom5760@4784
  1580
   * This should be called before calling GetTypeExt to make sure there
tom5760@4784
  1581
   * actually is one.
tom5760@4784
  1582
   */
tom5760@4775
  1583
  bool HasValue (void) const;
tom5760@4775
  1584
tom5760@4784
  1585
  /**
tom5760@4784
  1586
   * \return The size (in bytes) needed to serialize this TLV.
tom5760@4784
  1587
   */
tom5760@4775
  1588
  uint32_t GetSerializedSize (void) const;
tom5760@4784
  1589
tom5760@4784
  1590
  /**
tom5760@4784
  1591
   * \brief Serializes this TLV into the specified buffer.
tom5760@4784
  1592
   * \param start a reference to the point in a buffer to begin serializing.
tom5760@4784
  1593
   *
tom5760@4784
  1594
   * Users should not need to call this.  TLVs will be serialized by their
tom5760@4784
  1595
   * containing blocks.
tom5760@4784
  1596
   */
tom5760@4775
  1597
  void Serialize (Buffer::Iterator &start) const;
tom5760@4784
  1598
tom5760@4784
  1599
  /**
tom5760@4784
  1600
   * \brief Deserializes a TLV from the specified buffer.
tom5760@4784
  1601
   * \param start a reference to the point in a buffer to begin deserializing.
tom5760@4784
  1602
   *
tom5760@4784
  1603
   * Users should not need to call this.  TLVs will be deserialized by their
tom5760@4784
  1604
   * containing blocks.
tom5760@4784
  1605
   */
tom5760@4775
  1606
  void Deserialize (Buffer::Iterator &start);
tom5760@4784
  1607
tom5760@4784
  1608
  /**
tom5760@4784
  1609
   * \brief Pretty-prints the contents of this TLV.
tom5760@4784
  1610
   * \param os a stream object to print to.
tom5760@4784
  1611
   */
tom5760@4775
  1612
  void Print (std::ostream &os) const;
tom5760@4784
  1613
tom5760@4784
  1614
  /**
tom5760@4784
  1615
   * \brief Pretty-prints the contents of this TLV, with specified indentation.
tom5760@4784
  1616
   * \param os a stream object to print to.
tom5760@4784
  1617
   * \param level level of indentation.
tom5760@4784
  1618
   *
tom5760@4784
  1619
   * This probably never needs to be called by users.  This is used when
tom5760@4784
  1620
   * recursively printing sub-objects.
tom5760@4784
  1621
   */
tom5760@4775
  1622
  void Print (std::ostream &os, int level) const;
tom5760@4775
  1623
tom5760@4782
  1624
  bool operator== (const PbbTlv &other) const;
tom5760@4782
  1625
  bool operator!= (const PbbTlv &other) const;
tom5760@4775
  1626
tom5760@4775
  1627
protected:
tom5760@4775
  1628
  void SetIndexStart (uint8_t index);
tom5760@4776
  1629
  uint8_t GetIndexStart (void) const;
tom5760@4775
  1630
  bool HasIndexStart (void) const;
tom5760@4775
  1631
tom5760@4775
  1632
  void SetIndexStop (uint8_t index);
tom5760@4776
  1633
  uint8_t GetIndexStop (void) const;
tom5760@4775
  1634
  bool HasIndexStop (void) const;
tom5760@4775
  1635
tom5760@4775
  1636
  void SetMultivalue (bool isMultivalue);
tom5760@4775
  1637
  bool IsMultivalue (void) const;
tom5760@4775
  1638
tom5760@4775
  1639
private:
tom5760@4775
  1640
  uint8_t m_type;
tom5760@4775
  1641
tom5760@4775
  1642
  bool m_hasTypeExt;
tom5760@4775
  1643
  uint8_t m_typeExt;
tom5760@4775
  1644
tom5760@4775
  1645
  bool m_hasIndexStart;
tom5760@4775
  1646
  uint8_t m_indexStart;
tom5760@4775
  1647
tom5760@4775
  1648
  bool m_hasIndexStop;
tom5760@4775
  1649
  uint8_t m_indexStop;
tom5760@4775
  1650
tom5760@4775
  1651
  bool m_isMultivalue;
tom5760@4775
  1652
  bool m_hasValue;
tom5760@4775
  1653
  Buffer m_value;
tom5760@4775
  1654
};
tom5760@4775
  1655
tom5760@4779
  1656
/**
tom5760@4779
  1657
 * \brief An Address TLV
tom5760@4779
  1658
 */
tom5760@4782
  1659
class PbbAddressTlv : public PbbTlv
tom5760@4775
  1660
{
tom5760@4775
  1661
public:
tom5760@4784
  1662
  /**
tom5760@4784
  1663
   * \brief Sets the index of the first address in the associated address block
tom5760@4784
  1664
   * that this address TLV applies to.
tom5760@4784
  1665
   * \param index the index of the first address.
tom5760@4784
  1666
   */
tom5760@4775
  1667
  void SetIndexStart (uint8_t index);
tom5760@4784
  1668
tom5760@4779
  1669
  /**
tom5760@4784
  1670
   * \return the first (inclusive) index of the address in the corresponding
tom5760@4784
  1671
   * address block that this TLV applies to.
tom5760@4779
  1672
   *
tom5760@4779
  1673
   * Calling this while HasIndexStart is False is undefined.  Make sure you
tom5760@4780
  1674
   * check it first.  This will be checked by an assert in debug builds.
tom5760@4779
  1675
   */
tom5760@4776
  1676
  uint8_t GetIndexStart (void) const;
tom5760@4784
  1677
tom5760@4784
  1678
  /**
tom5760@4784
  1679
   * \brief Tests whether or not this address TLV has a start index.
tom5760@4784
  1680
   * \return true if this address TLV has a start index, false otherwise.
tom5760@4784
  1681
   *
tom5760@4784
  1682
   * This should be called before calling GetIndexStart to make sure there
tom5760@4784
  1683
   * actually is one.
tom5760@4784
  1684
   */
tom5760@4775
  1685
  bool HasIndexStart (void) const;
tom5760@4775
  1686
tom5760@4784
  1687
  /**
tom5760@4784
  1688
   * \brief Sets the index of the last address in the associated address block
tom5760@4784
  1689
   * that this address TLV applies to.
tom5760@4784
  1690
   * \param index the index of the last address.
tom5760@4784
  1691
   */
tom5760@4775
  1692
  void SetIndexStop (uint8_t index);
tom5760@4784
  1693
tom5760@4779
  1694
  /**
tom5760@4784
  1695
   * \return the last (inclusive) index of the address in the corresponding
tom5760@4782
  1696
   * PbbAddressBlock that this TLV applies to.
tom5760@4779
  1697
   *
tom5760@4779
  1698
   * Calling this while HasIndexStop is False is undefined.  Make sure you
tom5760@4780
  1699
   * check it first.  This will be checked by an assert in debug builds.
tom5760@4779
  1700
   */
tom5760@4776
  1701
  uint8_t GetIndexStop (void) const;
tom5760@4784
  1702
tom5760@4784
  1703
  /**
tom5760@4784
  1704
   * \brief Tests whether or not this address TLV has a stop index.
tom5760@4784
  1705
   * \return true if this address TLV has a stop index, false otherwise.
tom5760@4784
  1706
   *
tom5760@4784
  1707
   * This should be called before calling GetIndexStop to make sure there
tom5760@4784
  1708
   * actually is one.
tom5760@4784
  1709
   */
tom5760@4775
  1710
  bool HasIndexStop (void) const;
tom5760@4775
  1711
tom5760@4784
  1712
  /**
tom5760@4784
  1713
   * \brief Sets whether or not this address TLV is "multivalue"
tom5760@4784
  1714
   * \param isMultivalue whether or not this address TLV should be multivalue.
tom5760@4784
  1715
   *
tom5760@4784
  1716
   * If true, this means the value associated with this TLV should be divided
tom5760@4784
  1717
   * evenly into (GetIndexStop() - GetIndexStart() + 1) values.  Otherwise, the
tom5760@4784
  1718
   * value is one single value that applies to each address in the range.
tom5760@4784
  1719
   */
tom5760@4775
  1720
  void SetMultivalue (bool isMultivalue);
tom5760@4784
  1721
tom5760@4784
  1722
  /**
tom5760@4784
  1723
   * \brief Tests whether or not this address TLV is "multivalue"
tom5760@4784
  1724
   * \return whether this address TLV is multivalue or not.
tom5760@4784
  1725
   */
tom5760@4775
  1726
  bool IsMultivalue (void) const;
tom5760@4775
  1727
};
tom5760@4775
  1728
tom5760@4775
  1729
} /* namespace ns3 */
tom5760@4775
  1730
tom5760@4775
  1731
#endif /* PACKETBB_H */