src/node/packetbb.cc
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 5885 d6ee673adda4
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@4787
    21
/* These classes implement RFC 5444 - The Generalized Mobile Ad Hoc Network
tom5760@4787
    22
 * (MANET) Packet/PbbMessage Format
tom5760@4787
    23
 * See: http://tools.ietf.org/html/rfc5444 for details */
tom5760@4775
    24
tom5760@4775
    25
#include "ns3/ipv4-address.h"
tom5760@4775
    26
#include "ns3/ipv6-address.h"
tom5760@4780
    27
#include "ns3/assert.h"
tom5760@4775
    28
tom5760@4775
    29
#include "packetbb.h"
tom5760@4775
    30
tom5760@4775
    31
static const uint8_t VERSION = 0;
tom5760@4775
    32
/* Packet flags */
tom5760@4775
    33
static const uint8_t PHAS_SEQ_NUM = 0x8;
tom5760@4775
    34
static const uint8_t PHAS_TLV = 0x4;
tom5760@4775
    35
tom5760@4782
    36
/* PbbMessage flags */
tom5760@4775
    37
static const uint8_t MHAS_ORIG = 0x80;
tom5760@4775
    38
static const uint8_t MHAS_HOP_LIMIT = 0x40;
tom5760@4775
    39
static const uint8_t MHAS_HOP_COUNT = 0x20;
tom5760@4775
    40
static const uint8_t MHAS_SEQ_NUM = 0x10;
tom5760@4775
    41
tom5760@4775
    42
/* Address block flags */
tom5760@4775
    43
static const uint8_t AHAS_HEAD = 0x80;
tom5760@4775
    44
static const uint8_t AHAS_FULL_TAIL = 0x40;
tom5760@4775
    45
static const uint8_t AHAS_ZERO_TAIL = 0x20;
tom5760@4775
    46
static const uint8_t AHAS_SINGLE_PRE_LEN = 0x10;
tom5760@4775
    47
static const uint8_t AHAS_MULTI_PRE_LEN = 0x08;
tom5760@4775
    48
tom5760@4775
    49
/* TLV Flags */
tom5760@4775
    50
static const uint8_t THAS_TYPE_EXT = 0x80;
tom5760@4775
    51
static const uint8_t THAS_SINGLE_INDEX = 0x40;
tom5760@4775
    52
static const uint8_t THAS_MULTI_INDEX = 0x20;
tom5760@4775
    53
static const uint8_t THAS_VALUE = 0x10;
tom5760@4775
    54
static const uint8_t THAS_EXT_LEN = 0x08;
tom5760@4775
    55
static const uint8_t TIS_MULTIVALUE = 0x04;
tom5760@4775
    56
tom5760@4775
    57
