branch merge

This commit is contained in:
Craig Dowell
2008-03-24 12:57:32 -07:00
23 changed files with 451 additions and 151 deletions

View File

@@ -142,7 +142,7 @@ Experiment::Run (const WifiHelper &wifi)
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::StaticMobilityModel");
mobility.Layout (c.Begin (), c.End ());
mobility.Layout (c);
PacketSocketAddress destination = PacketSocketAddress ();
destination.SetProtocol (1);

View File

@@ -150,19 +150,19 @@ int main (int argc, char *argv[])
Ssid ssid = Ssid ("wifi-default");
wifi.SetPhy ("ns3::WifiPhy");
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
// setup ap.
// setup stas.
wifi.SetMac ("ns3::NqstaWifiMac", "Ssid", ssid,
"ActiveProbing", Boolean (false));
staDevs = wifi.Build (stas, channel);
// setup stas.
// setup ap.
wifi.SetMac ("ns3::NqapWifiMac", "Ssid", ssid,
"BeaconGeneration", Boolean (true),
"BeaconInterval", Seconds (2.5));
wifi.Build (ap, channel);
// mobility.
mobility.Layout (stas.Begin (), stas.End ());
mobility.Layout (ap.Begin (), ap.End ());
mobility.Layout (stas);
mobility.Layout (ap);
Simulator::Schedule (Seconds (1.0), &AdvancePosition, ap.Get (0));

View File

@@ -16,13 +16,10 @@ int main (int argc, char *argv[])
CommandLine cmd;
cmd.Parse (argc, argv);
std::vector<Ptr<Object> > nodes;
NodeContainer nodes;
// create an array of empty nodes for testing purposes
for (uint32_t i = 0; i < 120; i++)
{
nodes.push_back (CreateObject<Node> ());
}
nodes.Create (120);
MobilityHelper mobility;
// setup the grid itself: objects are layed out
@@ -44,13 +41,13 @@ int main (int argc, char *argv[])
// finalize the setup by attaching to each object
// in the input array a position and initializing
// this position with the calculated coordinates.
mobility.Layout (nodes.begin (), nodes.end ());
mobility.Layout (nodes);
// iterate our nodes and print their position.
for (std::vector<Ptr<Object> >::const_iterator j = nodes.begin ();
j != nodes.end (); j++)
for (NodeContainer::Iterator j = nodes.Begin ();
j != nodes.End (); ++j)
{
Ptr<Object> object = *j;
Ptr<Node> object = *j;
Ptr<MobilityModel> position = object->GetObject<MobilityModel> ();
NS_ASSERT (position != 0);
Vector pos = position->GetPosition ();

View File

@@ -29,11 +29,8 @@ int main (int argc, char *argv[])
cmd.Parse (argc, argv);
std::vector<Ptr<Object> > objects;
for (uint32_t i = 0; i < 10000; i++)
{
objects.push_back (CreateObject<Node> ());
}
NodeContainer c;
c.Create (10000);
MobilityHelper mobility;
mobility.EnableNotifier ();
@@ -42,7 +39,7 @@ int main (int argc, char *argv[])
"Y", String ("100.0"),
"Rho", String ("Uniform:0:30"));
mobility.SetMobilityModel ("ns3::StaticMobilityModel");
mobility.Layout (objects.begin (), objects.end ());
mobility.Layout (c);
Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange",
MakeCallback (&CourseChange));

View File

@@ -36,10 +36,8 @@ int main (int argc, char *argv[])
CommandLine cmd;
cmd.Parse (argc, argv);
for (uint32_t i = 0; i < 100; i++)
{
Ptr<Node> node = CreateObject<Node> ();
}
NodeContainer c;
c.Create (100);
MobilityHelper mobility;
mobility.EnableNotifier ();
@@ -52,7 +50,7 @@ int main (int argc, char *argv[])
"Time", String ("2s"),
"Speed", String ("Constant:1.0"),
"Bounds", String ("0:200:0:100"));
mobility.Layout (NodeList::Begin (), NodeList::End ());
mobility.LayoutAll ();
Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange",
MakeCallback (&CourseChange));

View File

