A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
NS_LOG_COMPONENT_DEFINE
(
"Ipv4PacketInfoTag"
);
28
29
namespace
ns3 {
30
31
Ipv4PacketInfoTag::Ipv4PacketInfoTag
()
32
: m_addr (
Ipv4Address
()),
33
m_spec_dst (
Ipv4Address
()),
34
m_ifindex (0),
35
m_ttl (0)
36
{
37
NS_LOG_FUNCTION
(
this
);
38
}
39
40
void
41
Ipv4PacketInfoTag::SetAddress
(
Ipv4Address
addr)
42
{
43
NS_LOG_FUNCTION
(
this
<< addr);
44
m_addr
= addr;
45
}
46
47
Ipv4Address
48
Ipv4PacketInfoTag::GetAddress
(
void
)
const
49
{
50
NS_LOG_FUNCTION
(
this
);
51
return
m_addr
;
52
}
53
54
void
55
Ipv4PacketInfoTag::SetLocalAddress
(
Ipv4Address
addr)
56
{
57
NS_LOG_FUNCTION
(
this
<< addr);
58
m_spec_dst
= addr;
59
}
60
61
Ipv4Address
62
Ipv4PacketInfoTag::GetLocalAddress
(
void
)
const
63
{
64
NS_LOG_FUNCTION
(
this
);
65
return
m_spec_dst
;
66
}
67
68
void
69
Ipv4PacketInfoTag::SetRecvIf
(uint32_t ifindex)
70
{
71
NS_LOG_FUNCTION
(
this
<< ifindex);
72
m_ifindex
= ifindex;
73
}
74
75
uint32_t
76
Ipv4PacketInfoTag::GetRecvIf
(
void
)
const
77
{
78
NS_LOG_FUNCTION
(
this
);
79
return
m_ifindex
;
80
}
81
82
void
83
Ipv4PacketInfoTag::SetTtl
(uint8_t ttl)
84
{
85
NS_LOG_FUNCTION
(
this
<< static_cast<uint32_t> (ttl));
86
m_ttl
= ttl;
87
}
88
89
uint8_t
90
Ipv4PacketInfoTag::GetTtl
(
void
)
const
91
{
92
NS_LOG_FUNCTION
(
this
);
93
return
m_ttl
;
94
}
95
96
97
98
TypeId
99
Ipv4PacketInfoTag::GetTypeId
(
void
)
100
{
101
static
TypeId
tid =
TypeId
(
"ns3::Ipv4PacketInfoTag"
)
102
.
SetParent
<
Tag
> ()
103
.AddConstructor<Ipv4PacketInfoTag> ()
104
;
105
return
tid;
106
}
107
TypeId
108
Ipv4PacketInfoTag::GetInstanceTypeId
(
void
)
const
109
{
110
NS_LOG_FUNCTION
(
this
);
111
return
GetTypeId
();
112
}
113
114
uint32_t
115
Ipv4PacketInfoTag::GetSerializedSize
(
void
)
const
116
{
117
NS_LOG_FUNCTION
(
this
);
118
return
4 + 4
119
+
sizeof
(uint32_t)
120
+
sizeof
(uint8_t);
121
}
122
void
123
Ipv4PacketInfoTag::Serialize
(
TagBuffer
i)
const
124
{
125
NS_LOG_FUNCTION
(
this
<< &i);
126
uint8_t buf[4];
127
m_addr
.
Serialize
(buf);
128
i.
Write
(buf, 4);
129
m_spec_dst
.
Serialize
(buf);
130
i.
Write
(buf, 4);
131
i.
WriteU32
(
m_ifindex
);
132
i.
WriteU8
(
m_ttl
);
133
}
134
void
135
Ipv4PacketInfoTag::Deserialize
(
TagBuffer
i)
136
{
137
NS_LOG_FUNCTION
(
this
<< &i);
138
uint8_t buf[4];
139
i.
Read
(buf, 4);
140
m_addr
=
Ipv4Address::Deserialize
(buf);
141
i.
Read
(buf, 4);
142
m_spec_dst
=
Ipv4Address::Deserialize
(buf);
143
m_ifindex
= i.
ReadU32
();
144
m_ttl
= i.
ReadU8
();
145
}
146
void
147
Ipv4PacketInfoTag::Print
(std::ostream &os)
const
148
{
149
NS_LOG_FUNCTION
(
this
<< &os);
150
os <<
"Ipv4 PKTINFO [DestAddr: "
<<
m_addr
;
151
os <<
", Local Address:"
<<
m_spec_dst
;
152
os <<
", RecvIf:"
<< (uint32_t)
m_ifindex
;
153
os <<
", TTL:"
<< (uint32_t)
m_ttl
;
154
os <<
"] "
;
155
}
156
}
// namespace ns3
157
ns3::Ipv4Address::Deserialize
static Ipv4Address Deserialize(const uint8_t buf[4])
Definition:
ipv4-address.cc:289
ns3::TagBuffer::Write
void Write(const uint8_t *buffer, uint32_t size)
Definition:
tag-buffer.cc:125
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::Ipv4PacketInfoTag::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition:
ipv4-packet-info-tag.cc:115
ns3::Ipv4PacketInfoTag::Ipv4PacketInfoTag
Ipv4PacketInfoTag()
Definition:
ipv4-packet-info-tag.cc:31
ns3::TagBuffer::ReadU32
TAG_BUFFER_INLINE uint32_t ReadU32(void)
Definition:
tag-buffer.h:199
ns3::Ipv4PacketInfoTag::m_addr
Ipv4Address m_addr
Header destination address.
Definition:
ipv4-packet-info-tag.h:124
ns3::TagBuffer::ReadU8
TAG_BUFFER_INLINE uint8_t ReadU8(void)
Definition:
tag-buffer.h:179
ns3::Ipv4PacketInfoTag::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Definition:
ipv4-packet-info-tag.cc:108
ns3::Ipv4PacketInfoTag::m_ifindex
uint32_t m_ifindex
interface index
Definition:
ipv4-packet-info-tag.h:126
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:83
ns3::Ipv4PacketInfoTag::m_spec_dst
Ipv4Address m_spec_dst
Local address.
Definition:
ipv4-packet-info-tag.h:125
ns3::Ipv4PacketInfoTag::GetRecvIf
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
Definition:
ipv4-packet-info-tag.cc:76
ns3::TagBuffer::WriteU32
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition:
tag-buffer.h:170
ns3::Ipv4Address::Serialize
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Definition:
ipv4-address.cc:280
ns3::Ipv4PacketInfoTag::Serialize
virtual void Serialize(TagBuffer i) const
Definition:
ipv4-packet-info-tag.cc:123
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:90
ns3::Tag
tag a set of bytes in a packet
Definition:
tag.h:36
ns3::Ipv4PacketInfoTag::GetLocalAddress
Ipv4Address GetLocalAddress(void) const
Get the tag's local address.
Definition:
ipv4-packet-info-tag.cc:62
ns3::Ipv4PacketInfoTag::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition:
ipv4-packet-info-tag.cc:99
ns3::Ipv4PacketInfoTag::m_ttl
uint8_t m_ttl
Time to Live.
Definition:
ipv4-packet-info-tag.h:129
ns3::TagBuffer::WriteU8
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition:
tag-buffer.h:156
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:38
ns3::TagBuffer
read and write tag data
Definition:
tag-buffer.h:51
ns3::Ipv4PacketInfoTag::Deserialize
virtual void Deserialize(TagBuffer i)
Definition:
ipv4-packet-info-tag.cc:135
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("Ipv4PacketInfoTag")
ns3::Ipv4PacketInfoTag::GetAddress
Ipv4Address GetAddress(void) const
Get the tag's address.
Definition:
ipv4-packet-info-tag.cc:48
ns3::Ipv4PacketInfoTag::SetLocalAddress
void SetLocalAddress(Ipv4Address addr)
Set the tag's local address.
Definition:
ipv4-packet-info-tag.cc:55
ns3::TagBuffer::Read
void Read(uint8_t *buffer, uint32_t size)
Definition:
tag-buffer.cc:176
ns3::Ipv4PacketInfoTag::Print
virtual void Print(std::ostream &os) const
Definition:
ipv4-packet-info-tag.cc:147
ns3::Ipv4PacketInfoTag::SetAddress
void SetAddress(Ipv4Address addr)
Set the tag's address.
Definition:
ipv4-packet-info-tag.cc:41
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
ipv4-packet-info-tag.h
ns3::Ipv4PacketInfoTag::SetRecvIf
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
Definition:
ipv4-packet-info-tag.cc:69
src
internet
model
ipv4-packet-info-tag.cc
Generated on Sat Apr 19 2014 14:06:56 for ns-3 by
1.8.6