Restructured installers

This commit is contained in:
Kirill Andreev
2009-06-17 18:50:57 +04:00
parent 49fe4a8b4f
commit 43fde668f1
7 changed files with 136 additions and 48 deletions

View File

@@ -58,14 +58,15 @@ class MeshTest
bool chan;
bool pcap;
uint64_t seed;
std::string stack;
/// List of network nodes
NodeContainer nodes;
/// List of all mesh point devices
NetDeviceContainer meshDevices;
//Addresses of interfaces:
Ipv4InterfaceContainer interfaces;
//InternetStackHelper stack;
//Ipv4AddressHelper address;
// MeshWifiHelper. Report is not static methods
MeshWifiHelper mesh;
private:
/// Create nodes and setup their mobility
void CreateNodes ();
@@ -87,7 +88,8 @@ MeshTest::MeshTest () :
nIfaces (1),
chan (true),
pcap (false),
seed (1)
seed (1),
stack ("ns3::Dot11sStack")
{
}
void
@@ -105,6 +107,7 @@ MeshTest::Configure (int argc, char *argv[])
cmd.AddValue ("channels", "Use different frequency channels for different interfaces. [0]", chan);
cmd.AddValue ("pcap", "Enable PCAP traces on interfaces. [0]", pcap);
cmd.AddValue ("seed", "Seed value", seed);
cmd.AddValue ("stack", "Type of protocol stack. ns3::Dot11sStack by default", stack);
cmd.Parse (argc, argv);
NS_LOG_DEBUG ("Grid:" << xSize << "*" << ySize);
@@ -120,15 +123,12 @@ MeshTest::CreateNodes ()
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
// Install mesh point devices & protocols
MeshWifiHelper mesh;
mesh.SetStackInstaller (stack);
mesh.SetSpreadInterfaceChannels (chan);
std::vector<uint32_t> roots;
//roots.push_back(xSize-1);
//roots.push_back(xSize*ySize-xSize);
MeshInterfaceHelper interface = MeshInterfaceHelper::Default ();
interface.SetType ("RandomStart", TimeValue (Seconds(randomStart)));
meshDevices = mesh.Install (wifiPhy, interface, nodes, roots, nIfaces);
meshDevices = mesh.Install (wifiPhy, interface, nodes, nIfaces);
// Setup mobility
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
@@ -196,7 +196,7 @@ MeshTest::Report ()
std::cerr << "Error: Can't open file " << os.str() << "\n";
return;
}
MeshWifiHelper::Report (*i, of);
mesh.Report (*i, of);
of.close ();
}
}

View File

@@ -23,9 +23,34 @@
#include "hwmp-protocol.h"
namespace ns3 {
namespace dot11s {
using namespace dot11s;
NS_OBJECT_ENSURE_REGISTERED (Dot11sStack);
TypeId
Dot11sStack::GetTypeId ()
{
static TypeId tid = TypeId ("ns3::Dot11sStack")
.SetParent<Object> ()
.AddConstructor<Dot11sStack> ()
;
return tid;
}
Dot11sStack::Dot11sStack ()
{}
Dot11sStack::~Dot11sStack ()
{}
void
Dot11sStack::DoDispose ()
{
}
void
Dot11sStack::SetRoot (Ptr<MeshPointDevice> mp)
{
Ptr <HwmpProtocol> hwmp = mp->GetObject<HwmpProtocol> ();
NS_ASSERT(hwmp != 0);
hwmp->SetRoot ();
}
bool
Dot11sStackInstaller::InstallDot11sStack (Ptr<MeshPointDevice> mp, bool root)
Dot11sStack::InstallStack (Ptr<MeshPointDevice> mp)
{
//Install Peer management protocol:
Ptr<PeerManagementProtocol> pmp = CreateObject<PeerManagementProtocol> ();
@@ -38,15 +63,13 @@ Dot11sStackInstaller::InstallDot11sStack (Ptr<MeshPointDevice> mp, bool root)
install_ok = hwmp->Install (mp);
if(!install_ok)
return false;
if(root)
hwmp->SetRoot ();
//Install interaction between HWMP and Peer management protocol:
pmp->SetPeerLinkStatusCallback(MakeCallback(&HwmpProtocol::PeerLinkStatus, hwmp));
hwmp->SetNeighboursCallback(MakeCallback(&PeerManagementProtocol::GetActiveLinks, pmp));
return true;
}
void
Dot11sStackInstaller::Report (const Ptr<MeshPointDevice> mp, std::ostream& os)
Dot11sStack::Report (const Ptr<MeshPointDevice> mp, std::ostream& os)
{
std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
for (std::vector<Ptr<NetDevice> >::const_iterator i = ifaces.begin(); i != ifaces.end(); ++i)
@@ -64,7 +87,7 @@ Dot11sStackInstaller::Report (const Ptr<MeshPointDevice> mp, std::ostream& os)
pmp->Report (os);
}
void
Dot11sStackInstaller::ResetStats (const Ptr<MeshPointDevice> mp)
Dot11sStack::ResetStats (const Ptr<MeshPointDevice> mp)
{
std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
for (std::vector<Ptr<NetDevice> >::const_iterator i = ifaces.begin(); i != ifaces.end(); ++i)
@@ -81,6 +104,4 @@ Dot11sStackInstaller::ResetStats (const Ptr<MeshPointDevice> mp)
NS_ASSERT(pmp != 0);
pmp->ResetStats ();
}
}
}
} //namespace ns3