namespace ns3 {
tom5760@4775
    58
tom5760@4782
    59
NS_OBJECT_ENSURE_REGISTERED (PbbPacket);
tom5760@4782
    60
tom5760@5263
    61
PbbTlvBlock::PbbTlvBlock (void)
tom5760@5263
    62
{
tom5760@5263
    63
  return;
tom5760@5263
    64
}
tom5760@5263
    65
tom5760@5263
    66
PbbTlvBlock::~PbbTlvBlock (void)
tom5760@5263
    67
{
tom5760@5263
    68
  Clear ();
tom5760@5263
    69
}
tom5760@5263
    70
tom5760@4782
    71
PbbTlvBlock::Iterator
tom5760@4782
    72
PbbTlvBlock::Begin (void)
tom5760@4775
    73
{
tom5760@4775
    74
  return m_tlvList.begin ();
tom5760@4775
    75
}
tom5760@4775
    76
tom5760@4782
    77
PbbTlvBlock::ConstIterator
tom5760@4782
    78
PbbTlvBlock::Begin (void) const
tom5760@4775
    79
{
tom5760@4775
    80
  return m_tlvList.begin ();
tom5760@4775
    81
}
tom5760@4775
    82
tom5760@4782
    83
PbbTlvBlock::Iterator
tom5760@4782
    84
PbbTlvBlock::End (void)
tom5760@4775
    85
{
tom5760@4775
    86
  return m_tlvList.end ();
tom5760@4775
    87
}
tom5760@4775
    88
tom5760@4782
    89
PbbTlvBlock::ConstIterator
tom5760@4782
    90
PbbTlvBlock::End (void) const
tom5760@4775
    91
{
tom5760@4775
    92
  return m_tlvList.end ();
tom5760@4775
    93
}
tom5760@4775
    94
tom5760@4775
    95
int
tom5760@4782
    96
PbbTlvBlock::Size (void) const
tom5760@4775
    97
{
tom5760@4775
    98
  return m_tlvList.size ();
tom5760@4775
    99
}
tom5760@4775
   100
tom5760@4775
   101
bool
tom5760@4782
   102
PbbTlvBlock::Empty (void) const
tom5760@4775
   103
{
tom5760@4775
   104
  return m_tlvList.empty ();
tom5760@4775
   105
}
tom5760@4775
   106
tom5760@4782
   107
Ptr<PbbTlv>
tom5760@4782
   108
PbbTlvBlock::Front (void) const
tom5760@4775
   109
{
tom5760@4775
   110
  return m_tlvList.front ();
tom5760@4775
   111
}
tom5760@4775
   112
tom5760@4782
   113
Ptr<PbbTlv>
tom5760@4782
   114
PbbTlvBlock::Back (void) const
tom5760@4775
   115
{
tom5760@4775
   116
  return m_tlvList.back ();
tom5760@4775
   117
}
tom5760@4775
   118
tom5760@4775
   119
void
tom5760@4782
   120
PbbTlvBlock::PushFront (Ptr<PbbTlv> tlv)
tom5760@4775
   121
{
tom5760@4775
   122
  m_tlvList.push_front (tlv);
tom5760@4775
   123
}
tom5760@4775
   124
tom5760@4775
   125
void
tom5760@4782
   126
PbbTlvBlock::PopFront (void)
tom5760@4775
   127
{
tom5760@4775
   128
  m_tlvList.pop_front ();
tom5760@4775
   129
}
tom5760@4775
   130
tom5760@4775
   131
void
tom5760@4782
   132
PbbTlvBlock::PushBack (Ptr<PbbTlv> tlv)
tom5760@4775
   133
{
tom5760@4775
   134
  m_tlvList.push_back (tlv);
tom5760@4775
   135
}
tom5760@4775
   136
tom5760@4775
   137
void
tom5760@4782
   138
PbbTlvBlock::PopBack (void)
tom5760@4775
   139
{
tom5760@4775
   140
  m_tlvList.pop_back ();
tom5760@4775
   141
}
tom5760@4775
   142
tom5760@4782
   143
PbbTlvBlock::Iterator
tom5760@4782
   144
PbbTlvBlock::Insert (PbbTlvBlock::Iterator position, const Ptr<PbbTlv> tlv)
tom5760@4775
   145
{
tom5760@4775
   146
  return m_tlvList.insert (position, tlv);
tom5760@4775
   147
}
tom5760@4775
   148
tom5760@4782
   149
PbbTlvBlock::Iterator
tom5760@4782
   150
PbbTlvBlock::Erase (PbbTlvBlock::Iterator position)
tom5760@4775
   151
{
tom5760@4775
   152
  return m_tlvList.erase (position);
tom5760@4775
   153
}
tom5760@4775
   154
tom5760@4782
   155
PbbTlvBlock::Iterator
tom5760@4782
   156
PbbTlvBlock::Erase (PbbTlvBlock::Iterator first, PbbTlvBlock::Iterator last)
tom5760@4775
   157
{
tom5760@4775
   158
  return m_tlvList.erase (first, last);
tom5760@4775
   159
}
tom5760@4775
   160
tom5760@4775
   161
void
tom5760@4782
   162
PbbTlvBlock::Clear (void)
tom5760@4775
   163
{
tom5760@5263
   164
  for (Iterator iter = Begin (); iter != End (); iter++)
tom5760@5263
   165
    {
tom5760@5263
   166
      *iter = 0;
tom5760@5263
   167
    }
tom5760@4775
   168
  m_tlvList.clear ();
tom5760@4775
   169
}
tom5760@4775
   170
tom5760@4775
   171
uint32_t
tom5760@4782
   172
PbbTlvBlock::GetSerializedSize (void) const
tom5760@4775
   173
{
tom5760@4775
   174
  /* tlv size */
tom5760@4775
   175
  uint32_t size = 2;
tom5760@4775
   176
  for (ConstIterator iter = Begin (); iter != End (); iter++)
tom5760@4776
   177
    {
tom5760@4776
   178
      size += (*iter)->GetSerializedSize ();
tom5760@4776
   179
    }
tom5760@4775
   180
  return size;
tom5760@4775
   181
}
tom5760@4775
   182
tom5760@4775
   183
void
tom5760@4782
   184
PbbTlvBlock::Serialize (Buffer::Iterator &start) const
tom5760@4775
   185
{
tom5760@4775
   186
  if (Empty ())
tom5760@4776
   187
    {
tom5760@4776
   188
      start.WriteHtonU16 (0);
tom5760@4776
   189
      return;
tom5760@4776
   190
    }
tom5760@4775
   191
tom5760@4775
   192
  /* We need to write the size of the TLV block in front, so save its
tom5760@4775
   193
   * position. */
tom5760@4775
   194
  Buffer::Iterator tlvsize = start;
tom5760@4775
   195
  start.Next (2);
tom5760@4775
   196
  for (ConstIterator iter = Begin (); iter != End (); iter++)
tom5760@4776
   197
    {
tom5760@4776
   198
      (*iter)->Serialize (start);
tom5760@4776
   199
    }
tom5760@4775
   200
  /* - 2 to not include the size field */
tom5760@4775
   201
  uint16_t size = start.GetDistanceFrom (tlvsize) - 2;
tom5760@4775
   202
  tlvsize.WriteHtonU16 (size);
tom5760@4775
   203
}
tom5760@4775
   204
tom5760@4775
   205
void
tom5760@4782
   206
PbbTlvBlock::Deserialize (Buffer::Iterator &start)
tom5760@4775
   207
{
tom5760@4775
   208
  uint16_t size = start.ReadNtohU16 ();
tom5760@4775
   209
tom5760@4775
   210
  Buffer::Iterator tlvstart = start;
tom5760@4775
   211
  if (size > 0)
tom5760@4775
   212
    {
tom5760@4776
   213
      while (start.GetDistanceFrom (tlvstart) < size)
tom5760@4776
   214
        {
tom5760@4782
   215
          Ptr<PbbTlv> newtlv = Create<PbbTlv> ();
tom5760@4776
   216
          newtlv->Deserialize (start);
tom5760@4776
   217
          PushBack (newtlv);
tom5760@4776
   218
        }
tom5760@4775
   219
    }
tom5760@4775
   220
}
tom5760@4775
   221
tom5760@4775
   222
void
tom5760@4782
   223
PbbTlvBlock::Print (std::ostream &os) const
tom5760@4775
   224
{
tom5760@4775
   225
  Print (os, 0);
tom5760@4775
   226
}
tom5760@4775
   227
tom5760@4775
   228
void
tom5760@4782
   229
PbbTlvBlock::Print (std::ostream &os, int level) const
tom5760@4775
   230
{
tom5760@4775
   231
  std::string prefix = "";
tom5760@4775
   232
  for (int i = 0; i < level; i++)
tom5760@4776
   233
    {
tom5760@4776
   234
      prefix.append("\t");
tom5760@4776
   235
    }
tom5760@4775
   236
tom5760@4775
   237
  os << prefix << "TLV Block {" << std::endl;
tom5760@4775
   238
  os << prefix << "\tsize = " << Size () << std::endl;
tom5760@4775
   239
  os << prefix << "\tmembers [" << std::endl;
tom5760@4776
   240
tom5760@4775
   241
  for (ConstIterator iter = Begin (); iter != End (); iter++)
tom5760@4776
   242
    {
tom5760@4776
   243
      (*iter)->Print (os, level+2);
tom5760@4776
   244
    }
tom5760@4776
   245
tom5760@4775
   246
  os << prefix << "\t]" << std::endl;
tom5760@4775
   247
  os << prefix << "}" << std::endl;
tom5760@4775
   248
}
tom5760@4775
   249
tom5760@4775
   250
bool
tom5760@4782
   251
PbbTlvBlock::operator== (const PbbTlvBlock &other) const
tom5760@4775
   252
{
tom5760@4775
   253
  if (Size () != other.Size ())
tom5760@4776
   254
    {
tom5760@4776
   255
      return false;
tom5760@4776
   256
    }
tom5760@4775
   257
tom5760@4775
   258
  ConstIterator ti, oi;
tom5760@4775
   259
  for (ti = Begin (), oi = other.Begin ();
tom5760@4775
   260
      ti != End () && oi != other.End ();
tom5760@4775
   261
      ti++, oi++)
tom5760@4776
   262
    {
tom5760@4776
   263
      if (**ti != **oi)
tom5760@4776
   264
        {
tom5760@4776
   265
          return false;
tom5760@4776
   266
        }
tom5760@4776
   267
    }
tom5760@4775
   268
  return true;
tom5760@4775
   269
}
tom5760@4775
   270
tom5760@4775
   271
bool
tom5760@4782
   272
PbbTlvBlock::operator!= (const PbbTlvBlock &other) const
tom5760@4775
   273
{
tom5760@4775
   274
  return !(*this == other);
tom5760@4775
   275
}
tom5760@4775
   276
tom5760@4782
   277
/* End PbbTlvBlock class */
tom5760@4782
   278
tom5760@5263
   279
PbbAddressTlvBlock::PbbAddressTlvBlock (void)
tom5760@5263
   280
{
tom5760@5263
   281
  return;
tom5760@5263
   282
}
tom5760@5263
   283
tom5760@5263
   284
PbbAddressTlvBlock::~PbbAddressTlvBlock (void)
tom5760@5263
   285
{
tom5760@5263
   286
  Clear ();
tom5760@5263
   287
}
tom5760@5263
   288
tom5760@4782
   289
PbbAddressTlvBlock::Iterator
tom5760@4782
   290
PbbAddressTlvBlock::Begin (void)
tom5760@4775
   291
{
tom5760@4775
   292
  return m_tlvList.begin ();
tom5760@4775
   293
}
tom5760@4775
   294
tom5760@4782
   295
PbbAddressTlvBlock::ConstIterator
tom5760@4782
   296
PbbAddressTlvBlock::Begin (void) const
tom5760@4775
   297
{
tom5760@4775
   298
  return m_tlvList.begin ();
tom5760@4775
   299
}
tom5760@4775
   300
tom5760@4782
   301
PbbAddressTlvBlock::Iterator
tom5760@4782
   302
PbbAddressTlvBlock::End (void)
tom5760@4775
   303
{
tom5760@4775
   304
  return m_tlvList.end ();
tom5760@4775
   305
}
tom5760@4775
   306
tom5760@4782
   307
PbbAddressTlvBlock::ConstIterator
tom5760@4782
   308
PbbAddressTlvBlock::End (void) const
tom5760@4775
   309
{
tom5760@4775
   310
  return m_tlvList.end ();
tom5760@4775
   311
}
tom5760@4775
   312
tom5760@4775
   313
int
tom5760@4782
   314
PbbAddressTlvBlock::Size (void) const
tom5760@4775
   315
{
tom5760@4775
   316
  return m_tlvList.size ();
tom5760@4775
   317
}
tom5760@4775
   318
tom5760@4775
   319
bool
tom5760@4782
   320
PbbAddressTlvBlock::Empty (void) const
tom5760@4775
   321
{
tom5760@4775
   322
  return m_tlvList.empty ();
tom5760@4775
   323
}
tom5760@4775
   324
tom5760@4782
   325
Ptr<PbbAddressTlv>
tom5760@4782
   326
PbbAddressTlvBlock::Front (void) const
tom5760@4775
   327
{
tom5760@4775
   328
  return m_tlvList.front ();
tom5760@4775
   329
}
tom5760@4775
   330
tom5760@4782
   331
Ptr<PbbAddressTlv>
tom5760@4782
   332
PbbAddressTlvBlock::Back (void) const
tom5760@4775
   333
{
tom5760@4775
   334
  return m_tlvList.back ();
tom5760@4775
   335
}
tom5760@4775
   336
tom5760@4775
   337
void
tom5760@4782
   338
PbbAddressTlvBlock::PushFront (Ptr<PbbAddressTlv> tlv)
tom5760@4775
   339
{
tom5760@4775
   340
  m_tlvList.push_front (tlv);
tom5760@4775
   341
}
tom5760@4775
   342
tom5760@4775
   343
void
tom5760@4782
   344
PbbAddressTlvBlock::PopFront (void)
tom5760@4775
   345
{
tom5760@4775
   346
  m_tlvList.pop_front ();
tom5760@4775
   347
}
tom5760@4775
   348
tom5760@4775
   349
void
tom5760@4782
   350
PbbAddressTlvBlock::PushBack (Ptr<PbbAddressTlv> tlv)
tom5760@4775
   351
{
tom5760@4775
   352
  m_tlvList.push_back (tlv);
tom5760@4775
   353
}
tom5760@4775
   354
tom5760@4775
   355
void
tom5760@4782
   356
PbbAddressTlvBlock::PopBack (void)
tom5760@4775
   357
{
tom5760@4775
   358
  m_tlvList.pop_back ();
tom5760@4775
   359
}
tom5760@4775
   360
tom5760@4782
   361
PbbAddressTlvBlock::Iterator
tom5760@4782
   362
PbbAddressTlvBlock::Insert (PbbAddressTlvBlock::Iterator position, const Ptr<PbbAddressTlv> tlv)
tom5760@4775
   363
{
tom5760@4775
   364
  return m_tlvList.insert (position, tlv);
tom5760@4775
   365
}
tom5760@4775
   366
tom5760@4782
   367
PbbAddressTlvBlock::Iterator
tom5760@4782
   368
PbbAddressTlvBlock::Erase (PbbAddressTlvBlock::Iterator position)
tom5760@4775
   369
{
tom5760@4775
   370
  return m_tlvList.erase (position);
tom5760@4775
   371
}
tom5760@4775
   372
tom5760@4782
   373
PbbAddressTlvBlock::Iterator
tom5760@4782
   374
PbbAddressTlvBlock::Erase (PbbAddressTlvBlock::Iterator first, PbbAddressTlvBlock::Iterator last)
tom5760@4775
   375
{
tom5760@4775
   376
  return m_tlvList.erase (first, last);
tom5760@4775
   377
}
tom5760@4775
   378
tom5760@4775
   379
void
tom5760@4782
   380
PbbAddressTlvBlock::Clear (void)
tom5760@4775
   381
{
tom5760@5263
   382
  for (Iterator iter = Begin (); iter != End (); iter++)
tom5760@5263
   383
    {
tom5760@5263
   384
      *iter = 0;
tom5760@5263
   385
    }
tom5760@4775
   386
  m_tlvList.clear ();
tom5760@4775
   387
}
tom5760@4775
   388
tom5760@4775
   389
uint32_t
tom5760@4782
   390
PbbAddressTlvBlock::GetSerializedSize (void) const
tom5760@4775
   391
{
tom5760@4775
   392
  /* tlv size */
tom5760@4775
   393
  uint32_t size = 2;
tom5760@4775
   394
  for (ConstIterator iter = Begin (); iter != End (); iter++)
tom5760@4776
   395
    {
tom5760@4776
   396
      size += (*iter)->GetSerializedSize ();
tom5760@4776
   397
    }
tom5760@4775
   398
  return size;
tom5760@4775
   399
}
tom5760@4775
   400
tom5760@4775
   401
void
tom5760@4782
   402
PbbAddressTlvBlock::Serialize (Buffer::Iterator &start) const
tom5760@4775
   403
{
tom5760@4775
   404
  if (Empty ())
tom5760@4776
   405
    {
tom5760@4776
   406
      start.WriteHtonU16 (0);
tom5760@4776
   407
      return;
tom5760@4776
   408
    }
tom5760@4775
   409
tom5760@4775
   410
  /* We need to write the size of the TLV block in front, so save its
tom5760@4775
   411
   * position. */
tom5760@4775
   412
  Buffer::Iterator tlvsize = start;
tom5760@4775
   413
  start.Next (2);
tom5760@4775
   414
  for (ConstIterator iter = Begin (); iter != End (); iter++)
tom5760@4776
   415
    {
tom5760@4776
   416
      (*iter)->Serialize (start);
tom5760@4776
   417
    }
tom5760@4775
   418
  /* - 2 to not include the size field */
tom5760@4775
   419
  uint16_t size = start.GetDistanceFrom (tlvsize) - 2;
tom5760@4775
   420
  tlvsize.WriteHtonU16 (size);
tom5760@4775
   421
}
tom5760@4775
   422
tom5760@4775
   423
void
tom5760@4782
   424
PbbAddressTlvBlock::Deserialize (Buffer::Iterator &start)
tom5760@4775
   425
{
tom5760@4775
   426
  uint16_t size = start.ReadNtohU16 ();
tom5760@4775
   427
tom5760@4775
   428
  Buffer::Iterator tlvstart = start;
tom5760@4775
   429
  if (size > 0)
tom5760@4775
   430
    {
tom5760@4776
   431
      while (start.GetDistanceFrom (tlvstart) < size)
tom5760@4776
   432
      {
tom5760@4782
   433
        Ptr<PbbAddressTlv> newtlv = Create<PbbAddressTlv> ();
tom5760@4776
   434
        newtlv->Deserialize (start);
tom5760@4776
   435
        PushBack (newtlv);
tom5760@4776
   436
      }
tom5760@4775
   437
    }
tom5760@4775
   438
}
tom5760@4775
   439
tom5760@4775
   440
void
tom5760@4782
   441
PbbAddressTlvBlock::Print (std::ostream &os) const
tom5760@4775
   442
{
tom5760@4775
   443
  Print (os, 0);
tom5760@4775
   444
}
tom5760@4775
   445
tom5760@4775
   446
void
tom5760@4782
   447
PbbAddressTlvBlock::Print (std::ostream &os, int level) const
tom5760@4775
   448
{
tom5760@4775
   449
  std::string prefix = "";
tom5760@4775
   450
  for (int i = 0; i < level; i++)
tom5760@4776
   451
    {
tom5760@4776
   452
      prefix.append("\t");
tom5760@4776
   453
    }
tom5760@4775
   454
tom5760@4775
   455
  os << prefix << "TLV Block {" << std::endl;
tom5760@4775
   456
  os << prefix << "\tsize = " << Size () << std::endl;
tom5760@4775
   457
  os << prefix << "\tmembers [" << std::endl;
tom5760@4776
   458
tom5760@4775
   459
  for (ConstIterator iter = Begin (); iter != End (); iter++)
tom5760@4776
   460
    {
tom5760@4776
   461
      (*iter)->Print (os, level+2);
tom5760@4776
   462
    }
tom5760@4776
   463
tom5760@4775
   464
  os << prefix << "\t]" << std::endl;
tom5760@4775
   465
  os << prefix << "}" << std::endl;
tom5760@4775
   466
}
tom5760@4775
   467
tom5760@4775
   468
bool
tom5760@4782
   469
PbbAddressTlvBlock::operator== (const PbbAddressTlvBlock &other) const
tom5760@4775
   470
{
tom5760@4775
   471
  if (Size () != other.Size ())
tom5760@4776
   472
    {
tom5760@4776
   473
      return false;
tom5760@4776
   474
    }
tom5760@4775
   475
tom5760@4775
   476
  ConstIterator it, ot;
tom5760@4775
   477
  for (it = Begin (), ot = other.Begin ();
tom5760@4775
   478
      it != End () && ot != other.End ();
tom5760@4775
   479
      it++, ot++)
tom5760@4776
   480
    {
tom5760@4776
   481
      if (**it != **ot)
tom5760@4776
   482
        {
tom5760@4776
   483
          return false;
tom5760@4776
   484
        }
tom5760@4776
   485
    }
tom5760@4775
   486
  return true;
tom5760@4775
   487
}
tom5760@4775
   488
tom5760@4775
   489
bool
tom5760@4782
   490
PbbAddressTlvBlock::operator!= (const PbbAddressTlvBlock &other) const
tom5760@4775
   491
{
tom5760@4775
   492
  return !(*this == other);
tom5760@4775
   493
}
tom5760@4775
   494
tom5760@4775
   495
tom5760@4782
   496
/* End PbbAddressTlvBlock Class */
tom5760@4782
   497
tom5760@4782
   498
PbbPacket::PbbPacket (void)
tom5760@4775
   499
{
tom5760@4775
   500
  m_version = VERSION;
tom5760@4775
   501
  m_hasseqnum = false;
tom5760@4775
   502
}
tom5760@4775
   503
tom5760@5263
   504
PbbPacket::~PbbPacket (void)
tom5760@5263
   505
{
tom5760@5263
   506
  MessageClear ();
tom5760@5263
   507
}
tom5760@5263
   508
tom5760@4775
   509
uint8_t
tom5760@4782
   510
PbbPacket::GetVersion (void) const
tom5760@4775
   511
{
tom5760@4775
   512
  return m_version;
tom5760@4775
   513
}
tom5760@4775
   514
tom5760@4775
   515
void
tom5760@4782
   516
PbbPacket::SetSequenceNumber (uint16_t number)
tom5760@4775
   517
{
tom5760@4775
   518
  m_seqnum = number;
tom5760@4775
   519
  m_hasseqnum = true;
tom5760@4775
   520
}
tom5760@4775
   521
tom5760@4775
   522
uint16_t
tom5760@4782
   523
PbbPacket::GetSequenceNumber (void) const
tom5760@4775
   524
{
tom5760@4780
   525
  NS_ASSERT (HasSequenceNumber ());
tom5760@4775
   526
  return m_seqnum;
tom5760@4775
   527
}
tom5760@4775
   528
tom5760@4775
   529
bool
tom5760@4782
   530
PbbPacket::HasSequenceNumber (void) const
tom5760@4775
   531
{
tom5760@4775
   532
  return m_hasseqnum;
tom5760@4775
   533
}
tom5760@4775
   534
tom5760@4775
   535
/* Manipulating Packet TLVs */
tom5760@4775
   536
tom5760@4782
   537
PbbPacket::TlvIterator
tom5760@4782
   538
PbbPacket::TlvBegin (void)
tom5760@4775
   539
{
tom5760@4775
   540
  return m_tlvList.Begin ();
tom5760@4775
   541
}
tom5760@4775
   542
tom5760@4782
   543
PbbPacket::ConstTlvIterator
tom5760@4782
   544
PbbPacket::TlvBegin (void) const
tom5760@4775
   545
{
tom5760@4775
   546
  return m_tlvList.Begin ();
tom5760@4775
   547
}
tom5760@4775
   548
tom5760@4782
   549
PbbPacket::TlvIterator
tom5760@4782
   550
PbbPacket::TlvEnd (void)
tom5760@4775
   551
{
tom5760@4775
   552
  return m_tlvList.End ();
tom5760@4775
   553
}
tom5760@4775
   554
tom5760@4782
   555
PbbPacket::ConstTlvIterator
tom5760@4782
   556
PbbPacket::TlvEnd (void) const
tom5760@4775
   557
{
tom5760@4775
   558
  return m_tlvList.End ();
tom5760@4775
   559
}
tom5760@4775
   560
tom5760@4775
   561
int
tom5760@4782
   562
PbbPacket::TlvSize (void) const
tom5760@4775
   563
{
tom5760@4775
   564
  return m_tlvList.Size ();
tom5760@4775
   565
}
tom5760@4775
   566
tom5760@4775
   567
bool
tom5760@4782
   568
PbbPacket::TlvEmpty (void) const
tom5760@4775
   569
{
tom5760@4775
   570
  return m_tlvList.Empty ();
tom5760@4775
   571
}
tom5760@4775
   572
tom5760@4782
   573
Ptr<PbbTlv>
tom5760@4782
   574
PbbPacket::TlvFront (void)
tom5760@4775
   575
{
tom5760@4775
   576
  return m_tlvList.Front ();
tom5760@4775
   577
}
tom5760@4775
   578
tom5760@4782
   579
const Ptr<PbbTlv>
tom5760@4782
   580
PbbPacket::TlvFront (void) const
tom5760@4775
   581
{
tom5760@4775
   582
  return m_tlvList.Front ();
tom5760@4775
   583
}
tom5760@4775
   584
tom5760@4782
   585
Ptr<PbbTlv>
tom5760@4782
   586
PbbPacket::TlvBack (void)
tom5760@4775
   587
{
tom5760@4775
   588
  return m_tlvList.Back ();
tom5760@4775
   589
}
tom5760@4775
   590
tom5760@4782
   591
const Ptr<PbbTlv>
tom5760@4782
   592
PbbPacket::TlvBack (void) const
tom5760@4775
   593
{
tom5760@4775
   594
  return m_tlvList.Back ();
tom5760@4775
   595
}
tom5760@4775
   596
tom5760@4775
   597
void
tom5760@4782
   598
PbbPacket::TlvPushFront (Ptr<PbbTlv> tlv)
tom5760@4775
   599
{
tom5760@4775
   600
  m_tlvList.PushFront (tlv);
tom5760@4775
   601
}
tom5760@4775
   602
tom5760@4775
   603
void
tom5760@4782
   604
PbbPacket::TlvPopFront (void)
tom5760@4775
   605
{
tom5760@4775
   606
  m_tlvList.PopFront ();
tom5760@4775
   607
}
tom5760@4775
   608
tom5760@4775
   609
void
tom5760@4782
   610
PbbPacket::TlvPushBack (Ptr<PbbTlv> tlv)
tom5760@4775
   611
{
tom5760@4775
   612
  m_tlvList.PushBack (tlv);
tom5760@4775
   613
}
tom5760@4775
   614
tom5760@4775
   615
void
tom5760@4782
   616
PbbPacket::TlvPopBack (void)
tom5760@4775
   617
{
tom5760@4775
   618
  m_tlvList.PopBack ();
tom5760@4775
   619
}
tom5760@4775
   620
tom5760@4782
   621
PbbPacket::TlvIterator
tom5760@4782
   622
PbbPacket::Erase (PbbPacket::TlvIterator position)
tom5760@4775
   623
{
tom5760@4775
   624
  return m_tlvList.Erase (position);
tom5760@4775
   625
}
tom5760@4775
   626
tom5760@4782
   627
PbbPacket::TlvIterator
tom5760@4782
   628
PbbPacket::Erase (PbbPacket::TlvIterator first, PbbPacket::TlvIterator last)
tom5760@4775
   629
{
tom5760@4775
   630
  return m_tlvList.Erase (first, last);
tom5760@4775
   631
}
tom5760@4775
   632
tom5760@4775
   633
void
tom5760@4782
   634
PbbPacket::TlvClear (void)
tom5760@4775
   635
{
tom5760@4775
   636
  m_tlvList.Clear ();
tom5760@4775
   637
}
tom5760@4775
   638
tom5760@4775
   639
/* Manipulating Packet Messages */
tom5760@4775
   640
tom5760@4782
   641
PbbPacket::MessageIterator
tom5760@4782
   642
PbbPacket::MessageBegin (void)
tom5760@4775
   643
{
tom5760@4775
   644
  return m_messageList.begin ();
tom5760@4775
   645
}
tom5760@4775
   646
tom5760@4782
   647
PbbPacket::ConstMessageIterator
tom5760@4782
   648
PbbPacket::MessageBegin (void) const
tom5760@4775
   649
{
tom5760@4775
   650
  return m_messageList.begin ();
tom5760@4775
   651
}
tom5760@4775
   652
tom5760@4782
   653
PbbPacket::MessageIterator
tom5760@4782
   654
PbbPacket::MessageEnd (void)
tom5760@4775
   655
{
tom5760@4775
   656
  return m_messageList.end ();
tom5760@4775
   657
}
tom5760@4775
   658
tom5760@4782
   659
PbbPacket::ConstMessageIterator
tom5760@4782
   660
PbbPacket::MessageEnd (void) const
tom5760@4775
   661
{
tom5760@4775
   662
  return m_messageList.end ();
tom5760@4775
   663
}
tom5760@4775
   664
tom5760@4775
   665
int
tom5760@4782
   666
PbbPacket::MessageSize (void) const
tom5760@4775
   667
{
tom5760@4775
   668
  return m_messageList.size ();
tom5760@4775
   669
}
tom5760@4775
   670
tom5760@4775
   671
bool
tom5760@4782
   672
PbbPacket::MessageEmpty (void) const
tom5760@4775
   673
{
tom5760@4775
   674
  return m_messageList.empty ();
tom5760@4775
   675
}
tom5760@4775
   676
tom5760@4782
   677
Ptr<PbbMessage>
tom5760@4782
   678
PbbPacket::MessageFront (void)
tom5760@4775
   679
{
tom5760@4775
   680
  return m_messageList.front ();
tom5760@4775
   681
}
tom5760@4775
   682
tom5760@4782
   683
const Ptr<PbbMessage>
tom5760@4782
   684
PbbPacket::MessageFront (void) const
tom5760@4775
   685
{
tom5760@4775
   686
  return m_messageList.front ();
tom5760@4775
   687
}
tom5760@4775
   688
tom5760@4782
   689
Ptr<PbbMessage>
tom5760@4782
   690
PbbPacket::MessageBack (void)
tom5760@4775
   691
{
tom5760@4775
   692
  return m_messageList.back ();
tom5760@4775
   693
}
tom5760@4775
   694
tom5760@4782
   695
const Ptr<PbbMessage>
tom5760@4782
   696
PbbPacket::MessageBack (void) const
tom5760@4775
   697
{
tom5760@4775
   698
  return m_messageList.back ();
tom5760@4775
   699
}
tom5760@4775
   700
tom5760@4775
   701
void
tom5760@4782
   702
PbbPacket::MessagePushFront (Ptr<PbbMessage> tlv)
tom5760@4775
   703
{
tom5760@4775
   704
  m_messageList.push_front (tlv);
tom5760@4775
   705
}
tom5760@4775
   706
tom5760@4775
   707
void
tom5760@4782
   708
PbbPacket::MessagePopFront (void)
tom5760@4775
   709
{
tom5760@4775
   710
  m_messageList.pop_front ();
tom5760@4775
   711
}
tom5760@4775
   712
tom5760@4775
   713
void
tom5760@4782
   714
PbbPacket::MessagePushBack (Ptr<PbbMessage> tlv)
tom5760@4775
   715
{
tom5760@4775
   716
  m_messageList.push_back (tlv);
tom5760@4775
   717
}
tom5760@4775
   718
tom5760@4775
   719
void
tom5760@4782
   720
PbbPacket::MessagePopBack (void)
tom5760@4775
   721
{
tom5760@4775
   722
  m_messageList.pop_back ();
tom5760@4775
   723
}
tom5760@4775
   724
tom5760@4782
   725
PbbPacket::MessageIterator
tom5760@4782
   726
PbbPacket::Erase (PbbPacket::MessageIterator position)
tom5760@4775
   727
{
tom5760@4775
   728
  return m_messageList.erase (position);
tom5760@4775
   729
}
tom5760@4775
   730
tom5760@4782
   731
PbbPacket::MessageIterator
tom5760@4782
   732
PbbPacket::Erase (PbbPacket::MessageIterator first,
tom5760@4782
   733
    PbbPacket::MessageIterator last)
tom5760@4775
   734
{
tom5760@4775
   735
  return m_messageList.erase (first, last);
tom5760@4775
   736
}
tom5760@4775
   737
tom5760@4775
   738
void
tom5760@4782
   739
PbbPacket::MessageClear (void)
tom5760@4775
   740
{
tom5760@5263
   741
  for (MessageIterator iter = MessageBegin (); iter != MessageEnd (); iter++)
tom5760@5263
   742
    {
tom5760@5263
   743
      *iter = 0;
tom5760@5263
   744
    }
tom5760@4775
   745
  m_messageList.clear ();
tom5760@4775
   746
}
tom5760@4775
   747
tom5760@4775
   748
tom5760@4775
   749
TypeId
tom5760@4782
   750
PbbPacket::GetTypeId (void)
tom5760@4775
   751
{
vincent@5225
   752
  static TypeId tid = TypeId ("ns3::PbbPacket")
tom5760@4775
   753
    .SetParent<Header> ()
tom5760@4782
   754
    .AddConstructor<PbbPacket> ()
tom5760@4775
   755
  ;
tom5760@4775
   756
  return tid;
tom5760@4775
   757
}
tom5760@4775
   758
tom5760@4775
   759
TypeId
tom5760@4782
   760
PbbPacket::GetInstanceTypeId (void) const
tom5760@4775
   761
{
tom5760@4775
   762
  return GetTypeId ();
tom5760@4775
   763
}
tom5760@4775
   764
tom5760@4775
   765
uint32_t
tom5760@4782
   766
PbbPacket::GetSerializedSize (void) const
tom5760@4775
   767
{
tom5760@4775
   768
  /* Version number + flags */
tom5760@4775
   769
  uint32_t size = 1;
tom5760@4775
   770
tom5760@4775
   771
  if (HasSequenceNumber())
tom5760@4776
   772
    {
tom5760@4776
   773
      size += 2;
tom5760@4776
   774
    }
tom5760@4775
   775
tom5760@4775
   776
  if (!TlvEmpty ())
tom5760@4776
   777
    {
tom5760@4776
   778
      size += m_tlvList.GetSerializedSize ();
tom5760@4776
   779
    }
tom5760@4776
   780
tom5760@4776
   781
  for (ConstMessageIterator iter = MessageBegin ();
tom5760@4776
   782
      iter != MessageEnd ();
tom5760@4775
   783
      iter++)
tom5760@4776
   784
    {
tom5760@4776
   785
      size += (*iter)->GetSerializedSize ();
tom5760@4776
   786
    }
tom5760@4775
   787
tom5760@4775
   788
  return size;
tom5760@4775
   789
}
tom5760@4775
   790
tom5760@4775
   791
void
tom5760@4782
   792
PbbPacket::Serialize (Buffer::Iterator start) const
tom5760@4775
   793
{
tom5760@4775
   794
  /* We remember the start, so we can write the flags after we check for a
tom5760@4775
   795
   * sequence number and TLV. */
tom5760@4775
   796
  Buffer::Iterator bufref = start;
tom5760@4775
   797
  start.Next ();
tom5760@4775
   798
tom5760@4775
   799
  uint8_t flags = VERSION;
tom5760@4775
   800
  /* Make room for 4 bit flags */
tom5760@4775
   801
  flags <<= 4;
tom5760@4775
   802
tom5760@4775
   803
  if (HasSequenceNumber ())
tom5760@4776
   804
    {
tom5760@4776
   805
      flags |= PHAS_SEQ_NUM;
tom5760@4776
   806
      start.WriteHtonU16 (GetSequenceNumber ());
tom5760@4776
   807
    }
tom5760@4775
   808
tom5760@4775
   809
  if (!TlvEmpty ())
tom5760@4776
   810
    {
tom5760@4776
   811
      flags |= PHAS_TLV;
tom5760@4776
   812
      m_tlvList.Serialize (start);
tom5760@4776
   813
    }
tom5760@4775
   814
tom5760@4775
   815
  bufref.WriteU8(flags);
tom5760@4775
   816
tom5760@4775
   817
  for (ConstMessageIterator iter = MessageBegin ();
tom5760@4775
   818
      iter != MessageEnd ();
tom5760@4775
   819
      iter++)
tom5760@4776
   820
    {
tom5760@4776
   821
      (*iter)->Serialize (start);
tom5760@4776
   822
    }
tom5760@4775
   823
}
tom5760@4775
   824
tom5760@4775
   825
uint32_t
tom5760@4782
   826
PbbPacket::Deserialize (Buffer::Iterator start)
tom5760@4775
   827
{
tom5760@4775
   828
  Buffer::Iterator begin = start;
tom5760@4775
   829
tom5760@4775
   830
  uint8_t flags = start.ReadU8 ();
tom5760@4775
   831
tom5760@4775
   832
  if (flags & PHAS_SEQ_NUM)
tom5760@4776
   833
    {
tom5760@4776
   834
      SetSequenceNumber (start.ReadNtohU16 ());
tom5760@4776
   835
    }
tom5760@4775
   836
tom5760@4775
   837
  if (flags & PHAS_TLV)
tom5760@4776
   838
    {
tom5760@4776
   839
      m_tlvList.Deserialize (start);
tom5760@4776
   840
    }
tom5760@4775
   841
tom5760@4775
   842
  while (!start.IsEnd())
tom5760@4776
   843
    {
tom5760@4782
   844
      Ptr<PbbMessage> newmsg = PbbMessage::DeserializeMessage (start);
tom5760@4776
   845
      if (newmsg == 0)
tom5760@4776
   846
        {
tom5760@4776
   847
          return start.GetDistanceFrom (begin);
tom5760@4776
   848
        }
tom5760@4776
   849
      MessagePushBack (newmsg);
tom5760@4776
   850
    }
tom5760@4775
   851
tom5760@4775
   852
  flags >>= 4;
tom5760@4775
   853
  m_version = flags;
tom5760@4775
   854
tom5760@4775
   855
  return start.GetDistanceFrom (begin);
tom5760@4775
   856
}
tom5760@4775
   857
tom5760@4775
   858
void
tom5760@4782
   859
PbbPacket::Print (std::ostream &os) const
tom5760@4775
   860
{
tom5760@4782
   861
  os << "PbbPacket {" << std::endl;
tom5760@4775
   862
tom5760@4775
   863
  if (HasSequenceNumber ())
tom5760@4776
   864
    {
tom5760@4776
   865
      os << "\tsequence number = " << GetSequenceNumber ();
tom5760@4776
   866
    }
tom5760@4775
   867
tom5760@4775
   868
  os << std::endl;
tom5760@4775
   869
tom5760@4775
   870
  m_tlvList.Print (os, 1);
tom5760@4775
   871
tom5760@4775
   872
  for (ConstMessageIterator iter = MessageBegin ();
tom5760@4775
   873
      iter != MessageEnd ();
tom5760@4775
   874
      iter++)
tom5760@4776
   875
    {
tom5760@4776
   876
      (*iter)->Print (os, 1);
tom5760@4776
   877
    }
tom5760@4775
   878
tom5760@4775
   879
  os << "}" << std::endl;
tom5760@4775
   880
}
tom5760@4775
   881
tom5760@4775
   882
bool
tom5760@4782
   883
PbbPacket::operator== (const PbbPacket &other) const
tom5760@4775
   884
{
tom5760@4775
   885
  if (GetVersion () != other.GetVersion ())
tom5760@4776
   886
    {
tom5760@4776
   887
      return false;
tom5760@4776
   888
    }
tom5760@4775
   889
tom5760@4775
   890
  if (HasSequenceNumber () != other.HasSequenceNumber ())
tom5760@4776
   891
    {
tom5760@4776
   892
      return false;
tom5760@4776
   893
    }
tom5760@4775
   894
tom5760@4775
   895
  if (HasSequenceNumber ())
tom5760@4776
   896
    {
tom5760@4776
   897
      if (GetSequenceNumber () != other.GetSequenceNumber ())
tom5760@4776
   898
        return false;
tom5760@4776
   899
    }
tom5760@4776
   900
tom5760@4776
   901
  if (m_tlvList != other.m_tlvList)
tom5760@4776
   902
    {
tom5760@4775
   903
      return false;
tom5760@4776
   904
    }
tom5760@4775
   905
tom5760@4775
   906
  if (MessageSize () != other.MessageSize ())
tom5760@4776
   907
    {
tom5760@4776
   908
        return false;
tom5760@4776
   909
    }
tom5760@4775
   910
tom5760@4775
   911
  ConstMessageIterator tmi, omi;
tom5760@4775
   912
  for (tmi = MessageBegin (), omi = other.MessageBegin ();
tom5760@4775
   913
    tmi != MessageEnd () && omi != other.MessageEnd ();
tom5760@4775
   914
    tmi++, omi++)
tom5760@4776
   915
    {
tom5760@4776
   916
      if (**tmi != **omi)
tom5760@4776
   917
        {
tom5760@4776
   918
          return false;
tom5760@4776
   919
        }
tom5760@4776
   920
    }
tom5760@4775
   921
  return true;
tom5760@4775
   922
}
tom5760@4775
   923
tom5760@4775
   924
bool
tom5760@4782
   925
PbbPacket::operator!= (const PbbPacket &other) const
tom5760@4775
   926
{
tom5760@4775
   927
  return !(*this == other);
tom5760@4775
   928
}
tom5760@4775
   929
tom5760@4782
   930
/* End PbbPacket class */
tom5760@4782
   931
craigdo@4790
   932
PbbMessage::PbbMessage ()
tom5760@4775
   933
{
tom5760@4775
   934
  /* Default to IPv4 */
tom5760@4775
   935
  m_addrSize = IPV4;
tom5760@4775
   936
  m_hasOriginatorAddress = false;
tom5760@4775
   937
  m_hasHopLimit = false;
tom5760@4775
   938
  m_hasHopCount = false;
tom5760@4775
   939
  m_hasSequenceNumber = false;
tom5760@4775
   940
}
tom5760@4775
   941
craigdo@4790
   942
PbbMessage::~PbbMessage ()
craigdo@4790
   943
{
tom5760@5263
   944
  AddressBlockClear ();
craigdo@4790
   945
}
craigdo@4790
   946
tom5760@4775
   947
void
tom5760@4782
   948
PbbMessage::SetType (uint8_t type)
tom5760@4775
   949
{
tom5760@4775
   950
  m_type = type;
tom5760@4775
   951
}
tom5760@4775
   952
tom5760@4775
   953
uint8_t
tom5760@4782
   954
PbbMessage::GetType (void) const
tom5760@4775
   955
{
tom5760@4775
   956
  return m_type;
tom5760@4775
   957
}
tom5760@4775
   958
tom5760@4783
   959
PbbAddressLength
tom5760@4782
   960
PbbMessage::GetAddressLength (void) const
tom5760@4775
   961
{
tom5760@4775
   962
  return m_addrSize;
tom5760@4775
   963
}
tom5760@4775
   964
tom5760@4775
   965
void
tom5760@4782
   966
PbbMessage::SetOriginatorAddress (Address address)
tom5760@4775
   967
{
tom5760@4775
   968
  m_originatorAddress = address;
tom5760@4775
   969
  m_hasOriginatorAddress = true;
tom5760@4775
   970
}
tom5760@4775
   971
tom5760@4775
   972
Address
tom5760@4782
   973
PbbMessage::GetOriginatorAddress (void) const
tom5760@4775
   974
{
tom5760@4780
   975
  NS_ASSERT (HasOriginatorAddress ());
tom5760@4775
   976
  return m_originatorAddress;
tom5760@4775
   977
}
tom5760@4775
   978
tom5760@4775
   979
bool
tom5760@4782
   980
PbbMessage::HasOriginatorAddress (void) const
tom5760@4775
   981
{
tom5760@4775
   982
  return m_hasOriginatorAddress;
tom5760@4775
   983
}
tom5760@4775
   984
tom5760@4775
   985
void
tom5760@4782
   986
PbbMessage::SetHopLimit (uint8_t hopLimit)
tom5760@4775
   987
{
tom5760@4775
   988
  m_hopLimit = hopLimit;
tom5760@4775
   989
  m_hasHopLimit = true;
tom5760@4775
   990
}
tom5760@4775
   991
tom5760@4775
   992
uint8_t
tom5760@4782
   993
PbbMessage::GetHopLimit (void) const
tom5760@4775
   994
{
tom5760@4780
   995
  NS_ASSERT (HasHopLimit ());
tom5760@4775
   996
  return m_hopLimit;
tom5760@4775
   997
}
tom5760@4775
   998
tom5760@4775
   999
bool
tom5760@4782
  1000
PbbMessage::HasHopLimit (void) const
tom5760@4775
  1001
{
tom5760@4775
  1002
  return m_hasHopLimit;
tom5760@4775
  1003
}
tom5760@4775
  1004
tom5760@4775
  1005
void
tom5760@4782
  1006
PbbMessage::SetHopCount (uint8_t hopCount)
tom5760@4775
  1007
{
tom5760@4775
  1008
  m_hopCount = hopCount;
tom5760@4775
  1009
  m_hasHopCount = true;
tom5760@4775
  1010
}
tom5760@4775
  1011
tom5760@4775
  1012
uint8_t
tom5760@4782
  1013
PbbMessage::GetHopCount (void) const
tom5760@4775
  1014
{
tom5760@4780
  1015
  NS_ASSERT (HasHopCount ());
tom5760@4775
  1016
  return m_hopCount;
tom5760@4775
  1017
}
tom5760@4775
  1018
tom5760@4775
  1019
bool
tom5760@4782
  1020
PbbMessage::HasHopCount (void) const
tom5760@4775
  1021
{
tom5760@4775
  1022
  return m_hasHopCount;
tom5760@4775
  1023
}
tom5760@4775
  1024
tom5760@4775
  1025
void
tom5760@4782
  1026
PbbMessage::SetSequenceNumber (uint16_t sequenceNumber)
tom5760@4775
  1027
{
tom5760@4775
  1028
  m_sequenceNumber = sequenceNumber;
tom5760@4775
  1029
  m_hasSequenceNumber = true;
tom5760@4775
  1030
}
tom5760@4775
  1031
tom5760@4775
  1032
uint16_t
tom5760@4782
  1033
PbbMessage::GetSequenceNumber (void) const
tom5760@4775
  1034
{
tom5760@4780
  1035
  NS_ASSERT (HasSequenceNumber ());
tom5760@4775
  1036
  return m_sequenceNumber;
tom5760@4775
  1037
}
tom5760@4775
  1038
tom5760@4775
  1039
bool
tom5760@4782
  1040
PbbMessage::HasSequenceNumber (void) const
tom5760@4775
  1041
{
tom5760@4775
  1042
  return m_hasSequenceNumber;
tom5760@4775
  1043
}
tom5760@4775
  1044
tom5760@4782
  1045
/* Manipulating PbbMessage TLVs */
tom5760@4782
  1046
tom5760@4782
  1047
PbbMessage::TlvIterator
tom5760@4782
  1048
PbbMessage::TlvBegin (void)
tom5760@4775
  1049
{
tom5760@4775
  1050
  return m_tlvList.Begin();
tom5760@4775
  1051
}
tom5760@4775
  1052
tom5760@4782
  1053
PbbMessage::ConstTlvIterator
tom5760@4782
  1054
PbbMessage::TlvBegin (void) const
tom5760@4775
  1055
{
tom5760@4775
  1056
  return m_tlvList.Begin();
tom5760@4775
  1057
}
tom5760@4775
  1058
tom5760@4782
  1059
PbbMessage::TlvIterator
tom5760@4782
  1060
PbbMessage::TlvEnd (void)
tom5760@4775
  1061
{
tom5760@4775
  1062
  return m_tlvList.End();
tom5760@4775
  1063
}
tom5760@4775
  1064
tom5760@4782
  1065
PbbMessage::ConstTlvIterator
tom5760@4782
  1066
PbbMessage::TlvEnd (void) const
tom5760@4775
  1067
{
tom5760@4775
  1068
  return m_tlvList.End();
tom5760@4775
  1069
}
tom5760@4775
  1070
tom5760@4775
  1071
int
tom5760@4782
  1072
PbbMessage::TlvSize (void) const
tom5760@4775
  1073
{
tom5760@4775
  1074
  return m_tlvList.Size();
tom5760@4775
  1075
}
tom5760@4775
  1076
tom5760@4775
  1077
bool
tom5760@4782
  1078
PbbMessage::TlvEmpty (void) const
tom5760@4775
  1079
{
tom5760@4775
  1080
  return m_tlvList.Empty();
tom5760@4775
  1081
}
tom5760@4775
  1082
tom5760@4782
  1083
Ptr<PbbTlv>
tom5760@4782
  1084
PbbMessage::TlvFront (void)
tom5760@4775
  1085
{
tom5760@4775
  1086
  return m_tlvList.Front();
tom5760@4775
  1087
}
tom5760@4775
  1088
tom5760@4782
  1089
const Ptr<PbbTlv>
tom5760@4782
  1090
PbbMessage::TlvFront (void) const
tom5760@4775
  1091
{
tom5760@4775
  1092
  return m_tlvList.Front();
tom5760@4775
  1093
}
tom5760@4775
  1094
tom5760@4782
  1095
Ptr<PbbTlv>
tom5760@4782
  1096
PbbMessage::TlvBack (void)
tom5760@4775
  1097
{
tom5760@4775
  1098
  return m_tlvList.Back();
tom5760@4775
  1099
}
tom5760@4775
  1100
tom5760@4782
  1101
const Ptr<PbbTlv>
tom5760@4782
  1102
PbbMessage::TlvBack (void) const
tom5760@4775
  1103
{
tom5760@4775
  1104
  return m_tlvList.Back();
tom5760@4775
  1105
}
tom5760@4775
  1106
tom5760@4775
  1107
void
tom5760@4782
  1108
PbbMessage::TlvPushFront (Ptr<PbbTlv> tlv)
tom5760@4775
  1109
{
tom5760@4775
  1110
  m_tlvList.PushFront(tlv);
tom5760@4775
  1111
}
tom5760@4775
  1112
tom5760@4775
  1113
void
tom5760@4782
  1114
PbbMessage::TlvPopFront (void)
tom5760@4775
  1115
{
tom5760@4775
  1116
  m_tlvList.PopFront();
tom5760@4775
  1117
}
tom5760@4775
  1118
tom5760@4775
  1119
void
tom5760@4782
  1120
PbbMessage::TlvPushBack (Ptr<PbbTlv> tlv)
tom5760@4775
  1121
{
tom5760@4775
  1122
  m_tlvList.PushBack(tlv);
tom5760@4775
  1123
}
tom5760@4775
  1124
tom5760@4775
  1125
void
tom5760@4782
  1126
PbbMessage::TlvPopBack (void)
tom5760@4775
  1127
{
tom5760@4775
  1128
  m_tlvList.PopBack();
tom5760@4775
  1129
}
tom5760@4775
  1130
tom5760@4782
  1131
PbbMessage::TlvIterator
tom5760@4782
  1132
PbbMessage::TlvErase (PbbMessage::TlvIterator position)
tom5760@4775
  1133
{
tom5760@4775
  1134
  return m_tlvList.Erase(position);
tom5760@4775
  1135
}
tom5760@4775
  1136
tom5760@4782
  1137
PbbMessage::TlvIterator
tom5760@4782
  1138
PbbMessage::TlvErase (PbbMessage::TlvIterator first, PbbMessage::TlvIterator last)
tom5760@4775
  1139
{
tom5760@4775
  1140
  return m_tlvList.Erase(first, last);
tom5760@4775
  1141
}
tom5760@4775
  1142
tom5760@4775
  1143
void
tom5760@4782
  1144
PbbMessage::TlvClear (void)
tom5760@4775
  1145
{
tom5760@5263
  1146
  m_tlvList.Clear();
tom5760@4775
  1147
}
tom5760@4775
  1148
tom5760@4775
  1149
/* Manipulating Address Block and Address TLV pairs */
tom5760@4775
  1150
tom5760@4782
  1151
PbbMessage::AddressBlockIterator
tom5760@4782
  1152
PbbMessage::AddressBlockBegin (void)
tom5760@4775
  1153
{
tom5760@4775
  1154
  return m_addressBlockList.begin();
tom5760@4775
  1155
}
tom5760@4775
  1156
tom5760@4782
  1157
PbbMessage::ConstAddressBlockIterator
tom5760@4782
  1158
PbbMessage::AddressBlockBegin (void) const
tom5760@4775
  1159
{
tom5760@4775
  1160
  return m_addressBlockList.begin();
tom5760@4775
  1161
}
tom5760@4775
  1162
tom5760@4782
  1163
PbbMessage::AddressBlockIterator
tom5760@4782
  1164
PbbMessage::AddressBlockEnd (void)
tom5760@4775
  1165
{
tom5760@4775
  1166
  return m_addressBlockList.end();
tom5760@4775
  1167
}
tom5760@4775
  1168
tom5760@4782
  1169
PbbMessage::ConstAddressBlockIterator
tom5760@4782
  1170
PbbMessage::AddressBlockEnd (void) const
tom5760@4775
  1171
{
tom5760@4775
  1172
  return m_addressBlockList.end();
tom5760@4775
  1173
}
tom5760@4775
  1174
tom5760@4775
  1175
int
tom5760@4782
  1176
PbbMessage::AddressBlockSize (void) const
tom5760@4775
  1177
{
tom5760@4775
  1178
  return m_addressBlockList.size();
tom5760@4775
  1179
}
tom5760@4775
  1180
tom5760@4775
  1181
bool
tom5760@4782
  1182
PbbMessage::AddressBlockEmpty (void) const
tom5760@4775
  1183
{
tom5760@4775
  1184
  return m_addressBlockList.empty();
tom5760@4775
  1185
}
tom5760@4775
  1186
tom5760@4782
  1187
Ptr<PbbAddressBlock>
tom5760@4782
  1188
PbbMessage::AddressBlockFront (void)
tom5760@4775
  1189
{
tom5760@4775
  1190
  return m_addressBlockList.front();
tom5760@4775
  1191
}
tom5760@4775
  1192
tom5760@4782
  1193
const Ptr<PbbAddressBlock>
tom5760@4782
  1194
PbbMessage::AddressBlockFront (void) const
tom5760@4775
  1195
{
tom5760@4775
  1196
  return m_addressBlockList.front();
tom5760@4775
  1197
}
tom5760@4775
  1198
tom5760@4782
  1199
Ptr<PbbAddressBlock>
tom5760@4782
  1200
PbbMessage::AddressBlockBack (void)
tom5760@4775
  1201
{
tom5760@4775
  1202
  return m_addressBlockList.back();
tom5760@4775
  1203
}
tom5760@4775
  1204
tom5760@4782
  1205
const Ptr<PbbAddressBlock>
tom5760@4782
  1206
PbbMessage::AddressBlockBack (void) const
tom5760@4775
  1207
{
tom5760@4775
  1208
  return m_addressBlockList.back();
tom5760@4775
  1209
}
tom5760@4775
  1210
tom5760@4775
  1211
void
tom5760@4782
  1212
PbbMessage::AddressBlockPushFront (Ptr<PbbAddressBlock> tlv)
tom5760@4775
  1213
{
tom5760@4775
  1214
  m_addressBlockList.push_front(tlv);
tom5760@4775
  1215
}
tom5760@4775
  1216
tom5760@4775
  1217
void
tom5760@4782
  1218
PbbMessage::AddressBlockPopFront (void)
tom5760@4775
  1219
{
tom5760@4775
  1220
  m_addressBlockList.pop_front();
tom5760@4775
  1221
}
tom5760@4775
  1222
tom5760@4775
  1223
void
tom5760@4782
  1224
PbbMessage::AddressBlockPushBack (Ptr<PbbAddressBlock> tlv)
tom5760@4775
  1225
{
tom5760@4775
  1226
  m_addressBlockList.push_back(tlv);
tom5760@4775
  1227
}
tom5760@4775
  1228
tom5760@4775
  1229
void
tom5760@4782
  1230
PbbMessage::AddressBlockPopBack (void)
tom5760@4775
  1231
{
tom5760@4775
  1232
  m_addressBlockList.pop_back();
tom5760@4775
  1233
}
tom5760@4775
  1234
tom5760@4782
  1235
PbbMessage::AddressBlockIterator
tom5760@4782
  1236
PbbMessage::AddressBlockErase (PbbMessage::AddressBlockIterator position)
tom5760@4775
  1237
{
tom5760@4775
  1238
  return m_addressBlockList.erase(position);
tom5760@4775
  1239
}
tom5760@4775
  1240
tom5760@4782
  1241
PbbMessage::AddressBlockIterator
tom5760@4782
  1242
PbbMessage::AddressBlockErase (PbbMessage::AddressBlockIterator first,
tom5760@4782
  1243
    PbbMessage::AddressBlockIterator last)
tom5760@4775
  1244
{
tom5760@4775
  1245
  return m_addressBlockList.erase(first, last);
tom5760@4775
  1246
}
tom5760@4775
  1247
tom5760@4775
  1248
void
tom5760@4782
  1249
PbbMessage::AddressBlockClear (void)
tom5760@4775
  1250
{
tom5760@5263
  1251
  for (AddressBlockIterator iter = AddressBlockBegin ();
tom5760@5263
  1252
      iter != AddressBlockEnd ();
tom5760@5263
  1253
      iter++)
tom5760@5263
  1254
    {
tom5760@5263
  1255
      *iter = 0;
tom5760@5263
  1256
    }
tom5760@4775
  1257
  return m_addressBlockList.clear();
tom5760@4775
  1258
}
tom5760@4775
  1259
tom5760@4775
  1260
uint32_t
tom5760@4782
  1261
PbbMessage::GetSerializedSize (void) const
tom5760@4775
  1262
{
tom5760@4775
  1263
  /* msg-type + (msg-flags + msg-addr-length) + 2msg-size */
tom5760@4775
  1264
  uint32_t size = 4;
tom5760@4775
  1265
tom5760@4775
  1266
  if (HasOriginatorAddress())
tom5760@4776
  1267
    {
tom5760@4776
  1268
      size += GetAddressLength() + 1;
tom5760@4776
  1269
    }
tom5760@4775
  1270
tom5760@4775
  1271
  if (HasHopLimit())
tom5760@4776
  1272
    {
tom5760@4776
  1273
      size++;
tom5760@4776
  1274
    }
tom5760@4775
  1275
tom5760@4775
  1276
  if (HasHopCount())
tom5760@4776
  1277
    {
tom5760@4776
  1278
      size++;
tom5760@4776
  1279
    }
tom5760@4775
  1280
tom5760@4775
  1281
  if (HasSequenceNumber())
tom5760@4776
  1282
    {
tom5760@4776
  1283
      size += 2;
tom5760@4776
  1284
    }
tom5760@4775
  1285
tom5760@4775
  1286
  size += m_tlvList.GetSerializedSize ();
tom5760@4775
  1287
tom5760@4775
  1288
  for (ConstAddressBlockIterator iter = AddressBlockBegin ();
tom5760@4775
  1289
      iter != AddressBlockEnd ();
tom5760@4775
  1290
      iter++)
tom5760@4776
  1291
    {
tom5760@4776
  1292
      size += (*iter)->GetSerializedSize ();
tom5760@4776
  1293
    }
tom5760@4775
  1294
tom5760@4775
  1295
  return size;
tom5760@4775
  1296
}
tom5760@4775
  1297
tom5760@4775
  1298
void
tom5760@4782
  1299
PbbMessage::Serialize (Buffer::Iterator &start) const
tom5760@4775
  1300
{
tom5760@4775
  1301
  Buffer::Iterator front = start;
tom5760@4775
  1302
tom5760@4775
  1303
  start.WriteU8 (GetType());
tom5760@4775
  1304
tom5760@4775
  1305
  /* Save a reference to the spot where we will later write the flags */
tom5760@4775
  1306
  Buffer::Iterator bufref = start;
tom5760@4775
  1307
  start.Next (1);
tom5760@4775
  1308
tom5760@4775
  1309
  uint8_t flags = 0;
tom5760@4775
  1310
tom5760@4775
  1311
  flags = GetAddressLength ();
tom5760@4775
  1312
tom5760@4775
  1313
  Buffer::Iterator sizeref = start;
tom5760@4775
  1314
  start.Next (2);
tom5760@4775
  1315
tom5760@4775
  1316
  if (HasOriginatorAddress ())
tom5760@4776
  1317
    {
tom5760@4776
  1318
      flags |= MHAS_ORIG;
tom5760@4776
  1319
      SerializeOriginatorAddress (start);
tom5760@4776
  1320
    }
tom5760@4775
  1321
tom5760@4775
  1322
  if (HasHopLimit ())
tom5760@4776
  1323
    {
tom5760@4776
  1324
      flags |= MHAS_HOP_LIMIT;
tom5760@4776
  1325
      start.WriteU8 (GetHopLimit ());
tom5760@4776
  1326
    }
tom5760@4775
  1327
tom5760@4775
  1328
  if (HasHopCount ())
tom5760@4776
  1329
    {
tom5760@4776
  1330
      flags |= MHAS_HOP_COUNT;
tom5760@4776
  1331
      start.WriteU8 (GetHopCount ());
tom5760@4776
  1332
    }
tom5760@4775
  1333
tom5760@4775
  1334
  if (HasSequenceNumber ())
tom5760@4776
  1335
    {
tom5760@4776
  1336
      flags |= MHAS_SEQ_NUM;
tom5760@4776
  1337
      start.WriteHtonU16 (GetSequenceNumber ());
tom5760@4776
  1338
    }
tom5760@4775
  1339
tom5760@4775
  1340
  bufref.WriteU8(flags);
tom5760@4775
  1341
tom5760@4775
  1342
  m_tlvList.Serialize (start);
tom5760@4775
  1343
tom5760@4775
  1344
  for (ConstAddressBlockIterator iter = AddressBlockBegin ();
tom5760@4775
  1345
      iter != AddressBlockEnd ();
tom5760@4775
  1346
      iter++)
tom5760@4776
  1347
    {
tom5760@4776
  1348
      (*iter)->Serialize (start);
tom5760@4776
  1349
    }
tom5760@4775
  1350
tom5760@4775
  1351
  sizeref.WriteHtonU16 (front.GetDistanceFrom (start));
tom5760@4775
  1352
}
tom5760@4775
  1353
tom5760@4782
  1354
Ptr<PbbMessage>
tom5760@4782
  1355
PbbMessage::DeserializeMessage (Buffer::Iterator &start)
tom5760@4775
  1356
{
tom5760@4775
  1357
  /* We need to read the msg-addr-len field to determine what kind of object to
tom5760@4775
  1358
   * construct. */
tom5760@4775
  1359
  start.Next ();
tom5760@4775
  1360
  uint8_t addrlen = start.ReadU8 ();
tom5760@4775
  1361
  start.Prev (2); /* Go back to the start */
tom5760@4775
  1362
tom5760@4775
  1363
  /* The first four bytes of the flag is the address length.  Set the last four
tom5760@4775
  1364
   * bytes to 0 to read it. */
tom5760@4775
  1365
  addrlen = (addrlen & 0xf);
tom5760@4775
  1366
tom5760@4782
  1367
  Ptr<PbbMessage> newmsg;
tom5760@4775
  1368
tom5760@4775
  1369
  switch (addrlen)
tom5760@4776
  1370
    {
tom5760@4776
  1371
      case 0:
tom5760@4776
  1372
      case IPV4:
tom5760@4782
  1373
        newmsg = Create<PbbMessageIpv4> ();
tom5760@4776
  1374
        break;
tom5760@4776
  1375
      case IPV6:
tom5760@4782
  1376
        newmsg = Create<PbbMessageIpv6> ();
tom5760@4776
  1377
        break;
tom5760@4776
  1378
      default:
tom5760@4776
  1379
        return 0;
tom5760@4776
  1380
        break;
tom5760@4776
  1381
    }
tom5760@4775
  1382
  newmsg->Deserialize (start);
tom5760@4775
  1383
  return newmsg;
tom5760@4775
  1384
}
tom5760@4775
  1385
tom5760@4775
  1386
void
tom5760@4782
  1387
PbbMessage::Deserialize (Buffer::Iterator &start)
tom5760@4775
  1388
{
tom5760@4775
  1389
  Buffer::Iterator front = start;
tom5760@4775
  1390
  SetType (start.ReadU8 ());
tom5760@4775
  1391
  uint8_t flags = start.ReadU8 ();
tom5760@4775
  1392
tom5760@4775
  1393
  uint16_t size = start.ReadNtohU16 ();
tom5760@4775
  1394
tom5760@4775
  1395
  if (flags & MHAS_ORIG)
tom5760@4776
  1396
    {
tom5760@4776
  1397
      SetOriginatorAddress (DeserializeOriginatorAddress (start));
tom5760@4776
  1398
    }
tom5760@4775
  1399
tom5760@4775
  1400
  if (flags & MHAS_HOP_LIMIT)
tom5760@4776
  1401
    {
tom5760@4776
  1402
      SetHopLimit (start.ReadU8 ());
tom5760@4776
  1403
    }
tom5760@4775
  1404
tom5760@4775
  1405
  if (flags & MHAS_HOP_COUNT)
tom5760@4776
  1406
    {
tom5760@4776
  1407
      SetHopCount (start.ReadU8 ());
tom5760@4776
  1408
    }
tom5760@4775
  1409
tom5760@4775
  1410
  if (flags & MHAS_SEQ_NUM)
tom5760@4776
  1411
    {
tom5760@4776
  1412
      SetSequenceNumber (start.ReadNtohU16 ());
tom5760@4776
  1413
    }
tom5760@4775
  1414
tom5760@4775
  1415
  m_tlvList.Deserialize (start);
tom5760@4775
  1416
tom5760@4775
  1417
  if (size > 0)
tom5760@4775
  1418
    {
tom5760@4776
  1419
      while (start.GetDistanceFrom(front) < size)
tom5760@4776
  1420
        {
tom5760@4782
  1421
          Ptr<PbbAddressBlock> newab = AddressBlockDeserialize (start);
tom5760@4776
  1422
          AddressBlockPushBack (newab);
tom5760@4776
  1423
        }
tom5760@4775
  1424
    }
tom5760@4775
  1425
}
tom5760@4775
  1426
tom5760@4775
  1427
void
tom5760@4782
  1428
PbbMessage::Print (std::ostream &os) const
tom5760@4775
  1429
{
tom5760@4775
  1430
  Print (os, 0);
tom5760@4775
  1431
}
tom5760@4775
  1432
tom5760@4775
  1433
void
tom5760@4782
  1434
PbbMessage::Print (std::ostream &os, int level) const
tom5760@4775
  1435
{
tom5760@4775
  1436
  std::string prefix = "";
tom5760@4775
  1437
  for (int i = 0; i < level; i++)
tom5760@4776
  1438
    {
tom5760@4776
  1439
      prefix.append ("\t");
tom5760@4776
  1440
    }
tom5760@4775
  1441
tom5760@4782
  1442
  os << prefix << "PbbMessage {" << std::endl;
tom5760@4775
  1443
tom5760@4775
  1444
  os << prefix << "\tmessage type = " << (int)GetType () << std::endl;
tom5760@4775
  1445
  os << prefix << "\taddress size = " << GetAddressLength () << std::endl;
tom5760@4775
  1446
tom5760@4775
  1447
  if (HasOriginatorAddress ())
tom5760@4776
  1448
    {
tom5760@4776
  1449
      os << prefix << "\toriginator address = ";
tom5760@4776
  1450
      PrintOriginatorAddress (os);
tom5760@4776
  1451
      os << std::endl;
tom5760@4776
  1452
    }
tom5760@4775
  1453
tom5760@4775
  1454
  if (HasHopLimit ())
tom5760@4776
  1455
    {
tom5760@4776
  1456
      os << prefix << "\thop limit = " << (int)GetHopLimit () << std::endl;
tom5760@4776
  1457
    }
tom5760@4775
  1458
tom5760@4775
  1459
  if (HasHopCount ())
tom5760@4776
  1460
    {
tom5760@4776
  1461
      os << prefix << "\thop count = " << (int)GetHopCount () << std::endl;
tom5760@4776
  1462
    }
tom5760@4775
  1463
tom5760@4775
  1464
  if (HasSequenceNumber ())
tom5760@4776
  1465
    {
tom5760@4776
  1466
      os << prefix << "\tseqnum = " << GetSequenceNumber () << std::endl;
tom5760@4776
  1467
    }
tom5760@4775
  1468
tom5760@4775
  1469
  m_tlvList.Print (os, level+1);
tom5760@4775
  1470
tom5760@4775
  1471
  for (ConstAddressBlockIterator iter = AddressBlockBegin ();
tom5760@4775
  1472
      iter != AddressBlockEnd ();
tom5760@4775
  1473
      iter++)
tom5760@4776
  1474
    {
tom5760@4776
  1475
      (*iter)->Print (os, level+1);
tom5760@4776
  1476
    }
tom5760@4775
  1477
  os << prefix << "}" << std::endl;
tom5760@4775
  1478
}
tom5760@4775
  1479
tom5760@4775
  1480
bool
tom5760@4782
  1481
PbbMessage::operator== (const PbbMessage &other) const
tom5760@4775
  1482
{
tom5760@4775
  1483
  if (GetAddressLength () != other.GetAddressLength ())
tom5760@4776
  1484
    {
tom5760@4776
  1485
      return false;
tom5760@4776
  1486
    }
tom5760@4775
  1487
tom5760@4775
  1488
  if (GetType () != other.GetType ())
tom5760@4776
  1489
    {
tom5760@4776
  1490
      return false;
tom5760@4776
  1491
    }
tom5760@4775
  1492
tom5760@4775
  1493
  if (HasOriginatorAddress () != other.HasOriginatorAddress ())
tom5760@4776
  1494
    {
tom5760@4776
  1495
      return false;
tom5760@4776
  1496
    }
tom5760@4775
  1497
tom5760@4775
  1498
  if (HasOriginatorAddress ())
tom5760@4776
  1499
    {
tom5760@4776
  1500
      if (GetOriginatorAddress () != other.GetOriginatorAddress ())
tom5760@4776
  1501
        {
tom5760@4776
  1502
          return false;
tom5760@4776
  1503
        }
tom5760@4776
  1504
    }
tom5760@4776
  1505
tom5760@4776
  1506
  if (HasHopLimit () != other.HasHopLimit ())
tom5760@4776
  1507
    {
tom5760@4775
  1508
      return false;
tom5760@4776
  1509
    }
tom5760@4775
  1510
tom5760@4775
  1511
  if (HasHopLimit ())
tom5760@4776
  1512
    {
tom5760@4776
  1513
      if (GetHopLimit () != other.GetHopLimit ())
tom5760@4776
  1514
        {
tom5760@4776
  1515
          return false;
tom5760@4776
  1516
        }
tom5760@4776
  1517
    }
tom5760@4776
  1518
tom5760@4776
  1519
  if (HasHopCount () != other.HasHopCount ())
tom5760@4776
  1520
    {
tom5760@4775
  1521
      return false;
tom5760@4776
  1522
    }
tom5760@4775
  1523
tom5760@4775
  1524
  if (HasHopCount ())
tom5760@4776
  1525
    {
tom5760@4776
  1526
      if (GetHopCount () != other.GetHopCount ())
tom5760@4776
  1527
        {
tom5760@4776
  1528
          return false;
tom5760@4776
  1529
        }
tom5760@4776
  1530
    }
tom5760@4776
  1531
tom5760@4776
  1532
  if (HasSequenceNumber () != other.HasSequenceNumber ())
tom5760@4776
  1533
    {
tom5760@4775
  1534
      return false;
tom5760@4776
  1535
    }
tom5760@4775
  1536
tom5760@4775
  1537
  if (HasSequenceNumber ())
tom5760@4776
  1538
    {
tom5760@4776
  1539
      if (GetSequenceNumber () != other.GetSequenceNumber ())
tom5760@4776
  1540
        {
tom5760@4776
  1541
          return false;
tom5760@4776
  1542
        }
tom5760@4776
  1543
    }
tom5760@4776
  1544
tom5760@4776
  1545
  if (m_tlvList != other.m_tlvList)
tom5760@4776
  1546
    {
tom5760@4775
  1547
      return false;
tom5760@4776
  1548
    }
tom5760@4775
  1549
tom5760@4775
  1550
  if (AddressBlockSize () != other.AddressBlockSize ())
tom5760@4776
  1551
    {
tom5760@4776
  1552
      return false;
tom5760@4776
  1553
    }
tom5760@4775
  1554
tom5760@4775
  1555
  ConstAddressBlockIterator tai, oai;
tom5760@4775
  1556
  for (tai = AddressBlockBegin (), oai = other.AddressBlockBegin ();
tom5760@4775
  1557
      tai != AddressBlockEnd () && oai != other.AddressBlockEnd ();
tom5760@4775
  1558
      tai++, oai++)
tom5760@4776
  1559
    {
tom5760@4776
  1560
      if (**tai != **oai)
tom5760@4776
  1561
        {
tom5760@4776
  1562
          return false;
tom5760@4776
  1563
        }
tom5760@4776
  1564
    }
tom5760@4775
  1565
  return true;
tom5760@4775
  1566
}
tom5760@4775
  1567
tom5760@4775
  1568
bool
tom5760@4782
  1569
PbbMessage::operator!= (const PbbMessage &other) const
tom5760@4775
  1570
{
tom5760@4775
  1571
  return !(*this == other);
tom5760@4775
  1572
}
tom5760@4775
  1573
tom5760@4782
  1574
/* End PbbMessage Class */
tom5760@4775
  1575
craigdo@4790
  1576
PbbMessageIpv4::PbbMessageIpv4 ()
craigdo@4790
  1577
{
craigdo@4790
  1578
}
craigdo@4790
  1579
craigdo@4790
  1580
PbbMessageIpv4::~PbbMessageIpv4 ()
craigdo@4790
  1581
{
craigdo@4790
  1582
}
craigdo@4790
  1583
tom5760@4783
  1584
PbbAddressLength
tom5760@4782
  1585
PbbMessageIpv4::GetAddressLength (void) const
tom5760@4775
  1586
{
tom5760@4775
  1587
  return IPV4;
tom5760@4775
  1588
}
tom5760@4775
  1589
tom5760@4775
  1590
void
tom5760@4782
  1591
PbbMessageIpv4::SerializeOriginatorAddress (Buffer::Iterator &start) const
tom5760@4775
  1592
{
tom5760@4775
  1593
  uint8_t buffer[GetAddressLength () + 1];
tom5760@4775
  1594
  Ipv4Address::ConvertFrom (GetOriginatorAddress ()).Serialize(buffer);
tom5760@4775
  1595
  start.Write (buffer, GetAddressLength () + 1);
tom5760@4775
  1596
}
tom5760@4775
  1597
tom5760@4775
  1598
Address
tom5760@4782
  1599
PbbMessageIpv4::DeserializeOriginatorAddress (Buffer::Iterator &start) const
tom5760@4775
  1600
{
tom5760@4775
  1601
  uint8_t buffer[GetAddressLength () + 1];
tom5760@4775
  1602
  start.Read(buffer, GetAddressLength () + 1);
tom5760@4775
  1603
  return Ipv4Address::Deserialize (buffer);
tom5760@4775
  1604
}
tom5760@4775
  1605
tom5760@4775
  1606
void
tom5760@4782
  1607
PbbMessageIpv4::PrintOriginatorAddress (std::ostream &os) const
tom5760@4775
  1608
{
tom5760@4775
  1609
  Ipv4Address::ConvertFrom (GetOriginatorAddress ()).Print (os);
tom5760@4775
  1610
}
tom5760@4775
  1611
tom5760@4782
  1612
Ptr<PbbAddressBlock>
tom5760@4782
  1613
PbbMessageIpv4::AddressBlockDeserialize (Buffer::Iterator &start) const
tom5760@4775
  1614
{
tom5760@4782
  1615
  Ptr<PbbAddressBlock> newab = Create<PbbAddressBlockIpv4> ();
tom5760@4775
  1616
  newab->Deserialize (start);
tom5760@4775
  1617
  return newab;
tom5760@4775
  1618
}
tom5760@4775
  1619
tom5760@4782
  1620
/* End PbbMessageIpv4 Class */
tom5760@4775
  1621
craigdo@4790
  1622
PbbMessageIpv6::PbbMessageIpv6 ()
craigdo@4790
  1623
{
craigdo@4790
  1624
}
craigdo@4790
  1625
craigdo@4790
  1626
PbbMessageIpv6::~PbbMessageIpv6 ()
craigdo@4790
  1627
{
craigdo@4790
  1628
}
craigdo@4790
  1629
tom5760@4783
  1630
PbbAddressLength
tom5760@4782
  1631
PbbMessageIpv6::GetAddressLength (void) const
tom5760@4775
  1632
{
tom5760@4775
  1633
  return IPV6;
tom5760@4775
  1634
}
tom5760@4775
  1635
tom5760@4775
  1636
void
tom5760@4782
  1637
PbbMessageIpv6::SerializeOriginatorAddress (Buffer::Iterator &start) const
tom5760@4775
  1638
{
tom5760@4775
  1639
  uint8_t buffer[GetAddressLength () + 1];
tom5760@4775
  1640
  Ipv6Address::ConvertFrom (GetOriginatorAddress ()).Serialize(buffer);
tom5760@4775
  1641
  start.Write (buffer, GetAddressLength () + 1);
tom5760@4775
  1642
}
tom5760@4775
  1643
tom5760@4775
  1644
Address
tom5760@4782
  1645
PbbMessageIpv6::DeserializeOriginatorAddress (Buffer::Iterator &start) const
tom5760@4775
  1646
{
tom5760@4775
  1647
  uint8_t buffer[GetAddressLength () + 1];
tom5760@4775
  1648
  start.Read(buffer, GetAddressLength () + 1);
tom5760@4775
  1649
  return Ipv6Address::Deserialize (buffer);
tom5760@4775
  1650
}
tom5760@4775
  1651
tom5760@4775
  1652
void
tom5760@4782
  1653
PbbMessageIpv6::PrintOriginatorAddress (std::ostream &os) const
tom5760@4775
  1654
{
tom5760@4775
  1655
  Ipv6Address::ConvertFrom (GetOriginatorAddress ()).Print (os);
tom5760@4775
  1656
}
tom5760@4775
  1657
tom5760@4782
  1658
Ptr<PbbAddressBlock>
tom5760@4782
  1659
PbbMessageIpv6::AddressBlockDeserialize (Buffer::Iterator &start) const
tom5760@4775
  1660
{
tom5760@4782
  1661
  Ptr<PbbAddressBlock> newab = Create<PbbAddressBlockIpv6> ();
tom5760@4775
  1662
  newab->Deserialize (start);
tom5760@4775
  1663
  return newab;
tom5760@4775
  1664
}
tom5760@4775
  1665
tom5760@4782
  1666
/* End PbbMessageIpv6 Class */
tom5760@4782
  1667
tom5760@4782
  1668
PbbAddressBlock::PbbAddressBlock ()
mathieu@5505
  1669
{}
tom5760@4775
  1670
craigdo@4790
  1671
PbbAddressBlock::~PbbAddressBlock ()
mathieu@5505
  1672
{}
craigdo@4790
  1673
tom5760@4775
  1674
/* Manipulating the address block */
tom5760@4775
  1675
tom5760@4782
  1676
PbbAddressBlock::AddressIterator
tom5760@4782
  1677
PbbAddressBlock::AddressBegin (void)
tom5760@4775
  1678
{
tom5760@4775
  1679
  return m_addressList.begin();
tom5760@4775
  1680
}
tom5760@4775
  1681
tom5760@4782
  1682
PbbAddressBlock::ConstAddressIterator
tom5760@4782
  1683
PbbAddressBlock::AddressBegin (void) const
tom5760@4775
  1684
{
tom5760@4775
  1685
  return m_addressList.begin();
tom5760@4775
  1686
}
tom5760@4775
  1687
tom5760@4782
  1688
PbbAddressBlock::AddressIterator
tom5760@4782
  1689
PbbAddressBlock::AddressEnd (void)
tom5760@4775
  1690
{
tom5760@4775
  1691
  return m_addressList.end();
tom5760@4775
  1692
}
tom5760@4775
  1693
tom5760@4782
  1694
PbbAddressBlock::ConstAddressIterator
tom5760@4782
  1695
PbbAddressBlock::AddressEnd (void) const
tom5760@4775
  1696
{
tom5760@4775
  1697
  return m_addressList.end();
tom5760@4775
  1698
}
tom5760@4775
  1699
tom5760@4775
  1700
int
tom5760@4782
  1701
PbbAddressBlock::AddressSize (void) const
tom5760@4775
  1702
{
tom5760@4775
  1703
  return m_addressList.size();
tom5760@4775
  1704
}
tom5760@4775
  1705
tom5760@4775
  1706
bool
tom5760@4782
  1707
PbbAddressBlock::AddressEmpty (void) const
tom5760@4775
  1708
{
tom5760@4775
  1709
  return m_addressList.empty();
tom5760@4775
  1710
}
tom5760@4775
  1711
tom5760@4775
  1712
Address
tom5760@4782
  1713
PbbAddressBlock::AddressFront (void) const
tom5760@4775
  1714
{
tom5760@4775
  1715
  return m_addressList.front();
tom5760@4775
  1716
}
tom5760@4775
  1717
tom5760@4775
  1718
Address
tom5760@4782
  1719
PbbAddressBlock::AddressBack (void) const
tom5760@4775
  1720
{
tom5760@4775
  1721
  return m_addressList.back();
tom5760@4775
  1722
}
tom5760@4775
  1723
tom5760@4775
  1724
void
tom5760@4782
  1725
PbbAddressBlock::AddressPushFront (Address tlv)
tom5760@4775
  1726
{
tom5760@4775
  1727
  m_addressList.push_front(tlv);
tom5760@4775
  1728
}
tom5760@4775
  1729
tom5760@4775
  1730
void
tom5760@4782
  1731
PbbAddressBlock::AddressPopFront (void)
tom5760@4775
  1732
{
tom5760@4775
  1733
  m_addressList.pop_front();
tom5760@4775
  1734
}
tom5760@4775
  1735
tom5760@4775
  1736
void
tom5760@4782
  1737
PbbAddressBlock::AddressPushBack (Address tlv)
tom5760@4775
  1738
{
tom5760@4775
  1739
  m_addressList.push_back(tlv);
tom5760@4775
  1740
}
tom5760@4775
  1741
tom5760@4775
  1742
void
tom5760@4782
  1743
PbbAddressBlock::AddressPopBack (void)
tom5760@4775
  1744
{
tom5760@4775
  1745
  m_addressList.pop_back();
tom5760@4775
  1746
}
tom5760@4775
  1747
tom5760@4782
  1748
PbbAddressBlock::AddressIterator
tom5760@4782
  1749
PbbAddressBlock::AddressErase (PbbAddressBlock::AddressIterator position)
tom5760@4775
  1750
{
tom5760@4775
  1751
  return m_addressList.erase(position);
tom5760@4775
  1752
}
tom5760@4775
  1753
tom5760@4782
  1754
PbbAddressBlock::AddressIterator
tom5760@4782
  1755
PbbAddressBlock::AddressErase (PbbAddressBlock::AddressIterator first,
tom5760@4782
  1756
    PbbAddressBlock::AddressIterator last)
tom5760@4775
  1757
{
tom5760@4775
  1758
  return m_addressList.erase(first, last);
tom5760@4775
  1759
}
tom5760@4775
  1760
tom5760@4775
  1761
  void
tom5760@4782
  1762
PbbAddressBlock::AddressClear (void)
tom5760@4775
  1763
{
tom5760@4775
  1764
  return m_addressList.clear();
tom5760@4775
  1765
}
tom5760@4775
  1766
tom5760@4775
  1767
/* Manipulating the prefix list */
tom5760@4775
  1768
tom5760@4782
  1769
PbbAddressBlock::PrefixIterator
tom5760@4782
  1770
PbbAddressBlock::PrefixBegin (void)
tom5760@4775
  1771
{
tom5760@4775
  1772
  return m_prefixList.begin ();
tom5760@4775
  1773
}
tom5760@4775
  1774
tom5760@4782
  1775
PbbAddressBlock::ConstPrefixIterator
tom5760@4782
  1776
PbbAddressBlock::PrefixBegin (void) const
tom5760@4775
  1777
{
tom5760@4775
  1778
  return m_prefixList.begin ();
tom5760@4775
  1779
}
tom5760@4775
  1780
tom5760@4782
  1781
PbbAddressBlock::PrefixIterator
tom5760@4782
  1782
PbbAddressBlock::PrefixEnd (void)
tom5760@4775
  1783
{
tom5760@4775
  1784
  return m_prefixList.end ();
tom5760@4775
  1785
}
tom5760@4775
  1786
tom5760@4782
  1787
PbbAddressBlock::ConstPrefixIterator
tom5760@4782
  1788
PbbAddressBlock::PrefixEnd (void) const
tom5760@4775
  1789
{
tom5760@4775
  1790
  return m_prefixList.end ();
tom5760@4775
  1791
}
tom5760@4775
  1792
tom5760@4775
  1793
int
tom5760@4782
  1794
PbbAddressBlock::PrefixSize (void) const
tom5760@4775
  1795
{
tom5760@4775
  1796
  return m_prefixList.size ();
tom5760@4775
  1797
}
tom5760@4775
  1798
tom5760@4775
  1799
bool
tom5760@4782
  1800
PbbAddressBlock::PrefixEmpty (void) const
tom5760@4775
  1801
{
tom5760@4775
  1802
  return m_prefixList.empty ();
tom5760@4775
  1803
}
tom5760@4775
  1804
tom5760@4775
  1805
uint8_t
tom5760@4782
  1806
PbbAddressBlock::PrefixFront (void) const
tom5760@4775
  1807
{
tom5760@4775
  1808
  return m_prefixList.front ();
tom5760@4775
  1809
}
tom5760@4775
  1810
tom5760@4775
  1811
uint8_t
tom5760@4782
  1812
PbbAddressBlock::PrefixBack (void) const
tom5760@4775
  1813
{
tom5760@4775
  1814
  return m_prefixList.back ();
tom5760@4775
  1815
}
tom5760@4775
  1816
tom5760@4775
  1817
void
tom5760@4782
  1818
PbbAddressBlock::PrefixPushFront (uint8_t prefix)
tom5760@4775
  1819
{
tom5760@4775
  1820
  m_prefixList.push_front (prefix);
tom5760@4775
  1821
}
tom5760@4775
  1822
tom5760@4775
  1823
void
tom5760@4782
  1824
PbbAddressBlock::PrefixPopFront (void)
tom5760@4775
  1825
{
tom5760@4775
  1826
  m_prefixList.pop_front ();
tom5760@4775
  1827
}
tom5760@4775
  1828
tom5760@4775
  1829
void
tom5760@4782
  1830
PbbAddressBlock::PrefixPushBack (uint8_t prefix)
tom5760@4775
  1831
{
tom5760@4775
  1832
  m_prefixList.push_back (prefix);
tom5760@4775
  1833
}
tom5760@4775
  1834
tom5760@4775
  1835
void
tom5760@4782
  1836
PbbAddressBlock::PrefixPopBack (void)
tom5760@4775
  1837
{
tom5760@4775
  1838
  m_prefixList.pop_back ();
tom5760@4775
  1839
}
tom5760@4775
  1840
tom5760@4782
  1841
PbbAddressBlock::PrefixIterator
tom5760@4782
  1842
PbbAddressBlock::PrefixInsert (PbbAddressBlock::PrefixIterator position, const uint8_t value)
tom5760@4775
  1843
{
tom5760@4775
  1844
  return m_prefixList.insert (position, value);
tom5760@4775
  1845
}
tom5760@4775
  1846
tom5760@4782
  1847
PbbAddressBlock::PrefixIterator
tom5760@4782
  1848
PbbAddressBlock::PrefixErase (PbbAddressBlock::PrefixIterator position)
tom5760@4775
  1849
{
tom5760@4775
  1850
  return m_prefixList.erase (position);
tom5760@4775
  1851
}
tom5760@4775
  1852
tom5760@4782
  1853
PbbAddressBlock::PrefixIterator
tom5760@4782
  1854
PbbAddressBlock::PrefixErase (PbbAddressBlock::PrefixIterator first, PbbAddressBlock::PrefixIterator last)
tom5760@4775
  1855
{
tom5760@4775
  1856
  return m_prefixList.erase (first, last);
tom5760@4775
  1857
}
tom5760@4775
  1858
tom5760@4775
  1859
void
tom5760@4782
  1860
PbbAddressBlock::PrefixClear (void)
tom5760@4775
  1861
{
tom5760@4775
  1862
  m_prefixList.clear ();
tom5760@4775
  1863
}
tom5760@4775
  1864
tom5760@4775
  1865
/* Manipulating the TLV block */
tom5760@4775
  1866
tom5760@4782
  1867
PbbAddressBlock::TlvIterator
tom5760@4782
  1868
PbbAddressBlock::TlvBegin (void)
tom5760@4775
  1869
{
tom5760@4775
  1870
  return m_addressTlvList.Begin();
tom5760@4775
  1871
}
tom5760@4775
  1872
tom5760@4782
  1873
PbbAddressBlock::ConstTlvIterator
tom5760@4782
  1874
PbbAddressBlock::TlvBegin (void) const
tom5760@4775
  1875
{
tom5760@4775
  1876
  return m_addressTlvList.Begin();
tom5760@4775
  1877
}
tom5760@4775
  1878
tom5760@4782
  1879
PbbAddressBlock::TlvIterator
tom5760@4782
  1880
PbbAddressBlock::TlvEnd (void)
tom5760@4775
  1881
{
tom5760@4775
  1882
  return m_addressTlvList.End();
tom5760@4775
  1883
}
tom5760@4775
  1884
tom5760@4782
  1885
PbbAddressBlock::ConstTlvIterator
tom5760@4782
  1886
PbbAddressBlock::TlvEnd (void) const
tom5760@4775
  1887
{
tom5760@4775
  1888
  return m_addressTlvList.End();
tom5760@4775
  1889
}
tom5760@4775
  1890
tom5760@4775
  1891
int
tom5760@4782
  1892
PbbAddressBlock::TlvSize (void) const
tom5760@4775
  1893
{
tom5760@4775
  1894
  return m_addressTlvList.Size();
tom5760@4775
  1895
}
tom5760@4775
  1896
tom5760@4775
  1897
bool
tom5760@4782
  1898
PbbAddressBlock::TlvEmpty (void) const
tom5760@4775
  1899
{
tom5760@4775
  1900
  return m_addressTlvList.Empty();
tom5760@4775
  1901
}
tom5760@4775
  1902
tom5760@4782
  1903
Ptr<PbbAddressTlv>
tom5760@4782
  1904
PbbAddressBlock::TlvFront (void)
tom5760@4775
  1905
{
tom5760@4775
  1906
  return m_addressTlvList.Front();
tom5760@4775
  1907
}
tom5760@4775
  1908
tom5760@4782
  1909
const Ptr<PbbAddressTlv>
tom5760@4782
  1910
PbbAddressBlock::TlvFront (void) const
tom5760@4775
  1911
{
tom5760@4775
  1912
  return m_addressTlvList.Front();
tom5760@4775
  1913
}
tom5760@4775
  1914
tom5760@4782
  1915
Ptr<PbbAddressTlv>
tom5760@4782
  1916
PbbAddressBlock::TlvBack (void)
tom5760@4775
  1917
{
tom5760@4775
  1918
  return m_addressTlvList.Back();
tom5760@4775
  1919
}
tom5760@4775
  1920
tom5760@4782
  1921
const Ptr<PbbAddressTlv>
tom5760@4782
  1922
PbbAddressBlock::TlvBack (void) const
tom5760@4775
  1923
{
tom5760@4775
  1924
  return m_addressTlvList.Back();
tom5760@4775
  1925
}
tom5760@4775
  1926
tom5760@4775
  1927
void
tom5760@4782
  1928
PbbAddressBlock::TlvPushFront (Ptr<PbbAddressTlv> tlv)
tom5760@4775
  1929
{
tom5760@4775
  1930
  m_addressTlvList.PushFront(tlv);
tom5760@4775
  1931
}
tom5760@4775
  1932
tom5760@4775
  1933
void
tom5760@4782
  1934
PbbAddressBlock::TlvPopFront (void)
tom5760@4775
  1935
{
tom5760@4775
  1936
  m_addressTlvList.PopFront();
tom5760@4775
  1937
}
tom5760@4775
  1938
tom5760@4775
  1939
void
tom5760@4782
  1940
PbbAddressBlock::TlvPushBack (Ptr<PbbAddressTlv> tlv)
tom5760@4775
  1941
{
tom5760@4775
  1942
  m_addressTlvList.PushBack(tlv);
tom5760@4775
  1943
}
tom5760@4775
  1944
tom5760@4775
  1945
void
tom5760@4782
  1946
PbbAddressBlock::TlvPopBack (void)
tom5760@4775
  1947
{
tom5760@4775
  1948
  m_addressTlvList.PopBack();
tom5760@4775
  1949
}
tom5760@4775
  1950
tom5760@4782
  1951
PbbAddressBlock::TlvIterator
tom5760@4782
  1952
PbbAddressBlock::TlvErase (PbbAddressBlock::TlvIterator position)
tom5760@4775
  1953
{
tom5760@4775
  1954
  return m_addressTlvList.Erase(position);
tom5760@4775
  1955
}
tom5760@4775
  1956
tom5760@4782
  1957
PbbAddressBlock::TlvIterator
tom5760@4782
  1958
PbbAddressBlock::TlvErase (PbbAddressBlock::TlvIterator first,
tom5760@4782
  1959
    PbbAddressBlock::TlvIterator last)
tom5760@4775
  1960
{
tom5760@4775
  1961
  return m_addressTlvList.Erase(first, last);
tom5760@4775
  1962
}
tom5760@4775
  1963
tom5760@4775
  1964
void
tom5760@4782
  1965
PbbAddressBlock::TlvClear (void)
tom5760@4775
  1966
{
tom5760@5263
  1967
  m_addressTlvList.Clear();
tom5760@4775
  1968
}
tom5760@4775
  1969
uint32_t
tom5760@4782
  1970
PbbAddressBlock::GetSerializedSize (void) const
tom5760@4775
  1971
{
tom5760@4775
  1972
  /* num-addr + flags */
tom5760@4775
  1973
  uint32_t size = 2;
tom5760@4775
  1974
tom5760@4775
  1975
  if (AddressSize () == 1)
tom5760@4776
  1976
    {
tom5760@4776
  1977
      size += GetAddressLength () + PrefixSize();
tom5760@4776
  1978
    }
tom5760@4775
  1979
  else if (AddressSize () > 0)
tom5760@4775
  1980
    {
tom5760@4776
  1981
      uint8_t head[GetAddressLength ()];
tom5760@4776
  1982
      uint8_t headlen = 0;
tom5760@4776
  1983
      uint8_t tail[GetAddressLength ()];
tom5760@4776
  1984
      uint8_t taillen = 0;
tom5760@4776
  1985
tom5760@4776
  1986
      GetHeadTail (head, headlen, tail, taillen);
tom5760@4776
  1987
tom5760@4776
  1988
      if (headlen > 0)
tom5760@4776
  1989
        {
tom5760@4776
  1990
          size += 1 + headlen;
tom5760@4776
  1991
        }
tom5760@4776
  1992
tom5760@4776
  1993
      if (taillen > 0)
tom5760@4776
  1994
        {
tom5760@4776
  1995
          size++;
tom5760@4776
  1996
          if (!HasZeroTail (tail, taillen))
tom5760@4776
  1997
            {
tom5760@4776
  1998
              size += taillen;
tom5760@4776
  1999
            }
tom5760@4776
  2000
        }
tom5760@4776
  2001
tom5760@4776
  2002
      /* mid size */
tom5760@4776
  2003
      size += (GetAddressLength () - headlen - taillen) * AddressSize ();
tom5760@4776
  2004
tom5760@4776
  2005
      size += PrefixSize ();
tom5760@4775
  2006
    }
tom5760@4775
  2007
tom5760@4775
  2008
  size += m_addressTlvList.GetSerializedSize ();
tom5760@4775
  2009
tom5760@4775
  2010
  return size;
tom5760@4775
  2011
}
tom5760@4775
  2012
tom5760@4775
  2013
void
tom5760@4782
  2014
PbbAddressBlock::Serialize (Buffer::Iterator &start) const
tom5760@4775
  2015
{
tom5760@4775
  2016
  start.WriteU8 (AddressSize ());
tom5760@4775
  2017
tom5760@4776
  2018
  if (AddressSize () == 1)
tom5760@4776
  2019
    {
tom5760@4776
  2020
      start.WriteU8 (0);
tom5760@4776
  2021
tom5760@4776
  2022
      uint8_t buf[GetAddressLength ()];
tom5760@4776
  2023
      SerializeAddress (buf, AddressBegin ());
tom5760@4776
  2024
      start.Write (buf, GetAddressLength ());
tom5760@4776
  2025
tom5760@4776
  2026
      if (PrefixSize () == 1)
tom5760@4776
  2027
        {
tom5760@4776
  2028
          start.WriteU8 (PrefixFront ());
tom5760@4776
  2029
        }
tom5760@4776
  2030
    }
tom5760@4775
  2031
  else if (AddressSize () > 0)
tom5760@4775
  2032
    {
tom5760@4776
  2033
      Buffer::Iterator bufref = start;
tom5760@4776
  2034
      uint8_t flags = 0;
tom5760@4776
  2035
      start.Next ();
tom5760@4776
  2036
tom5760@4776
  2037
      uint8_t head[GetAddressLength ()];
tom5760@4776
  2038
      uint8_t tail[GetAddressLength ()];
tom5760@4776
  2039
      uint8_t headlen = 0;
tom5760@4776
  2040
      uint8_t taillen = 0;
tom5760@4776
  2041
tom5760@4776
  2042
      GetHeadTail (head, headlen, tail, taillen);
tom5760@4776
  2043
tom5760@4776
  2044
      if (headlen > 0)
tom5760@4776
  2045
        {
tom5760@4776
  2046
          flags |= AHAS_HEAD;
tom5760@4776
  2047
          start.WriteU8 (headlen);
tom5760@4776
  2048
          start.Write (head, headlen);
tom5760@4776
  2049
        }
tom5760@4776
  2050
tom5760@4776
  2051
      if (taillen > 0)
tom5760@4776
  2052
        {
tom5760@4776
  2053
          start.WriteU8 (taillen);
tom5760@4776
  2054
tom5760@4776
  2055
          if (HasZeroTail (tail, taillen))
tom5760@4776
  2056
            {
tom5760@4776
  2057
              flags |= AHAS_ZERO_TAIL;
tom5760@4776
  2058
            }
tom5760@4776
  2059
          else
tom5760@4776
  2060
            {
tom5760@4776
  2061
              flags |= AHAS_FULL_TAIL;
tom5760@4776
  2062
              start.Write (tail, taillen);
tom5760@4776
  2063
            }
tom5760@4776
  2064
        }
tom5760@4776
  2065
tom5760@4776
  2066
      if (headlen + taillen < GetAddressLength ())
tom5760@4776
  2067
        {
tom5760@4776
  2068
          uint8_t mid[GetAddressLength ()];
tom5760@4782
  2069
          for (PbbAddressBlock::ConstAddressIterator iter = AddressBegin ();
tom5760@4776
  2070
              iter != AddressEnd ();
tom5760@4776
  2071
              iter++)
tom5760@4776
  2072
            {
tom5760@4776
  2073
              SerializeAddress (mid, iter);
tom5760@4776
  2074
              start.Write (mid + headlen, GetAddressLength () - headlen - taillen);
tom5760@4776
  2075
            }
tom5760@4776
  2076
        }
tom5760@4776
  2077
tom5760@4776
  2078
      flags |= GetPrefixFlags ();
tom5760@4776
  2079
      bufref.WriteU8 (flags);
tom5760@4776
  2080
tom5760@4776
  2081
      for (ConstPrefixIterator iter = PrefixBegin ();
tom5760@4776
  2082
          iter != PrefixEnd ();
tom5760@4776
  2083
          iter++)
tom5760@4776
  2084
        {
tom5760@4776
  2085
          start.WriteU8 (*iter);
tom5760@4776
  2086
        }
tom5760@4775
  2087
    }
tom5760@4775
  2088
  
tom5760@4775
  2089
  m_addressTlvList.Serialize (start);
tom5760@4775
  2090
}
tom5760@4775
  2091
tom5760@4775
  2092
void
tom5760@4782
  2093
PbbAddressBlock::Deserialize (Buffer::Iterator &start)
tom5760@4775
  2094
{
tom5760@4775
  2095
  uint8_t numaddr = start.ReadU8 ();
tom5760@4775
  2096
  uint8_t flags = start.ReadU8 ();
tom5760@4775
  2097
tom5760@4775
  2098
  if (numaddr > 0)
tom5760@4775
  2099
    {
tom5760@4776
  2100
      uint8_t headlen = 0;
tom5760@4776
  2101
      uint8_t taillen = 0;
tom5760@4776
  2102
      uint8_t addrtmp[GetAddressLength ()];
tom5760@4776
  2103
      memset(addrtmp, 0, GetAddressLength ());
tom5760@4776
  2104
tom5760@4776
  2105
      if (flags & AHAS_HEAD)
tom5760@4776
  2106
        {
tom5760@4776
  2107
          headlen = start.ReadU8 ();
tom5760@4776
  2108
          start.Read (addrtmp, headlen);
tom5760@4776
  2109
        }
tom5760@4776
  2110
tom5760@4776
  2111
      if ((flags & AHAS_FULL_TAIL) ^ (flags & AHAS_ZERO_TAIL))
tom5760@4776
  2112
        {
tom5760@4776
  2113
          taillen = start.ReadU8 ();
tom5760@4776
  2114
          
tom5760@4776
  2115
          if (flags & AHAS_FULL_TAIL)
tom5760@4776
  2116
            {
tom5760@4776
  2117
              start.Read (addrtmp + GetAddressLength () - taillen, taillen);
tom5760@4776
  2118
            }
tom5760@4776
  2119
        }
tom5760@4776
  2120
tom5760@4776
  2121
      for (int i = 0; i < numaddr; i++)
tom5760@4776
  2122
        {
tom5760@4776
  2123
          start.Read (addrtmp + headlen, GetAddressLength () - headlen - taillen);
tom5760@4776
  2124
          AddressPushBack (DeserializeAddress (addrtmp));
tom5760@4776
  2125
        }
tom5760@4776
  2126
tom5760@4776
  2127
      if (flags & AHAS_SINGLE_PRE_LEN)
tom5760@4776
  2128
        {
tom5760@4776
  2129
          PrefixPushBack (start.ReadU8 ());
tom5760@4776
  2130
        }
tom5760@4776
  2131
      else if (flags & AHAS_MULTI_PRE_LEN)
tom5760@4776
  2132
        {
tom5760@4776
  2133
          for (int i = 0; i < numaddr; i++)
tom5760@4776
  2134
            {
tom5760@4776
  2135
              PrefixPushBack (start.ReadU8 ());
tom5760@4776
  2136
            }
tom5760@4776
  2137
        }
tom5760@4775
  2138
    }
tom5760@4775
  2139
tom5760@4775
  2140
  m_addressTlvList.Deserialize (start);
tom5760@4775
  2141
}
tom5760@4775
  2142
tom5760@4775
  2143
void
tom5760@4782
  2144
PbbAddressBlock::Print (std::ostream &os) const
tom5760@4775
  2145
{
tom5760@4775
  2146
  Print (os, 0);
tom5760@4775
  2147
}
tom5760@4775
  2148
tom5760@4775
  2149
void
tom5760@4782
  2150
PbbAddressBlock::Print (std::ostream &os, int level) const
tom5760@4775
  2151
{
tom5760@4775
  2152
  std::string prefix = "";
tom5760@4775
  2153
  for (int i = 0; i < level; i++)
tom5760@4776
  2154
    {
tom5760@4776
  2155
      prefix.append ("\t");
tom5760@4776
  2156
    }
tom5760@4775
  2157
tom5760@4782
  2158
  os << prefix << "PbbAddressBlock {" << std::endl;
tom5760@4775
  2159
  os << prefix << "\taddresses = " << std::endl;
tom5760@4775
  2160
  for (ConstAddressIterator iter = AddressBegin ();
tom5760@4775
  2161
      iter != AddressEnd ();
tom5760@4775
  2162
      iter++)
tom5760@4776
  2163
    {
tom5760@4776
  2164
      os << prefix << "\t\t";
tom5760@4776
  2165
      PrintAddress(os, iter);
tom5760@4776
  2166
      os << std::endl;
tom5760@4776
  2167
    }
tom5760@4775
  2168
tom5760@4775
  2169
  os << prefix << "\tprefixes = " << std::endl;
tom5760@4775
  2170
  for (ConstPrefixIterator iter = PrefixBegin ();
tom5760@4775
  2171
      iter != PrefixEnd ();
tom5760@4775
  2172
      iter++)
tom5760@4776
  2173
    {
tom5760@4776
  2174
      os << prefix << "\t\t" << (int)(*iter) << std::endl;
tom5760@4776
  2175
    }
tom5760@4775
  2176
tom5760@4775
  2177
  m_addressTlvList.Print (os, level+1);
tom5760@4775
  2178
}
tom5760@4775
  2179
tom5760@4775
  2180
bool
tom5760@4782
  2181
PbbAddressBlock::operator== (const PbbAddressBlock &other) const
tom5760@4775
  2182
{
tom5760@4775
  2183
  if (AddressSize () != other.AddressSize ())
tom5760@4776
  2184
    {
tom5760@4776
  2185
      return false;
tom5760@4776
  2186
    }
tom5760@4775
  2187
tom5760@4775
  2188
  ConstAddressIterator tai, oai;
tom5760@4775
  2189
  for (tai = AddressBegin (), oai = other.AddressBegin ();
tom5760@4775
  2190
      tai != AddressEnd () && oai != other.AddressEnd ();
tom5760@4775
  2191
      tai++, oai++)
tom5760@4776
  2192
    {
tom5760@4776
  2193
      if (*tai != *oai)
tom5760@4776
  2194
        {
tom5760@4776
  2195
          return false;
tom5760@4776
  2196
        }
tom5760@4776
  2197
    }
tom5760@4776
  2198
tom5760@4776
  2199
  if (PrefixSize () != other.PrefixSize ())
tom5760@4776
  2200
    {
tom5760@4775
  2201
      return false;
tom5760@4776
  2202
    }
tom5760@4775
  2203
tom5760@4775
  2204
  ConstPrefixIterator tpi, opi;
tom5760@4775
  2205
  for (tpi = PrefixBegin (), opi = other.PrefixBegin ();
tom5760@4775
  2206
      tpi != PrefixEnd () && opi != other.PrefixEnd ();
tom5760@4775
  2207
      tpi++, opi++)
tom5760@4776
  2208
    {
tom5760@4776
  2209
      if (*tpi != *opi)
tom5760@4776
  2210
        {
tom5760@4776
  2211
          return false;
tom5760@4776
  2212
        }
tom5760@4776
  2213
    }
tom5760@4776
  2214
tom5760@4776
  2215
  if (m_addressTlvList != other.m_addressTlvList)
tom5760@4776
  2216
    {
tom5760@4775
  2217
      return false;
tom5760@4776
  2218
    }
tom5760@4775
  2219
tom5760@4775
  2220
  return true;
tom5760@4775
  2221
}
tom5760@4775
  2222
tom5760@4775
  2223
bool
tom5760@4782
  2224
PbbAddressBlock::operator!= (const PbbAddressBlock &other) const
tom5760@4775
  2225
{
tom5760@4775
  2226
  return !(*this == other);
tom5760@4775
  2227
}
tom5760@4775
  2228
tom5760@4775
  2229
uint8_t
tom5760@4782
  2230
PbbAddressBlock::GetPrefixFlags (void) const
tom5760@4775
  2231
{
tom5760@4775
  2232
  switch (PrefixSize ())
tom5760@4776
  2233
    {
tom5760@4776
  2234
      case 0:
tom5760@4776
  2235
        return 0;
tom5760@4776
  2236
        break;
tom5760@4776
  2237
      case 1:
tom5760@4776
  2238
        return AHAS_SINGLE_PRE_LEN;
tom5760@4776
  2239
        break;
tom5760@4776
  2240
      default:
tom5760@4776
  2241
        return AHAS_MULTI_PRE_LEN;
tom5760@4776
  2242
        break;
tom5760@4776
  2243
    }
craigdo@4791
  2244
craigdo@4791
  2245
  /* Quiet compiler */
craigdo@4792
  2246
  return 0;
tom5760@4775
  2247
}
tom5760@4775
  2248
tom5760@4775
  2249
void
tom5760@4782
  2250
PbbAddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen,
tom5760@4775
  2251
    uint8_t *tail, uint8_t &taillen) const