@@ -10,11 +10,28 @@
namespace ns3 {
/**
* \brief build a set of CsmaNetDevice objects
*/
class CsmaHelper
{
public:
CsmaHelper ();
/**
* \param type the type of queue
* \param n1 the name of the attribute to set on the queue
* \param v1 the value of the attribute to set on the queue
* \param n2 the name of the attribute to set on the queue
* \param v2 the value of the attribute to set on the queue
* \param n3 the name of the attribute to set on the queue
* \param v3 the value of the attribute to set on the queue
* \param n4 the name of the attribute to set on the queue
* \param v4 the value of the attribute to set on the queue
*
* Set the type of queue to create and associated to each
* CsmaNetDevice created through CsmaHelper::Build.
*/
void SetQueue (std::string type,
std::string n1 = "", Attribute v1 = Attribute (),
std::string n2 = "", Attribute v2 = Attribute (),
@@ -22,15 +39,40 @@ public:
std::string n4 = "", Attribute v4 = Attribute ());
/**
* Set these parameters on each PointToPointNetDevice created
* by this helper.
* \param n1 the name of the attribute to set
* \param v1 the value of the attribute to set
*
* Set these parameters on each ns3::CsmaNetDevice created
* by CsmaHelper::Build
*/
void SetDeviceParameter (std::string n1, Attribute v1);
/**
* \param n1 the name of the attribute to set
* \param v1 the value of the attribute to set
*
* Set these parameters on each ns3::CsmaChannel created
* by CsmaHelper::Build
*/
void SetChannelParameter (std::string n1, Attribute v1);
/**
* \param c a set of nodes
*
* This method creates a simple ns3::CsmaChannel with the
* attributes configured by CsmaHelper::SetChannelParameter and
* then calls CsmaHelper::Build.
*/
NetDeviceContainer Build (const NodeContainer &c);
/**
* \param c a set of nodes
* \param channel the channel to use as a backbone.
*
* For each node in the input container, we create a ns3::CsmaNetDevice with
* the requested parameters, a queue for this NetDevice, and associate
* the resulting ns3::NetDevice with the ns3::Node and ns3::CsmaChannel.
*/
NetDeviceContainer Build (const NodeContainer &c, Ptr<CsmaChannel> channel);
private:

View File

@@ -0,0 +1,17 @@
#include "internet-stack-helper.h"
#include "ns3/internet-stack.h"
namespace ns3 {
void
InternetStackHelper::Build (NodeContainer c)
{
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
Ptr<Node> node = *i;
AddInternetStack (node);
}
}
} // namespace ns3

View File

@@ -0,0 +1,25 @@
#ifndef INTERNET_STACK_HELPER_H
#define INTERNET_STACK_HELPER_H
#include "node-container.h"
namespace ns3 {
/**
* \brief aggregate ip/tcp/udp functionality to existing Nodes.
*/
class InternetStackHelper
{
public:
/**
* \param c the set of nodes
*
* For each node in the input container, aggregate implementations
* of the ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes.
*/
void Build (NodeContainer c);
};
} // namespace ns3
#endif /* INTERNET_STACK_HELPER_H */

View File

@@ -101,9 +101,9 @@ MobilityHelper::GetMobilityModelType (void) const
}
void
MobilityHelper::Layout (const std::vector<Ptr<Object> > &objects)
MobilityHelper::Layout (NodeContainer c)
{
for (std::vector<Ptr<Object> >::const_iterator i = objects.begin (); i != objects.end (); i++)
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
Ptr<Object> object = *i;
Ptr<MobilityModel> model = object->GetObject<MobilityModel> ();
@@ -145,4 +145,10 @@ MobilityHelper::Layout (const std::vector<Ptr<Object> > &objects)
}
}
void
MobilityHelper::LayoutAll (void)
{
Layout (NodeContainer::GetGlobal ());
}
} // namespace ns3

View File

