A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
three-gpp-http-header.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015 Magister Solutions
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Budiarto Herman <budiarto.herman@magister.fi>
18
*
19
*/
20
21
#include "
three-gpp-http-header.h
"
22
23
#include <ns3/log.h>
24
#include <ns3/packet.h>
25
26
#include <sstream>
27
28
NS_LOG_COMPONENT_DEFINE
(
"ThreeGppHttpHeader"
);
29
30
namespace
ns3
31
{
32
33
NS_OBJECT_ENSURE_REGISTERED
(ThreeGppHttpHeader);
34
35
ThreeGppHttpHeader::ThreeGppHttpHeader
()
36
:
Header
(),
37
m_contentType(NOT_SET),
38
m_contentLength(0),
39
m_clientTs(0),
40
m_serverTs(0)
41
{
42
NS_LOG_FUNCTION
(
this
);
43
}
44
45
// static
46
TypeId
47
ThreeGppHttpHeader::GetTypeId
()
48
{
49
static
TypeId
tid =
50
TypeId
(
"ns3::ThreeGppHttpHeader"
).
SetParent
<
Header
>().AddConstructor<ThreeGppHttpHeader>();
51
return
tid;
52
}
53
54
TypeId
55
ThreeGppHttpHeader::GetInstanceTypeId
()
const
56
{
57
return
GetTypeId
();
58
}
59
60
uint32_t
61
ThreeGppHttpHeader::GetSerializedSize
()
const
62
{
63
return
2 + 4 + 8 + 8;
64
}
65
66
void
67
ThreeGppHttpHeader::Serialize
(
Buffer::Iterator
start
)
const
68
{
69
NS_LOG_FUNCTION
(
this
<< &
start
);
70
start
.WriteU16(
m_contentType
);
71
start
.WriteU32(
m_contentLength
);
72
start
.WriteU64(
m_clientTs
);
73
start
.WriteU64(
m_serverTs
);
74
}
75
76
uint32_t
77
ThreeGppHttpHeader::Deserialize
(
Buffer::Iterator
start
)
78
{
79
NS_LOG_FUNCTION
(
this
<< &
start
);
80
uint32_t bytesRead = 0;
81
82
// First block of 2 bytes (content type)
83
m_contentType
=
start
.ReadU16();
84
bytesRead += 2;
85
86
// Second block of 4 bytes (content length)
87
m_contentLength
=
start
.ReadU32();
88
bytesRead += 4;
89
90
// Third block of 8 bytes (client time stamp)
91
m_clientTs
=
start
.ReadU64();
92
bytesRead += 8;
93
94
// Fourth block of 8 bytes (server time stamp)
95
m_serverTs
=
start
.ReadU64();
96
bytesRead += 8;
97
98
return
bytesRead;
99
}
100
101
void
102
ThreeGppHttpHeader::Print
(std::ostream& os)
const
103
{
104
NS_LOG_FUNCTION
(
this
<< &os);
105
os <<
"(Content-Type: "
<<
m_contentType
<<
" Content-Length: "
<<
m_contentLength
106
<<
" Client TS: "
<< TimeStep(
m_clientTs
).As(
Time::S
)
107
<<
" Server TS: "
<< TimeStep(
m_serverTs
).As(
Time::S
) <<
")"
;
108
}
109
110
std::string
111
ThreeGppHttpHeader::ToString
()
const
112
{
113
NS_LOG_FUNCTION
(
this
);
114
std::ostringstream oss;
115
Print
(oss);
116
return
oss.str();
117
}
118
119
void
120
ThreeGppHttpHeader::SetContentType
(
ThreeGppHttpHeader::ContentType_t
contentType)
121
{
122
NS_LOG_FUNCTION
(
this
<<
static_cast<
uint16_t
>
(contentType));
123
switch
(contentType)
124
{
125
case
NOT_SET
:
126
m_contentType
= 0;
127
break
;
128
case
MAIN_OBJECT
:
129
m_contentType
= 1;
130
break
;
131
case
EMBEDDED_OBJECT
:
132
m_contentType
= 2;
133
break
;
134
default
:
135
NS_FATAL_ERROR
(
"Unknown Content-Type: "
<< contentType);
136
break
;
137
}
138
}
139
140
ThreeGppHttpHeader::ContentType_t
141
ThreeGppHttpHeader::GetContentType
()
const
142
{
143
ContentType_t
ret;
144
switch
(
m_contentType
)
145
{
146
case
0:
147
ret =
NOT_SET
;
148
break
;
149
case
1:
150
ret =
MAIN_OBJECT
;
151
break
;
152
case
2:
153
ret =
EMBEDDED_OBJECT
;
154
break
;
155
default
:
156
NS_FATAL_ERROR
(
"Unknown Content-Type: "
<<
m_contentType
);
157
break
;
158
}
159
return
ret;
160
}
161
162
void
163
ThreeGppHttpHeader::SetContentLength
(uint32_t contentLength)
164
{
165
NS_LOG_FUNCTION
(
this
<< contentLength);
166
m_contentLength
= contentLength;
167
}
168
169
uint32_t
170
ThreeGppHttpHeader::GetContentLength
()
const
171
{
172
return
m_contentLength
;
173
}
174
175
void
176
ThreeGppHttpHeader::SetClientTs
(
Time
clientTs)
177
{
178
NS_LOG_FUNCTION
(
this
<< clientTs.
As
(
Time::S
));
179
m_clientTs
= clientTs.
GetTimeStep
();
180
}
181
182
Time
183
ThreeGppHttpHeader::GetClientTs
()
const
184
{
185
return
TimeStep(
m_clientTs
);
186
}
187
188
void
189
ThreeGppHttpHeader::SetServerTs
(
Time
serverTs)
190
{
191
NS_LOG_FUNCTION
(
this
<< serverTs.
As
(
Time::S
));
192
m_serverTs
= serverTs.
GetTimeStep
();
193
}
194
195
Time
196
ThreeGppHttpHeader::GetServerTs
()
const
197
{
198
return
TimeStep(
m_serverTs
);
199
}
200
201
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:44
ns3::Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::ThreeGppHttpHeader::SetClientTs
void SetClientTs(Time clientTs)
Definition:
three-gpp-http-header.cc:176
ns3::ThreeGppHttpHeader::ToString
std::string ToString() const
Definition:
three-gpp-http-header.cc:111
ns3::ThreeGppHttpHeader::SetServerTs
void SetServerTs(Time serverTs)
Definition:
three-gpp-http-header.cc:189
ns3::ThreeGppHttpHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
three-gpp-http-header.cc:61
ns3::ThreeGppHttpHeader::GetClientTs
Time GetClientTs() const
Definition:
three-gpp-http-header.cc:183
ns3::ThreeGppHttpHeader::SetContentLength
void SetContentLength(uint32_t contentLength)
Definition:
three-gpp-http-header.cc:163
ns3::ThreeGppHttpHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition:
three-gpp-http-header.cc:67
ns3::ThreeGppHttpHeader::SetContentType
void SetContentType(ContentType_t contentType)
Definition:
three-gpp-http-header.cc:120
ns3::ThreeGppHttpHeader::ContentType_t
ContentType_t
The possible types of content (default = NOT_SET).
Definition:
three-gpp-http-header.h:82
ns3::ThreeGppHttpHeader::NOT_SET
@ NOT_SET
Integer equivalent = 0.
Definition:
three-gpp-http-header.h:83
ns3::ThreeGppHttpHeader::EMBEDDED_OBJECT
@ EMBEDDED_OBJECT
Integer equivalent = 2.
Definition:
three-gpp-http-header.h:85
ns3::ThreeGppHttpHeader::MAIN_OBJECT
@ MAIN_OBJECT
Integer equivalent = 1.
Definition:
three-gpp-http-header.h:84
ns3::ThreeGppHttpHeader::ThreeGppHttpHeader
ThreeGppHttpHeader()
Creates an empty instance.
Definition:
three-gpp-http-header.cc:35
ns3::ThreeGppHttpHeader::m_clientTs
uint64_t m_clientTs
" Client time stamp field (in time step unit).
Definition:
three-gpp-http-header.h:131
ns3::ThreeGppHttpHeader::m_contentLength
uint32_t m_contentLength
" Content length field (in bytes unit).
Definition:
three-gpp-http-header.h:130
ns3::ThreeGppHttpHeader::Print
void Print(std::ostream &os) const override
Definition:
three-gpp-http-header.cc:102
ns3::ThreeGppHttpHeader::m_serverTs
uint64_t m_serverTs
" Server time stamp field (in time step unit).
Definition:
three-gpp-http-header.h:132
ns3::ThreeGppHttpHeader::GetContentType
ContentType_t GetContentType() const
Definition:
three-gpp-http-header.cc:141
ns3::ThreeGppHttpHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
three-gpp-http-header.cc:55
ns3::ThreeGppHttpHeader::GetServerTs
Time GetServerTs() const
Definition:
three-gpp-http-header.cc:196
ns3::ThreeGppHttpHeader::GetContentLength
uint32_t GetContentLength() const
Definition:
three-gpp-http-header.cc:170
ns3::ThreeGppHttpHeader::m_contentType
uint16_t m_contentType
" Content type field in integer format.
Definition:
three-gpp-http-header.h:129
ns3::ThreeGppHttpHeader::GetTypeId
static TypeId GetTypeId()
Returns the object TypeId.
Definition:
three-gpp-http-header.cc:47
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:105
ns3::Time::As
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition:
time.cc:415
ns3::Time::S
@ S
second
Definition:
nstime.h:116
ns3::Time::GetTimeStep
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition:
nstime.h:445
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:931
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:179
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
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:240
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
two-ray-to-three-gpp-ch-calibration.start
start
Definition:
two-ray-to-three-gpp-ch-calibration.py:520
three-gpp-http-header.h
src
applications
model
three-gpp-http-header.cc
Generated on Sun Mar 3 2024 17:10:54 for ns-3 by
1.9.1