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/callback.h>
15#include <ns3/double.h>
16#include <ns3/inet-socket-address.h>
17#include <ns3/inet6-socket-address.h>
18#include <ns3/log.h>
19#include <ns3/packet.h>
20#include <ns3/pointer.h>
21#include <ns3/simulator.h>
22#include <ns3/socket.h>
23#include <ns3/tcp-socket-factory.h>
24#include <ns3/uinteger.h>
25
26NS_LOG_COMPONENT_DEFINE("ThreeGppHttpClient");
27
28namespace ns3
29{
30
31NS_OBJECT_ENSURE_REGISTERED(ThreeGppHttpClient);
32
34 : m_state(NOT_STARTED),
35 m_socket(nullptr),
36 m_objectBytesToBeReceived(0),
37 m_objectClientTs(MilliSeconds(0)),
38 m_objectServerTs(MilliSeconds(0)),
39 m_embeddedObjectsToBeRequested(0),
40 m_pageLoadStartTs(MilliSeconds(0)),
41 m_numberEmbeddedObjectsRequested(0),
42 m_numberBytesPage(0),
43 m_httpVariables(CreateObject<ThreeGppHttpVariables>())
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 .AddAttribute("RemoteServerAddress",
63 "The address of the destination server.",
67 .AddAttribute("RemoteServerPort",
68 "The destination port of the outbound packets.",
69 UintegerValue(80), // the default HTTP port
72 .AddAttribute("Tos",
73 "The Type of Service used to send packets. "
74 "All 8 bits of the TOS byte are set (including ECN bits).",
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
144{
145 return m_socket;
146}
147
150{
151 return m_state;
152}
153
154std::string
159
160// static
161std::string
163{
164 switch (state)
165 {
166 case NOT_STARTED:
167 return "NOT_STARTED";
168 case CONNECTING:
169 return "CONNECTING";
171 return "EXPECTING_MAIN_OBJECT";
173 return "PARSING_MAIN_OBJECT";
175 return "EXPECTING_EMBEDDED_OBJECT";
176 case READING:
177 return "READING";
178 case STOPPED:
179 return "STOPPED";
180 default:
181 NS_FATAL_ERROR("Unknown state");
182 return "FATAL_ERROR";
183 }
184}
185
186void
188{
189 NS_LOG_FUNCTION(this);
190
192 {
194 }
195
196 Application::DoDispose(); // Chain up.
197}
198
199void
201{
202 NS_LOG_FUNCTION(this);
203
204 if (m_state == NOT_STARTED)
205 {
206 m_httpVariables->Initialize();
208 }
209 else
210 {
211 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for StartApplication().");
212 }
213}
214
215void
227
228void
230{
231 NS_LOG_FUNCTION(this << socket);
232
233 if (m_state == CONNECTING)
234 {
235 NS_ASSERT_MSG(m_socket == socket, "Invalid socket.");
237 socket->SetRecvCallback(MakeCallback(&ThreeGppHttpClient::ReceivedDataCallback, this));
241 }
242 else
243 {
244 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ConnectionSucceeded().");
245 }
246}
247
248void
250{
251 NS_LOG_FUNCTION(this << socket);
252
253 if (m_state == CONNECTING)
254 {
255 NS_LOG_ERROR("Client failed to connect"
256 << " to remote address " << m_remoteServerAddress << " port "
257 << m_remoteServerPort << ".");
258 }
259 else
260 {
261 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ConnectionFailed().");
262 }
263}
264
265void
267{
268 NS_LOG_FUNCTION(this << socket);
269
271
272 if (socket->GetErrno() != Socket::ERROR_NOTERROR)
273 {
274 NS_LOG_ERROR(this << " Connection has been terminated,"
275 << " error code: " << socket->GetErrno() << ".");
276 }
277
280
282}
283
284void
286{
287 NS_LOG_FUNCTION(this << socket);
288
290 if (socket->GetErrno() != Socket::ERROR_NOTERROR)
291 {
292 NS_LOG_ERROR(this << " Connection has been terminated,"
293 << " error code: " << socket->GetErrno() << ".");
294 }
295
297}
298
299void
301{
302 NS_LOG_FUNCTION(this << socket);
303
304 Ptr<Packet> packet;
305 Address from;
306
307 while ((packet = socket->RecvFrom(from)))
308 {
309 if (packet->GetSize() == 0)
310 {
311 break; // EOF
312 }
313
314#ifdef NS3_LOG_ENABLE
315 // Some log messages.
317 {
318 NS_LOG_INFO(this << " A packet of " << packet->GetSize() << " bytes"
319 << " received from " << InetSocketAddress::ConvertFrom(from).GetIpv4()
320 << " port " << InetSocketAddress::ConvertFrom(from).GetPort() << " / "
321 << InetSocketAddress::ConvertFrom(from) << ".");
322 }
324 {
325 NS_LOG_INFO(this << " A packet of " << packet->GetSize() << " bytes"
326 << " received from " << Inet6SocketAddress::ConvertFrom(from).GetIpv6()
327 << " port " << Inet6SocketAddress::ConvertFrom(from).GetPort() << " / "
328 << Inet6SocketAddress::ConvertFrom(from) << ".");
329 }
330#endif /* NS3_LOG_ENABLE */
331
332 m_rxTrace(packet, from);
333
334 switch (m_state)
335 {
337 ReceiveMainObject(packet, from);
338 break;
340 ReceiveEmbeddedObject(packet, from);
341 break;
342 default:
343 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceivedData().");
344 break;
345 }
346
347 } // end of `while ((packet = socket->RecvFrom (from)))`
348
349} // end of `void ReceivedDataCallback (Ptr<Socket> socket)`
350
351void
353{
354 NS_LOG_FUNCTION(this);
355
358 {
361 "'RemoteServerAddress' attribute not properly set");
363 {
364 int ret [[maybe_unused]];
365
366 ret = m_socket->Bind();
367 NS_LOG_DEBUG(this << " Bind() return value= " << ret
368 << " GetErrNo= " << m_socket->GetErrno() << ".");
369
372 NS_LOG_INFO(this << " Connecting to " << ipv4 << " port " << m_remoteServerPort << " / "
373 << inetSocket << ".");
375 ret = m_socket->Connect(inetSocket);
376 NS_LOG_DEBUG(this << " Connect() return value= " << ret
377 << " GetErrNo= " << m_socket->GetErrno() << ".");
378 }
380 {
381 int ret [[maybe_unused]];
382
383 ret = m_socket->Bind6();
384 NS_LOG_DEBUG(this << " Bind6() return value= " << ret
385 << " GetErrNo= " << m_socket->GetErrno() << ".");
386
389 NS_LOG_INFO(this << " connecting to " << ipv6 << " port " << m_remoteServerPort << " / "
390 << inet6Socket << ".");
391 ret = m_socket->Connect(inet6Socket);
392 NS_LOG_DEBUG(this << " Connect() return value= " << ret
393 << " GetErrNo= " << m_socket->GetErrno() << ".");
394 }
395
396 NS_ASSERT_MSG(m_socket, "Failed creating socket.");
397
399
406 m_socket->SetAttribute("MaxSegLifetime", DoubleValue(0.02)); // 20 ms.
407
408 } // end of `if (m_state == {NOT_STARTED, EXPECTING_EMBEDDED_OBJECT, PARSING_MAIN_OBJECT,
409 // READING})`
410 else
411 {
412 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for OpenConnection().");
413 }
414
415} // end of `void OpenConnection ()`
416
417void
419{
420 NS_LOG_FUNCTION(this);
421
422 if (m_state == CONNECTING || m_state == READING)
423 {
424 ThreeGppHttpHeader header;
425 header.SetContentLength(0); // Request does not need any content length.
427 header.SetClientTs(Simulator::Now());
428
429 const uint32_t requestSize = m_httpVariables->GetRequestSize();
430 Ptr<Packet> packet = Create<Packet>(requestSize);
431 packet->AddHeader(header);
432 const uint32_t packetSize = packet->GetSize();
434 m_txTrace(packet);
435 const int actualBytes = m_socket->Send(packet);
436 NS_LOG_DEBUG(this << " Send() packet " << packet << " of " << packet->GetSize() << " bytes,"
437 << " return value= " << actualBytes << ".");
438 if (actualBytes != static_cast<int>(packetSize))
439 {
440 NS_LOG_ERROR(this << " Failed to send request for embedded object,"
441 << " GetErrNo= " << m_socket->GetErrno() << ","
442 << " waiting for another Tx opportunity.");
443 }
444 else
445 {
447 m_pageLoadStartTs = Simulator::Now(); // start counting page loading time
448 }
449 }
450 else
451 {
452 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for RequestMainObject().");
453 }
454
455} // end of `void RequestMainObject ()`
456
457void
459{
460 NS_LOG_FUNCTION(this);
461
464 {
466 {
467 ThreeGppHttpHeader header;
468 header.SetContentLength(0); // Request does not need any content length.
470 header.SetClientTs(Simulator::Now());
471
472 const uint32_t requestSize = m_httpVariables->GetRequestSize();
473 Ptr<Packet> packet = Create<Packet>(requestSize);
474 packet->AddHeader(header);
475 const uint32_t packetSize = packet->GetSize();
477 m_txTrace(packet);
478 const int actualBytes = m_socket->Send(packet);
479 NS_LOG_DEBUG(this << " Send() packet " << packet << " of " << packet->GetSize()
480 << " bytes,"
481 << " return value= " << actualBytes << ".");
482
483 if (actualBytes != static_cast<int>(packetSize))
484 {
485 NS_LOG_ERROR(this << " Failed to send request for embedded object,"
486 << " GetErrNo= " << m_socket->GetErrno() << ","
487 << " waiting for another Tx opportunity.");
488 }
489 else
490 {
493 }
494 }
495 else
496 {
497 NS_LOG_WARN(this << " No embedded object to be requested.");
498 }
499 }
500 else
501 {
502 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for RequestEmbeddedObject().");
503 }
504
505} // end of `void RequestEmbeddedObject ()`
506
507void
509{
510 NS_LOG_FUNCTION(this << packet << from);
511
513 {
514 /*
515 * In the following call to Receive(), #m_objectBytesToBeReceived *will*
516 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
517 * ThreeGppHttpHeader will be removed from the packet, if it is the first
518 * packet of the object to be received; the header will be available in
519 * #m_constructedPacketHeader.
520 * #m_constructedPacket will also be updated.
521 */
522 Receive(packet);
524
526 {
527 /*
528 * There are more packets of this main object, so just stay still
529 * and wait until they arrive.
530 */
531 NS_LOG_INFO(this << " " << m_objectBytesToBeReceived << " byte(s)"
532 << " remains from this chunk of main object.");
533 }
534 else
535 {
536 /*
537 * This is the last packet of this main object. Acknowledge the
538 * reception of a whole main object
539 */
540 NS_LOG_INFO(this << " Finished receiving a main object.");
542
544 {
546 m_objectServerTs = MilliSeconds(0); // Reset back to zero.
547 }
548
550 {
552 m_objectClientTs = MilliSeconds(0); // Reset back to zero.
553 }
554
556
557 } // end of else of `if (m_objectBytesToBeReceived > 0)`
558
559 } // end of `if (m_state == EXPECTING_MAIN_OBJECT)`
560 else
561 {
562 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceiveMainObject().");
563 }
564
565} // end of `void ReceiveMainObject (Ptr<Packet> packet)`
566
567void
569{
570 NS_LOG_FUNCTION(this << packet << from);
571
573 {
574 /*
575 * In the following call to Receive(), #m_objectBytesToBeReceived *will*
576 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
577 * ThreeGppHttpHeader will be removed from the packet, if it is the first
578 * packet of the object to be received; the header will be available in
579 * #m_constructedPacket, which will also be updated.
580 */
581 Receive(packet);
583
585 {
586 /*
587 * There are more packets of this embedded object, so just stay
588 * still and wait until they arrive.
589 */
590 NS_LOG_INFO(this << " " << m_objectBytesToBeReceived << " byte(s)"
591 << " remains from this chunk of embedded object");
592 }
593 else
594 {
595 /*
596 * This is the last packet of this embedded object. Acknowledge
597 * the reception of a whole embedded object
598 */
599 NS_LOG_INFO(this << " Finished receiving an embedded object.");
601
603 {
605 m_objectServerTs = MilliSeconds(0); // Reset back to zero.
606 }
607
609 {
611 m_objectClientTs = MilliSeconds(0); // Reset back to zero.
612 }
613
615 {
617 << " more embedded object(s) to be requested.");
618 // Immediately request another using the existing connection.
621 }
622 else
623 {
624 /*
625 * There is no more embedded object, the web page has been
626 * downloaded completely. Now is the time to read it.
627 */
628 NS_LOG_INFO(this << " Finished receiving a web page.");
629 FinishReceivingPage(); // trigger callback for page loading time
631 }
632
633 } // end of else of `if (m_objectBytesToBeReceived > 0)`
634
635 } // end of `if (m_state == EXPECTING_EMBEDDED_OBJECT)`
636 else
637 {
638 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceiveEmbeddedObject().");
639 }
640
641} // end of `void ReceiveEmbeddedObject (Ptr<Packet> packet)`
642
643void
645{
646 NS_LOG_FUNCTION(this << packet);
647
648 /* In a "real" HTTP message the message size is coded differently. The use of a header
649 * is to avoid the burden of doing a real message parser.
650 */
651 bool firstPacket = false;
652
654 {
655 // This is the first packet of the object.
656 firstPacket = true;
657
658 // Remove the header in order to calculate remaining data to be received.
659 ThreeGppHttpHeader httpHeader;
660 packet->RemoveHeader(httpHeader);
661
663 m_objectClientTs = httpHeader.GetClientTs();
664 m_objectServerTs = httpHeader.GetServerTs();
665
666 // Take a copy for constructed packet trace. Note that header is included.
667 m_constructedPacket = packet->Copy();
668 m_constructedPacket->AddHeader(httpHeader);
669 }
670 uint32_t contentSize = packet->GetSize();
671 m_numberBytesPage += contentSize; // increment counter of page size
672
673 /* Note that the packet does not contain header at this point.
674 * The content is purely raw data, which was the only intended data to be received.
675 */
676 if (m_objectBytesToBeReceived < contentSize)
677 {
678 NS_LOG_WARN(this << " The received packet"
679 << " (" << contentSize << " bytes of content)"
680 << " is larger than"
681 << " the content that we expected to receive"
682 << " (" << m_objectBytesToBeReceived << " bytes).");
683 // Stop expecting any more packet of this object.
685 m_constructedPacket = nullptr;
686 }
687 else
688 {
689 m_objectBytesToBeReceived -= contentSize;
690 if (!firstPacket)
691 {
692 Ptr<Packet> packetCopy = packet->Copy();
693 m_constructedPacket->AddAtEnd(packetCopy);
694 }
695 }
696
697} // end of `void Receive (packet)`
698
699void
701{
702 NS_LOG_FUNCTION(this);
703
705 {
706 const Time parsingTime = m_httpVariables->GetParsingTime();
707 NS_LOG_INFO(this << " The parsing of this main object"
708 << " will complete in " << parsingTime.As(Time::S) << ".");
712 }
713 else
714 {
715 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for EnterParsingTime().");
716 }
717}
718
719void
721{
722 NS_LOG_FUNCTION(this);
723
725 {
726 m_embeddedObjectsToBeRequested = m_httpVariables->GetNumOfEmbeddedObjects();
727 // saving total number of embedded objects
729 NS_LOG_INFO(this << " Parsing has determined " << m_embeddedObjectsToBeRequested
730 << " embedded object(s) in the main object.");
731
733 {
734 /*
735 * Immediately request the first embedded object using the
736 * existing connection.
737 */
740 }
741 else
742 {
743 /*
744 * There is no embedded object in the main object. So sit back and
745 * enjoy the plain web page.
746 */
747 NS_LOG_INFO(this << " Finished receiving a web page.");
748 FinishReceivingPage(); // trigger callback for page loading time
750 }
751 }
752 else
753 {
754 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ParseMainObject().");
755 }
756
757} // end of `void ParseMainObject ()`
758
759void
761{
762 NS_LOG_FUNCTION(this);
763
765 {
766 const Time readingTime = m_httpVariables->GetReadingTime();
767 NS_LOG_INFO(this << " Client will finish reading this web page in "
768 << readingTime.As(Time::S) << ".");
769
770 // Schedule a request of another main object once the reading time expires.
774 }
775 else
776 {
777 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for EnterReadingTime().");
778 }
779}
780
781void
783{
784 NS_LOG_FUNCTION(this);
785
787 {
788 NS_LOG_INFO(this << " Canceling RequestMainObject() which is due in "
791 }
792
794 {
795 NS_LOG_INFO(this << " Canceling RequestEmbeddedObject() which is due in "
797 << ".");
799 }
800
802 {
803 NS_LOG_INFO(this << " Canceling ParseMainObject() which is due in "
806 }
807}
808
809void
811{
812 const std::string oldState = GetStateString();
813 const std::string newState = GetStateString(state);
814 NS_LOG_FUNCTION(this << oldState << newState);
815
816 if ((state == EXPECTING_MAIN_OBJECT) || (state == EXPECTING_EMBEDDED_OBJECT))
817 {
819 {
820 NS_FATAL_ERROR("Cannot start a new receiving session"
821 << " if the previous object"
822 << " (" << m_objectBytesToBeReceived << " bytes)"
823 << " is not completely received yet.");
824 }
825 }
826
827 m_state = state;
828 NS_LOG_INFO(this << " HttpClient " << oldState << " --> " << newState << ".");
829 m_stateTransitionTrace(oldState, newState);
830}
831
832void
843
844} // namespace ns3
a polymophic address class
Definition address.h:90
bool IsInvalid() const
Definition address.cc:60
The base class for all ns3 applications.
Definition application.h:51
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
An Inet6 address class.
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.
an Inet address class
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address ConvertFrom(const Address &address)
static bool IsMatchingType(const Address &address)
Describes an IPv6 address.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
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:560
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:594
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.
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 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.
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...
uint16_t m_remoteServerPort
The RemoteServerPort attribute.
uint32_t m_numberBytesPage
Number of bytes received for the current page.
Address m_remoteServerAddress
The RemoteServerAddress attribute. The address of the web server.
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.
uint8_t m_tos
The Tos attribute.
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.
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_remoteServerAddress and m_remoteSer...
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.
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
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:304
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#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 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
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:1320
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
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
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeAddressChecker()
Definition address.cc:169
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Definition address.h:275
static const uint32_t packetSize
Packet size generated at the AP.