@@ -4,23 +4,67 @@
#include <vector>
#include "ns3/object-factory.h"
#include "ns3/attribute.h"
#include "position-allocator.h"
#include "ns3/position-allocator.h"
#include "node-container.h"
namespace ns3 {
class PositionAllocator;
class MobilityModel;
/**
* \brief assign positions and mobility models to nodes.
*
* MobilityHelper::Layout is the most important method here.
*/
class MobilityHelper
{
public:
MobilityHelper ();
/**
* After this method is called, every call to MobilityHelper::Layout
* will also attach to the new ns3::MobilityModel an ns3::MobilityModelNotifier
* which can be used to listen to CourseChange events.
*/
void EnableNotifier (void);
/**
* After this method is called, no ns3::MobilityModelNotifier object will
* be associated to any new ns3::MobilityModel created by MobilityHelper::Layout.
* This will make it impossible to listen to "CourseChange" events from these
* new ns3::MobilityModel instances.
*/
void DisableNotifier (void);
/**
* \param allocator allocate initial node positions
*
* Set the position allocator which will be used to allocate
* the initial position of every node in MobilityModel::Layout.
*/
void SetPositionAllocator (Ptr<PositionAllocator> allocator);
/**
* \param type the type of mobility model to use.
* \param n1 the name of the attribute to set in the mobility model.
* \param v1 the value of the attribute to set in the mobility model.
* \param n2 the name of the attribute to set in the mobility model.
* \param v2 the value of the attribute to set in the mobility model.
* \param n3 the name of the attribute to set in the mobility model.
* \param v3 the value of the attribute to set in the mobility model.
* \param n4 the name of the attribute to set in the mobility model.
* \param v4 the value of the attribute to set in the mobility model.
* \param n5 the name of the attribute to set in the mobility model.
* \param v5 the value of the attribute to set in the mobility model.
* \param n6 the name of the attribute to set in the mobility model.
* \param v6 the value of the attribute to set in the mobility model.
* \param n7 the name of the attribute to set in the mobility model.
* \param v7 the value of the attribute to set in the mobility model.
* \param n8 the name of the attribute to set in the mobility model.
* \param v8 the value of the attribute to set in the mobility model.
* \param n9 the name of the attribute to set in the mobility model.
* \param v9 the value of the attribute to set in the mobility model.
*/
void SetPositionAllocator (std::string type,
std::string n1 = "", Attribute v1 = Attribute (),
std::string n2 = "", Attribute v2 = Attribute (),
@@ -32,6 +76,30 @@ public:
std::string n8 = "", Attribute v8 = Attribute (),
std::string n9 = "", Attribute v9 = Attribute ());
/**
* \param type the type of mobility model to use.
* \param n1 the name of the attribute to set in the mobility model.
* \param v1 the value of the attribute to set in the mobility model.
* \param n2 the name of the attribute to set in the mobility model.
* \param v2 the value of the attribute to set in the mobility model.
* \param n3 the name of the attribute to set in the mobility model.
* \param v3 the value of the attribute to set in the mobility model.
* \param n4 the name of the attribute to set in the mobility model.
* \param v4 the value of the attribute to set in the mobility model.
* \param n5 the name of the attribute to set in the mobility model.
* \param v5 the value of the attribute to set in the mobility model.
* \param n6 the name of the attribute to set in the mobility model.
* \param v6 the value of the attribute to set in the mobility model.
* \param n7 the name of the attribute to set in the mobility model.
* \param v7 the value of the attribute to set in the mobility model.
* \param n8 the name of the attribute to set in the mobility model.
* \param v8 the value of the attribute to set in the mobility model.
* \param n9 the name of the attribute to set in the mobility model.
* \param v9 the value of the attribute to set in the mobility model.
*
* Calls to MobilityHelper::Layout will create an instance of a matching
* mobility model for each node.
*/
void SetMobilityModel (std::string type,
std::string n1 = "", Attribute v1 = Attribute (),
std::string n2 = "", Attribute v2 = Attribute (),
@@ -43,15 +111,56 @@ public:
std::string n8 = "", Attribute v8 = Attribute (),
std::string n9 = "", Attribute v9 = Attribute ());
/**
* \param reference item to push.
*
* Push an item on the top of the stack of "reference mobility models".
* The input item should be a node instance to which a mobility model
* has already been aggregated (usually by a call to Layout).
*
* If this this stack is not empty when MobilityHelper::Layout
* is called, the model from the top of the stack is used
* to create a ns3::HierarchicalMobilityModel to make the
* newly-created models define their positions relative to that
* of the parent mobility model.
*
* This method is typically used to create hierarchical mobility
* patterns and positions by starting with the large-scale mobility
* features, and, then, defining the smaller-scale movements relative
* to a few reference points in the large-scale model.
*/
void PushReferenceMobilityModel (Ptr<Object> reference);
/**
* Remove the top item from the top of the stack of
* "reference mobility models".
*/
void PopReferenceMobilityModel (void);
/**
* \returns a string which contains the TypeId of the currently-selected
* mobility model.
*/
std::string GetMobilityModelType (void) const;
template <typename T>
void Layout (T begin, T end);
/**
* \param container the set of nodes to layout.
*
* For each input node, this method creates an instance of a ns3::MobilityModel
* subclass (the type of which was set with MobilityHelper::SetMobilityModel),
* aggregates it to the mode, and sets an initial position based on the current
* position allocator (set through MobilityHelper::SetPositionAllocator).
* Optionally, this method will also create and aggregate a
* ns3::MobilityModelNotifier to generate 'CourseChange' events based on the
* boolean flag set by MobilityHelper::EnableNotifier and MobilityHelper::DisableNotifier.
*/
void Layout (NodeContainer container);
/**
* Perform the work of MobilityHelper::Layout on _all_ nodes which
* exist in the simulation.
*/
void LayoutAll (void);
private:
void Layout (const std::vector<Ptr<Object> > &objects);
std::vector<Ptr<MobilityModel> > m_mobilityStack;
bool m_notifierEnabled;
@@ -61,21 +170,4 @@ private:
} // namespace ns3
namespace ns3 {
template <typename T>
void
MobilityHelper::Layout (T begin, T end)
{
std::vector<Ptr<Object> > objects;
for (T i = begin; i != end; i++)
{
Ptr<Object> object = *i;
objects.push_back (object);
}
Layout (objects);
}
} // namespace ns3
#endif /* MOBILITY_HELPER_H */

View File

@@ -5,36 +5,36 @@ namespace ns3 {
NetDeviceContainer::Iterator
NetDeviceContainer::Begin (void) const
{
return m_nodes.begin ();
return m_devices.begin ();
}
NetDeviceContainer::Iterator
NetDeviceContainer::End (void) const
{
return m_nodes.end ();
return m_devices.end ();
}
uint32_t
NetDeviceContainer::GetN (void) const
{
return m_nodes.size ();
return m_devices.size ();
}
Ptr<NetDevice>
NetDeviceContainer::Get (uint32_t i) const
{
return m_nodes[i];
return m_devices[i];
}
void
NetDeviceContainer::Add (NetDeviceContainer other)
{
for (Iterator i = other.Begin (); i != other.End (); i++)
{
m_nodes.push_back (*i);
m_devices.push_back (*i);
}
}
void
NetDeviceContainer::Add (Ptr<NetDevice> node)
NetDeviceContainer::Add (Ptr<NetDevice> device)
{
m_nodes.push_back (node);
m_devices.push_back (device);
}
} // namespace ns3

View File

@@ -7,23 +7,49 @@
namespace ns3 {
/**
* \brief holds a vector of ns3::NetDevice pointers
*
*/
class NetDeviceContainer
{
public:
typedef std::vector<Ptr<NetDevice> >::const_iterator Iterator;
/**
* \returns an iterator which points to the start of the array of pointers.
*/
Iterator Begin (void) const;
/**
* \returns an iterator which points to the end of the array of pointers.
*/
Iterator End (void) const;
/**
* \returns the number of netdevice pointers stored in this container.
*/
uint32_t GetN (void) const;
/**
* \param i the index of the requested netdevice pointer.
* \returns the requested netdevice pointer.
*/
Ptr<NetDevice> Get (uint32_t i) const;
void Create (uint32_t n);
/**
* \param other another netdevice container
*
* Append to the end of this container the other input container.
*/
void Add (NetDeviceContainer other);
void Add (Ptr<NetDevice> node);
/**
* \param device another netdevice pointer.
*
* Append to the end of this container the input netdevice pointer.
*/
void Add (Ptr<NetDevice> device);
private:
std::vector<Ptr<NetDevice> > m_nodes;
std::vector<Ptr<NetDevice> > m_devices;
};
} // namespace ns3

View File

@@ -1,4 +1,5 @@
#include "node-container.h"
#include "ns3/node-list.h"
namespace ns3 {
@@ -58,4 +59,15 @@ NodeContainer::Add (Ptr<Node> node)
m_nodes.push_back (node);
}
NodeContainer
NodeContainer::GetGlobal (void)
{
NodeContainer c;
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
{
c.Add (*i);
}
return c;
}
} // namespace ns3

