A Discrete-Event Network Simulator
API
ipv4-queue-disc-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 
19 #include "ns3/log.h"
20 #include "ipv4-queue-disc-item.h"
21 
22 namespace ns3 {
23 
24 NS_LOG_COMPONENT_DEFINE ("Ipv4QueueDiscItem");
25 
27  uint16_t protocol, const Ipv4Header & header)
28  : QueueDiscItem (p, addr, protocol),
29  m_header (header),
30  m_headerAdded (false)
31 {
32 }
33 
35 {
36  NS_LOG_FUNCTION (this);
37 }
38 
40 {
41  Ptr<Packet> p = GetPacket ();
42  NS_ASSERT (p != 0);
43  uint32_t ret = p->GetSize ();
44  if (!m_headerAdded)
45  {
46  ret += m_header.GetSerializedSize ();
47  }
48  return ret;
49 }
50 
51 const Ipv4Header&
53 {
54  return m_header;
55 }
56 
58 {
59  NS_LOG_FUNCTION (this);
60 
61  NS_ASSERT_MSG (!m_headerAdded, "The header has been already added to the packet");
62  Ptr<Packet> p = GetPacket ();
63  NS_ASSERT (p != 0);
64  p->AddHeader (m_header);
65  m_headerAdded = true;
66 }
67 
68 void
69 Ipv4QueueDiscItem::Print (std::ostream& os) const
70 {
71  if (!m_headerAdded)
72  {
73  os << m_header << " ";
74  }
75  os << GetPacket () << " "
76  << "Dst addr " << GetAddress () << " "
77  << "proto " << (uint16_t) GetProtocol () << " "
78  << "txq " << (uint8_t) GetTxQueueIndex ()
79  ;
80 }
81 
82 bool
84 {
85  bool ret = false;
86 
87  switch (field)
88  {
89  case IP_DSFIELD:
90  value = m_header.GetTos ();
91  ret = true;
92  break;
93  }
94 
95  return ret;
96 }
97 
98 } // namespace ns3
uint8_t GetTxQueueIndex(void) const
Get the transmission queue index included in this item.
Definition: queue-disc.cc:60
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ipv4Header m_header
The IPv4 header.
#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:201
virtual void Print(std::ostream &os) const
Print the item contents.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:792
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition: queue-disc.h:43
Address GetAddress(void) const
Get the MAC address included in this item.
Definition: queue-disc.cc:48
Ipv4QueueDiscItem()
Default constructor.
a polymophic address class
Definition: address.h:90
Packet header for IPv4.
Definition: ipv4-header.h:33
const Ipv4Header & GetHeader(void) const
virtual bool GetUint8Value(Uint8Values field, uint8_t &value) const
Retrieve the value of a given field from the packet, if present.
virtual uint32_t GetPacketSize(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Uint8Values
1-byte fields of the packet whose value can be retrieved, if present
Definition: net-device.h:86
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
virtual void AddHeader(void)
Add the header to the packet.
bool m_headerAdded
True if the header has already been added to the packet.
uint8_t GetTos(void) const
Definition: ipv4-header.cc:194
uint16_t GetProtocol(void) const
Get the L3 protocol included in this item.
Definition: queue-disc.cc:54
virtual uint32_t GetSerializedSize(void) const
Definition: ipv4-header.cc:375
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
Ptr< Packet > GetPacket(void) const
Definition: net-device.cc:45