14#include "ns3/address-utils.h"
15#include "ns3/callback.h"
16#include "ns3/double.h"
18#include "ns3/packet.h"
19#include "ns3/pointer.h"
20#include "ns3/simulator.h"
21#include "ns3/socket.h"
22#include "ns3/tcp-socket-factory.h"
23#include "ns3/uinteger.h"
45 TypeId(
"ns3::ThreeGppHttpClient")
47 .AddConstructor<ThreeGppHttpClient>()
50 "Variable collection, which is used to control e.g. timing and HTTP request size.",
55 .AddAttribute(
"RemoteServerAddress",
56 "The address of the destination server.",
61 "Replaced by Remote in ns-3.44.")
63 .AddAttribute(
"RemoteServerPort",
64 "The destination port of the outbound packets.",
69 "Replaced by Remote in ns-3.44.")
70 .AddTraceSource(
"RxPage",
71 "A page has been received.",
73 "ns3::ThreeGppHttpClient::RxPageTracedCallback")
75 "ConnectionEstablished",
76 "Connection to the destination web server has been established.",
78 "ns3::ThreeGppHttpClient::TracedCallback")
79 .AddTraceSource(
"ConnectionClosed",
80 "Connection to the destination web server is closed.",
82 "ns3::ThreeGppHttpClient::TracedCallback")
84 "TxMainObjectRequest",
85 "Sent a request for a main object.",
87 "ns3::Packet::TracedCallback")
89 "TxEmbeddedObjectRequest",
90 "Sent a request for an embedded object.",
92 "ns3::Packet::TracedCallback")
93 .AddTraceSource(
"RxMainObjectPacket",
94 "A packet of main object has been received.",
96 "ns3::Packet::TracedCallback")
97 .AddTraceSource(
"RxMainObject",
98 "Received a whole main object. Header is included.",
100 "ns3::ThreeGppHttpClient::TracedCallback")
102 "RxEmbeddedObjectPacket",
103 "A packet of embedded object has been received.",
105 "ns3::Packet::TracedCallback")
106 .AddTraceSource(
"RxEmbeddedObject",
107 "Received a whole embedded object. Header is included.",
109 "ns3::ThreeGppHttpClient::TracedCallback")
110 .AddTraceSource(
"Rx",
111 "General trace for receiving a packet of any kind.",
113 "ns3::Packet::PacketAddressTracedCallback")
114 .AddTraceSource(
"RxDelay",
115 "General trace of delay for receiving a complete object.",
117 "ns3::Application::DelayAddressCallback")
120 "General trace of round trip delay time for receiving a complete object.",
122 "ns3::Application::DelayAddressCallback")
123 .AddTraceSource(
"StateTransition",
124 "Trace fired upon every HTTP client state transition.",
126 "ns3::Application::StateTransitionCallback");
179 return "NOT_STARTED";
183 return "EXPECTING_MAIN_OBJECT";
185 return "PARSING_MAIN_OBJECT";
187 return "EXPECTING_EMBEDDED_OBJECT";
194 return "FATAL_ERROR";
277 <<
" error code: " << socket->GetErrno() <<
".");
295 <<
" error code: " << socket->GetErrno() <<
".");
307 while (
auto packet = socket->RecvFrom(from))
309 if (packet->GetSize() == 0)
318 NS_LOG_INFO(
this <<
" A packet of " << packet->GetSize() <<
" bytes"
325 NS_LOG_INFO(
this <<
" A packet of " << packet->GetSize() <<
" bytes"
385 packet->AddHeader(header);
389 const auto actualBytes =
m_socket->Send(packet);
390 NS_LOG_DEBUG(
this <<
" Send() packet " << packet <<
" of " << packet->GetSize() <<
" bytes,"
391 <<
" return value= " << actualBytes <<
".");
392 if (actualBytes !=
static_cast<int>(
packetSize))
394 NS_LOG_ERROR(
this <<
" Failed to send request for embedded object,"
395 <<
" GetErrNo= " <<
m_socket->GetErrno() <<
","
396 <<
" waiting for another Tx opportunity.");
418 NS_LOG_WARN(
this <<
" No embedded object to be requested.");
429 packet->AddHeader(header);
433 const auto actualBytes =
m_socket->Send(packet);
434 NS_LOG_DEBUG(
this <<
" Send() packet " << packet <<
" of " << packet->GetSize() <<
" bytes,"
435 <<
" return value= " << actualBytes <<
".");
437 if (actualBytes !=
static_cast<int>(
packetSize))
439 NS_LOG_ERROR(
this <<
" Failed to send request for embedded object,"
440 <<
" GetErrNo= " <<
m_socket->GetErrno() <<
","
441 <<
" waiting for another Tx opportunity.");
478 <<
" remains from this chunk of main object.");
486 NS_LOG_INFO(
this <<
" Finished receiving a main object.");
531 <<
" remains from this chunk of embedded object");
539 NS_LOG_INFO(
this <<
" Finished receiving an embedded object.");
557 <<
" more embedded object(s) to be requested.");
568 NS_LOG_INFO(
this <<
" Finished receiving a web page.");
582 bool firstPacket =
false;
591 packet->RemoveHeader(httpHeader);
601 auto contentSize = packet->GetSize();
609 NS_LOG_WARN(
this <<
" The received packet (" << contentSize <<
" bytes of content)"
610 <<
" is larger than the content that we expected to receive ("
621 auto packetCopy = packet->Copy();
638 NS_LOG_INFO(
this <<
" The parsing of this main object will complete in "
639 << parsingTime.As(
Time::S) <<
".");
659 <<
" embedded object(s) in the main object.");
676 NS_LOG_INFO(
this <<
" Finished receiving a web page.");
693 NS_LOG_INFO(
this <<
" Client will finish reading this web page in " << readingTime.As(
Time::S)
709 NS_LOG_INFO(
this <<
" Canceling RequestMainObject() which is due in "
716 NS_LOG_INFO(
this <<
" Canceling RequestEmbeddedObject() which is due in "
724 NS_LOG_INFO(
this <<
" Canceling ParseMainObject() which is due in "
741 NS_FATAL_ERROR(
"Cannot start a new receiving session if the previous object ("
743 <<
" bytes) is not completely received yet.");
748 NS_LOG_INFO(
this <<
" HttpClient " << oldState <<
" --> " << newState <<
".");
a polymophic address class
AttributeValue implementation for Address.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
static bool IsMatchingType(const Address &address)
static bool IsMatchingType(const Address &address)
If the Address matches the type.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
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...
static bool IsFinished()
Check if the simulation should finish.
static Time Now()
Return the current simulation virtual time.
static bool IsExpired(const EventId &id)
Check if an event has already run or been cancelled.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
TypeId m_protocolTid
Protocol TypeId value.
SourceApplication(bool allowPacketSocket=true)
Constructor.
Ptr< Socket > m_socket
Socket.
void DoDispose() override
Destructor implementation.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced Callback: transmitted packets.
Address m_peer
Peer address.
bool CloseSocket()
Close the socket.
Model application which simulates the traffic of a web browser.
ns3::TracedCallback< const Time &, const Address & > m_rxRttTrace
The RxRtt trace source.
Time m_pageLoadStartTs
The time stamp when the page started loading.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, const Time &, uint32_t, uint32_t > m_rxPageTrace
The RxPage trace source.
void SetPort(uint16_t port)
set the remote port (temporary function until deprecated attributes are removed)
void ReceiveMainObject(Ptr< Packet > packet, const Address &from)
Receive a packet of main object from the destination web server.
void DoConnectionFailed(Ptr< Socket > socket) override
Application specific code for child subclasses upon a Connection Failed event.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionClosedTrace
The ConnectionClosed trace source.
std::optional< uint16_t > m_peerPort
The RemoteServerPort attribute.
ns3::TracedCallback< const Time &, const Address & > m_rxDelayTrace
The RxDelay trace source.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxEmbeddedObjectTrace
The TxEmbeddedObject trace source.
void DoStartApplication() override
Application specific startup code for child subclasses.
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.
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.
void RequestEmbeddedObject()
Send a request object for an embedded object to the destination web server.
void CancelEvents() override
Cancel all pending events.
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 DoConnectionSucceeded(Ptr< Socket > socket) override
Application specific code for child subclasses upon a Connection Succeed event.
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.
static TypeId GetTypeId()
Returns the object TypeId.
void ErrorCloseCallback(Ptr< Socket > socket)
Invoked when connection between m_socket and the web sever is terminated.
EventId m_eventRequestMainObject
An event of either RequestMainObject() or OpenConnection(), scheduled to trigger after a connection h...
uint32_t m_numberBytesPage
Number of bytes received for the current page.
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.
ns3::TracedCallback< Ptr< const Packet > > m_rxMainObjectPacketTrace
The TxMainObjectPacket trace source.
void SetRemote(const Address &addr) override
set the remote address
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
void RequestMainObject()
Send a request object for a main object to the destination web server.
void DoStopApplication() override
Application specific shutdown code for child subclasses.
Time m_objectServerTs
The server time stamp of the ThreeGppHttpHeader from the last received packet.
void NormalCloseCallback(Ptr< Socket > socket)
Invoked when connection between m_socket and the web sever is terminated.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionEstablishedTrace
The ConnectionEstablished trace source.
ns3::TracedCallback< Ptr< const Packet > > m_txEmbeddedObjectRequestTrace
The TxEmbeddedObjectRequest trace source.
void ReceivedDataCallback(Ptr< Socket > socket)
Invoked when m_socket receives some packet data.
ns3::TracedCallback< Ptr< const Packet > > m_rxEmbeddedObjectPacketTrace
The TxEmbeddedObjectPacket trace source.
void Receive(Ptr< Packet > packet)
Simulate a consumption of the received packet by subtracting the packet size from the internal counte...
void ReceiveEmbeddedObject(Ptr< Packet > packet, const Address &from)
Receive a packet of embedded object from the destination web server.
void OpenConnection()
Initialize m_socket to connect to the destination web server at m_peer and m_peerPort and set up call...
std::string GetStateString() const
Returns the current state of the application in string format.
EventId m_eventRequestEmbeddedObject
An event of either RequestEmbeddedObject() or OpenConnection().
Container of various random variables to assist in generating web browsing traffic pattern.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
@ DEPRECATED
Attribute or trace source is deprecated; user is warned.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeChecker > MakeAddressChecker()
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Callback< R, Args... > MakeNullCallback()
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Address ConvertToSocketAddress(const Address &address, uint16_t port)
Convert IPv4/IPv6 address with port to a socket address.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
static const uint32_t packetSize
Packet size generated at the AP.