1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Hajime Tazaki
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  * Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
19  */
20 
21 #ifndef IPV6_PACKET_INFO_TAG_H
22 #define IPV6_PACKET_INFO_TAG_H
23 
24 #include "ns3/tag.h"
25 #include "ns3/ipv6-address.h"
26 
27 namespace ns3 {
28 
29 
30 class Node;
31 class Packet;
32 
33 /**
34  * \ingroup ipv6
35  *
36  * \brief This class implements a tag that carries socket ancillary
37  * data to the socket interface. This is used like
38  * socket option of IP_PKTINFO/IPV6_PKTINFO in \RFC{3542}
39  *
40  * See also SocketIpv6TclassTag and SocketIpv6HopLimitTag
41  *
42  * This tag in the send direction is presently not enabled but we
43  * would accept a patch along those lines in the future. To include
44  * the nexthop in the send direction would increase the size of the
45  * tag beyond 20 bytes, so in that case, we recommend that an
46  * additional tag be used to carry the IPv6 next hop address.
47  */
48 class Ipv6PacketInfoTag : public Tag
49 {
50 public:
51   Ipv6PacketInfoTag ();
52 
53   /**
54    * \brief Get the type ID.
55    * \return the object TypeId
56    */
57   static TypeId GetTypeId (void);
58 
59   /**
60    * \brief Set the tag's address
61    *
62    * \param addr the address
63    */
64   void SetAddress (Ipv6Address addr);
65 
66   /**
67    * \brief Get the tag's address
68    *
69    * \returns the address
70    */
71   Ipv6Address GetAddress (void) const;
72 
73   /**
74    * \brief Set the tag's receiving interface
75    *
76    * \param ifindex the interface index
77    */
78   void SetRecvIf (uint32_t ifindex);
79 
80   /**
81    * \brief Get the tag's receiving interface
82    *
83    * \returns the interface index
84    */
85   uint32_t GetRecvIf (void) const;
86 
87   /**
88    * \brief Set the tag's Hop Limit
89    *
90    * \param ttl the hop limit
91    */
92   void SetHoplimit (uint8_t ttl);
93 
94   /**
95    * \brief Get the tag's Hop Limit
96    *
97    * \returns the Hop Limit
98    */
99   uint8_t GetHoplimit (void) const;
100 
101   /**
102    * \brief Set the tag's Traffic Class
103    *
104    * \param tclass the Traffic Class
105    */
106   void SetTrafficClass (uint8_t tclass);
107 
108   /**
109    * \brief Get the tag's Traffic Class
110    *
111    * \returns the Traffic Class
112    */
113   uint8_t GetTrafficClass (void) const;
114 
115   // inherited functions, no doc necessary
116   virtual TypeId GetInstanceTypeId (void) const;
117   virtual uint32_t GetSerializedSize (void) const;
118   virtual void Serialize (TagBuffer i) const;
119   virtual void Deserialize (TagBuffer i);
120   virtual void Print (std::ostream &os) const;
121 
122 private:
123   /*
124    * RFC 3542 includes
125    * for outgoing packet,
126    *  1.  the source IPv6 address,
127    *  2.  the outgoing interface index,
128    *  3.  the outgoing hop limit,
129    *  4.  the next hop address, and
130    *  5.  the outgoing traffic class value.
131    *
132    * for incoming packet,
133    *  1.  the destination IPv6 address,
134    *  2.  the arriving interface index,
135    *  3.  the arriving hop limit, and
136    *  4.  the arriving traffic class value.
137   */
138   Ipv6Address m_addr;  //!< the packet address (src or dst)
139   uint8_t m_ifindex;   //!< the Interface index
140   uint8_t m_hoplimit;  //!< the Hop Limit
141   uint8_t m_tclass;    //!< the Traffic Class
142 };
143 } // namespace ns3
144 
145 #endif /* IPV6_PACKET_INFO_TAG_H */
146 
147