start of work towards port of wifi code
This commit is contained in:
@@ -41,3 +41,7 @@ def build(bld):
|
||||
['core', 'simulator', 'mobility'])
|
||||
obj.source = 'main-random-topology.cc'
|
||||
|
||||
obj = bld.create_ns3_program('main-adhoc-wifi',
|
||||
['core', 'simulator', 'mobility', 'wifi'])
|
||||
obj.source = 'main-adhoc-wifi.cc'
|
||||
|
||||
|
||||
45
src/devices/wifi/propagation-delay-model.cc
Normal file
45
src/devices/wifi/propagation-delay-model.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "propagation-delay-model.h"
|
||||
#include "ns3/random-variable.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
PropagationDelayModel::~PropagationDelayModel ()
|
||||
{}
|
||||
|
||||
RandomPropagationDelayModel::RandomPropagationDelayModel (const RandomVariable &variable)
|
||||
: m_variable (variable.Copy ())
|
||||
{}
|
||||
RandomPropagationDelayModel::~RandomPropagationDelayModel ()
|
||||
{
|
||||
delete m_variable;
|
||||
}
|
||||
Time
|
||||
RandomPropagationDelayModel::GetDelay (double distance) const
|
||||
{
|
||||
return Seconds (m_variable->GetValue ());
|
||||
}
|
||||
|
||||
ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel ()
|
||||
: m_speed (300000000.0)
|
||||
{}
|
||||
ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel (double speed)
|
||||
: m_speed (speed)
|
||||
{}
|
||||
Time
|
||||
ConstantSpeedPropagationDelayModel::GetDelay (double distance) const
|
||||
{
|
||||
double seconds = distance / m_speed;
|
||||
return Seconds (seconds);
|
||||
}
|
||||
void
|
||||
ConstantSpeedPropagationDelayModel::SetSpeed (double speed)
|
||||
{
|
||||
m_speed = speed;
|
||||
}
|
||||
double
|
||||
ConstantSpeedPropagationDelayModel::GetSpeed (void) const
|
||||
{
|
||||
return m_speed;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
43
src/devices/wifi/propagation-delay-model.h
Normal file
43
src/devices/wifi/propagation-delay-model.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef PROPAGATION_DELAY_MODEL_H
|
||||
#define PROPAGATION_DELAY_MODEL_H
|
||||
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/nstime.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class RandomVariable;
|
||||
|
||||
class PropagationDelayModel : public Object
|
||||
{
|
||||
public:
|
||||
virtual ~PropagationDelayModel ();
|
||||
virtual Time GetDelay (double distance) const = 0;
|
||||
};
|
||||
|
||||
class RandomPropagationDelayModel : public PropagationDelayModel
|
||||
{
|
||||
public:
|
||||
RandomPropagationDelayModel (const RandomVariable &variable);
|
||||
virtual ~RandomPropagationDelayModel ();
|
||||
virtual Time GetDelay (double distance) const;
|
||||
private:
|
||||
RandomVariable *m_variable;
|
||||
};
|
||||
|
||||
class ConstantSpeedPropagationDelayModel : public PropagationDelayModel
|
||||
{
|
||||
public:
|
||||
ConstantSpeedPropagationDelayModel ();
|
||||
ConstantSpeedPropagationDelayModel (double speed);
|
||||
virtual Time GetDelay (double distance) const;
|
||||
void SetSpeed (double speed);
|
||||
double GetSpeed (void) const;
|
||||
private:
|
||||
double m_speed;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* PROPAGATION_DELAY_MODEL_H */
|
||||
121
src/devices/wifi/propagation-loss-model.cc
Normal file
121
src/devices/wifi/propagation-loss-model.cc
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "propagation-loss-model.h"
|
||||
#include <math.h>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
const double FriisPropagationLossModel::PI = 3.1415;
|
||||
|
||||
PropagationLossModel::~PropagationLossModel ()
|
||||
{}
|
||||
|
||||
FriisPropagationLossModel::FriisPropagationLossModel ()
|
||||
: m_lambda (),
|
||||
m_systemLoss (1.0)
|
||||
{}
|
||||
void
|
||||
FriisPropagationLossModel::SetSystemLoss (double systemLoss)
|
||||
{
|
||||
m_systemLoss = systemLoss;
|
||||
}
|
||||
double
|
||||
FriisPropagationLossModel::GetSystemLoss (void) const
|
||||
{
|
||||
return m_systemLoss;
|
||||
}
|
||||
void
|
||||
FriisPropagationLossModel::SetLambda (double frequency, double speed)
|
||||
{
|
||||
m_lambda = speed / frequency;
|
||||
}
|
||||
void
|
||||
FriisPropagationLossModel::SetLambda (double lambda)
|
||||
{
|
||||
m_lambda = lambda;
|
||||
}
|
||||
double
|
||||
FriisPropagationLossModel::GetLambda (void) const
|
||||
{
|
||||
return m_lambda;
|
||||
}
|
||||
|
||||
double
|
||||
FriisPropagationLossModel::DbmToW (double dbm) const
|
||||
{
|
||||
double mw = pow(10.0,dbm/10.0);
|
||||
return mw / 1000.0;
|
||||
}
|
||||
|
||||
double
|
||||
FriisPropagationLossModel::DbmFromW (double w) const
|
||||
{
|
||||
double dbm = log10 (w * 1000.0) * 10.0;
|
||||
return dbm;
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
FriisPropagationLossModel::GetRxPower (double txPowerDbm,
|
||||
double distance) const
|
||||
{
|
||||
/*
|
||||
* Friis free space equation:
|
||||
* where Pt, Gr, Gr and P are in Watt units
|
||||
* L is in meter units.
|
||||
*
|
||||
* Pt * Gt * Gr * (lambda^2)
|
||||
* P = --------------------------
|
||||
* (4 * pi * d)^2 * L
|
||||
*
|
||||
* Gt: tx gain (W)
|
||||
* Gr: rx gain (W)
|
||||
* Pt: tx power (W)
|
||||
* d: distance (m)
|
||||
* L: system loss
|
||||
* lambda: wavelength (m)
|
||||
*
|
||||
* Here, we ignore tx and rx gain.
|
||||
*/
|
||||
double numerator = DbmToW (txPowerDbm) * m_lambda * m_lambda;
|
||||
double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
|
||||
double pr = numerator / denominator;
|
||||
return DbmFromW (pr);
|
||||
}
|
||||
|
||||
|
||||
PathLossPropagationLossModel::PathLossPropagationLossModel ()
|
||||
{}
|
||||
|
||||
void
|
||||
PathLossPropagationLossModel::SetPathLossExponent (double n)
|
||||
{
|
||||
m_exponent = n;
|
||||
}
|
||||
double
|
||||
PathLossPropagationLossModel::GetPathLossExponent (void) const
|
||||
{
|
||||
return m_exponent;
|
||||
}
|
||||
|
||||
double
|
||||
PathLossPropagationLossModel::DbToW (double db) const
|
||||
{
|
||||
return pow(10.0,db/10.0);
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
PathLossPropagationLossModel::GetRxPower (double txPowerDbm,
|
||||
double distance) const
|
||||
{
|
||||
if (distance <= 1.0)
|
||||
{
|
||||
return txPowerDbm;
|
||||
}
|
||||
double prd0 = m_reference->GetRxPower (txPowerDbm, 1.0);
|
||||
double pr = 10*log10(prd0) - m_exponent * 10.0 * log10(distance);
|
||||
return DbToW (pr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
59
src/devices/wifi/propagation-loss-model.h
Normal file
59
src/devices/wifi/propagation-loss-model.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef PROPAGATION_LOSS_MODEL_H
|
||||
#define PROPAGATION_LOSS_MODEL_H
|
||||
|
||||
#include "ns3/object.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class PropagationLossModel : public Object
|
||||
{
|
||||
public:
|
||||
virtual ~PropagationLossModel ();
|
||||
virtual double GetRxPower (double txPowerDbm,
|
||||
double distance) const = 0;
|
||||
};
|
||||
|
||||
class FriisPropagationLossModel : public PropagationLossModel
|
||||
{
|
||||
public:
|
||||
FriisPropagationLossModel ();
|
||||
void SetLambda (double frequency, double speed);
|
||||
void SetLambda (double lambda);
|
||||
void SetSystemLoss (double systemLoss);
|
||||
double GetLambda (void) const;
|
||||
double GetSystemLoss (void) const;
|
||||
|
||||
virtual double GetRxPower (double txPowerDbm,
|
||||
double distance) const;
|
||||
private:
|
||||
double DbmToW (double dbm) const;
|
||||
double DbmFromW (double w) const;
|
||||
|
||||
static const double PI;
|
||||
double m_lambda;
|
||||
double m_systemLoss;
|
||||
};
|
||||
|
||||
class PathLossPropagationLossModel : public PropagationLossModel
|
||||
{
|
||||
public:
|
||||
PathLossPropagationLossModel ();
|
||||
|
||||
void SetPathLossExponent (double n);
|
||||
double GetPathLossExponent (void) const;
|
||||
|
||||
void SetReferenceModel (Ptr<PropagationLossModel> model);
|
||||
|
||||
virtual double GetRxPower (double txPowerDbm,
|
||||
double distance) const;
|
||||
private:
|
||||
double DbToW (double db) const;
|
||||
|
||||
double m_lambda;
|
||||
double m_exponent;
|
||||
Ptr<PropagationLossModel> m_reference;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* PROPAGATION_LOSS_MODEL_H */
|
||||
@@ -21,6 +21,7 @@ all_modules = (
|
||||
'applications',
|
||||
'routing/global-routing',
|
||||
'mobility',
|
||||
'devices/wifi',
|
||||
)
|
||||
|
||||
def set_options(opt):
|
||||
|
||||
Reference in New Issue
Block a user