A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tutorial-app.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5#include "tutorial-app.h"
6
7#include "ns3/applications-module.h"
8
9using namespace ns3;
10
12 : m_socket(nullptr),
13 m_peer(),
14 m_packetSize(0),
15 m_nPackets(0),
16 m_dataRate(0),
18 m_running(false),
20{
21}
22
24{
25 m_socket = nullptr;
26}
27
28/* static */
31{
32 static TypeId tid = TypeId("TutorialApp")
34 .SetGroupName("Tutorial")
35 .AddConstructor<TutorialApp>();
36 return tid;
37}
38
39void
41 Address address,
43 uint32_t nPackets,
44 DataRate dataRate)
45{
46 m_socket = socket;
47 m_peer = address;
49 m_nPackets = nPackets;
50 m_dataRate = dataRate;
51}
52
53void
55{
56 m_running = true;
57 m_packetsSent = 0;
58 m_socket->Bind();
59 m_socket->Connect(m_peer);
60 SendPacket();
61}
62
63void
65{
66 m_running = false;
67
68 if (m_sendEvent.IsPending())
69 {
71 }
72
73 if (m_socket)
74 {
75 m_socket->Close();
76 }
77}
78
79void
81{
83 m_socket->Send(packet);
84
86 {
87 ScheduleTx();
88 }
89}
90
91void
93{
94 if (m_running)
95 {
96 Time tNext(Seconds(m_packetSize * 8 / static_cast<double>(m_dataRate.GetBitRate())));
98 }
99}
a polymophic address class
Definition address.h:90
Class for representing data rates.
Definition data-rate.h:78
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition simulator.cc:274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
void StopApplication() override
Application specific shutdown code.
void ScheduleTx()
Schedule a new transmission.
static TypeId GetTypeId()
Register this type.
~TutorialApp() override
EventId m_sendEvent
Send event.
Ptr< Socket > m_socket
The transmission socket.
uint32_t m_packetsSent
The number of packets sent.
void SendPacket()
Send a packet.
Address m_peer
The destination address.
uint32_t m_packetSize
The packet size.
void Setup(Ptr< Socket > socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate)
Setup the socket.
void StartApplication() override
Application specific startup code.
DataRate m_dataRate
The data rate to use.
uint32_t m_nPackets
The number of packets to send.
bool m_running
True if the application is running.
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t packetSize
Packet size generated at the AP.