A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
ipv4-packet-info-tag.cc
Go to the documentation of this file.
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
22
#include <stdint.h>
23
#include "ns3/ipv4-address.h"
24
#include "
ipv4-packet-info-tag.h
"
25
#include "ns3/log.h"
26
27
namespace
ns3
{
28
29
NS_LOG_COMPONENT_DEFINE
(
"Ipv4PacketInfoTag"
);
30
31
Ipv4PacketInfoTag::Ipv4PacketInfoTag
()
32
: m_addr (
Ipv4Address
()),
33
m_ifindex (0),
34
m_ttl (0)
35
{
36
NS_LOG_FUNCTION
(
this
);
37
}
38
39
void
40
Ipv4PacketInfoTag::SetAddress
(
Ipv4Address
addr)
41
{
42
NS_LOG_FUNCTION
(
this
<< addr);
43
m_addr
= addr;
44
}
45
46
Ipv4Address
47
Ipv4PacketInfoTag::GetAddress
(
void
)
const
48
{
49
NS_LOG_FUNCTION
(
this
);
50
return
m_addr
;
51
}
52
53
void
54
Ipv4PacketInfoTag::SetRecvIf
(uint32_t ifindex)
55
{
56
NS_LOG_FUNCTION
(
this
<< ifindex);
57
m_ifindex
= ifindex;
58
}
59
60
uint32_t
61
Ipv4PacketInfoTag::GetRecvIf
(
void
)
const
62
{
63
NS_LOG_FUNCTION
(
this
);
64
return
m_ifindex
;
65
}
66
67
void
68
Ipv4PacketInfoTag::SetTtl
(uint8_t ttl)
69
{
70
NS_LOG_FUNCTION
(
this
<<
static_cast<
uint32_t
>
(ttl));
71
m_ttl
= ttl;
72
}
73
74
uint8_t
75
Ipv4PacketInfoTag::GetTtl
(
void
)
const
76
{
77
NS_LOG_FUNCTION
(
this
);
78
return
m_ttl
;
79
}
80
81
82
83
TypeId
84
Ipv4PacketInfoTag::GetTypeId
(
void
)
85
{
86
static
TypeId
tid =
TypeId
(
"ns3::Ipv4PacketInfoTag"
)
87
.
SetParent
<
Tag
> ()
88
.SetGroupName (
"Internet"
)
89
.AddConstructor<
Ipv4PacketInfoTag
> ()
90
;
91
return
tid;
92
}
93
TypeId
94
Ipv4PacketInfoTag::GetInstanceTypeId
(
void
)
const
95
{
96
NS_LOG_FUNCTION
(
this
);
97
return
GetTypeId
();
98
}
99
100
uint32_t
101
Ipv4PacketInfoTag::GetSerializedSize
(
void
)
const
102
{
103
NS_LOG_FUNCTION
(
this
);
104
return
4 +
sizeof
(uint32_t) +
sizeof
(uint8_t);
105
}
106
void
107
Ipv4PacketInfoTag::Serialize
(
TagBuffer
i)
const
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
void
117
Ipv4PacketInfoTag::Deserialize
(
TagBuffer
i)
118
{
119
NS_LOG_FUNCTION
(
this
<< &i);
120
uint8_t buf[4];
121
i.
Read
(buf, 4);
122
m_addr
=
Ipv4Address::Deserialize
(buf);
123
m_ifindex
= i.
ReadU32
();
124
m_ttl
= i.
ReadU8
();
125
}
126
void
127
Ipv4PacketInfoTag::Print
(std::ostream &os)
const
128
{
129
NS_LOG_FUNCTION
(
this
<< &os);
130
os <<
"Ipv4 PKTINFO [DestAddr: "
<<
m_addr
;
131
os <<
", RecvIf:"
<< (uint32_t)
m_ifindex
;
132
os <<
", TTL:"
<< (uint32_t)
m_ttl
;
133
os <<
"] "
;
134
}
135
}
// namespace ns3
136
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TagBuffer::WriteU32
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition:
tag-buffer.h:186
ns3::Ipv4PacketInfoTag::GetRecvIf
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
Definition:
ipv4-packet-info-tag.cc:61
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:41
ns3::TagBuffer::ReadU32
TAG_BUFFER_INLINE uint32_t ReadU32(void)
Definition:
tag-buffer.h:215
ns3::Ipv4PacketInfoTag::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition:
ipv4-packet-info-tag.cc:84
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:68
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:923
ns3::Ipv4Address::Deserialize
static Ipv4Address Deserialize(const uint8_t buf[4])
Definition:
ipv4-address.cc:322
ns3::Ipv4PacketInfoTag::GetAddress
Ipv4Address GetAddress(void) const
Get the tag's address.
Definition:
ipv4-packet-info-tag.cc:47
ns3::TagBuffer::Write
void Write(const uint8_t *buffer, uint32_t size)
Definition:
tag-buffer.cc:125
ns3::Tag
tag a set of bytes in a packet
Definition:
tag.h:37
ns3::Ipv4PacketInfoTag::m_ifindex
uint32_t m_ifindex
interface index
Definition:
ipv4-packet-info-tag.h:116
ns3::TagBuffer::ReadU8
TAG_BUFFER_INLINE uint8_t ReadU8(void)
Definition:
tag-buffer.h:195
ns3::Ipv4PacketInfoTag::Serialize
virtual void Serialize(TagBuffer i) const
Definition:
ipv4-packet-info-tag.cc:107
ns3::Ipv4PacketInfoTag::m_addr
Ipv4Address m_addr
Header destination address.
Definition:
ipv4-packet-info-tag.h:115
ipv4-packet-info-tag.h
ns3::TagBuffer::WriteU8
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition:
tag-buffer.h:172
ns3::Ipv4PacketInfoTag
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
Definition:
ipv4-packet-info-tag.h:50
ns3::Ipv4PacketInfoTag::Deserialize
virtual void Deserialize(TagBuffer i)
Definition:
ipv4-packet-info-tag.cc:117
ns3::TagBuffer::Read
void Read(uint8_t *buffer, uint32_t size)
Definition:
tag-buffer.cc:176
ns3::Ipv4Address::Serialize
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Definition:
ipv4-address.cc:313
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:244
ns3::Ipv4PacketInfoTag::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition:
ipv4-packet-info-tag.cc:94
ns3::Ipv4PacketInfoTag::m_ttl
uint8_t m_ttl
Time to Live.
Definition:
ipv4-packet-info-tag.h:119
ns3::Ipv4PacketInfoTag::Ipv4PacketInfoTag
Ipv4PacketInfoTag()
Definition:
ipv4-packet-info-tag.cc:31
ns3::Ipv4PacketInfoTag::SetAddress
void SetAddress(Ipv4Address addr)
Set the tag's address.
Definition:
ipv4-packet-info-tag.cc:40
ns3::TagBuffer
read and write tag data
Definition:
tag-buffer.h:52
ns3::Ipv4PacketInfoTag::SetRecvIf
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
Definition:
ipv4-packet-info-tag.cc:54
ns3::Ipv4PacketInfoTag::GetTtl
uint8_t GetTtl(void) const
Get the tag's Time to Live Implemented, but not used in the stack yet.
Definition:
ipv4-packet-info-tag.cc:75
ns3::Ipv4PacketInfoTag::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition:
ipv4-packet-info-tag.cc:101
ns3::Ipv4PacketInfoTag::Print
virtual void Print(std::ostream &os) const
Definition:
ipv4-packet-info-tag.cc:127
src
internet
model
ipv4-packet-info-tag.cc
Generated on Fri Oct 1 2021 17:03:06 for ns-3 by
1.8.20