A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
three-gpp-http-client.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Magister Solutions
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Budiarto Herman <budiarto.herman@magister.fi>
7 *
8 */
9
11
13
14#include "ns3/address-utils.h"
15#include "ns3/callback.h"
16#include "ns3/double.h"
17#include "ns3/log.h"
18#include "ns3/packet.h"
19#include "ns3/pointer.h"
20#include "ns3/simulator.h"
21#include "ns3/socket.h"
22#include "ns3/tcp-socket-factory.h"
23#include "ns3/uinteger.h"
24
25NS_LOG_COMPONENT_DEFINE("ThreeGppHttpClient");
26
27namespace ns3
28{
29
30NS_OBJECT_ENSURE_REGISTERED(ThreeGppHttpClient);
31
33 : m_state{NOT_STARTED},
34 m_socket{nullptr},
35 m_objectBytesToBeReceived{0},
36 m_objectClientTs{},
37 m_objectServerTs{},
38 m_embeddedObjectsToBeRequested{0},
39 m_pageLoadStartTs{},
40 m_numberEmbeddedObjectsRequested{0},
41 m_numberBytesPage{0},
42 m_httpVariables{CreateObject<ThreeGppHttpVariables>()},
43 m_peerPort{}
44{
45 NS_LOG_FUNCTION(this);
46}
47
48// static
51{
52 static TypeId tid =
53 TypeId("ns3::ThreeGppHttpClient")
55 .AddConstructor<ThreeGppHttpClient>()
56 .AddAttribute(
57 "Variables",
58 "Variable collection, which is used to control e.g. timing and HTTP request size.",
62 // NS_DEPRECATED_3_44
63 .AddAttribute("RemoteServerAddress",
64 "The address of the destination server.",
69 "Replaced by Remote in ns-3.44.")
70 // NS_DEPRECATED_3_44
71 .AddAttribute("RemoteServerPort",
72 "The destination port of the outbound packets.",
73 UintegerValue(80), // the default HTTP port
77 "Replaced by Remote in ns-3.44.")
78 .AddTraceSource("RxPage",
79 "A page has been received.",
81 "ns3::ThreeGppHttpClient::RxPageTracedCallback")
82 .AddTraceSource(
83 "ConnectionEstablished",
84 "Connection to the destination web server has been established.",
86 "ns3::ThreeGppHttpClient::TracedCallback")
87 .AddTraceSource("ConnectionClosed",
88 "Connection to the destination web server is closed.",
90 "ns3::ThreeGppHttpClient::TracedCallback")
91 .AddTraceSource("Tx",
92 "General trace for sending a packet of any kind.",
94 "ns3::Packet::TracedCallback")
95 .AddTraceSource(
96 "TxMainObjectRequest",
97 "Sent a request for a main object.",
99 "ns3::Packet::TracedCallback")
100 .AddTraceSource(
101 "TxEmbeddedObjectRequest",
102 "Sent a request for an embedded object.",
104 "ns3::Packet::TracedCallback")
105 .AddTraceSource("RxMainObjectPacket",
106 "A packet of main object has been received.",
108 "ns3::Packet::TracedCallback")
109 .AddTraceSource("RxMainObject",
110 "Received a whole main object. Header is included.",
112 "ns3::ThreeGppHttpClient::TracedCallback")
113 .AddTraceSource(
114 "RxEmbeddedObjectPacket",
115 "A packet of embedded object has been received.",
117 "ns3::Packet::TracedCallback")
118 .AddTraceSource("RxEmbeddedObject",
119 "Received a whole embedded object. Header is included.",
121 "ns3::ThreeGppHttpClient::TracedCallback")
122 .AddTraceSource("Rx",
123 "General trace for receiving a packet of any kind.",
125 "ns3::Packet::PacketAddressTracedCallback")
126 .AddTraceSource("RxDelay",
127 "General trace of delay for receiving a complete object.",
129 "ns3::Application::DelayAddressCallback")
130 .AddTraceSource(
131 "RxRtt",
132 "General trace of round trip delay time for receiving a complete object.",
134 "ns3::Application::DelayAddressCallback")
135 .AddTraceSource("StateTransition",
136 "Trace fired upon every HTTP client state transition.",
138 "ns3::Application::StateTransitionCallback");
139 return tid;
140}
141
142void
144{
145 NS_LOG_FUNCTION(this << addr);
146 if (!addr.IsInvalid())
147 {
148 m_peer = addr;
149 if (m_peerPort)
150 {
152 }
153 }
154}
155
156void
158{
159 NS_LOG_FUNCTION(this << port);
160 if (m_peer.IsInvalid())
161 {
162 // save for later
164 return;
165 }
167 {
169 }
170}
171
174{
175 return m_socket;
176}
177
180{
181 return m_state;
182}
183
184std::string
189
190// static
191std::string
193{
194 switch (state)
195 {
196 case NOT_STARTED:
197 return "NOT_STARTED";
198 case CONNECTING:
199 return "CONNECTING";
201 return "EXPECTING_MAIN_OBJECT";
203 return "PARSING_MAIN_OBJECT";
205 return "EXPECTING_EMBEDDED_OBJECT";
206 case READING:
207 return "READING";
208 case STOPPED:
209 return "STOPPED";
210 default:
211 NS_FATAL_ERROR("Unknown state");
212 return "FATAL_ERROR";
213 }
214}
215
216void
218{
219 NS_LOG_FUNCTION(this);
220
222 {
224 }
225
226 Application::DoDispose(); // Chain up.
227}
228
229void
231{
232 NS_LOG_FUNCTION(this);
233
234 if (m_state == NOT_STARTED)
235 {
236 m_httpVariables->Initialize();
238 }
239 else
240 {
241 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for StartApplication().");
242 }
243}
244
245void
257
258void
260{
261 NS_LOG_FUNCTION(this << socket);
262
263 if (m_state != CONNECTING)
264 {
265 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ConnectionSucceeded().");
266 }
267
268 NS_ASSERT_MSG(m_socket == socket, "Invalid socket.");
270 socket->SetRecvCallback(MakeCallback(&ThreeGppHttpClient::ReceivedDataCallback, this));
273}
274
275void
277{
278 NS_LOG_FUNCTION(this << socket);
279
280 if (m_state == CONNECTING)
281 {
282 NS_LOG_ERROR("Client failed to connect to remote address " << m_peer);
283 }
284 else
285 {
286 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ConnectionFailed().");
287 }
288}
289
290void
292{
293 NS_LOG_FUNCTION(this << socket);
294
296
297 if (socket->GetErrno() != Socket::ERROR_NOTERROR)
298 {
299 NS_LOG_ERROR(this << " Connection has been terminated,"
300 << " error code: " << socket->GetErrno() << ".");
301 }
302
305
307}
308
309void
311{
312 NS_LOG_FUNCTION(this << socket);
313
315 if (socket->GetErrno() != Socket::ERROR_NOTERROR)
316 {
317 NS_LOG_ERROR(this << " Connection has been terminated,"
318 << " error code: " << socket->GetErrno() << ".");
319 }
320
322}
323
324void
326{
327 NS_LOG_FUNCTION(this << socket);
328
329 Address from;
330 while (auto packet = socket->RecvFrom(from))
331 {
332 if (packet->GetSize() == 0)
333 {
334 break; // EOF
335 }
336
337#ifdef NS3_LOG_ENABLE
338 // Some log messages.
340 {
341 NS_LOG_INFO(this << " A packet of " << packet->GetSize() << " bytes"
342 << " received from " << InetSocketAddress::ConvertFrom(from).GetIpv4()
343 << " port " << InetSocketAddress::ConvertFrom(from).GetPort() << " / "
344 << InetSocketAddress::ConvertFrom(from) << ".");
345 }
347 {
348 NS_LOG_INFO(this << " A packet of " << packet->GetSize() << " bytes"
349 << " received from " << Inet6SocketAddress::ConvertFrom(from).GetIpv6()
350 << " port " << Inet6SocketAddress::ConvertFrom(from).GetPort() << " / "
351 << Inet6SocketAddress::ConvertFrom(from) << ".");
352 }
353#endif /* NS3_LOG_ENABLE */
354
355 m_rxTrace(packet, from);
356
357 switch (m_state)
358 {
360 ReceiveMainObject(packet, from);
361 break;
363 ReceiveEmbeddedObject(packet, from);
364 break;
365 default:
366 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceivedData().");
367 break;
368 }
369 }
370}
371
372void
374{
375 NS_LOG_FUNCTION(this);
376
379 {
380 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for OpenConnection().");
381 }
382
384 NS_ABORT_MSG_IF(m_peer.IsInvalid(), "Remote address not properly set");
385 if (!m_local.IsInvalid())
386 {
391 "Incompatible peer and local address IP version");
392 }
394 {
395 const auto ret [[maybe_unused]] =
397 NS_LOG_DEBUG(this << " Bind() return value= " << ret
398 << " GetErrNo= " << m_socket->GetErrno() << ".");
399
400 const auto ipv4 = InetSocketAddress::ConvertFrom(m_peer).GetIpv4();
402 NS_LOG_INFO(this << " Connecting to " << ipv4 << " port " << port << " / " << m_peer
403 << ".");
405 }
407 {
408 const auto ret [[maybe_unused]] =
410 NS_LOG_DEBUG(this << " Bind6() return value= " << ret
411 << " GetErrNo= " << m_socket->GetErrno() << ".");
412
415 NS_LOG_INFO(this << " Connecting to " << ipv6 << " port " << port << " / " << m_peer
416 << ".");
417 }
418 else
419 {
420 NS_ASSERT_MSG(false, "Incompatible address type: " << m_peer);
421 }
422
423 const auto ret [[maybe_unused]] = m_socket->Connect(m_peer);
424 NS_LOG_DEBUG(this << " Connect() return value= " << ret << " GetErrNo= " << m_socket->GetErrno()
425 << ".");
426
427 NS_ASSERT_MSG(m_socket, "Failed creating socket.");
428
430
437 m_socket->SetAttribute("MaxSegLifetime", DoubleValue(0.02)); // 20 ms.
438}
439
440void
442{
443 NS_LOG_FUNCTION(this);
444
445 if (m_state != CONNECTING && m_state != READING)
446 {
447 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for RequestMainObject().");
448 }
449
450 ThreeGppHttpHeader header;
451 header.SetContentLength(0); // Request does not need any content length.
453 header.SetClientTs(Simulator::Now());
454
455 const auto requestSize = m_httpVariables->GetRequestSize();
456 auto packet = Create<Packet>(requestSize);
457 packet->AddHeader(header);
458 const auto packetSize = packet->GetSize();
460 m_txTrace(packet);
461 const auto actualBytes = m_socket->Send(packet);
462 NS_LOG_DEBUG(this << " Send() packet " << packet << " of " << packet->GetSize() << " bytes,"
463 << " return value= " << actualBytes << ".");
464 if (actualBytes != static_cast<int>(packetSize))
465 {
466 NS_LOG_ERROR(this << " Failed to send request for embedded object,"
467 << " GetErrNo= " << m_socket->GetErrno() << ","
468 << " waiting for another Tx opportunity.");
469 }
470 else
471 {
473 m_pageLoadStartTs = Simulator::Now(); // start counting page loading time
474 }
475}
476
477void
479{
480 NS_LOG_FUNCTION(this);
481
484 {
485 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for RequestEmbeddedObject().");
486 }
487
489 {
490 NS_LOG_WARN(this << " No embedded object to be requested.");
491 return;
492 }
493
494 ThreeGppHttpHeader header;
495 header.SetContentLength(0); // Request does not need any content length.
497 header.SetClientTs(Simulator::Now());
498
499 const auto requestSize = m_httpVariables->GetRequestSize();
500 auto packet = Create<Packet>(requestSize);
501 packet->AddHeader(header);
502 const auto packetSize = packet->GetSize();
504 m_txTrace(packet);
505 const auto actualBytes = m_socket->Send(packet);
506 NS_LOG_DEBUG(this << " Send() packet " << packet << " of " << packet->GetSize() << " bytes,"
507 << " return value= " << actualBytes << ".");
508
509 if (actualBytes != static_cast<int>(packetSize))
510 {
511 NS_LOG_ERROR(this << " Failed to send request for embedded object,"
512 << " GetErrNo= " << m_socket->GetErrno() << ","
513 << " waiting for another Tx opportunity.");
514 }
515 else
516 {
519 }
520}
521
522void
524{
525 NS_LOG_FUNCTION(this << packet << from);
526
528 {
529 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceiveMainObject().");
530 }
531
532 /*
533 * In the following call to Receive(), #m_objectBytesToBeReceived *will*
534 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
535 * ThreeGppHttpHeader will be removed from the packet, if it is the first
536 * packet of the object to be received; the header will be available in
537 * #m_constructedPacketHeader.
538 * #m_constructedPacket will also be updated.
539 */
540 Receive(packet);
542
544 {
545 /*
546 * There are more packets of this main object, so just stay still
547 * and wait until they arrive.
548 */
549 NS_LOG_INFO(this << " " << m_objectBytesToBeReceived << " byte(s)"
550 << " remains from this chunk of main object.");
551 return;
552 }
553
554 /*
555 * This is the last packet of this main object. Acknowledge the
556 * reception of a whole main object
557 */
558 NS_LOG_INFO(this << " Finished receiving a main object.");
560
562 {
564 m_objectServerTs = MilliSeconds(0); // Reset back to zero.
565 }
566
568 {
570 m_objectClientTs = MilliSeconds(0); // Reset back to zero.
571 }
572
574}
575
576void
578{
579 NS_LOG_FUNCTION(this << packet << from);
580
582 {
583 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceiveEmbeddedObject().");
584 }
585
586 /*
587 * In the following call to Receive(), #m_objectBytesToBeReceived *will*
588 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
589 * ThreeGppHttpHeader will be removed from the packet, if it is the first
590 * packet of the object to be received; the header will be available in
591 * #m_constructedPacket, which will also be updated.
592 */
593 Receive(packet);
595
597 {
598 /*
599 * There are more packets of this embedded object, so just stay
600 * still and wait until they arrive.
601 */
602 NS_LOG_INFO(this << " " << m_objectBytesToBeReceived << " byte(s)"
603 << " remains from this chunk of embedded object");
604 return;
605 }
606
607 /*
608 * This is the last packet of this embedded object. Acknowledge
609 * the reception of a whole embedded object
610 */
611 NS_LOG_INFO(this << " Finished receiving an embedded object.");
613
615 {
617 m_objectServerTs = MilliSeconds(0); // Reset back to zero.
618 }
619
621 {
623 m_objectClientTs = MilliSeconds(0); // Reset back to zero.
624 }
625
627 {
629 << " more embedded object(s) to be requested.");
630 // Immediately request another using the existing connection.
633 }
634 else
635 {
636 /*
637 * There is no more embedded object, the web page has been
638 * downloaded completely. Now is the time to read it.
639 */
640 NS_LOG_INFO(this << " Finished receiving a web page.");
641 FinishReceivingPage(); // trigger callback for page loading time
643 }
644}
645
646void
648{
649 NS_LOG_FUNCTION(this << packet);
650
651 /* In a "real" HTTP message the message size is coded differently. The use of a header
652 * is to avoid the burden of doing a real message parser.
653 */
654 bool firstPacket = false;
655
657 {
658 // This is the first packet of the object.
659 firstPacket = true;
660
661 // Remove the header in order to calculate remaining data to be received.
662 ThreeGppHttpHeader httpHeader;
663 packet->RemoveHeader(httpHeader);
664
666 m_objectClientTs = httpHeader.GetClientTs();
667 m_objectServerTs = httpHeader.GetServerTs();
668
669 // Take a copy for constructed packet trace. Note that header is included.
670 m_constructedPacket = packet->Copy();
671 m_constructedPacket->AddHeader(httpHeader);
672 }
673 auto contentSize = packet->GetSize();
674 m_numberBytesPage += contentSize; // increment counter of page size
675
676 /* Note that the packet does not contain header at this point.
677 * The content is purely raw data, which was the only intended data to be received.
678 */
679 if (m_objectBytesToBeReceived < contentSize)
680 {
681 NS_LOG_WARN(this << " The received packet (" << contentSize << " bytes of content)"
682 << " is larger than the content that we expected to receive ("
683 << m_objectBytesToBeReceived << " bytes).");
684 // Stop expecting any more packet of this object.
686 m_constructedPacket = nullptr;
687 }
688 else
689 {
690 m_objectBytesToBeReceived -= contentSize;
691 if (!firstPacket)
692 {
693 auto packetCopy = packet->Copy();
694 m_constructedPacket->AddAtEnd(packetCopy);
695 }
696 }
697}
698
699void
701{
702 NS_LOG_FUNCTION(this);
703
705 {
706 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for EnterParsingTime().");
707 }
708
709 const auto parsingTime = m_httpVariables->GetParsingTime();
710 NS_LOG_INFO(this << " The parsing of this main object will complete in "
711 << parsingTime.As(Time::S) << ".");
715}
716
717void
719{
720 NS_LOG_FUNCTION(this);
721
723 {
724 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ParseMainObject().");
725 }
726
727 m_embeddedObjectsToBeRequested = m_httpVariables->GetNumOfEmbeddedObjects();
728 // saving total number of embedded objects
730 NS_LOG_INFO(this << " Parsing has determined " << m_embeddedObjectsToBeRequested
731 << " embedded object(s) in the main object.");
732
734 {
735 /*
736 * Immediately request the first embedded object using the
737 * existing connection.
738 */
741 }
742 else
743 {
744 /*
745 * There is no embedded object in the main object. So sit back and
746 * enjoy the plain web page.
747 */
748 NS_LOG_INFO(this << " Finished receiving a web page.");
749 FinishReceivingPage(); // trigger callback for page loading time
751 }
752}
753
754void
756{
757 NS_LOG_FUNCTION(this);
758
760 {
761 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for EnterReadingTime().");
762 }
763
764 const auto readingTime = m_httpVariables->GetReadingTime();
765 NS_LOG_INFO(this << " Client will finish reading this web page in " << readingTime.As(Time::S)
766 << ".");
767
768 // Schedule a request of another main object once the reading time expires.
772}
773
774void
776{
777 NS_LOG_FUNCTION(this);
778
780 {
781 NS_LOG_INFO(this << " Canceling RequestMainObject() which is due in "
784 }
785
787 {
788 NS_LOG_INFO(this << " Canceling RequestEmbeddedObject() which is due in "
790 << ".");
792 }
793
795 {
796 NS_LOG_INFO(this << " Canceling ParseMainObject() which is due in "
799 }
800}
801
802void
804{
805 const auto oldState = GetStateString();
806 const auto newState = GetStateString(state);
807 NS_LOG_FUNCTION(this << oldState << newState);
808
809 if ((state == EXPECTING_MAIN_OBJECT) || (state == EXPECTING_EMBEDDED_OBJECT))
810 {
812 {
813 NS_FATAL_ERROR("Cannot start a new receiving session if the previous object ("
815 << " bytes) is not completely received yet.");
816 }
817 }
818
819 m_state = state;
820 NS_LOG_INFO(this << " HttpClient " << oldState << " --> " << newState << ".");
821 m_stateTransitionTrace(oldState, newState);
822}
823
824void
835
836} // namespace ns3
a polymophic address class
Definition address.h:90
bool IsInvalid() const
Definition address.cc:60
AttributeValue implementation for Address.
Definition address.h:275
void DoDispose() override
Destructor implementation.
Ptr< Node > GetNode() const
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
uint16_t GetPort() const
Get the port.
static bool IsMatchingType(const Address &addr)
If the address match.
Ipv6Address GetIpv6() const
Get the IPv6 address.
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
static bool IsMatchingType(const Address &address)
static bool IsMatchingType(const Address &address)
If the Address matches the type.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition packet.cc:343
void AddHeader(const Header &header)
Add header to this packet.
Definition packet.cc:257
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition simulator.cc:274
static bool IsFinished()
Check if the simulation should finish.
Definition simulator.cc:160
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static bool IsExpired(const EventId &id)
Check if an event has already run or been cancelled.
Definition simulator.cc:284
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:595
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition simulator.cc:206
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
void SetConnectCallback(Callback< void, Ptr< Socket > > connectionSucceeded, Callback< void, Ptr< Socket > > connectionFailed)
Specify callbacks to allow the caller to determine if the connection succeeds of fails.
Definition socket.cc:76
virtual Socket::SocketErrno GetErrno() const =0
Get last error number.
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
Definition socket.cc:423
virtual int Bind6()=0
Allocate a local IPv6 endpoint for this socket.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
void SetCloseCallbacks(Callback< void, Ptr< Socket > > normalClose, Callback< void, Ptr< Socket > > errorClose)
Detect socket recv() events such as graceful shutdown or error.
Definition socket.cc:85
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition socket.cc:117
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition socket.cc:61
virtual int Close()=0
Close a socket.
@ ERROR_NOTERROR
Definition socket.h:74
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Base class for source applications.
Address m_local
Local address to bind to.
uint8_t m_tos
The packets Type of Service.
Address m_peer
Peer address.
static TypeId GetTypeId()
Get the type ID.
ns3::TracedCallback< const Time &, const Address & > m_rxRttTrace
The RxRtt trace source.
Time m_pageLoadStartTs
The time stamp when the page started loading.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, const Time &, uint32_t, uint32_t > m_rxPageTrace
The RxPage trace source.
void SetPort(uint16_t port)
set the remote port (temporary function until deprecated attributes are removed)
void ReceiveMainObject(Ptr< Packet > packet, const Address &from)
Receive a packet of main object from the destination web server.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionClosedTrace
The ConnectionClosed trace source.
std::optional< uint16_t > m_peerPort
The RemoteServerPort attribute.
ns3::TracedCallback< const Time &, const Address & > m_rxDelayTrace
The RxDelay trace source.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxEmbeddedObjectTrace
The TxEmbeddedObject trace source.
Ptr< ThreeGppHttpVariables > m_httpVariables
The Variables attribute.
uint32_t m_embeddedObjectsToBeRequested
Determined after parsing the main object.
EventId m_eventParseMainObject
An event of ParseMainObject(), scheduled to trigger after parsing time has elapsed.
void SwitchToState(State_t state)
Change the state of the client.
uint32_t m_numberEmbeddedObjectsRequested
Number of embedded objects to requested in the current page.
void ConnectionFailedCallback(Ptr< Socket > socket)
Invoked when m_socket cannot establish a connection with the web server.
ThreeGppHttpClient()
Creates a new instance of HTTP client application.
ns3::TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
The Rx trace source.
void EnterParsingTime()
Becomes idle for a randomly determined amount of time, and then triggers ParseMainObject().
State_t m_state
The current state of the client application. Begins with NOT_STARTED.
void FinishReceivingPage()
Finish receiving a page.
Ptr< Socket > m_socket
The socket for sending and receiving packets to/from the web server.
void RequestEmbeddedObject()
Send a request object for an embedded object to the destination web server.
void ParseMainObject()
Randomly determines the number of embedded objects in the main object.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxMainObjectTrace
The TxMainObject trace source.
State_t GetState() const
Returns the current state of the application.
void EnterReadingTime()
Becomes idle for a randomly determined amount of time, and then triggers RequestMainObject().
void DoDispose() override
Destructor implementation.
void StartApplication() override
Application specific startup code.
Ptr< Packet > m_constructedPacket
The packet constructed of one or more parts with ThreeGppHttpHeader.
uint32_t m_objectBytesToBeReceived
According to the content length specified by the ThreeGppHttpHeader.
void ConnectionSucceededCallback(Ptr< Socket > socket)
Invoked when a connection is established successfully on m_socket.
static TypeId GetTypeId()
Returns the object TypeId.
void ErrorCloseCallback(Ptr< Socket > socket)
Invoked when connection between m_socket and the web sever is terminated.
EventId m_eventRequestMainObject
An event of either RequestMainObject() or OpenConnection(), scheduled to trigger after a connection h...
uint32_t m_numberBytesPage
Number of bytes received for the current page.
void CancelAllPendingEvents()
Cancels m_eventRequestMainObject, m_eventRequestEmbeddedObject, and m_eventParseMainObject.
Ptr< Socket > GetSocket() const
Returns a pointer to the associated socket.
ns3::TracedCallback< Ptr< const Packet > > m_txTrace
The Tx trace source.
Time m_objectClientTs
The client time stamp of the ThreeGppHttpHeader from the last received packet.
State_t
The possible states of the application.
@ CONNECTING
Sent the server a connection request and waiting for the server to be accept it.
@ NOT_STARTED
Before StartApplication() is invoked.
@ READING
User reading a web page that has just been received.
@ EXPECTING_MAIN_OBJECT
Sent the server a request for a main object and waiting to receive the packets.
@ STOPPED
After StopApplication() is invoked.
@ PARSING_MAIN_OBJECT
Parsing a main object that has just been received.
@ EXPECTING_EMBEDDED_OBJECT
Sent the server a request for an embedded object and waiting to receive the packets.
ns3::TracedCallback< Ptr< const Packet > > m_txMainObjectRequestTrace
The TxMainObjectRequest trace source.
void StopApplication() override
Application specific shutdown code.
ns3::TracedCallback< Ptr< const Packet > > m_rxMainObjectPacketTrace
The TxMainObjectPacket trace source.
void SetRemote(const Address &addr) override
set the remote address
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
void RequestMainObject()
Send a request object for a main object to the destination web server.
Time m_objectServerTs
The server time stamp of the ThreeGppHttpHeader from the last received packet.
void NormalCloseCallback(Ptr< Socket > socket)
Invoked when connection between m_socket and the web sever is terminated.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionEstablishedTrace
The ConnectionEstablished trace source.
ns3::TracedCallback< Ptr< const Packet > > m_txEmbeddedObjectRequestTrace
The TxEmbeddedObjectRequest trace source.
void ReceivedDataCallback(Ptr< Socket > socket)
Invoked when m_socket receives some packet data.
ns3::TracedCallback< Ptr< const Packet > > m_rxEmbeddedObjectPacketTrace
The TxEmbeddedObjectPacket trace source.
void Receive(Ptr< Packet > packet)
Simulate a consumption of the received packet by subtracting the packet size from the internal counte...
void ReceiveEmbeddedObject(Ptr< Packet > packet, const Address &from)
Receive a packet of embedded object from the destination web server.
void OpenConnection()
Initialize m_socket to connect to the destination web server at m_peer and m_peerPort and set up call...
std::string GetStateString() const
Returns the current state of the application in string format.
EventId m_eventRequestEmbeddedObject
An event of either RequestEmbeddedObject() or OpenConnection().
Header used by web browsing applications to transmit information about content type,...
void SetContentLength(uint32_t contentLength)
void SetContentType(ContentType_t contentType)
@ EMBEDDED_OBJECT
Integer equivalent = 2.
@ MAIN_OBJECT
Integer equivalent = 1.
Container of various random variables to assist in generating web browsing traffic pattern.
@ S
second
Definition nstime.h:105
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:304
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
@ DEPRECATED
Attribute or trace source is deprecated; user is warned.
Hold an unsigned integer type.
Definition uinteger.h:34
uint16_t port
Definition dsdv-manet.cc:33
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
Ptr< const AttributeChecker > MakeAddressChecker()
Definition address.cc:169
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition address.h:275
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition pointer.h:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition uinteger.h:35
Callback< R, Args... > MakeNullCallback()
Definition callback.h:727
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1357
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Address ConvertToSocketAddress(const Address &address, uint16_t port)
Convert IPv4/IPv6 address with port to a socket address.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
static const uint32_t packetSize
Packet size generated at the AP.