A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-example-apps.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Authors: Joe Kopena <tjkopena@cs.drexel.edu>
5 *
6 * These applications are used in the WiFi Distance Test experiment,
7 * described and implemented in test02.cc. That file should be in the
8 * same place as this file. The applications have two very simple
9 * jobs, they just generate and receive packets. We could use the
10 * standard Application classes included in the NS-3 distribution.
11 * These have been written just to change the behavior a little, and
12 * provide more examples.
13 *
14 */
15
16#include "ns3/application.h"
17#include "ns3/core-module.h"
18#include "ns3/network-module.h"
19#include "ns3/stats-module.h"
20
21using namespace ns3;
22
23// ==============================================
24// SENDER
25// ==============================================
26
27/**
28 * Sender application.
29 */
30class Sender : public Application
31{
32 public:
33 /**
34 * \brief Get the type ID.
35 * \return The object TypeId.
36 */
37 static TypeId GetTypeId();
38
39 Sender();
40 ~Sender() override;
41
42 protected:
43 void DoDispose() override;
44
45 private:
46 void StartApplication() override;
47 void StopApplication() override;
48
49 /**
50 * Send a packet.
51 */
52 void SendPacket();
53
54 Ipv4Address m_destAddr; //!< Destination address
55 uint32_t m_destPort{0}; //!< Destination port
56 uint32_t m_packetSize{0}; //!< The packet size
57 Ptr<ConstantRandomVariable> m_interval; //!< Rng for sending packets
58 uint32_t m_nPackets{0}; //!< Number of packets to send
59 uint32_t m_count{0}; //!< Number of packets sent
60
61 Ptr<Socket> m_socket; //!< Sending socket
62 EventId m_sendEvent; //!< Send packet event
63
64 /// Tx TracedCallback
66};
67
68// ==============================================
69// RECEIVER
70// ==============================================
71
72/**
73 * Receiver application.
74 */
75class Receiver : public Application
76{
77 public:
78 /**
79 * \brief Get the type ID.
80 * \return The object TypeId.
81 */
82 static TypeId GetTypeId();
83
84 Receiver();
85 ~Receiver() override;
86
87 /**
88 * Set the counter calculator for received packets.
89 * \param calc The CounterCalculator.
90 */
92
93 /**
94 * Set the delay tracker for received packets.
95 * \param delay The Delay calculator.
96 */
98
99 protected:
100 void DoDispose() override;
101
102 private:
103 void StartApplication() override;
104 void StopApplication() override;
105
106 /**
107 * Receive a packet.
108 * \param socket The receiving socket.
109 */
110 void Receive(Ptr<Socket> socket);
111
112 Ptr<Socket> m_socket; //!< Receiving socket
113 uint32_t m_port{0}; //!< Listening port
114
115 Ptr<CounterCalculator<>> m_calc; //!< Counter of the number of received packets
117};
Receiver application.
~Receiver() override
void StopApplication() override
Application specific shutdown code.
uint32_t m_port
Listening port.
Ptr< Socket > m_socket
Receiving socket.
void DoDispose() override
Destructor implementation.
void SetDelayTracker(Ptr< TimeMinMaxAvgTotalCalculator > delay)
Set the delay tracker for received packets.
static TypeId GetTypeId()
Get the type ID.
void Receive(Ptr< Socket > socket)
Receive a packet.
Ptr< CounterCalculator<> > m_calc
Counter of the number of received packets.
void StartApplication() override
Application specific startup code.
void SetCounter(Ptr< CounterCalculator<> > calc)
Set the counter calculator for received packets.
Ptr< TimeMinMaxAvgTotalCalculator > m_delay
Delay calculator.
Sender application.
Ptr< Socket > m_socket
Sending socket.
void SendPacket()
Send a packet.
uint32_t m_count
Number of packets sent.
uint32_t m_destPort
Destination port.
Ptr< ConstantRandomVariable > m_interval
Rng for sending packets.
void StopApplication() override
Application specific shutdown code.
Ipv4Address m_destAddr
Destination address.
void DoDispose() override
Destructor implementation.
static TypeId GetTypeId()
Get the type ID.
EventId m_sendEvent
Send packet event.
~Sender() override
uint32_t m_packetSize
The packet size.
TracedCallback< Ptr< const Packet > > m_txTrace
Tx TracedCallback.
uint32_t m_nPackets
Number of packets to send.
void StartApplication() override
Application specific startup code.
The base class for all ns3 applications.
Definition application.h:51
Template class CounterCalculator.
An identifier for simulation events.
Definition event-id.h:45
Ipv4 addresses are stored in host order in this class.
Smart pointer class similar to boost::intrusive_ptr.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.