bug 1774: fix LrWpanHelper to enable MultiModelSpectrumChannel and add a default PropagationDelayModel

This commit is contained in:
Tommaso Pecorella
2015-02-01 21:01:25 -08:00
parent 47789200d4
commit a25be3e3d5
3 changed files with 94 additions and 10 deletions

View File

@@ -37,6 +37,7 @@
#include <ns3/node.h>
#include <ns3/net-device.h>
#include <ns3/single-model-spectrum-channel.h>
#include <ns3/multi-model-spectrum-channel.h>
#include <ns3/mac16-address.h>
#include <ns3/constant-position-mobility-model.h>
#include <ns3/uinteger.h>
@@ -95,7 +96,7 @@ int main (int argc, char *argv[])
Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice> ();
dev0->SetAddress (Mac16Address ("00:01"));
dev1->SetAddress (Mac16Address ("00:02"));
Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel> ();
Ptr<MultiModelSpectrumChannel> channel = CreateObject<MultiModelSpectrumChannel> ();
Ptr<LogDistancePropagationLossModel> model = CreateObject<LogDistancePropagationLossModel> ();
channel->AddPropagationLossModel (model);
dev0->SetChannel (channel);

View File

@@ -25,8 +25,11 @@
#include <ns3/lr-wpan-net-device.h>
#include <ns3/mobility-model.h>
#include <ns3/single-model-spectrum-channel.h>
#include <ns3/multi-model-spectrum-channel.h>
#include <ns3/propagation-loss-model.h>
#include <ns3/propagation-delay-model.h>
#include <ns3/log.h>
#include "ns3/names.h"
namespace ns3 {
@@ -63,8 +66,29 @@ AsciiLrWpanMacTransmitSinkWithoutContext (
LrWpanHelper::LrWpanHelper (void)
{
m_channel = CreateObject<SingleModelSpectrumChannel> ();
Ptr<LogDistancePropagationLossModel> model = CreateObject<LogDistancePropagationLossModel> ();
m_channel->AddPropagationLossModel (model);
Ptr<LogDistancePropagationLossModel> lossModel = CreateObject<LogDistancePropagationLossModel> ();
m_channel->AddPropagationLossModel (lossModel);
Ptr<ConstantSpeedPropagationDelayModel> delayModel = CreateObject<ConstantSpeedPropagationDelayModel> ();
m_channel->SetPropagationDelayModel (delayModel);
}
LrWpanHelper::LrWpanHelper (bool useMultiModelSpectrumChannel)
{
if (useMultiModelSpectrumChannel)
{
m_channel = CreateObject<MultiModelSpectrumChannel> ();
}
else
{
m_channel = CreateObject<SingleModelSpectrumChannel> ();
}
Ptr<LogDistancePropagationLossModel> lossModel = CreateObject<LogDistancePropagationLossModel> ();
m_channel->AddPropagationLossModel (lossModel);
Ptr<ConstantSpeedPropagationDelayModel> delayModel = CreateObject<ConstantSpeedPropagationDelayModel> ();
m_channel->SetPropagationDelayModel (delayModel);
}
LrWpanHelper::~LrWpanHelper (void)
@@ -167,6 +191,27 @@ LrWpanHelper::Install (NodeContainer c)
return devices;
}
Ptr<SpectrumChannel>
LrWpanHelper::GetChannel (void)
{
return m_channel;
}
void
LrWpanHelper::SetChannel (Ptr<SpectrumChannel> channel)
{
m_channel = channel;
}
void
LrWpanHelper::SetChannel (std::string channelName)
{
Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName);
m_channel = channel;
}
int64_t
LrWpanHelper::AssignStreams (NetDeviceContainer c, int64_t stream)
{

View File

@@ -29,7 +29,7 @@
namespace ns3 {
class SingleModelSpectrumChannel;
class SpectrumChannel;
class MobilityModel;
/**
@@ -40,6 +40,10 @@ class MobilityModel;
* This class can help to create IEEE 802.15.4 NetDevice objects
* and to configure their attributes during creation. It also contains
* additional helper functions used by client code.
*
* Only one channel is created, and all devices attached to it. If
* multiple channels are needed, multiple helper objects must be used,
* or else the channel object must be replaced.
*/
class LrWpanHelper : public PcapHelperForDevice,
@@ -47,16 +51,50 @@ class LrWpanHelper : public PcapHelperForDevice,
{
public:
/**
* \brief Create a LrWpan helper in an empty state.
* \brief Create a LrWpan helper in an empty state. By default, a
* SingleModelSpectrumChannel is created, with a
* LogDistancePropagationLossModel and a ConstantSpeedPropagationDelayModel.
*
* To change the channel type, loss model, or delay model, the Get/Set
* Channel methods may be used.
*/
LrWpanHelper (void);
/**
* \brief Create a LrWpan helper in an empty state with either a
* SingleModelSpectrumChannel or a MultiModelSpectrumChannel.
* \param useMultiModelSpectrumChannel use a MultiModelSpectrumChannel if true, a SingleModelSpectrumChannel otherwise
*
* A LogDistancePropagationLossModel and a
* ConstantSpeedPropagationDelayModel are added to the channel.
*/
LrWpanHelper (bool useMultiModelSpectrumChannel);
virtual ~LrWpanHelper (void);
/**
* \brief Add mobility model to a physical device
* \param phy the physical device
* \param m the mobility model
*/
* \brief Get the channel associated to this helper
* \returns the channel
*/
Ptr<SpectrumChannel> GetChannel (void);
/**
* \brief Set the channel associated to this helper
* \param channel the channel
*/
void SetChannel (Ptr<SpectrumChannel> channel);
/**
* \brief Set the channel associated to this helper
* \param channelName the channel name
*/
void SetChannel (std::string channelName);
/**
* \brief Add mobility model to a physical device
* \param phy the physical device
* \param m the mobility model
*/
void AddMobility (Ptr<LrWpanPhy> phy, Ptr<MobilityModel> m);
/**
@@ -147,7 +185,7 @@ private:
bool explicitFilename);
private:
Ptr<SingleModelSpectrumChannel> m_channel; //!< channel to be used for the devices
Ptr<SpectrumChannel> m_channel; //!< channel to be used for the devices
};