author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Fri, 11 Jul 2008 18:39:19 +0100 | |
changeset 3416 | 926ccb845111 |
parent 3174 | efeb6e5c276d |
child 3930 | 591392bea401 |
permissions | -rw-r--r-- |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
/* |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
* Copyright (c) 2006 Georgia Tech Research Corporation |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
* |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
* |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
* |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
* |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
18 |
* Author: George F. Riley<riley@ece.gatech.edu> |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
21 |
// Implementation for ns3 Application base class. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
22 |
// George F. Riley, Georgia Tech, Fall 2006 |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
23 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
24 |
#include "application.h" |
729
b5e744285e92
rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
728
diff
changeset
|
25 |
#include "ns3/node.h" |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
26 |
#include "ns3/nstime.h" |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
#include "ns3/random-variable.h" |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
#include "ns3/simulator.h" |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
29 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
30 |
using namespace std; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
31 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
32 |
namespace ns3 { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
33 |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
34 |
NS_OBJECT_ENSURE_REGISTERED (Application); |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
35 |
|
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
36 |
// Application Methods |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
37 |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
38 |
TypeId |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
39 |
Application::GetTypeId (void) |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
40 |
{ |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
41 |
static TypeId tid = TypeId ("ns3::Application") |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
42 |
.SetParent<Object> () |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
43 |
; |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
44 |
return tid; |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
45 |
} |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
46 |
|
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
47 |
// \brief Application Constructor |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
48 |
Application::Application() |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
49 |
{} |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
50 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
51 |
// \brief Application Destructor |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
52 |
Application::~Application() |
517
702e96b8960f
finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
497
diff
changeset
|
53 |
{} |
497
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
54 |
|
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
55 |
void |
517
702e96b8960f
finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
497
diff
changeset
|
56 |
Application::DoDispose (void) |
497
34d6f349478f
implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
493
diff
changeset
|
57 |
{ |
563
fc4833e1a9b0
implement properly Application::DoDispose and rename Application::PeekNOde to Application::GetNode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
545
diff
changeset
|
58 |
m_node = 0; |
588
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
59 |
Simulator::Cancel(m_startEvent); |
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
60 |
Simulator::Cancel(m_stopEvent); |
587
8d2fd4c1bb7a
remove Application::Copy
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
585
diff
changeset
|
61 |
} |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
62 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
63 |
void Application::Start(const Time& startTime) |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
{ |
588
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
65 |
ScheduleStart (startTime); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
66 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
67 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
68 |
void Application::Start(const RandomVariable& startVar) |
588
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
69 |
{ |
2336
28ce210b91bb
bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
729
diff
changeset
|
70 |
RandomVariable v = startVar; |
28ce210b91bb
bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
729
diff
changeset
|
71 |
ScheduleStart (Seconds (v.GetValue ())); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
72 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
73 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
74 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
75 |
void Application::Stop(const Time& stopTime) |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
76 |
{ |
588
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
77 |
ScheduleStop (stopTime); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
78 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
80 |
void Application::Stop(const RandomVariable& stopVar) |
588
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
81 |
{ |
2336
28ce210b91bb
bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
729
diff
changeset
|
82 |
RandomVariable v = stopVar; |
28ce210b91bb
bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
729
diff
changeset
|
83 |
ScheduleStop (Seconds (v.GetValue ())); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
84 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
85 |
|
728
95c426b1cb60
rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
607
diff
changeset
|
86 |
Ptr<Node> Application::GetNode() const |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
87 |
{ |
493
68542941fc8a
use ref/unref for Node in more cases
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
488
diff
changeset
|
88 |
return m_node; |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
89 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
90 |
|
2600
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
91 |
void |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
92 |
Application::SetNode (Ptr<Node> node) |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
93 |
{ |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
94 |
m_node = node; |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
95 |
} |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
96 |
|
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
97 |
// Protected methods |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
98 |
// StartApp and StopApp will likely be overridden by application subclasses |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
99 |
void Application::StartApplication() |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
100 |
{ // Provide null functionality in case subclass is not interested |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
101 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
102 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
103 |
void Application::StopApplication() |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
104 |
{ // Provide null functionality in case subclass is not interested |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
105 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
106 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
107 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
108 |
// Private helpers |
588
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
109 |
void Application::ScheduleStart (const Time &startTime) |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
110 |
{ |
3174
efeb6e5c276d
Make Application::Start/Stop times relative, Simulator::StopAt(time) renamed to Simulator::Stop(time) and time also made relative, to improve consistency of the API which uses relative times everywhere else. Closes bug #191.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
2602
diff
changeset
|
111 |
m_startEvent = Simulator::Schedule (startTime, |
efeb6e5c276d
Make Application::Start/Stop times relative, Simulator::StopAt(time) renamed to Simulator::Stop(time) and time also made relative, to improve consistency of the API which uses relative times everywhere else. Closes bug #191.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
2602
diff
changeset
|
112 |
&Application::StartApplication, this); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
113 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
114 |
|
588
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
115 |
void Application::ScheduleStop (const Time &stopTime) |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
116 |
{ |
3174
efeb6e5c276d
Make Application::Start/Stop times relative, Simulator::StopAt(time) renamed to Simulator::Stop(time) and time also made relative, to improve consistency of the API which uses relative times everywhere else. Closes bug #191.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
2602
diff
changeset
|
117 |
m_stopEvent = Simulator::Schedule (stopTime, |
588
639ee55495ec
fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
587
diff
changeset
|
118 |
&Application::StopApplication, this); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
119 |
} |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
120 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
121 |
} //namespace ns3 |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
122 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
123 |