--- a/SConstruct Tue Mar 27 15:42:17 2007 -0700
+++ b/SConstruct Tue Mar 27 21:48:22 2007 -0700
@@ -204,8 +204,10 @@
'udp-end-point.cc',
'datagram-socket.cc',
'udp.cc',
+ 'capability.cc',
'arp-header.cc',
'application.cc',
+ 'application-list.cc',
'onoff-application.cc',
'arp-cache.cc',
'arp-ipv4-interface.cc',
@@ -226,6 +228,7 @@
'udp.h',
'ipv4-l4-protocol.h',
'application.h',
+ 'application-list.h',
'onoff-application.h',
'arp-header.h',
'arp-cache-cache.h',
@@ -259,7 +262,9 @@
'udp-header.h',
'channel.h',
'node-list.h',
+ 'capability.h',
'application.h',
+ 'application-list.h',
'onoff-application.h',
])
--- a/examples/simple-p2p.cc Tue Mar 27 15:42:17 2007 -0700
+++ b/examples/simple-p2p.cc Tue Mar 27 21:48:22 2007 -0700
@@ -68,6 +68,7 @@
#include "ns3/object-container.h"
#include "ns3/p2p-topology.h"
#include "ns3/onoff-application.h"
+#include "ns3/application-list.h"
#include "ns3/random-variable.h"
using namespace ns3;
@@ -265,6 +266,13 @@
sink1->Bind (80);
#ifdef NOTYET
+ // The arguments to ApplicationTCPSend constructor are the IPAddress
+ // of the server, port number for the server, and a random variable
+ // specifying the amount of data to send.
+ OnOffApplication* ooff = n1->GetApplicationList()->
+ Add(OnOffApplication(*n0, Ipv4Address("10.1.2.2"),
+ 80, ConstantVariable(1), ConstantVariable(0), 1000, 210));
+
// This is functional and could soon replace the above DatagramSockets,
// but needs tuning
OnOffApplication* ooff = new OnOffApplication(*n0, Ipv4Address("10.1.2.2"),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/application-list.cc Tue Mar 27 21:48:22 2007 -0700
@@ -0,0 +1,91 @@
+// -*- 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"
+
+#define nil 0
+
+namespace ns3{
+
+ApplicationList::ApplicationList()
+ : Capability(nil)
+{
+}
+
+ApplicationList::ApplicationList(Node* n)
+ : Capability(n)
+{
+}
+
+ApplicationList::~ApplicationList()
+{ // Destructor, nothing needed as the SmartSet destroys itself
+}
+
+ApplicationList* ApplicationList::Copy(Node& n) const
+{ // Copy this app list
+ ApplicationList* r = new ApplicationList();
+ r->SetNode(n);
+ return r;
+}
+
+void ApplicationList::SetNode(Node& n)
+{
+ Capability::SetNode(n);
+ // Set the node pointer in each application
+ for (SmartSet<Application*>::const_iterator i = m_apps.Begin();
+ i != m_apps.End(); ++i)
+ { // Set correct node pointer in each app
+ (*i)->SetNode(n);
+ }
+}
+
+void ApplicationList::Remove(Application* a)
+{ // Remove the specified application from the list
+ m_apps.Remove(a);
+}
+
+SmartSet<Application*>::size_type ApplicationList::Count() const
+{
+ return m_apps.Size();
+}
+
+Application* ApplicationList::Get(SmartSet<Application*>::size_type i) const
+{ // Get the i'th application. Note, this is linear time in N
+ if (m_apps.Empty()) return nil; // List is empty
+ SmartSet<Application*>::const_iterator k = m_apps.Begin();
+ while(i > 0)
+ {
+ if (k == m_apps.End()) return nil; // Not found
+ --i;
+ ++k;
+ }
+ return *k;
+}
+
+const SmartSet<Application*>& ApplicationList::GetAll() const
+{
+ return m_apps;
+}
+
+}//namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/application-list.h Tue Mar 27 21:48:22 2007 -0700
@@ -0,0 +1,60 @@
+// -*- 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/smartset.h"
+#include "capability.h"
+
+namespace ns3 {
+
+class ApplicationList : public Capability {
+public:
+ ApplicationList();
+ ApplicationList(Node*);
+ // Copy constructor not needed, default one is correct
+ ~ApplicationList();
+ // Inherited from Capabilty
+ virtual ApplicationList* Copy(Node&) const;
+ virtual void SetNode(Node&); // Sets the node for all apps
+ // Manage the list
+ template <typename T> T* Add(const T& t) // Add a new application
+ {
+ T* a = t.Copy();
+ m_apps.Add(a);
+ return a;
+ }
+ void Remove(Application*); // Application has finished
+ SmartSet<Application*>::size_type Count() const; // Number of applications
+ Application* Get(SmartSet<Application*>::size_type) const; // Get app by index
+ const SmartSet<Application*>& GetAll() const; // Get the entire app list
+
+private:
+ SmartSet<Application*> m_apps;
+};
+
+}//namespace ns3
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/capability.cc Tue Mar 27 21:48:22 2007 -0700
@@ -0,0 +1,82 @@
+// -*- 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>
+//
+
+// Implementation of the capability base class.
+
+#include "capability.h"
+#include "node.h"
+#include "node-reference.h"
+
+#define nil 0
+
+namespace ns3 {
+
+Capability::Capability()
+ : m_node(nil)
+{ // Nothing else needed
+}
+
+Capability::Capability(Node* n)
+{
+ m_node = new NodeReference(*n);
+}
+
+// Copy constructor
+Capability::Capability(const Capability& o)
+{
+ m_node = new NodeReference(*o.GetNode());
+}
+
+
+// Assignment operator
+Capability& Capability::operator=(const Capability& rhs)
+{
+ if (this == &rhs) return *this; // Self assignment
+ delete m_node;
+ m_node = new NodeReference(*rhs.GetNode());
+ return *this;
+}
+
+
+
+Capability::~Capability()
+{
+ delete m_node;
+}
+
+// SetNode should be overridden by any capability subclass
+// that manages other objects needing node information, such
+// as the ApplicationList.
+void Capability::SetNode(Node& n)
+{
+ delete m_node;
+ m_node = new NodeReference(n);
+}
+
+
+Node* Capability::GetNode() const
+{
+ if (!m_node) return nil;
+ return m_node->GetNode();
+}
+
+} // namespace ns3
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/capability.h Tue Mar 27 21:48:22 2007 -0700
@@ -0,0 +1,55 @@
+// -*- 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>
+//
+// Define the base class for all node capabilities.
+// George F. Riley, Georgia Tech, Fall 2006
+
+#ifndef __CAPABILITY_H__
+#define __CAPABILITY_H__
+
+// All capabilities must implement a copy method, to allow node subclasses
+// to have a pointer to any subclass of the capability and still copy
+// correctly. Capabilities also have a pointer to the owning node.
+// The node pointer is not owned by the capability, and is not deleted
+// by the capability destructor.
+
+#define nil 0
+
+namespace ns3 {
+class Node;
+class NodeReference;
+
+class Capability
+{
+public:
+ Capability();
+ Capability(Node* n);
+ Capability(const Capability&); // Copy constructor
+ virtual Capability& operator=(const Capability&); // Assignment operator
+ virtual ~Capability();
+ virtual Capability* Copy(Node&) const = 0;
+ virtual void SetNode(Node&);
+ virtual Node* GetNode() const;
+private:
+ NodeReference* m_node; // Node on which this capability is assigned
+};
+
+} //namespace ns3
+#endif
--- a/src/node/internet-node.cc Tue Mar 27 15:42:17 2007 -0700
+++ b/src/node/internet-node.cc Tue Mar 27 21:48:22 2007 -0700
@@ -24,6 +24,7 @@
#include "ns3/composite-trace-resolver.h"
#include "net-device-list.h"
+#include "application-list.h"
#include "l3-demux.h"
#include "ipv4-l4-demux.h"
#include "internet-node.h"
@@ -45,6 +46,7 @@
{
// Instantiate the capabilities
m_netDevices = new NetDeviceList();
+ m_applicationList = new ApplicationList();
m_l3Demux = new L3Demux(this);
m_ipv4L4Demux = new Ipv4L4Demux(this);
m_l3Demux->Insert (Ipv4 (this));
@@ -56,6 +58,7 @@
InternetNode::InternetNode (InternetNode const &o)
{
m_netDevices = new NetDeviceList ();
+ m_applicationList = new ApplicationList();
m_l3Demux = o.m_l3Demux->Copy (this);
m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this);
SetupLoopback ();
@@ -64,6 +67,7 @@
InternetNode::operator = (InternetNode const &o)
{
delete m_netDevices;
+ delete m_applicationList;
delete m_l3Demux;
delete m_ipv4L4Demux;
m_netDevices = new NetDeviceList ();
@@ -76,6 +80,7 @@
InternetNode::~InternetNode ()
{
delete m_netDevices;
+ delete m_applicationList;
delete m_l3Demux;
delete m_ipv4L4Demux;
}
@@ -128,6 +133,12 @@
return m_netDevices;
}
+ApplicationList*
+InternetNode::GetApplicationList() const
+{
+ return m_applicationList;
+}
+
L3Demux*
InternetNode::GetL3Demux() const
{
--- a/src/node/internet-node.h Tue Mar 27 15:42:17 2007 -0700
+++ b/src/node/internet-node.h Tue Mar 27 21:48:22 2007 -0700
@@ -48,6 +48,7 @@
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
// Capability access
virtual NetDeviceList* GetNetDeviceList() const;
+ virtual ApplicationList* GetApplicationList() const;
virtual L3Demux* GetL3Demux() const;
virtual Ipv4L4Demux* GetIpv4L4Demux() const;
virtual Ipv4 * GetIpv4 (void) const;
@@ -59,6 +60,7 @@
void SetupLoopback (void);
// Capabilities
NetDeviceList* m_netDevices;
+ ApplicationList* m_applicationList;
L3Demux* m_l3Demux;
Ipv4L4Demux* m_ipv4L4Demux;
std::string m_name;
--- a/src/node/node.cc Tue Mar 27 15:42:17 2007 -0700
+++ b/src/node/node.cc Tue Mar 27 21:48:22 2007 -0700
@@ -124,6 +124,11 @@
return 0;
}
+ApplicationList* Node::GetApplicationList() const
+{
+ return 0;
+}
+
NetDeviceList*
Node::GetNetDeviceList() const
{
--- a/src/node/node.h Tue Mar 27 15:42:17 2007 -0700
+++ b/src/node/node.h Tue Mar 27 21:48:22 2007 -0700
@@ -86,15 +86,20 @@
namespace ns3 {
+class NodeList;
+
+class NetDeviceList;
+class ApplicationList;
+
+// The below five may be encapsulated/abstracted in a Kernel or Stack class
class L3Demux;
class Ipv4L4Demux;
-class NetDeviceList;
class Ipv4;
class Udp;
class Arp;
+
class TraceContext;
class TraceResolver;
-class NodeList;
class Node {
friend class NodeList;
@@ -168,6 +173,7 @@
virtual L3Demux* GetL3Demux() const;
virtual Ipv4L4Demux* GetIpv4L4Demux() const;
virtual NetDeviceList* GetNetDeviceList() const;
+ virtual ApplicationList* GetApplicationList() const;
virtual Ipv4 * GetIpv4 (void) const;
virtual Udp * GetUdp (void) const;
virtual Arp * GetArp (void) const;