A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
queue-item.h
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#ifndef QUEUE_ITEM_H
20#define QUEUE_ITEM_H
21
22#include "ns3/nstime.h"
23#include "ns3/ptr.h"
24#include "ns3/simple-ref-count.h"
25#include <ns3/address.h>
26
27namespace ns3
28{
29
30class Packet;
31
32/**
33 * \ingroup network
34 * \defgroup netdevice Network Device
35 */
36
37/**
38 * \ingroup netdevice
39 * \brief Base class to represent items of packet Queues
40 *
41 * An item stored in an ns-3 packet Queue contains a packet and possibly other
42 * information. An item of the base class only contains a packet. Subclasses
43 * can be derived from this base class to allow items to contain additional
44 * information.
45 */
46class QueueItem : public SimpleRefCount<QueueItem>
47{
48 public:
49 /**
50 * \brief Create a queue item containing a packet.
51 * \param p the packet included in the created item.
52 */
54
55 virtual ~QueueItem();
56
57 // Delete default constructor, copy constructor and assignment operator to avoid misuse
58 QueueItem() = delete;
59 QueueItem(const QueueItem&) = delete;
60 QueueItem& operator=(const QueueItem&) = delete;
61
62 /**
63 * \return the packet included in this item.
64 */
65 Ptr<Packet> GetPacket() const;
66
67 /**
68 * \brief Use this method (instead of GetPacket ()->GetSize ()) to get the packet size
69 *
70 * Subclasses may keep header and payload separate to allow manipulating the header,
71 * so using this method ensures that the correct packet size is returned.
72 *
73 * \return the size of the packet included in this item.
74 */
75 virtual uint32_t GetSize() const;
76
77 /**
78 * \enum Uint8Values
79 * \brief 1-byte fields of the packet whose value can be retrieved, if present
80 */
82 {
84 };
85
86 /**
87 * \brief Retrieve the value of a given field from the packet, if present
88 * \param field the field whose value has to be retrieved
89 * \param value the output parameter to store the retrieved value
90 *
91 * \return true if the requested field is present in the packet, false otherwise.
92 */
93 virtual bool GetUint8Value(Uint8Values field, uint8_t& value) const;
94
95 /**
96 * \brief Print the item contents.
97 * \param os output stream in which the data should be printed.
98 */
99 virtual void Print(std::ostream& os) const;
100
101 /**
102 * TracedCallback signature for Ptr<QueueItem>
103 *
104 * \param [in] item The queue item.
105 */
107
108 private:
109 /**
110 * The packet contained in the queue item.
111 */
113};
114
115/**
116 * \brief Stream insertion operator.
117 *
118 * \param os the stream
119 * \param item the item
120 * \returns a reference to the stream
121 */
122std::ostream& operator<<(std::ostream& os, const QueueItem& item);
123
124/**
125 * \ingroup network
126 *
127 * QueueDiscItem is the abstract base class for items that are stored in a queue
128 * disc. It is derived from QueueItem (which only consists of a Ptr<Packet>)
129 * to additionally store the destination MAC address, the
130 * L3 protocol number and the transmission queue index,
131 */
133{
134 public:
135 /**
136 * \brief Create a queue disc item.
137 * \param p the packet included in the created item.
138 * \param addr the destination MAC address
139 * \param protocol the L3 protocol number
140 */
141 QueueDiscItem(Ptr<Packet> p, const Address& addr, uint16_t protocol);
142
143 ~QueueDiscItem() override;
144
145 // Delete default constructor, copy constructor and assignment operator to avoid misuse
146 QueueDiscItem() = delete;
147 QueueDiscItem(const QueueDiscItem&) = delete;
149
150 /**
151 * \brief Get the MAC address included in this item
152 * \return the MAC address included in this item.
153 */
154 Address GetAddress() const;
155
156 /**
157 * \brief Get the L3 protocol included in this item
158 * \return the L3 protocol included in this item.
159 */
160 uint16_t GetProtocol() const;
161
162 /**
163 * \brief Get the transmission queue index included in this item
164 * \return the transmission queue index included in this item.
165 */
166 uint8_t GetTxQueueIndex() const;
167
168 /**
169 * \brief Set the transmission queue index to store in this item
170 * \param txq the transmission queue index to store in this item.
171 */
172 void SetTxQueueIndex(uint8_t txq);
173
174 /**
175 * \brief Get the timestamp included in this item
176 * \return the timestamp included in this item.
177 */
178 Time GetTimeStamp() const;
179
180 /**
181 * \brief Set the timestamp included in this item
182 * \param t the timestamp to include in this item.
183 */
184 void SetTimeStamp(Time t);
185
186 /**
187 * \brief Add the header to the packet
188 *
189 * Subclasses may keep header and payload separate to allow manipulating the header,
190 * so this method allows to add the header to the packet before sending the packet
191 * to the device.
192 */
193 virtual void AddHeader() = 0;
194
195 /**
196 * \brief Print the item contents.
197 * \param os output stream in which the data should be printed.
198 */
199 void Print(std::ostream& os) const override;
200
201 /**
202 * \brief Marks the packet as a substitute for dropping it, such as for Explicit Congestion
203 * Notification
204 *
205 * \return true if the packet is marked by this method or is already marked, false otherwise
206 */
207 virtual bool Mark() = 0;
208
209 /**
210 * \brief Computes the hash of various fields of the packet header
211 *
212 * This method just returns 0. Subclasses should implement a reasonable hash
213 * for their protocol type, such as hashing on the TCP/IP 5-tuple.
214 *
215 * \param perturbation hash perturbation value
216 * \return the hash of various fields of the packet header
217 */
218 virtual uint32_t Hash(uint32_t perturbation = 0) const;
219
220 private:
221 Address m_address; //!< MAC destination address
222 uint16_t m_protocol; //!< L3 Protocol number
223 uint8_t m_txq; //!< Transmission queue index
224 Time m_tstamp; //!< timestamp when the packet was enqueued
225};
226
227} // namespace ns3
228
229#endif /* QUEUE_ITEM_H */
a polymophic address class
Definition: address.h:101
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition: queue-item.h:133
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
virtual void AddHeader()=0
Add the header to the packet.
QueueDiscItem & operator=(const QueueDiscItem &)=delete
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
virtual bool Mark()=0
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
Time GetTimeStamp() const
Get the timestamp included in this item.
Definition: queue-item.cc:120
QueueDiscItem(const QueueDiscItem &)=delete
Base class to represent items of packet Queues.
Definition: queue-item.h:47
QueueItem()=delete
QueueItem(const 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
QueueItem & operator=(const QueueItem &)=delete
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
A template-based reference counting class.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
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