tom5760@4775
  2252
{
tom5760@4775
  2253
  headlen = GetAddressLength ();
tom5760@4775
  2254
  taillen = headlen;
tom5760@4775
  2255
tom5760@4775
  2256
  /* Temporary automatic buffers to store serialized addresses */
tom5760@4775
  2257
  uint8_t * buflast = new uint8_t[GetAddressLength ()];
tom5760@4775
  2258
  uint8_t * bufcur = new uint8_t[GetAddressLength ()];
tom5760@4775
  2259
  uint8_t * tmp;
tom5760@4775
  2260
tom5760@4775
  2261
  SerializeAddress (buflast, AddressBegin ());
tom5760@4775
  2262
tom5760@4775
  2263
  /* Skip the first item */
tom5760@4782
  2264
  for (PbbAddressBlock::ConstAddressIterator iter = AddressBegin ()++;
tom5760@4775
  2265
      iter != AddressEnd ();
tom5760@4775
  2266
      iter++)
tom5760@4775
  2267
    {
tom5760@4776
  2268
      SerializeAddress (bufcur, iter);
tom5760@4776
  2269
tom5760@4776
  2270
      int i;
tom5760@4776
  2271
      for (i = 0; i < headlen; i++)
tom5760@4776
  2272
        {
tom5760@4776
  2273
          if (buflast[i] != bufcur[i])
tom5760@4776
  2274
            {
tom5760@4776
  2275
              headlen = i;
tom5760@4776
  2276
              break;
tom5760@4776
  2277
            }
tom5760@4776
  2278
        }
tom5760@4776
  2279
tom5760@4776
  2280
      /* If headlen == fulllen - 1, then tail is 0 */
tom5760@4776
  2281
      if (headlen <= GetAddressLength () - 1)
tom5760@4776
  2282
        {
tom5760@4776
  2283
          for (i = GetAddressLength () - 1;
tom5760@4776
  2284
              GetAddressLength () - 1 - i <= taillen && i > headlen;
tom5760@4776
  2285
              i--)
tom5760@4776
  2286
            {
tom5760@4776
  2287
              if (buflast[i] != bufcur[i])
tom5760@4776
  2288
                {
tom5760@4776
  2289
                  break;
tom5760@4776
  2290
                }
tom5760@4776
  2291
            }
tom5760@4776
  2292
          taillen = GetAddressLength () - 1 - i;
tom5760@4776
  2293
        }
tom5760@4776
  2294
      else if (headlen == 0)
tom5760@4776
  2295
        {
tom5760@4776
  2296
          taillen = 0;
tom5760@4776
  2297
          break;
tom5760@4776
  2298
        }
tom5760@4776
  2299
tom5760@4776
  2300
      tmp = buflast;
tom5760@4776
  2301
      buflast = bufcur;
tom5760@4776
  2302
      bufcur = tmp;
tom5760@4775
  2303
    }
tom5760@4775
  2304
tom5760@4775
  2305
  memcpy(head, bufcur, headlen);
tom5760@4775
  2306
  memcpy(tail, bufcur + (GetAddressLength () - taillen), taillen);
tom5760@4775
  2307
tom5760@4775
  2308
  delete[] buflast;
tom5760@4775
  2309
  delete[] bufcur;
tom5760@4775
  2310
}
tom5760@4775
  2311
