A Discrete-Event Network Simulator
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
11
12#include <ns3/log.h>
13#include <ns3/packet.h>
14
15#include <sstream>
16
17NS_LOG_COMPONENT_DEFINE("ThreeGppHttpHeader");
18
19namespace ns3
20{
21
22NS_OBJECT_ENSURE_REGISTERED(ThreeGppHttpHeader);
23
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
37{
38 static TypeId tid =
39 TypeId("ns3::ThreeGppHttpHeader").SetParent<Header>().AddConstructor<ThreeGppHttpHeader>();
40 return tid;
41}
42
48
51{
52 return 2 + 4 + 8 + 8;
53}
54
55void
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
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
90void
91ThreeGppHttpHeader::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
99std::string
101{
102 NS_LOG_FUNCTION(this);
103 std::ostringstream oss;
104 Print(oss);
105 return oss.str();
106}
107
108void
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
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
151void
153{
154 NS_LOG_FUNCTION(this << contentLength);
155 m_contentLength = contentLength;
156}
157
163
164void
166{
167 NS_LOG_FUNCTION(this << clientTs.As(Time::S));
168 m_clientTs = clientTs.GetTimeStep();
169}
170
171Time
173{
174 return TimeStep(m_clientTs);
175}
176
177void
179{
180 NS_LOG_FUNCTION(this << serverTs.As(Time::S));
181 m_serverTs = serverTs.GetTimeStep();
182}
183
184Time
186{
187 return TimeStep(m_serverTs);
188}
189
190} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:33
uint32_t GetSerializedSize() const override
uint32_t Deserialize(Buffer::Iterator start) override
void SetContentLength(uint32_t contentLength)
void Serialize(Buffer::Iterator start) const override
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.
uint64_t m_clientTs
" Client time stamp field (in time step unit).
uint32_t m_contentLength
" Content length field (in bytes unit).
void Print(std::ostream &os) const override
uint64_t m_serverTs
" Server time stamp field (in time step unit).
ContentType_t GetContentType() const
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
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:94
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
@ S
second
Definition nstime.h:105
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:434
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.