A Discrete-Event Network Simulator
API
arp-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) 2018 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 "arp-queue-disc-item.h"
21 
22 namespace ns3 {
23 
24 NS_LOG_COMPONENT_DEFINE ("ArpQueueDiscItem");
25 
27  uint16_t protocol, const ArpHeader & 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 ArpQueueDiscItem::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 ArpHeader&
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 ArpQueueDiscItem::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);
87  return false;
88 }
89 
90 uint32_t
91 ArpQueueDiscItem::Hash (uint32_t perturbation) const
92 {
93  NS_LOG_FUNCTION (this << perturbation);
94 
100 
101  /* serialize the addresses and the perturbation in buf */
102  uint8_t tmp = 8 + macSrc.GetLength () + macDst.GetLength ();
103  uint8_t buf[tmp + 5];
104  ipv4Src.Serialize (buf);
105  ipv4Dst.Serialize (buf + 4);
106  macSrc.CopyTo (buf + 8);
107  macDst.CopyTo (buf + 8 + macSrc.GetLength ());
108  buf[tmp] = type;
109  buf[tmp+1] = (perturbation >> 24) & 0xff;
110  buf[tmp+2] = (perturbation >> 16) & 0xff;
111  buf[tmp+3] = (perturbation >> 8) & 0xff;
112  buf[tmp+4] = perturbation & 0xff;
113 
114  // Linux calculates jhash2 (jenkins hash), we calculate murmur3 because it is
115  // already available in ns-3
116 
117  uint32_t hash = Hash32 ((char*) buf, tmp+5);
118 
119  NS_LOG_DEBUG ("Hash value " << hash);
120 
121  return hash;
122 }
123 
124 } // namespace ns3
a polymophic address class
Definition: address.h:91
uint8_t GetLength(void) const
Get the length of the underlying address.
Definition: address.cc:75
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
The packet header for an ARP packet.
Definition: arp-header.h:35
Ipv4Address GetDestinationIpv4Address(void) const
Returns the destination IP address.
Definition: arp-header.cc:89
Address GetSourceHardwareAddress(void) const
Returns the source hardware address.
Definition: arp-header.cc:71
bool IsRequest(void) const
Check if the ARP is a request.
Definition: arp-header.cc:59
Ipv4Address GetSourceIpv4Address(void) const
Returns the source IP address.
Definition: arp-header.cc:83
Address GetDestinationHardwareAddress(void) const
Returns the destination hardware address.
Definition: arp-header.cc:77
virtual uint32_t GetSerializedSize(void) const
Definition: arp-header.cc:136
virtual uint32_t Hash(uint32_t perturbation) const
Computes the hash of the packet's 5-tuple.
ArpHeader m_header
The ARP header.
bool m_headerAdded
True if the header has already been added to the packet.
virtual bool Mark(void)
Inherited from the base class, but we cannot mark ARP packets.
virtual ~ArpQueueDiscItem()
Destructor.
virtual void AddHeader(void)
Add the header to the packet.
const ArpHeader & GetHeader(void) const
virtual void Print(std::ostream &os) const
Print the item contents.
virtual uint32_t GetSize(void) const
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition: queue-item.h:133
uint16_t GetProtocol(void) const
Get the L3 protocol included in this item.
Definition: queue-item.cc:98
Address GetAddress(void) const
Get the MAC address included in this item.
Definition: queue-item.cc:91
uint8_t GetTxQueueIndex(void) const
Get the transmission queue index included in this item.
Definition: queue-item.cc:105
Ptr< Packet > GetPacket(void) const
Definition: queue-item.cc:42
#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_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:88
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:282
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition: json.h:4680
Every class exported by the ns3 library is enclosed in the ns3 namespace.