tom5760@4775
  2312
bool
tom5760@4782
  2313
PbbAddressBlock::HasZeroTail (const uint8_t *tail, uint8_t taillen) const
tom5760@4775
  2314
{
tom5760@4775
  2315
  int i;
tom5760@4775
  2316
  for (i = 0; i < taillen; i++)
tom5760@4776
  2317
    {
tom5760@4776
  2318
      if (tail[i] != 0)
tom5760@4776
  2319
        {
tom5760@4776
  2320
          break;
tom5760@4776
  2321
        }
tom5760@4776
  2322
    }
tom5760@4775
  2323
  return i == taillen;
tom5760@4775
  2324
}
tom5760@4775
  2325
tom5760@4782
  2326
/* End PbbAddressBlock Class */
tom5760@4775
  2327
craigdo@4790
  2328
PbbAddressBlockIpv4::PbbAddressBlockIpv4 ()
craigdo@4790
  2329
{
craigdo@4790
  2330
}
craigdo@4790
  2331
craigdo@4790
  2332
PbbAddressBlockIpv4::~PbbAddressBlockIpv4 ()
craigdo@4790
  2333
{
craigdo@4790
  2334
}
craigdo@4790
  2335
tom5760@4775
  2336
uint8_t
tom5760@4782
  2337
