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 
39 uint32_t Ipv4QueueDiscItem::GetSize (void) const
40 {
41  NS_LOG_FUNCTION (this);
42  Ptr<Packet> p = GetPacket ();
43  NS_ASSERT (p != 0);
44  uint32_t ret = p->GetSize ();
45  if (!m_headerAdded)
46  {
47  ret += m_header.GetSerializedSize ();
48  }
49  return ret;
50 }
51 
52 const Ipv4Header&
54 {
55  return m_header;
56 }
57 
59 {
60  NS_LOG_FUNCTION (this);
61 
62  NS_ASSERT_MSG (!m_headerAdded, "The header has been already added to the packet");
63  Ptr<Packet> p = GetPacket ();
64  NS_ASSERT (p != 0);
65  p->AddHeader (m_header);
66  m_headerAdded = true;
67 }
68 
69 void
70 Ipv4QueueDiscItem::Print (std::ostream& os) const
71 {
72  if (!m_headerAdded)
73  {
74  os << m_header << " ";
75  }
76  os << GetPacket () << " "
77  << "Dst addr " << GetAddress () << " "
78  << "proto " << (uint16_t) GetProtocol () << " "
79  << "txq " << (uint8_t) GetTxQueueIndex ()
80  ;
81 }
82 
83 bool
85 {
86  NS_LOG_FUNCTION (this);
88  {
90  return true;
91  }
92  return false;
93 }
94 
95 
96 bool
98 {
99  bool ret = false;
100 
101  switch (field)
102  {
103  case IP_DSFIELD:
104  value = m_header.GetTos ();
105  ret = true;
106  break;
107  }
108 
109  return ret;
110 }
111 
112 } // namespace ns3
uint8_t GetTxQueueIndex(void) const
Get the transmission queue index included in this item.
Definition: queue-item.cc:105
#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:796
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition: queue-item.h:148
Address GetAddress(void) const
Get the MAC address included in this item.
Definition: queue-item.cc:91
virtual uint32_t GetSize(void) const
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual bool Mark(void)
Marks the packet by setting ECN_CE bits if the packet has ECN_ECT0 or ECN_ECT1 bits set...
Uint8Values
1-byte fields of the packet whose value can be retrieved, if present
Definition: queue-item.h:76
#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
void SetEcn(EcnType ecn)
Set ECN Field.
Definition: ipv4-header.cc:97
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-item.cc:98
virtual uint32_t GetSerializedSize(void) const
Definition: ipv4-header.cc:375
EcnType GetEcn(void) const
Definition: ipv4-header.cc:167
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Ptr< Packet > GetPacket(void) const
Definition: queue-item.cc:42