diff --git a/examples/mesh.cc b/examples/mesh.cc index d11ccf3af..91347e844 100644 --- a/examples/mesh.cc +++ b/examples/mesh.cc @@ -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 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 (); } } diff --git a/src/devices/mesh/dot11s/dot11s-installer.cc b/src/devices/mesh/dot11s/dot11s-installer.cc index 2cdee18bf..26ebccb94 100644 --- a/src/devices/mesh/dot11s/dot11s-installer.cc +++ b/src/devices/mesh/dot11s/dot11s-installer.cc @@ -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 () + .AddConstructor () + ; + return tid; +} +Dot11sStack::Dot11sStack () +{} +Dot11sStack::~Dot11sStack () +{} +void +Dot11sStack::DoDispose () +{ +} +void +Dot11sStack::SetRoot (Ptr mp) +{ + Ptr hwmp = mp->GetObject (); + NS_ASSERT(hwmp != 0); + hwmp->SetRoot (); +} bool -Dot11sStackInstaller::InstallDot11sStack (Ptr mp, bool root) +Dot11sStack::InstallStack (Ptr mp) { //Install Peer management protocol: Ptr pmp = CreateObject (); @@ -38,15 +63,13 @@ Dot11sStackInstaller::InstallDot11sStack (Ptr 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 mp, std::ostream& os) +Dot11sStack::Report (const Ptr mp, std::ostream& os) { std::vector > ifaces = mp->GetInterfaces (); for (std::vector >::const_iterator i = ifaces.begin(); i != ifaces.end(); ++i) @@ -64,7 +87,7 @@ Dot11sStackInstaller::Report (const Ptr mp, std::ostream& os) pmp->Report (os); } void -Dot11sStackInstaller::ResetStats (const Ptr mp) +Dot11sStack::ResetStats (const Ptr mp) { std::vector > ifaces = mp->GetInterfaces (); for (std::vector >::const_iterator i = ifaces.begin(); i != ifaces.end(); ++i) @@ -81,6 +104,4 @@ Dot11sStackInstaller::ResetStats (const Ptr mp) NS_ASSERT(pmp != 0); pmp->ResetStats (); } - -} -} +} //namespace ns3 diff --git a/src/devices/mesh/dot11s/dot11s-installer.h b/src/devices/mesh/dot11s/dot11s-installer.h index 62dff1748..521b0c825 100644 --- a/src/devices/mesh/dot11s/dot11s-installer.h +++ b/src/devices/mesh/dot11s/dot11s-installer.h @@ -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 mp, bool root); - static void Report (const Ptr mp, std::ostream&); - static void ResetStats (const Ptr mp); -}; + static TypeId GetTypeId (); + Dot11sStack (); + ~Dot11sStack (); + void DoDispose (); -} -} + ///\brief Installs 802.11s stack. needed by helper only + bool InstallStack (Ptr mp); + void SetRoot (Ptr mp); + void Report (const Ptr mp, std::ostream&); + void ResetStats (const Ptr mp); +}; +} //namespace ns3 #endif diff --git a/src/devices/mesh/mesh-stack-installer.h b/src/devices/mesh/mesh-stack-installer.h new file mode 100644 index 000000000..7a571d27f --- /dev/null +++ b/src/devices/mesh/mesh-stack-installer.h @@ -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 + */ + + +#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 mp) = 0; + virtual void Report (const Ptr mp, std::ostream&) = 0; + virtual void ResetStats (const Ptr mp) = 0; +}; +} +#endif + diff --git a/src/devices/mesh/wscript b/src/devices/mesh/wscript index 98496f732..cb2ba37e8 100644 --- a/src/devices/mesh/wscript +++ b/src/devices/mesh/wscript @@ -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', ] diff --git a/src/helper/dot11s-helper.cc b/src/helper/dot11s-helper.cc index 239d6bd5b..5afe30f03 100644 --- a/src/helper/dot11s-helper.cc +++ b/src/helper/dot11s-helper.cc @@ -19,14 +19,15 @@ * Pavel Boyko */ #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 (); + if (m_stack == 0) + NS_FATAL_ERROR ("Stack has not been created: "< 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 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, std::vector roots, uint32_t nInterfaces) const +MeshWifiHelper::Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr 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& device, std::ostream& os) { + NS_ASSERT (m_stack != 0); Ptr mp = device->GetObject (); NS_ASSERT (mp != 0); std::vector > ifaces = mp->GetInterfaces (); os << "GetAddress () << "\">\n"; - Dot11sStackInstaller::Report (mp, os); + m_stack->Report (mp, os); os << "\n"; } void MeshWifiHelper::ResetStats (const ns3::Ptr& device) { + NS_ASSERT (m_stack != 0); Ptr mp = device->GetObject (); NS_ASSERT (mp != 0); - Dot11sStackInstaller::ResetStats (mp); + m_stack->ResetStats (mp); } } //namespace ns3 diff --git a/src/helper/dot11s-helper.h b/src/helper/dot11s-helper.h index cde95aa8f..3fafc3bcc 100644 --- a/src/helper/dot11s-helper.h +++ b/src/helper/dot11s-helper.h @@ -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 roots = std::vector (), 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, std::vector roots = std::vector (), uint32_t nInterfaces = 1) const; - static void Report (const ns3::Ptr&, std::ostream&); - static void ResetStats (const ns3::Ptr&); + NetDeviceContainer Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr 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&, std::ostream&); + void ResetStats (const ns3::Ptr&); private: bool m_spreadInterfaceChannels; + Ptr m_stack; + ObjectFactory m_stackFactory; }; } //namespace ns3