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
{
27
NS_LOG_FUNCTION
(
this
);
28
}
29
30
// static
31
TypeId
32
ThreeGppHttpHeader::GetTypeId
()
33
{
34
static
TypeId
tid =
35
TypeId
(
"ns3::ThreeGppHttpHeader"
).
SetParent
<
Header
>().AddConstructor<ThreeGppHttpHeader>();
36
return
tid;
37
}
38
39
TypeId
40
ThreeGppHttpHeader::GetInstanceTypeId
()
const
41
{
42
return
GetTypeId
();
43
}
44
45
uint32_t
46
ThreeGppHttpHeader::GetSerializedSize
()
const
47
{
48
return
2 + 4 + 8 + 8;
49
}
50
51
void
52
ThreeGppHttpHeader::Serialize
(
Buffer::Iterator
start)
const
53
{
54
NS_LOG_FUNCTION
(
this
<< &start);
55
start.WriteU16(
m_contentType
);
56
start.WriteU32(
m_contentLength
);
57
start.WriteU64(
m_clientTs
);
58
start.WriteU64(
m_serverTs
);
59
}
60
61
uint32_t
62
ThreeGppHttpHeader::Deserialize
(
Buffer::Iterator
start)
63
{
64
NS_LOG_FUNCTION
(
this
<< &start);
65
uint32_t
bytesRead = 0;
66
67
// First block of 2 bytes (content type)
68
m_contentType
= start.ReadU16();
69
bytesRead += 2;
70
71
// Second block of 4 bytes (content length)
72
m_contentLength
= start.ReadU32();
73
bytesRead += 4;
74
75
// Third block of 8 bytes (client time stamp)
76
m_clientTs
= start.ReadU64();
77
bytesRead += 8;
78
79
// Fourth block of 8 bytes (server time stamp)
80
m_serverTs
= start.ReadU64();
81
bytesRead += 8;
82
83
return
bytesRead;
84
}
85
86
void
87
ThreeGppHttpHeader::Print
(std::ostream& os)
const
88
{
89
NS_LOG_FUNCTION
(
this
<< &os);
90
os <<
"(Content-Type: "
<<
m_contentType
<<
" Content-Length: "
<<
m_contentLength
91
<<
" Client TS: "
<<
TimeStep
(
m_clientTs
).
As
(
Time::S
)
92
<<
" Server TS: "
<<
TimeStep
(
m_serverTs
).
As
(
Time::S
) <<
")"
;
93
}
94
95
std::string
96
ThreeGppHttpHeader::ToString
()
const
97
{
98
NS_LOG_FUNCTION
(
this
);
99
std::ostringstream oss;
100
Print
(oss);
101
return
oss.str();
102
}
103
104
void
105
ThreeGppHttpHeader::SetContentType
(
ThreeGppHttpHeader::ContentType_t
contentType)
106
{
107
NS_LOG_FUNCTION
(
this
<<
static_cast<
uint16_t
>
(contentType));
108
switch
(contentType)
109
{
110
case
NOT_SET
:
111
m_contentType
= 0;
112
break
;
113
case
MAIN_OBJECT
:
114
m_contentType
= 1;
115
break
;
116
case
EMBEDDED_OBJECT
:
117
m_contentType
= 2;
118
break
;
119
default
:
120
NS_FATAL_ERROR
(
"Unknown Content-Type: "
<< contentType);
121
break
;
122
}
123
}
124
125
ThreeGppHttpHeader::ContentType_t
126
ThreeGppHttpHeader::GetContentType
()
const
127
{
128
ContentType_t
ret;
129
switch
(
m_contentType
)
130
{
131
case
0:
132
ret =
NOT_SET
;
133
break
;
134
case
1:
135
ret =
MAIN_OBJECT
;
136
break
;
137
case
2:
138
ret =
EMBEDDED_OBJECT
;
139
break
;
140
default
:
141
NS_FATAL_ERROR
(
"Unknown Content-Type: "
<<
m_contentType
);
142
break
;
143
}
144
return
ret;
145
}
146
147
void
148
ThreeGppHttpHeader::SetContentLength
(
uint32_t
contentLength)
149
{
150
NS_LOG_FUNCTION
(
this
<< contentLength);
151
m_contentLength
= contentLength;
152
}
153
154
uint32_t
155
ThreeGppHttpHeader::GetContentLength
()
const
156
{
157
return
m_contentLength
;
158
}
159
160
void
161
ThreeGppHttpHeader::SetClientTs
(
Time
clientTs)
162
{
163
NS_LOG_FUNCTION
(
this
<< clientTs.
As
(
Time::S
));
164
m_clientTs
= clientTs.
GetTimeStep
();
165
}
166
167
Time
168
ThreeGppHttpHeader::GetClientTs
()
const
169
{
170
return
TimeStep
(
m_clientTs
);
171
}
172
173
void
174
ThreeGppHttpHeader::SetServerTs
(
Time
serverTs)
175
{
176
NS_LOG_FUNCTION
(
this
<< serverTs.
As
(
Time::S
));
177
m_serverTs
= serverTs.
GetTimeStep
();
178
}
179
180
Time
181
ThreeGppHttpHeader::GetServerTs
()
const
182
{
183
return
TimeStep
(
m_serverTs
);
184
}
185
186
}
// 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
Header used by web browsing applications to transmit information about content type,...
Definition
three-gpp-http-header.h:44
ns3::ThreeGppHttpHeader::SetClientTs
void SetClientTs(Time clientTs)
Definition
three-gpp-http-header.cc:161
ns3::ThreeGppHttpHeader::ToString
std::string ToString() const
Definition
three-gpp-http-header.cc:96
ns3::ThreeGppHttpHeader::SetServerTs
void SetServerTs(Time serverTs)
Definition
three-gpp-http-header.cc:174
ns3::ThreeGppHttpHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
three-gpp-http-header.cc:46
ns3::ThreeGppHttpHeader::GetClientTs
Time GetClientTs() const
Definition
three-gpp-http-header.cc:168
ns3::ThreeGppHttpHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
three-gpp-http-header.cc:62
ns3::ThreeGppHttpHeader::SetContentLength
void SetContentLength(uint32_t contentLength)
Definition
three-gpp-http-header.cc:148
ns3::ThreeGppHttpHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
three-gpp-http-header.cc:52
ns3::ThreeGppHttpHeader::SetContentType
void SetContentType(ContentType_t contentType)
Definition
three-gpp-http-header.cc:105
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:87
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:126
ns3::ThreeGppHttpHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
three-gpp-http-header.cc:40
ns3::ThreeGppHttpHeader::GetServerTs
Time GetServerTs() const
Definition
three-gpp-http-header.cc:181
ns3::ThreeGppHttpHeader::GetContentLength
uint32_t GetContentLength() const
Definition
three-gpp-http-header.cc:155
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:32
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:96
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:409
ns3::Time::TimeStep
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition
nstime.h:1451
ns3::Time::S
@ S
second
Definition
nstime.h:107
ns3::Time::GetTimeStep
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition
nstime.h:436
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:49
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:186
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:231
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
for ns-3 by
1.15.0