mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 10:03:58 +02:00
init
This commit is contained in:
commit
13e4bf1aa7
21 changed files with 2601 additions and 0 deletions
258
helper/isl-helper.cc
Normal file
258
helper/isl-helper.cc
Normal file
|
@ -0,0 +1,258 @@
|
|||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2008 INRIA
|
||||
*
|
||||
* 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include "ns3/abort.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/point-to-point-net-device.h"
|
||||
#include "ns3/point-to-point-channel.h"
|
||||
#include "ns3/point-to-point-remote-channel.h"
|
||||
#include "ns3/queue.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/names.h"
|
||||
#include "ns3/trace-helper.h"
|
||||
|
||||
#include "../model/isl-net-device.h"
|
||||
#include "../model/isl-channel.h"
|
||||
#include "isl-helper.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("IslHelper");
|
||||
|
||||
IslHelper::IslHelper ()
|
||||
{
|
||||
m_queueFactory.SetTypeId ("ns3::DropTailQueue<Packet>");
|
||||
m_deviceFactory.SetTypeId ("ns3::IslNetDevice");
|
||||
m_channelFactory.SetTypeId ("ns3::IslChannel");
|
||||
}
|
||||
|
||||
void
|
||||
IslHelper::SetQueue (std::string type,
|
||||
std::string n1, const AttributeValue &v1,
|
||||
std::string n2, const AttributeValue &v2,
|
||||
std::string n3, const AttributeValue &v3,
|
||||
std::string n4, const AttributeValue &v4)
|
||||
{
|
||||
QueueBase::AppendItemTypeIfNotPresent (type, "Packet");
|
||||
|
||||
m_queueFactory.SetTypeId (type);
|
||||
m_queueFactory.Set (n1, v1);
|
||||
m_queueFactory.Set (n2, v2);
|
||||
m_queueFactory.Set (n3, v3);
|
||||
m_queueFactory.Set (n4, v4);
|
||||
}
|
||||
|
||||
void
|
||||
IslHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
|
||||
{
|
||||
m_deviceFactory.Set (n1, v1);
|
||||
}
|
||||
|
||||
void
|
||||
IslHelper::SetChannelAttribute (std::string n1, const AttributeValue &v1)
|
||||
{
|
||||
m_channelFactory.Set (n1, v1);
|
||||
}
|
||||
|
||||
void
|
||||
IslHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
|
||||
{
|
||||
//
|
||||
// All of the Pcap enable functions vector through here including the ones
|
||||
// that are wandering through all of devices on perhaps all of the nodes in
|
||||
// the system. We can only deal with devices of type IslNetDevice.
|
||||
//
|
||||
Ptr<IslNetDevice> device = nd->GetObject<IslNetDevice> ();
|
||||
if (device == 0)
|
||||
{
|
||||
NS_LOG_INFO ("IslHelper::EnablePcapInternal(): Device " << device << " not of type ns3::IslNetDevice");
|
||||
return;
|
||||
}
|
||||
|
||||
PcapHelper pcapHelper;
|
||||
|
||||
std::string filename;
|
||||
if (explicitFilename)
|
||||
{
|
||||
filename = prefix;
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = pcapHelper.GetFilenameFromDevice (prefix, device);
|
||||
}
|
||||
|
||||
Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out,
|
||||
PcapHelper::DLT_PPP);
|
||||
pcapHelper.HookDefaultSink<IslNetDevice> (device, "PromiscSniffer", file);
|
||||
}
|
||||
|
||||
void
|
||||
IslHelper::EnableAsciiInternal (
|
||||
Ptr<OutputStreamWrapper> stream,
|
||||
std::string prefix,
|
||||
Ptr<NetDevice> nd,
|
||||
bool explicitFilename)
|
||||
{
|
||||
//
|
||||
// All of the ascii enable functions vector through here including the ones
|
||||
// that are wandering through all of devices on perhaps all of the nodes in
|
||||
// the system. We can only deal with devices of type IslNetDevice.
|
||||
//
|
||||
Ptr<IslNetDevice> device = nd->GetObject<IslNetDevice> ();
|
||||
if (device == 0)
|
||||
{
|
||||
NS_LOG_INFO ("IslHelper::EnableAsciiInternal(): Device " << device <<
|
||||
" not of type ns3::IslNetDevice");
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Our default trace sinks are going to use packet printing, so we have to
|
||||
// make sure that is turned on.
|
||||
//
|
||||
Packet::EnablePrinting ();
|
||||
|
||||
//
|
||||
// If we are not provided an OutputStreamWrapper, we are expected to create
|
||||
// one using the usual trace filename conventions and do a Hook*WithoutContext
|
||||
// since there will be one file per context and therefore the context would
|
||||
// be redundant.
|
||||
//
|
||||
if (stream == 0)
|
||||
{
|
||||
//
|
||||
// Set up an output stream object to deal with private ofstream copy
|
||||
// constructor and lifetime issues. Let the helper decide the actual
|
||||
// name of the file given the prefix.
|
||||
//
|
||||
AsciiTraceHelper asciiTraceHelper;
|
||||
|
||||
std::string filename;
|
||||
if (explicitFilename)
|
||||
{
|
||||
filename = prefix;
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
|
||||
}
|
||||
|
||||
Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
|
||||
|
||||
//
|
||||
// The MacRx trace source provides our "r" event.
|
||||
//
|
||||
asciiTraceHelper.HookDefaultReceiveSinkWithoutContext<IslNetDevice> (device, "MacRx", theStream);
|
||||
|
||||
//
|
||||
// The "+", '-', and 'd' events are driven by trace sources actually in the
|
||||
// transmit queue.
|
||||
//
|
||||
Ptr<Queue<Packet> > queue = device->GetQueue ();
|
||||
asciiTraceHelper.HookDefaultEnqueueSinkWithoutContext<Queue<Packet> > (queue, "Enqueue", theStream);
|
||||
asciiTraceHelper.HookDefaultDropSinkWithoutContext<Queue<Packet> > (queue, "Drop", theStream);
|
||||
asciiTraceHelper.HookDefaultDequeueSinkWithoutContext<Queue<Packet> > (queue, "Dequeue", theStream);
|
||||
|
||||
// PhyRxDrop trace source for "d" event
|
||||
asciiTraceHelper.HookDefaultDropSinkWithoutContext<IslNetDevice> (device, "PhyRxDrop", theStream);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// If we are provided an OutputStreamWrapper, we are expected to use it, and
|
||||
// to providd a context. We are free to come up with our own context if we
|
||||
// want, and use the AsciiTraceHelper Hook*WithContext functions, but for
|
||||
// compatibility and simplicity, we just use Config::Connect and let it deal
|
||||
// with the context.
|
||||
//
|
||||
// Note that we are going to use the default trace sinks provided by the
|
||||
// ascii trace helper. There is actually no AsciiTraceHelper in sight here,
|
||||
// but the default trace sinks are actually publicly available static
|
||||
// functions that are always there waiting for just such a case.
|
||||
//
|
||||
uint32_t nodeid = nd->GetNode ()->GetId ();
|
||||
uint32_t deviceid = nd->GetIfIndex ();
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << "/NodeList/" << nd->GetNode ()->GetId () << "/DeviceList/" << deviceid << "/$ns3::IslNetDevice/MacRx";
|
||||
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultReceiveSinkWithContext, stream));
|
||||
|
||||
oss.str ("");
|
||||
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::IslNetDevice/TxQueue/Enqueue";
|
||||
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultEnqueueSinkWithContext, stream));
|
||||
|
||||
oss.str ("");
|
||||
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::IslNetDevice/TxQueue/Dequeue";
|
||||
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDequeueSinkWithContext, stream));
|
||||
|
||||
oss.str ("");
|
||||
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::IslNetDevice/TxQueue/Drop";
|
||||
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream));
|
||||
|
||||
oss.str ("");
|
||||
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::IslNetDevice/PhyRxDrop";
|
||||
Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream));
|
||||
}
|
||||
|
||||
NetDeviceContainer
|
||||
IslHelper::Install (NodeContainer c)
|
||||
{
|
||||
std::vector<Ptr<Node> > nodes = std::vector<Ptr<Node> >(c.Begin(), c.End());
|
||||
return Install (nodes);
|
||||
}
|
||||
|
||||
NetDeviceContainer
|
||||
IslHelper::Install (std::vector<Ptr<Node> > &nodes)
|
||||
{
|
||||
Ptr<IslChannel> channel = m_channelFactory.Create<IslChannel> ();
|
||||
|
||||
NetDeviceContainer container;
|
||||
|
||||
for (Ptr<Node> node: nodes)
|
||||
{
|
||||
Ptr<IslNetDevice> dev = m_deviceFactory.Create<IslNetDevice> ();
|
||||
dev->SetAddress (Mac48Address::Allocate ());
|
||||
node->AddDevice (dev);
|
||||
Ptr<Queue<Packet> > queue = m_queueFactory.Create<Queue<Packet> > ();
|
||||
dev->SetQueue (queue);
|
||||
dev->Attach (channel);
|
||||
container.Add (dev);
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
NetDeviceContainer
|
||||
IslHelper::Install (std::vector<std::string> &names)
|
||||
{
|
||||
std::vector<Ptr<Node> > nodes;
|
||||
for (std::string name : names)
|
||||
{
|
||||
Ptr<Node> node = Names::Find<Node>(name);
|
||||
nodes.push_back (node);
|
||||
}
|
||||
|
||||
return Install (nodes);
|
||||
}
|
||||
|
||||
} // namespace ns3
|
169
helper/isl-helper.h
Normal file
169
helper/isl-helper.h
Normal file
|
@ -0,0 +1,169 @@
|
|||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2008 INRIA
|
||||
*
|
||||
* 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#ifndef ISL_HELPER_H
|
||||
#define ISL_HELPER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <ns3/object-factory.h>
|
||||
#include <ns3/net-device-container.h>
|
||||
#include <ns3/node-container.h>
|
||||
|
||||
#include <ns3/trace-helper.h>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class NetDevice;
|
||||
class Node;
|
||||
|
||||
/**
|
||||
* \brief Build a set of IslNetDevice objects
|
||||
*
|
||||
* Normally we eschew multiple inheritance, however, the classes
|
||||
* PcapUserHelperForDevice and AsciiTraceUserHelperForDevice are
|
||||
* "mixins".
|
||||
*/
|
||||
class IslHelper : public PcapHelperForDevice,
|
||||
public AsciiTraceHelperForDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create a IslHelper to make life easier when creating ISL networks.
|
||||
*/
|
||||
IslHelper ();
|
||||
virtual ~IslHelper () {}
|
||||
|
||||
/**
|
||||
* Each point to point net device must have a queue to pass packets through.
|
||||
* This method allows one to set the type of the queue that is automatically
|
||||
* created when the device is created and attached to a node.
|
||||
*
|
||||
* \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
|
||||
* IslNetDevice created through IslHelper::Install.
|
||||
*/
|
||||
void SetQueue (std::string type,
|
||||
std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
|
||||
std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
|
||||
std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
|
||||
std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ());
|
||||
|
||||
|
||||
/**
|
||||
* Set an attribute value to be propagated to each NetDevice created by the
|
||||
* helper.
|
||||
*
|
||||
* \param name the name of the attribute to set
|
||||
* \param value the value of the attribute to set
|
||||
*
|
||||
* Set these attributes on each ns3::IslNetDevice created
|
||||
* by IslHelper::Install
|
||||
*/
|
||||
void SetDeviceAttribute (std::string name, const AttributeValue &value);
|
||||
|
||||
/**
|
||||
* Set an attribute value to be propagated to each Channel created by the
|
||||
* helper.
|
||||
*
|
||||
* \param name the name of the attribute to set
|
||||
* \param value the value of the attribute to set
|
||||
*
|
||||
* Set these attribute on each ns3::IslChannel created
|
||||
* by IslHelper::Install
|
||||
*/
|
||||
void SetChannelAttribute (std::string name, const AttributeValue &value);
|
||||
|
||||
/**
|
||||
* \param c a set of nodes
|
||||
* \return a NetDeviceContainer for nodes
|
||||
*
|
||||
* This method creates a ns3::IslChannel with the
|
||||
* attributes configured by IslHelper::SetChannelAttribute,
|
||||
* then, for each node in the input container, we create a
|
||||
* ns3::IslNetDevice with the requested attributes,
|
||||
* a queue for this ns3::NetDevice, and associate the resulting
|
||||
* ns3::NetDevice with the ns3::Node and ns3::IslChannel.
|
||||
*/
|
||||
NetDeviceContainer Install (NodeContainer c);
|
||||
|
||||
/**
|
||||
* \param nodes Nodes
|
||||
* \return a NetDeviceContainer for nodes
|
||||
*
|
||||
* Saves you from having to construct a temporary NodeContainer.
|
||||
*/
|
||||
NetDeviceContainer Install (std::vector<Ptr<Node> > &nodes);
|
||||
|
||||
/**
|
||||
* \param nodes Names of the nodes
|
||||
* \return a NetDeviceContainer for nodes
|
||||
*
|
||||
* Saves you from having to construct a temporary NodeContainer.
|
||||
*/
|
||||
NetDeviceContainer Install (std::vector<std::string> &nodes);
|
||||
|
||||
private:
|
||||
/**
|
||||
* \brief Enable pcap output the indicated net device.
|
||||
*
|
||||
* NetDevice-specific implementation mechanism for hooking the trace and
|
||||
* writing to the trace file.
|
||||
*
|
||||
* \param prefix Filename prefix to use for pcap files.
|
||||
* \param nd Net device for which you want to enable tracing.
|
||||
* \param promiscuous If true capture all possible packets available at the device.
|
||||
* \param explicitFilename Treat the prefix as an explicit filename if true
|
||||
*/
|
||||
virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename);
|
||||
|
||||
/**
|
||||
* \brief Enable ascii trace output on the indicated net device.
|
||||
*
|
||||
* NetDevice-specific implementation mechanism for hooking the trace and
|
||||
* writing to the trace file.
|
||||
*
|
||||
* \param stream The output stream object to use when logging ascii traces.
|
||||
* \param prefix Filename prefix to use for ascii trace files.
|
||||
* \param nd Net device for which you want to enable tracing.
|
||||
* \param explicitFilename Treat the prefix as an explicit filename if true
|
||||
*/
|
||||
virtual void EnableAsciiInternal (
|
||||
Ptr<OutputStreamWrapper> stream,
|
||||
std::string prefix,
|
||||
Ptr<NetDevice> nd,
|
||||
bool explicitFilename);
|
||||
|
||||
ObjectFactory m_queueFactory; //!< Queue Factory
|
||||
ObjectFactory m_channelFactory; //!< Channel Factory
|
||||
ObjectFactory m_deviceFactory; //!< Device Factory
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* ISL_HELPER_H */
|
11
helper/leo-helper.cc
Normal file
11
helper/leo-helper.cc
Normal file
|
@ -0,0 +1,11 @@
|
|||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
|
||||
#include "leo-helper.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/* ... */
|
||||
|
||||
|
||||
}
|
||||
|
14
helper/leo-helper.h
Normal file
14
helper/leo-helper.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
#ifndef LEO_HELPER_H
|
||||
#define LEO_HELPER_H
|
||||
|
||||
#include "ns3/leo.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/* ... */
|
||||
|
||||
}
|
||||
|
||||
#endif /* LEO_HELPER_H */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue