A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
queue-item.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stefano.avallone@unina.it>
18 */
19
20#include "queue-item.h"
21
22#include "ns3/log.h"
23#include "ns3/packet.h"
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("QueueItem");
29
31{
32 NS_LOG_FUNCTION(this << p);
33 m_packet = p;
34}
35
37{
38 NS_LOG_FUNCTION(this);
39 m_packet = nullptr;
40}
41
44{
45 NS_LOG_FUNCTION(this);
46 return m_packet;
47}
48
51{
52 NS_LOG_FUNCTION(this);
54 return m_packet->GetSize();
55}
56
57bool
59{
60 NS_LOG_FUNCTION(this);
61 return false;
62}
63
64void
65QueueItem::Print(std::ostream& os) const
66{
67 os << GetPacket();
68}
69
70std::ostream&
71operator<<(std::ostream& os, const QueueItem& item)
72{
73 item.Print(os);
74 return os;
75}
76
77QueueDiscItem::QueueDiscItem(Ptr<Packet> p, const Address& addr, uint16_t protocol)
78 : QueueItem(p),
79 m_address(addr),
80 m_protocol(protocol),
81 m_txq(0)
82{
83 NS_LOG_FUNCTION(this << p << addr << protocol);
84}
85
87{
88 NS_LOG_FUNCTION(this);
89}
90
93{
94 NS_LOG_FUNCTION(this);
95 return m_address;
96}
97
98uint16_t
100{
101 NS_LOG_FUNCTION(this);
102 return m_protocol;
103}
104
105uint8_t
107{
108 NS_LOG_FUNCTION(this);
109 return m_txq;
110}
111
112void
114{
115 NS_LOG_FUNCTION(this << (uint16_t)txq);
116 m_txq = txq;
117}
118
119Time
121{
122 NS_LOG_FUNCTION(this);
123 return m_tstamp;
124}
125
126void
128{
129 NS_LOG_FUNCTION(this << t);
130 m_tstamp = t;
131}
132
133void
134QueueDiscItem::Print(std::ostream& os) const
135{
136 os << GetPacket() << " "
137 << "Dst addr " << m_address << " "
138 << "proto " << m_protocol << " "
139 << "txq " << +m_txq;
140}
141
143QueueDiscItem::Hash(uint32_t perturbation) const
144{
145 NS_LOG_WARN("The Hash method should be redefined by subclasses");
146 return 0;
147}
148
149} // namespace ns3
a polymophic address class
Definition: address.h:101
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
void Print(std::ostream &os) const override
Print the item contents.
Definition: queue-item.cc:134
QueueDiscItem()=delete
uint8_t m_txq
Transmission queue index.
Definition: queue-item.h:223
Time m_tstamp
timestamp when the packet was enqueued
Definition: queue-item.h:224
Address m_address
MAC destination address.
Definition: queue-item.h:221
void SetTimeStamp(Time t)
Set the timestamp included in this item.
Definition: queue-item.cc:127
uint16_t m_protocol
L3 Protocol number.
Definition: queue-item.h:222
virtual uint32_t Hash(uint32_t perturbation=0) const
Computes the hash of various fields of the packet header.
Definition: queue-item.cc:143
Address GetAddress() const
Get the MAC address included in this item.
Definition: queue-item.cc:92
~QueueDiscItem() override
Definition: queue-item.cc:86
uint8_t GetTxQueueIndex() const
Get the transmission queue index included in this item.
Definition: queue-item.cc:106
void SetTxQueueIndex(uint8_t txq)
Set the transmission queue index to store in this item.
Definition: queue-item.cc:113
uint16_t GetProtocol() const
Get the L3 protocol included in this item.
Definition: queue-item.cc:99
Time GetTimeStamp() const
Get the timestamp included in this item.
Definition: queue-item.cc:120
Base class to represent items of packet Queues.
Definition: queue-item.h:47
QueueItem()=delete
virtual bool GetUint8Value(Uint8Values field, uint8_t &value) const
Retrieve the value of a given field from the packet, if present.
Definition: queue-item.cc:58
Ptr< Packet > GetPacket() const
Definition: queue-item.cc:43
virtual void Print(std::ostream &os) const
Print the item contents.
Definition: queue-item.cc:65
virtual uint32_t GetSize() const
Use this method (instead of GetPacket ()->GetSize ()) to get the packet size.
Definition: queue-item.cc:50
Uint8Values
1-byte fields of the packet whose value can be retrieved, if present
Definition: queue-item.h:82
virtual ~QueueItem()
Definition: queue-item.cc:36
Ptr< Packet > m_packet
The packet contained in the queue item.
Definition: queue-item.h:112
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159