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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Budiarto Herman <budiarto.herman@magister.fi>
18 *
19 */
20
22
24
25#include <ns3/callback.h>
26#include <ns3/double.h>
27#include <ns3/inet-socket-address.h>
28#include <ns3/inet6-socket-address.h>
29#include <ns3/log.h>
30#include <ns3/packet.h>
31#include <ns3/pointer.h>
32#include <ns3/simulator.h>
33#include <ns3/socket.h>
34#include <ns3/tcp-socket-factory.h>
35#include <ns3/uinteger.h>
36
37NS_LOG_COMPONENT_DEFINE("ThreeGppHttpClient");
38
39namespace ns3
40{
41
42NS_OBJECT_ENSURE_REGISTERED(ThreeGppHttpClient);
43
45 : m_state(NOT_STARTED),
46 m_socket(nullptr),
47 m_objectBytesToBeReceived(0),
48 m_objectClientTs(MilliSeconds(0)),
49 m_objectServerTs(MilliSeconds(0)),
50 m_embeddedObjectsToBeRequested(0),
51 m_pageLoadStartTs(MilliSeconds(0)),
52 m_numberEmbeddedObjectsRequested(0),
53 m_numberBytesPage(0),
54 m_httpVariables(CreateObject<ThreeGppHttpVariables>())
55{
56 NS_LOG_FUNCTION(this);
57}
58
59// static
62{
63 static TypeId tid =
64 TypeId("ns3::ThreeGppHttpClient")
66 .AddConstructor<ThreeGppHttpClient>()
67 .AddAttribute(
68 "Variables",
69 "Variable collection, which is used to control e.g. timing and HTTP request size.",
72 MakePointerChecker<ThreeGppHttpVariables>())
73 .AddAttribute("RemoteServerAddress",
74 "The address of the destination server.",
78 .AddAttribute("RemoteServerPort",
79 "The destination port of the outbound packets.",
80 UintegerValue(80), // the default HTTP port
82 MakeUintegerChecker<uint16_t>())
83 .AddAttribute("Tos",
84 "The Type of Service used to send packets. "
85 "All 8 bits of the TOS byte are set (including ECN bits).",
88 MakeUintegerChecker<uint8_t>())
89 .AddTraceSource("RxPage",
90 "A page has been received.",
92 "ns3::ThreeGppHttpClient::RxPageTracedCallback")
93 .AddTraceSource(
94 "ConnectionEstablished",
95 "Connection to the destination web server has been established.",
97 "ns3::ThreeGppHttpClient::TracedCallback")
98 .AddTraceSource("ConnectionClosed",
99 "Connection to the destination web server is closed.",
101 "ns3::ThreeGppHttpClient::TracedCallback")
102 .AddTraceSource("Tx",
103 "General trace for sending a packet of any kind.",
105 "ns3::Packet::TracedCallback")
106 .AddTraceSource(
107 "TxMainObjectRequest",
108 "Sent a request for a main object.",
110 "ns3::Packet::TracedCallback")
111 .AddTraceSource(
112 "TxEmbeddedObjectRequest",
113 "Sent a request for an embedded object.",
115 "ns3::Packet::TracedCallback")
116 .AddTraceSource("RxMainObjectPacket",
117 "A packet of main object has been received.",
119 "ns3::Packet::TracedCallback")
120 .AddTraceSource("RxMainObject",
121 "Received a whole main object. Header is included.",
123 "ns3::ThreeGppHttpClient::TracedCallback")
124 .AddTraceSource(
125 "RxEmbeddedObjectPacket",
126 "A packet of embedded object has been received.",
128 "ns3::Packet::TracedCallback")
129 .AddTraceSource("RxEmbeddedObject",
130 "Received a whole embedded object. Header is included.",
132 "ns3::ThreeGppHttpClient::TracedCallback")
133 .AddTraceSource("Rx",
134 "General trace for receiving a packet of any kind.",
136 "ns3::Packet::PacketAddressTracedCallback")
137 .AddTraceSource("RxDelay",
138 "General trace of delay for receiving a complete object.",
140 "ns3::Application::DelayAddressCallback")
141 .AddTraceSource(
142 "RxRtt",
143 "General trace of round trip delay time for receiving a complete object.",
145 "ns3::Application::DelayAddressCallback")
146 .AddTraceSource("StateTransition",
147 "Trace fired upon every HTTP client state transition.",
149 "ns3::Application::StateTransitionCallback");
150 return tid;
151}
152
155{
156 return m_socket;
157}
158
161{
162 return m_state;
163}
164
165std::string
167{
168 return GetStateString(m_state);
169}
170
171// static
172std::string
174{
175 switch (state)
176 {
177 case NOT_STARTED:
178 return "NOT_STARTED";
179 case CONNECTING:
180 return "CONNECTING";
182 return "EXPECTING_MAIN_OBJECT";
184 return "PARSING_MAIN_OBJECT";
186 return "EXPECTING_EMBEDDED_OBJECT";
187 case READING:
188 return "READING";
189 case STOPPED:
190 return "STOPPED";
191 default:
192 NS_FATAL_ERROR("Unknown state");
193 return "FATAL_ERROR";
194 }
195}
196
197void
199{
200 NS_LOG_FUNCTION(this);
201
203 {
205 }
206
207 Application::DoDispose(); // Chain up.
208}
209
210void
212{
213 NS_LOG_FUNCTION(this);
214
215 if (m_state == NOT_STARTED)
216 {
217 m_httpVariables->Initialize();
219 }
220 else
221 {
222 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for StartApplication().");
223 }
224}
225
226void
228{
229 NS_LOG_FUNCTION(this);
230
233 m_socket->Close();
237}
238
239void
241{
242 NS_LOG_FUNCTION(this << socket);
243
244 if (m_state == CONNECTING)
245 {
246 NS_ASSERT_MSG(m_socket == socket, "Invalid socket.");
248 socket->SetRecvCallback(MakeCallback(&ThreeGppHttpClient::ReceivedDataCallback, this));
252 }
253 else
254 {
255 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ConnectionSucceeded().");
256 }
257}
258
259void
261{
262 NS_LOG_FUNCTION(this << socket);
263
264 if (m_state == CONNECTING)
265 {
266 NS_LOG_ERROR("Client failed to connect"
267 << " to remote address " << m_remoteServerAddress << " port "
268 << m_remoteServerPort << ".");
269 }
270 else
271 {
272 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ConnectionFailed().");
273 }
274}
275
276void
278{
279 NS_LOG_FUNCTION(this << socket);
280
282
283 if (socket->GetErrno() != Socket::ERROR_NOTERROR)
284 {
285 NS_LOG_ERROR(this << " Connection has been terminated,"
286 << " error code: " << socket->GetErrno() << ".");
287 }
288
291
293}
294
295void
297{
298 NS_LOG_FUNCTION(this << socket);
299
301 if (socket->GetErrno() != Socket::ERROR_NOTERROR)
302 {
303 NS_LOG_ERROR(this << " Connection has been terminated,"
304 << " error code: " << socket->GetErrno() << ".");
305 }
306
308}
309
310void
312{
313 NS_LOG_FUNCTION(this << socket);
314
315 Ptr<Packet> packet;
316 Address from;
317
318 while ((packet = socket->RecvFrom(from)))
319 {
320 if (packet->GetSize() == 0)
321 {
322 break; // EOF
323 }
324
325#ifdef NS3_LOG_ENABLE
326 // Some log messages.
328 {
329 NS_LOG_INFO(this << " A packet of " << packet->GetSize() << " bytes"
330 << " received from " << InetSocketAddress::ConvertFrom(from).GetIpv4()
331 << " port " << InetSocketAddress::ConvertFrom(from).GetPort() << " / "
332 << InetSocketAddress::ConvertFrom(from) << ".");
333 }
335 {
336 NS_LOG_INFO(this << " A packet of " << packet->GetSize() << " bytes"
337 << " received from " << Inet6SocketAddress::ConvertFrom(from).GetIpv6()
338 << " port " << Inet6SocketAddress::ConvertFrom(from).GetPort() << " / "
339 << Inet6SocketAddress::ConvertFrom(from) << ".");
340 }
341#endif /* NS3_LOG_ENABLE */
342
343 m_rxTrace(packet, from);
344
345 switch (m_state)
346 {
348 ReceiveMainObject(packet, from);
349 break;
351 ReceiveEmbeddedObject(packet, from);
352 break;
353 default:
354 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceivedData().");
355 break;
356 }
357
358 } // end of `while ((packet = socket->RecvFrom (from)))`
359
360} // end of `void ReceivedDataCallback (Ptr<Socket> socket)`
361
362void
364{
365 NS_LOG_FUNCTION(this);
366
369 {
372 "'RemoteServerAddress' attribute not properly set");
374 {
375 int ret [[maybe_unused]];
376
377 ret = m_socket->Bind();
378 NS_LOG_DEBUG(this << " Bind() return value= " << ret
379 << " GetErrNo= " << m_socket->GetErrno() << ".");
380
383 NS_LOG_INFO(this << " Connecting to " << ipv4 << " port " << m_remoteServerPort << " / "
384 << inetSocket << ".");
386 ret = m_socket->Connect(inetSocket);
387 NS_LOG_DEBUG(this << " Connect() return value= " << ret
388 << " GetErrNo= " << m_socket->GetErrno() << ".");
389 }
391 {
392 int ret [[maybe_unused]];
393
394 ret = m_socket->Bind6();
395 NS_LOG_DEBUG(this << " Bind6() return value= " << ret
396 << " GetErrNo= " << m_socket->GetErrno() << ".");
397
400 NS_LOG_INFO(this << " connecting to " << ipv6 << " port " << m_remoteServerPort << " / "
401 << inet6Socket << ".");
402 ret = m_socket->Connect(inet6Socket);
403 NS_LOG_DEBUG(this << " Connect() return value= " << ret
404 << " GetErrNo= " << m_socket->GetErrno() << ".");
405 }
406
407 NS_ASSERT_MSG(m_socket, "Failed creating socket.");
408
410
417 m_socket->SetAttribute("MaxSegLifetime", DoubleValue(0.02)); // 20 ms.
418
419 } // end of `if (m_state == {NOT_STARTED, EXPECTING_EMBEDDED_OBJECT, PARSING_MAIN_OBJECT,
420 // READING})`
421 else
422 {
423 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for OpenConnection().");
424 }
425
426} // end of `void OpenConnection ()`
427
428void
430{
431 NS_LOG_FUNCTION(this);
432
433 if (m_state == CONNECTING || m_state == READING)
434 {
435 ThreeGppHttpHeader header;
436 header.SetContentLength(0); // Request does not need any content length.
438 header.SetClientTs(Simulator::Now());
439
440 const uint32_t requestSize = m_httpVariables->GetRequestSize();
441 Ptr<Packet> packet = Create<Packet>(requestSize);
442 packet->AddHeader(header);
443 const uint32_t packetSize = packet->GetSize();
445 m_txTrace(packet);
446 const int actualBytes = m_socket->Send(packet);
447 NS_LOG_DEBUG(this << " Send() packet " << packet << " of " << packet->GetSize() << " bytes,"
448 << " return value= " << actualBytes << ".");
449 if (actualBytes != static_cast<int>(packetSize))
450 {
451 NS_LOG_ERROR(this << " Failed to send request for embedded object,"
452 << " GetErrNo= " << m_socket->GetErrno() << ","
453 << " waiting for another Tx opportunity.");
454 }
455 else
456 {
458 m_pageLoadStartTs = Simulator::Now(); // start counting page loading time
459 }
460 }
461 else
462 {
463 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for RequestMainObject().");
464 }
465
466} // end of `void RequestMainObject ()`
467
468void
470{
471 NS_LOG_FUNCTION(this);
472
475 {
477 {
478 ThreeGppHttpHeader header;
479 header.SetContentLength(0); // Request does not need any content length.
481 header.SetClientTs(Simulator::Now());
482
483 const uint32_t requestSize = m_httpVariables->GetRequestSize();
484 Ptr<Packet> packet = Create<Packet>(requestSize);
485 packet->AddHeader(header);
486 const uint32_t packetSize = packet->GetSize();
488 m_txTrace(packet);
489 const int actualBytes = m_socket->Send(packet);
490 NS_LOG_DEBUG(this << " Send() packet " << packet << " of " << packet->GetSize()
491 << " bytes,"
492 << " return value= " << actualBytes << ".");
493
494 if (actualBytes != static_cast<int>(packetSize))
495 {
496 NS_LOG_ERROR(this << " Failed to send request for embedded object,"
497 << " GetErrNo= " << m_socket->GetErrno() << ","
498 << " waiting for another Tx opportunity.");
499 }
500 else
501 {
504 }
505 }
506 else
507 {
508 NS_LOG_WARN(this << " No embedded object to be requested.");
509 }
510 }
511 else
512 {
513 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for RequestEmbeddedObject().");
514 }
515
516} // end of `void RequestEmbeddedObject ()`
517
518void
520{
521 NS_LOG_FUNCTION(this << packet << from);
522
524 {
525 /*
526 * In the following call to Receive(), #m_objectBytesToBeReceived *will*
527 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
528 * ThreeGppHttpHeader will be removed from the packet, if it is the first
529 * packet of the object to be received; the header will be available in
530 * #m_constructedPacketHeader.
531 * #m_constructedPacket will also be updated.
532 */
533 Receive(packet);
535
537 {
538 /*
539 * There are more packets of this main object, so just stay still
540 * and wait until they arrive.
541 */
542 NS_LOG_INFO(this << " " << m_objectBytesToBeReceived << " byte(s)"
543 << " remains from this chunk of main object.");
544 }
545 else
546 {
547 /*
548 * This is the last packet of this main object. Acknowledge the
549 * reception of a whole main object
550 */
551 NS_LOG_INFO(this << " Finished receiving a main object.");
553
555 {
557 m_objectServerTs = MilliSeconds(0); // Reset back to zero.
558 }
559
561 {
563 m_objectClientTs = MilliSeconds(0); // Reset back to zero.
564 }
565
567
568 } // end of else of `if (m_objectBytesToBeReceived > 0)`
569
570 } // end of `if (m_state == EXPECTING_MAIN_OBJECT)`
571 else
572 {
573 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceiveMainObject().");
574 }
575
576} // end of `void ReceiveMainObject (Ptr<Packet> packet)`
577
578void
580{
581 NS_LOG_FUNCTION(this << packet << from);
582
584 {
585 /*
586 * In the following call to Receive(), #m_objectBytesToBeReceived *will*
587 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
588 * ThreeGppHttpHeader will be removed from the packet, if it is the first
589 * packet of the object to be received; the header will be available in
590 * #m_constructedPacket, which will also be updated.
591 */
592 Receive(packet);
594
596 {
597 /*
598 * There are more packets of this embedded object, so just stay
599 * still and wait until they arrive.
600 */
601 NS_LOG_INFO(this << " " << m_objectBytesToBeReceived << " byte(s)"
602 << " remains from this chunk of embedded object");
603 }
604 else
605 {
606 /*
607 * This is the last packet of this embedded object. Acknowledge
608 * the reception of a whole embedded object
609 */
610 NS_LOG_INFO(this << " Finished receiving an embedded object.");
612
614 {
616 m_objectServerTs = MilliSeconds(0); // Reset back to zero.
617 }
618
620 {
622 m_objectClientTs = MilliSeconds(0); // Reset back to zero.
623 }
624
626 {
628 << " more embedded object(s) to be requested.");
629 // Immediately request another using the existing connection.
632 }
633 else
634 {
635 /*
636 * There is no more embedded object, the web page has been
637 * downloaded completely. Now is the time to read it.
638 */
639 NS_LOG_INFO(this << " Finished receiving a web page.");
640 FinishReceivingPage(); // trigger callback for page loading time
642 }
643
644 } // end of else of `if (m_objectBytesToBeReceived > 0)`
645
646 } // end of `if (m_state == EXPECTING_EMBEDDED_OBJECT)`
647 else
648 {
649 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceiveEmbeddedObject().");
650 }
651
652} // end of `void ReceiveEmbeddedObject (Ptr<Packet> packet)`
653
654void
656{
657 NS_LOG_FUNCTION(this << packet);
658
659 /* In a "real" HTTP message the message size is coded differently. The use of a header
660 * is to avoid the burden of doing a real message parser.
661 */
662 bool firstPacket = false;
663
665 {
666 // This is the first packet of the object.
667 firstPacket = true;
668
669 // Remove the header in order to calculate remaining data to be received.
670 ThreeGppHttpHeader httpHeader;
671 packet->RemoveHeader(httpHeader);
672
674 m_objectClientTs = httpHeader.GetClientTs();
675 m_objectServerTs = httpHeader.GetServerTs();
676
677 // Take a copy for constructed packet trace. Note that header is included.
678 m_constructedPacket = packet->Copy();
679 m_constructedPacket->AddHeader(httpHeader);
680 }
681 uint32_t contentSize = packet->GetSize();
682 m_numberBytesPage += contentSize; // increment counter of page size
683
684 /* Note that the packet does not contain header at this point.
685 * The content is purely raw data, which was the only intended data to be received.
686 */
687 if (m_objectBytesToBeReceived < contentSize)
688 {
689 NS_LOG_WARN(this << " The received packet"
690 << " (" << contentSize << " bytes of content)"
691 << " is larger than"
692 << " the content that we expected to receive"
693 << " (" << m_objectBytesToBeReceived << " bytes).");
694 // Stop expecting any more packet of this object.
696 m_constructedPacket = nullptr;
697 }
698 else
699 {
700 m_objectBytesToBeReceived -= contentSize;
701 if (!firstPacket)
702 {
703 Ptr<Packet> packetCopy = packet->Copy();
704 m_constructedPacket->AddAtEnd(packetCopy);
705 }
706 }
707
708} // end of `void Receive (packet)`
709
710void
712{
713 NS_LOG_FUNCTION(this);
714
716 {
717 const Time parsingTime = m_httpVariables->GetParsingTime();
718 NS_LOG_INFO(this << " The parsing of this main object"
719 << " will complete in " << parsingTime.As(Time::S) << ".");
723 }
724 else
725 {
726 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for EnterParsingTime().");
727 }
728}
729
730void
732{
733 NS_LOG_FUNCTION(this);
734
736 {
737 m_embeddedObjectsToBeRequested = m_httpVariables->GetNumOfEmbeddedObjects();
738 // saving total number of embedded objects
740 NS_LOG_INFO(this << " Parsing has determined " << m_embeddedObjectsToBeRequested
741 << " embedded object(s) in the main object.");
742
744 {
745 /*
746 * Immediately request the first embedded object using the
747 * existing connection.
748 */
751 }
752 else
753 {
754 /*
755 * There is no embedded object in the main object. So sit back and
756 * enjoy the plain web page.
757 */
758 NS_LOG_INFO(this << " Finished receiving a web page.");
759 FinishReceivingPage(); // trigger callback for page loading time
761 }
762 }
763 else
764 {
765 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ParseMainObject().");
766 }
767
768} // end of `void ParseMainObject ()`
769
770void
772{
773 NS_LOG_FUNCTION(this);
774
776 {
777 const Time readingTime = m_httpVariables->GetReadingTime();
778 NS_LOG_INFO(this << " Client will finish reading this web page in "
779 << readingTime.As(Time::S) << ".");
780
781 // Schedule a request of another main object once the reading time expires.
785 }
786 else
787 {
788 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for EnterReadingTime().");
789 }
790}
791
792void
794{
795 NS_LOG_FUNCTION(this);
796
798 {
799 NS_LOG_INFO(this << " Canceling RequestMainObject() which is due in "
802 }
803
805 {
806 NS_LOG_INFO(this << " Canceling RequestEmbeddedObject() which is due in "
808 << ".");
810 }
811
813 {
814 NS_LOG_INFO(this << " Canceling ParseMainObject() which is due in "
817 }
818}
819
820void
822{
823 const std::string oldState = GetStateString();
824 const std::string newState = GetStateString(state);
825 NS_LOG_FUNCTION(this << oldState << newState);
826
827 if ((state == EXPECTING_MAIN_OBJECT) || (state == EXPECTING_EMBEDDED_OBJECT))
828 {
830 {
831 NS_FATAL_ERROR("Cannot start a new receiving session"
832 << " if the previous object"
833 << " (" << m_objectBytesToBeReceived << " bytes)"
834 << " is not completely received yet.");
835 }
836 }
837
838 m_state = state;
839 NS_LOG_INFO(this << " HttpClient " << oldState << " --> " << newState << ".");
840 m_stateTransitionTrace(oldState, newState);
841}
842
843void
845{
846 m_rxPageTrace(this,
850 // Reset counter variables.
853}
854
855} // namespace ns3
a polymophic address class
Definition: address.h:101
bool IsInvalid() const
Definition: address.cc:71
AttributeValue implementation for Address.
Definition: address.h:286
The base class for all ns3 applications.
Definition: application.h:62
void DoDispose() override
Destructor implementation.
Definition: application.cc:86
Ptr< Node > GetNode() const
Definition: application.cc:108
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
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.
Definition: ipv4-address.h:42
static Ipv4Address ConvertFrom(const Address &address)
static bool IsMatchingType(const Address &address)
Describes an IPv6 address.
Definition: ipv6-address.h:49
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.
Definition: object-base.cc:211
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:354
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
AttributeValue implementation for Pointer.
Definition: pointer.h:48
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
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:285
static bool IsFinished()
Check if the simulation should finish.
Definition: simulator.cc:171
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static bool IsExpired(const EventId &id)
Check if an event has already run or been cancelled.
Definition: simulator.cc:295
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:605
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition: simulator.cc:217
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:87
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:434
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:96
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:128
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:72
virtual int Close()=0
Close a socket.
@ ERROR_NOTERROR
Definition: socket.h:85
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 SetClientTs(Time clientTs)
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:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:415
@ S
second
Definition: nstime.h:116
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:315
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
Ptr< const AttributeChecker > MakeAddressChecker()
Definition: address.cc:180
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Definition: address.h:286
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:259
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
Callback< R, Args... > MakeNullCallback()
Definition: callback.h:747
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:261
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition: object.h:630
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
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.
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:704
static const uint32_t packetSize
Packet size generated at the AP.