This documentation is not the Latest Release.
A Discrete-Event Network Simulator
API
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 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("Packet");
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  ByteTagList byteTagList = m_byteTagList;
233  byteTagList.Adjust (-start);
234  NS_ASSERT (m_buffer.GetSize () >= start + length);
235  uint32_t end = m_buffer.GetSize () - (start + length);
236  PacketMetadata metadata = m_metadata.CreateFragment (start, end);
237  // again, call the constructor directly rather than
238  // through Create because it is private.
239  return Ptr<Packet> (new Packet (buffer, byteTagList, m_packetTagList, metadata), false);
240 }
241 
242 void
244 {
245  m_nixVector = nixVector;
246 }
247 
250 {
251  return m_nixVector;
252 }
253 
254 void
255 Packet::AddHeader (const Header &header)
256 {
257  uint32_t size = header.GetSerializedSize ();
258  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << size);
259  m_buffer.AddAtStart (size);
260  m_byteTagList.Adjust (size);
261  m_byteTagList.AddAtStart (size);
262  header.Serialize (m_buffer.Begin ());
263  m_metadata.AddHeader (header, size);
264 }
265 uint32_t
267 {
268  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
269  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized);
270  m_buffer.RemoveAtStart (deserialized);
271  m_byteTagList.Adjust (-deserialized);
272  m_metadata.RemoveHeader (header, deserialized);
273  return deserialized;
274 }
275 uint32_t
276 Packet::PeekHeader (Header &header) const
277 {
278  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
279  NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized);
280  return deserialized;
281 }
282 void
283 Packet::AddTrailer (const Trailer &trailer)
284 {
285  uint32_t size = trailer.GetSerializedSize ();
286  NS_LOG_FUNCTION (this << trailer.GetInstanceTypeId ().GetName () << size);
288  m_buffer.AddAtEnd (size);
289  Buffer::Iterator end = m_buffer.End ();
290  trailer.Serialize (end);
291  m_metadata.AddTrailer (trailer, size);
292 }
293 uint32_t
295 {
296  uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
297  NS_LOG_FUNCTION (this << trailer.GetInstanceTypeId ().GetName () << deserialized);
298  m_buffer.RemoveAtEnd (deserialized);
299  m_metadata.RemoveTrailer (trailer, deserialized);
300  return deserialized;
301 }
302 uint32_t
304 {
305  uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
306  NS_LOG_FUNCTION (this << trailer.GetInstanceTypeId ().GetName () << deserialized);
307  return deserialized;
308 }
309 
310 void
312 {
313  NS_LOG_FUNCTION (this << packet << packet->GetSize ());
315  ByteTagList copy = packet->m_byteTagList;
316  copy.AddAtStart (0);
317  copy.Adjust (GetSize ());
318  m_byteTagList.Add (copy);
319  m_buffer.AddAtEnd (packet->m_buffer);
320  m_metadata.AddAtEnd (packet->m_metadata);
321 }
322 void
323 Packet::AddPaddingAtEnd (uint32_t size)
324 {
325  NS_LOG_FUNCTION (this << size);
327  m_buffer.AddAtEnd (size);
329 }
330 void
331 Packet::RemoveAtEnd (uint32_t size)
332 {
333  NS_LOG_FUNCTION (this << size);
334  m_buffer.RemoveAtEnd (size);
335  m_metadata.RemoveAtEnd (size);
336 }
337 void
338 Packet::RemoveAtStart (uint32_t size)
339 {
340  NS_LOG_FUNCTION (this << size);
341  m_buffer.RemoveAtStart (size);
342  m_byteTagList.Adjust (-size);
343  m_metadata.RemoveAtStart (size);
344 }
345 
346 void
348 {
349  NS_LOG_FUNCTION (this);
351 }
352 
353 uint32_t
354 Packet::CopyData (uint8_t *buffer, uint32_t size) const
355 {
356  return m_buffer.CopyData (buffer, size);
357 }
358 
359 void
360 Packet::CopyData (std::ostream *os, uint32_t size) const
361 {
362  return m_buffer.CopyData (os, size);
363 }
364 
365 uint64_t
366 Packet::GetUid (void) const
367 {
368  return m_metadata.GetUid ();
369 }
370 
371 void
372 Packet::PrintByteTags (std::ostream &os) const
373 {
375  while (i.HasNext ())
376  {
377  ByteTagIterator::Item item = i.Next ();
378  os << item.GetTypeId ().GetName () << " [" << item.GetStart () << "-" << item.GetEnd () << "]";
379  Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
380  if (constructor.IsNull ())
381  {
382  if (i.HasNext ())
383  {
384  os << " ";
385  }
386  continue;
387  }
388  Tag *tag = dynamic_cast<Tag *> (constructor ());
389  NS_ASSERT (tag != 0);
390  os << " ";
391  item.GetTag (*tag);
392  tag->Print (os);
393  if (i.HasNext ())
394  {
395  os << " ";
396  }
397  delete tag;
398  }
399 }
400 
401 std::string
403 {
404  std::ostringstream oss;
405  Print (oss);
406  return oss.str();
407 }
408 
409 void
410 Packet::Print (std::ostream &os) const
411 {
413  while (i.HasNext ())
414  {
415  PacketMetadata::Item item = i.Next ();
416  if (item.isFragment)
417  {
418  switch (item.type) {
420  os << "Payload";
421  break;
424  os << item.tid.GetName ();
425  break;
426  }
427  os << " Fragment [" << item.currentTrimedFromStart<<":"
428  << (item.currentTrimedFromStart + item.currentSize) << "]";
429  }
430  else
431  {
432  switch (item.type) {
434  os << "Payload (size=" << item.currentSize << ")";
435  break;
438  os << item.tid.GetName () << " (";
439  {
440  NS_ASSERT (item.tid.HasConstructor ());
441  Callback<ObjectBase *> constructor = item.tid.GetConstructor ();
442  NS_ASSERT (!constructor.IsNull ());
443  ObjectBase *instance = constructor ();
444  NS_ASSERT (instance != 0);
445  Chunk *chunk = dynamic_cast<Chunk *> (instance);
446  NS_ASSERT (chunk != 0);
447  chunk->Deserialize (item.current);
448  chunk->Print (os);
449  delete chunk;
450  }
451  os << ")";
452  break;
453  }
454  }
455  if (i.HasNext ())
456  {
457  os << " ";
458  }
459  }
460 #if 0
461  // The code below will work only if headers and trailers
462  // define the right attributes which is not the case for
463  // now. So, as a temporary measure, we use the
464  // headers' and trailers' Print method as shown above.
466  while (i.HasNext ())
467  {
468  PacketMetadata::Item item = i.Next ();
469  if (item.isFragment)
470  {
471  switch (item.type) {
473  os << "Payload";
474  break;
477  os << item.tid.GetName ();
478  break;
479  }
480  os << " Fragment [" << item.currentTrimedFromStart<<":"
481  << (item.currentTrimedFromStart + item.currentSize) << "]";
482  }
483  else
484  {
485  switch (item.type) {
487  os << "Payload (size=" << item.currentSize << ")";
488  break;
491  os << item.tid.GetName () << "(";
492  {
493  NS_ASSERT (item.tid.HasConstructor ());
494  Callback<ObjectBase *> constructor = item.tid.GetConstructor ();
495  NS_ASSERT (constructor.IsNull ());
496  ObjectBase *instance = constructor ();
497  NS_ASSERT (instance != 0);
498  Chunk *chunk = dynamic_cast<Chunk *> (instance);
499  NS_ASSERT (chunk != 0);
500  chunk->Deserialize (item.current);
501  for (uint32_t j = 0; j < item.tid.GetAttributeN (); j++)
502  {
503  std::string attrName = item.tid.GetAttributeName (j);
504  std::string value;
505  bool ok = chunk->GetAttribute (attrName, value);
506  NS_ASSERT (ok);
507  os << attrName << "=" << value;
508  if ((j + 1) < item.tid.GetAttributeN ())
509  {
510  os << ",";
511  }
512  }
513  }
514  os << ")";
515  break;
516  }
517  }
518  if (i.HasNext ())
519  {
520  os << " ";
521  }
522  }
523 #endif
524 }
525 
527 Packet::BeginItem (void) const
528 {
529  return m_metadata.BeginItem (m_buffer);
530 }
531 
532 void
534 {
537 }
538 
539 void
541 {
544 }
545 
546 uint32_t Packet::GetSerializedSize (void) const
547 {
548  uint32_t size = 0;
549 
550  if (m_nixVector)
551  {
552  // increment total size by the size of the nix-vector
553  // ensuring 4-byte boundary
554  size += ((m_nixVector->GetSerializedSize () + 3) & (~3));
555 
556  // add 4-bytes for entry of total length of nix-vector
557  size += 4;
558  }
559  else
560  {
561  // if no nix-vector, still have to add 4-bytes
562  // to account for the entry of total size for
563  // nix-vector in the buffer
564  size += 4;
565  }
566 
567  //Tag size
569  //size += m_tags.GetSerializedSize ();
570 
571  // increment total size by size of meta-data
572  // ensuring 4-byte boundary
573  size += ((m_metadata.GetSerializedSize () + 3) & (~3));
574 
575  // add 4-bytes for entry of total length of meta-data
576  size += 4;
577 
578  // increment total size by size of buffer
579  // ensuring 4-byte boundary
580  size += ((m_buffer.GetSerializedSize () + 3) & (~3));
581 
582  // add 4-bytes for entry of total length of buffer
583  size += 4;
584 
585  return size;
586 }
587 
588 uint32_t
589 Packet::Serialize (uint8_t* buffer, uint32_t maxSize) const
590 {
591  uint32_t* p = reinterpret_cast<uint32_t *> (buffer);
592  uint32_t size = 0;
593 
594  // if nix-vector exists, serialize it
595  if (m_nixVector)
596  {
597  uint32_t nixSize = m_nixVector->GetSerializedSize ();
598  if (size + nixSize <= maxSize)
599  {
600  // put the total length of nix-vector in the
601  // buffer. this includes 4-bytes for total
602  // length itself
603  *p++ = nixSize + 4;
604  size += nixSize;
605 
606  // serialize the nix-vector
607  uint32_t serialized =
608  m_nixVector->Serialize (p, nixSize);
609  if (serialized)
610  {
611  // increment p by nixSize bytes
612  // ensuring 4-byte boundary
613  p += ((nixSize+3) & (~3)) / 4;
614  }
615  else
616  {
617  return 0;
618  }
619  }
620  else
621  {
622  return 0;
623  }
624  }
625  else
626  {
627  // no nix vector, set zero length,
628  // ie 4-bytes, since it must include
629  // length for itself
630  if (size + 4 <= maxSize)
631  {
632  size += 4;
633  *p++ = 4;
634  }
635  else
636  {
637  return 0;
638  }
639  }
640 
641  // Serialize Tags
643 
644  // Serialize Metadata
645  uint32_t metaSize = m_metadata.GetSerializedSize ();
646  if (size + metaSize <= maxSize)
647  {
648  // put the total length of metadata in the
649  // buffer. this includes 4-bytes for total
650  // length itself
651  *p++ = metaSize + 4;
652  size += metaSize;
653 
654  // serialize the metadata
655  uint32_t serialized =
656  m_metadata.Serialize (reinterpret_cast<uint8_t *> (p), metaSize);
657  if (serialized)
658  {
659  // increment p by metaSize bytes
660  // ensuring 4-byte boundary
661  p += ((metaSize+3) & (~3)) / 4;
662  }
663  else
664  {
665  return 0;
666  }
667  }
668  else
669  {
670  return 0;
671  }
672 
673  // Serialize the packet contents
674  uint32_t bufSize = m_buffer.GetSerializedSize ();
675  if (size + bufSize <= maxSize)
676  {
677  // put the total length of the buffer in the
678  // buffer. this includes 4-bytes for total
679  // length itself
680  *p++ = bufSize + 4;
681  size += bufSize;
682 
683  // serialize the buffer
684  uint32_t serialized =
685  m_buffer.Serialize (reinterpret_cast<uint8_t *> (p), bufSize);
686  if (serialized)
687  {
688  // increment p by bufSize bytes
689  // ensuring 4-byte boundary
690  p += ((bufSize+3) & (~3)) / 4;
691  }
692  else
693  {
694  return 0;
695  }
696  }
697  else
698  {
699  return 0;
700  }
701 
702  // Serialized successfully
703  return 1;
704 }
705 
706 uint32_t
707 Packet::Deserialize (const uint8_t* buffer, uint32_t size)
708 {
709  NS_LOG_FUNCTION (this);
710 
711  const uint32_t* p = reinterpret_cast<const uint32_t *> (buffer);
712 
713  // read nix-vector
715  uint32_t nixSize = *p++;
716 
717  // if size less than nixSize, the buffer
718  // will be overrun, assert
719  NS_ASSERT (size >= nixSize);
720 
721  size -= nixSize;
722 
723  if (nixSize > 4)
724  {
725  Ptr<NixVector> nix = Create<NixVector> ();
726  uint32_t nixDeserialized = nix->Deserialize (p, nixSize);
727  if (!nixDeserialized)
728  {
729  // nix-vector not deserialized
730  // completely
731  return 0;
732  }
733  m_nixVector = nix;
734  // increment p by nixSize ensuring
735  // 4-byte boundary
736  p += ((((nixSize - 4) + 3) & (~3)) / 4);
737  }
738 
739  // read tags
741  //uint32_t tagsDeserialized = m_tags.Deserialize (buffer.Begin ());
742  //buffer.RemoveAtStart (tagsDeserialized);
743 
744  // read metadata
745  uint32_t metaSize = *p++;
746 
747  // if size less than metaSize, the buffer
748  // will be overrun, assert
749  NS_ASSERT (size >= metaSize);
750 
751  size -= metaSize;
752 
753  uint32_t metadataDeserialized =
754  m_metadata.Deserialize (reinterpret_cast<const uint8_t *> (p), metaSize);
755  if (!metadataDeserialized)
756  {
757  // meta-data not deserialized
758  // completely
759  return 0;
760  }
761  // increment p by metaSize ensuring
762  // 4-byte boundary
763  p += ((((metaSize - 4) + 3) & (~3)) / 4);
764 
765  // read buffer contents
766  uint32_t bufSize = *p++;
767 
768  // if size less than bufSize, the buffer
769  // will be overrun, assert
770  NS_ASSERT (size >= bufSize);
771 
772  size -= bufSize;
773 
774  uint32_t bufferDeserialized =
775  m_buffer.Deserialize (reinterpret_cast<const uint8_t *> (p), bufSize);
776  if (!bufferDeserialized)
777  {
778  // buffer not deserialized
779  // completely
780  return 0;
781  }
782 
783  // return zero if did not deserialize the
784  // number of expected bytes
785  return (size == 0);
786 }
787 
788 void
789 Packet::AddByteTag (const Tag &tag) const
790 {
791  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
792  ByteTagList *list = const_cast<ByteTagList *> (&m_byteTagList);
793  TagBuffer buffer = list->Add (tag.GetInstanceTypeId (), tag.GetSerializedSize (),
794  0,
795  GetSize ());
796  tag.Serialize (buffer);
797 }
800 {
801  return ByteTagIterator (m_byteTagList.Begin (0, GetSize ()));
802 }
803 
804 bool
806 {
807  TypeId tid = tag.GetInstanceTypeId ();
809  while (i.HasNext ())
810  {
811  ByteTagIterator::Item item = i.Next ();
812  if (tid == item.GetTypeId ())
813  {
814  item.GetTag (tag);
815  return true;
816  }
817  }
818  return false;
819 }
820 
821 void
822 Packet::AddPacketTag (const Tag &tag) const
823 {
824  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
825  m_packetTagList.Add (tag);
826 }
827 
828 bool
830 {
831  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
832  bool found = m_packetTagList.Remove (tag);
833  return found;
834 }
835 bool
837 {
838  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
839  bool found = m_packetTagList.Replace (tag);
840  return found;
841 }
842 
843 bool
845 {
846  bool found = m_packetTagList.Peek (tag);
847  return found;
848 }
849 void
851 {
852  NS_LOG_FUNCTION (this);
854 }
855 
856 void
857 Packet::PrintPacketTags (std::ostream &os) const
858 {
860  while (i.HasNext ())
861  {
862  PacketTagIterator::Item item = i.Next ();
863  NS_ASSERT (item.GetTypeId ().HasConstructor ());
864  Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
865  NS_ASSERT (!constructor.IsNull ());
866  ObjectBase *instance = constructor ();
867  Tag *tag = dynamic_cast<Tag *> (instance);
868  NS_ASSERT (tag != 0);
869  item.GetTag (*tag);
870  tag->Print (os);
871  delete tag;
872  if (i.HasNext ())
873  {
874  os << " ";
875  }
876  }
877 }
878 
881 {
883 }
884 
885 std::ostream& operator<< (std::ostream& os, const Packet &packet)
886 {
887  packet.Print (os);
888  return os;
889 }
890 
891 } // namespace ns3
bool HasNext(void) const
Definition: packet.cc:65
Protocol header serialization and deserialization.
Definition: header.h:42
void RemoveAtEnd(uint32_t end)
Remove a chunk of metadata at the metadata end.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:266
PacketMetadata m_metadata
the packet's metadata
Definition: packet.h:719
uint32_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:968
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition: packet.cc:805
bool Remove(Tag &tag)
Remove (the first instance of) tag from the list.
Size of serialization buffer data.
void AddAtStart(uint32_t start)
Definition: buffer.cc:309
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void PrintPacketTags(std::ostream &os) const
Print the list of packet tags.
Definition: packet.cc:857
Control the scheduling of simulation events.
Definition: simulator.h:70
Callback template class.
Definition: callback.h:1164
void RemoveAtEnd(uint32_t end)
Definition: buffer.cc:486
struct TagData * next
Pointer to next in list.
Buffer::Iterator current
an iterator which can be fed to Deserialize.
uint32_t Deserialize(uint8_t const *buffer, uint32_t size)
Definition: packet.cc:707
void RemoveAtStart(uint32_t start)
Definition: buffer.cc:441
virtual uint32_t GetSerializedSize(void) const =0
const struct PacketTagList::TagData * Head(void) const
uint64_t GetUid(void) const
Get the packet Uid.
Item Next(void)
Retrieve the next metadata item.
automatically resized byte buffer
Definition: buffer.h:92
Ptr< NixVector > Copy(void) const
Definition: nix-vector.cc:71
def start()
Definition: core.py:1482
structure describing a packet metadata item
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:822
List of the packet tags stored in a packet.
bool isFragment
true: this is a fragmented header, trailer, or, payload.
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:366
TypeId tid
TypeId of Header or Trailer.
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Serialize a packet, tags, and metadata into a byte buffer.
Definition: packet.cc:589
keep track of the byte tags stored in a packet.
Definition: byte-tag-list.h:63
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1258
static uint32_t m_globalUid
Global counter of packets Uid.
Definition: packet.h:724
static void EnableChecking(void)
Enable the packet metadata checking.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
bool HasNext(void) const
Used to determine if the iterator is at the end of the byteTagList.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
TagBuffer Add(TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
uint32_t GetSerializedSize(void) const
Return the number of bytes required for serialization.
Definition: buffer.cc:559
void Adjust(int32_t adjustment)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:145
uint32_t GetSerializedSize(void) const
Get the metadata serialized size.
Buffer m_buffer
the packet buffer (it's actual contents)
Definition: packet.h:716
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Anchor the ns-3 type and attribute system.
Definition: object-base.h:68
Ptr< NixVector > GetNixVector(void) const
Get the packet nix-vector.
Definition: packet.cc:249
Item(TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
Constructor.
Definition: packet.cc:57
void Print(std::ostream &os) const
Print the packet contents.
Definition: packet.cc:410
Packet & operator=(const Packet &o)
Basic assignment.
Definition: packet.cc:157
network packets
Definition: packet.h:227
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
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)
Add an header.
PacketTagIterator GetPacketTagIterator(void) const
Returns an object which can be used to iterate over the list of packet tags.
Definition: packet.cc:880
iterator in a Buffer instance
Definition: buffer.h:98
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
Definition: type-id.cc:952
ByteTagList::Iterator m_current
actual position over the set of byte tags in a packet
Definition: packet.h:120
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
Check if this TypeId has a constructor.
Definition: type-id.cc:902
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:303
void AddAtEnd(int32_t appendOffset)
Make sure that all offsets are smaller than appendOffset which represents the location where new byte...
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:311
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:649
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:844
void RemoveAllPacketTags(void)
Remove all packet tags.
Definition: packet.cc:850
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
Definition: packet.h:61
void AddTrailer(Trailer const &trailer, uint32_t size)
Add a trailer.
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:338
void AddPaddingAtEnd(uint32_t end)
Add some padding at the end.
bool Replace(Tag &tag)
Replace the value of a tag.
std::string ToString(void) const
Return a string representation of the packet.
Definition: packet.cc:402
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:533
TypeId m_tid
the ns3::TypeId associated to this tag.
Definition: packet.h:100
PacketMetadata CreateFragment(uint32_t start, uint32_t end) const
Creates a fragment.
void SetNixVector(Ptr< NixVector > nixVector)
Set the packet nix-vector.
Definition: packet.cc:243
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
Definition: nix-vector.cc:225
virtual void Print(std::ostream &os) const =0
Print the object contents.
ByteTagList m_byteTagList
the ByteTag list
Definition: packet.h:717
uint8_t data[writeSize]
Iterator class for metadata items.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:836
uint32_t GetSerializedSize(void) const
Definition: nix-vector.cc:214
Buffer::Iterator End(void) const
Definition: buffer.h:1069
static void EnableChecking(void)
Enable packets metadata checking.
Definition: packet.cc:540
void AddPaddingAtEnd(uint32_t size)
Add a zero-filled padding to the packet.
Definition: packet.cc:323
int32_t start
offset to the start of the tag from the virtual byte buffer
Definition: byte-tag-list.h:85
virtual void Serialize(Buffer::Iterator start) const =0
ByteTagIterator GetByteTagIterator(void) const
Retiurns an iterator over the set of byte tags included in this packet.
Definition: packet.cc:799
bool HasNext(void) const
Checks if there is another metadata item.
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:715
virtual uint32_t Deserialize(Buffer::Iterator end)=0
Item Next(void)
Definition: packet.cc:70
uint32_t GetEnd(void) const
The index is an offset from the start of the packet.
Definition: packet.cc:44
Iterator over the set of packet tags in a packet.
Definition: packet.h:129
void PrintByteTags(std::ostream &os) const
Iterate over the byte tags present in this packet, and invoke the Print method of each tag stored in ...
Definition: packet.cc:372
const struct PacketTagList::TagData * m_current
actual position over the set of tags in a packet
Definition: packet.h:175
Buffer::Iterator Begin(void) const
Definition: buffer.h:1063
void AddAtEnd(PacketMetadata const &o)
Add a metadata at the metadata start.
struct ByteTagList::Iterator::Item Next(void)
Returns the next Item from the ByteTagList.
#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:42
void AddAtEnd(uint32_t end)
Definition: buffer.cc:354
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:276
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)
Enable the packet metadata.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual uint32_t GetSerializedSize(void) const =0
PacketMetadata::ItemIterator BeginItem(void) const
Returns an iterator which points to the first 'item' stored in this buffer.
Definition: packet.cc:527
PacketTagIterator(const struct PacketTagList::TagData *head)
Constructor.
Definition: packet.cc:84
enum ns3::PacketMetadata::Item::@79 type
metadata type
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Definition: packet.cc:283
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
Definition: packet.cc:331
friend class Packet
Definition: packet.h:169
Iterator over the set of byte tags in a packet.
Definition: packet.h:54
virtual void Deserialize(TagBuffer i)=0
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
Definition: packet.cc:294
std::string GetName(void) const
Get the name.
Definition: type-id.cc:880
uint32_t GetOffsetStart(void) const
Returns the offset from the start of the virtual byte buffer to the ByteTagList.
PacketTagList m_packetTagList
the packet's Tag list
Definition: packet.h:718
int32_t end
offset to the end of the tag from the virtual byte buffer
Definition: byte-tag-list.h:86
uint32_t Deserialize(const uint8_t *buffer, uint32_t size)
Deserialization from raw uint8_t*.
TypeId GetTypeId(void) const
Definition: packet.cc:34
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:229
Identifies a packet tag within a packet.
Definition: packet.h:135
uint32_t GetSize(void) const
Definition: buffer.h:1057
void RemoveHeader(Header const &header, uint32_t size)
Remove an header.
TypeId GetTypeId(void) const
Definition: packet.cc:107
TypeId tid
type of the tag
Definition: byte-tag-list.h:83
Buffer CreateFragment(uint32_t start, uint32_t length) const
Definition: buffer.cc:522
uint32_t currentSize
size of item.
Item(const struct PacketTagList::TagData *data)
Constructor.
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:579
ByteTagList::Iterator Begin(int32_t offsetStart, int32_t offsetEnd) const
TagBuffer buf
the data for the tag as generated by Tag::Serialize
Definition: byte-tag-list.h:87
An iterator for iterating through a byte tag list.
Definition: byte-tag-list.h:72
read and write tag data
Definition: tag-buffer.h:51
uint32_t GetStart(void) const
The index is an offset from the start of the packet.
Definition: packet.cc:39
void RemoveTrailer(Trailer const &trailer, uint32_t size)
Remove a trailer.
uint32_t GetSerializedSize(void) const
Returns number of bytes required for packet serialization.
Definition: packet.cc:546
virtual TypeId GetInstanceTypeId(void) const =0
Get the most derived TypeId for this Object.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:829
void AddAtStart(int32_t prependOffset)
Make sure that all offsets are bigger than prependOffset which represents the location where new byte...
ItemIterator BeginItem(Buffer buffer) const
Initialize the item iterator to the buffer begin.
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Definition: packet.cc:347
virtual uint32_t GetSerializedSize(void) const =0
Ptr< NixVector > m_nixVector
the packet's Nix vector
Definition: packet.h:722
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:953
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:354
virtual void Serialize(Buffer::Iterator start) const =0
ByteTagIterator(ByteTagList::Iterator i)
Copy Constructor.
Definition: packet.cc:78
void RemoveAtStart(uint32_t start)
Remove a chunk of metadata at the metadata start.
uint32_t currentTrimedFromStart
how many bytes were trimed from the start of a fragment.
void RemoveAll(void)
Remove all tags from this list (up to the first merge).
a unique identifier for an interface.
Definition: type-id.h:58
abstract base class for ns3::Header and ns3::Trailer
Definition: chunk.h:34
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:255
virtual void Print(std::ostream &os) const =0
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Serialization to raw uint8_t*.
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:789
An item specifies an individual tag within a byte buffer.
Definition: byte-tag-list.h:81