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
32using namespace ns3;
33
37class Sender : public Application
38{
39 public:
44 static TypeId GetTypeId();
45 Sender();
46 ~Sender() override;
47
48 protected:
49 void DoDispose() override;
50
51 private:
52 void StartApplication() override;
53 void StopApplication() override;
54
58 void SendPacket();
59
65
68
71
73
74 // end class Sender
75};
76
80class Receiver : public Application
81{
82 public:
87 static TypeId GetTypeId();
88 Receiver();
89 ~Receiver() override;
90
96
102
103 protected:
104 void DoDispose() override;
105
106 private:
107 void StartApplication() override;
108 void StopApplication() override;
109
114 void Receive(Ptr<Socket> socket);
115
118
121
122 // end class Receiver
123};
124
132class TimestampTag : public Tag
133{
134 public:
139 static TypeId GetTypeId();
140 TypeId GetInstanceTypeId() const override;
141
142 uint32_t GetSerializedSize() const override;
143 void Serialize(TagBuffer i) const override;
144 void Deserialize(TagBuffer i) override;
145
150 void SetTimestamp(Time time);
155 Time GetTimestamp() const;
156
157 void Print(std::ostream& os) const override;
158
159 private:
161
162 // end class TimestampTag
163};
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.
uint32_t m_numPkts
Number of packets to send.
~Sender() override
TracedCallback< Ptr< const Packet > > m_txTrace
Tx TracedCallback.
void StartApplication() override
Application specific startup code.
uint32_t m_pktSize
The packet size.
Timestamp tag - it carries when the packet has been sent.
void Print(std::ostream &os) const override
void Serialize(TagBuffer i) const override
static TypeId GetTypeId()
Get the type ID.
uint32_t GetSerializedSize() const override
void SetTimestamp(Time time)
Set the timestamp.
void Deserialize(TagBuffer i) override
Time GetTimestamp() const
Get the timestamp.
Time m_timestamp
Timestamp.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
The base class for all ns3 applications.
Definition: application.h:61
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:43
read and write tag data
Definition: tag-buffer.h:52
tag a set of bytes in a packet
Definition: tag.h:39
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:60
Every class exported by the ns3 library is enclosed in the ns3 namespace.