A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
application.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 Georgia Tech Research Corporation
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: George F. Riley<riley@ece.gatech.edu>
7 */
8
9#ifndef APPLICATION_H
10#define APPLICATION_H
11
12#include "node.h"
13
14#include "ns3/event-id.h"
15#include "ns3/nstime.h"
16#include "ns3/object.h"
17#include "ns3/ptr.h"
18
19namespace ns3
20{
21
22class Node;
23
24/**
25 * @addtogroup applications Applications
26 *
27 * Class ns3::Application can be used as a base class for ns3 applications.
28 * Applications are associated with individual nodes. Each node
29 * holds a list of references (smart pointers) to its applications.
30 *
31 * Conceptually, an application has zero or more ns3::Socket
32 * objects associated with it, that are created using the Socket
33 * creation API of the Kernel capability. The Socket object
34 * API is modeled after the
35 * well-known BSD sockets interface, although it is somewhat
36 * simplified for use with ns3. Further, any socket call that
37 * would normally "block" in normal sockets will return immediately
38 * in ns3. A set of "upcalls" are defined that will be called when
39 * the previous blocking call would normally exit. THis is documented
40 * in more detail Socket class in socket.h.
41 *
42 * The main purpose of the base class application public API is to
43 * provide a uniform way to start and stop applications.
44 */
45
46/**
47 * @brief The base class for all ns3 applications
48 *
49 */
50class Application : public Object
51{
52 public:
53 /**
54 * @brief Get the type ID.
55 * @return the object TypeId
56 */
57 static TypeId GetTypeId();
59 ~Application() override;
60
61 /**
62 * @brief Specify application start time
63 * @param start Start time for this application,
64 * relative to the current simulation time.
65 *
66 * Applications start at various times in the simulation scenario.
67 * This method specifies when the application should be
68 * started. The application subclasses should override the
69 * private "StartApplication" method defined below, which is called at the
70 * time specified, to cause the application to begin.
71 */
72 void SetStartTime(Time start);
73
74 /**
75 * @brief Specify application stop time
76 * @param stop Stop time for this application, relative to the
77 * current simulation time.
78 *
79 * Once an application has started, it is sometimes useful
80 * to stop the application. This method specifies when an
81 * application is to stop. The application subclasses should override
82 * the private StopApplication method, to be notified when that
83 * time has come.
84 */
85 void SetStopTime(Time stop);
86
87 /**
88 * @returns the Node to which this Application object is attached.
89 */
90 Ptr<Node> GetNode() const;
91
92 /**
93 * @param node the node to which this Application object is attached.
94 */
95 void SetNode(Ptr<Node> node);
96
97 /**
98 * @brief Assign a fixed random variable stream number to the random variables
99 * used by this Application object.
100 *
101 * @param stream first stream index to use
102 * @return the number of stream indices assigned by this Application object
103 */
104 virtual int64_t AssignStreams(int64_t stream);
105
106 /**
107 * @brief Common callback signature for packet delay and address.
108 *
109 * @param delay The packet delay.
110 * @param from The source socket address associated with the packet,
111 * indicating the packet's origin.
112 */
113 typedef void (*DelayAddressCallback)(const Time& delay, const Address& from);
114
115 /**
116 * @brief Common signature used by callbacks to application's state
117 * transition trace source.
118 * @param oldState The name of the previous state.
119 * @param newState The name of the current state.
120 */
121 typedef void (*StateTransitionCallback)(const std::string& oldState,
122 const std::string& newState);
123
124 private:
125 /**
126 * @brief Application specific startup code
127 *
128 * The StartApplication method is called at the start time specified by Start
129 * This method should be overridden by all or most application
130 * subclasses.
131 */
132 virtual void StartApplication();
133
134 /**
135 * @brief Application specific shutdown code
136 *
137 * The StopApplication method is called at the stop time specified by Stop
138 * This method should be overridden by all or most application
139 * subclasses.
140 */
141 virtual void StopApplication();
142
143 protected:
144 void DoDispose() override;
145 void DoInitialize() override;
146
147 Ptr<Node> m_node; //!< The node that this application is installed on
148 Time m_startTime; //!< The simulation time that the application will start
149 Time m_stopTime; //!< The simulation time that the application will end
150 EventId m_startEvent; //!< The event that will fire at m_startTime to start the application
151 EventId m_stopEvent; //!< The event that will fire at m_stopTime to end the application
152};
153
154} // namespace ns3
155
156#endif /* APPLICATION_H */
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
EventId m_startEvent
The event that will fire at m_startTime to start the application.
void DoInitialize() override
Initialize() implementation.
void SetNode(Ptr< Node > node)
void DoDispose() override
Destructor implementation.
Time m_startTime
The simulation time that the application will start.
Time m_stopTime
The simulation time that the application will end.
~Application() override
void SetStopTime(Time stop)
Specify application stop time.
virtual void StopApplication()
Application specific shutdown code.
virtual void StartApplication()
Application specific startup code.
void SetStartTime(Time start)
Specify application start time.
void(* DelayAddressCallback)(const Time &delay, const Address &from)
Common callback signature for packet delay and address.
EventId m_stopEvent
The event that will fire at m_stopTime to end the application.
void(* StateTransitionCallback)(const std::string &oldState, const std::string &newState)
Common signature used by callbacks to application's state transition trace source.
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this Application object.
static TypeId GetTypeId()
Get the type ID.
Ptr< Node > GetNode() const
Ptr< Node > m_node
The node that this application is installed on.
An identifier for simulation events.
Definition event-id.h:45
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.