A Discrete-Event Network Simulator
API
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>
26
27NS_LOG_COMPONENT_DEFINE ("ThreeGppHttpHeader");
28
29namespace ns3 {
30
31NS_OBJECT_ENSURE_REGISTERED (ThreeGppHttpHeader);
32
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
47{
48 static TypeId tid = TypeId ("ns3::ThreeGppHttpHeader")
49 .SetParent<Header> ()
50 .AddConstructor<ThreeGppHttpHeader> ()
51 ;
52 return tid;
53}
54
55
58{
59 return GetTypeId ();
60}
61
62
65{
66 return 2 + 4 + 8 + 8;
67}
68
69
70void
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
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
107void
108ThreeGppHttpHeader::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).As (Time::S)
114 << " Server TS: " << TimeStep (m_serverTs).As (Time::S) << ")";
115}
116
117
118std::string
120{
121 NS_LOG_FUNCTION (this);
122 std::ostringstream oss;
123 Print (oss);
124 return oss.str ();
125}
126
127
128void
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
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
173void
175{
176 NS_LOG_FUNCTION (this << contentLength);
177 m_contentLength = contentLength;
178}
179
180
183{
184 return m_contentLength;
185}
186
187
188void
190{
191 NS_LOG_FUNCTION (this << clientTs.As (Time::S));
192 m_clientTs = clientTs.GetTimeStep ();
193}
194
195
196Time
198{
199 return TimeStep (m_clientTs);
200}
201
202
203void
205{
206 NS_LOG_FUNCTION (this << serverTs.As (Time::S));
207 m_serverTs = serverTs.GetTimeStep ();
208}
209
210
211Time
213{
214 return TimeStep (m_serverTs);
215}
216
217
218} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
Protocol header serialization and deserialization.
Definition: header.h:43
void SetClientTs(Time clientTs)
void SetServerTs(Time serverTs)
virtual uint32_t Deserialize(Buffer::Iterator start)
virtual void Serialize(Buffer::Iterator start) const
void SetContentLength(uint32_t contentLength)
void SetContentType(ContentType_t contentType)
ContentType_t
The possible types of content (default = NOT_SET).
@ NOT_SET
Integer equivalent = 0.
@ EMBEDDED_OBJECT
Integer equivalent = 2.
@ MAIN_OBJECT
Integer equivalent = 1.
ThreeGppHttpHeader()
Creates an empty instance .
virtual uint32_t GetSerializedSize() const
uint64_t m_clientTs
" Client time stamp field (in time step unit).
uint32_t m_contentLength
" Content length field (in bytes unit).
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
virtual void Print(std::ostream &os) const
uint64_t m_serverTs
" Server time stamp field (in time step unit).
ContentType_t GetContentType() const
uint16_t m_contentType
" Content type field in integer format.
static TypeId GetTypeId()
Returns the object TypeId.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:415
@ S
second
Definition: nstime.h:114
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:432
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1853