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
23
29
30// static
33{
34 static TypeId tid =
35 TypeId("ns3::ThreeGppHttpHeader").SetParent<Header>().AddConstructor<ThreeGppHttpHeader>();
36 return tid;
37}
38
44
47{
48 return 2 + 4 + 8 + 8;
49}
50
51void
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
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
86void
87ThreeGppHttpHeader::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
95std::string
97{
98 NS_LOG_FUNCTION(this);
99 std::ostringstream oss;
100 Print(oss);
101 return oss.str();
102}
103
104void
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
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
147void
149{
150 NS_LOG_FUNCTION(this << contentLength);
151 m_contentLength = contentLength;
152}
153
159
160void
162{
163 NS_LOG_FUNCTION(this << clientTs.As(Time::S));
164 m_clientTs = clientTs.GetTimeStep();
165}
166
167Time
172
173void
175{
176 NS_LOG_FUNCTION(this << serverTs.As(Time::S));
177 m_serverTs = serverTs.GetTimeStep();
178}
179
180Time
185
186} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:33
Header used by web browsing applications to transmit information about content type,...
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:96
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
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition nstime.h:1451
@ S
second
Definition nstime.h:107
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:436
a unique identifier for an interface.
Definition type-id.h:49
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.