A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
arp-queue-disc-item.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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
18#include "arp-queue-disc-item.h"
19
20#include "ns3/log.h"
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("ArpQueueDiscItem");
26
28 const Address& addr,
29 uint16_t protocol,
30 const ArpHeader& header)
31 : QueueDiscItem(p, addr, protocol),
32 m_header(header),
33 m_headerAdded(false)
34{
35}
36
38{
39 NS_LOG_FUNCTION(this);
40}
41
44{
45 NS_LOG_FUNCTION(this);
47 NS_ASSERT(p);
48 uint32_t ret = p->GetSize();
49 if (!m_headerAdded)
50 {
52 }
53 return ret;
54}
55
56const ArpHeader&
58{
59 return m_header;
60}
61
62void
64{
65 NS_LOG_FUNCTION(this);
66
67 NS_ASSERT_MSG(!m_headerAdded, "The header has been already added to the packet");
69 NS_ASSERT(p);
70 p->AddHeader(m_header);
71 m_headerAdded = true;
72}
73
74void
75ArpQueueDiscItem::Print(std::ostream& os) const
76{
77 if (!m_headerAdded)
78 {
79 os << m_header << " ";
80 }
81 os << GetPacket() << " "
82 << "Dst addr " << GetAddress() << " "
83 << "proto " << (uint16_t)GetProtocol() << " "
84 << "txq " << (uint8_t)GetTxQueueIndex();
85}
86
87bool
89{
90 NS_LOG_FUNCTION(this);
91 return false;
92}
93
96{
97 NS_LOG_FUNCTION(this << perturbation);
98
104
105 /* serialize the addresses and the perturbation in buf */
106 uint8_t tmp = 8 + macSrc.GetLength() + macDst.GetLength();
107 uint8_t buf[tmp + 5];
108 ipv4Src.Serialize(buf);
109 ipv4Dst.Serialize(buf + 4);
110 macSrc.CopyTo(buf + 8);
111 macDst.CopyTo(buf + 8 + macSrc.GetLength());
112 buf[tmp] = type;
113 buf[tmp + 1] = (perturbation >> 24) & 0xff;
114 buf[tmp + 2] = (perturbation >> 16) & 0xff;
115 buf[tmp + 3] = (perturbation >> 8) & 0xff;
116 buf[tmp + 4] = perturbation & 0xff;
117
118 // Linux calculates jhash2 (jenkins hash), we calculate murmur3 because it is
119 // already available in ns-3
120
121 uint32_t hash = Hash32((char*)buf, tmp + 5);
122
123 NS_LOG_DEBUG("Hash value " << hash);
124
125 return hash;
126}
127
128} // namespace ns3
a polymophic address class
Definition: address.h:101
uint8_t GetLength() const
Get the length of the underlying address.
Definition: address.cc:78
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:86
The packet header for an ARP packet.
Definition: arp-header.h:36
bool IsRequest() const
Check if the ARP is a request.
Definition: arp-header.cc:64
Address GetDestinationHardwareAddress() const
Returns the destination hardware address.
Definition: arp-header.cc:85
Ipv4Address GetDestinationIpv4Address() const
Returns the destination IP address.
Definition: arp-header.cc:99
Ipv4Address GetSourceIpv4Address() const
Returns the source IP address.
Definition: arp-header.cc:92
uint32_t GetSerializedSize() const override
Definition: arp-header.cc:145
Address GetSourceHardwareAddress() const
Returns the source hardware address.
Definition: arp-header.cc:78
void AddHeader() override
Add the header to the packet.
ArpHeader m_header
The ARP header.
const ArpHeader & GetHeader() const
bool m_headerAdded
True if the header has already been added to the packet.
uint32_t Hash(uint32_t perturbation) const override
Computes the hash of the packet's 5-tuple.
void Print(std::ostream &os) const override
Print the item contents.
bool Mark() override
Inherited from the base class, but we cannot mark ARP packets.
uint32_t GetSize() const override
~ArpQueueDiscItem() override
Destructor.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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
#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 ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.