View File

@@ -74,6 +74,13 @@ public:
*/
void Add (Ptr<Node> node);
/**
* \returns a container which contains a list of _all_ nodes
* created through NodeContainer::Create and stored
* in ns3::NodeList.
*/
static NodeContainer GetGlobal (void);
private:
std::vector<Ptr<Node> > m_nodes;
};

View File

@@ -34,7 +34,11 @@ OlsrHelper::SetAgent (std::string tid,
void
OlsrHelper::Enable (NodeContainer container)
{
Enable (container.Begin (), container.End ());
for (NodeContainer::Iterator i = container.Begin (); i != container.End (); ++i)
{
Ptr<Node> node = *i;
Enable (node);
}
}
void
OlsrHelper::Enable (Ptr<Node> node)
@@ -47,7 +51,7 @@ OlsrHelper::Enable (Ptr<Node> node)
void
OlsrHelper::EnableAll (void)
{
Enable (NodeList::Begin (), NodeList::End ());
Enable (NodeContainer::GetGlobal ());
}
} // namespace ns3

View File

@@ -22,8 +22,6 @@ public:
std::string n6 = "", Attribute v6 = Attribute (),
std::string n7 = "", Attribute v7 = Attribute ());
template <typename InputIterator>
void Enable (InputIterator begin, InputIterator end);
void Enable (NodeContainer container);
void Enable (Ptr<Node> node);
void EnableAll (void);
@@ -33,20 +31,4 @@ private:
} // namespace ns3
namespace ns3 {
template <typename T>
void
OlsrHelper::Enable (T begin, T end)
{
for (T i = begin; i != end; i++)
{
Ptr<Object> obj = (*i);
Ptr<Node> node = obj->GetObject<Node> ();
Enable (node);
}
}
} // namespace ns3
#endif /* OLSR_HELPER_H */

