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 IPV4_PACKET_INFO_TAG_H 22 #define IPV4_PACKET_INFO_TAG_H 23 24 #include "ns3/tag.h" 25 #include "ns3/ipv4-address.h" 26 27 namespace ns3 { 28 29 30 class Node; 31 class Packet; 32 33 /** 34 * \ingroup ipv4 35 * 36 * \brief This class implements Linux struct pktinfo 37 * in order to deliver ancillary information to the socket interface. 38 * This is used with socket option such as IP_PKTINFO, IP_RECVTTL, 39 * IP_RECVTOS. See linux manpage ip(7). 40 * 41 * See also SocketIpTosTag and SocketIpTtlTag 42 * 43 * The Tag does not carry the Local address (as it is not currently 44 * used to force a source address). 45 * 46 * This tag in the send direction is presently not enabled but we 47 * would accept a patch along those lines in the future. 48 */ 49 class Ipv4PacketInfoTag : public Tag 50 { 51 public: 52 Ipv4PacketInfoTag (); 53 54 /** 55 * \brief Set the tag's address 56 * 57 * \param addr the address 58 */ 59 void SetAddress (Ipv4Address addr); 60 61 /** 62 * \brief Get the tag's address 63 * 64 * \returns the address 65 */ 66 Ipv4Address GetAddress (void) const; 67 68 /** 69 * \brief Set the tag's receiving interface 70 * 71 * \param ifindex the interface index 72 */ 73 void SetRecvIf (uint32_t ifindex); 74 /** 75 * \brief Get the tag's receiving interface 76 * 77 * \returns the interface index 78 */ 79 uint32_t GetRecvIf (void) const; 80 81 /** 82 * \brief Set the tag's Time to Live 83 * Implemented, but not used in the stack yet 84 * \param ttl the TTL 85 */ 86 void SetTtl (uint8_t ttl); 87 /** 88 * \brief Get the tag's Time to Live 89 * Implemented, but not used in the stack yet 90 * \returns the TTL 91 */ 92 uint8_t GetTtl (void) const; 93 94 /** 95 * \brief Get the type ID. 96 * \return the object TypeId 97 */ 98 static TypeId GetTypeId (void); 99 virtual TypeId GetInstanceTypeId (void) const; 100 virtual uint32_t GetSerializedSize (void) const; 101 virtual void Serialize (TagBuffer i) const; 102 virtual void Deserialize (TagBuffer i); 103 virtual void Print (std::ostream &os) const; 104 105 private: 106 // Linux IP_PKTINFO ip(7) implementation 107 // 108 // struct in_pktinfo { 109 // unsigned int ipi_ifindex; /* Interface index */ 110 // struct in_addr ipi_spec_dst; /* Local address */ 111 // struct in_addr ipi_addr; /* Header Destination 112 // address */ 113 // }; 114 115 Ipv4Address m_addr; //!< Header destination address 116 uint32_t m_ifindex; //!< interface index 117 118 // Used for IP_RECVTTL, though not implemented yet. 119 uint8_t m_ttl; //!< Time to Live 120 }; 121 } // namespace ns3 122 123 #endif /* IPV4_PACKET_INFO_TAG_H */ 124