PbbAddressBlockIpv4::GetAddressLength (void) const
tom5760@4775
  2338
{
tom5760@4775
  2339
  return 4;
tom5760@4775
  2340
}
tom5760@4775
  2341
tom5760@4775
  2342
void
tom5760@4782
  2343
PbbAddressBlockIpv4::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const
tom5760@4775
  2344
{
tom5760@4775
  2345
  Ipv4Address::ConvertFrom (*iter).Serialize (buffer);
tom5760@4775
  2346
}
tom5760@4775
  2347
tom5760@4775
  2348
Address
tom5760@4782
  2349
PbbAddressBlockIpv4::DeserializeAddress (uint8_t *buffer) const
tom5760@4775
  2350
{
tom5760@4775
  2351
  return Ipv4Address::Deserialize (buffer);
tom5760@4775
  2352
}
tom5760@4775
  2353
tom5760@4775
  2354
void
tom5760@4782
  2355
PbbAddressBlockIpv4::PrintAddress (std::ostream &os, ConstAddressIterator iter) const
tom5760@4775
  2356
{
tom5760@4775
  2357
  Ipv4Address::ConvertFrom (*iter).Print (os);
tom5760@4775
  2358
}
tom5760@4775
  2359
tom5760@4782
  2360
/* End PbbAddressBlockIpv4 Class */
tom5760@4775
  2361
