A Discrete-Event Network Simulator
API
queue-item.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stefano.avallone@unina.it>
19  */
20 
21 #include "queue-item.h"
22 #include "ns3/packet.h"
23 #include "ns3/log.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("QueueItem");
28 
30 {
31  NS_LOG_FUNCTION (this << p);
32  m_packet = p;
33 }
34 
36 {
37  NS_LOG_FUNCTION (this);
38  m_packet = 0;
39 }
40 
43 {
44  NS_LOG_FUNCTION (this);
45  return m_packet;
46 }
47 
48 uint32_t
49 QueueItem::GetSize (void) const
50 {
51  NS_LOG_FUNCTION (this);
52  NS_ASSERT (m_packet != 0);
53  return m_packet->GetSize ();
54 }
55 
56 bool
57 QueueItem::GetUint8Value (QueueItem::Uint8Values field, uint8_t& value) const
58 {
59  NS_LOG_FUNCTION (this);
60  return false;
61 }
62 
63 void
64 QueueItem::Print (std::ostream& os) const
65 {
66  os << GetPacket();
67 }
68 
69 std::ostream & operator << (std::ostream &os, const QueueItem &item)
70 {
71  item.Print (os);
72  return os;
73 }
74 
75 
76 QueueDiscItem::QueueDiscItem (Ptr<Packet> p, const Address& addr, uint16_t protocol)
77  : QueueItem (p),
78  m_address (addr),
79  m_protocol (protocol),
80  m_txq (0)
81 {
82  NS_LOG_FUNCTION (this << p << addr << protocol);
83 }
84 
86 {
87  NS_LOG_FUNCTION (this);
88 }
89 
90 Address
92 {
93  NS_LOG_FUNCTION (this);
94  return m_address;
95 }
96 
97 uint16_t
99 {
100  NS_LOG_FUNCTION (this);
101  return m_protocol;
102 }
103 
104 uint8_t
106 {
107  NS_LOG_FUNCTION (this);
108  return m_txq;
109 }
110 
111 void
113 {
114  NS_LOG_FUNCTION (this << (uint16_t) txq);
115  m_txq = txq;
116 }
117 
118 Time
120 {
121  NS_LOG_FUNCTION (this);
122  return m_tstamp;
123 }
124 
125 void
127 {
128  NS_LOG_FUNCTION (this << t);
129  m_tstamp = t;
130 }
131 
132 void
133 QueueDiscItem::Print (std::ostream& os) const
134 {
135  os << GetPacket () << " "
136  << "Dst addr " << m_address << " "
137  << "proto " << m_protocol << " "
138  << "txq " << +m_txq
139  ;
140 }
141 
142 uint32_t
143 QueueDiscItem::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:91
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
QueueDiscItem()=delete
uint8_t m_txq
Transmission queue index.
Definition: queue-item.h:222
Time m_tstamp
timestamp when the packet was enqueued
Definition: queue-item.h:223
Address m_address
MAC destination address.
Definition: queue-item.h:220
void SetTimeStamp(Time t)
Set the timestamp included in this item.
Definition: queue-item.cc:126
uint16_t m_protocol
L3 Protocol number.
Definition: queue-item.h:221
virtual void Print(std::ostream &os) const
Print the item contents.
Definition: queue-item.cc:133
virtual uint32_t Hash(uint32_t perturbation=0) const
Computes the hash of various fields of the packet header.
Definition: queue-item.cc:143
Time GetTimeStamp(void) const
Get the timestamp included in this item.
Definition: queue-item.cc:119
uint16_t GetProtocol(void) const
Get the L3 protocol included in this item.
Definition: queue-item.cc:98
virtual ~QueueDiscItem()
Definition: queue-item.cc:85
Address GetAddress(void) const
Get the MAC address included in this item.
Definition: queue-item.cc:91
void SetTxQueueIndex(uint8_t txq)
Set the transmission queue index to store in this item.
Definition: queue-item.cc:112
uint8_t GetTxQueueIndex(void) const
Get the transmission queue index included in this item.
Definition: queue-item.cc:105
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:57
virtual void Print(std::ostream &os) const
Print the item contents.
Definition: queue-item.cc:64
virtual uint32_t GetSize(void) const
Use this method (instead of GetPacket ()->GetSize ()) to get the packet size.
Definition: queue-item.cc:49
Ptr< Packet > GetPacket(void) const
Definition: queue-item.cc:42
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:35
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:103
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:265
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:139