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/microwave-oven-spectrum-value-helper.h>
27 #include <ns3/mobility-module.h>
28 #include <ns3/multi-model-spectrum-channel.h>
29 #include <ns3/network-module.h>
30 #include <ns3/non-communicating-net-device.h>
31 #include <ns3/propagation-delay-model.h>
32 #include <ns3/spectrum-analyzer-helper.h>
33 #include <ns3/spectrum-analyzer.h>
34 #include <ns3/spectrum-helper.h>
35 #include <ns3/spectrum-model-300kHz-300GHz-log.h>
36 #include <ns3/spectrum-model-ism2400MHz-res1MHz.h>
37 #include <ns3/waveform-generator-helper.h>
38 #include <ns3/waveform-generator.h>
61 std::cout << context <<
" PHY TX START p: " << p << std::endl;
76 std::cout << context <<
" PHY TX END p: " << p << std::endl;
91 std::cout << context <<
" PHY RX START p:" << p << std::endl;
106 std::cout << context <<
" PHY RX END OK p:" << p << std::endl;
121 std::cout << context <<
" PHY RX END ERROR p:" << p << std::endl;
135 while ((packet = socket->
Recv()))
141 std::cout <<
"SOCKET received " << bytes <<
" bytes" << std::endl;
162 main(
int argc,
char** argv)
165 cmd.AddValue(
"verbose",
"Print trace information if true",
g_verbose);
166 cmd.Parse(argc, argv);
174 waveformGeneratorNodes.
Create(1);
175 spectrumAnalyzerNodes.
Create(1);
176 allNodes.
Add(ofdmNodes);
177 allNodes.
Add(waveformGeneratorNodes);
178 allNodes.
Add(spectrumAnalyzerNodes);
182 nodePositionList->Add(Vector(5.0, 0.0, 0.0));
183 nodePositionList->Add(Vector(0.0, 0.0, 0.0));
184 nodePositionList->Add(Vector(30.0, 0.0, 0.0));
185 nodePositionList->Add(Vector(0.0, 0.0, 0.0));
186 mobility.SetPositionAllocator(nodePositionList);
187 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
192 channelHelper.
SetChannel(
"ns3::MultiModelSpectrumChannel");
201 double txPower = 0.1;
202 uint32_t channelNumber = 4;
207 const double k = 1.381e-23;
208 const double T = 290;
209 double noisePsdValue =
k * T;
220 packetSocket.
Install(ofdmNodes);
228 onoff.SetAttribute(
"OnTime",
StringValue(
"ns3::ExponentialRandomVariable[Mean=0.04]"));
229 onoff.SetAttribute(
"OffTime",
StringValue(
"ns3::ExponentialRandomVariable[Mean=0.01]"));
230 onoff.SetAttribute(
"DataRate", DataRateValue(
DataRate(
"0.4Mbps")));
254 waveformGeneratorHelper.
Install(waveformGeneratorNodes);
258 waveformGeneratorDevices.
Get(0)
273 spectrumAnalyzerHelper.
EnableAsciiAll(
"spectrum-analyzer-output");
275 spectrumAnalyzerHelper.
Install(spectrumAnalyzerNodes);
void PhyTxEndTrace(std::string context, Ptr< const Packet > p)
PHY start TX trace.
Ptr< Socket > SetupPacketReceive(Ptr< Node > node)
Create a socket and prepare it for packet reception.
void PhyRxEndErrorTrace(std::string context, Ptr< const Packet > p)
PHY end error RX trace.
void PhyRxStartTrace(std::string context, Ptr< const Packet > p)
PHY end TX trace.
void ReceivePacket(Ptr< Socket > socket)
Receive callback.
static bool g_verbose
True for verbose output.
void PhyRxEndOkTrace(std::string context, Ptr< const Packet > p)
PHY end OK RX trace.
void PhyTxStartTrace(std::string context, Ptr< const Packet > p)
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.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
static Ptr< SpectrumValue > CreatePowerSpectralDensityMwo1()
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
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.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
This class implements a device which does not communicate, in the sense that it does not interact wit...
Ptr< Object > GetPhy() const
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 EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
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.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Class to allow the Spectrum Analysis.
NetDeviceContainer Install(NodeContainer c) const
void SetPhyAttribute(std::string name, const AttributeValue &v)
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper.
void EnableAsciiAll(std::string prefix)
Enable ASCII output.
void SetRxSpectrumModel(Ptr< SpectrumModel > m)
Set the spectrum model used by the created SpectrumAnalyzer instances to represent incoming signals.
Ptr< SpectrumChannel > Create() const
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
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...
Hold variables of type string.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
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_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Ptr< SpectrumModel > SpectrumModelIsm2400MhzRes1Mhz
Spectrum model logger for frequencies in the 2.4 GHz ISM band with 1 MHz resolution.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t 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...
Ptr< PacketSink > sink
Pointer to the packet sink application.