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 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
9#include "tcp-header.h"
10#include "udp-header.h"
11
12#include "ns3/log.h"
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("Ipv6QueueDiscItem");
18
20 const Address& addr,
21 uint16_t protocol,
22 const Ipv6Header& header)
23 : QueueDiscItem(p, addr, protocol),
24 m_header(header),
25 m_headerAdded(false)
26{
27}
28
33
36{
37 NS_LOG_FUNCTION(this);
39 NS_ASSERT(p);
40 uint32_t ret = p->GetSize();
41 if (!m_headerAdded)
42 {
44 }
45 return ret;
46}
47
48const Ipv6Header&
50{
51 return m_header;
52}
53
54void
56{
57 NS_LOG_FUNCTION(this);
58
59 NS_ASSERT_MSG(!m_headerAdded, "The header has been already added to the packet");
61 NS_ASSERT(p);
62 p->AddHeader(m_header);
63 m_headerAdded = true;
64}
65
66void
67Ipv6QueueDiscItem::Print(std::ostream& os) const
68{
69 if (!m_headerAdded)
70 {
71 os << m_header << " ";
72 }
73 os << GetPacket() << " "
74 << "Dst addr " << GetAddress() << " "
75 << "proto " << (uint16_t)GetProtocol() << " "
76 << "txq " << (uint16_t)GetTxQueueIndex();
77}
78
79bool
81{
82 NS_LOG_FUNCTION(this);
84 {
86 return true;
87 }
88 return false;
89}
90
91bool
93{
94 bool ret = false;
95
96 switch (field)
97 {
98 case IP_DSFIELD:
99 value = m_header.GetTrafficClass();
100 ret = true;
101 break;
102 }
103
104 return ret;
105}
106
109{
110 NS_LOG_FUNCTION(this << perturbation);
111
114 uint8_t prot = m_header.GetNextHeader();
115
116 TcpHeader tcpHdr;
117 UdpHeader udpHdr;
118 uint16_t srcPort = 0;
119 uint16_t destPort = 0;
120
121 if (prot == 6) // TCP
122 {
123 GetPacket()->PeekHeader(tcpHdr);
124 srcPort = tcpHdr.GetSourcePort();
125 destPort = tcpHdr.GetDestinationPort();
126 }
127 else if (prot == 17) // UDP
128 {
129 GetPacket()->PeekHeader(udpHdr);
130 srcPort = udpHdr.GetSourcePort();
131 destPort = udpHdr.GetDestinationPort();
132 }
133 if (prot != 6 && prot != 17)
134 {
135 NS_LOG_WARN("Unknown transport protocol, no port number included in hash computation");
136 }
137
138 /* serialize the 5-tuple and the perturbation in buf */
139 uint8_t buf[41];
140 src.Serialize(buf);
141 dest.Serialize(buf + 16);
142 buf[32] = prot;
143 buf[33] = (srcPort >> 8) & 0xff;
144 buf[34] = srcPort & 0xff;
145 buf[35] = (destPort >> 8) & 0xff;
146 buf[36] = destPort & 0xff;
147 buf[37] = (perturbation >> 24) & 0xff;
148 buf[38] = (perturbation >> 16) & 0xff;
149 buf[39] = (perturbation >> 8) & 0xff;
150 buf[40] = perturbation & 0xff;
151
152 // Linux calculates jhash2 (jenkins hash), we calculate murmur3 because it is
153 // already available in ns-3
154 uint32_t hash = Hash32((char*)buf, 41);
155
156 NS_LOG_DEBUG("Found Ipv6 packet; hash of the five tuple " << hash);
157
158 return hash;
159}
160
161} // namespace ns3
a polymophic address class
Definition address.h:90
Describes an IPv6 address.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Packet header for IPv6.
Definition ipv6-header.h:24
void SetEcn(EcnType ecn)
Set ECN field bits.
uint8_t GetNextHeader() const
Get the next header.
Ipv6Address GetDestination() const
Get the "Destination address" field.
uint8_t GetTrafficClass() const
Get the "Traffic class" field.
EcnType GetEcn() const
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Ipv6Address GetSource() const
Get the "Source address" field.
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:294
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
Address GetAddress() const
Get the MAC address included in this item.
Definition queue-item.cc:81
uint8_t GetTxQueueIndex() const
Get the transmission queue index included in this item.
Definition queue-item.cc:95
uint16_t GetProtocol() const
Get the L3 protocol included in this item.
Definition queue-item.cc:88
Ptr< Packet > GetPacket() const
Definition queue-item.cc:32
Uint8Values
1-byte fields of the packet whose value can be retrieved, if present
Definition queue-item.h:71
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
uint16_t GetDestinationPort() const
Get the destination port.
uint16_t GetSourcePort() const
Get the source port.
Definition tcp-header.cc:95
Packet header for UDP packets.
Definition udp-header.h:30
uint16_t GetDestinationPort() const
Definition udp-header.cc:43
uint16_t GetSourcePort() const
Definition udp-header.cc:37
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
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:263
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:250
Every class exported by the ns3 library is enclosed in the ns3 namespace.