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),
17 m_sendEvent(),
18 m_running(false),
19 m_packetsSent(0)
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
62
63void
65{
66 m_running = false;
67
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
The base class for all ns3 applications.
Definition application.h:51
Class for representing data rates.
Definition data-rate.h:78
uint64_t GetBitRate() const
Get the underlying bitrate.
Definition data-rate.cc:234
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
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
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual int Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Tutorial - a simple Application sending packets.
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:48
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:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t packetSize
Packet size generated at the AP.