View File

@@ -8,22 +8,69 @@
namespace ns3 {
/**
* \brief build a set of PointToPointNetDevice objects
*/
class PointToPointHelper
{
public:
// by default, create queues of type DropTailQueue.
PointToPointHelper ();
/**
* \param type the type of queue
* \param n1 the name of the attribute to set on the queue
* \param v1 the value of the attribute to set on the queue
* \param n2 the name of the attribute to set on the queue
* \param v2 the value of the attribute to set on the queue
* \param n3 the name of the attribute to set on the queue
* \param v3 the value of the attribute to set on the queue
* \param n4 the name of the attribute to set on the queue
* \param v4 the value of the attribute to set on the queue
*
* Set the type of queue to create and associated to each
* PointToPointNetDevice created through PointToPointHelper::Build.
*/
void SetQueue (std::string type,
std::string n1 = "", Attribute v1 = Attribute (),
std::string n2 = "", Attribute v2 = Attribute (),
std::string n3 = "", Attribute v3 = Attribute (),
std::string n4 = "", Attribute v4 = Attribute ());
/**
* \param name the name of the attribute to set
* \param value the value of the attribute to set
*
* Set these parameters on each ns3::PointToPointNetDevice created
* by PointToPointHelper::Build
*/
void SetDeviceParameter (std::string name, Attribute value);
/**
* \param name the name of the attribute to set
* \param value the value of the attribute to set
*
* Set these parameters on each ns3::PointToPointChannel created
* by PointToPointHelper::Build
*/
void SetChannelParameter (std::string name, Attribute value);
/**
* \param c a set of nodes
*
* This method creates a ns3::PointToPointChannel with the
* attributes configured by PointToPointHelper::SetChannelParameter,
* then, for each node in the input container, we create a
* ns3::PointToPointNetDevice with the requested parameters,
* a queue for this ns3::NetDevice, and associate the resulting
* ns3::NetDevice with the ns3::Node and ns3::PointToPointChannel.
*/
NetDeviceContainer Build (NodeContainer c);
/**
* \param a first node
* \param b second node
*
* Saves you from having to construct a temporary NodeContainer.
*/
NetDeviceContainer Build (Ptr<Node> a, Ptr<Node> b);
private:

View File

@@ -12,6 +12,7 @@ def build(bld):
'mobility-helper.cc',
'ns2-mobility-helper.cc',
'ipv4-address-helper.cc',
'internet-stack-helper.cc',
]
headers = bld.create_obj('ns3header')
@@ -26,4 +27,5 @@ def build(bld):
'mobility-helper.h',
'ns2-mobility-helper.h',
'ipv4-address-helper.h',
'internet-stack-helper.h',
]

View File

