View | Details | Raw Unified | Return to bug 2505
Collapse All | Expand All

(-)a/src/network/model/chunk.cc (+8 lines)
 Lines 34-37    Link Here 
34
  return tid;
34
  return tid;
35
}
35
}
36
36
37
// This default implementation is provided for backward compatibility
38
// reasons.  Subclasses should implement this method themselves.
39
uint32_t
40
Chunk::Deserialize (Buffer::Iterator start, Buffer::Iterator end)
41
{
42
  return Deserialize (start);
43
}
44
37
} // namespace ns3
45
} // namespace ns3
(-)a/src/network/model/chunk.h (+20 lines)
 Lines 42-53    Link Here 
42
42
43
  /**
43
  /**
44
   * \brief Deserialize the object from a buffer iterator
44
   * \brief Deserialize the object from a buffer iterator
45
   *
46
   * This version of Deserialize can be used when the Chunk has a fixed
47
   * size.  It should not be called for variable-sized Chunk derived types
48
   * (but must be implemented, for historical reasons).
49
   *
45
   * \param start the buffer iterator
50
   * \param start the buffer iterator
46
   * \returns the number of deserialized bytes
51
   * \returns the number of deserialized bytes
47
   */
52
   */
48
  virtual uint32_t Deserialize (Buffer::Iterator start) = 0;
53
  virtual uint32_t Deserialize (Buffer::Iterator start) = 0;
49
54
50
  /**
55
  /**
56
   * \brief Deserialize the object from a buffer iterator
57
   *
58
   * This version of Deserialize must be used when the Chunk has a variable
59
   * size, because the bounds of the Chunk may not be known at the point
60
   * of deserialization (e.g. a sequence of TLV fields).
61
   *
62
   * The size of the chunk should be start.GetDistanceFrom (end);
63
   *
64
   * \param start the starting point
65
   * \param end the ending point
66
   * \returns the number of deserialized bytes
67
   */
68
  virtual uint32_t Deserialize (Buffer::Iterator start, Buffer::Iterator end);
69
70
  /**
51
   * \brief Print the object contents
71
   * \brief Print the object contents
52
   * \param os the output stream
72
   * \param os the output stream
53
   */
73
   */
(-)a/src/network/model/header.h (+2 lines)
 Lines 48-53    Link Here 
48
   */
48
   */
49
  static TypeId GetTypeId (void);
49
  static TypeId GetTypeId (void);
50
  virtual ~Header ();
50
  virtual ~Header ();
51
52
  using Chunk::Deserialize;
51
  /**
53
  /**
52
   * \returns the expected size of the header.
54
   * \returns the expected size of the header.
53
   *
55
   *
(-)a/src/network/model/packet.cc (-1 / +39 lines)
 Lines 264-269    Link Here 
264
  m_metadata.AddHeader (header, size);
264
  m_metadata.AddHeader (header, size);
265
}
265
}
266
uint32_t
266
uint32_t
267
Packet::RemoveHeader (Header &header, uint32_t size)
268
{
269
  Buffer::Iterator end;
270
  end = m_buffer.Begin ();
271
  end.Next (size);
272
  uint32_t deserialized = header.Deserialize (m_buffer.Begin (), end);
273
  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized);
274
  m_buffer.RemoveAtStart (deserialized);
275
  m_byteTagList.Adjust (-deserialized);
276
  m_metadata.RemoveHeader (header, deserialized);
277
  return deserialized;
278
}
279
uint32_t
267
Packet::RemoveHeader (Header &header)
280
Packet::RemoveHeader (Header &header)
268
{
281
{
269
  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
282
  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
 Lines 280-285    Link Here 
280
  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized);
293
  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized);
281
  return deserialized;
294
  return deserialized;
282
}
295
}
296
uint32_t
297
Packet::PeekHeader (Header &header, uint32_t size) const
298
{
299
  Buffer::Iterator end;
300
  end = m_buffer.Begin ();
301
  end.Next (size);
302
  uint32_t deserialized = header.Deserialize (m_buffer.Begin (), end);
303
  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized);
304
  return deserialized;
305
}
283
void
306
void
284
Packet::AddTrailer (const Trailer &trailer)
307
Packet::AddTrailer (const Trailer &trailer)
285
{
308
{
 Lines 445-451    Link Here 
445
                NS_ASSERT (instance != 0);
468
                NS_ASSERT (instance != 0);
446
                Chunk *chunk = dynamic_cast<Chunk *> (instance);
469
                Chunk *chunk = dynamic_cast<Chunk *> (instance);
447
                NS_ASSERT (chunk != 0);
470
                NS_ASSERT (chunk != 0);
448
                chunk->Deserialize (item.current);
471
                if (item.type == PacketMetadata::Item::HEADER)
472
                  {
473
                    Buffer::Iterator end = item.current;
474
                    end.Next (item.currentSize); // move from start 
475
                    chunk->Deserialize (item.current, end);
476
                  }
477
                else if (item.type == PacketMetadata::Item::TRAILER)
478
                  {
479
                    Buffer::Iterator start = item.current;
480
                    start.Prev (item.currentSize); // move from end
481
                    chunk->Deserialize (start, item.current);
482
                  }
483
                else
484
                  {
485
                    chunk->Deserialize (item.current);
486
                  }    
449
                chunk->Print (os);
487
                chunk->Print (os);
450
                delete chunk;
488
                delete chunk;
451
              }
489
              }
(-)a/src/network/model/packet.h (-1 / +26 lines)
 Lines 316-328    Link Here 
316
  /**
316
  /**
317
   * \brief Deserialize and remove the header from the internal buffer.
317
   * \brief Deserialize and remove the header from the internal buffer.
318
   *
318
   *
319
   * This method invokes Header::Deserialize.
319
   * This method invokes Header::Deserialize (begin) and should be used for
320
   * variable-length headers.
320
   *
321
   *
321
   * \param header a reference to the header to remove from the internal buffer.
322
   * \param header a reference to the header to remove from the internal buffer.
322
   * \returns the number of bytes removed from the packet.
323
   * \returns the number of bytes removed from the packet.
323
   */
