remove ApplicationList. Move functionality to Node class
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 13 May 2007 09:46:38 +0200
changeset 585 a009b03b720a
parent 584 d843d0d5314d
child 586 6220d0040d50
remove ApplicationList. Move functionality to Node class
SConstruct
examples/simple-p2p.cc
src/applications/application-list.cc
src/applications/application-list.h
src/applications/application.cc
src/applications/application.h
src/applications/onoff-application.h
src/internet-node/internet-node.cc
src/node/application.cc
src/node/application.h
src/node/node.cc
src/node/node.h
--- a/SConstruct	Sun May 13 09:35:03 2007 +0200
+++ b/SConstruct	Sun May 13 09:46:38 2007 +0200
@@ -209,6 +209,7 @@
     'socket.cc',
     'i-udp.cc',
     'i-ipv4.cc',
+    'application.cc',
     ])
 node.add_inst_headers ([
     'node.h',
@@ -224,25 +225,22 @@
     'socket.h',
     'i-udp.h',
     'i-ipv4.h',
+    'application.h',
     ])
 
 applications = build.Ns3Module ('applications', 'src/applications')
 ns3.add (applications)
 applications.add_deps (['node'])
 applications.add_sources ([
-    'application-list.cc',
-    'application.cc',
     'onoff-application.cc',
 ])
 applications.add_inst_headers ([
-    'application-list.h',
-    'application.h',
     'onoff-application.h',
 ])
 
 inode = build.Ns3Module ('internet-node', 'src/internet-node')
 ns3.add (inode)