craigdo@4790
  2362
PbbAddressBlockIpv6::PbbAddressBlockIpv6 ()
craigdo@4790
  2363
{
craigdo@4790
  2364
}
craigdo@4790
  2365
craigdo@4790
  2366
PbbAddressBlockIpv6::~PbbAddressBlockIpv6 ()
craigdo@4790
  2367
{
craigdo@4790
  2368
}
craigdo@4790
  2369
tom5760@4775
  2370
uint8_t
tom5760@4782
  2371
PbbAddressBlockIpv6::GetAddressLength (void) const
tom5760@4775
  2372
{
tom5760@4775
  2373
  return 16;
tom5760@4775
  2374
}
tom5760@4775
  2375
tom5760@4775
  2376
void
tom5760@4782
  2377
PbbAddressBlockIpv6::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const
tom5760@4775
  2378
{
tom5760@4775
  2379
  Ipv6Address::ConvertFrom (*iter).Serialize (buffer);
tom5760@4775
  2380
}
tom5760@4775
  2381
tom5760@4775
  2382
Address
tom5760@4782
  2383
PbbAddressBlockIpv6::DeserializeAddress (uint8_t *buffer) const
tom5760@4775
  2384
{
tom5760@4775
  2385
  return Ipv6Address::Deserialize (buffer);
tom5760@4775
  2386
}
tom5760@4775
  2387
