A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
packet-burst.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
7 */
8
9#include "packet-burst.h"
10
11#include "ns3/log.h"
12#include "ns3/packet.h"
13
14#include <list>
15#include <stdint.h>
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("PacketBurst");
21
23
24TypeId
26{
27 static TypeId tid = TypeId("ns3::PacketBurst")
29 .SetGroupName("Network")
30 .AddConstructor<PacketBurst>();
31 return tid;
32}
33
38
40{
41 NS_LOG_FUNCTION(this);
42 for (auto iter = m_packets.begin(); iter != m_packets.end(); ++iter)
43 {
44 (*iter)->Unref();
45 }
46}
47
48void
50{
51 NS_LOG_FUNCTION(this);
52 m_packets.clear();
53}
54
57{
58 NS_LOG_FUNCTION(this);
60
61 for (auto iter = m_packets.begin(); iter != m_packets.end(); ++iter)
62 {
63 Ptr<Packet> packet = (*iter)->Copy();
64 burst->AddPacket(packet);
65 }
66 return burst;
67}
68
69void
71{
72 NS_LOG_FUNCTION(this << packet);
73 if (packet)
74 {
75 m_packets.push_back(packet);
76 }
77}
78
79std::list<Ptr<Packet>>
81{
82 NS_LOG_FUNCTION(this);
83 return m_packets;
84}
85
88{
89 NS_LOG_FUNCTION(this);
90 return m_packets.size();
91}
92
95{
96 NS_LOG_FUNCTION(this);
97 uint32_t size = 0;
98 for (auto iter = m_packets.begin(); iter != m_packets.end(); ++iter)
99 {
100 Ptr<Packet> packet = *iter;
101 size += packet->GetSize();
102 }
103 return size;
104}
105
106std::list<Ptr<Packet>>::const_iterator
108{
109 NS_LOG_FUNCTION(this);
110 return m_packets.begin();
111}
112
113std::list<Ptr<Packet>>::const_iterator
115{
116 NS_LOG_FUNCTION(this);
117 return m_packets.end();
118}
119
120} // namespace ns3
A base class which provides memory management and object aggregation.
Definition object.h:78
this class implement a burst as a list of packets
~PacketBurst() override
std::list< Ptr< Packet > >::const_iterator End() const
Returns an iterator to the end of the burst.
static TypeId GetTypeId()
Get the type ID.
std::list< Ptr< Packet > > m_packets
the list of packets in the burst
std::list< Ptr< Packet > >::const_iterator Begin() const
Returns an iterator to the begin of the burst.
Ptr< PacketBurst > Copy() const
uint32_t GetNPackets() const
std::list< Ptr< Packet > > GetPackets() const
uint32_t GetSize() const
void DoDispose() override
Destructor implementation.
void AddPacket(Ptr< Packet > packet)
add a packet to the list of packet
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.