A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
applications
model
three-gpp-http-header.cc
Go to the documentation of this file.
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2015 Magister Solutions
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
* Author: Budiarto Herman <budiarto.herman@magister.fi>
19
*
20
*/
21
22
#include <ns3/log.h>
23
#include <ns3/packet.h>
24
#include <sstream>
25
#include "
three-gpp-http-header.h
"
26
27
NS_LOG_COMPONENT_DEFINE
(
"ThreeGppHttpHeader"
);
28
29
namespace
ns3
{
30
31
NS_OBJECT_ENSURE_REGISTERED
(ThreeGppHttpHeader);
32
33
ThreeGppHttpHeader::ThreeGppHttpHeader
()
34
:
Header
(),
35
m_contentType (NOT_SET),
36
m_contentLength (0),
37
m_clientTs (0),
38
m_serverTs (0)
39
{
40
NS_LOG_FUNCTION
(
this
);
41
}
42
43
44
// static
45
TypeId
46
ThreeGppHttpHeader::GetTypeId
()
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::ThreeGppHttpHeader"
)
49
.
SetParent
<
Header
> ()
50
.AddConstructor<ThreeGppHttpHeader> ()
51
;
52
return
tid;
53
}
54
55
56
TypeId
57
ThreeGppHttpHeader::GetInstanceTypeId
()
const
58
{
59
return
GetTypeId
();
60
}
61
62
63
uint32_t
64
ThreeGppHttpHeader::GetSerializedSize
()
const
65
{
66
return
2 + 4 + 8 + 8;
67
}
68
69
70
void
71
ThreeGppHttpHeader::Serialize
(
Buffer::Iterator
start
)
const
72
{
73
NS_LOG_FUNCTION
(
this
<< &
start
);
74
start
.WriteU16 (
m_contentType
);
75
start
.WriteU32 (
m_contentLength
);
76
start
.WriteU64 (
m_clientTs
);
77
start
.WriteU64 (
m_serverTs
);
78
}
79
80
81
uint32_t
82
ThreeGppHttpHeader::Deserialize
(
Buffer::Iterator
start
)
83
{
84
NS_LOG_FUNCTION
(
this
<< &
start
);
85
uint32_t bytesRead = 0;
86
87
// First block of 2 bytes (content type)
88
m_contentType
=
start
.ReadU16 ();
89
bytesRead += 2;
90
91
// Second block of 4 bytes (content length)
92
m_contentLength
=
start
.ReadU32 ();
93
bytesRead += 4;
94
95
// Third block of 8 bytes (client time stamp)
96
m_clientTs
=
start
.ReadU64 ();
97
bytesRead += 8;
98
99
// Fourth block of 8 bytes (server time stamp)
100
m_serverTs
=
start
.ReadU64 ();
101
bytesRead += 8;
102
103
return
bytesRead;
104
}
105
106
107
void
108
ThreeGppHttpHeader::Print
(std::ostream &os)
const
109
{
110
NS_LOG_FUNCTION
(
this
<< &os);
111
os <<
"(Content-Type: "
<<
m_contentType
112
<<
" Content-Length: "
<<
m_contentLength
113
<<
" Client TS: "
<<
TimeStep
(
m_clientTs
).
GetSeconds
()
114
<<
" Server TS: "
<<
TimeStep
(
m_serverTs
).
GetSeconds
() <<
")"
;
115
}
116
117
118
std::string
119
ThreeGppHttpHeader::ToString
()
const
120
{
121
NS_LOG_FUNCTION
(
this
);
122
std::ostringstream oss;
123
Print
(oss);
124
return
oss.str ();
125
}
126
127
128
void
129
ThreeGppHttpHeader::SetContentType
(
ThreeGppHttpHeader::ContentType_t
contentType)
130
{
131
NS_LOG_FUNCTION
(
this
<< static_cast<uint16_t> (contentType));
132
switch
(contentType)
133
{
134
case
NOT_SET
:
135
m_contentType
= 0;
136
break
;
137
case
MAIN_OBJECT
:
138
m_contentType
= 1;
139
break
;
140
case
EMBEDDED_OBJECT
:
141
m_contentType
= 2;
142
break
;
143
default
:
144
NS_FATAL_ERROR
(
"Unknown Content-Type: "
<< contentType);
145
break
;
146
}
147
}
148
149
150
ThreeGppHttpHeader::ContentType_t
151
ThreeGppHttpHeader::GetContentType
()
const
152
{
153
ContentType_t
ret;
154
switch
(
m_contentType
)
155
{
156
case
0:
157
ret =
NOT_SET
;
158
break
;
159
case
1:
160
ret =
MAIN_OBJECT
;
161
break
;
162
case
2:
163
ret =
EMBEDDED_OBJECT
;
164
break
;
165
default
:
166
NS_FATAL_ERROR
(
"Unknown Content-Type: "
<<
m_contentType
);
167
break
;
168
}
169
return
ret;
170
}
171
172
173
void
174
ThreeGppHttpHeader::SetContentLength
(uint32_t contentLength)
175
{
176
NS_LOG_FUNCTION
(
this
<< contentLength);
177
m_contentLength
= contentLength;
178
}
179
180
181
uint32_t
182
ThreeGppHttpHeader::GetContentLength
()
const
183
{
184
return
m_contentLength
;
185
}
186
187
188
void
189
ThreeGppHttpHeader::SetClientTs
(
Time
clientTs)
190
{
191
NS_LOG_FUNCTION
(
this
<< clientTs.
GetSeconds
());
192
m_clientTs
= clientTs.
GetTimeStep
();
193
}
194
195
196
Time
197
ThreeGppHttpHeader::GetClientTs
()
const
198
{
199
return
TimeStep
(
m_clientTs
);
200
}
201
202
203
void
204
ThreeGppHttpHeader::SetServerTs
(
Time
serverTs)
205
{
206
NS_LOG_FUNCTION
(
this
<< serverTs.
GetSeconds
());
207
m_serverTs
= serverTs.
GetTimeStep
();
208
}
209
210
211
Time
212
ThreeGppHttpHeader::GetServerTs
()
const
213
{
214
return
TimeStep
(
m_serverTs
);
215
}
216
217
218
}
// namespace ns3
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:42
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:102
ns3::ThreeGppHttpHeader::GetContentType
ContentType_t GetContentType() const
Definition:
three-gpp-http-header.cc:151
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:213
ns3::ThreeGppHttpHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
Definition:
three-gpp-http-header.cc:64
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:45
ns3::ThreeGppHttpHeader::NOT_SET
Integer equivalent = 0.
Definition:
three-gpp-http-header.h:84
visualizer.core.start
def start()
Definition:
core.py:1844
ns3::Time::GetSeconds
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition:
nstime.h:355
ns3::ThreeGppHttpHeader::Print
virtual void Print(std::ostream &os) const
Definition:
three-gpp-http-header.cc:108
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3::ThreeGppHttpHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Definition:
three-gpp-http-header.cc:71
ns3::ThreeGppHttpHeader::GetClientTs
Time GetClientTs() const
Definition:
three-gpp-http-header.cc:197
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:162
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:98
ns3::ThreeGppHttpHeader::ThreeGppHttpHeader
ThreeGppHttpHeader()
Creates an empty instance .
Definition:
three-gpp-http-header.cc:33
ns3::ThreeGppHttpHeader::GetContentLength
uint32_t GetContentLength() const
Definition:
three-gpp-http-header.cc:182
ns3::ThreeGppHttpHeader::SetServerTs
void SetServerTs(Time serverTs)
Definition:
three-gpp-http-header.cc:204
ns3::ThreeGppHttpHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Definition:
three-gpp-http-header.cc:57
ns3::ThreeGppHttpHeader::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition:
three-gpp-http-header.cc:82
ns3::ThreeGppHttpHeader::MAIN_OBJECT
Integer equivalent = 1.
Definition:
three-gpp-http-header.h:85
ns3::ThreeGppHttpHeader::ContentType_t
ContentType_t
The possible types of content (default = NOT_SET).
Definition:
three-gpp-http-header.h:82
ns3::ThreeGppHttpHeader::SetContentLength
void SetContentLength(uint32_t contentLength)
Definition:
three-gpp-http-header.cc:174
ns3::ThreeGppHttpHeader::GetServerTs
Time GetServerTs() const
Definition:
three-gpp-http-header.cc:212
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ThreeGppHttpHeader::EMBEDDED_OBJECT
Integer equivalent = 2.
Definition:
three-gpp-http-header.h:86
ns3::ThreeGppHttpHeader::GetTypeId
static TypeId GetTypeId()
Returns the object TypeId.
Definition:
three-gpp-http-header.cc:46
ns3::TimeStep
Time TimeStep(uint64_t ts)
Definition:
nstime.h:1071
ns3::ThreeGppHttpHeader::m_contentLength
uint32_t m_contentLength
" Content length field (in bytes unit).
Definition:
three-gpp-http-header.h:131
ns3::ThreeGppHttpHeader::SetClientTs
void SetClientTs(Time clientTs)
Definition:
three-gpp-http-header.cc:189
ns3::ThreeGppHttpHeader::ToString
std::string ToString() const
Definition:
three-gpp-http-header.cc:119
ns3::ThreeGppHttpHeader::m_clientTs
uint64_t m_clientTs
" Client time stamp field (in time step unit).
Definition:
three-gpp-http-header.h:132
ns3::ThreeGppHttpHeader::m_serverTs
uint64_t m_serverTs
" Server time stamp field (in time step unit).
Definition:
three-gpp-http-header.h:133
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:58
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:915
ns3::ThreeGppHttpHeader::SetContentType
void SetContentType(ContentType_t contentType)
Definition:
three-gpp-http-header.cc:129
three-gpp-http-header.h
ns3::ThreeGppHttpHeader::m_contentType
uint16_t m_contentType
" Content type field in integer format.
Definition:
three-gpp-http-header.h:130
ns3::Time::GetTimeStep
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition:
nstime.h:391
Generated on Wed Nov 7 2018 10:01:48 for ns-3 by
1.8.14