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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
7 */
8
10
11#include "ns3/ipv4-address.h"
12#include "ns3/log.h"
13
14#include <stdint.h>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("Ipv4PacketInfoTag");
20
22 : m_addr(Ipv4Address()),
23 m_ifindex(0),
24 m_ttl(0)
25{
26 NS_LOG_FUNCTION(this);
27}
28
29void
31{
32 NS_LOG_FUNCTION(this << addr);
33 m_addr = addr;
34}
35
38{
39 NS_LOG_FUNCTION(this);
40 return m_addr;
41}
42
43void
45{
46 NS_LOG_FUNCTION(this << ifindex);
47 m_ifindex = ifindex;
48}
49
52{
53 NS_LOG_FUNCTION(this);
54 return m_ifindex;
55}
56
57void
59{
60 NS_LOG_FUNCTION(this << static_cast<uint32_t>(ttl));
61 m_ttl = ttl;
62}
63
64uint8_t
66{
67 NS_LOG_FUNCTION(this);
68 return m_ttl;
69}
70
73{
74 static TypeId tid = TypeId("ns3::Ipv4PacketInfoTag")
75 .SetParent<Tag>()
76 .SetGroupName("Internet")
77 .AddConstructor<Ipv4PacketInfoTag>();
78 return tid;
79}
80
83{
84 NS_LOG_FUNCTION(this);
85 return GetTypeId();
86}
87
90{
91 NS_LOG_FUNCTION(this);
92 return 4 + sizeof(uint32_t) + sizeof(uint8_t);
93}
94
95void
97{
98 NS_LOG_FUNCTION(this << &i);
99 uint8_t buf[4];
100 m_addr.Serialize(buf);
101 i.Write(buf, 4);
103 i.WriteU8(m_ttl);
104}
105
106void
108{
109 NS_LOG_FUNCTION(this << &i);
110 uint8_t buf[4];
111 i.Read(buf, 4);
113 m_ifindex = i.ReadU32();
114 m_ttl = i.ReadU8();
115}
116
117void
118Ipv4PacketInfoTag::Print(std::ostream& os) const
119{
120 NS_LOG_FUNCTION(this << &os);
121 os << "Ipv4 PKTINFO [DestAddr: " << m_addr;
122 os << ", RecvIf:" << (uint32_t)m_ifindex;
123 os << ", TTL:" << (uint32_t)m_ttl;
124 os << "] ";
125}
126} // namespace ns3
Ipv4 addresses are stored in host order in this class.
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:41
TAG_BUFFER_INLINE uint32_t ReadU32()
Definition tag-buffer.h:206
void Read(uint8_t *buffer, uint32_t size)
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition tag-buffer.h:161
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition tag-buffer.h:185
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition tag-buffer.h:176
void Write(const uint8_t *buffer, uint32_t size)
tag a set of bytes in a packet
Definition tag.h:28
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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.