A Discrete-Event Network Simulator
API
three-gpp-http-client.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Budiarto Herman <budiarto.herman@magister.fi>
19  *
20  */
21 
22 #include "three-gpp-http-client.h"
23 
24 #include <ns3/log.h>
25 #include <ns3/simulator.h>
26 #include <ns3/callback.h>
27 #include <ns3/pointer.h>
28 #include <ns3/uinteger.h>
29 #include <ns3/double.h>
30 #include <ns3/three-gpp-http-variables.h>
31 #include <ns3/packet.h>
32 #include <ns3/socket.h>
33 #include <ns3/tcp-socket-factory.h>
34 #include <ns3/inet-socket-address.h>
35 #include <ns3/inet6-socket-address.h>
36 #include <ns3/unused.h>
37 
38 
39 NS_LOG_COMPONENT_DEFINE ("ThreeGppHttpClient");
40 
41 
42 namespace ns3 {
43 
44 NS_OBJECT_ENSURE_REGISTERED (ThreeGppHttpClient);
45 
46 
48  : m_state (NOT_STARTED),
49  m_socket (0),
50  m_objectBytesToBeReceived (0),
51  m_objectClientTs (MilliSeconds (0)),
52  m_objectServerTs (MilliSeconds (0)),
53  m_embeddedObjectsToBeRequested (0),
54  m_httpVariables (CreateObject<ThreeGppHttpVariables> ())
55 {
56  NS_LOG_FUNCTION (this);
57 }
58 
59 
60 // static
61 TypeId
63 {
64  static TypeId tid = TypeId ("ns3::ThreeGppHttpClient")
66  .AddConstructor<ThreeGppHttpClient> ()
67  .AddAttribute ("Variables",
68  "Variable collection, which is used to control e.g. timing and HTTP request size.",
69  PointerValue (),
71  MakePointerChecker<ThreeGppHttpVariables> ())
72  .AddAttribute ("RemoteServerAddress",
73  "The address of the destination server.",
74  AddressValue (),
77  .AddAttribute ("RemoteServerPort",
78  "The destination port of the outbound packets.",
79  UintegerValue (80), // the default HTTP port
81  MakeUintegerChecker<uint16_t> ())
82  .AddTraceSource ("ConnectionEstablished",
83  "Connection to the destination web server has been established.",
85  "ns3::ThreeGppHttpClient::TracedCallback")
86  .AddTraceSource ("ConnectionClosed",
87  "Connection to the destination web server is closed.",
89  "ns3::ThreeGppHttpClient::TracedCallback")
90  .AddTraceSource ("Tx",
91  "General trace for sending a packet of any kind.",
93  "ns3::Packet::TracedCallback")
94  .AddTraceSource ("TxMainObjectRequest",
95  "Sent a request for a main object.",
97  "ns3::Packet::TracedCallback")
98  .AddTraceSource ("TxEmbeddedObjectRequest",
99  "Sent a request for an embedded object.",
101  "ns3::Packet::TracedCallback")
102  .AddTraceSource ("RxMainObjectPacket",
103  "A packet of main object has been received.",
105  "ns3::Packet::TracedCallback")
106  .AddTraceSource ("RxMainObject",
107  "Received a whole main object. Header is included.",
109  "ns3::ThreeGppHttpClient::TracedCallback")
110  .AddTraceSource ("RxEmbeddedObjectPacket",
111  "A packet of embedded object has been received.",
113  "ns3::Packet::TracedCallback")
114  .AddTraceSource ("RxEmbeddedObject",
115  "Received a whole embedded object. Header is included.",
117  "ns3::ThreeGppHttpClient::TracedCallback")
118  .AddTraceSource ("Rx",
119  "General trace for receiving a packet of any kind.",
121  "ns3::Packet::PacketAddressTracedCallback")
122  .AddTraceSource ("RxDelay",
123  "General trace of delay for receiving a complete object.",
125  "ns3::Application::DelayAddressCallback")
126  .AddTraceSource ("RxRtt",
127  "General trace of round trip delay time for receiving a complete object.",
129  "ns3::Application::DelayAddressCallback")
130  .AddTraceSource ("StateTransition",
131  "Trace fired upon every HTTP client state transition.",
133  "ns3::Application::StateTransitionCallback")
134  ;
135  return tid;
136 }
137 
138 
141 {
142  return m_socket;
143 }
144 
145 
148 {
149  return m_state;
150 }
151 
152 
153 std::string
155 {
156  return GetStateString (m_state);
157 }
158 
159 // static
160 std::string
162 {
163  switch (state)
164  {
165  case NOT_STARTED:
166  return "NOT_STARTED";
167  break;
168  case CONNECTING:
169  return "CONNECTING";
170  break;
172  return "EXPECTING_MAIN_OBJECT";
173  break;
174  case PARSING_MAIN_OBJECT:
175  return "PARSING_MAIN_OBJECT";
176  break;
178  return "EXPECTING_EMBEDDED_OBJECT";
179  break;
180  case READING:
181  return "READING";
182  break;
183  case STOPPED:
184  return "STOPPED";
185  break;
186  default:
187  NS_FATAL_ERROR ("Unknown state");
188  return "FATAL_ERROR";
189  break;
190  }
191 }
192 
193 
194 void
196 {
197  NS_LOG_FUNCTION (this);
198 
199  if (!Simulator::IsFinished ())
200  {
201  StopApplication ();
202  }
203 
204  Application::DoDispose (); // Chain up.
205 }
206 
207 
208 void
210 {
211  NS_LOG_FUNCTION (this);
212 
213  if (m_state == NOT_STARTED)
214  {
215  m_httpVariables->Initialize ();
216  OpenConnection ();
217  }
218  else
219  {
220  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
221  << " for StartApplication().");
222  }
223 }
224 
225 
226 void
228 {
229  NS_LOG_FUNCTION (this);
230 
233  m_socket->Close ();
235  MakeNullCallback<void, Ptr<Socket> > ());
237 }
238 
239 
240 void
242 {
243  NS_LOG_FUNCTION (this << socket);
244 
245  if (m_state == CONNECTING)
246  {
247  NS_ASSERT_MSG (m_socket == socket, "Invalid socket.");
250  this));
254  }
255  else
256  {
257  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
258  << " for ConnectionSucceeded().");
259  }
260 }
261 
262 
263 void
265 {
266  NS_LOG_FUNCTION (this << socket);
267 
268  if (m_state == CONNECTING)
269  {
270  NS_LOG_ERROR ("Client failed to connect"
271  << " to remote address " << m_remoteServerAddress
272  << " port " << m_remoteServerPort << ".");
273  }
274  else
275  {
276  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
277  << " for ConnectionFailed().");
278  }
279 }
280 
281 
282 void
284 {
285  NS_LOG_FUNCTION (this << socket);
286 
288 
289  if (socket->GetErrno () != Socket::ERROR_NOTERROR)
290  {
291  NS_LOG_ERROR (this << " Connection has been terminated,"
292  << " error code: " << socket->GetErrno () << ".");
293  }
294 
296  MakeNullCallback<void, Ptr<Socket> > ());
297 
299 }
300 
301 
302 void
304 {
305  NS_LOG_FUNCTION (this << socket);
306 
308  if (socket->GetErrno () != Socket::ERROR_NOTERROR)
309  {
310  NS_LOG_ERROR (this << " Connection has been terminated,"
311  << " error code: " << socket->GetErrno () << ".");
312  }
313 
315 }
316 
317 
318 void
320 {
321  NS_LOG_FUNCTION (this << socket);
322 
323  Ptr<Packet> packet;
324  Address from;
325 
326  while ((packet = socket->RecvFrom (from)))
327  {
328  if (packet->GetSize () == 0)
329  {
330  break; // EOF
331  }
332 
333 #ifdef NS3_LOG_ENABLE
334  // Some log messages.
336  {
337  NS_LOG_INFO (this << " A packet of " << packet->GetSize () << " bytes"
338  << " received from " << InetSocketAddress::ConvertFrom (from).GetIpv4 ()
339  << " port " << InetSocketAddress::ConvertFrom (from).GetPort ()
340  << " / " << InetSocketAddress::ConvertFrom (from) << ".");
341  }
342  else if (Inet6SocketAddress::IsMatchingType (from))
343  {
344  NS_LOG_INFO (this << " A packet of " << packet->GetSize () << " bytes"
345  << " received from " << Inet6SocketAddress::ConvertFrom (from).GetIpv6 ()
346  << " port " << Inet6SocketAddress::ConvertFrom (from).GetPort ()
347  << " / " << Inet6SocketAddress::ConvertFrom (from) << ".");
348  }
349 #endif /* NS3_LOG_ENABLE */
350 
351  m_rxTrace (packet, from);
352 
353  switch (m_state)
354  {
356  ReceiveMainObject (packet, from);
357  break;
359  ReceiveEmbeddedObject (packet, from);
360  break;
361  default:
362  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
363  << " for ReceivedData().");
364  break;
365  }
366 
367  } // end of `while ((packet = socket->RecvFrom (from)))`
368 
369 } // end of `void ReceivedDataCallback (Ptr<Socket> socket)`
370 
371 
372 void
374 {
375  NS_LOG_FUNCTION (this);
376 
379  {
382 
383  int ret;
384 
386  {
387  ret = m_socket->Bind ();
388  NS_LOG_DEBUG (this << " Bind() return value= " << ret
389  << " GetErrNo= " << m_socket->GetErrno () << ".");
390 
392  InetSocketAddress inetSocket = InetSocketAddress (ipv4,
394  NS_LOG_INFO (this << " Connecting to " << ipv4
395  << " port " << m_remoteServerPort
396  << " / " << inetSocket << ".");
397  ret = m_socket->Connect (inetSocket);
398  NS_LOG_DEBUG (this << " Connect() return value= " << ret
399  << " GetErrNo= " << m_socket->GetErrno () << ".");
400  }
402  {
403  ret = m_socket->Bind6 ();
404  NS_LOG_DEBUG (this << " Bind6() return value= " << ret
405  << " GetErrNo= " << m_socket->GetErrno () << ".");
406 
408  Inet6SocketAddress inet6Socket = Inet6SocketAddress (ipv6,
410  NS_LOG_INFO (this << " connecting to " << ipv6
411  << " port " << m_remoteServerPort
412  << " / " << inet6Socket << ".");
413  ret = m_socket->Connect (inet6Socket);
414  NS_LOG_DEBUG (this << " Connect() return value= " << ret
415  << " GetErrNo= " << m_socket->GetErrno () << ".");
416  }
417 
418  NS_UNUSED (ret); // Mute compiler warning.
419  NS_ASSERT_MSG (m_socket != 0, "Failed creating socket.");
420 
422 
424  this),
426  this));
428  this),
430  this));
432  this));
433  m_socket->SetAttribute ("MaxSegLifetime", DoubleValue (0.02)); // 20 ms.
434 
435  } // end of `if (m_state == {NOT_STARTED, EXPECTING_EMBEDDED_OBJECT, PARSING_MAIN_OBJECT, READING})`
436  else
437  {
438  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
439  << " for OpenConnection().");
440  }
441 
442 } // end of `void OpenConnection ()`
443 
444 
445 void
447 {
448  NS_LOG_FUNCTION (this);
449 
450  if (m_state == CONNECTING || m_state == READING)
451  {
452  ThreeGppHttpHeader header;
453  header.SetContentLength (0); // Request does not need any content length.
455  header.SetClientTs (Simulator::Now ());
456 
457  const uint32_t requestSize = m_httpVariables->GetRequestSize ();
458  Ptr<Packet> packet = Create<Packet> (requestSize);
459  packet->AddHeader (header);
460  const uint32_t packetSize = packet->GetSize ();
462  m_txTrace (packet);
463  const int actualBytes = m_socket->Send (packet);
464  NS_LOG_DEBUG (this << " Send() packet " << packet
465  << " of " << packet->GetSize () << " bytes,"
466  << " return value= " << actualBytes << ".");
467  if (actualBytes != static_cast<int> (packetSize))
468  {
469  NS_LOG_ERROR (this << " Failed to send request for embedded object,"
470  << " GetErrNo= " << m_socket->GetErrno () << ","
471  << " waiting for another Tx opportunity.");
472  }
473  else
474  {
476  }
477  }
478  else
479  {
480  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
481  << " for RequestMainObject().");
482  }
483 
484 } // end of `void RequestMainObject ()`
485 
486 
487 void
489 {
490  NS_LOG_FUNCTION (this);
491 
494  {
496  {
497  ThreeGppHttpHeader header;
498  header.SetContentLength (0); // Request does not need any content length.
500  header.SetClientTs (Simulator::Now ());
501 
502  const uint32_t requestSize = m_httpVariables->GetRequestSize ();
503  Ptr<Packet> packet = Create<Packet> (requestSize);
504  packet->AddHeader (header);
505  const uint32_t packetSize = packet->GetSize ();
507  m_txTrace (packet);
508  const int actualBytes = m_socket->Send (packet);
509  NS_LOG_DEBUG (this << " Send() packet " << packet
510  << " of " << packet->GetSize () << " bytes,"
511  << " return value= " << actualBytes << ".");
512 
513  if (actualBytes != static_cast<int> (packetSize))
514  {
515  NS_LOG_ERROR (this << " Failed to send request for embedded object,"
516  << " GetErrNo= " << m_socket->GetErrno () << ","
517  << " waiting for another Tx opportunity.");
518  }
519  else
520  {
523  }
524  }
525  else
526  {
527  NS_LOG_WARN (this << " No embedded object to be requested.");
528  }
529  }
530  else
531  {
532  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
533  << " for RequestEmbeddedObject().");
534  }
535 
536 } // end of `void RequestEmbeddedObject ()`
537 
538 
539 void
541 {
542  NS_LOG_FUNCTION (this << packet << from);
543 
545  {
546  /*
547  * In the following call to Receive(), #m_objectBytesToBeReceived *will*
548  * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
549  * ThreeGppHttpHeader will be removed from the packet, if it is the first
550  * packet of the object to be received; the header will be available in
551  * #m_constructedPacketHeader.
552  * #m_constructedPacket will also be updated.
553  */
554  Receive (packet);
555  m_rxMainObjectPacketTrace (packet);
556 
558  {
559  /*
560  * There are more packets of this main object, so just stay still
561  * and wait until they arrive.
562  */
563  NS_LOG_INFO (this << " " << m_objectBytesToBeReceived << " byte(s)"
564  << " remains from this chunk of main object.");
565  }
566  else
567  {
568  /*
569  * This is the last packet of this main object. Acknowledge the
570  * reception of a whole main object
571  */
572  NS_LOG_INFO (this << " Finished receiving a main object.");
574 
575  if (!m_objectServerTs.IsZero ())
576  {
578  m_objectServerTs = MilliSeconds (0); // Reset back to zero.
579  }
580 
581  if (!m_objectClientTs.IsZero ())
582  {
584  m_objectClientTs = MilliSeconds (0); // Reset back to zero.
585  }
586 
587  EnterParsingTime ();
588 
589  } // end of else of `if (m_objectBytesToBeReceived > 0)`
590 
591  } // end of `if (m_state == EXPECTING_MAIN_OBJECT)`
592  else
593  {
594  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
595  << " for ReceiveMainObject().");
596  }
597 
598 } // end of `void ReceiveMainObject (Ptr<Packet> packet)`
599 
600 
601 void
603 {
604  NS_LOG_FUNCTION (this << packet << from);
605 
607  {
608  /*
609  * In the following call to Receive(), #m_objectBytesToBeReceived *will*
610  * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated.
611  * ThreeGppHttpHeader will be removed from the packet, if it is the first
612  * packet of the object to be received; the header will be available in
613  * #m_constructedPacket, which will also be updated.
614  */
615  Receive (packet);
617 
619  {
620  /*
621  * There are more packets of this embedded object, so just stay
622  * still and wait until they arrive.
623  */
624  NS_LOG_INFO (this << " " << m_objectBytesToBeReceived << " byte(s)"
625  << " remains from this chunk of embedded object");
626  }
627  else
628  {
629  /*
630  * This is the last packet of this embedded object. Acknowledge
631  * the reception of a whole embedded object
632  */
633  NS_LOG_INFO (this << " Finished receiving an embedded object.");
635 
636  if (!m_objectServerTs.IsZero ())
637  {
639  m_objectServerTs = MilliSeconds (0); // Reset back to zero.
640  }
641 
642  if (!m_objectClientTs.IsZero ())
643  {
645  m_objectClientTs = MilliSeconds (0); // Reset back to zero.
646  }
647 
649  {
651  << " more embedded object(s) to be requested.");
652  // Immediately request another using the existing connection.
655  }
656  else
657  {
658  /*
659  * There is no more embedded object, the web page has been
660  * downloaded completely. Now is the time to read it.
661  */
662  NS_LOG_INFO (this << " Finished receiving a web page.");
663  EnterReadingTime ();
664  }
665 
666  } // end of else of `if (m_objectBytesToBeReceived > 0)`
667 
668  } // end of `if (m_state == EXPECTING_EMBEDDED_OBJECT)`
669  else
670  {
671  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
672  << " for ReceiveEmbeddedObject().");
673  }
674 
675 } // end of `void ReceiveEmbeddedObject (Ptr<Packet> packet)`
676 
677 
678 void
680 {
681  NS_LOG_FUNCTION (this << packet);
682 
683  /* In a "real" HTTP message the message size is coded differently. The use of a header
684  * is to avoid the burden of doing a real message parser.
685  */
686  bool firstPacket = false;
687 
688  if (m_objectBytesToBeReceived == 0)
689  {
690  // This is the first packet of the object.
691  firstPacket = true;
692 
693  // Remove the header in order to calculate remaining data to be received.
694  ThreeGppHttpHeader httpHeader;
695  packet->RemoveHeader (httpHeader);
696 
698  m_objectClientTs = httpHeader.GetClientTs ();
699  m_objectServerTs = httpHeader.GetServerTs ();
700 
701  // Take a copy for constructed packet trace. Note that header is included.
702  m_constructedPacket = packet->Copy ();
703  m_constructedPacket->AddHeader (httpHeader);
704  }
705  uint32_t contentSize = packet->GetSize ();
706 
707  /* Note that the packet does not contain header at this point.
708  * The content is purely raw data, which was the only intended data to be received.
709  */
710  if (m_objectBytesToBeReceived < contentSize)
711  {
712  NS_LOG_WARN (this << " The received packet"
713  << " (" << contentSize << " bytes of content)"
714  << " is larger than"
715  << " the content that we expected to receive"
716  << " (" << m_objectBytesToBeReceived << " bytes).");
717  // Stop expecting any more packet of this object.
719  m_constructedPacket = NULL;
720  }
721  else
722  {
723  m_objectBytesToBeReceived -= contentSize;
724  if (!firstPacket)
725  {
726  Ptr<Packet> packetCopy = packet->Copy ();
727  m_constructedPacket->AddAtEnd (packetCopy);
728  }
729  }
730 
731 } // end of `void Receive (packet)`
732 
733 
734 void
736 {
737  NS_LOG_FUNCTION (this);
738 
740  {
741  const Time parsingTime = m_httpVariables->GetParsingTime ();
742  NS_LOG_INFO (this << " The parsing of this main object"
743  << " will complete in "
744  << parsingTime.GetSeconds () << " seconds.");
746  parsingTime, &ThreeGppHttpClient::ParseMainObject, this);
748  }
749  else
750  {
751  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
752  << " for EnterParsingTime().");
753  }
754 }
755 
756 
757 void
759 {
760  NS_LOG_FUNCTION (this);
761 
763  {
764  m_embeddedObjectsToBeRequested = m_httpVariables->GetNumOfEmbeddedObjects ();
765  NS_LOG_INFO (this << " Parsing has determined "
767  << " embedded object(s) in the main object.");
768 
770  {
771  /*
772  * Immediately request the first embedded object using the
773  * existing connection.
774  */
777  }
778  else
779  {
780  /*
781  * There is no embedded object in the main object. So sit back and
782  * enjoy the plain web page.
783  */
784  NS_LOG_INFO (this << " Finished receiving a web page.");
785  EnterReadingTime ();
786  }
787 
788  }
789  else
790  {
791  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
792  << " for ParseMainObject().");
793  }
794 
795 } // end of `void ParseMainObject ()`
796 
797 
798 void
800 {
801  NS_LOG_FUNCTION (this);
802 
804  {
805  const Time readingTime = m_httpVariables->GetReadingTime ();
806  NS_LOG_INFO (this << " Client will finish reading this web page in "
807  << readingTime.GetSeconds () << " seconds.");
808 
809  // Schedule a request of another main object once the reading time expires.
811  readingTime, &ThreeGppHttpClient::RequestMainObject, this);
813  }
814  else
815  {
816  NS_FATAL_ERROR ("Invalid state " << GetStateString ()
817  << " for EnterReadingTime().");
818  }
819 }
820 
821 
822 void
824 {
825  NS_LOG_FUNCTION (this);
826 
828  {
829  NS_LOG_INFO (this << " Canceling RequestMainObject() which is due in "
831  << " seconds.");
833  }
834 
836  {
837  NS_LOG_INFO (this << " Canceling RequestEmbeddedObject() which is due in "
839  << " seconds.");
841  }
842 
844  {
845  NS_LOG_INFO (this << " Canceling ParseMainObject() which is due in "
847  << " seconds.");
849  }
850 }
851 
852 
853 void
855 {
856  const std::string oldState = GetStateString ();
857  const std::string newState = GetStateString (state);
858  NS_LOG_FUNCTION (this << oldState << newState);
859 
860  if ((state == EXPECTING_MAIN_OBJECT) || (state == EXPECTING_EMBEDDED_OBJECT))
861  {
863  {
864  NS_FATAL_ERROR ("Cannot start a new receiving session"
865  << " if the previous object"
866  << " (" << m_objectBytesToBeReceived << " bytes)"
867  << " is not completely received yet.");
868  }
869  }
870 
871  m_state = state;
872  NS_LOG_INFO (this << " HttpClient " << oldState
873  << " --> " << newState << ".");
874  m_stateTransitionTrace (oldState, newState);
875 }
876 
877 
878 } // end of `namespace ns3`
879 
static bool IsMatchingType(const Address &address)
If the Address matches the type.
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition: simulator.cc:202
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
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.
Time m_objectClientTs
The client time stamp of the ThreeGppHttpHeader from the last received packet.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
User reading a web page that has just been received.
an Inet address class
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ns3::TracedCallback< Ptr< const Packet > > m_rxEmbeddedObjectPacketTrace
The TxEmbeddedObjectPacket trace source.
void EnterReadingTime()
Becomes idle for a randomly determined amount of time, and then triggers RequestMainObject().
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
virtual int Bind6()=0
Allocate a local IPv6 endpoint for this socket.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
static const uint32_t packetSize
uint32_t m_objectBytesToBeReceived
According to the content length specified by the ThreeGppHttpHeader.
void OpenConnection()
Initialize m_socket to connect to the destination web server at m_remoteServerAddress and m_remoteSer...
Parsing a main object that has just been received.
State_t GetState() const
Returns the current state of the application.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:361
void ReceiveMainObject(Ptr< Packet > packet, const Address &from)
Receive a packet of main object from the destination web server.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
Header used by web browsing applications to transmit information about content type, content length and timestamps for delay statistics.
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
Sent the server a request for a main object and waiting to receive the packets.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
void ErrorCloseCallback(Ptr< Socket > socket)
Invoked when connection between m_socket and the web sever is terminated.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event&#39;s associated function will not be invoked when it expires...
Definition: simulator.cc:290
static TypeId GetTypeId()
Returns the object TypeId.
Callback< R > MakeNullCallback(void)
Definition: callback.h:1786
virtual enum Socket::SocketErrno GetErrno(void) const =0
Get last error number.
a polymophic address class
Definition: address.h:90
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
ns3::TracedCallback< Ptr< const Packet > > m_txEmbeddedObjectRequestTrace
The TxEmbeddedObjectRequest trace source.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:335
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionEstablishedTrace
The ConnectionEstablished trace source.
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: address.h:278
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:227
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1390
bool IsZero(void) const
Definition: nstime.h:294
The base class for all ns3 applications.
Definition: application.h:60
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
The Rx trace source.
ns3::TracedCallback< const Time &, const Address & > m_rxDelayTrace
The RxDelay trace source.
State_t m_state
The current state of the client application. Begins with NOT_STARTED.
An Inet6 address class.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1610
ns3::TracedCallback< Ptr< const Packet > > m_txMainObjectRequestTrace
The TxMainObjectRequest trace source.
void SetRecvCallback(Callback< void, Ptr< Socket > >)
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:71
void SetContentLength(uint32_t contentLength)
static bool IsMatchingType(const Address &address)
Ptr< Node > GetNode() const
Definition: application.cc:104
void ReceiveEmbeddedObject(Ptr< Packet > packet, const Address &from)
Receive a packet of embedded object from the destination web server.
static TypeId GetTypeId(void)
Get the type ID.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual void DoDispose(void)
Destructor implementation.
Definition: application.cc:83
EventId m_eventRequestMainObject
An event of either RequestMainObject() or OpenConnection(), scheduled to trigger after a connection h...
void RequestMainObject()
Send a request object for a main object to the destination web server.
void ParseMainObject()
Randomly determines the number of embedded objects in the main object.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
void ReceivedDataCallback(Ptr< Socket > socket)
Invoked when m_socket receives some packet data.
Ptr< ThreeGppHttpVariables > m_httpVariables
The Variables attribute.
static bool IsExpired(const EventId &id)
Check if an event has already run or been cancelled.
Definition: simulator.cc:300
uint16_t GetPort(void) const
Container of various random variables to assist in generating web browsing traffic pattern...
Before StartApplication() is invoked.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
std::string GetStateString() const
Returns the current state of the application in string format.
void EnterParsingTime()
Becomes idle for a randomly determined amount of time, and then triggers ParseMainObject().
State_t
The possible states of the application.
void SwitchToState(State_t state)
Change the state of the client.
void RequestEmbeddedObject()
Send a request object for an embedded object to the destination web server.
Ptr< const AttributeChecker > MakeAddressChecker(void)
Definition: address.cc:172
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:1579
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxMainObjectTrace
The TxMainObject trace source.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
Sent the server a connection request and waiting for the server to be accept it.
ns3::TracedCallback< const Time &, const Address & > m_rxRttTrace
The RxRtt trace source.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
AttributeValue implementation for Address.
Definition: address.h:278
void SetClientTs(Time clientTs)
void Receive(Ptr< Packet > packet)
Simulate a consumption of the received packet by subtracting the packet size from the internal counte...
Ptr< Packet > m_constructedPacket
The packet constructed of one or more parts with ThreeGppHttpHeader.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
ns3::TracedCallback< Ptr< const Packet > > m_rxMainObjectPacketTrace
The TxMainObjectPacket trace source.
virtual void StartApplication()
Application specific startup code.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxEmbeddedObjectTrace
The TxEmbeddedObject trace source.
static bool IsMatchingType(const Address &addr)
If the address match.
Ptr< Socket > GetSocket() const
Returns a pointer to the associated socket.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionClosedTrace
The ConnectionClosed trace source.
Address m_remoteServerAddress
The RemoteServerAddress attribute. The address of the web server.
static bool IsFinished(void)
Check if the simulation should finish.
Definition: simulator.cc:163
Ptr< T > CreateObject(void)
Create an object by type, with varying number of constructor parameters.
Definition: object.h:533
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
static Ipv4Address ConvertFrom(const Address &address)
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:84
uint16_t m_remoteServerPort
The RemoteServerPort attribute.
EventId m_eventRequestEmbeddedObject
An event of either RequestEmbeddedObject() or OpenConnection().
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
void CancelAllPendingEvents()
Cancels m_eventRequestMainObject, m_eventRequestEmbeddedObject, and m_eventParseMainObject.
ThreeGppHttpClient()
Creates a new instance of HTTP client application.
virtual void StopApplication()
Application specific shutdown code.
uint16_t GetPort(void) const
Get the port.
Sent the server a request for an embedded object and waiting to receive the packets.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
ns3::TracedCallback< Ptr< const Packet > > m_txTrace
The Tx trace source.
virtual int Close(void)=0
Close a socket.
void ConnectionFailedCallback(Ptr< Socket > socket)
Invoked when m_socket cannot establish a connection with the web server.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
uint32_t m_embeddedObjectsToBeRequested
Determined after parsing the main object.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:187
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
void ConnectionSucceededCallback(Ptr< Socket > socket)
Invoked when a connection is established successfully on m_socket.
Ptr< Socket > m_socket
The socket for sending and receiving packets to/from the web server.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
static bool IsMatchingType(const Address &address)
void SetContentType(ContentType_t contentType)
virtual void DoDispose()
Destructor implementation.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
EventId m_eventParseMainObject
An event of ParseMainObject(), scheduled to trigger after parsing time has elapsed.
After StopApplication() is invoked.
Ipv4Address GetIpv4(void) const
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.