A Discrete-Event Network Simulator
API
wifi-example-apps.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * Authors: Joe Kopena <tjkopena@cs.drexel.edu>
16  *
17  * These applications are used in the WiFi Distance Test experiment,
18  * described and implemented in test02.cc. That file should be in the
19  * same place as this file. The applications have two very simple
20  * jobs, they just generate and receive packets. We could use the
21  * standard Application classes included in the NS-3 distribution.
22  * These have been written just to change the behavior a little, and
23  * provide more examples.
24  *
25  */
26 
27 #include "ns3/application.h"
28 #include "ns3/core-module.h"
29 #include "ns3/network-module.h"
30 #include "ns3/stats-module.h"
31 
32 using namespace ns3;
33 
34 // ==============================================
35 // SENDER
36 // ==============================================
37 
41 class Sender : public Application
42 {
43  public:
48  static TypeId GetTypeId();
49 
50  Sender();
51  ~Sender() override;
52 
53  protected:
54  void DoDispose() override;
55 
56  private:
57  void StartApplication() override;
58  void StopApplication() override;
59 
63  void SendPacket();
64 
66  uint32_t m_destPort{0};
67  uint32_t m_packetSize{0};
69  uint32_t m_nPackets{0};
70  uint32_t m_count{0};
71 
74 
77 };
78 
79 // ==============================================
80 // RECEIVER
81 // ==============================================
82 
86 class Receiver : public Application
87 {
88  public:
93  static TypeId GetTypeId();
94 
95  Receiver();
96  ~Receiver() override;
97 
102  void SetCounter(Ptr<CounterCalculator<>> calc);
103 
108  void SetDelayTracker(Ptr<TimeMinMaxAvgTotalCalculator> delay);
109 
110  protected:
111  void DoDispose() override;
112 
113  private:
114  void StartApplication() override;
115  void StopApplication() override;
116 
121  void Receive(Ptr<Socket> socket);
122 
124  uint32_t m_port{0};
125 
128 };
Receiver application.
Ptr< Socket > m_socket
Receiving socket.
Ptr< CounterCalculator<> > m_calc
Counter of the number of received packets.
Ptr< TimeMinMaxAvgTotalCalculator > m_delay
Delay calculator.
Sender application.
Ptr< Socket > m_socket
Sending socket.
Ptr< ConstantRandomVariable > m_interval
Rng for sending packets.
Ipv4Address m_destAddr
Destination address.
EventId m_sendEvent
Send packet event.
TracedCallback< Ptr< const Packet > > m_txTrace
Tx TracedCallback.
The base class for all ns3 applications.
Definition: application.h:62
Template class CounterCalculator.
An identifier for simulation events.
Definition: event-id.h:55
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
This example (inspired from tv-trans-example) enables to generate the transmitted spectra of Wi-Fi st...