From a6d24b73bdc69febfc8193cd53e9ce382df54a2c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 14 May 2007 10:25:50 +0200 Subject: [PATCH] simplify the implementation --- src/applications/onoff-application.cc | 28 +++++++-------------------- src/applications/onoff-application.h | 2 -- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/applications/onoff-application.cc b/src/applications/onoff-application.cc index c2c468549..f47dd5855 100644 --- a/src/applications/onoff-application.cc +++ b/src/applications/onoff-application.cc @@ -61,11 +61,8 @@ uint32_t OnOffApplication::g_defaultSize = 512; m_residualBits(0), m_lastStartTime((HighPrecision)0), m_maxBytes(0xffffffff), - m_totBytes(0), - m_startStopScheduled(false), - m_sendScheduled(false) -{ -} + m_totBytes(0) +{} OnOffApplication::~OnOffApplication() {} @@ -112,32 +109,25 @@ void OnOffApplication::StartApplication() // Called at time specified by Star void OnOffApplication::StopApplication() // Called at time specified by Stop { - if (m_startStopScheduled) - { // Cancel the startStop event - Simulator::Cancel(m_startStopEvent); - m_startStopScheduled = false; - } - if (m_sendScheduled) + if (m_sendEvent.IsRunning ()) { // Cancel the pending send packet event - Simulator::Cancel(m_sendEvent); - m_sendScheduled = false; // Calculate residual bits since last packet sent Time delta(Simulator::Now() - m_lastStartTime); m_residualBits += (uint32_t)(m_cbrRate.GetBitRate() * delta.GetSeconds()); } + Simulator::Cancel(m_sendEvent); + Simulator::Cancel(m_startStopEvent); } // Event handlers void OnOffApplication::StartSending() { - m_startStopScheduled = true; ScheduleNextTx(); // Schedule the send packet event } void OnOffApplication::StopSending() { - m_startStopScheduled = true; - if (m_sendScheduled) Simulator::Cancel(m_sendEvent); + Simulator::Cancel(m_sendEvent); } // Private helpers @@ -148,7 +138,6 @@ void OnOffApplication::ScheduleNextTx() uint32_t bits = m_pktSize * 8 - m_residualBits; Time nextTime(Seconds (bits / static_cast(m_cbrRate.GetBitRate()))); // Time till next packet - m_sendScheduled = true; m_sendEvent = Simulator::Schedule(nextTime, &OnOffApplication::SendPacket, this); } else @@ -161,21 +150,18 @@ void OnOffApplication::ScheduleStartEvent() { // Schedules the event to start sending data (switch to the "On" state) Time offInterval = Seconds(m_offTime->GetValue()); m_startStopEvent = Simulator::Schedule(offInterval, &OnOffApplication::StartSending, this); - m_startStopScheduled = true; } void OnOffApplication::ScheduleStopEvent() { // Schedules the event to stop sending data (switch to "Off" state) Time onInterval = Seconds(m_onTime->GetValue()); Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this); - m_startStopScheduled = true; } void OnOffApplication::SendPacket() { - NS_ASSERT (m_sendScheduled); - m_sendScheduled = false; + NS_ASSERT (m_sendEvent.IsExpired ()); m_socket->Send(0, m_pktSize); m_totBytes += m_pktSize; m_lastStartTime = Simulator::Now(); diff --git a/src/applications/onoff-application.h b/src/applications/onoff-application.h index 431f00a98..0484e6fc0 100644 --- a/src/applications/onoff-application.h +++ b/src/applications/onoff-application.h @@ -81,9 +81,7 @@ private: Time m_lastStartTime;// Time last packet sent uint32_t m_maxBytes; // Limit total number of bytes sent uint32_t m_totBytes; // Total bytes sent so far - bool m_startStopScheduled; // True if start or stop event scheduled EventId m_startStopEvent; // Event id for next start or stop event - bool m_sendScheduled;// True of send event scheduled EventId m_sendEvent; // Eventid of pending "send packet" event bool m_sending; // True if currently in sending state