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 }
46 
48 {
49  for (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
50  != m_packets.end (); ++iter)
51  {
52  (*iter)->Unref ();
53 
54  }
55 }
56 
57 void
59 {
60  m_packets.clear ();
61 }
62 
64 {
65  Ptr<PacketBurst> burst = Create<PacketBurst> ();
66 
67  for (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
68  != m_packets.end (); ++iter)
69  {
70  Ptr<Packet> packet = (*iter)->Copy ();
71  burst->AddPacket (packet);
72  }
73  return burst;
74 }
75 
76 void
78 {
79  if (packet)
80  {
81  m_packets.push_back (packet);
82  }
83 }
84 
85 std::list<Ptr<Packet> >
87 {
88  return m_packets;
89 }
90 
91 uint32_t
93 {
94  return m_packets.size ();
95 }
96 
97 uint32_t
99 {
100  uint32_t size = 0;
101  for (std::list<Ptr<Packet> >::const_iterator iter = m_packets.begin (); iter
102  != m_packets.end (); ++iter)
103  {
104  Ptr<Packet> packet = *iter;
105  size += packet->GetSize ();
106  }
107  return size;
108 }
109 
110 std::list<Ptr<Packet> >::const_iterator
111 PacketBurst::Begin (void) const
112 {
113  return m_packets.begin ();
114 }
115 
116 std::list<Ptr<Packet> >::const_iterator
117 PacketBurst::End (void) const
118 {
119  return m_packets.end ();
120 }
121 
122 
123 } // namespace ns3
124 
125