A Discrete-Event Network Simulator
API
packet-burst.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008 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: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  */
20 
21 #include <stdint.h>
22 #include <list>
23 #include "ns3/packet.h"
24 #include "packet-burst.h"
25 #include "ns3/log.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("PacketBurst");
30 
31 NS_OBJECT_ENSURE_REGISTERED (PacketBurst);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::PacketBurst")
37  .SetParent<Object> ()
38  .SetGroupName("Network")
39  .AddConstructor<PacketBurst> ()
40  ;
41  return tid;
42 }
43 
45 {
46  NS_LOG_FUNCTION (this);
47 }
48 
50 {
51  NS_LOG_FUNCTION (this);
52  for (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
53  != m_packets.end (); ++iter)
54  {
55  (*iter)->Unref ();
56 
57  }
58 }
59 
60 void
62 {
63  NS_LOG_FUNCTION (this);
64  m_packets.clear ();
65 }
66 
68 {
69  NS_LOG_FUNCTION (this);
70  Ptr<PacketBurst> burst = Create<PacketBurst> ();
71 
72  for (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
73  != m_packets.end (); ++iter)
74  {
75  Ptr<Packet> packet = (*iter)->Copy ();
76  burst->AddPacket (packet);
77  }
78  return burst;
79 }
80 
81 void
83 {
84  NS_LOG_FUNCTION (this << packet);
85  if (packet)
86  {
87  m_packets.push_back (packet);
88  }
89 }
90 
91 std::list<Ptr<Packet> >
93 {
94  NS_LOG_FUNCTION (this);
95  return m_packets;
96 }
97 
98 uint32_t
100 {
101  NS_LOG_FUNCTION (this);
102  return m_packets.size ();
103 }
104 
105 uint32_t
107 {
108  NS_LOG_FUNCTION (this);
109  uint32_t size = 0;
110  for (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
111  != m_packets.end (); ++iter)
112  {
113  Ptr<Packet> packet = *iter;
114  size += packet->GetSize ();
115  }
116  return size;
117 }
118 
119 std::list<Ptr<Packet> >::const_iterator
120 PacketBurst::Begin (void) const
121 {
122  NS_LOG_FUNCTION (this);
123  return m_packets.begin ();
124 }
125 
126 std::list<Ptr<Packet> >::const_iterator
127 PacketBurst::End (void) const
128 {
129  NS_LOG_FUNCTION (this);
130  return m_packets.end ();
131 }
132 
133 
134 } // namespace ns3
135 
136 
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
std::list< Ptr< Packet > > m_packets
the list of packets in the burst
Definition: packet-burst.h:88
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
std::list< Ptr< Packet > > GetPackets(void) const
Definition: packet-burst.cc:92
uint32_t GetNPackets(void) const
Definition: packet-burst.cc:99
std::list< Ptr< Packet > >::const_iterator End(void) const
Returns an iterator to the end of the burst.
#define list
void DoDispose(void)
Destructor implementation.
Definition: packet-burst.cc:61
void AddPacket(Ptr< Packet > packet)
add a packet to the list of packet
Definition: packet-burst.cc:82
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual ~PacketBurst(void)
Definition: packet-burst.cc:49
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
static TypeId GetTypeId(void)
Get the type ID.
Definition: packet-burst.cc:34
std::list< Ptr< Packet > >::const_iterator Begin(void) const
Returns an iterator to the begin of the burst.
Ptr< PacketBurst > Copy(void) const
Definition: packet-burst.cc:67
this class implement a burst as a list of packets
Definition: packet-burst.h:35
A base class which provides memory management and object aggregation.
Definition: object.h:87
uint32_t GetSize(void) const
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915