diff --git a/SConstruct b/SConstruct index 607dcb1ce..1f0d3fef0 100644 --- a/SConstruct +++ b/SConstruct @@ -209,6 +209,7 @@ node.add_sources ([ 'socket.cc', 'i-udp.cc', 'i-ipv4.cc', + 'application.cc', ]) node.add_inst_headers ([ 'node.h', @@ -224,25 +225,22 @@ node.add_inst_headers ([ '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', diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index ca2bd1e78..b767febbb 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -134,7 +134,7 @@ int main (int argc, char *argv[]) // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s - Ptr ooff0 = MakeNewObject ( + Ptr ooff = MakeNewObject ( n0, Ipv4Address("10.1.3.2"), 80, @@ -142,16 +142,12 @@ int main (int argc, char *argv[]) ConstantVariable(0), DataRate(448000), 210); - // Add to Node's ApplicationList (takes ownership of pointer) - Ptr apl0 = n0->QueryInterface (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 ooff1 = MakeNewObject ( + ooff = MakeNewObject ( n3, Ipv4Address("10.1.2.1"), 80, @@ -159,12 +155,9 @@ int main (int argc, char *argv[]) ConstantVariable(0), DataRate(448000), 210); - // Add to Node's ApplicationList (takes ownership of pointer) - Ptr apl3 = n3->QueryInterface (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 diff --git a/src/applications/application-list.cc b/src/applications/application-list.cc deleted file mode 100644 index 576f1fc4a..000000000 --- a/src/applications/application-list.cc +++ /dev/null @@ -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 -// -// 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 n) - : Interface (ApplicationList::iid) -{} - -void -ApplicationList::DoDispose (void) -{ - for (std::vector >::iterator i = m_apps.begin(); - i != m_apps.end(); ++i) - { - Ptr app = *i; - app->Dispose (); - *i = 0; - } - m_apps.clear (); - Interface::DoDispose (); -} - -ApplicationList::~ApplicationList() -{} - -void -ApplicationList::Add(Ptr a) -{ - m_apps.push_back(a); -} - -uint32_t ApplicationList::Count() const -{ - return m_apps.size(); -} - -Ptr ApplicationList::Get(uint32_t i) const -{ - if (m_apps.empty()) - { - return 0; - } - return m_apps[i]; -} - -}//namespace ns3 diff --git a/src/applications/application-list.h b/src/applications/application-list.h deleted file mode 100644 index 2f4d0226a..000000000 --- a/src/applications/application-list.h +++ /dev/null @@ -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 -// -// 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 - -namespace ns3 { - -class ApplicationList : public Interface -{ -public: - static const InterfaceId iid; - ApplicationList(Ptr); - // Copy constructor not needed, default one is correct - virtual ~ApplicationList(); - virtual void Add(Ptr application); - - uint32_t Count() const; // Number of applications - Ptr Get(uint32_t i) const; // Get app by index - -protected: - virtual void DoDispose (void); -private: - std::vector > m_apps; -}; - -}//namespace ns3 -#endif - diff --git a/src/applications/onoff-application.h b/src/applications/onoff-application.h index 0902a2885..66fff3916 100644 --- a/src/applications/onoff-application.h +++ b/src/applications/onoff-application.h @@ -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" diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 0e54800d9..15b95c675 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -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 @@ InternetNode::InternetNode() Ptr arp = MakeNewObject (this); Ptr udp = MakeNewObject (this); - Ptr applicationList = MakeNewObject (this); Ptr l3Demux = MakeNewObject (this); Ptr ipv4L4Demux = MakeNewObject (this); @@ -62,7 +60,6 @@ InternetNode::InternetNode() Interface::AddInterface (ipv4Impl); Interface::AddInterface (arpPrivate); Interface::AddInterface (udpImpl); - Interface::AddInterface (applicationList); Interface::AddInterface (l3Demux); Interface::AddInterface (ipv4L4Demux); } diff --git a/src/applications/application.cc b/src/node/application.cc similarity index 99% rename from src/applications/application.cc rename to src/node/application.cc index 2d4badcd6..ed4fc7ecd 100644 --- a/src/applications/application.cc +++ b/src/node/application.cc @@ -39,6 +39,7 @@ Application::Application(Ptr n) m_startVar(0), m_stopVar(0), m_start(false), m_stop(false) { + m_node->AddApplication (this); } Application::Application(const Application& o) diff --git a/src/applications/application.h b/src/node/application.h similarity index 100% rename from src/applications/application.h rename to src/node/application.h diff --git a/src/node/node.cc b/src/node/node.cc index 7d57305ab..81ba3e678 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -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 @@ Node::GetNDevices (void) const return m_devices.size (); } +uint32_t +Node::AddApplication (Ptr application) +{ + uint32_t index = m_applications.size (); + m_applications.push_back (application); + return index; +} +Ptr +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 >::iterator i = m_devices.begin (); @@ -98,6 +118,14 @@ void Node::DoDispose() *i = 0; } m_devices.clear (); + for (std::vector >::iterator i = m_applications.begin (); + i != m_applications.end (); i++) + { + Ptr application = *i; + application->Dispose (); + *i = 0; + } + m_applications.clear (); Interface::DoDispose (); } diff --git a/src/node/node.h b/src/node/node.h index 42fa0b4fe..f0c7d142e 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -34,6 +34,7 @@ namespace ns3 { class TraceContext; class TraceResolver; class NetDevice; +class Application; class Node : public Interface { @@ -54,6 +55,10 @@ public: Ptr GetDevice (uint32_t index) const; uint32_t GetNDevices (void) const; + uint32_t AddApplication (Ptr application); + Ptr GetApplication (uint32_t index) const; + uint32_t GetNApplications (void) const; + protected: virtual void DoDispose (void); private: @@ -62,6 +67,7 @@ private: uint32_t m_id; // Node id for this node uint32_t m_sid; // System id for this node std::vector > m_devices; + std::vector > m_applications; }; } //namespace ns3