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 #ifndef ARP_QUEUE_DISC_ITEM_H
20 #define ARP_QUEUE_DISC_ITEM_H
21 
22 #include "ns3/packet.h"
23 #include "ns3/queue-item.h"
24 #include "arp-header.h"
25 
26 namespace ns3 {
27 
28 /**
29  * \ingroup arp
30  * \ingroup traffic-control
31  *
32  * ArpQueueDiscItem is a subclass of QueueDiscItem which stores ARP packets.
33  * Header and payload are kept separate to allow the queue disc to hash the
34  * fields of the header, which is added to the packet when the packet is dequeued.
35  */
36 class ArpQueueDiscItem : public QueueDiscItem {
37 public:
38   /**
39    * \brief Create an ARP queue disc item containing an ARP packet.
40    * \param p the packet included in the created item.
41    * \param addr the destination MAC address
42    * \param protocol the protocol number
43    * \param header the ARP header
44    */
45   ArpQueueDiscItem (Ptr<Packet> p, const Address & addr, uint16_t protocol, const ArpHeader & header);
46 
47   virtual ~ArpQueueDiscItem ();
48 
49   /**
50    * \return the correct packet size (header plus payload).
51    */
52   virtual uint32_t GetSize (void) const;
53 
54   /**
55    * \return the header stored in this item..
56    */
57   const ArpHeader & GetHeader (void) const;
58 
59   /**
60    * \brief Add the header to the packet
61    */
62   virtual void AddHeader (void);
63 
64   /**
65    * \brief Print the item contents.
66    * \param os output stream in which the data should be printed.
67    */
68   virtual void Print (std::ostream &os) const;
69 
70   /**
71    * \brief Inherited from the base class, but we cannot mark ARP packets
72    * \return false
73    */
74   virtual bool Mark (void);
75 
76   /**
77    * \brief Computes the hash of the packet's 5-tuple
78    *
79    * \param perturbation hash perturbation value
80    * \return the hash of the packet's 5-tuple
81    */
82   virtual uint32_t Hash (uint32_t perturbation) const;
83 
84 private:
85   /**
86    * \brief Default constructor
87    *
88    * Defined and unimplemented to avoid misuse
89    */
90   ArpQueueDiscItem ();
91   /**
92    * \brief Copy constructor
93    *
94    * Defined and unimplemented to avoid misuse
95    */
96   ArpQueueDiscItem (const ArpQueueDiscItem &);
97   /**
98    * \brief Assignment operator
99    *
100    * Defined and unimplemented to avoid misuse
101    * \returns
102    */
103   ArpQueueDiscItem &operator = (const ArpQueueDiscItem &);
104 
105   ArpHeader m_header;  //!< The ARP header.
106   bool m_headerAdded;   //!< True if the header has already been added to the packet.
107 };
108 
109 } // namespace ns3
110 
111 #endif /* ARP_QUEUE_DISC_ITEM_H */
112