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 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
9#include "ns3/log.h"
10
11#include <vector>
12
13namespace ns3
14{
15
16NS_LOG_COMPONENT_DEFINE("ArpQueueDiscItem");
17
19 const Address& addr,
20 uint16_t protocol,
21 const ArpHeader& header)
22 : QueueDiscItem(p, addr, protocol),
23 m_header(header),
24 m_headerAdded(false)
25{
26}
27
32
35{
36 NS_LOG_FUNCTION(this);
38 NS_ASSERT(p);
39 uint32_t ret = p->GetSize();
40 if (!m_headerAdded)
41 {
43 }
44 return ret;
45}
46
47const ArpHeader&
49{
50 return m_header;
51}
52
53void
55{
56 NS_LOG_FUNCTION(this);
57
58 NS_ASSERT_MSG(!m_headerAdded, "The header has been already added to the packet");
60 NS_ASSERT(p);
61 p->AddHeader(m_header);
62 m_headerAdded = true;
63}
64
65void
66ArpQueueDiscItem::Print(std::ostream& os) const
67{
68 if (!m_headerAdded)
69 {
70 os << m_header << " ";
71 }
72 os << GetPacket() << " "
73 << "Dst addr " << GetAddress() << " "
74 << "proto " << (uint16_t)GetProtocol() << " "
75 << "txq " << (uint8_t)GetTxQueueIndex();
76}
77
78bool
80{
81 NS_LOG_FUNCTION(this);
82 return false;
83}
84
87{
88 NS_LOG_FUNCTION(this << perturbation);
89
95
96 /* serialize the addresses and the perturbation in buf */
97 uint8_t tmp = 8 + macSrc.GetLength() + macDst.GetLength();
98 std::vector<uint8_t> buf(tmp + 5);
99 ipv4Src.Serialize(buf.data());
100 ipv4Dst.Serialize(buf.data() + 4);
101 macSrc.CopyTo(buf.data() + 8);
102 macDst.CopyTo(buf.data() + 8 + macSrc.GetLength());
103 buf[tmp] = type;
104 buf[tmp + 1] = (perturbation >> 24) & 0xff;
105 buf[tmp + 2] = (perturbation >> 16) & 0xff;
106 buf[tmp + 3] = (perturbation >> 8) & 0xff;
107 buf[tmp + 4] = perturbation & 0xff;
108
109 // Linux calculates jhash2 (jenkins hash), we calculate murmur3 because it is
110 // already available in ns-3
111
112 uint32_t hash = Hash32((char*)buf.data(), tmp + 5);
113
114 NS_LOG_DEBUG("Hash value " << hash);
115
116 return hash;
117}
118
119} // namespace ns3
a polymophic address class
Definition address.h:90
uint8_t GetLength() const
Get the length of the underlying address.
Definition address.cc:67
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition address.cc:75
The packet header for an ARP packet.
Definition arp-header.h:25
bool IsRequest() const
Check if the ARP is a request.
Definition arp-header.cc:53
Address GetDestinationHardwareAddress() const
Returns the destination hardware address.
Definition arp-header.cc:74
Ipv4Address GetDestinationIpv4Address() const
Returns the destination IP address.
Definition arp-header.cc:88
Ipv4Address GetSourceIpv4Address() const
Returns the source IP address.
Definition arp-header.cc:81
uint32_t GetSerializedSize() const override
Address GetSourceHardwareAddress() const
Returns the source hardware address.
Definition arp-header.cc:67
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.
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
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
#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 ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.