From fce22caf9e6e2a34be08fffc0e89f0bbac626c89 Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Wed, 10 Jun 2009 12:51:49 +0400 Subject: [PATCH] Added dot11s installator, fixed bug with adding tag in proactive mode of HWMP --- examples/mesh.cc | 2 +- src/devices/mesh/dot11s/dot11s-installator.cc | 90 +++++++++++++++++++ src/devices/mesh/dot11s/dot11s-installator.h | 39 ++++++++ src/devices/mesh/dot11s/hwmp-mac-plugin.cc | 5 -- src/devices/mesh/dot11s/hwmp-protocol.cc | 7 +- src/devices/mesh/dot11s/hwmp-protocol.h | 2 +- src/devices/mesh/mesh-point-device.cc | 2 +- src/helper/dot11s-helper.cc | 8 +- src/helper/mesh-interface-helper.cc | 7 +- src/helper/mesh-interface-helper.h | 4 +- 10 files changed, 150 insertions(+), 16 deletions(-) create mode 100644 src/devices/mesh/dot11s/dot11s-installator.cc create mode 100644 src/devices/mesh/dot11s/dot11s-installator.h diff --git a/examples/mesh.cc b/examples/mesh.cc index 739a46e78..72230c0fc 100644 --- a/examples/mesh.cc +++ b/examples/mesh.cc @@ -28,7 +28,7 @@ #include "ns3/mesh-module.h" #include "ns3/mobility-module.h" #include "ns3/dot11s-helper.h" -#include "ns3/dot11s-interface-helper.h" +#include "ns3/mesh-interface-helper.h" #include #include diff --git a/src/devices/mesh/dot11s/dot11s-installator.cc b/src/devices/mesh/dot11s/dot11s-installator.cc new file mode 100644 index 000000000..03f79d670 --- /dev/null +++ b/src/devices/mesh/dot11s/dot11s-installator.cc @@ -0,0 +1,90 @@ +/* -*- 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 + */ +#include "ns3/mesh-interface-helper.h" +#include "dot11s-installator.h" +#include "peer-management-protocol.h" +#include "hwmp-protocol.h" + +namespace ns3 { +namespace dot11s { +bool +Dot11sStackInstallator::InstallDot11sStack (Ptr mp, bool root) +{ + //Install Peer management protocol: + Ptr pmp = CreateObject (); + pmp->SetMeshId("mesh"); + bool install_ok = pmp->Install (mp); + if(!install_ok) + return false; + //Install HWMP: + Ptr hwmp = CreateObject (); + 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 +Dot11sStackInstallator::Report (const ns3::Ptr& device, std::ostream& os) +{ + Ptr mp = device->GetObject (); + std::vector > ifaces = mp->GetInterfaces (); + NS_ASSERT (mp != 0); + for (std::vector >::const_iterator i = ifaces.begin(); i != ifaces.end(); ++i) + { + Ptr device = (*i)->GetObject (); + NS_ASSERT (device != 0); + MeshInterfaceHelper::Report(device, os); + } + Ptr hwmp = mp->GetObject (); + NS_ASSERT(hwmp != 0); + hwmp->Report (os); + + Ptr pmp = mp->GetObject (); + NS_ASSERT(pmp != 0); + pmp->Report (os); +} +void +Dot11sStackInstallator::ResetStats (const ns3::Ptr& device) +{ + Ptr mp = device->GetObject (); + NS_ASSERT (mp != 0); + std::vector > ifaces = mp->GetInterfaces (); + for (std::vector >::const_iterator i = ifaces.begin(); i != ifaces.end(); ++i) + { + Ptr device = (*i)->GetObject (); + NS_ASSERT (device != 0); + MeshInterfaceHelper::ResetStats (device); + } + Ptr hwmp = mp->GetObject (); + NS_ASSERT(hwmp != 0); + hwmp->ResetStats (); + + Ptr pmp = mp->GetObject (); + NS_ASSERT(pmp != 0); + pmp->ResetStats (); +} + +} +} diff --git a/src/devices/mesh/dot11s/dot11s-installator.h b/src/devices/mesh/dot11s/dot11s-installator.h new file mode 100644 index 000000000..83b0a9392 --- /dev/null +++ b/src/devices/mesh/dot11s/dot11s-installator.h @@ -0,0 +1,39 @@ +/* -*- 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_INSTALLATOR_H +#define MESH_INSTALLATOR_H +#include "ns3/mesh-point-device.h" +namespace ns3 { +namespace dot11s { +class Dot11sStackInstallator +{ + public: + ///\brief Installs 802.11s stack. needed by helper only + static bool InstallDot11sStack (Ptr mp, bool root); + static void Report (const ns3::Ptr&, std::ostream&); + static void ResetStats (const ns3::Ptr&); +}; + +} +} +#endif + diff --git a/src/devices/mesh/dot11s/hwmp-mac-plugin.cc b/src/devices/mesh/dot11s/hwmp-mac-plugin.cc index bbc723a0a..e9242c13e 100644 --- a/src/devices/mesh/dot11s/hwmp-mac-plugin.cc +++ b/src/devices/mesh/dot11s/hwmp-mac-plugin.cc @@ -75,11 +75,6 @@ HwmpMacPlugin::Receive (Ptr packet, const WifiMacHeader & header) NS_ASSERT(false); }; tag.SetSeqno (meshHdr.GetMeshSeqno ()); - if(meshHdr.GetMeshTtl () == 0) - { - NS_ASSERT(false); - return false; - } tag.SetTtl (meshHdr.GetMeshTtl ()); if(m_protocol->GetAddress() != destination) packet->AddPacketTag(tag); diff --git a/src/devices/mesh/dot11s/hwmp-protocol.cc b/src/devices/mesh/dot11s/hwmp-protocol.cc index db91c61bb..d6e4f8090 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol.cc +++ b/src/devices/mesh/dot11s/hwmp-protocol.cc @@ -268,7 +268,7 @@ HwmpProtocol::ForwardUnicast(uint32_t sourceIface, const Mac48Address source, c HwmpTag tag; tag.SetAddress (result.retransmitter); tag.SetTtl (ttl); - //seqno and metric is not used; + //seqno and metric is not used; packet->AddPacketTag(tag); if(result.retransmitter != Mac48Address::GetBroadcast ()) { @@ -794,7 +794,10 @@ HwmpProtocol::ProactivePathResolved () return; //set RA tag for retransmitter: HwmpTag tag; - NS_ASSERT (packet.pkt->PeekPacketTag(tag)); + if(!packet.pkt->RemovePacketTag (tag)) + { + NS_ASSERT (false); + } tag.SetAddress (result.retransmitter); packet.pkt->AddPacketTag (tag); m_stats.txUnicast ++; diff --git a/src/devices/mesh/dot11s/hwmp-protocol.h b/src/devices/mesh/dot11s/hwmp-protocol.h index 662900382..2195be60f 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol.h +++ b/src/devices/mesh/dot11s/hwmp-protocol.h @@ -24,8 +24,8 @@ #include "ns3/mesh-l2-routing-protocol.h" #include "ns3/nstime.h" -#include "ns3/ie-dot11s-perr.h" #include "ns3/event-id.h" +#include "ie-dot11s-perr.h" #include #include diff --git a/src/devices/mesh/mesh-point-device.cc b/src/devices/mesh/mesh-point-device.cc index b17a06541..2526f92d7 100644 --- a/src/devices/mesh/mesh-point-device.cc +++ b/src/devices/mesh/mesh-point-device.cc @@ -87,7 +87,7 @@ MeshPointDevice::ReceiveFromDevice (Ptr incomingPort, PtrCopy (), protocol, src48, dst48); diff --git a/src/helper/dot11s-helper.cc b/src/helper/dot11s-helper.cc index 0f31bf874..222cc5422 100644 --- a/src/helper/dot11s-helper.cc +++ b/src/helper/dot11s-helper.cc @@ -38,6 +38,7 @@ NetDeviceContainer MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, std::vector roots, uint32_t nInterfaces) const { NetDeviceContainer devices; + uint16_t node_counter = 0; for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { Ptr node = *i; @@ -53,11 +54,16 @@ MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelp Ptr iface = interfaceHelper.CreateInterface (phyHelper,node, (m_spreadInterfaceChannels ? channel : 0)); mp->AddInterface (iface); } - if(!Dot11sStackInstallator::InstallDot11sStack (mp, false)) + bool root = false; + for (unsigned int j = 0; j < roots.size (); j ++) + if(node_counter == roots[j]) + root = true; + if(!Dot11sStackInstallator::InstallDot11sStack (mp, root)) { NS_ASSERT(false); } devices.Add (mp); + node_counter ++; } return devices; } diff --git a/src/helper/mesh-interface-helper.cc b/src/helper/mesh-interface-helper.cc index 8cc025fb0..a9b90719d 100644 --- a/src/helper/mesh-interface-helper.cc +++ b/src/helper/mesh-interface-helper.cc @@ -121,7 +121,8 @@ MeshInterfaceHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr { Ptr device = CreateObject (); - Ptr mac = Create (); + Ptr mac = DynamicCast (Create ()); + NS_ASSERT (mac != 0); mac->SetSsid (Ssid ()); Ptr manager = m_stationManager.Create (); Ptr phy = phyHelper.Create (node, device); @@ -133,10 +134,10 @@ MeshInterfaceHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr mac->SwitchFrequencyChannel (channelId); return device; } -Ptr +Ptr MeshInterfaceHelper::Create (void) const { - Ptr mac = m_mac.Create (); + Ptr mac = m_mac.Create (); Ptr be = m_Be.Create (); Ptr vo = m_Vo.Create (); mac->SetAttribute ("BE", PointerValue (be)); diff --git a/src/helper/mesh-interface-helper.h b/src/helper/mesh-interface-helper.h index b134c29ab..a67b8664e 100644 --- a/src/helper/mesh-interface-helper.h +++ b/src/helper/mesh-interface-helper.h @@ -25,7 +25,7 @@ #include "ns3/mesh-wifi-interface-mac.h" namespace ns3 { -class MeshInterfaceHelper +class MeshInterfaceHelper : public WifiMacHelper { public: MeshInterfaceHelper (); @@ -101,7 +101,7 @@ private: * * This method implements the pure virtual method defined in \ref ns3::WifiMacHelper. */ - Ptr Create (void) const; + Ptr Create (void) const; ObjectFactory m_mac; ObjectFactory m_Be;