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
26
namespace
ns3 {
27
28
Ipv4PacketInfoTag::Ipv4PacketInfoTag
()
29
: m_addr (
Ipv4Address
()),
30
m_spec_dst (
Ipv4Address
()),
31
m_ifindex (0),
32
m_ttl (0)
33
{
34
}
35
36
void
37
Ipv4PacketInfoTag::SetAddress
(
Ipv4Address
addr)
38
{
39
m_addr
= addr;
40
}
41
42
Ipv4Address
43
Ipv4PacketInfoTag::GetAddress
(
void
)
const
44
{
45
return
m_addr
;
46
}
47
48
void
49
Ipv4PacketInfoTag::SetLocalAddress
(
Ipv4Address
addr)
50
{
51
m_spec_dst
= addr;
52
}
53
54
Ipv4Address
55
Ipv4PacketInfoTag::GetLocalAddress
(
void
)
const
56
{
57
return
m_spec_dst
;
58
}
59
60
void
61
Ipv4PacketInfoTag::SetRecvIf
(uint32_t ifindex)
62
{
63
m_ifindex
= ifindex;
64
}
65
66
uint32_t
67
Ipv4PacketInfoTag::GetRecvIf
(
void
)
const
68
{
69
return
m_ifindex
;
70
}
71
72
void
73
Ipv4PacketInfoTag::SetTtl
(uint8_t ttl)
74
{
75
m_ttl
= ttl;
76
}
77
78
uint8_t
79
Ipv4PacketInfoTag::GetTtl
(
void
)
const
80
{
81
return
m_ttl
;
82
}
83
84
85
86
TypeId
87
Ipv4PacketInfoTag::GetTypeId
(
void
)
88
{
89
static
TypeId
tid =
TypeId
(
"ns3::Ipv4PacketInfoTag"
)
90
.
SetParent
<
Tag
> ()
91
.AddConstructor<Ipv4PacketInfoTag> ()
92
;
93
return
tid;
94
}
95
TypeId
96
Ipv4PacketInfoTag::GetInstanceTypeId
(
void
)
const
97
{
98
return
GetTypeId
();
99
}
100
101
uint32_t
102
Ipv4PacketInfoTag::GetSerializedSize
(
void
)
const
103
{
104
return
4 + 4
105
+
sizeof
(uint32_t)
106
+
sizeof
(uint8_t);
107
}
108
void
109
Ipv4PacketInfoTag::Serialize
(
TagBuffer
i)
const
110
{
111
uint8_t buf[4];
112
m_addr
.
Serialize
(buf);
113
i.
Write
(buf, 4);
114
m_spec_dst
.
Serialize
(buf);
115
i.
Write
(buf, 4);
116
i.
WriteU32
(
m_ifindex
);
117
i.
WriteU8
(
m_ttl
);
118
}
119
void
120
Ipv4PacketInfoTag::Deserialize
(
TagBuffer
i)
121
{
122
uint8_t buf[4];
123
i.
Read
(buf, 4);
124
m_addr
=
Ipv4Address::Deserialize
(buf);
125
i.
Read
(buf, 4);
126
m_spec_dst
=
Ipv4Address::Deserialize
(buf);
127
m_ifindex
= i.
ReadU32
();
128
m_ttl
= i.
ReadU8
();
129
}
130
void
131
Ipv4PacketInfoTag::Print
(std::ostream &os)
const
132
{
133
os <<
"Ipv4 PKTINFO [DestAddr: "
<<
m_addr
;
134
os <<
", Local Address:"
<<
m_spec_dst
;
135
os <<
", RecvIf:"
<< (uint32_t)
m_ifindex
;
136
os <<
", TTL:"
<< (uint32_t)
m_ttl
;
137
os <<
"] "
;
138
}
139
}
// namespace ns3
140
src
internet
model
ipv4-packet-info-tag.cc
Generated on Fri Dec 21 2012 19:00:36 for ns-3 by
1.8.1.2