A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
9
#include "
ipv4-packet-info-tag.h
"
10
11
#include "ns3/ipv4-address.h"
12
#include "ns3/log.h"
13
14
#include <stdint.h>
15
16
namespace
ns3
17
{
18
19
NS_LOG_COMPONENT_DEFINE
(
"Ipv4PacketInfoTag"
);
20
21
Ipv4PacketInfoTag::Ipv4PacketInfoTag
()
22
: m_addr(
Ipv4Address
()),
23
m_ifindex(0),
24
m_ttl(0)
25
{
26
NS_LOG_FUNCTION
(
this
);
27
}
28
29
void
30
Ipv4PacketInfoTag::SetAddress
(
Ipv4Address
addr)
31
{
32
NS_LOG_FUNCTION
(
this
<< addr);
33
m_addr
= addr;
34
}
35
36
Ipv4Address
37
Ipv4PacketInfoTag::GetAddress
()
const
38
{
39
NS_LOG_FUNCTION
(
this
);
40
return
m_addr
;
41
}
42
43
void
44
Ipv4PacketInfoTag::SetRecvIf
(
uint32_t
ifindex)
45
{
46
NS_LOG_FUNCTION
(
this
<< ifindex);
47
m_ifindex
= ifindex;
48
}
49
50
uint32_t
51
Ipv4PacketInfoTag::GetRecvIf
()
const
52
{
53
NS_LOG_FUNCTION
(
this
);
54
return
m_ifindex
;
55
}
56
57
void
58
Ipv4PacketInfoTag::SetTtl
(uint8_t ttl)
59
{
60
NS_LOG_FUNCTION
(
this
<<
static_cast<
uint32_t
>
(ttl));
61
m_ttl
= ttl;
62
}
63
64
uint8_t
65
Ipv4PacketInfoTag::GetTtl
()
const
66
{
67
NS_LOG_FUNCTION
(
this
);
68
return
m_ttl
;
69
}
70
71
TypeId
72
Ipv4PacketInfoTag::GetTypeId
()
73
{
74
static
TypeId
tid =
TypeId
(
"ns3::Ipv4PacketInfoTag"
)
75
.
SetParent
<
Tag
>()
76
.SetGroupName(
"Internet"
)
77
.AddConstructor<
Ipv4PacketInfoTag
>();
78
return
tid;
79
}
80
81
TypeId
82
Ipv4PacketInfoTag::GetInstanceTypeId
()
const
83
{
84
NS_LOG_FUNCTION
(
this
);
85
return
GetTypeId
();
86
}
87
88
uint32_t
89
Ipv4PacketInfoTag::GetSerializedSize
()
const
90
{
91
NS_LOG_FUNCTION
(
this
);
92
return
4 +
sizeof
(
uint32_t
) +
sizeof
(uint8_t);
93
}
94
95
void
96
Ipv4PacketInfoTag::Serialize
(
TagBuffer
i)
const
97
{
98
NS_LOG_FUNCTION
(
this
<< &i);
99
uint8_t buf[4];
100
m_addr
.
Serialize
(buf);
101
i.
Write
(buf, 4);
102
i.
WriteU32
(
m_ifindex
);
103
i.
WriteU8
(
m_ttl
);
104
}
105
106
void
107
Ipv4PacketInfoTag::Deserialize
(
TagBuffer
i)
108
{
109
NS_LOG_FUNCTION
(
this
<< &i);
110
uint8_t buf[4];
111
i.
Read
(buf, 4);
112
m_addr
=
Ipv4Address::Deserialize
(buf);
113
m_ifindex
= i.
ReadU32
();
114
m_ttl
= i.
ReadU8
();
115
}
116
117
void
118
Ipv4PacketInfoTag::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
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4Address::Serialize
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Definition
ipv4-address.cc:285
ns3::Ipv4Address::Deserialize
static Ipv4Address Deserialize(const uint8_t buf[4])
Definition
ipv4-address.cc:295
ns3::Ipv4PacketInfoTag
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
Definition
ipv4-packet-info-tag.h:38
ns3::Ipv4PacketInfoTag::Print
void Print(std::ostream &os) const override
Definition
ipv4-packet-info-tag.cc:118
ns3::Ipv4PacketInfoTag::m_ttl
uint8_t m_ttl
Time to Live.
Definition
ipv4-packet-info-tag.h:107
ns3::Ipv4PacketInfoTag::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
ipv4-packet-info-tag.cc:72
ns3::Ipv4PacketInfoTag::SetRecvIf
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
Definition
ipv4-packet-info-tag.cc:44
ns3::Ipv4PacketInfoTag::Ipv4PacketInfoTag
Ipv4PacketInfoTag()
Definition
ipv4-packet-info-tag.cc:21
ns3::Ipv4PacketInfoTag::SetAddress
void SetAddress(Ipv4Address addr)
Set the tag's address.
Definition
ipv4-packet-info-tag.cc:30
ns3::Ipv4PacketInfoTag::GetTtl
uint8_t GetTtl() const
Get the tag's Time to Live Implemented, but not used in the stack yet.
Definition
ipv4-packet-info-tag.cc:65
ns3::Ipv4PacketInfoTag::GetRecvIf
uint32_t GetRecvIf() const
Get the tag's receiving interface.
Definition
ipv4-packet-info-tag.cc:51
ns3::Ipv4PacketInfoTag::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
ipv4-packet-info-tag.cc:82
ns3::Ipv4PacketInfoTag::m_addr
Ipv4Address m_addr
Header destination address.
Definition
ipv4-packet-info-tag.h:103
ns3::Ipv4PacketInfoTag::Serialize
void Serialize(TagBuffer i) const override
Definition
ipv4-packet-info-tag.cc:96
ns3::Ipv4PacketInfoTag::SetTtl
void SetTtl(uint8_t ttl)
Set the tag's Time to Live Implemented, but not used in the stack yet.
Definition
ipv4-packet-info-tag.cc:58
ns3::Ipv4PacketInfoTag::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
ipv4-packet-info-tag.cc:89
ns3::Ipv4PacketInfoTag::m_ifindex
uint32_t m_ifindex
interface index
Definition
ipv4-packet-info-tag.h:104
ns3::Ipv4PacketInfoTag::GetAddress
Ipv4Address GetAddress() const
Get the tag's address.
Definition
ipv4-packet-info-tag.cc:37
ns3::Ipv4PacketInfoTag::Deserialize
void Deserialize(TagBuffer i) override
Definition
ipv4-packet-info-tag.cc:107
ns3::TagBuffer
read and write tag data
Definition
tag-buffer.h:41
ns3::TagBuffer::ReadU32
TAG_BUFFER_INLINE uint32_t ReadU32()
Definition
tag-buffer.h:206
ns3::TagBuffer::Read
void Read(uint8_t *buffer, uint32_t size)
Definition
tag-buffer.cc:172
ns3::TagBuffer::WriteU8
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition
tag-buffer.h:161
ns3::TagBuffer::ReadU8
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition
tag-buffer.h:185
ns3::TagBuffer::WriteU32
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition
tag-buffer.h:176
ns3::TagBuffer::Write
void Write(const uint8_t *buffer, uint32_t size)
Definition
tag-buffer.cc:118
ns3::Tag
tag a set of bytes in a packet
Definition
tag.h:28
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
ipv4-packet-info-tag.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
model
ipv4-packet-info-tag.cc
Generated on Fri Nov 8 2024 13:59:01 for ns-3 by
1.11.0