A Discrete-Event Network Simulator
API
tutorial-app.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation;
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
16
17#include "tutorial-app.h"
18#include "ns3/applications-module.h"
19
20using namespace ns3;
21
22TutorialApp::TutorialApp ()
23 : m_socket (0),
24 m_peer (),
25 m_packetSize (0),
26 m_nPackets (0),
27 m_dataRate (0),
28 m_sendEvent (),
29 m_running (false),
30 m_packetsSent (0)
31{
32}
33
35{
36 m_socket = 0;
37}
38
39/* static */
41{
42 static TypeId tid = TypeId ("TutorialApp")
44 .SetGroupName ("Tutorial")
45 .AddConstructor<TutorialApp> ()
46 ;
47 return tid;
48}
49
50void
52{
53 m_socket = socket;
56 m_nPackets = nPackets;
57 m_dataRate = dataRate;
58}
59
60void
62{
63 m_running = true;
64 m_packetsSent = 0;
65 m_socket->Bind ();
67 SendPacket ();
68}
69
70void
72{
73 m_running = false;
74
76 {
78 }
79
80 if (m_socket)
81 {
82 m_socket->Close ();
83 }
84}
85
86void
88{
89 Ptr<Packet> packet = Create<Packet> (m_packetSize);
90 m_socket->Send (packet);
91
93 {
94 ScheduleTx ();
95 }
96}
97
98void
100{
101 if (m_running)
102 {
103 Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));
105 }
106}
a polymophic address class
Definition: address.h:91
The base class for all ns3 applications.
Definition: application.h:61
Class for representing data rates.
Definition: data-rate.h:89
uint64_t GetBitRate() const
Get the underlying bitrate.
Definition: data-rate.cc:287
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
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:268
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
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(void)=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:103
Tutorial - a simple Application sending packets.
Definition: tutorial-app.h:32
virtual ~TutorialApp()
Definition: tutorial-app.cc:34
static TypeId GetTypeId(void)
Register this type.
Definition: tutorial-app.cc:40
virtual void StopApplication(void)
Application specific shutdown code.
Definition: tutorial-app.cc:71
EventId m_sendEvent
Send event.
Definition: tutorial-app.h:67
Ptr< Socket > m_socket
The tranmission socket.
Definition: tutorial-app.h:62
uint32_t m_packetsSent
The number of pacts sent.
Definition: tutorial-app.h:69
void ScheduleTx(void)
Schedule a new transmission.
Definition: tutorial-app.cc:99
void SendPacket(void)
Send a packet.
Definition: tutorial-app.cc:87
Address m_peer
The destination address.
Definition: tutorial-app.h:63
uint32_t m_packetSize
The packet size.
Definition: tutorial-app.h:64
void Setup(Ptr< Socket > socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate)
Setup the socket.
Definition: tutorial-app.cc:51
DataRate m_dataRate
The datarate to use.
Definition: tutorial-app.h:66
uint32_t m_nPackets
The number of pacts to send.
Definition: tutorial-app.h:65
virtual void StartApplication(void)
Application specific startup code.
Definition: tutorial-app.cc:61
bool m_running
True if the application is running.
Definition: tutorial-app.h:68
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t packetSize
Pcket size generated at the AP.