From d45e1afeb350b36b231acb3ed0b548abf8bf31d2 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Tue, 5 Nov 2024 10:37:03 +0100 Subject: [PATCH] applications: Add state trace source to OnOffApplication --- CHANGES.md | 1 + src/applications/model/onoff-application.cc | 9 +++++++-- src/applications/model/onoff-application.h | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1d98e7ad1..336ca1653 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ This file is a best-effort approach to solving this issue; we will do our best b * (applications) Added two new base classes for source and sink applications, `SourceApplication` and `SinkApplication`, respectively. * (wifi) Changes have been made to the `WifiRemoteStationManager` interface for what concerns the update of the frame retry count of the MPDUs and the decision of dropping MPDUs (possibly based on the max retry limit). The `NeedRetransmission` method has been replaced by the `GetMpdusToDropOnTxFailure` method and the `DoNeedRetransmission` method has been replaced by the `DoGetMpdusToDropOnTxFailure` method. Also, the `DoIncrementRetryCountOnTxFailure` method has been added to implement custom policies for the update of the frame retry count of MPDUs upon transmission failure. +* (applications) Added an `OnOffState` trace source to `OnOffApplication`, to track whether the application is transmitting or not. ### Changes to existing API diff --git a/src/applications/model/onoff-application.cc b/src/applications/model/onoff-application.cc index 90675355f..0e5c99ea5 100644 --- a/src/applications/model/onoff-application.cc +++ b/src/applications/model/onoff-application.cc @@ -96,7 +96,11 @@ OnOffApplication::GetTypeId() .AddTraceSource("TxWithSeqTsSize", "A new packet is created with SeqTsSizeHeader", MakeTraceSourceAccessor(&OnOffApplication::m_txTraceWithSeqTsSize), - "ns3::PacketSink::SeqTsSizeCallback"); + "ns3::PacketSink::SeqTsSizeCallback") + .AddTraceSource("OnOffState", + "Application state (0-OFF, 1-ON)", + MakeTraceSourceAccessor(&OnOffApplication::m_state), + "ns3::TracedValueCallback::Bool"); return tid; } @@ -268,6 +272,7 @@ OnOffApplication::StartSending() m_lastStartTime = Simulator::Now(); ScheduleNextTx(); // Schedule the send packet event ScheduleStopEvent(); + m_state = true; } void @@ -275,8 +280,8 @@ OnOffApplication::StopSending() { NS_LOG_FUNCTION(this); CancelEvents(); - ScheduleStartEvent(); + m_state = false; } // Private helpers diff --git a/src/applications/model/onoff-application.h b/src/applications/model/onoff-application.h index 7b57ccf93..12311597e 100644 --- a/src/applications/model/onoff-application.h +++ b/src/applications/model/onoff-application.h @@ -20,6 +20,7 @@ #include "ns3/event-id.h" #include "ns3/ptr.h" #include "ns3/traced-callback.h" +#include "ns3/traced-value.h" namespace ns3 { @@ -189,6 +190,8 @@ class OnOffApplication : public SourceApplication * @param socket the not connected socket */ void ConnectionFailed(Ptr socket); + + TracedValue m_state; //!< State of application (0-OFF, 1-ON) }; } // namespace ns3