A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-queue-disc-item.cc
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
19
20#include "ns3/log.h"
21#include "ns3/tcp-header.h"
22#include "ns3/udp-header.h"
23
24namespace ns3
25{
26
27NS_LOG_COMPONENT_DEFINE("Ipv6QueueDiscItem");
28
30 const Address& addr,
31 uint16_t protocol,
32 const Ipv6Header& header)
33 : QueueDiscItem(p, addr, protocol),
34 m_header(header),
35 m_headerAdded(false)
36{
37}
38
40{
41 NS_LOG_FUNCTION(this);
42}
43
46{
47 NS_LOG_FUNCTION(this);
49 NS_ASSERT(p);
50 uint32_t ret = p->GetSize();
51 if (!m_headerAdded)
52 {
54 }
55 return ret;
56}
57
58const Ipv6Header&
60{
61 return m_header;
62}
63
64void
66{
67 NS_LOG_FUNCTION(this);
68
69 NS_ASSERT_MSG(!m_headerAdded, "The header has been already added to the packet");
71 NS_ASSERT(p);
72 p->AddHeader(m_header);
73 m_headerAdded = true;
74}
75
76void
77Ipv6QueueDiscItem::Print(std::ostream& os) const
78{
79 if (!m_headerAdded)
80 {
81 os << m_header << " ";
82 }
83 os << GetPacket() << " "
84 << "Dst addr " << GetAddress() << " "
85 << "proto " << (uint16_t)GetProtocol() << " "
86 << "txq " << (uint16_t)GetTxQueueIndex();
87}
88
89bool
91{
92 NS_LOG_FUNCTION(this);
94 {
96 return true;
97 }
98 return false;
99}
100
101bool
103{
104 bool ret = false;
105
106 switch (field)
107 {
108 case IP_DSFIELD:
109 value = m_header.GetTrafficClass();
110 ret = true;
111 break;
112 }
113
114 return ret;
115}
116
119{
120 NS_LOG_FUNCTION(this << perturbation);
121
124 uint8_t prot = m_header.GetNextHeader();
125
126 TcpHeader tcpHdr;
127 UdpHeader udpHdr;
128 uint16_t srcPort = 0;
129 uint16_t destPort = 0;
130
131 if (prot == 6) // TCP
132 {
133 GetPacket()->PeekHeader(tcpHdr);
134 srcPort = tcpHdr.GetSourcePort();
135 destPort = tcpHdr.GetDestinationPort();
136 }
137 else if (prot == 17) // UDP
138 {
139 GetPacket()->PeekHeader(udpHdr);
140 srcPort = udpHdr.GetSourcePort();
141 destPort = udpHdr.GetDestinationPort();
142 }
143 if (prot != 6 && prot != 17)
144 {
145 NS_LOG_WARN("Unknown transport protocol, no port number included in hash computation");
146 }
147
148 /* serialize the 5-tuple and the perturbation in buf */
149 uint8_t buf[41];
150 src.Serialize(buf);
151 dest.Serialize(buf + 16);
152 buf[32] = prot;
153 buf[33] = (srcPort >> 8) & 0xff;
154 buf[34] = srcPort & 0xff;
155 buf[35] = (destPort >> 8) & 0xff;
156 buf[36] = destPort & 0xff;
157 buf[37] = (perturbation >> 24) & 0xff;
158 buf[38] = (perturbation >> 16) & 0xff;
159 buf[39] = (perturbation >> 8) & 0xff;
160 buf[40] = perturbation & 0xff;
161
162 // Linux calculates jhash2 (jenkins hash), we calculate murmur3 because it is
163 // already available in ns-3
164 uint32_t hash = Hash32((char*)buf, 41);
165
166 NS_LOG_DEBUG("Found Ipv6 packet; hash of the five tuple " << hash);
167
168 return hash;
169}
170
171} // namespace ns3
a polymophic address class
Definition: address.h:100
Describes an IPv6 address.
Definition: ipv6-address.h:50
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Packet header for IPv6.
Definition: ipv6-header.h:36
void SetEcn(EcnType ecn)
Set ECN field bits.
Definition: ipv6-header.cc:215
uint8_t GetNextHeader() const
Get the next header.
Definition: ipv6-header.cc:88
Ipv6Address GetDestination() const
Get the "Destination address" field.
Definition: ipv6-header.cc:124
uint8_t GetTrafficClass() const
Get the "Traffic class" field.
Definition: ipv6-header.cc:52
EcnType GetEcn() const
Definition: ipv6-header.cc:284
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition: ipv6-header.cc:159
Ipv6Address GetSource() const
Get the "Source address" field.
Definition: ipv6-header.cc:112
const Ipv6Header & GetHeader() const
void AddHeader() override
Add the header to the packet.
bool Mark() override
Marks the packet by setting ECN_CE bits if the packet has ECN_ECT0 or ECN_ECT1 set.
bool GetUint8Value(Uint8Values field, uint8_t &value) const override
Retrieve the value of a given field from the packet, if present.
uint32_t GetSize() const override
Ipv6Header m_header
The IPv6 header.
void Print(std::ostream &os) const override
Print the item contents.
uint32_t Hash(uint32_t perturbation) const override
Computes the hash of the packet's 5-tuple.
bool m_headerAdded
True if the header has already been added to the packet.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:305
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition: queue-item.h:133
Address GetAddress() const
Get the MAC address included in this item.
Definition: queue-item.cc:92
uint8_t GetTxQueueIndex() const
Get the transmission queue index included in this item.
Definition: queue-item.cc:106
uint16_t GetProtocol() const
Get the L3 protocol included in this item.
Definition: queue-item.cc:99
Ptr< Packet > GetPacket() const
Definition: queue-item.cc:43
Uint8Values
1-byte fields of the packet whose value can be retrieved, if present
Definition: queue-item.h:82
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
uint16_t GetDestinationPort() const
Get the destination port.
Definition: tcp-header.cc:131
uint16_t GetSourcePort() const
Get the source port.
Definition: tcp-header.cc:125
Packet header for UDP packets.
Definition: udp-header.h:41
uint16_t GetDestinationPort() const
Definition: udp-header.cc:75
uint16_t GetSourcePort() const
Definition: udp-header.cc:69
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
uint32_t Hash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer, using the default hash function.
Definition: hash.h:274
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:261
Every class exported by the ns3 library is enclosed in the ns3 namespace.