Add ApplicationList and Capability
This commit is contained in:
91
src/node/application-list.cc
Normal file
91
src/node/application-list.cc
Normal file
@@ -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
|
||||
60
src/node/application-list.h
Normal file
60
src/node/application-list.h
Normal file
@@ -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
|
||||
|
||||
82
src/node/capability.cc
Normal file
82
src/node/capability.cc
Normal file
@@ -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
|
||||
|
||||
55
src/node/capability.h
Normal file
55
src/node/capability.h
Normal file
@@ -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
|
||||
@@ -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 @@ InternetNode::InternetNode()
|
||||
{
|
||||
// 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::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 const &
|
||||
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::operator = (InternetNode const &o)
|
||||
InternetNode::~InternetNode ()
|
||||
{
|
||||
delete m_netDevices;
|
||||
delete m_applicationList;
|
||||
delete m_l3Demux;
|
||||
delete m_ipv4L4Demux;
|
||||
}
|
||||
@@ -128,6 +133,12 @@ InternetNode::GetNetDeviceList() const
|
||||
return m_netDevices;
|
||||
}
|
||||
|
||||
ApplicationList*
|
||||
InternetNode::GetApplicationList() const
|
||||
{
|
||||
return m_applicationList;
|
||||
}
|
||||
|
||||
L3Demux*
|
||||
InternetNode::GetL3Demux() const
|
||||
{
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
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 @@ private:
|
||||
void SetupLoopback (void);
|
||||
// Capabilities
|
||||
NetDeviceList* m_netDevices;
|
||||
ApplicationList* m_applicationList;
|
||||
L3Demux* m_l3Demux;
|
||||
Ipv4L4Demux* m_ipv4L4Demux;
|
||||
std::string m_name;
|
||||
|
||||
@@ -124,6 +124,11 @@ Node::GetIpv4L4Demux() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
ApplicationList* Node::GetApplicationList() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NetDeviceList*
|
||||
Node::GetNetDeviceList() const
|
||||
{
|
||||
|
||||
@@ -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 @@ public:
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user