A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ipv4-packet-info-tag.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Hajime Tazaki
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
18  */
19 
20 #include "ipv4-packet-info-tag.h"
21 
22 #include "ns3/ipv4-address.h"
23 #include "ns3/log.h"
24 
25 #include <stdint.h>
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("Ipv4PacketInfoTag");
31 
33  : m_addr(Ipv4Address()),
34  m_ifindex(0),
35  m_ttl(0)
36 {
37  NS_LOG_FUNCTION(this);
38 }
39 
40 void
42 {
43  NS_LOG_FUNCTION(this << addr);
44  m_addr = addr;
45 }
46 
49 {
50  NS_LOG_FUNCTION(this);
51  return m_addr;
52 }
53 
54 void
56 {
57  NS_LOG_FUNCTION(this << ifindex);
58  m_ifindex = ifindex;
59 }
60 
61 uint32_t
63 {
64  NS_LOG_FUNCTION(this);
65  return m_ifindex;
66 }
67 
68 void
70 {
71  NS_LOG_FUNCTION(this << static_cast<uint32_t>(ttl));
72  m_ttl = ttl;
73 }
74 
75 uint8_t
77 {
78  NS_LOG_FUNCTION(this);
79  return m_ttl;
80 }
81 
82 TypeId
84 {
85  static TypeId tid = TypeId("ns3::Ipv4PacketInfoTag")
86  .SetParent<Tag>()
87  .SetGroupName("Internet")
88  .AddConstructor<Ipv4PacketInfoTag>();
89  return tid;
90 }
91 
92 TypeId
94 {
95  NS_LOG_FUNCTION(this);
96  return GetTypeId();
97 }
98 
99 uint32_t
101 {
102  NS_LOG_FUNCTION(this);
103  return 4 + sizeof(uint32_t) + sizeof(uint8_t);
104 }
105 
106 void
108 {
109  NS_LOG_FUNCTION(this << &i);
110  uint8_t buf[4];
111  m_addr.Serialize(buf);
112  i.Write(buf, 4);
113  i.WriteU32(m_ifindex);
114  i.WriteU8(m_ttl);
115 }
116 
117 void
119 {
120  NS_LOG_FUNCTION(this << &i);
121  uint8_t buf[4];
122  i.Read(buf, 4);
124  m_ifindex = i.ReadU32();
125  m_ttl = i.ReadU8();
126 }
127 
128 void
129 Ipv4PacketInfoTag::Print(std::ostream& os) const
130 {
131  NS_LOG_FUNCTION(this << &os);
132  os << "Ipv4 PKTINFO [DestAddr: " << m_addr;
133  os << ", RecvIf:" << (uint32_t)m_ifindex;
134  os << ", TTL:" << (uint32_t)m_ttl;
135  os << "] ";
136 }
137 } // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
static Ipv4Address Deserialize(const uint8_t buf[4])
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
void Print(std::ostream &os) const override
uint8_t m_ttl
Time to Live.
static TypeId GetTypeId()
Get the type ID.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
void SetAddress(Ipv4Address addr)
Set the tag's address.
uint8_t GetTtl() const
Get the tag's Time to Live Implemented, but not used in the stack yet.
uint32_t GetRecvIf() const
Get the tag's receiving interface.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Ipv4Address m_addr
Header destination address.
void Serialize(TagBuffer i) const override
void SetTtl(uint8_t ttl)
Set the tag's Time to Live Implemented, but not used in the stack yet.
uint32_t GetSerializedSize() const override
uint32_t m_ifindex
interface index
Ipv4Address GetAddress() const
Get the tag's address.
void Deserialize(TagBuffer i) override
read and write tag data
Definition: tag-buffer.h:52
TAG_BUFFER_INLINE uint32_t ReadU32()
Definition: tag-buffer.h:217
void Read(uint8_t *buffer, uint32_t size)
Definition: tag-buffer.cc:183
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:172
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition: tag-buffer.h:196
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition: tag-buffer.h:187
void Write(const uint8_t *buffer, uint32_t size)
Definition: tag-buffer.cc:129
tag a set of bytes in a packet
Definition: tag.h:39
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.