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