1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 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 IPV6_QUEUE_DISC_ITEM_H
20 #define IPV6_QUEUE_DISC_ITEM_H
21 
22 #include "ns3/packet.h"
23 #include "ns3/queue-item.h"
24 #include "ipv6-header.h"
25 
26 namespace ns3 {
27 
28 /**
29  * \ingroup ipv6
30  * \ingroup traffic-control
31  *
32  * Ipv6QueueDiscItem is a subclass of QueueDiscItem which stores IPv6 packets.
33  * Header and payload are kept separate to allow the queue disc to manipulate
34  * the header, which is added to the packet when the packet is dequeued.
35  */
36 class Ipv6QueueDiscItem : public QueueDiscItem {
37 public:
38   /**
39    * \brief Create an IPv6 queue disc item containing an IPv6 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 IPv6 header
44    */
45   Ipv6QueueDiscItem (Ptr<Packet> p, const Address & addr, uint16_t protocol, const Ipv6Header & header);
46 
47   virtual ~Ipv6QueueDiscItem ();
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 Ipv6Header & 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    * The values for the fields of the Ipv6 header are taken from m_header and
72    * thus might differ from those present in the packet in case the header is
73    * modified after being added to the packet. However, this function is likely
74    * to be called before the header is added to the packet (i.e., before the
75    * packet is dequeued from the queue disc)
76    */
77   virtual bool GetUint8Value (Uint8Values field, uint8_t &value) const;
78 
79   /**
80    * \brief Marks the packet by setting ECN_CE bits if the packet has
81    * ECN_ECT0 or ECN_ECT1 set.  If ECN_CE is already set, returns true.
82    * \return true if the method results in a marked packet, false otherwise
83    */
84   virtual bool Mark (void);
85 
86   /**
87    * \brief Computes the hash of the packet's 5-tuple
88    *
89    * Computes the hash of the source and destination IP addresses, protocol
90    * number and, if the transport protocol is either UDP or TCP, the source
91    * and destination port
92    *
93    * \param perturbation hash perturbation value
94    * \return the hash of the packet's 5-tuple
95    */
96   virtual uint32_t Hash (uint32_t perturbation) const;
97 
98 private:
99   /**
100    * \brief Default constructor
101    *
102    * Defined and unimplemented to avoid misuse
103    */
104   Ipv6QueueDiscItem ();
105   /**
106    * \brief Copy constructor
107    *
108    * Defined and unimplemented to avoid misuse
109    */
110   Ipv6QueueDiscItem (const Ipv6QueueDiscItem &);
111   /**
112    * \brief Assignment operator
113    *
114    * Defined and unimplemented to avoid misuse
115    * \returns
116    */
117   Ipv6QueueDiscItem &operator = (const Ipv6QueueDiscItem &);
118 
119   Ipv6Header m_header;  //!< The IPv6 header.
120   bool m_headerAdded;   //!< True if the header has already been added to the packet.
121 };
122 
123 } // namespace ns3
124 
125 #endif /* IPV6_QUEUE_DISC_ITEM_H */
126