View File

@@ -19,21 +19,24 @@
*/
#ifndef MESH_INSTALLER_H
#define MESH_INSTALLER_H
#include "ns3/mesh-point-device.h"
#ifndef DOT11S_STACK_INSTALLER_H
#define DOT11S_STACK_INSTALLER_H
#include "ns3/mesh-stack-installer.h"
namespace ns3 {
namespace dot11s {
class Dot11sStackInstaller
class Dot11sStack : public MeshStack
{
public:
///\brief Installs 802.11s stack. needed by helper only
static bool InstallDot11sStack (Ptr<MeshPointDevice> mp, bool root);
static void Report (const Ptr<MeshPointDevice> mp, std::ostream&);
static void ResetStats (const Ptr<MeshPointDevice> mp);
};
static TypeId GetTypeId ();
Dot11sStack ();
~Dot11sStack ();
void DoDispose ();
}
}
///\brief Installs 802.11s stack. needed by helper only
bool InstallStack (Ptr<MeshPointDevice> mp);
void SetRoot (Ptr<MeshPointDevice> mp);
void Report (const Ptr<MeshPointDevice> mp, std::ostream&);
void ResetStats (const Ptr<MeshPointDevice> mp);
};
} //namespace ns3
#endif

View File

@@ -0,0 +1,42 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008,2009 IITP RAS
*
* 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
*
* Authors: Kirill Andreev <andreev@iitp.ru>
*/
#ifndef MESH_STACK_INSTALLER_H
#define MESH_STACK_INSTALLER_H
#include "ns3/mesh-point-device.h"
namespace ns3 {
/**
* \ingroup mesh
*
* \brief Prototype for class, which helps to install mesh stack of
* protocols
*/
class MeshStack : public Object
{
public:
///\brief Installs mesh stack. needed by helper only
virtual bool InstallStack (Ptr<MeshPointDevice> mp) = 0;
virtual void Report (const Ptr<MeshPointDevice> mp, std::ostream&) = 0;
virtual void ResetStats (const Ptr<MeshPointDevice> mp) = 0;
};
}
#endif

View File

@@ -19,4 +19,5 @@ def build(bld):
'mesh-wifi-beacon.h',
'mesh-wifi-interface-mac.h',
'mesh-wifi-interface-mac-plugin.h',
'mesh-stack-installer.h',
]

View File