-inode.add_deps (['node', 'applications'])
+inode.add_deps (['node'])
 inode.add_sources ([
     'internet-node.cc',
     'l3-demux.cc',
--- a/examples/simple-p2p.cc	Sun May 13 09:35:03 2007 +0200
+++ b/examples/simple-p2p.cc	Sun May 13 09:46:38 2007 +0200
@@ -134,7 +134,7 @@
 
   // Create the OnOff application to send UDP datagrams of size
   // 210 bytes at a rate of 448 Kb/s
-  Ptr<OnOffApplication> ooff0 = MakeNewObject<OnOffApplication> (
+  Ptr<OnOffApplication> ooff = MakeNewObject<OnOffApplication> (
     n0, 
     Ipv4Address("10.1.3.2"), 
     80, 
@@ -142,16 +142,12 @@
     ConstantVariable(0), 
     DataRate(448000), 
     210);
-  // Add to Node's ApplicationList (takes ownership of pointer)
-  Ptr<ApplicationList> apl0 = n0->QueryInterface<ApplicationList> (ApplicationList::iid);
-  apl0->Add(ooff0);
-
   // Start the application
-  ooff0->Start(Seconds(1.0));
-  ooff0->Stop (Seconds(10.0));
+  ooff->Start(Seconds(1.0));
+  ooff->Stop (Seconds(10.0));
 
   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
-  Ptr<OnOffApplication> ooff1 = MakeNewObject<OnOffApplication> (
+  ooff = MakeNewObject<OnOffApplication> (
     n3, 
     Ipv4Address("10.1.2.1"), 
     80, 
@@ -159,12 +155,9 @@
     ConstantVariable(0), 
     DataRate(448000), 
     210);
-  // Add to Node's ApplicationList (takes ownership of pointer)
-  Ptr<ApplicationList> apl3 = n3->QueryInterface<ApplicationList> (ApplicationList::iid);
-  apl3->Add(ooff1);
   // Start the application
-  ooff1->Start(Seconds(1.1));
-  ooff1->Stop (Seconds(10.0));
+  ooff->Start(Seconds(1.1));
+  ooff->Stop (Seconds(10.0));
 
   // Here, finish off packet routing configuration
   // This will likely set by some global StaticRouting object in the future
--- a/src/applications/application-list.cc	Sun May 13 09:35:03 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-// -*- Mode:NS3 -*-
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-// All rights reserved.
-//
-// 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>
-//
-// Implement the application list capability for NS3 nodes
-// George F. Riley, Georgia Tech, Spring 2007
-
-#include "application.h"
-#include "application-list.h"
-
-namespace ns3{
-
-const InterfaceId ApplicationList::iid ("ApplicationList");
-
-ApplicationList::ApplicationList(Ptr<Node> n)
-  : Interface (ApplicationList::iid)
-{}
-
-void 
-ApplicationList::DoDispose (void)
-{
-  for (std::vector<Ptr<Application> >::iterator i = m_apps.begin();
-       i != m_apps.end(); ++i)
-    {
-      Ptr<Application> app = *i;
-      app->Dispose ();
-      *i = 0;
-    }
-  m_apps.clear ();
-  Interface::DoDispose ();
-}
-  
-ApplicationList::~ApplicationList()
-{}
-
-void
-ApplicationList::Add(Ptr<Application> a)
-{
-  m_apps.push_back(a);
-}  
-
-uint32_t ApplicationList::Count() const
-{
-  return m_apps.size();
-}
-
-Ptr<Application> ApplicationList::Get(uint32_t i) const
-{
-  if (m_apps.empty()) 
-    {
-      return 0;
-    }
-  return m_apps[i];
-}
-  
-}//namespace ns3
--- a/src/applications/application-list.h	Sun May 13 09:35:03 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-// -*- Mode:NS3 -*-
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-// All rights reserved.
-//
-// 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>
-//
-// Manages the list of applications associated with a node.
-// George F. Riley, Georgia Tech, Spring 2007
-
-#ifndef __APPLICATION_LIST_H__
-#define __APPLICATION_LIST_H__
-
-#include "application.h"
-#include "ns3/interface.h"
-#include "ns3/ptr.h"
-#include <vector>
-
-namespace ns3 {
-
-class ApplicationList : public Interface
-{
-public:
-  static const InterfaceId iid;
-  ApplicationList(Ptr<Node>);
-  // Copy constructor not needed, default one is correct
-  virtual ~ApplicationList();
-  virtual void Add(Ptr<Application> application);
-
-  uint32_t Count() const;  // Number of applications
-  Ptr<Application> Get(uint32_t i) const; // Get app by index
-  
-protected:
-  virtual void DoDispose (void);
-private:
-  std::vector<Ptr<Application> > m_apps;
-};
-
-}//namespace ns3
-#endif
-
--- a/src/applications/application.cc	Sun May 13 09:35:03 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +0,0 @@
-/* -*-  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"
-#include "ns3/node.h"
-#include "ns3/nstime.h"
-#include "ns3/random-variable.h"
-#include "ns3/simulator.h"
-
-using namespace std;
-
-namespace ns3 {
-
-// Application Methods
-
-// \brief Application Constructor
-Application::Application(Ptr<Node> n) 
-    : m_node (n),
-      m_startVar(0), m_stopVar(0),
-      m_start(false), m_stop(false)
-{
-}
-
-Application::Application(const Application& o)
-    : m_node(0), m_startVar(0), m_stopVar(0),
-      m_start(false), m_stop(false)
-{ // Copy constructor
-  m_node = o.m_node;
-  // Copy the start and stop random variables if they exist
-  if (o.m_startVar) m_startVar = o.m_startVar->Copy();
-  if (o.m_stopVar)  m_stopVar  = o.m_stopVar->Copy();
-  if (o.m_start)    ScheduleStart();
-  if (o.m_stop)     ScheduleStop();
-}
-
-  
-// \brief Application Destructor
-Application::~Application()
-{}
-
-void
-Application::DoDispose (void)
-{
-  m_node = 0;
-  if (m_start) 
-    {
-      Simulator::Cancel(m_startEvent);
-      m_start = false;
-    }
-  if (m_stop) 
-    {
-      Simulator::Cancel(m_stopEvent);
-      m_stop = false;
-    }
-  delete m_startVar;
-  m_startVar = 0;
-  delete m_stopVar;
-  m_stopVar = 0;
-}
-  
-Application& Application::operator=(const Application& rhs)
-{
-  if (this == &rhs) return *this; // Self assignment
-  m_node = rhs.m_node;
-
-  delete m_startVar;
-  m_startVar = 0;
-  if (rhs.m_startVar) m_startVar = rhs.m_startVar->Copy();
-  
-  delete m_stopVar;
-  m_stopVar = 0;
-  if (rhs.m_stopVar) m_stopVar = rhs.m_stopVar->Copy();
-  
-  m_start = false;
-  if (rhs.m_start) ScheduleStart();
-  if (rhs.m_stop)  ScheduleStop();
-  return *this;
-}
-  
-   
-// \brief Specify application start time
-// The virtual method STartApp will be called at the time
-// specified by startTime.
-// \param Time to start application (absolute time, from start of simulation)
-void Application::Start(const Time& startTime)
-{
-  delete m_startVar;
-  m_startVar = new ConstantVariable(startTime.GetSeconds());
-  ScheduleStart();
-}
-
-void Application::Start(const RandomVariable& startVar)
-{ // Start at random time
-  delete m_startVar;
-  m_startVar = startVar.Copy();
-  ScheduleStart();
-}
-
-   
-// \brief Specify application stop time
-// The virtual method StopApp will be called at the time
-// specified by stopTime.
-// \param Time to stop application (absolute time, from start of simulation)
-void Application::Stop(const Time& stopTime)
-{
-  delete m_stopVar;
-  m_stopVar = new ConstantVariable(stopTime.GetSeconds());
-  ScheduleStop();
-}
-
-void Application::Stop(const RandomVariable& stopVar)
-{ // Stop at random time
-  delete m_stopVar;
-  m_stopVar = stopVar.Copy();
-  ScheduleStop();
-}
-  
-Ptr<Node> Application::GetNode() const
-{
-  return m_node;
-}
-
-// 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
-void Application::ScheduleStart()
-{
-  m_startEvent = Simulator::Schedule(Seconds(m_startVar->GetValue()) -
-                                     Simulator::Now(),
-                                     &Application::StartApplication, this);
-  m_start = true;
-}
-
-void Application::ScheduleStop()
-{
-  m_stopEvent = Simulator::Schedule(Seconds(m_stopVar->GetValue()) -
-                                     Simulator::Now(),
-                                     &Application::StopApplication, this);
-  m_stop = true;
-}
-
-} //namespace ns3
-      
-  
--- a/src/applications/application.h	Sun May 13 09:35:03 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-/* -*-  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>
- */
-
-#ifndef __APPLICATION_H__
-#define __APPLICATION_H__
-
-//
-// \brief The base class for all ns3 applicationes
-//
-// Class Application is the base class for all ns3 applications.
-// Applications are associated with individual nodes, and are created
-// using the AddApplication method in the ApplicationManager capability.
-// 
-// Conceptually, an application has zero or more Socket
-// objects associated with it, that are created using the Socket
-// creation API of the Kernel capability.  The Socket object
-// API is modeled after the
-// well-known BSD sockets interface, although it is somewhat 
-// simplified for use with ns3.  Further, any socket call that
-// would normally "block" in normal sockets will return immediately
-// in ns3.  A set of "upcalls" are defined that will be called when
-// the previous blocking call would normally exit.  THis is documented
-// in more detail Socket class in socket.h.
-// 
-// There is a second application class in ns3, called "ThreadedApplication"
-// that implements a true sockets interface, which should be used
-// when porting existing sockets code to ns3.  The true
-// sockets approach is significantly
-// less memory--efficient using private stacks for each defined application,
-// so that approach should be used with care.  The design and implementation
-// of the ThreadedApplication are still being discussed.
-
-#include "ns3/event-id.h"
-#include "ns3/nstime.h"
-#include "ns3/object.h"
-#include "ns3/ptr.h"
-#include "ns3/node.h"
-
-namespace ns3 {
-
-class Node;
-class RandomVariable;
-  
-class Application : public Object
-{
-public:
-  Application(Ptr<Node>);
-  Application(const Application&);  // Copy constructor
-  Application& operator=(const Application&); // Assignment operator
-  virtual ~Application();
-  
-  virtual Application* Copy() const = 0; // All applications must provide
-  
-  // \brief Specify application start time
-  // Applications start at various times in the simulation scenario.
-  // The Start method specifies when the application should be
-  // started.  The application subclasses should override the
-  // private "StartApplication" method defined below, which is called at the
-  // time specified, to cause the application to begin.
-  // \param Start time for this application, relative to the
-  // current simulation time.
-  void Start(const Time&);
-
-  // \brief Same as above, but uses a random variable for start time
-  // The random variable returns the desired start time in units of
-  // Seconds.
-  
-void Start(const RandomVariable&);
-  
-  // \brief Specify application stop time
-  // Once an application has started, it is sometimes useful
-  // to stop the application.  The Stop method specifies when an
-  // application is to stop.  The application subclasses should override
-  // the private StopApplication method defined below, to cause the application
-  // to stop.
-  // \param Stop time for this application, relative to the
-  // current simulation time.
-  void Stop(const Time&);
-
-  // \brief Same as above, but uses a random variable for stop time
-  // The random variable returns the desired stop time in units of
-  // Seconds.
-  void Stop(const RandomVariable&);
-  
-  // \brief Attaches an application to a specific node
-  // Specifies which node object this application is associated with.
-  // \param Node object to associate with this application.
-  // \brief Returns the pointer to the attached node.
-  Ptr<Node> GetNode() const;
-  
-  // Members
-  Ptr<Node>       m_node;      // All applications have an associated node
-  RandomVariable* m_startVar;  // Random variable for start time
-  RandomVariable* m_stopVar;   // Random variable for stop time
-  EventId         m_startEvent;// Event identifier for start event
-  EventId         m_stopEvent; // Event identifier for the stop event
-  bool            m_start;     // True if start event scheduled
-  bool            m_stop;      // True if stop event scheduled
-  
-protected:
-  // \brief Application specific startup code
-  // The StartApplication method is called at the start time specifed by Start
-  // This method should be overridden by all or most application
-  // subclasses.
-  virtual void StartApplication();
-
-  // \brief Application specific shutdown code
-  // The StopApplication method is called at the stop time specifed by Stop
-  // This method should be overridden by all or most application
-  // subclasses.
-  virtual void StopApplication();
-
-  virtual void DoDispose (void);
-private:
-  // Helpers
-  void ScheduleStart();
-  void ScheduleStop();
-};
-
-} //namespace ns3
-#endif
--- a/src/applications/onoff-application.h	Sun May 13 09:35:03 2007 +0200
+++ b/src/applications/onoff-application.h	Sun May 13 09:46:38 2007 +0200
@@ -27,7 +27,7 @@
 #ifndef __onoff_application_h__
 #define __onoff_application_h__
 
-#include "application.h"
+#include "ns3/application.h"
 #include "ns3/event-id.h"
 #include "ns3/ptr.h"
 
--- a/src/internet-node/internet-node.cc	Sun May 13 09:35:03 2007 +0200
+++ b/src/internet-node/internet-node.cc	Sun May 13 09:46:38 2007 +0200
@@ -22,7 +22,6 @@
 // George F. Riley, Georgia Tech, Fall 2006
 
 #include "ns3/composite-trace-resolver.h"
-#include "ns3/application-list.h"
 #include "ns3/net-device.h"
 
 #include "l3-demux.h"
@@ -45,7 +44,6 @@
   Ptr<Arp> arp = MakeNewObject<Arp> (this);
   Ptr<Udp> udp = MakeNewObject<Udp> (this);
 
-  Ptr<ApplicationList> applicationList = MakeNewObject<ApplicationList> (this);
   Ptr<L3Demux> l3Demux = MakeNewObject<L3Demux> (this);
   Ptr<Ipv4L4Demux> ipv4L4Demux = MakeNewObject<Ipv4L4Demux> (this);
 
@@ -62,7 +60,6 @@
   Interface::AddInterface (ipv4Impl);
   Interface::AddInterface (arpPrivate);
   Interface::AddInterface (udpImpl);
-  Interface::AddInterface (applicationList);
   Interface::AddInterface (l3Demux);
   Interface::AddInterface (ipv4L4Demux);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/application.cc	Sun May 13 09:46:38 2007 +0200
@@ -0,0 +1,174 @@
+/* -*-  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"
+#include "ns3/node.h"
+#include "ns3/nstime.h"
+#include "ns3/random-variable.h"
+#include "ns3/simulator.h"
+
+using namespace std;
+
+namespace ns3 {
+
+// Application Methods
+
+// \brief Application Constructor
+Application::Application(Ptr<Node> n) 
+    : m_node (n),
+      m_startVar(0), m_stopVar(0),
+      m_start(false), m_stop(false)
+{
+  m_node->AddApplication (this);
+}
+
+Application::Application(const Application& o)
+    : m_node(0), m_startVar(0), m_stopVar(0),
+      m_start(false), m_stop(false)
+{ // Copy constructor
+  m_node = o.m_node;
+  // Copy the start and stop random variables if they exist
+  if (o.m_startVar) m_startVar = o.m_startVar->Copy();
+  if (o.m_stopVar)  m_stopVar  = o.m_stopVar->Copy();
+  if (o.m_start)    ScheduleStart();
+  if (o.m_stop)     ScheduleStop();
+}
+
+  
+// \brief Application Destructor
+Application::~Application()
+{}
+
+void
+Application::DoDispose (void)
+{
+  m_node = 0;
+  if (m_start) 
+    {
+      Simulator::Cancel(m_startEvent);
+      m_start = false;
+    }
+  if (m_stop) 
+    {
+      Simulator::Cancel(m_stopEvent);
+      m_stop = false;
+    }
+  delete m_startVar;
+  m_startVar = 0;
+  delete m_stopVar;
+  m_stopVar = 0;
+}
+  
+Application& Application::operator=(const Application& rhs)
+{
+  if (this == &rhs) return *this; // Self assignment
+  m_node = rhs.m_node;
+
+  delete m_startVar;
+  m_startVar = 0;
+  if (rhs.m_startVar) m_startVar = rhs.m_startVar->Copy();
+  
+  delete m_stopVar;
+  m_stopVar = 0;
+  if (rhs.m_stopVar) m_stopVar = rhs.m_stopVar->Copy();
+  
+  m_start = false;
+  if (rhs.m_start) ScheduleStart();
+  if (rhs.m_stop)  ScheduleStop();
+  return *this;
+}
+  
+   
+// \brief Specify application start time
+// The virtual method STartApp will be called at the time
+// specified by startTime.
+// \param Time to start application (absolute time, from start of simulation)
+void Application::Start(const Time& startTime)
+{
+  delete m_startVar;
+  m_startVar = new ConstantVariable(startTime.GetSeconds());
+  ScheduleStart();
+}
+
+void Application::Start(const RandomVariable& startVar)
+{ // Start at random time
+  delete m_startVar;
+  m_startVar = startVar.Copy();
+  ScheduleStart();
+}
+
+   
+// \brief Specify application stop time
+// The virtual method StopApp will be called at the time
+// specified by stopTime.
+// \param Time to stop application (absolute time, from start of simulation)
+void Application::Stop(const Time& stopTime)
+{
+  delete m_stopVar;
+  m_stopVar = new ConstantVariable(stopTime.GetSeconds());
+  ScheduleStop();
+}
+
+void Application::Stop(const RandomVariable& stopVar)
+{ // Stop at random time
+  delete m_stopVar;
+  m_stopVar = stopVar.Copy();
+  ScheduleStop();
+}
+  
+Ptr<Node> Application::GetNode() const
+{
+  return m_node;
+}
+
+// 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
+void Application::ScheduleStart()
+{
+  m_startEvent = Simulator::Schedule(Seconds(m_startVar->GetValue()) -
+                                     Simulator::Now(),
+                                     &Application::StartApplication, this);
+  m_start = true;
+}
+
+void Application::ScheduleStop()
+{
+  m_stopEvent = Simulator::Schedule(Seconds(m_stopVar->GetValue()) -
+                                     Simulator::Now(),
+                                     &Application::StopApplication, this);
+  m_stop = true;
+}
+
+} //namespace ns3
+      
+  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/application.h	Sun May 13 09:46:38 2007 +0200
@@ -0,0 +1,138 @@
+/* -*-  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>
+ */
+
+#ifndef __APPLICATION_H__
+#define __APPLICATION_H__
+
+//
+// \brief The base class for all ns3 applicationes
+//
+// Class Application is the base class for all ns3 applications.
+// Applications are associated with individual nodes, and are created
+// using the AddApplication method in the ApplicationManager capability.
+// 
+// Conceptually, an application has zero or more Socket
+// objects associated with it, that are created using the Socket
+// creation API of the Kernel capability.  The Socket object
+// API is modeled after the
+// well-known BSD sockets interface, although it is somewhat 
+// simplified for use with ns3.  Further, any socket call that
+// would normally "block" in normal sockets will return immediately
+// in ns3.  A set of "upcalls" are defined that will be called when
+// the previous blocking call would normally exit.  THis is documented
+// in more detail Socket class in socket.h.
+// 
+// There is a second application class in ns3, called "ThreadedApplication"
+// that implements a true sockets interface, which should be used
+// when porting existing sockets code to ns3.  The true
+// sockets approach is significantly
+// less memory--efficient using private stacks for each defined application,
+// so that approach should be used with care.  The design and implementation
+// of the ThreadedApplication are still being discussed.
+
+#include "ns3/event-id.h"
+#include "ns3/nstime.h"
+#include "ns3/object.h"
+#include "ns3/ptr.h"
+#include "ns3/node.h"
+
+namespace ns3 {
+
+class Node;
+class RandomVariable;
+  
+class Application : public Object
+{
+public:
+  Application(Ptr<Node>);
+  Application(const Application&);  // Copy constructor
+  Application& operator=(const Application&); // Assignment operator
+  virtual ~Application();
+  
+  virtual Application* Copy() const = 0; // All applications must provide
+  
+  // \brief Specify application start time
+  // Applications start at various times in the simulation scenario.
+  // The Start method specifies when the application should be
+  // started.  The application subclasses should override the
+  // private "StartApplication" method defined below, which is called at the
+  // time specified, to cause the application to begin.
+  // \param Start time for this application, relative to the
+  // current simulation time.
+  void Start(const Time&);
+
+  // \brief Same as above, but uses a random variable for start time
+  // The random variable returns the desired start time in units of
+  // Seconds.
+  
+void Start(const RandomVariable&);
+  
+  // \brief Specify application stop time
+  // Once an application has started, it is sometimes useful
+  // to stop the application.  The Stop method specifies when an
+  // application is to stop.  The application subclasses should override
+  // the private StopApplication method defined below, to cause the application
+  // to stop.
+  // \param Stop time for this application, relative to the
+  // current simulation time.
+  void Stop(const Time&);
+
+  // \brief Same as above, but uses a random variable for stop time
+  // The random variable returns the desired stop time in units of
+  // Seconds.
+  void Stop(const RandomVariable&);
+  
+  // \brief Attaches an application to a specific node
+  // Specifies which node object this application is associated with.
+  // \param Node object to associate with this application.
+  // \brief Returns the pointer to the attached node.
+  Ptr<Node> GetNode() const;
+  
+  // Members
+  Ptr<Node>       m_node;      // All applications have an associated node
+  RandomVariable* m_startVar;  // Random variable for start time
+  RandomVariable* m_stopVar;   // Random variable for stop time
+  EventId         m_startEvent;// Event identifier for start event
+  EventId         m_stopEvent; // Event identifier for the stop event
+  bool            m_start;     // True if start event scheduled
+  bool            m_stop;      // True if stop event scheduled
+  
+protected:
+  // \brief Application specific startup code
+  // The StartApplication method is called at the start time specifed by Start
+  // This method should be overridden by all or most application
+  // subclasses.
+  virtual void StartApplication();
+
+  // \brief Application specific shutdown code
+  // The StopApplication method is called at the stop time specifed by Stop
+  // This method should be overridden by all or most application
+  // subclasses.
+  virtual void StopApplication();
+
+  virtual void DoDispose (void);
+private:
+  // Helpers
+  void ScheduleStart();
+  void ScheduleStop();
+};
+
+} //namespace ns3
+#endif
--- a/src/node/node.cc	Sun May 13 09:35:03 2007 +0200
+++ b/src/node/node.cc	Sun May 13 09:46:38 2007 +0200
@@ -25,6 +25,7 @@
 #include "node.h"
 #include "node-list.h"
 #include "net-device.h"
+#include "application.h"
 #include "ns3/simulator.h"
 
 namespace ns3{
@@ -88,6 +89,25 @@
   return m_devices.size ();
 }
 
+uint32_t 
+Node::AddApplication (Ptr<Application> application)
+{
+  uint32_t index = m_applications.size ();
+  m_applications.push_back (application);
+  return index;
+}
+Ptr<Application> 
+Node::GetApplication (uint32_t index) const
+{
+  return m_applications[index];
+}
+uint32_t 
+Node::GetNApplications (void) const
+{
+  return m_applications.size ();
+}
+
+
 void Node::DoDispose()
 {
   for (std::vector<Ptr<NetDevice> >::iterator i = m_devices.begin ();
@@ -98,6 +118,14 @@
       *i = 0;
     }
   m_devices.clear ();
+  for (std::vector<Ptr<Application> >::iterator i = m_applications.begin ();
+       i != m_applications.end (); i++)
+    {
+      Ptr<Application> application = *i;
+      application->Dispose ();
+      *i = 0;
+    }
+  m_applications.clear ();
   Interface::DoDispose ();
 }
 
--- a/src/node/node.h	Sun May 13 09:35:03 2007 +0200
+++ b/src/node/node.h	Sun May 13 09:46:38 2007 +0200
@@ -34,6 +34,7 @@
 class TraceContext;
 class TraceResolver;
 class NetDevice;
+class Application;
 
 class Node : public Interface
 {
@@ -54,6 +55,10 @@
   Ptr<NetDevice> GetDevice (uint32_t index) const;
   uint32_t GetNDevices (void) const;
 
+  uint32_t AddApplication (Ptr<Application> application);
+  Ptr<Application> GetApplication (uint32_t index) const;
+  uint32_t GetNApplications (void) const;
+
 protected:
   virtual void DoDispose (void);
 private:
@@ -62,6 +67,7 @@
   uint32_t    m_id;         // Node id for this node
   uint32_t    m_sid;        // System id for this node
   std::vector<Ptr<NetDevice> > m_devices;
+  std::vector<Ptr<Application> > m_applications;
 };
 
 } //namespace ns3