A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
21
22#include "ns3/ipv4-address.h"
23#include "ns3/log.h"
24
25#include <stdint.h>
26
27namespace ns3
28{
29
30NS_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
40void
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
54void
56{
57 NS_LOG_FUNCTION(this << ifindex);
58 m_ifindex = ifindex;
59}
60
63{
64 NS_LOG_FUNCTION(this);
65 return m_ifindex;
66}
67
68void
70{
71 NS_LOG_FUNCTION(this << static_cast<uint32_t>(ttl));
72 m_ttl = ttl;
73}
74
75uint8_t
77{
78 NS_LOG_FUNCTION(this);
79 return m_ttl;
80}
81
84{
85 static TypeId tid = TypeId("ns3::Ipv4PacketInfoTag")
86 .SetParent<Tag>()
87 .SetGroupName("Internet")
88 .AddConstructor<Ipv4PacketInfoTag>();
89 return tid;
90}
91
94{
95 NS_LOG_FUNCTION(this);
96 return GetTypeId();
97}
98
101{
102 NS_LOG_FUNCTION(this);
103 return 4 + sizeof(uint32_t) + sizeof(uint8_t);
104}
105
106void
108{
109 NS_LOG_FUNCTION(this << &i);
110 uint8_t buf[4];
111 m_addr.Serialize(buf);
112 i.Write(buf, 4);
114 i.WriteU8(m_ttl);
115}
116
117void
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
128void
129Ipv4PacketInfoTag::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:932
#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.