A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("PacketBurst");
28 
29 namespace ns3 {
30 
31 NS_OBJECT_ENSURE_REGISTERED (PacketBurst);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::PacketBurst")
37  .SetParent<Object> ()
38  .AddConstructor<PacketBurst> ()
39  ;
40  return tid;
41 }
42 
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 
49 {
50  NS_LOG_FUNCTION (this);
51  for (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
52  != m_packets.end (); ++iter)
53  {
54  (*iter)->Unref ();
55 
56  }
57 }
58 
59 void
61 {
62  NS_LOG_FUNCTION (this);
63  m_packets.clear ();
64 }
65 
67 {
68  NS_LOG_FUNCTION (this);
69  Ptr<PacketBurst> burst = Create<PacketBurst> ();
70 
71  for (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
72  != 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 (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
110  != m_packets.end (); ++iter)
111  {
112  Ptr<Packet> packet = *iter;
113  size += packet->GetSize ();
114  }
115  return size;
116 }
117 
118 std::list<Ptr<Packet> >::const_iterator
119 PacketBurst::Begin (void) const
120 {
121  NS_LOG_FUNCTION (this);
122  return m_packets.begin ();
123 }
124 
125 std::list<Ptr<Packet> >::const_iterator
126 PacketBurst::End (void) const
127 {
128  NS_LOG_FUNCTION (this);
129  return m_packets.end ();
130 }
131 
132 
133 } // namespace ns3
134 
135 
#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:79
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
std::list< Ptr< Packet > >::const_iterator Begin(void) const
Returns an iterator to the begin of the burst.
#define list
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: packet-burst.cc:60
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
std::list< Ptr< Packet > >::const_iterator End(void) const
Returns an iterator to the end of the burst.
void AddPacket(Ptr< Packet > packet)
add a packet to the list of packet
Definition: packet-burst.cc:81
virtual ~PacketBurst(void)
Definition: packet-burst.cc:48
static TypeId GetTypeId(void)
Get the type ID.
Definition: packet-burst.cc:34
a base class which provides memory management and object aggregation
Definition: object.h:64
Ptr< PacketBurst > Copy(void) const
Definition: packet-burst.cc:66
uint32_t GetSize(void) const
uint32_t GetNPackets(void) const
Definition: packet-burst.cc:98
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
std::list< Ptr< Packet > > GetPackets(void) const
Definition: packet-burst.cc:91