applications: (merges !1348) Add RxPage trace source to ThreeGppHttpClient

This commit is contained in:
Carlos Natalino
2023-04-25 12:15:11 +00:00
committed by Tommaso Pecorella
parent 703a9ac5e0
commit 511132dd5c
3 changed files with 66 additions and 0 deletions

View File

@@ -93,6 +93,17 @@ ClientEmbeddedObjectReceived(Ptr<const ThreeGppHttpClient>, Ptr<const Packet> pa
}
}
void
ClientPageReceived(Ptr<const ThreeGppHttpClient> client,
const Time& time,
uint32_t numObjects,
uint32_t numBytes)
{
NS_LOG_INFO("Client " << client << " has received a page that took " << time.As(Time::MS)
<< " ms to load with " << numObjects << " objects and " << numBytes
<< " bytes.");
}
int
main(int argc, char* argv[])
{
@@ -163,6 +174,7 @@ main(int argc, char* argv[])
httpClient->TraceConnectWithoutContext("RxEmbeddedObject",
MakeCallback(&ClientEmbeddedObjectReceived));
httpClient->TraceConnectWithoutContext("Rx", MakeCallback(&ClientRx));
httpClient->TraceConnectWithoutContext("RxPage", MakeCallback(&ClientPageReceived));
// Stop browsing after 30 minutes
clientApps.Stop(Seconds(simTimeSec));

View File

@@ -47,6 +47,9 @@ ThreeGppHttpClient::ThreeGppHttpClient()
m_objectClientTs(MilliSeconds(0)),
m_objectServerTs(MilliSeconds(0)),
m_embeddedObjectsToBeRequested(0),
m_pageLoadStartTs(MilliSeconds(0)),
m_numberEmbeddedObjectsRequested(0),
m_numberBytesPage(0),
m_httpVariables(CreateObject<ThreeGppHttpVariables>())
{
NS_LOG_FUNCTION(this);
@@ -76,6 +79,10 @@ ThreeGppHttpClient::GetTypeId()
UintegerValue(80), // the default HTTP port
MakeUintegerAccessor(&ThreeGppHttpClient::m_remoteServerPort),
MakeUintegerChecker<uint16_t>())
.AddTraceSource("RxPage",
"A page has been received.",
MakeTraceSourceAccessor(&ThreeGppHttpClient::m_rxPageTrace),
"ns3::ThreeGppHttpClient::RxPageTracedCallback")
.AddTraceSource(
"ConnectionEstablished",
"Connection to the destination web server has been established.",
@@ -447,6 +454,7 @@ ThreeGppHttpClient::RequestMainObject()
else
{
SwitchToState(EXPECTING_MAIN_OBJECT);
m_pageLoadStartTs = Simulator::Now(); // start counting page loading time
}
}
else
@@ -628,6 +636,7 @@ ThreeGppHttpClient::ReceiveEmbeddedObject(Ptr<Packet> packet, const Address& fro
* downloaded completely. Now is the time to read it.
*/
NS_LOG_INFO(this << " Finished receiving a web page.");
FinishReceivingPage(); // trigger callback for page loading time
EnterReadingTime();
}
@@ -669,6 +678,7 @@ ThreeGppHttpClient::Receive(Ptr<Packet> packet)
m_constructedPacket->AddHeader(httpHeader);
}
uint32_t contentSize = packet->GetSize();
m_numberBytesPage += contentSize; // increment counter of page size
/* Note that the packet does not contain header at this point.
* The content is purely raw data, which was the only intended data to be received.
@@ -724,6 +734,8 @@ ThreeGppHttpClient::ParseMainObject()
if (m_state == PARSING_MAIN_OBJECT)
{
m_embeddedObjectsToBeRequested = m_httpVariables->GetNumOfEmbeddedObjects();
// saving total number of embedded objects
m_numberEmbeddedObjectsRequested = m_embeddedObjectsToBeRequested;
NS_LOG_INFO(this << " Parsing has determined " << m_embeddedObjectsToBeRequested
<< " embedded object(s) in the main object.");
@@ -743,6 +755,7 @@ ThreeGppHttpClient::ParseMainObject()
* enjoy the plain web page.
*/
NS_LOG_INFO(this << " Finished receiving a web page.");
FinishReceivingPage(); // trigger callback for page loading time
EnterReadingTime();
}
}
@@ -826,4 +839,16 @@ ThreeGppHttpClient::SwitchToState(ThreeGppHttpClient::State_t state)
m_stateTransitionTrace(oldState, newState);
}
void
ThreeGppHttpClient::FinishReceivingPage()
{
m_rxPageTrace(this,
Simulator::Now() - m_pageLoadStartTs,
m_numberEmbeddedObjectsRequested,
m_numberBytesPage);
// Reset counter variables.
m_numberEmbeddedObjectsRequested = 0;
m_numberBytesPage = 0;
}
} // namespace ns3

View File

@@ -172,6 +172,20 @@ class ThreeGppHttpClient : public Application
*/
typedef void (*TracedCallback)(Ptr<const ThreeGppHttpClient> httpClient);
/**
* Callback signature for `RxPage` trace sources.
* \param httpClient Pointer to this instance of ThreeGppHttpClient,
* which is where the trace originated.
* \param time Elapsed time from the start to the end of the request.
* \param numObjects Number of objects downloaded, including main and
* embedded objects.
* \param numBytes Total number of bytes included in the page.
*/
typedef void (*RxPageTracedCallback)(Ptr<const ThreeGppHttpClient> httpClient,
const Time& time,
uint32_t numObjects,
uint32_t numBytes);
protected:
// Inherited from Object base class.
void DoDispose() override;
@@ -343,6 +357,12 @@ class ThreeGppHttpClient : public Application
*/
void SwitchToState(State_t state);
/**
* Finish receiving a page. This function should be called when a full-page
* finishes loading, including the main object and all embedded objects.
*/
void FinishReceivingPage();
/// The current state of the client application. Begins with NOT_STARTED.
State_t m_state;
/// The socket for sending and receiving packets to/from the web server.
@@ -357,6 +377,12 @@ class ThreeGppHttpClient : public Application
Time m_objectServerTs;
/// Determined after parsing the main object.
uint32_t m_embeddedObjectsToBeRequested;
/// The time stamp when the page started loading.
Time m_pageLoadStartTs;
/// Number of embedded objects to requested in the current page.
uint32_t m_numberEmbeddedObjectsRequested;
/// Number of bytes received for the current page.
uint32_t m_numberBytesPage;
// ATTRIBUTES
@@ -369,6 +395,9 @@ class ThreeGppHttpClient : public Application
// TRACE SOURCES
/// The `RxPage` trace source.
ns3::TracedCallback<Ptr<const ThreeGppHttpClient>, const Time&, uint32_t, uint32_t>
m_rxPageTrace;
/// The `ConnectionEstablished` trace source.
ns3::TracedCallback<Ptr<const ThreeGppHttpClient>> m_connectionEstablishedTrace;
/// The `ConnectionClosed` trace source.