20 #include <ns3/adhoc-aloha-noack-ideal-phy-helper.h>
21 #include <ns3/applications-module.h>
22 #include <ns3/core-module.h>
23 #include <ns3/friis-spectrum-propagation-loss.h>
24 #include <ns3/ism-spectrum-value-helper.h>
26 #include <ns3/mobility-module.h>
27 #include <ns3/network-module.h>
28 #include <ns3/propagation-delay-model.h>
29 #include <ns3/single-model-spectrum-channel.h>
30 #include <ns3/spectrum-analyzer.h>
31 #include <ns3/spectrum-helper.h>
32 #include <ns3/spectrum-model-300kHz-300GHz-log.h>
33 #include <ns3/spectrum-model-ism2400MHz-res1MHz.h>
34 #include <ns3/waveform-generator.h>
58 std::cout << context <<
" PHY RX END OK p:" << p << std::endl;
82 void UpdatePathloss(std::string context,
107 m_pathlossMap[txNodeId][rxNodeId] = lossDb;
113 for (
auto txit = m_pathlossMap.begin(); txit != m_pathlossMap.end(); ++txit)
115 for (
auto rxit = txit->second.begin(); rxit != txit->second.end(); ++rxit)
117 std::cout << txit->first <<
" --> " << rxit->first <<
" : " << rxit->second <<
" dB"
124 main(
int argc,
char** argv)
128 double txPowerW = 0.1;
129 uint64_t phyRate = 500000;
131 double simDuration = 0.5;
132 std::string channelType(
"ns3::SingleModelSpectrumChannel");
133 cmd.AddValue(
"verbose",
"Print trace information if true",
g_verbose);
134 cmd.AddValue(
"lossDb",
"link loss in dB", lossDb);
135 cmd.AddValue(
"txPowerW",
"txPower in Watts", txPowerW);
136 cmd.AddValue(
"phyRate",
"PHY rate in bps", phyRate);
137 cmd.AddValue(
"pktSize",
"packet size in bytes",
pktSize);
138 cmd.AddValue(
"simDuration",
"duration of the simulation in seconds", simDuration);
139 cmd.AddValue(
"channelType",
"which SpectrumChannel implementation to be used", channelType);
140 cmd.Parse(argc, argv);
146 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
163 uint32_t channelNumber = 1;
168 const double k = 1.381e-23;
169 const double T = 290;
170 double noisePsdValue =
k * T;
208 globalPathlossDatabase.
Print();
210 double throughputBps = (
g_rxBytes * 8.0) / simDuration;
211 std::cout <<
"throughput: " << throughputBps << std::endl;
212 std::cout <<
"throughput: " << std::setw(20) << std::fixed << throughputBps <<
" bps"
214 std::cout <<
"phy rate : " << std::setw(20) << std::fixed << phyRate * 1.0 <<
" bps"
216 double rxPowerW = txPowerW / (std::pow(10.0, lossDb / 10.0));
217 double capacity = 20e6 * log2(1.0 + (rxPowerW / 20.0e6) / noisePsdValue);
218 std::cout <<
"shannon capacity: " << std::setw(20) << std::fixed << capacity <<
" bps"
static bool g_verbose
True if verbose output.
void PhyRxEndOkTrace(std::string context, Ptr< const Packet > p)
Trace for PHY Rx successful end.
static uint64_t g_rxBytes
Rx bytes counter.
Store the last pathloss value for each TX-RX pair.
void Print()
print the stored pathloss values to standard output
void UpdatePathloss(std::string context, Ptr< const SpectrumPhy > txPhy, Ptr< const SpectrumPhy > rxPhy, double lossDb)
update the pathloss value
std::map< uint32_t, std::map< uint32_t, double > > m_pathlossMap
Path loss map.
a polymophic address class
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
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Parse command-line arguments.
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
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.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
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)
virtual Ptr< MobilityModel > GetMobility() const =0
Get the associated MobilityModel instance.
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...
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.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Seconds(double value)
Construct a Time in the indicated unit.
void Print(ComponentCarrier cc)
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...
uint32_t pktSize
packet size used for the simulation (in bytes)