A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
packet-burst.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007,2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18  */
19 
20 #include "packet-burst.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/packet.h"
24 
25 #include <list>
26 #include <stdint.h>
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("PacketBurst");
32 
33 NS_OBJECT_ENSURE_REGISTERED(PacketBurst);
34 
35 TypeId
37 {
38  static TypeId tid = TypeId("ns3::PacketBurst")
39  .SetParent<Object>()
40  .SetGroupName("Network")
41  .AddConstructor<PacketBurst>();
42  return tid;
43 }
44 
46 {
47  NS_LOG_FUNCTION(this);
48 }
49 
51 {
52  NS_LOG_FUNCTION(this);
53  for (auto iter = m_packets.begin(); iter != m_packets.end(); ++iter)
54  {
55  (*iter)->Unref();
56  }
57 }
58 
59 void
61 {
62  NS_LOG_FUNCTION(this);
63  m_packets.clear();
64 }
65 
68 {
69  NS_LOG_FUNCTION(this);
70  Ptr<PacketBurst> burst = Create<PacketBurst>();
71 
72  for (auto iter = m_packets.begin(); iter != m_packets.end(); ++iter)
73  {
74  Ptr<Packet> packet = (*iter)->Copy();
75  burst->AddPacket(packet);
76  }
77  return burst;
78 }
79 
80 void
82 {
83  NS_LOG_FUNCTION(this << packet);
84  if (packet)
85  {
86  m_packets.push_back(packet);
87  }
88 }
89 
90 std::list<Ptr<Packet>>
92 {
93  NS_LOG_FUNCTION(this);
94  return m_packets;
95 }
96 
97 uint32_t
99 {
100  NS_LOG_FUNCTION(this);
101  return m_packets.size();
102 }
103 
104 uint32_t
106 {
107  NS_LOG_FUNCTION(this);
108  uint32_t size = 0;
109  for (auto iter = m_packets.begin(); iter != m_packets.end(); ++iter)
110  {
111  Ptr<Packet> packet = *iter;
112  size += packet->GetSize();
113  }
114  return size;
115 }
116 
117 std::list<Ptr<Packet>>::const_iterator
119 {
120  NS_LOG_FUNCTION(this);
121  return m_packets.begin();
122 }
123 
124 std::list<Ptr<Packet>>::const_iterator
126 {
127  NS_LOG_FUNCTION(this);
128  return m_packets.end();
129 }
130 
131 } // namespace ns3
A base class which provides memory management and object aggregation.
Definition: object.h:89
this class implement a burst as a list of packets
Definition: packet-burst.h:37
~PacketBurst() override
Definition: packet-burst.cc:50
std::list< Ptr< Packet > >::const_iterator End() const
Returns an iterator to the end of the burst.
static TypeId GetTypeId()
Get the type ID.
Definition: packet-burst.cc:36
std::list< Ptr< Packet > > m_packets
the list of packets in the burst
Definition: packet-burst.h:88
std::list< Ptr< Packet > >::const_iterator Begin() const
Returns an iterator to the begin of the burst.
Ptr< PacketBurst > Copy() const
Definition: packet-burst.cc:67
uint32_t GetNPackets() const
Definition: packet-burst.cc:98
std::list< Ptr< Packet > > GetPackets() const
Definition: packet-burst.cc:91
uint32_t GetSize() const
void DoDispose() override
Destructor implementation.
Definition: packet-burst.cc:60
void AddPacket(Ptr< Packet > packet)
add a packet to the list of packet
Definition: packet-burst.cc:81
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition: packet.cc:131
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.