tom5760@4775
  2388
void
tom5760@4782
  2389
PbbAddressBlockIpv6::PrintAddress (std::ostream &os, ConstAddressIterator iter) const
tom5760@4775
  2390
{
tom5760@4775
  2391
  Ipv6Address::ConvertFrom (*iter).Print (os);
tom5760@4775
  2392
}
tom5760@4775
  2393
tom5760@4782
  2394
/* End PbbAddressBlockIpv6 Class */
tom5760@4782
  2395
tom5760@4782
  2396
PbbTlv::PbbTlv (void)
tom5760@4775
  2397
{
tom5760@4775
  2398
  m_hasTypeExt = false;
tom5760@4775
  2399
  m_hasIndexStart = false;
tom5760@4775
  2400
  m_hasIndexStop = false;
tom5760@4775
  2401
  m_isMultivalue = false;
tom5760@4775
  2402
  m_hasValue = false;
tom5760@4775
  2403
}
tom5760@4775
  2404
tom5760@5263
  2405
PbbTlv::~PbbTlv (void)
tom5760@5263
  2406
{
tom5760@5263
  2407
  m_value.RemoveAtEnd (m_value.GetSize ());
tom5760@5263
  2408
}
tom5760@5263
  2409
tom5760@4775
  2410
void
tom5760@4782
  2411
PbbTlv::SetType (uint8_t type)
tom5760@4775
  2412
{
tom5760@4775
  2413
  m_type = type;
tom5760@4775
  2414
}
tom5760@4775
  2415
tom5760@4775
  2416
uint8_t
tom5760@4782
  2417
PbbTlv::GetType (void) const
tom5760@4775
  2418
{
tom5760@4775
  2419
  return m_type;
tom5760@4775
  2420
}
tom5760@4775
  2421
tom5760@4775
  2422
void
tom5760@4782
  2423
PbbTlv::SetTypeExt (uint8_t typeExt)
tom5760@4775
  2424
{
tom5760@4775
  2425
  m_typeExt = typeExt;
tom5760@4775
  2426
  m_hasTypeExt = true;
tom5760@4775
  2427
}
tom5760@4775
  2428
tom5760@4775
  2429
uint8_t
tom5760@4782
  2430
PbbTlv::GetTypeExt (void) const
tom5760@4775
  2431
{
tom5760@4780
  2432
  NS_ASSERT (HasTypeExt ());
tom5760@4775
  2433
  return m_typeExt;
tom5760@4775
  2434
}
tom5760@4775
  2435
tom5760@4775
  2436
bool
tom5760@4782
  2437
PbbTlv::HasTypeExt (void) const
tom5760@4775
  2438
{
tom5760@4775
  2439
  return m_hasTypeExt;
tom5760@4775
  2440
}
tom5760@4775
  2441
tom5760@4775
  2442
void
tom5760@4782
  2443
PbbTlv::SetIndexStart (uint8_t index)
tom5760@4775
  2444
{
tom5760@4775
  2445
  m_indexStart = index;
tom5760@4775
  2446
  m_hasIndexStart = true;
tom5760@4775
  2447
}
tom5760@4775
  2448
