2007-03-17 22:32:08 -07:00
|
|
|
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006 Georgia Tech Research Corporation
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
* Author: George F. Riley<riley@ece.gatech.edu>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Implementation for ns3 Application base class.
|
|
|
|
|
// George F. Riley, Georgia Tech, Fall 2006
|
|
|
|
|
|
|
|
|
|
#include "application.h"
|
2007-06-04 16:21:05 +02:00
|
|
|
#include "ns3/node.h"
|
2007-03-17 22:32:08 -07:00
|
|
|
#include "ns3/nstime.h"
|
|
|
|
|
#include "ns3/random-variable.h"
|
|
|
|
|
#include "ns3/simulator.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace ns3 {
|
|
|
|
|
|
|
|
|
|
// Application Methods
|
|
|
|
|
|
|
|
|
|
// \brief Application Constructor
|
2007-06-04 16:17:01 +02:00
|
|
|
Application::Application(Ptr<Node> n)
|
2007-05-13 10:24:35 +02:00
|
|
|
: m_node (n)
|
2007-03-17 22:32:08 -07:00
|
|
|
{
|
2007-05-13 09:46:38 +02:00
|
|
|
m_node->AddApplication (this);
|
2007-03-17 22:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// \brief Application Destructor
|
|
|
|
|
Application::~Application()
|
2007-05-03 13:24:43 +02:00
|
|
|
{}
|
2007-05-02 23:08:41 +02:00
|
|
|
|
|
|
|
|
void
|
2007-05-03 13:24:43 +02:00
|
|
|
Application::DoDispose (void)
|
2007-05-02 23:08:41 +02:00
|
|
|
{
|
2007-05-10 08:19:53 +02:00
|
|
|
m_node = 0;
|
2007-05-13 10:24:35 +02:00
|
|
|
Simulator::Cancel(m_startEvent);
|
|
|
|
|
Simulator::Cancel(m_stopEvent);
|
2007-05-13 10:02:10 +02:00
|
|
|
}
|
2007-03-17 22:32:08 -07:00
|
|
|
|
|
|
|
|
void Application::Start(const Time& startTime)
|
|
|
|
|
{
|
2007-05-13 10:24:35 +02:00
|
|
|
ScheduleStart (startTime);
|
2007-03-17 22:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Application::Start(const RandomVariable& startVar)
|
2007-05-13 10:24:35 +02:00
|
|
|
{
|
|
|
|
|
RandomVariable *v = startVar.Copy ();
|
|
|
|
|
ScheduleStart (Seconds (v->GetValue ()));
|
|
|
|
|
delete v;
|
2007-03-17 22:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Application::Stop(const Time& stopTime)
|
|
|
|
|
{
|
2007-05-13 10:24:35 +02:00
|
|
|
ScheduleStop (stopTime);
|
2007-03-17 22:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Application::Stop(const RandomVariable& stopVar)
|
2007-05-13 10:24:35 +02:00
|
|
|
{
|
|
|
|
|
RandomVariable *v = stopVar.Copy ();
|
|
|
|
|
ScheduleStop (Seconds (v->GetValue ()));
|
|
|
|
|
delete v;
|
2007-03-17 22:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
2007-06-04 16:17:01 +02:00
|
|
|
Ptr<Node> Application::GetNode() const
|
2007-03-17 22:32:08 -07:00
|
|
|
{
|
2007-05-02 15:07:33 +02:00
|
|
|
return m_node;
|
2007-03-17 22:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Protected methods
|
|
|
|
|
// StartApp and StopApp will likely be overridden by application subclasses
|
|
|
|
|
void Application::StartApplication()
|
|
|
|
|
{ // Provide null functionality in case subclass is not interested
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Application::StopApplication()
|
|
|
|
|
{ // Provide null functionality in case subclass is not interested
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Private helpers
|
2007-05-13 10:24:35 +02:00
|
|
|
void Application::ScheduleStart (const Time &startTime)
|
2007-03-17 22:32:08 -07:00
|
|
|
{
|
2007-05-13 10:24:35 +02:00
|
|
|
m_startEvent = Simulator::Schedule(startTime -
|
2007-03-17 22:32:08 -07:00
|
|
|
Simulator::Now(),
|
|
|
|
|
&Application::StartApplication, this);
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-13 10:24:35 +02:00
|
|
|
void Application::ScheduleStop (const Time &stopTime)
|
2007-03-17 22:32:08 -07:00
|
|
|
{
|
2007-05-13 10:24:35 +02:00
|
|
|
m_stopEvent = Simulator::Schedule(stopTime -
|
|
|
|
|
Simulator::Now(),
|
|
|
|
|
&Application::StopApplication, this);
|
2007-03-17 22:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //namespace ns3
|
|
|
|
|
|
|
|
|
|
|