A Discrete-Event Network Simulator
API
packet.h
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 #ifndef PACKET_H
21 #define PACKET_H
22 
23 #include <stdint.h>
24 #include "buffer.h"
25 #include "header.h"
26 #include "trailer.h"
27 #include "packet-metadata.h"
28 #include "tag.h"
29 #include "byte-tag-list.h"
30 #include "packet-tag-list.h"
31 #include "nix-vector.h"
32 #include "ns3/mac48-address.h"
33 #include "ns3/callback.h"
34 #include "ns3/assert.h"
35 #include "ns3/ptr.h"
36 #include "ns3/deprecated.h"
37 
38 namespace ns3 {
39 
40 // Forward declaration
41 class Address;
42 
55 {
56 public:
61  class Item
62  {
63 public:
67  TypeId GetTypeId (void) const;
73  uint32_t GetStart (void) const;
79  uint32_t GetEnd (void) const;
88  void GetTag (Tag &tag) const;
89 private:
91  friend class ByteTagIterator;
99  Item (TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer);
100 
102  uint32_t m_start;
103  uint32_t m_end;
105  };
109  bool HasNext (void) const;
113  Item Next (void);
114 private:
116  friend class Packet;
123 };
124 
132 {
133 public:
137  class Item
138  {
139 public:
143  TypeId GetTypeId (void) const;
152  void GetTag (Tag &tag) const;
153 private:
155  friend class PacketTagIterator;
160  Item (const struct PacketTagList::TagData *data);
162  };
166  bool HasNext (void) const;
170  Item Next (void);
171 private:
173  friend class Packet;
178  PacketTagIterator (const struct PacketTagList::TagData *head);
180 };
181 
231 class Packet : public SimpleRefCount<Packet>
232 {
233 public:
234 
239  Packet ();
244  Packet (const Packet &o);
250  Packet &operator = (const Packet &o);
262  Packet (uint32_t size);
275  Packet (uint8_t const*buffer, uint32_t size, bool magic);
286  Packet (uint8_t const*buffer, uint32_t size);
297  Ptr<Packet> CreateFragment (uint32_t start, uint32_t length) const;
304  inline uint32_t GetSize (void) const;
315  void AddHeader (const Header & header);
325  uint32_t RemoveHeader (Header &header);
337  uint32_t RemoveHeader (Header &header, uint32_t size);
346  uint32_t PeekHeader (Header &header) const;
358  uint32_t PeekHeader (Header &header, uint32_t size) const;
369  void AddTrailer (const Trailer &trailer);
378  uint32_t RemoveTrailer (Trailer &trailer);
387  uint32_t PeekTrailer (Trailer &trailer);
388 
397  void AddAtEnd (Ptr<const Packet> packet);
403  void AddPaddingAtEnd (uint32_t size);
412  void RemoveAtEnd (uint32_t size);
421  void RemoveAtStart (uint32_t size);
422 
433  uint32_t CopyData (uint8_t *buffer, uint32_t size) const;
434 
443  void CopyData (std::ostream *os, uint32_t size) const;
444 
454  Ptr<Packet> Copy (void) const;
455 
475  uint64_t GetUid (void) const;
476 
487  void Print (std::ostream &os) const;
488 
496  std::string ToString (void) const;
497 
510  PacketMetadata::ItemIterator BeginItem (void) const;
511 
521  static void EnablePrinting (void);
532  static void EnableChecking (void);
533 
545  uint32_t GetSerializedSize (void) const;
546 
555  uint32_t Serialize (uint8_t* buffer, uint32_t maxSize) const;
556 
573  void AddByteTag (const Tag &tag) const;
579  ByteTagIterator GetByteTagIterator (void) const;
589  bool FindFirstMatchingByteTag (Tag &tag) const;
590 
594  void RemoveAllByteTags (void);
595 
602  void PrintByteTags (std::ostream &os) const;
603 
613  void AddPacketTag (const Tag &tag) const;
622  bool RemovePacketTag (Tag &tag);
633  bool ReplacePacketTag (Tag & tag);
641  bool PeekPacketTag (Tag &tag) const;
645  void RemoveAllPacketTags (void);
646 
655  void PrintPacketTags (std::ostream &os) const;
656 
664  PacketTagIterator GetPacketTagIterator (void) const;
665 
678  void SetNixVector (Ptr<NixVector> nixVector);
686  Ptr<NixVector> GetNixVector (void) const;
687 
693  typedef void (* TracedCallback) (Ptr<const Packet> packet);
694 
701  typedef void (* AddressTracedCallback)
703 
711  typedef void (* TwoAddressTracedCallback)
712  (const Ptr<const Packet> packet, const Address &srcAddress, const Address &destAddress);
713 
720  typedef void (* Mac48AddressTracedCallback)
722 
729  typedef void (* SizeTracedCallback)
730  (uint32_t oldSize, uint32_t newSize);
731 
738  typedef void (* SinrTracedCallback)
739  (Ptr<const Packet> packet, double sinr);
740 
741 
742 private:
750  Packet (const Buffer &buffer, const ByteTagList &byteTagList,
751  const PacketTagList &packetTagList, const PacketMetadata &metadata);
752 
759  uint32_t Deserialize (uint8_t const*buffer, uint32_t size);
760 
765 
766  /* Please see comments above about nix-vector */
768 
769  static uint32_t m_globalUid;
770 };
771 
779 std::ostream& operator<< (std::ostream& os, const Packet &packet);
780 
822 } // namespace ns3
823 
824 /****************************************************
825  * Implementation of inline methods for performance
826  ****************************************************/
827 
828 namespace ns3 {
829 
830 uint32_t
831 Packet::GetSize (void) const
832 {
833  return m_buffer.GetSize ();
834 }
835 
836 } // namespace ns3
837 
838 #endif /* PACKET_H */
bool HasNext(void) const
Definition: packet.cc:65
Protocol header serialization and deserialization.
Definition: header.h:42
PacketMetadata m_metadata
the packet&#39;s metadata
Definition: packet.h:764
const struct PacketTagList::TagData * m_data
the tag data
Definition: packet.h:161
automatically resized byte buffer
Definition: buffer.h:92
def start()
Definition: core.py:1806
Forward calls to a chain of Callback.
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added...
Definition: wifi-utils.cc:163
List of the packet tags stored in a packet.
keep track of the byte tags stored in a packet.
Definition: byte-tag-list.h:63
static uint32_t m_globalUid
Global counter of packets Uid.
Definition: packet.h:769
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
Buffer m_buffer
the packet buffer (it&#39;s actual contents)
Definition: packet.h:761
Item(TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
Constructor.
Definition: packet.cc:57
network packets
Definition: packet.h:231
a polymophic address class
Definition: address.h:90
ByteTagList::Iterator m_current
actual position over the set of byte tags in a packet
Definition: packet.h:122
friend class ByteTagIterator
Friend class.
Definition: packet.h:91
Tree node for sharing serialized tags.
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
Definition: packet.h:61
TagBuffer m_buffer
the buffer associated with this tag.
Definition: packet.h:104
TypeId m_tid
the ns3::TypeId associated to this tag.
Definition: packet.h:101
ByteTagList m_byteTagList
the ByteTag list
Definition: packet.h:762
Defines a linked list of Packet tags, including copy-on-write semantics.
uint8_t data[writeSize]
Iterator class for metadata items.
mac
Definition: third.py:92
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:131
const struct PacketTagList::TagData * m_current
actual position over the set of tags in a packet
Definition: packet.h:179
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
uint32_t m_end
the index of the last byte tagged by this tag.
Definition: packet.h:103
Protocol trailer serialization and deserialization.
Definition: trailer.h:40
tag a set of bytes in a packet
Definition: tag.h:36
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:37
Iterator over the set of byte tags in a packet.
Definition: packet.h:54
friend class Packet
Friend class.
Definition: packet.h:116
an EUI-48 address
Definition: mac48-address.h:43
PacketTagList m_packetTagList
the packet&#39;s Tag list
Definition: packet.h:763
TypeId GetTypeId(void) const
Definition: packet.cc:34
Identifies a packet tag within a packet.
Definition: packet.h:137
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
Definition: packet.cc:49
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
static const std::string & ToString(EpcUeNas::State s)
Definition: epc-ue-nas.cc:50
void Print(ComponentCarrier cc)
Ptr< NixVector > m_nixVector
the packet&#39;s Nix vector
Definition: packet.h:767
uint32_t m_start
the index of the first byte tagged by this tag.
Definition: packet.h:102
A template-based reference counting class.
a unique identifier for an interface.
Definition: type-id.h:58
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:688
Handle packet metadata about packet headers and trailers.