324
   */
324
  uint32_t RemoveHeader (Header &header);
325
  uint32_t RemoveHeader (Header &header);
325
  /**
326
  /**
327
   * \brief Deserialize and remove the header from the internal buffer.
328
   *
329
   * This method invokes Header::Deserialize (begin, end) and should be 
330
   * used for variable-length headers (where the size is determined somehow
331
   * by the caller).
332
   *
333
   * \param header a reference to the header to remove from the internal buffer.
334
   * \param size number of bytes to deserialize
335
   * \returns the number of bytes removed from the packet.
336
   */
337
  uint32_t RemoveHeader (Header &header, uint32_t size);
338
  /**
326
   * \brief Deserialize but does _not_ remove the header from the internal buffer.
339
   * \brief Deserialize but does _not_ remove the header from the internal buffer.
327
   * s
340
   * s
328
   * This method invokes Header::Deserialize.
341
   * This method invokes Header::Deserialize.
 Lines 332-337    Link Here 
332
   */
345
   */
333
  uint32_t PeekHeader (Header &header) const;
346
  uint32_t PeekHeader (Header &header) const;
334
  /**
347
  /**
348
   * \brief Deserialize but does _not_ remove the header from the internal buffer.
349
   * s
350
   * This method invokes Header::Deserialize (begin, end) and should be used
351
   * for variable-length headers (where the size is determined somehow
352
   * by the caller).
353
   *
354
   * \param header a reference to the header to read from the internal buffer.
355
   * \param size number of bytes to deserialize
356
   * \returns the number of bytes read from the packet.
357
   */
358
  uint32_t PeekHeader (Header &header, uint32_t size) const;
359
  /**
335
   * \brief Add trailer to this packet.
360
   * \brief Add trailer to this packet.
336
   *
361
   *
337
   * This method invokes the
362
   * This method invokes the
(-)a/src/network/model/trailer.cc (+8 lines)
 Lines 42-47    Link Here 
42
  return tid;
42
  return tid;
43
}
43
}
44
44
45
// This default implementation is provided for backward compatibility
46
// reasons.  Subclasses should implement this method themselves.
47
uint32_t
48
Trailer::Deserialize (Buffer::Iterator start, Buffer::Iterator end)
49
{
50
  return Deserialize (end);
51
}
52
45
std::ostream & operator << (std::ostream &os, const Trailer &trailer)
53
std::ostream & operator << (std::ostream &os, const Trailer &trailer)
46
{
54
{
47
  trailer.Print (os);
55
  trailer.Print (os);
(-)a/src/network/model/trailer.h (-1 / +19 lines)
 Lines 79-88    Link Here 
79
   * representation of this trailer in real networks.
79
   * representation of this trailer in real networks.
80
   * The input iterator points to the end of the area where the 
80
   * The input iterator points to the end of the area where the 
81
   * data shall be written. This method is thus expected to call
81
   * data shall be written. This method is thus expected to call
82
   * Buffer::Iterator::Prev prio to actually reading any data.
82
   * Buffer::Iterator::Prev prior to actually reading any data.
83
   */
83
   */
84
  virtual uint32_t Deserialize (Buffer::Iterator end) = 0;
84
  virtual uint32_t Deserialize (Buffer::Iterator end) = 0;
85
  /**
85
  /**
86
   * \param start an iterator which points to the start of the buffer
87
   *        where the trailer should be read from.
88
   * \param end an iterator which points to the end of the buffer
89
   *        where the trailer should be read from.
90
   * \returns the number of bytes read.
91
   *
92
   * This method is used by Packet::RemoveTrailer to
93
   * re-create a trailer from the byte buffer of a packet. 
94
   * The data read is expected to match bit-for-bit the 
95
   * representation of this trailer in real networks.
96
   * The input iterator end points to the end of the area where the 
97
   * data shall be written. 
98
   *
99
   * This variant should be provided by any variable-sized trailer subclass
100
   * (i.e. if GetSerializedSize () does not return a constant). 
101
   */
102
  virtual uint32_t Deserialize (Buffer::Iterator start, Buffer::Iterator end);
103
  /**
86
   * \param os output stream
104
   * \param os output stream
87
   * This method is used by Packet::Print to print the 
105
   * This method is used by Packet::Print to print the 
88
   * content of a trailer as ascii data to a c++ output stream.
106
   * content of a trailer as ascii data to a c++ output stream.

Return to bug 2505