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#ifndef WIFI_EXAMPLE_APPS_H
17#define WIFI_EXAMPLE_APPS_H
18
19#include "ns3/application.h"
20#include "ns3/core-module.h"
21#include "ns3/network-module.h"
22#include "ns3/stats-module.h"
23
24using namespace ns3;
25
26// ==============================================
27// SENDER
28// ==============================================
29
30/**
31 * Sender application.
32 */
33class Sender : public Application
34{
35 public:
36 /**
37 * @brief Get the type ID.
38 * @return The object TypeId.
39 */
40 static TypeId GetTypeId();
41
42 Sender();
43 ~Sender() override;
44
45 protected:
46 void DoDispose() override;
47
48 private:
49 void StartApplication() override;
50 void StopApplication() override;
51
52 /**
53 * Send a packet.
54 */
55 void SendPacket();
56
57 Ipv4Address m_destAddr; //!< Destination address
58 uint32_t m_destPort{0}; //!< Destination port
59 uint32_t m_packetSize{0}; //!< The packet size
60 Ptr<ConstantRandomVariable> m_interval; //!< Rng for sending packets
61 uint32_t m_nPackets{0}; //!< Number of packets to send
62 uint32_t m_count{0}; //!< Number of packets sent
63
64 Ptr<Socket> m_socket; //!< Sending socket
65 EventId m_sendEvent; //!< Send packet event
66
67 /// Tx TracedCallback
69};
70
71// ==============================================
72// RECEIVER
73// ==============================================
74
75/**
76 * Receiver application.
77 */
78class Receiver : public Application
79{
80 public:
81 /**
82 * @brief Get the type ID.
83 * @return The object TypeId.
84 */
85 static TypeId GetTypeId();
86
87 Receiver();
88 ~Receiver() override;
89
90 /**
91 * Set the counter calculator for received packets.
92 * @param calc The CounterCalculator.
93 */
95
96 /**
97 * Set the delay tracker for received packets.
98 * @param delay The Delay calculator.
99 */
101
102 protected:
103 void DoDispose() override;
104
105 private:
106 void StartApplication() override;
107 void StopApplication() override;
108
109 /**
110 * Receive a packet.
111 * @param socket The receiving socket.
112 */
113 void Receive(Ptr<Socket> socket);
114
115 Ptr<Socket> m_socket; //!< Receiving socket
116 uint32_t m_port{0}; //!< Listening port
117
118 Ptr<CounterCalculator<>> m_calc; //!< Counter of the number of received packets
120};
121
122#endif // WIFI_EXAMPLE_APPS_H
~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.
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.
Template class CounterCalculator.
An identifier for simulation events.
Definition event-id.h:44
Ipv4 addresses are stored in host order in this class.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.