A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
packet.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include "packet.h"
21 #include "ns3/assert.h"
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 #include <string>
25 #include <cstdarg>
26 
27 NS_LOG_COMPONENT_DEFINE ("Packet");
28 
29 namespace ns3 {
30 
31 uint32_t Packet::m_globalUid = 0;
32 
33 TypeId
35 {
36  return m_tid;
37 }
38 uint32_t
40 {
41  return m_start;
42 }
43 uint32_t
45 {
46  return m_end;
47 }
48 void
50 {
51  if (tag.GetInstanceTypeId () != GetTypeId ())
52  {
53  NS_FATAL_ERROR ("The tag you provided is not of the right type.");
54  }
55  tag.Deserialize (m_buffer);
56 }
57 ByteTagIterator::Item::Item (TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
58  : m_tid (tid),
59  m_start (start),
60  m_end (end),
61  m_buffer (buffer)
62 {
63 }
64 bool
66 {
67  return m_current.HasNext ();
68 }
71 {
73  return ByteTagIterator::Item (i.tid,
76  i.buf);
77 }
79  : m_current (i)
80 {
81 }
82 
83 
85  : m_current (head)
86 {
87 }
88 bool
90 {
91  return m_current != 0;
92 }
95 {
96  NS_ASSERT (HasNext ());
97  const struct PacketTagList::TagData *prev = m_current;
99  return PacketTagIterator::Item (prev);
100 }
101 
103  : m_data (data)
104 {
105 }
106 TypeId
108 {
109  return m_data->tid;
110 }
111 void
113 {
114  NS_ASSERT (tag.GetInstanceTypeId () == m_data->tid);
115  tag.Deserialize (TagBuffer ((uint8_t*)m_data->data,
116  (uint8_t*)m_data->data
118 }
119 
120 
122 Packet::Copy (void) const
123 {
124  // we need to invoke the copy constructor directly
125  // rather than calling Create because the copy constructor
126  // is private.
127  return Ptr<Packet> (new Packet (*this), false);
128 }
129 
131  : m_buffer (),
132  m_byteTagList (),
133  m_packetTagList (),
134  /* The upper 32 bits of the packet id in
135  * metadata is for the system id. For non-
136  * distributed simulations, this is simply
137  * zero. The lower 32 bits are for the
138  * global UID
139  */
140  m_metadata (static_cast<uint64_t> (Simulator::GetSystemId ()) << 32 | m_globalUid, 0),
141  m_nixVector (0)
142 {
143  m_globalUid++;
144 }
145 
147  : m_buffer (o.m_buffer),
148  m_byteTagList (o.m_byteTagList),
149  m_packetTagList (o.m_packetTagList),
150  m_metadata (o.m_metadata)
151 {
153  : m_nixVector = 0;
154 }
155 
156 Packet &
158 {
159  if (this == &o)
160  {
161  return *this;
162  }
163  m_buffer = o.m_buffer;
168  : m_nixVector = 0;
169  return *this;
170 }
171 
172 Packet::Packet (uint32_t size)
173  : m_buffer (size),
174  m_byteTagList (),
175  m_packetTagList (),
176  /* The upper 32 bits of the packet id in
177  * metadata is for the system id. For non-
178  * distributed simulations, this is simply
179  * zero. The lower 32 bits are for the
180  * global UID
181  */
182  m_metadata (static_cast<uint64_t> (Simulator::GetSystemId ()) << 32 | m_globalUid, size),
183  m_nixVector (0)
184 {
185  m_globalUid++;
186 }
187 Packet::Packet (uint8_t const *buffer, uint32_t size, bool magic)
188  : m_buffer (0, false),
189  m_byteTagList (),
190  m_packetTagList (),
191  m_metadata (0,0),
192  m_nixVector (0)
193 {
194  NS_ASSERT (magic);
195  Deserialize (buffer, size);
196 }
197 
198 Packet::Packet (uint8_t const*buffer, uint32_t size)
199  : m_buffer (),
200  m_byteTagList (),
201  m_packetTagList (),
202  /* The upper 32 bits of the packet id in
203  * metadata is for the system id. For non-
204  * distributed simulations, this is simply
205  * zero. The lower 32 bits are for the
206  * global UID
207  */
208  m_metadata (static_cast<uint64_t> (Simulator::GetSystemId ()) << 32 | m_globalUid, size),
209  m_nixVector (0)
210 {
211  m_globalUid++;
212  m_buffer.AddAtStart (size);
214  i.Write (buffer, size);
215 }
216 
217 Packet::Packet (const Buffer &buffer, const ByteTagList &byteTagList,
218  const PacketTagList &packetTagList, const PacketMetadata &metadata)
219  : m_buffer (buffer),
220  m_byteTagList (byteTagList),
221  m_packetTagList (packetTagList),
222  m_metadata (metadata),
223  m_nixVector (0)
224 {
225 }
226 
228 Packet::CreateFragment (uint32_t start, uint32_t length) const
229 {
230  NS_LOG_FUNCTION (this << start << length);
231  Buffer buffer = m_buffer.CreateFragment (start, length);
232  NS_ASSERT (m_buffer.GetSize () >= start + length);
233  uint32_t end = m_buffer.GetSize () - (start + length);
234  PacketMetadata metadata = m_metadata.CreateFragment (start, end);
235  // again, call the constructor directly rather than
236  // through Create because it is private.
237  return Ptr<Packet> (new Packet (buffer, m_byteTagList, m_packetTagList, metadata), false);
238 }
239 
240 void
242 {
243  m_nixVector = nixVector;
244 }
245 
248 {
249  return m_nixVector;
250 }
251 
252 void
253 Packet::AddHeader (const Header &header)
254 {
255  uint32_t size = header.GetSerializedSize ();
256  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << size);
257  uint32_t orgStart = m_buffer.GetCurrentStartOffset ();
258  bool resized = m_buffer.AddAtStart (size);
259  if (resized)
260  {
262  m_buffer.GetCurrentStartOffset () + size);
263  }
264  header.Serialize (m_buffer.Begin ());
265  m_metadata.AddHeader (header, size);
266 }
267 uint32_t
269 {
270  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
271  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized);
272  m_buffer.RemoveAtStart (deserialized);
273  m_metadata.RemoveHeader (header, deserialized);
274  return deserialized;
275 }
276 uint32_t
277 Packet::PeekHeader (Header &header) const
278 {
279  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
280  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized);
281  return deserialized;
282 }
283 void
284 Packet::AddTrailer (const Trailer &trailer)
285 {
286  uint32_t size = trailer.GetSerializedSize ();
287  NS_LOG_FUNCTION (this << trailer.GetInstanceTypeId ().GetName () << size);
288  uint32_t orgStart = m_buffer.GetCurrentStartOffset ();
289  bool resized = m_buffer.AddAtEnd (size);
290  if (resized)
291  {
293  m_buffer.GetCurrentEndOffset () - size);
294  }
295  Buffer::Iterator end = m_buffer.End ();
296  trailer.Serialize (end);
297  m_metadata.AddTrailer (trailer, size);
298 }
299 uint32_t
301 {
302  uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
303  NS_LOG_FUNCTION (this << trailer.GetInstanceTypeId ().GetName () << deserialized);
304  m_buffer.RemoveAtEnd (deserialized);
305  m_metadata.RemoveTrailer (trailer, deserialized);
306  return deserialized;
307 }
308 uint32_t
310 {
311  uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
312  NS_LOG_FUNCTION (this << trailer.GetInstanceTypeId ().GetName () << deserialized);
313  return deserialized;
314 }
315 
316 void
318 {
319  NS_LOG_FUNCTION (this << packet << packet->GetSize ());
320  uint32_t aStart = m_buffer.GetCurrentStartOffset ();
321  uint32_t bEnd = packet->m_buffer.GetCurrentEndOffset ();
322  m_buffer.AddAtEnd (packet->m_buffer);
323  uint32_t appendPrependOffset = m_buffer.GetCurrentEndOffset () - packet->m_buffer.GetSize ();
325  appendPrependOffset);
326  ByteTagList copy = packet->m_byteTagList;
327  copy.AddAtStart (m_buffer.GetCurrentEndOffset () - bEnd,
328  appendPrependOffset);
329  m_byteTagList.Add (copy);
330  m_metadata.AddAtEnd (packet->m_metadata);
331 }
332 void
333 Packet::AddPaddingAtEnd (uint32_t size)
334 {
335  NS_LOG_FUNCTION (this << size);
336  uint32_t orgEnd = m_buffer.GetCurrentEndOffset ();
337  bool resized = m_buffer.AddAtEnd (size);
338  if (resized)
339  {
341  m_buffer.GetCurrentEndOffset () - size);
342  }
344 }
345 void
346 Packet::RemoveAtEnd (uint32_t size)
347 {
348  NS_LOG_FUNCTION (this << size);
349  m_buffer.RemoveAtEnd (size);
350  m_metadata.RemoveAtEnd (size);
351 }
352 void
353 Packet::RemoveAtStart (uint32_t size)
354 {
355  NS_LOG_FUNCTION (this << size);
356  m_buffer.RemoveAtStart (size);
357  m_metadata.RemoveAtStart (size);
358 }
359 
360 void
362 {
363  NS_LOG_FUNCTION (this);
365 }
366 
367 uint8_t const *
368 Packet::PeekData (void) const
369 {
370  NS_LOG_FUNCTION (this);
371  uint32_t oldStart = m_buffer.GetCurrentStartOffset ();
372  uint8_t const * data = m_buffer.PeekData ();
373  uint32_t newStart = m_buffer.GetCurrentStartOffset ();
374 
375  // Update tag offsets if buffer offsets were changed
376  const_cast<ByteTagList &>(m_byteTagList).AddAtStart (newStart - oldStart, newStart);
377  return data;
378 }
379 
380 uint32_t
381 Packet::CopyData (uint8_t *buffer, uint32_t size) const
382 {
383  return m_buffer.CopyData (buffer, size);
384 }
385 
386 void
387 Packet::CopyData (std::ostream *os, uint32_t size) const
388 {
389  return m_buffer.CopyData (os, size);
390 }
391 
392 uint64_t
393 Packet::GetUid (void) const
394 {
395  return m_metadata.GetUid ();
396 }
397 
398 void
399 Packet::PrintByteTags (std::ostream &os) const
400 {
402  while (i.HasNext ())
403  {
404  ByteTagIterator::Item item = i.Next ();
405  os << item.GetTypeId ().GetName () << " [" << item.GetStart () << "-" << item.GetEnd () << "]";
406  Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
407  if (constructor.IsNull ())
408  {
409  if (i.HasNext ())
410  {
411  os << " ";
412  }
413  continue;
414  }
415  Tag *tag = dynamic_cast<Tag *> (constructor ());
416  NS_ASSERT (tag != 0);
417  os << " ";
418  item.GetTag (*tag);
419  tag->Print (os);
420  if (i.HasNext ())
421  {
422  os << " ";
423  }
424  delete tag;
425  }
426 }
427 
428 void
429 Packet::Print (std::ostream &os) const
430 {
432  while (i.HasNext ())
433  {
434  PacketMetadata::Item item = i.Next ();
435  if (item.isFragment)
436  {
437  switch (item.type) {
439  os << "Payload";
440  break;
443  os << item.tid.GetName ();
444  break;
445  }
446  os << " Fragment [" << item.currentTrimedFromStart<<":"
447  << (item.currentTrimedFromStart + item.currentSize) << "]";
448  }
449  else
450  {
451  switch (item.type) {
453  os << "Payload (size=" << item.currentSize << ")";
454  break;
457  os << item.tid.GetName () << " (";
458  {
459  NS_ASSERT (item.tid.HasConstructor ());
460  Callback<ObjectBase *> constructor = item.tid.GetConstructor ();
461  NS_ASSERT (!constructor.IsNull ());
462  ObjectBase *instance = constructor ();
463  NS_ASSERT (instance != 0);
464  Chunk *chunk = dynamic_cast<Chunk *> (instance);
465  NS_ASSERT (chunk != 0);
466  chunk->Deserialize (item.current);
467  chunk->Print (os);
468  delete chunk;
469  }
470  os << ")";
471  break;
472  }
473  }
474  if (i.HasNext ())
475  {
476  os << " ";
477  }
478  }
479 #if 0
480  // The code below will work only if headers and trailers
481  // define the right attributes which is not the case for
482  // now. So, as a temporary measure, we use the
483  // headers' and trailers' Print method as shown above.
485  while (i.HasNext ())
486  {
487  PacketMetadata::Item item = i.Next ();
488  if (item.isFragment)
489  {
490  switch (item.type) {
492  os << "Payload";
493  break;
496  os << item.tid.GetName ();
497  break;
498  }
499  os << " Fragment [" << item.currentTrimedFromStart<<":"
500  << (item.currentTrimedFromStart + item.currentSize) << "]";
501  }
502  else
503  {
504  switch (item.type) {
506  os << "Payload (size=" << item.currentSize << ")";
507  break;
510  os << item.tid.GetName () << "(";
511  {
512  NS_ASSERT (item.tid.HasConstructor ());
513  Callback<ObjectBase *> constructor = item.tid.GetConstructor ();
514  NS_ASSERT (constructor.IsNull ());
515  ObjectBase *instance = constructor ();
516  NS_ASSERT (instance != 0);
517  Chunk *chunk = dynamic_cast<Chunk *> (instance);
518  NS_ASSERT (chunk != 0);
519  chunk->Deserialize (item.current);
520  for (uint32_t j = 0; j < item.tid.GetAttributeN (); j++)
521  {
522  std::string attrName = item.tid.GetAttributeName (j);
523  std::string value;
524  bool ok = chunk->GetAttribute (attrName, value);
525  NS_ASSERT (ok);
526  os << attrName << "=" << value;
527  if ((j + 1) < item.tid.GetAttributeN ())
528  {
529  os << ",";
530  }
531  }
532  }
533  os << ")";
534  break;
535  }
536  }
537  if (i.HasNext ())
538  {
539  os << " ";
540  }
541  }
542 #endif
543 }
544 
546 Packet::BeginItem (void) const
547 {
548  return m_metadata.BeginItem (m_buffer);
549 }
550 
551 void
553 {
556 }
557 
558 void
560 {
563 }
564 
565 uint32_t Packet::GetSerializedSize (void) const
566 {
567  uint32_t size = 0;
568 
569  if (m_nixVector)
570  {
571  // increment total size by the size of the nix-vector
572  // ensuring 4-byte boundary
573  size += ((m_nixVector->GetSerializedSize () + 3) & (~3));
574 
575  // add 4-bytes for entry of total length of nix-vector
576  size += 4;
577  }
578  else
579  {
580  // if no nix-vector, still have to add 4-bytes
581  // to account for the entry of total size for
582  // nix-vector in the buffer
583  size += 4;
584  }
585 
586  //Tag size
588  //size += m_tags.GetSerializedSize ();
589 
590  // increment total size by size of meta-data
591  // ensuring 4-byte boundary
592  size += ((m_metadata.GetSerializedSize () + 3) & (~3));
593 
594  // add 4-bytes for entry of total length of meta-data
595  size += 4;
596 
597  // increment total size by size of buffer
598  // ensuring 4-byte boundary
599  size += ((m_buffer.GetSerializedSize () + 3) & (~3));
600 
601  // add 4-bytes for entry of total length of buffer
602  size += 4;
603 
604  return size;
605 }
606 
607 uint32_t
608 Packet::Serialize (uint8_t* buffer, uint32_t maxSize) const
609 {
610  uint32_t* p = reinterpret_cast<uint32_t *> (buffer);
611  uint32_t size = 0;
612 
613  // if nix-vector exists, serialize it
614  if (m_nixVector)
615  {
616  uint32_t nixSize = m_nixVector->GetSerializedSize ();
617  if (size + nixSize <= maxSize)
618  {
619  // put the total length of nix-vector in the
620  // buffer. this includes 4-bytes for total
621  // length itself
622  *p++ = nixSize + 4;
623  size += nixSize;
624 
625  // serialize the nix-vector
626  uint32_t serialized =
627  m_nixVector->Serialize (p, nixSize);
628  if (serialized)
629  {
630  // increment p by nixSize bytes
631  // ensuring 4-byte boundary
632  p += ((nixSize+3) & (~3)) / 4;
633  }
634  else
635  {
636  return 0;
637  }
638  }
639  else
640  {
641  return 0;
642  }
643  }
644  else
645  {
646  // no nix vector, set zero length,
647  // ie 4-bytes, since it must include
648  // length for itself
649  if (size + 4 <= maxSize)
650  {
651  size += 4;
652  *p++ = 4;
653  }
654  else
655  {
656  return 0;
657  }
658  }
659 
660  // Serialize Tags
662 
663  // Serialize Metadata
664  uint32_t metaSize = m_metadata.GetSerializedSize ();
665  if (size + metaSize <= maxSize)
666  {
667  // put the total length of metadata in the
668  // buffer. this includes 4-bytes for total
669  // length itself
670  *p++ = metaSize + 4;
671  size += metaSize;
672 
673  // serialize the metadata
674  uint32_t serialized =
675  m_metadata.Serialize (reinterpret_cast<uint8_t *> (p), metaSize);
676  if (serialized)
677  {
678  // increment p by metaSize bytes
679  // ensuring 4-byte boundary
680  p += ((metaSize+3) & (~3)) / 4;
681  }
682  else
683  {
684  return 0;
685  }
686  }
687  else
688  {
689  return 0;
690  }
691 
692  // Serialize the packet contents
693  uint32_t bufSize = m_buffer.GetSerializedSize ();
694  if (size + bufSize <= maxSize)
695  {
696  // put the total length of the buffer in the
697  // buffer. this includes 4-bytes for total
698  // length itself
699  *p++ = bufSize + 4;
700  size += bufSize;
701 
702  // serialize the buffer
703  uint32_t serialized =
704  m_buffer.Serialize (reinterpret_cast<uint8_t *> (p), bufSize);
705  if (serialized)
706  {
707  // increment p by bufSize bytes
708  // ensuring 4-byte boundary
709  p += ((bufSize+3) & (~3)) / 4;
710  }
711  else
712  {
713  return 0;
714  }
715  }
716  else
717  {
718  return 0;
719  }
720 
721  // Serialized successfully
722  return 1;
723 }
724 
725 uint32_t
726 Packet::Deserialize (const uint8_t* buffer, uint32_t size)
727 {
728  NS_LOG_FUNCTION (this);
729 
730  const uint32_t* p = reinterpret_cast<const uint32_t *> (buffer);
731 
732  // read nix-vector
734  uint32_t nixSize = *p++;
735 
736  // if size less than nixSize, the buffer
737  // will be overrun, assert
738  NS_ASSERT (size >= nixSize);
739 
740  size -= nixSize;
741 
742  if (nixSize > 4)
743  {
744  Ptr<NixVector> nix = Create<NixVector> ();
745  uint32_t nixDeserialized = nix->Deserialize (p, nixSize);
746  if (!nixDeserialized)
747  {
748  // nix-vector not deserialized
749  // completely
750  return 0;
751  }
752  m_nixVector = nix;
753  // increment p by nixSize ensuring
754  // 4-byte boundary
755  p += ((((nixSize - 4) + 3) & (~3)) / 4);
756  }
757 
758  // read tags
760  //uint32_t tagsDeserialized = m_tags.Deserialize (buffer.Begin ());
761  //buffer.RemoveAtStart (tagsDeserialized);
762 
763  // read metadata
764  uint32_t metaSize = *p++;
765 
766  // if size less than metaSize, the buffer
767  // will be overrun, assert
768  NS_ASSERT (size >= metaSize);
769 
770  size -= metaSize;
771 
772  uint32_t metadataDeserialized =
773  m_metadata.Deserialize (reinterpret_cast<const uint8_t *> (p), metaSize);
774  if (!metadataDeserialized)
775  {
776  // meta-data not deserialized
777  // completely
778  return 0;
779  }
780  // increment p by metaSize ensuring
781  // 4-byte boundary
782  p += ((((metaSize - 4) + 3) & (~3)) / 4);
783 
784  // read buffer contents
785  uint32_t bufSize = *p++;
786 
787  // if size less than bufSize, the buffer
788  // will be overrun, assert
789  NS_ASSERT (size >= bufSize);
790 
791  size -= bufSize;
792 
793  uint32_t bufferDeserialized =
794  m_buffer.Deserialize (reinterpret_cast<const uint8_t *> (p), bufSize);
795  if (!bufferDeserialized)
796  {
797  // buffer not deserialized
798  // completely
799  return 0;
800  }
801 
802  // return zero if did not deserialize the
803  // number of expected bytes
804  return (size == 0);
805 }
806 
807 void
808 Packet::AddByteTag (const Tag &tag) const
809 {
810  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
811  ByteTagList *list = const_cast<ByteTagList *> (&m_byteTagList);
812  TagBuffer buffer = list->Add (tag.GetInstanceTypeId (), tag.GetSerializedSize (),
815  tag.Serialize (buffer);
816 }
819 {
821 }
822 
823 bool
825 {
826  TypeId tid = tag.GetInstanceTypeId ();
828  while (i.HasNext ())
829  {
830  ByteTagIterator::Item item = i.Next ();
831  if (tid == item.GetTypeId ())
832  {
833  item.GetTag (tag);
834  return true;
835  }
836  }
837  return false;
838 }
839 
840 void
841 Packet::AddPacketTag (const Tag &tag) const
842 {
843  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
844  m_packetTagList.Add (tag);
845 }
846 
847 bool
849 {
850  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
851  bool found = m_packetTagList.Remove (tag);
852  return found;
853 }
854 bool
856 {
857  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
858  bool found = m_packetTagList.Replace (tag);
859  return found;
860 }
861 
862 bool
864 {
865  bool found = m_packetTagList.Peek (tag);
866  return found;
867 }
868 void
870 {
871  NS_LOG_FUNCTION (this);
873 }
874 
875 void
876 Packet::PrintPacketTags (std::ostream &os) const
877 {
879  while (i.HasNext ())
880  {
881  PacketTagIterator::Item item = i.Next ();
882  NS_ASSERT (item.GetTypeId ().HasConstructor ());
883  Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
884  NS_ASSERT (!constructor.IsNull ());
885  ObjectBase *instance = constructor ();
886  Tag *tag = dynamic_cast<Tag *> (instance);
887  NS_ASSERT (tag != 0);
888  item.GetTag (*tag);
889  tag->Print (os);
890  delete tag;
891  if (i.HasNext ())
892  {
893  os << " ";
894  }
895  }
896 }
897 
900 {
902 }
903 
904 std::ostream& operator<< (std::ostream& os, const Packet &packet)
905 {
906  packet.Print (os);
907  return os;
908 }
909 
910 } // namespace ns3
bool HasNext(void) const
Definition: packet.cc:65
Protocol header serialization and deserialization.
Definition: header.h:42
void RemoveAtEnd(uint32_t end)
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
PacketMetadata m_metadata
Definition: packet.h:590
uint32_t GetAttributeN(void) const
Definition: type-id.cc:739
bool FindFirstMatchingByteTag(Tag &tag) const
Definition: packet.cc:824
bool Remove(Tag &tag)
Remove (the first instance of) tag from the list.
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
void PrintPacketTags(std::ostream &os) const
Print the list of packet tags.
Definition: packet.cc:876
Control the scheduling of simulation events.
Definition: simulator.h:62
Callback template class.
Definition: callback.h:920
void RemoveAtEnd(uint32_t end)
Definition: buffer.cc:497
struct TagData * next
Pointer to next in list.
uint32_t Deserialize(uint8_t const *buffer, uint32_t size)
Definition: packet.cc:726
void RemoveAtStart(uint32_t start)
Definition: buffer.cc:452
virtual uint32_t GetSerializedSize(void) const =0
const struct PacketTagList::TagData * Head(void) const
uint64_t GetUid(void) const
automatically resized byte buffer
Definition: buffer.h:92
Ptr< NixVector > Copy(void) const
Definition: nix-vector.cc:71
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:841
List of the packet tags stored in a packet.
uint64_t GetUid(void) const
A packet is allocated a new uid when it is created empty or with zero-filled payload.
Definition: packet.cc:393
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Serialize a packet, tags, and metadata into a byte buffer.
Definition: packet.cc:608
keep track of the byte tags stored in a packet.
Definition: byte-tag-list.h:68
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1014
static uint32_t m_globalUid
Definition: packet.h:595
static void EnableChecking(void)
#define NS_ASSERT(condition)
Definition: assert.h:64
bool HasNext(void) const
TagBuffer Add(TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
uint32_t GetSize(void) const
Definition: packet.h:650
uint32_t GetSerializedSize(void) const
Definition: buffer.cc:570
uint32_t GetSerializedSize(void) const
Buffer m_buffer
Definition: packet.h:587
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
implement the ns-3 type and attribute system
Definition: object-base.h:70
Ptr< NixVector > GetNixVector(void) const
Get the packet nix-vector.
Definition: packet.cc:247
Item(TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
Definition: packet.cc:57
void Print(std::ostream &os) const
Definition: packet.cc:429
Packet & operator=(const Packet &o)
Definition: packet.cc:157
network packets
Definition: packet.h:203
virtual uint32_t Deserialize(Buffer::Iterator start)=0
bool Peek(Tag &tag) const
Find a tag and return its value.
Item Next(void)
Definition: packet.cc:94
void AddHeader(Header const &header, uint32_t size)
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
PacketTagIterator GetPacketTagIterator(void) const
Definition: packet.cc:899
iterator in a Buffer instance
Definition: buffer.h:98
Callback< ObjectBase * > GetConstructor(void) const
Definition: type-id.cc:723
ByteTagList::Iterator m_current
Definition: packet.h:104
Packet()
Create an empty packet with a new uid (as returned by getUid).
Definition: packet.cc:130
void Add(Tag const &tag) const
Add a tag to the head of this branch.
bool HasConstructor(void) const
Definition: type-id.cc:673
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
Definition: packet.cc:112
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:228
uint32_t PeekTrailer(Trailer &trailer)
Deserialize but does not remove a trailer from the internal buffer.
Definition: packet.cc:309
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:317
void RemoveAll(void)
Removes all of the tags from the ByteTagList.
Tree node for sharing serialized tags.
uint32_t Deserialize(const uint8_t *buffer, uint32_t size)
Definition: buffer.cc:660
uint8_t const * PeekData(void) const NS_DEPRECATED
Definition: packet.cc:368
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:863
void RemoveAllPacketTags(void)
Remove all packet tags.
Definition: packet.cc:869
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
Definition: packet.h:57
void AddTrailer(Trailer const &trailer, uint32_t size)
bool HasNext(void) const
Definition: packet.cc:89
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:353
void AddPaddingAtEnd(uint32_t end)
bool Replace(Tag &tag)
Replace the value of a tag.
static void EnablePrinting(void)
By default, packets do not keep around enough metadata to perform the operations requested by the Pri...
Definition: packet.cc:552
PacketMetadata CreateFragment(uint32_t start, uint32_t end) const
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
Definition: nix-vector.cc:225
virtual void Print(std::ostream &os) const =0
void SetNixVector(Ptr< NixVector >)
Set the packet nix-vector.
Definition: packet.cc:241
ByteTagList m_byteTagList
Definition: packet.h:588
uint8_t data[writeSize]
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:855
uint32_t GetSerializedSize(void) const
Definition: nix-vector.cc:214
Buffer::Iterator End(void) const
Definition: buffer.h:881
static void EnableChecking(void)
The packet metadata is also used to perform extensive sanity checks at runtime when performing operat...
Definition: packet.cc:559
uint8_t const * PeekData(void) const
Definition: buffer.cc:729
void AddPaddingAtEnd(uint32_t size)
Definition: packet.cc:333
int32_t start
size of tag data
Definition: byte-tag-list.h:90
virtual void Serialize(Buffer::Iterator start) const =0
ByteTagIterator GetByteTagIterator(void) const
Definition: packet.cc:818
void CopyData(std::ostream *os, uint32_t size) const
Copy the specified amount of data from the buffer to the given output stream.
Definition: buffer.cc:739
virtual uint32_t Deserialize(Buffer::Iterator end)=0
Item Next(void)
Definition: packet.cc:70
uint32_t GetEnd(void) const
Definition: packet.cc:44
int32_t GetCurrentEndOffset(void) const
Definition: buffer.cc:710
Iterator over the set of packet tags in a packet.
Definition: packet.h:113
void PrintByteTags(std::ostream &os) const
Definition: packet.cc:399
void AddAtEnd(int32_t adjustment, int32_t appendOffset)
Adjust the offsets stored internally by the adjustment delta and make sure that all offsets are small...
const struct PacketTagList::TagData * m_current
Definition: packet.h:151
Buffer::Iterator Begin(void) const
Definition: buffer.h:875
void AddAtEnd(PacketMetadata const &o)
struct ByteTagList::Iterator::Item Next(void)
#define list
virtual uint32_t Deserialize(Buffer::Iterator start)=0
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
Ptr< Packet > Copy(void) const
Definition: packet.cc:122
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:277
Protocol trailer serialization and deserialization.
Definition: trailer.h:40
virtual void Serialize(TagBuffer i) const =0
tag a set of bytes in a packet
Definition: tag.h:36
static void Enable(void)
virtual uint32_t GetSerializedSize(void) const =0
PacketMetadata::ItemIterator BeginItem(void) const
Definition: packet.cc:546
PacketTagIterator(const struct PacketTagList::TagData *head)
Definition: packet.cc:84
enum ns3::PacketMetadata::Item::@79 type
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Definition: packet.cc:284
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet It is safe to remove more bytes than are present...
Definition: packet.cc:346
friend class Packet
Definition: packet.h:149
Iterator over the set of byte tags in a packet.
Definition: packet.h:50
virtual void Deserialize(TagBuffer i)=0
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
Definition: packet.cc:300
std::string GetName(void) const
Definition: type-id.cc:658
uint32_t GetOffsetStart(void) const
PacketTagList m_packetTagList
Definition: packet.h:589
NS_LOG_COMPONENT_DEFINE("Packet")
int32_t end
offset to the start of the tag from the virtual byte buffer
Definition: byte-tag-list.h:91
uint32_t Deserialize(const uint8_t *buffer, uint32_t size)
TypeId GetTypeId(void) const
Definition: packet.cc:34
void GetAttribute(std::string name, AttributeValue &value) const
Definition: object-base.cc:199
Identifies a packet tag within a packet.
Definition: packet.h:119
uint32_t GetSize(void) const
Definition: buffer.h:869
void RemoveHeader(Header const &header, uint32_t size)
TypeId GetTypeId(void) const
Definition: packet.cc:107
Buffer CreateFragment(uint32_t start, uint32_t length) const
Definition: buffer.cc:533
bool AddAtEnd(uint32_t end)
Definition: buffer.cc:356
Item(const struct PacketTagList::TagData *data)
Definition: packet.cc:102
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
Definition: packet.cc:49
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Definition: buffer.cc:590
Size of serialization buffer data.
ByteTagList::Iterator Begin(int32_t offsetStart, int32_t offsetEnd) const
TagBuffer buf
offset to the end of the tag from the virtual byte buffer
Definition: byte-tag-list.h:92
read and write tag data
Definition: tag-buffer.h:51
uint32_t GetStart(void) const
Definition: packet.cc:39
void RemoveTrailer(Trailer const &trailer, uint32_t size)
uint32_t GetSerializedSize(void) const
Definition: packet.cc:565
virtual TypeId GetInstanceTypeId(void) const =0
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:848
ItemIterator BeginItem(Buffer buffer) const
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Definition: packet.cc:361
virtual uint32_t GetSerializedSize(void) const =0
Ptr< NixVector > m_nixVector
Definition: packet.h:593
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
Definition: nix-vector.cc:282
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:978
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:381
virtual void Serialize(Buffer::Iterator start) const =0
ByteTagIterator(ByteTagList::Iterator i)
Definition: packet.cc:78
bool AddAtStart(uint32_t start)
Definition: buffer.cc:305
void RemoveAtStart(uint32_t start)
int32_t GetCurrentStartOffset(void) const
Definition: buffer.cc:704
void RemoveAll(void)
Remove all tags from this list (up to the first merge).
a unique identifier for an interface.
Definition: type-id.h:49
abstract base class for ns3::Header and ns3::Trailer
Definition: chunk.h:14
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
virtual void Print(std::ostream &os) const =0
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
void AddAtStart(int32_t adjustment, int32_t prependOffset)
Adjust the offsets stored internally by the adjustment delta and make sure that all offsets are bigge...
handle packet metadata about packet headers and trailers
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:808