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
23#include <ns3/callback.h>
24#include <ns3/double.h>
25#include <ns3/inet-socket-address.h>
26#include <ns3/inet6-socket-address.h>
27#include <ns3/log.h>
28#include <ns3/packet.h>
29#include <ns3/pointer.h>
30#include <ns3/simulator.h>
31#include <ns3/socket.h>
32#include <ns3/tcp-socket-factory.h>
33#include <ns3/three-gpp-http-variables.h>
34#include <ns3/uinteger.h>
35
36NS_LOG_COMPONENT_DEFINE("ThreeGppHttpClient");
37
38namespace ns3
39{
40
41NS_OBJECT_ENSURE_REGISTERED(ThreeGppHttpClient);
42
44 : m_state(NOT_STARTED),
45 m_socket(nullptr),
46 m_objectBytesToBeReceived(0),
47 m_objectClientTs(MilliSeconds(0)),
48 m_objectServerTs(MilliSeconds(0)),
49 m_embeddedObjectsToBeRequested(0),
50 m_pageLoadStartTs(MilliSeconds(0)),
51 m_numberEmbeddedObjectsRequested(0),
52 m_numberBytesPage(0),
53 m_httpVariables(CreateObject<ThreeGppHttpVariables>())
54{
55 NS_LOG_FUNCTION(this);
56}
57
58// static
61{
62 static TypeId tid =
63 TypeId("ns3::ThreeGppHttpClient")
65 .AddConstructor<ThreeGppHttpClient>()
66 .AddAttribute(
67 "Variables",
68 "Variable collection, which is used to control e.g. timing and HTTP request size.",
71 MakePointerChecker<ThreeGppHttpVariables>())
72 .AddAttribute("RemoteServerAddress",
73 "The address of the destination server.",
76 MakeAddressChecker())
77 .AddAttribute("RemoteServerPort",
78 "The destination port of the outbound packets.",
79 UintegerValue(80), // the default HTTP port
81 MakeUintegerChecker<uint16_t>())
82 .AddTraceSource("RxPage",
83 "A page has been received.",
85 "ns3::ThreeGppHttpClient::RxPageTracedCallback")
86 .AddTraceSource(
87 "ConnectionEstablished",
88 "Connection to the destination web server has been established.",
90 "ns3::ThreeGppHttpClient::TracedCallback")
91 .AddTraceSource("ConnectionClosed",
92 "Connection to the destination web server is closed.",
94 "ns3::ThreeGppHttpClient::TracedCallback")
95 .AddTraceSource("Tx",
96 "General trace for sending a packet of any kind.",
98 "ns3::Packet::TracedCallback")
99 .AddTraceSource(
100 "TxMainObjectRequest",
101 "Sent a request for a main object.",
103 "ns3::Packet::TracedCallback")
104 .AddTraceSource(
105 "TxEmbeddedObjectRequest",
106 "Sent a request for an embedded object.",
108 "ns3::Packet::TracedCallback")
109 .AddTraceSource("RxMainObjectPacket",
110 "A packet of main object has been received.",
112 "ns3::Packet::TracedCallback")
113 .AddTraceSource("RxMainObject",
114 "Received a whole main object. Header is included.",
116 "ns3::ThreeGppHttpClient::TracedCallback")
117 .AddTraceSource(
118 "RxEmbeddedObjectPacket",
119 "A packet of embedded object has been received.",
121 "ns3::Packet::TracedCallback")
122 .AddTraceSource("RxEmbeddedObject",
123 "Received a whole embedded object. Header is included.",
125 "ns3::ThreeGppHttpClient::TracedCallback")
126 .AddTraceSource("Rx",
127 "General trace for receiving a packet of any kind.",
129 "ns3::Packet::PacketAddressTracedCallback")
130 .AddTraceSource("RxDelay",
131 "General trace of delay for receiving a complete object.",
133 "ns3::Application::DelayAddressCallback")
134 .AddTraceSource(
135 "RxRtt",
136 "General trace of round trip delay time for receiving a complete object.",
138 "ns3::Application::DelayAddressCallback")
139 .AddTraceSource("StateTransition",
140 "Trace fired upon every HTTP client state transition.",
142 "ns3::Application::StateTransitionCallback");
143 return tid;
144}
145
148{
149 return m_socket;
150}
151
154{
155 return m_state;
156}
157
158std::string
160{
161 return GetStateString(m_state);
162}
163
164// static
165std::string
167{
168 switch (state)
169 {
170 case NOT_STARTED:
171 return "NOT_STARTED";
172 case CONNECTING:
173 return "CONNECTING";
175 return "EXPECTING_MAIN_OBJECT";
177 return "PARSING_MAIN_OBJECT";
179 return "EXPECTING_EMBEDDED_OBJECT";
180 case READING:
181 return "READING";
182 case STOPPED:
183 return "STOPPED";
184 default:
185 NS_FATAL_ERROR("Unknown state");
186 return "FATAL_ERROR";
187 }
188}
189
190void
192{
193 NS_LOG_FUNCTION(this);
194
196 {
198 }
199
200 Application::DoDispose(); // Chain up.
201}
202
203void
205{
206 NS_LOG_FUNCTION(this);
207
208 if (m_state == NOT_STARTED)
209 {
210 m_httpVariables->Initialize();
212 }
213 else
214 {
215 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for StartApplication().");
216 }
217}
218
219void
221{
222 NS_LOG_FUNCTION(this);
223
226 m_socket->Close();
230}
231
232void
234{
235 NS_LOG_FUNCTION(this << socket);
236
237 if (m_state == CONNECTING)
238 {
239 NS_ASSERT_MSG(m_socket == socket, "Invalid socket.");
241 socket->SetRecvCallback(MakeCallback(&ThreeGppHttpClient::ReceivedDataCallback, this));
245 }
246 else
247 {
248 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ConnectionSucceeded().");
249 }
250}
251
252void
254{
255 NS_LOG_FUNCTION(this << socket);
256
257 if (m_state == CONNECTING)
258 {
259 NS_LOG_ERROR("Client failed to connect"
260 << " to remote address " << m_remoteServerAddress << " port "
261 << m_remoteServerPort << ".");
262 }
263 else
264 {
265 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ConnectionFailed().");
266 }
267}
268
269void
271{
272 NS_LOG_FUNCTION(this << socket);
273
275
276 if (socket->GetErrno() != Socket::ERROR_NOTERROR)
277 {
278 NS_LOG_ERROR(this << " Connection has been terminated,"
279 << " error code: " << socket->GetErrno() << ".");
280 }
281
284
286}
287
288void
290{
291 NS_LOG_FUNCTION(this << socket);
292
294 if (socket->GetErrno() != Socket::ERROR_NOTERROR)
295 {
296 NS_LOG_ERROR(this << " Connection has been terminated,"
297 << " error code: " << socket->GetErrno() << ".");
298 }
299
301}
302
303void
305{
306 NS_LOG_FUNCTION(this << socket);
307
308 Ptr<Packet> packet;
309 Address from;
310
311 while ((packet = socket->RecvFrom(from)))
312 {
313 if (packet->GetSize() == 0)
314 {
315 break; // EOF
316 }
317
318#ifdef NS3_LOG_ENABLE
319 // Some log messages.
321 {
322 NS_LOG_INFO(this << " A packet of " << packet->GetSize() << " bytes"
323 << " received from " << InetSocketAddress::ConvertFrom(from).GetIpv4()
324 << " port " << InetSocketAddress::ConvertFrom(from).GetPort() << " / "
325 << InetSocketAddress::ConvertFrom(from) << ".");
326 }
328 {
329 NS_LOG_INFO(this << " A packet of " << packet->GetSize() << " bytes"
330 << " received from " << Inet6SocketAddress::ConvertFrom(from).GetIpv6()
331 << " port " << Inet6SocketAddress::ConvertFrom(from).GetPort() << " / "
332 << Inet6SocketAddress::ConvertFrom(from) << ".");
333 }
334#endif /* NS3_LOG_ENABLE */
335
336 m_rxTrace(packet, from);
337
338 switch (m_state)
339 {
341 ReceiveMainObject(packet, from);
342 break;
344 ReceiveEmbeddedObject(packet, from);
345 break;
346 default:
347 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceivedData().");
348 break;
349 }
350
351 } // end of `while ((packet = socket->RecvFrom (from)))`
352
353} // end of `void ReceivedDataCallback (Ptr<Socket> socket)`
354
355void
357{
358 NS_LOG_FUNCTION(this);
359
362 {
364
366 {
367 int ret [[maybe_unused]];
368
369 ret = m_socket->Bind();
370 NS_LOG_DEBUG(this << " Bind() return value= " << ret
371 << " GetErrNo= " << m_socket->GetErrno() << ".");
372
375 NS_LOG_INFO(this << " Connecting to " << ipv4 << " port " << m_remoteServerPort << " / "
376 << inetSocket << ".");
377 ret = m_socket->Connect(inetSocket);
378 NS_LOG_DEBUG(this << " Connect() return value= " << ret
379 << " GetErrNo= " << m_socket->GetErrno() << ".");
380 }
382 {
383 int ret [[maybe_unused]];
384
385 ret = m_socket->Bind6();
386 NS_LOG_DEBUG(this << " Bind6() return value= " << ret
387 << " GetErrNo= " << m_socket->GetErrno() << ".");
388
391 NS_LOG_INFO(this << " connecting to " << ipv6 << " port " << m_remoteServerPort << " / "
392 << inet6Socket << ".");
393 ret = m_socket->Connect(inet6Socket);
394 NS_LOG_DEBUG(this << " Connect() return value= " << ret
395 << " GetErrNo= " << m_socket->GetErrno() << ".");
396 }
397
398 NS_ASSERT_MSG(m_socket, "Failed creating socket.");
399
401
408 m_socket->SetAttribute("MaxSegLifetime", DoubleValue(0.02)); // 20 ms.
409
410 } // end of `if (m_state == {NOT_STARTED, EXPECTING_EMBEDDED_OBJECT, PARSING_MAIN_OBJECT,
411 // READING})`
412 else
413 {
414 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for OpenConnection().");
415 }
416
417} // end of `void OpenConnection ()`
418
419void
421{
422 NS_LOG_FUNCTION(this);
423
424 if (m_state == CONNECTING || m_state == READING)
425 {
426 ThreeGppHttpHeader header;
427 header.SetContentLength(0); // Request does not need any content length.
429 header.SetClientTs(Simulator::Now());
430
431 const uint32_t requestSize = m_httpVariables->GetRequestSize();
432 Ptr<Packet> packet = Create<Packet>(requestSize);
433 packet->AddHeader(header);
434 const uint32_t packetSize = packet->GetSize();
436 m_txTrace(packet);
437 const int actualBytes = m_socket->Send(packet);
438 NS_LOG_DEBUG(this << " Send() packet " << packet << " of " << packet->GetSize() << " bytes,"
439 << " return value= " << actualBytes << ".");
440 if (actualBytes != static_cast<int>(packetSize))
441 {
442 NS_LOG_ERROR(this << " Failed to send request for embedded object,"
443 << " GetErrNo= " << m_socket->GetErrno() << ","
444 << " waiting for another Tx opportunity.");
445 }
446 else
447 {
449 m_pageLoadStartTs = Simulator::Now(); // start counting page loading time
450 }
451 }
452 else
453 {
454 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for RequestMainObject().");
455 }
456
457} // end of `void RequestMainObject ()`
458
459void
461{
462 NS_LOG_FUNCTION(this);
463
466 {
468 {
469 ThreeGppHttpHeader header;
470 header.SetContentLength(0); // Request does not need any content length.
472 header.SetClientTs(Simulator::Now());
473
474 const uint32_t requestSize = m_httpVariables->GetRequestSize();
475 Ptr<Packet> packet = Create<Packet>(requestSize);
476 packet->AddHeader(header);
477 const uint32_t packetSize = packet->GetSize();
479 m_txTrace(packet);
480 const int actualBytes = m_socket->Send(packet);
481 NS_LOG_DEBUG(this << " Send() packet " << packet << " of " << packet->GetSize()
482 << " bytes,"
483 << " return value= " << actualBytes << ".");
484
485 if (actualBytes != static_cast<int>(packetSize))
486 {
487 NS_LOG_ERROR(this << " Failed to send request for embedded object,"
488 << " GetErrNo= " << m_socket->GetErrno() << ","
489 << " waiting for another Tx opportunity.");
490 }
491 else
492 {
495 }
496 }
497 else
498 {
499 NS_LOG_WARN(this << " No embedded object to be requested.");
500 }
501 }
502 else
503 {
504 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for RequestEmbeddedObject().");
505 }
506
507} // end of `void RequestEmbeddedObject ()`
508
509void
511{
512 NS_LOG_FUNCTION(this << packet << from);
513
515 {
516 /*
517 * In the following call to Receive(), #m_objectBytesToBeReceived *will*
518 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
519 * ThreeGppHttpHeader will be removed from the packet, if it is the first
520 * packet of the object to be received; the header will be available in
521 * #m_constructedPacketHeader.
522 * #m_constructedPacket will also be updated.
523 */
524 Receive(packet);
526
528 {
529 /*
530 * There are more packets of this main object, so just stay still
531 * and wait until they arrive.
532 */
533 NS_LOG_INFO(this << " " << m_objectBytesToBeReceived << " byte(s)"
534 << " remains from this chunk of main object.");
535 }
536 else
537 {
538 /*
539 * This is the last packet of this main object. Acknowledge the
540 * reception of a whole main object
541 */
542 NS_LOG_INFO(this << " Finished receiving a main object.");
544
546 {
548 m_objectServerTs = MilliSeconds(0); // Reset back to zero.
549 }
550
552 {
554 m_objectClientTs = MilliSeconds(0); // Reset back to zero.
555 }
556
558
559 } // end of else of `if (m_objectBytesToBeReceived > 0)`
560
561 } // end of `if (m_state == EXPECTING_MAIN_OBJECT)`
562 else
563 {
564 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceiveMainObject().");
565 }
566
567} // end of `void ReceiveMainObject (Ptr<Packet> packet)`
568
569void
571{
572 NS_LOG_FUNCTION(this << packet << from);
573
575 {
576 /*
577 * In the following call to Receive(), #m_objectBytesToBeReceived *will*
578 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
579 * ThreeGppHttpHeader will be removed from the packet, if it is the first
580 * packet of the object to be received; the header will be available in
581 * #m_constructedPacket, which will also be updated.
582 */
583 Receive(packet);
585
587 {
588 /*
589 * There are more packets of this embedded object, so just stay
590 * still and wait until they arrive.
591 */
592 NS_LOG_INFO(this << " " << m_objectBytesToBeReceived << " byte(s)"
593 << " remains from this chunk of embedded object");
594 }
595 else
596 {
597 /*
598 * This is the last packet of this embedded object. Acknowledge
599 * the reception of a whole embedded object
600 */
601 NS_LOG_INFO(this << " Finished receiving an embedded object.");
603
605 {
607 m_objectServerTs = MilliSeconds(0); // Reset back to zero.
608 }
609
611 {
613 m_objectClientTs = MilliSeconds(0); // Reset back to zero.
614 }
615
617 {
619 << " more embedded object(s) to be requested.");
620 // Immediately request another using the existing connection.
623 }
624 else
625 {
626 /*
627 * There is no more embedded object, the web page has been
628 * downloaded completely. Now is the time to read it.
629 */
630 NS_LOG_INFO(this << " Finished receiving a web page.");
631 FinishReceivingPage(); // trigger callback for page loading time
633 }
634
635 } // end of else of `if (m_objectBytesToBeReceived > 0)`
636
637 } // end of `if (m_state == EXPECTING_EMBEDDED_OBJECT)`
638 else
639 {
640 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ReceiveEmbeddedObject().");
641 }
642
643} // end of `void ReceiveEmbeddedObject (Ptr<Packet> packet)`
644
645void
647{
648 NS_LOG_FUNCTION(this << packet);
649
650 /* In a "real" HTTP message the message size is coded differently. The use of a header
651 * is to avoid the burden of doing a real message parser.
652 */
653 bool firstPacket = false;
654
656 {
657 // This is the first packet of the object.
658 firstPacket = true;
659
660 // Remove the header in order to calculate remaining data to be received.
661 ThreeGppHttpHeader httpHeader;
662 packet->RemoveHeader(httpHeader);
663
665 m_objectClientTs = httpHeader.GetClientTs();
666 m_objectServerTs = httpHeader.GetServerTs();
667
668 // Take a copy for constructed packet trace. Note that header is included.
669 m_constructedPacket = packet->Copy();
670 m_constructedPacket->AddHeader(httpHeader);
671 }
672 uint32_t contentSize = packet->GetSize();
673 m_numberBytesPage += contentSize; // increment counter of page size
674
675 /* Note that the packet does not contain header at this point.
676 * The content is purely raw data, which was the only intended data to be received.
677 */
678 if (m_objectBytesToBeReceived < contentSize)
679 {
680 NS_LOG_WARN(this << " The received packet"
681 << " (" << contentSize << " bytes of content)"
682 << " is larger than"
683 << " the content that we expected to receive"
684 << " (" << m_objectBytesToBeReceived << " bytes).");
685 // Stop expecting any more packet of this object.
687 m_constructedPacket = nullptr;
688 }
689 else
690 {
691 m_objectBytesToBeReceived -= contentSize;
692 if (!firstPacket)
693 {
694 Ptr<Packet> packetCopy = packet->Copy();
695 m_constructedPacket->AddAtEnd(packetCopy);
696 }
697 }
698
699} // end of `void Receive (packet)`
700
701void
703{
704 NS_LOG_FUNCTION(this);
705
707 {
708 const Time parsingTime = m_httpVariables->GetParsingTime();
709 NS_LOG_INFO(this << " The parsing of this main object"
710 << " will complete in " << parsingTime.As(Time::S) << ".");
714 }
715 else
716 {
717 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for EnterParsingTime().");
718 }
719}
720
721void
723{
724 NS_LOG_FUNCTION(this);
725
727 {
728 m_embeddedObjectsToBeRequested = m_httpVariables->GetNumOfEmbeddedObjects();
729 // saving total number of embedded objects
731 NS_LOG_INFO(this << " Parsing has determined " << m_embeddedObjectsToBeRequested
732 << " embedded object(s) in the main object.");
733
735 {
736 /*
737 * Immediately request the first embedded object using the
738 * existing connection.
739 */
742 }
743 else
744 {
745 /*
746 * There is no embedded object in the main object. So sit back and
747 * enjoy the plain web page.
748 */
749 NS_LOG_INFO(this << " Finished receiving a web page.");
750 FinishReceivingPage(); // trigger callback for page loading time
752 }
753 }
754 else
755 {
756 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for ParseMainObject().");
757 }
758
759} // end of `void ParseMainObject ()`
760
761void
763{
764 NS_LOG_FUNCTION(this);
765
767 {
768 const Time readingTime = m_httpVariables->GetReadingTime();
769 NS_LOG_INFO(this << " Client will finish reading this web page in "
770 << readingTime.As(Time::S) << ".");
771
772 // Schedule a request of another main object once the reading time expires.
776 }
777 else
778 {
779 NS_FATAL_ERROR("Invalid state " << GetStateString() << " for EnterReadingTime().");
780 }
781}
782
783void
785{
786 NS_LOG_FUNCTION(this);
787
789 {
790 NS_LOG_INFO(this << " Canceling RequestMainObject() which is due in "
793 }
794
796 {
797 NS_LOG_INFO(this << " Canceling RequestEmbeddedObject() which is due in "
799 << ".");
801 }
802
804 {
805 NS_LOG_INFO(this << " Canceling ParseMainObject() which is due in "
808 }
809}
810
811void
813{
814 const std::string oldState = GetStateString();
815 const std::string newState = GetStateString(state);
816 NS_LOG_FUNCTION(this << oldState << newState);
817
818 if ((state == EXPECTING_MAIN_OBJECT) || (state == EXPECTING_EMBEDDED_OBJECT))
819 {
821 {
822 NS_FATAL_ERROR("Cannot start a new receiving session"
823 << " if the previous object"
824 << " (" << m_objectBytesToBeReceived << " bytes)"
825 << " is not completely received yet.");
826 }
827 }
828
829 m_state = state;
830 NS_LOG_INFO(this << " HttpClient " << oldState << " --> " << newState << ".");
831 m_stateTransitionTrace(oldState, newState);
832}
833
834void
836{
837 m_rxPageTrace(this,
841 // Reset counter variables.
844}
845
846} // namespace ns3
a polymophic address class
Definition: address.h:100
AttributeValue implementation for Address.
The base class for all ns3 applications.
Definition: application.h:61
void DoDispose() override
Destructor implementation.
Definition: application.cc:85
Ptr< Node > GetNode() const
Definition: application.cc:107
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:200
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
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
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:276
static bool IsFinished()
Check if the simulation should finish.
Definition: simulator.cc:169
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
static bool IsExpired(const EventId &id)
Check if an event has already run or been cancelled.
Definition: simulator.cc:286
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:606
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition: simulator.cc:208
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:85
virtual Socket::SocketErrno GetErrno() const =0
Get last error number.
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:94
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:126
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.
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:417
@ S
second
Definition: nstime.h:116
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:314
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
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 AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
Callback< R, Args... > MakeNullCallback()
Definition: callback.h:745
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#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:579
#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:1348
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:702
static const uint32_t packetSize
Packet size generated at the AP.