OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2014 University of Washington | 3 * Copyright (c) 2014 University of Washington |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 */ | 17 */ |
18 | 18 |
19 // | 19 // |
20 // This example is designed to show the main features of an ns3::TimeProbe. | 20 // This example is designed to show the main features of an ns3::TimeProbe. |
21 // A test object is used to emit values through a trace source. The | 21 // A test object is used to emit values through a trace source. The |
22 // example shows three ways to use a ns3::TimeProbe to hook the output | 22 // example shows three ways to use a ns3::TimeProbe to hook the output |
23 // of this trace source (in addition to hooking the raw trace source). | 23 // of this trace source (in addition to hooking the raw trace source). |
24 // | 24 // |
25 // It produces two types of output. By default, it will generate a | 25 // It produces two types of output. By default, it will generate a |
26 // gnuplot of interarrival times. If the '--verbose=1' argument is passed, | 26 // gnuplot of interarrival times. If the '--verbose=1' argument is passed, |
27 // it will also generate debugging output of the form (for example): | 27 // it will also generate debugging output of the form (for example): |
28 // | 28 // |
29 // Emitting at 96.5378 seconds | 29 // Emitting at 96.5378 seconds |
30 // context: raw trace source old 0.293343 new 0.00760254 | 30 // context: raw trace source old 0.293343 new 0.00760254 |
31 // context: probe1 old 0.293343 new 0.00760254 | 31 // context: probe1 old 0.293343 new 0.00760254 |
32 // context: probe2 old 0.293343 new 0.00760254 | 32 // context: probe2 old 0.293343 new 0.00760254 |
33 // context: probe3 old 0.293343 new 0.00760254 | 33 // context: probe3 old 0.293343 new 0.00760254 |
34 // | 34 // |
35 // The stopTime defaults to 100 seconds but can be changed by an argument. | 35 // The stopTime defaults to 100 seconds but can be changed by an argument. |
36 // | 36 // |
37 | 37 |
38 #include <string> | 38 #include <string> |
39 | 39 |
40 #include "ns3/core-module.h" | 40 #include "ns3/core-module.h" |
41 #include "ns3/time-probe.h" | 41 #include "ns3/time-probe.h" |
42 #include "ns3/gnuplot-helper.h" | 42 #include "ns3/gnuplot-helper.h" |
43 | 43 |
44 using namespace ns3; | 44 using namespace ns3; |
45 | 45 |
46 NS_LOG_COMPONENT_DEFINE ("TimeProbeExample"); | 46 NS_LOG_COMPONENT_DEFINE ("TimeProbeExample"); |
47 | 47 |
48 // | 48 // |
49 // This is our test object, an object that emits values according to | 49 // This is our test object, an object that emits values according to |
50 // a Poisson arrival process. It emits a traced Time value as a | 50 // a Poisson arrival process. It emits a traced Time value as a |
51 // trace source; this takes the value of interarrival time | 51 // trace source; this takes the value of interarrival time |
52 // | 52 // |
53 class Emitter : public Object | 53 class Emitter : public Object |
54 { | 54 { |
55 public: | 55 public: |
56 /** | 56 /** |
57 * Register this type. | 57 * Register this type. |
58 * \return The TypeId. | 58 * \return The TypeId. |
59 */ | 59 */ |
60 static TypeId GetTypeId (void); | 60 static TypeId GetTypeId (void); |
61 Emitter (); | 61 Emitter (); |
62 private: | 62 private: |
63 void DoInitialize (void); | 63 void DoInitialize (void); |
64 // void Emit (void); | 64 // void Emit (void); |
65 void Emit (void); | 65 void Emit (void); |
66 | 66 |
67 TracedValue<Time> m_interval; | 67 TracedValue<Time> m_interval; |
68 Time m_last; | 68 Time m_last; |
69 Ptr<ExponentialRandomVariable> m_var; | 69 Ptr<ExponentialRandomVariable> m_var; |
70 }; | 70 }; |
71 | 71 |
72 NS_OBJECT_ENSURE_REGISTERED (Emitter); | 72 NS_OBJECT_ENSURE_REGISTERED (Emitter); |
73 | 73 |
74 TypeId | 74 TypeId |
75 Emitter::GetTypeId (void) | 75 Emitter::GetTypeId (void) |
76 { | 76 { |
77 static TypeId tid = TypeId ("ns3::Emitter") | 77 static TypeId tid = TypeId ("ns3::Emitter") |
78 .SetParent<Object> () | 78 .SetParent<Object> () |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 BooleanValue verbose; | 116 BooleanValue verbose; |
117 GlobalValue::GetValueByName ("verbose", verbose); | 117 GlobalValue::GetValueByName ("verbose", verbose); |
118 if (verbose.Get ()) | 118 if (verbose.Get ()) |
119 { | 119 { |
120 std::cout << "context: " << context << " old " << oldVal.GetSeconds () <<
" new " << newVal.GetSeconds () << std::endl; | 120 std::cout << "context: " << context << " old " << oldVal.GetSeconds () <<
" new " << newVal.GetSeconds () << std::endl; |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 // This is a function to test hooking it to the probe output | 124 // This is a function to test hooking it to the probe output |
125 void | 125 void |
126 NotifyViaProbe (std::string context, double oldVal, double newVal) | 126 NotifyViaProbe (std::string context, Time oldVal, Time newVal) |
127 { | 127 { |
128 BooleanValue verbose; | 128 BooleanValue verbose; |
129 GlobalValue::GetValueByName ("verbose", verbose); | 129 GlobalValue::GetValueByName ("verbose", verbose); |
130 if (verbose.Get ()) | 130 if (verbose.Get ()) |
131 { | 131 { |
132 std::cout << "context: " << context << " old " << oldVal << " new " << new
Val << std::endl; | 132 std::cout << "context: " << context << " old " << oldVal.GetSeconds () <<
" new " << newVal.GetSeconds () << std::endl; |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 static ns3::GlobalValue g_verbose ("verbose", | 136 static ns3::GlobalValue g_verbose ("verbose", |
137 "Whether to enable verbose output", | 137 "Whether to enable verbose output", |
138 ns3::BooleanValue (false), | 138 ns3::BooleanValue (false), |
139 ns3::MakeBooleanChecker ()); | 139 ns3::MakeBooleanChecker ()); |
140 | 140 |
141 int main (int argc, char *argv[]) | 141 int main (int argc, char *argv[]) |
142 { | 142 { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 GnuplotHelper plotHelper; | 228 GnuplotHelper plotHelper; |
229 plotHelper.ConfigurePlot ("time-probe-example", | 229 plotHelper.ConfigurePlot ("time-probe-example", |
230 "Emitter interarrivals vs. Time", | 230 "Emitter interarrivals vs. Time", |
231 "Simulation time (Seconds)", | 231 "Simulation time (Seconds)", |
232 "Interarrival time (Seconds)", | 232 "Interarrival time (Seconds)", |
233 "png"); | 233 "png"); |
234 | 234 |
235 // Helper creates a TimeProbe and hooks it to the /Names/Emitter/Interval | 235 // Helper creates a TimeProbe and hooks it to the /Names/Emitter/Interval |
236 // source. Helper also takes the Output of the TimeProbe and plots it | 236 // source. Helper also takes the Output of the TimeProbe and plots it |
237 // as a dataset labeled 'Emitter Interarrival Time' | 237 // as a dataset labeled 'Emitter Interarrival Time' |
238 plotHelper.PlotProbe ("ns3::TimeProbe", | 238 plotHelper.AddProbe ("ns3::TimeProbe", |
239 "/Names/Emitter/Interval", | 239 "/Names/Emitter/Interval", |
240 "Output", | 240 "Output", |
241 "Emitter Interarrival Time", | 241 "Emitter Interarrival Time"); |
242 GnuplotAggregator::KEY_INSIDE); | |
243 | 242 |
244 // The Emitter object is not associated with an ns-3 node, so | 243 // The Emitter object is not associated with an ns-3 node, so |
245 // it won't get started automatically, so we need to do this ourselves | 244 // it won't get started automatically, so we need to do this ourselves |
246 Simulator::Schedule (Seconds (0.0), &Emitter::Initialize, emitter); | 245 Simulator::Schedule (Seconds (0.0), &Emitter::Initialize, emitter); |
247 | 246 |
248 Simulator::Stop (Seconds (stopTime)); | 247 Simulator::Stop (Seconds (stopTime)); |
249 Simulator::Run (); | 248 Simulator::Run (); |
250 Simulator::Destroy (); | 249 Simulator::Destroy (); |
251 | 250 |
252 return 0; | 251 return 0; |
253 } | 252 } |
OLD | NEW |