@@ -19,14 +19,15 @@
* Pavel Boyko <boyko@iitp.ru>
*/
#include "dot11s-helper.h"
#include "ns3/dot11s-installer.h"
#include "ns3/simulator.h"
#include "ns3/mesh-point-device.h"
#include "ns3/wifi-net-device.h"
#include "ns3/log.h"
NS_LOG_COMPONENT_DEFINE ("MeshWifiHelper");
namespace ns3 {
using namespace dot11s ;
MeshWifiHelper::MeshWifiHelper () :
m_spreadInterfaceChannels (false)
m_spreadInterfaceChannels (false),
m_stack (0)
{
}
void
@@ -34,10 +35,22 @@ MeshWifiHelper::SetSpreadInterfaceChannels (bool s)
{
m_spreadInterfaceChannels = s;
}
void
MeshWifiHelper::SetStackInstaller (std::string type)
{
NS_LOG_FUNCTION (this << type);
m_stackFactory = ObjectFactory ();
m_stackFactory.SetTypeId (type);
m_stack = m_stackFactory.Create<MeshStack> ();
if (m_stack == 0)
NS_FATAL_ERROR ("Stack has not been created: "<<type);
}
NetDeviceContainer
MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, std::vector<uint32_t> roots, uint32_t nInterfaces) const
MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, uint32_t nInterfaces) const
{
NetDeviceContainer devices;
NS_ASSERT (m_stack != 0);
uint16_t node_counter = 0;
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
@@ -54,13 +67,9 @@ MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelp
Ptr<WifiNetDevice> iface = interfaceHelper.CreateInterface (phyHelper,node, (m_spreadInterfaceChannels ? channel : 0));
mp->AddInterface (iface);
}
bool root = false;
for (unsigned int j = 0; j < roots.size (); j ++)
if(node_counter == roots[j])
root = true;
if(!Dot11sStackInstaller::InstallDot11sStack (mp, root))
if(!m_stack->InstallStack (mp))
{
NS_FATAL_ERROR ("802.11s stack is not installed!");
NS_FATAL_ERROR ("Stack is not installed!");
}
devices.Add (mp);
node_counter ++;
@@ -69,26 +78,28 @@ MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelp
}
NetDeviceContainer
MeshWifiHelper::Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, std::vector<uint32_t> roots, uint32_t nInterfaces) const
MeshWifiHelper::Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, uint32_t nInterfaces) const
{
return Install (phy, interfaceHelper, NodeContainer (node), roots, nInterfaces);
return Install (phy, interfaceHelper, NodeContainer (node), nInterfaces);
}
void
MeshWifiHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
{
NS_ASSERT (m_stack != 0);
Ptr <MeshPointDevice> mp = device->GetObject<MeshPointDevice> ();
NS_ASSERT (mp != 0);
std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
os << "<MeshPointDevice ReportTime=\"" << Simulator::Now().GetSeconds() << "s\" MpAddress=\"" << mp->GetAddress () << "\">\n";
Dot11sStackInstaller::Report (mp, os);
m_stack->Report (mp, os);
os << "</MeshPointDevice>\n";
}
void
MeshWifiHelper::ResetStats (const ns3::Ptr<ns3::NetDevice>& device)
{
NS_ASSERT (m_stack != 0);
Ptr <MeshPointDevice> mp = device->GetObject<MeshPointDevice> ();
NS_ASSERT (mp != 0);
Dot11sStackInstaller::ResetStats (mp);
m_stack->ResetStats (mp);
}
} //namespace ns3

View File

@@ -24,6 +24,7 @@
#define _MESHWIFIHELPER_H
#include "ns3/wifi-helper.h"
#include "ns3/mesh-stack-installer.h"
#include "ns3/nstime.h"
#include "ns3/mesh-interface-helper.h"
@@ -58,7 +59,7 @@ public:
*
* \return list of created mesh point devices, see MeshPointDevice
*/
NetDeviceContainer Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, std::vector<uint32_t> roots = std::vector<uint32_t> (), uint32_t nInterfaces = 1) const;
NetDeviceContainer Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, uint32_t nInterfaces = 1) const;
/**
* \brief Install 802.11s mesh device & protocols on given node
*
@@ -69,11 +70,20 @@ public:
*
* \return list of created mesh point devices, see MeshPointDevice
*/
NetDeviceContainer Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, std::vector<uint32_t> roots = std::vector<uint32_t> (), uint32_t nInterfaces = 1) const;
static void Report (const ns3::Ptr<ns3::NetDevice>&, std::ostream&);
static void ResetStats (const ns3::Ptr<ns3::NetDevice>&);
NetDeviceContainer Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, uint32_t nInterfaces = 1) const;
/**
* \param type the type of ns3::MeshStack.
*
* All the attributes specified in this method should exist
* in the requested station manager.
*/
void SetStackInstaller (std::string type);
void Report (const ns3::Ptr<ns3::NetDevice>&, std::ostream&);
void ResetStats (const ns3::Ptr<ns3::NetDevice>&);
private:
bool m_spreadInterfaceChannels;
Ptr<MeshStack> m_stack;
ObjectFactory m_stackFactory;
};
} //namespace ns3