tom5760@4775
  2449
uint8_t
tom5760@4782
  2450
PbbTlv::GetIndexStart (void) const
tom5760@4775
  2451
{
tom5760@4780
  2452
  NS_ASSERT (HasIndexStart ());
tom5760@4775
  2453
  return m_indexStart;
tom5760@4775
  2454
}
tom5760@4775
  2455
tom5760@4775
  2456
bool
tom5760@4782
  2457
PbbTlv::HasIndexStart (void) const
tom5760@4775
  2458
{
tom5760@4775
  2459
  return m_hasIndexStart;
tom5760@4775
  2460
}
tom5760@4775
  2461
tom5760@4775
  2462
void
tom5760@4782
  2463
PbbTlv::SetIndexStop (uint8_t index)
tom5760@4775
  2464
{
tom5760@4775
  2465
  m_indexStop = index;
tom5760@4775
  2466
  m_hasIndexStop = true;
tom5760@4775
  2467
}
tom5760@4775
  2468
tom5760@4775
  2469
uint8_t
tom5760@4782
  2470
PbbTlv::GetIndexStop (void) const
tom5760@4775
  2471
{
tom5760@4780
  2472
  NS_ASSERT (HasIndexStop ());
tom5760@4775
  2473
  return m_indexStop;
tom5760@4775
  2474
}
tom5760@4775
  2475
tom5760@4775
  2476
bool
tom5760@4782
  2477
PbbTlv::HasIndexStop (void) const
tom5760@4775
  2478
{
tom5760@4775
  2479
  return m_hasIndexStop;
tom5760@4775
  2480
}
tom5760@4775
  2481
tom5760@4775
  2482
void
tom5760@4782
  2483
PbbTlv::SetMultivalue (bool isMultivalue)
tom5760@4775
  2484
{
tom5760@4775
  2485
  m_isMultivalue = isMultivalue;
tom5760@4775
  2486
}
tom5760@4775
  2487
tom5760@4775
  2488
bool
tom5760@4782
  2489
PbbTlv::IsMultivalue (void) const
tom5760@4775
  2490
{
tom5760@4775
  2491
  return m_isMultivalue;
tom5760@4775
  2492
}
tom5760@4775
  2493
tom5760@4775
  2494
void
tom5760@4782
  2495
PbbTlv::SetValue (Buffer start)
tom5760@4775
  2496
{
tom5760@4775
  2497
  m_hasValue = true;
tom5760@4775
  2498
  m_value = start;
tom5760@4775
  2499
}
tom5760@4775
  2500
tom5760@4775
  2501
void
tom5760@4782
  2502
PbbTlv::SetValue (const uint8_t * buffer, uint32_t size)
tom5760@4775
  2503
{
tom5760@5263
  2504
  m_hasValue = true;
tom5760@5263
  2505
  m_value.AddAtStart (size);
tom5760@5263
  2506
  m_value.Begin ().Write (buffer, size);
tom5760@4775
  2507
}
tom5760@4775
  2508
tom5760@4775
  2509
Buffer
tom5760@4782
  2510
PbbTlv::GetValue (void) const
tom5760@4775
  2511
{
tom5760@4780
  2512
  NS_ASSERT (HasValue ());
tom5760@4775
  2513
  return m_value;
tom5760@4775
  2514
}
tom5760@4775
  2515
tom5760@4775
  2516
bool
tom5760@4782
  2517
PbbTlv::HasValue (void) const
tom5760@4775
  2518
{
tom5760@4775
  2519
  return m_hasValue;
tom5760@4775
  2520
}
tom5760@4775
  2521
tom5760@4775
  2522
uint32_t
tom5760@4782
  2523
PbbTlv::GetSerializedSize (void) const
tom5760@4775
  2524
{
tom5760@4775
  2525
  /* type + flags */
tom5760@4775
  2526
  uint32_t size = 2;
tom5760@4775
  2527
tom5760@4776
  2528
  if (HasTypeExt ())
tom5760@4776
  2529
    {
tom5760@4775
  2530
      size++;
tom5760@4775
  2531
    }
tom5760@4776
  2532
tom5760@4776
  2533
  if (HasIndexStart ())
tom5760@4776
  2534
    {
tom5760@4776
  2535
      size++;
tom5760@4776
  2536
    }
tom5760@4776
  2537
tom5760@4776
  2538
  if (HasIndexStop ())
tom5760@4776
  2539
    {
tom5760@4776
  2540
      size++;
tom5760@4776
  2541
    }
tom5760@4776
  2542
tom5760@4776
  2543
  if (HasValue ())
tom5760@4776
  2544
    {
tom5760@4776
  2545
      if (GetValue ().GetSize () > 255)
tom5760@4776
  2546
        {
tom5760@4776
  2547
          size += 2;
tom5760@4776
  2548
        } 
tom5760@4776
  2549
      else 
tom5760@4776
  2550
        {
tom5760@4776
  2551
          size++;
tom5760@4776
  2552
        }
tom5760@4776
  2553
      size += GetValue ().GetSize ();
tom5760@4776
  2554
    }
tom5760@4775
  2555
tom5760@4775
  2556
  return size;
tom5760@4775
  2557
}
tom5760@4775
  2558
tom5760@4775
  2559
void
tom5760@4782
  2560
PbbTlv::Serialize (Buffer::Iterator &start) const
tom5760@4775
  2561
{
tom5760@4775
  2562
  start.WriteU8 (GetType ());
tom5760@4775
  2563
tom5760@4775
  2564
  Buffer::Iterator bufref = start;
tom5760@4775
  2565
  uint8_t flags = 0;
tom5760@4775
  2566
  start.Next();
tom5760@4775
  2567
tom5760@4775
  2568
  if (HasTypeExt())
tom5760@4776
  2569
    {
tom5760@4776
  2570
      flags |= THAS_TYPE_EXT;
tom5760@4776
  2571
      start.WriteU8 (GetTypeExt ());
tom5760@4776
  2572
    }
tom5760@4775
  2573
tom5760@4775
  2574
  if (HasIndexStart ())
tom5760@4775
  2575
    {
tom5760@4776
  2576
      start.WriteU8 (GetIndexStart ());
tom5760@4776
  2577
tom5760@4776
  2578
      if (HasIndexStop ())
tom5760@4776
  2579
        {
tom5760@4776
  2580
          flags |= THAS_MULTI_INDEX;
tom5760@4776
  2581
          start.WriteU8 (GetIndexStop ());
tom5760@4776
  2582
        } 
tom5760@4776
  2583
      else
tom5760@4776
  2584
        {
tom5760@4776
  2585
          flags |= THAS_SINGLE_INDEX;
tom5760@4776
  2586
        }
tom5760@4776
  2587
    }
tom5760@4776
  2588
tom5760@4776
  2589
  if (HasValue ()) 
tom5760@4775
  2590
    {
tom5760@4776
  2591
      flags |= THAS_VALUE;
tom5760@4776
  2592
tom5760@4776
  2593
      uint32_t size = GetValue ().GetSize ();
tom5760@4776
  2594
      if (size > 255)
tom5760@4776
  2595
        {
tom5760@4776
  2596
          flags |= THAS_EXT_LEN;
tom5760@4776
  2597
          start.WriteHtonU16 (size);
tom5760@4776
  2598
        }
tom5760@4776
  2599
      else
tom5760@4776
  2600
        {
tom5760@4776
  2601
          start.WriteU8 (size);
tom5760@4776
  2602
        }
tom5760@4776
  2603
tom5760@4776
  2604
      if (IsMultivalue ())
tom5760@4776
  2605
        {
tom5760@4776
  2606
          flags |= TIS_MULTIVALUE;
tom5760@4776
  2607
        }
tom5760@4776
  2608
tom5760@4776
  2609
      start.Write(GetValue ().Begin (), GetValue ().End ());
tom5760@4775
  2610
    }
tom5760@4775
  2611
tom5760@4775
  2612
  bufref.WriteU8 (flags);
tom5760@4775
  2613
}
tom5760@4775
  2614
tom5760@4775
  2615
void
tom5760@4782
  2616
PbbTlv::Deserialize (Buffer::Iterator &start)
tom5760@4775
  2617
{
tom5760@4775
  2618
  SetType (start.ReadU8 ());
tom5760@4775
  2619
tom5760@4775
  2620
  uint8_t flags = start.ReadU8 ();
tom5760@4775
  2621
tom5760@4775
  2622
  if (flags & THAS_TYPE_EXT)
tom5760@4776
  2623
    {
tom5760@4776
  2624
      SetTypeExt (start.ReadU8 ());
tom5760@4776
  2625
    }
tom5760@4775
  2626
tom5760@4775
  2627
  if (flags & THAS_MULTI_INDEX)
tom5760@4776
  2628
    {
tom5760@4776
  2629
      SetIndexStart (start.ReadU8 ());
tom5760@4776
  2630
      SetIndexStop (start.ReadU8 ());
tom5760@4776
  2631
    }
tom5760@4775
  2632
  else if (flags & THAS_SINGLE_INDEX)
tom5760@4776
  2633
    {
tom5760@4776
  2634
      SetIndexStart (start.ReadU8 ());
tom5760@4776
  2635
    }
tom5760@4775
  2636
tom5760@4775
  2637
  if (flags & THAS_VALUE)
tom5760@4776
  2638
    {
tom5760@4776
  2639
      uint16_t len = 0;
tom5760@4776
  2640
tom5760@4776
  2641
      if (flags & THAS_EXT_LEN)
tom5760@4776
  2642
        {
tom5760@4776
  2643
          len = start.ReadNtohU16 ();
tom5760@4776
  2644
        }
tom5760@4776
  2645
      else
tom5760@4776
  2646
        {
tom5760@4776
  2647
          len = start.ReadU8 ();
tom5760@4776
  2648
        }
tom5760@4776
  2649
tom5760@4776
  2650
      m_value.AddAtStart (len);
tom5760@4776
  2651
tom5760@4776
  2652
      Buffer::Iterator valueStart = start;
tom5760@4776
  2653
      start.Next (len);
tom5760@4776
  2654
      m_value.Begin ().Write (valueStart, start);
tom5760@4776
  2655
      m_hasValue = true;
tom5760@4776
  2656
    }
tom5760@4775
  2657
}
tom5760@4775
  2658
tom5760@4775
  2659
void
tom5760@4782
  2660
PbbTlv::Print (std::ostream &os) const
tom5760@4775
  2661
{
tom5760@4775
  2662
  Print (os, 0);
tom5760@4775
  2663
}
tom5760@4775
  2664
tom5760@4775
  2665
void
tom5760@4782
  2666
PbbTlv::Print (std::ostream &os, int level) const
tom5760@4775
  2667
{
tom5760@4775
  2668
  std::string prefix = "";
tom5760@4775
  2669
  for (int i = 0; i < level; i++)
tom5760@4776
  2670
    {
tom5760@4776
  2671
      prefix.append ("\t");
tom5760@4776
  2672
    }
tom5760@4775
  2673
tom5760@4782
  2674
  os << prefix << "PbbTlv {" << std::endl;
tom5760@4775
  2675
  os << prefix << "\ttype = " << (int)GetType () << std::endl;
tom5760@4775
  2676
tom5760@4775
  2677
  if (HasTypeExt ())
tom5760@4776
  2678
    {
tom5760@4776
  2679
      os << prefix << "\ttypeext = " << (int)GetTypeExt () << std::endl;
tom5760@4776
  2680
    }
tom5760@4775
  2681
tom5760@4775
  2682
  if (HasIndexStart ())
tom5760@4776
  2683
    {
tom5760@4776
  2684
      os << prefix << "\tindexStart = " << (int)GetIndexStart () << std::endl;
tom5760@4776
  2685
    }
tom5760@4775
  2686
tom5760@4775
  2687
  if (HasIndexStop ())
tom5760@4776
  2688
    {
tom5760@4776
  2689
      os << prefix << "\tindexStop = " << (int)GetIndexStop () << std::endl;
tom5760@4776
  2690
    }
tom5760@4775
  2691
tom5760@4775
  2692
  os << prefix << "\tisMultivalue = " << IsMultivalue () << std::endl;
tom5760@4775
  2693
tom5760@4775
  2694
  if (HasValue ())
tom5760@4776
  2695
    {
tom5760@4776
  2696
      os << prefix << "\thas value; size = " << GetValue (). GetSize () << std::endl;
tom5760@4776
  2697
    }
tom5760@4775
  2698
tom5760@4775
  2699
  os << prefix << "}" << std::endl;
tom5760@4775
  2700
}
tom5760@4775
  2701
tom5760@4775
  2702
bool
tom5760@4782
  2703
PbbTlv::operator== (const PbbTlv &other) const
tom5760@4775
  2704
{
tom5760@4775
  2705
  if (GetType () != other.GetType ())
tom5760@4776
  2706
    {
tom5760@4776
  2707
      return false;
tom5760@4776
  2708
    }
tom5760@4775
  2709
tom5760@4775
  2710
  if (HasTypeExt () != other.HasTypeExt ())
tom5760@4776
  2711
    {
tom5760@4776
  2712
      return false;
tom5760@4776
  2713
    }
tom5760@4775
  2714
tom5760@4775
  2715
  if (HasTypeExt ())
tom5760@4776
  2716
    {
tom5760@4776
  2717
      if (GetTypeExt () != other.GetTypeExt ())
tom5760@4776
  2718
        {
tom5760@4776
  2719
          return false;
tom5760@4776
  2720
        }
tom5760@4776
  2721
    }
tom5760@4776
  2722
tom5760@4776
  2723
  if (HasValue () != other.HasValue ())
tom5760@4776
  2724
    {
tom5760@4775
  2725
      return false;
tom5760@4776
  2726
    }
tom5760@4775
  2727
tom5760@4775
  2728
  if (HasValue ())
tom5760@4776
  2729
    {
tom5760@4776
  2730
      Buffer tv = GetValue ();
tom5760@4776
  2731
      Buffer ov = other.GetValue ();
tom5760@4776
  2732
      if (tv.GetSize () != ov.GetSize ())
tom5760@4776
  2733
        {
tom5760@4776
  2734
          return false;
tom5760@4776
  2735
        }
tom5760@4776
  2736
tom5760@4776
  2737
      /* The docs say I probably shouldn't use Buffer::PeekData, but I think it
tom5760@4776
  2738
       * is justified in this case. */
tom5760@4776
  2739
      if (memcmp (tv.PeekData (), ov.PeekData (), tv.GetSize ()) != 0)
tom5760@4776
  2740
        {
tom5760@4776
  2741
          return false;
tom5760@4776
  2742
        }
tom5760@4776
  2743
    }
tom5760@4775
  2744
  return true;
tom5760@4775
  2745
}
tom5760@4775
  2746
tom5760@4775
  2747
bool
tom5760@4782
  2748
PbbTlv::operator!= (const PbbTlv &other) const
tom5760@4775
  2749
{
tom5760@4775
  2750
  return !(*this == other);
tom5760@4775
  2751
}
tom5760@4775
  2752
tom5760@4782
  2753
/* End PbbTlv Class */
tom5760@4775
  2754
tom5760@4775
  2755
void 
tom5760@4782
  2756
PbbAddressTlv::SetIndexStart (uint8_t index)
tom5760@4775
  2757
{
tom5760@4782
  2758
  PbbTlv::SetIndexStart (index);
tom5760@4775
  2759
}
tom5760@4775
  2760
tom5760@4775
  2761
uint8_t
tom5760@4782
  2762
PbbAddressTlv::GetIndexStart (void) const
tom5760@4775
  2763
{
tom5760@4782
  2764
  return PbbTlv::GetIndexStart ();
tom5760@4775
  2765
}
tom5760@4775
  2766
tom5760@4775
  2767
bool
tom5760@4782
  2768
PbbAddressTlv::HasIndexStart (void) const
tom5760@4775
  2769
{
tom5760@4782
  2770
  return PbbTlv::HasIndexStart ();
tom5760@4775
  2771
}
tom5760@4775
  2772
tom5760@4775
  2773
void 
tom5760@4782
  2774
PbbAddressTlv::SetIndexStop (uint8_t index)
tom5760@4775
  2775
{
tom5760@4782
  2776
  PbbTlv::SetIndexStop (index);
tom5760@4775
  2777
}
tom5760@4775
  2778
tom5760@4775
  2779
uint8_t
tom5760@4782
  2780
PbbAddressTlv::GetIndexStop (void) const
tom5760@4775
  2781
{
tom5760@4782
  2782
  return PbbTlv::GetIndexStop ();
tom5760@4775
  2783
}
tom5760@4775
  2784
tom5760@4775
  2785
bool
tom5760@4782
  2786
PbbAddressTlv::HasIndexStop (void) const
tom5760@4775
  2787
{
tom5760@4782
  2788
  return PbbTlv::HasIndexStop ();
tom5760@4775
  2789
}
tom5760@4775
  2790
tom5760@4775
  2791
void
tom5760@4782
  2792
PbbAddressTlv::SetMultivalue (bool isMultivalue)
tom5760@4775
  2793
{
tom5760@4782
  2794
  PbbTlv::SetMultivalue (isMultivalue);
tom5760@4775
  2795
}
tom5760@4775
  2796
tom5760@4775
  2797
bool
tom5760@4782
  2798
PbbAddressTlv::IsMultivalue (void) const
tom5760@4775
  2799
{
tom5760@4782
  2800
  return PbbTlv::IsMultivalue ();
tom5760@4775
  2801
}
tom5760@4775
  2802
tom5760@4775
  2803
} /* namespace ns3 */