20 #include <ns3/adhoc-aloha-noack-ideal-phy-helper.h>
21 #include <ns3/config.h>
22 #include <ns3/data-rate.h>
23 #include <ns3/friis-spectrum-propagation-loss.h>
24 #include <ns3/ism-spectrum-value-helper.h>
27 #include <ns3/mobility-helper.h>
28 #include <ns3/object.h>
29 #include <ns3/packet-socket-address.h>
30 #include <ns3/packet-socket-client.h>
31 #include <ns3/packet-socket-helper.h>
32 #include <ns3/packet.h>
33 #include <ns3/propagation-delay-model.h>
35 #include <ns3/simulator.h>
36 #include <ns3/single-model-spectrum-channel.h>
37 #include <ns3/spectrum-analyzer.h>
38 #include <ns3/spectrum-error-model.h>
39 #include <ns3/spectrum-helper.h>
40 #include <ns3/spectrum-interference.h>
41 #include <ns3/spectrum-model-300kHz-300GHz-log.h>
42 #include <ns3/spectrum-model-ism2400MHz-res1MHz.h>
43 #include <ns3/string.h>
45 #include <ns3/uinteger.h>
46 #include <ns3/waveform-generator.h>
82 bool rateIsAchievable,
83 std::string channelType);
87 void DoRun()
override;
95 static std::string
Name(std::string channelType,
double snrLinear, uint64_t phyRate);
106 std::ostringstream oss;
107 oss << channelType <<
" snr = " << snrLinear <<
" (linear), "
108 <<
" phyRate = " << phyRate <<
" bps";
114 bool rateIsAchievable,
115 std::string channelType)
117 m_snrLinear(snrLinear),
119 m_rateIsAchievable(rateIsAchievable),
120 m_channelType(channelType)
132 double txPowerW = 0.1;
135 const double k = 1.381e-23;
136 const double T = 290;
137 double noisePsdValue =
k * T;
139 double lossDb = 10 * std::log10(lossLinear);
143 uint32_t numPkts = 200;
147 double testDuration = (numPkts *
pktSize * 8.0) / phyRate;
148 NS_LOG_INFO(
"test duration = " << std::fixed << testDuration);
155 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
156 positionAlloc->Add(Vector(5.0, 0.0, 0.0));
157 mobility.SetPositionAllocator(positionAlloc);
158 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
175 uint32_t channelNumber = 1;
196 client->SetRemote(socket);
197 client->SetAttribute(
"Interval",
208 Simulator::Stop(
Seconds(testDuration + 0.000000001));
210 double throughputBps = (
g_rxBytes * 8.0) / testDuration;
212 std::clog.unsetf(std::ios_base::floatfield);
219 "throughput does not match PHY rate");
225 "PHY rate is not achievable but throughput is non-zero");
228 Simulator::Destroy();
243 :
TestSuite(
"spectrum-ideal-phy", SYSTEM)
247 for (
double snr = 0.01; snr <= 10; snr *= 2)
249 double achievableRate =
g_bandwidth * log2(1 + snr);
251 static_cast<uint64_t
>(achievableRate * 0.1),
253 "ns3::SingleModelSpectrumChannel"),
256 static_cast<uint64_t
>(achievableRate * 0.5),
258 "ns3::SingleModelSpectrumChannel"),
261 static_cast<uint64_t
>(achievableRate * 0.95),
263 "ns3::SingleModelSpectrumChannel"),
266 static_cast<uint64_t
>(achievableRate * 1.05),
268 "ns3::SingleModelSpectrumChannel"),
271 static_cast<uint64_t
>(achievableRate * 2),
273 "ns3::SingleModelSpectrumChannel"),
276 static_cast<uint64_t
>(achievableRate * 4),
278 "ns3::SingleModelSpectrumChannel"),
281 for (
double snr = 0.01; snr <= 10; snr *= 10)
283 double achievableRate =
g_bandwidth * log2(1 + snr);
285 static_cast<uint64_t
>(achievableRate * 0.1),
287 "ns3::MultiModelSpectrumChannel"),
290 static_cast<uint64_t
>(achievableRate * 0.5),
292 "ns3::MultiModelSpectrumChannel"),
295 static_cast<uint64_t
>(achievableRate * 0.95),
297 "ns3::MultiModelSpectrumChannel"),
300 static_cast<uint64_t
>(achievableRate * 1.05),
302 "ns3::MultiModelSpectrumChannel"),
305 static_cast<uint64_t
>(achievableRate * 2),
307 "ns3::MultiModelSpectrumChannel"),
310 static_cast<uint64_t
>(achievableRate * 4),
312 "ns3::MultiModelSpectrumChannel"),
static std::string Name(std::string channelType, double snrLinear, uint64_t phyRate)
Get the test name.
~SpectrumIdealPhyTestCase() override
double m_snrLinear
SNR (linear)
bool m_rateIsAchievable
Check if the rate is achievable.
uint64_t m_phyRate
PHY rate (bps)
void DoRun() override
Implementation to actually run this TestCase.
std::string m_channelType
Channel type.
SpectrumIdealPhyTestCase(double snrLinear, uint64_t phyRate, bool rateIsAchievable, std::string channelType)
Constructor.
Ideal Spectrum PHY TestSuite.
SpectrumIdealPhyTestSuite()
create the AlohaNoackNetDevice
void SetPhyAttribute(std::string name, const AttributeValue &v)
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
void SetNoisePowerSpectralDensity(Ptr< SpectrumValue > noisePsd)
void SetChannel(Ptr< SpectrumChannel > channel)
set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper
NetDeviceContainer Install(NodeContainer c) const
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
Give ns3::PacketSocket powers to ns3::Node.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Ptr< SpectrumChannel > Create() const
void AddPropagationLoss(std::string name, Ts &&... args)
void SetPropagationDelay(std::string name, Ts &&... args)
void SetChannel(std::string type, Ts &&... args)
Implements Wifi SpectrumValue for the 2.4 GHz ISM band only, with a 5 MHz spectrum resolution.
virtual Ptr< SpectrumValue > CreateConstant(double psd)
Creates a SpectrumValue instance with a constant value for all frequencies.
virtual Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint8_t channel)
Creates a SpectrumValue instance that represents the TX Power Spectral Density of a wifi device corre...
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Hold an unsigned integer type.
void Connect(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void PhyRxEndOkTrace(std::string context, Ptr< const Packet > p)
static SpectrumIdealPhyTestSuite g_spectrumIdealPhyTestSuite
Static variable for test initialization.
static uint64_t g_rxBytes
static double g_bandwidth
static std::string Name(std::string str, uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t serverReadSize, uint32_t serverWriteSize, uint32_t sourceReadSize, bool useIpv6)
uint32_t pktSize
packet size used for the simulation (in bytes)