@@ -23,77 +23,16 @@
#include "ns3/net-device.h"
#include "ns3/callback.h"
#include "ipv4-l4-demux.h"
#include "internet-node.h"
#include "udp-l4-protocol.h"
#include "tcp-l4-protocol.h"
#include "ipv4-l3-protocol.h"
#include "arp-l3-protocol.h"
#include "udp-impl.h"
#include "tcp-impl.h"
#include "ipv4-impl.h"
#include "internet-stack.h"
namespace ns3 {
InternetNode::InternetNode()
{
Construct ();
AddInternetStack (this);
}
InternetNode::InternetNode(uint32_t systemId)
{
Construct ();
}
InternetNode::~InternetNode ()
{}
void
InternetNode::Construct (void)
{
Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
ipv4->SetNode (this);
arp->SetNode (this);
// XXX remove the PeekPointer below.
RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, PeekPointer (ipv4)),
Ipv4L3Protocol::PROT_NUMBER, 0);
RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (arp)),
ArpL3Protocol::PROT_NUMBER, 0);
Ptr<Ipv4L4Demux> ipv4L4Demux = CreateObject<Ipv4L4Demux> ();
Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
ipv4L4Demux->SetNode (this);
udp->SetNode (this);
tcp->SetNode (this);
ipv4L4Demux->Insert (udp);
ipv4L4Demux->Insert (tcp);
Ptr<UdpImpl> udpImpl = CreateObject<UdpImpl> ();
Ptr<TcpImpl> tcpImpl = CreateObject<TcpImpl> ();
Ptr<Ipv4Impl> ipv4Impl = CreateObject<Ipv4Impl> ();
udpImpl->SetUdp (udp);
tcpImpl->SetTcp (tcp);
ipv4Impl->SetIpv4 (ipv4);
Object::AggregateObject (ipv4);
Object::AggregateObject (arp);
Object::AggregateObject (ipv4Impl);
Object::AggregateObject (udpImpl);
Object::AggregateObject (tcpImpl);
Object::AggregateObject (ipv4L4Demux);
}
void
InternetNode::DoDispose()
{
Node::DoDispose ();
}
}//namespace ns3

View File

@@ -58,13 +58,6 @@ class InternetNode : public Node
{
public:
InternetNode();
InternetNode(uint32_t systemId);
virtual ~InternetNode ();
protected:
virtual void DoDispose(void);
private:
void Construct (void);
};
}//namespace ns3

View File

@@ -0,0 +1,78 @@
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
//
// 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>
//
#include "ns3/net-device.h"
#include "ns3/callback.h"
#include "ipv4-l4-demux.h"
#include "internet-node.h"
#include "udp-l4-protocol.h"
#include "tcp-l4-protocol.h"
#include "ipv4-l3-protocol.h"
#include "arp-l3-protocol.h"
#include "udp-impl.h"
#include "tcp-impl.h"
#include "ipv4-impl.h"
namespace ns3 {
void
AddInternetStack (Ptr<Node> node)
{
Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
ipv4->SetNode (node);
arp->SetNode (node);
// XXX remove the PeekPointer below.
node->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, PeekPointer (ipv4)),
Ipv4L3Protocol::PROT_NUMBER, 0);
node->RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (arp)),
ArpL3Protocol::PROT_NUMBER, 0);
Ptr<Ipv4L4Demux> ipv4L4Demux = CreateObject<Ipv4L4Demux> ();
Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
ipv4L4Demux->SetNode (node);
udp->SetNode (node);
tcp->SetNode (node);
ipv4L4Demux->Insert (udp);
ipv4L4Demux->Insert (tcp);
Ptr<UdpImpl> udpImpl = CreateObject<UdpImpl> ();
Ptr<TcpImpl> tcpImpl = CreateObject<TcpImpl> ();
Ptr<Ipv4Impl> ipv4Impl = CreateObject<Ipv4Impl> ();
udpImpl->SetUdp (udp);
tcpImpl->SetTcp (tcp);
ipv4Impl->SetIpv4 (ipv4);
node->AggregateObject (ipv4);
node->AggregateObject (arp);
node->AggregateObject (ipv4Impl);
node->AggregateObject (udpImpl);
node->AggregateObject (tcpImpl);
node->AggregateObject (ipv4L4Demux);
}
}//namespace ns3

View File

@@ -0,0 +1,34 @@
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
//
// 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>
#ifndef INTERNET_STACK_H
#define INTERNET_STACK_H
#include "ns3/ptr.h"
namespace ns3 {
class Node;
void AddInternetStack (Ptr<Node> node);
}//namespace ns3
#endif /* INTERNET_STACK_H */

View File

@@ -5,6 +5,7 @@ def build(bld):
obj = bld.create_ns3_module('internet-node', ['node'])
obj.source = [
'internet-node.cc',
'internet-stack.cc',
'ipv4-l4-demux.cc',
'ipv4-l4-protocol.cc',
'ipv4-header.cc',
@@ -39,6 +40,7 @@ def build(bld):
headers.module = 'internet-node'
headers.source = [
'internet-node.h',
'internet-stack.h',
'ascii-trace.h',
'pcap-trace.h',
'ipv4-header.h',