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