LEFT | RIGHT |
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) 2012,2014 University of Zagreb | 3 * Copyright (c) 2012,2014 University of Zagreb |
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 * Author: Vedran Miletić <rivanvx@gmail.com> | 18 * Author: Vedran Miletić <rivanvx@gmail.com> |
19 */ | 19 */ |
20 | 20 |
21 #include "ns3/core-module.h" | 21 #include "ns3/core-module.h" |
22 #include "ns3/failure-repair-module.h" | 22 #include "ns3/failure-repair-module.h" |
23 | 23 |
24 using namespace ns3; | 24 using namespace ns3; |
25 | 25 |
26 class ExampleStartStopObject : public Object, public StartStopFunctionality | 26 class ExampleStartStopObject : public Object, public StopRestartFunctionality |
27 { | 27 { |
28 public: | 28 public: |
29 static TypeId GetTypeId (void) | 29 static TypeId GetTypeId (void) |
30 { | 30 { |
31 static TypeId tid = TypeId ("ns3::ExampleStartStopObject") | 31 static TypeId tid = TypeId ("ns3::ExampleStartStopObject") |
32 .SetParent<Object> () | 32 .SetParent<Object> () |
33 .AddConstructor<ExampleStartStopObject> () | 33 .AddConstructor<ExampleStartStopObject> () |
34 .AddTraceSource ("StartTrace", | 34 .AddTraceSource ("StartTrace", |
35 "Tracing change of object state to started", | 35 "Tracing change of object state to started", |
36 MakeTraceSourceAccessor (&ExampleStartStopObject::m
_startTrace)) | 36 MakeTraceSourceAccessor (&ExampleStartStopObject::m
_restartTrace), |
| 37 » » » » » » » "void") |
37 .AddTraceSource ("StopTrace", | 38 .AddTraceSource ("StopTrace", |
38 "Tracing change of object state to stop", | 39 "Tracing change of object state to stopped", |
39 MakeTraceSourceAccessor (&ExampleStartStopObject::m
_stopTrace)) | 40 MakeTraceSourceAccessor (&ExampleStartStopObject::m
_stopTrace), |
| 41 » » » » » » » "void") |
40 ; | 42 ; |
41 return tid; | 43 return tid; |
42 } | 44 } |
43 | 45 |
44 ExampleStartStopObject () | 46 ExampleStartStopObject () |
45 { | 47 { |
46 }; | 48 }; |
47 ~ExampleStartStopObject () | 49 ~ExampleStartStopObject () |
48 { | 50 { |
49 }; | 51 }; |
(...skipping 18 matching lines...) Expand all Loading... |
68 cmd.Parse (argc, argv); | 70 cmd.Parse (argc, argv); |
69 | 71 |
70 /* ... */ | 72 /* ... */ |
71 | 73 |
72 Ptr<ExampleStartStopObject> obj = CreateObject<ExampleStartStopObject> (); | 74 Ptr<ExampleStartStopObject> obj = CreateObject<ExampleStartStopObject> (); |
73 Ptr<FailureRepairModel> frm = CreateObject<FailureRepairModel> (); | 75 Ptr<FailureRepairModel> frm = CreateObject<FailureRepairModel> (); |
74 | 76 |
75 frm->SetAttribute ("NumberOfStateChanges", UintegerValue (50)); | 77 frm->SetAttribute ("NumberOfStateChanges", UintegerValue (50)); |
76 frm->SetAttribute ("RepairedStateDuration", StringValue ("ns3::ConstantRandomV
ariable[Constant=1.0]")); | 78 frm->SetAttribute ("RepairedStateDuration", StringValue ("ns3::ConstantRandomV
ariable[Constant=1.0]")); |
77 frm->SetAttribute ("FailedStateDuration", StringValue ("ns3::ConstantRandomVar
iable[Constant=1.0]")); | 79 frm->SetAttribute ("FailedStateDuration", StringValue ("ns3::ConstantRandomVar
iable[Constant=1.0]")); |
78 frm->AssociateObject (obj, MakeCallback (&ExampleStartStopObject::Start, obj),
MakeCallback (&ExampleStartStopObject::Stop, obj)); | 80 frm->AssociateObject (obj, MakeCallback (&ExampleStartStopObject::Restart, obj
), MakeCallback (&ExampleStartStopObject::Stop, obj)); |
79 ·· | 81 ·· |
80 FailureRepairTimeTrackerContainer a; | 82 FailureRepairTimeTrackerContainer a; |
81 a.Create (1); | 83 a.Create (1); |
82 a.Get (0)->AssociateObject (obj, "StartTrace", "StopTrace"); | 84 a.Get (0)->AssociateObject (obj, "StartTrace", "StopTrace"); |
83 | 85 |
84 Simulator::Schedule (Seconds (1.1), &PrintObjectStatus, obj); | 86 Simulator::Schedule (Seconds (1.1), &PrintObjectStatus, obj); |
85 Simulator::Schedule (Seconds (2.1), &PrintObjectStatus, obj); | 87 Simulator::Schedule (Seconds (2.1), &PrintObjectStatus, obj); |
86 Simulator::Schedule (Seconds (3.1), &PrintObjectStatus, obj); | 88 Simulator::Schedule (Seconds (3.1), &PrintObjectStatus, obj); |
87 Simulator::Schedule (Seconds (4.1), &PrintObjectStatus, obj); | 89 Simulator::Schedule (Seconds (4.1), &PrintObjectStatus, obj); |
88 Simulator::Schedule (Seconds (5.1), &PrintObjectStatus, obj); | 90 Simulator::Schedule (Seconds (5.1), &PrintObjectStatus, obj); |
89 | 91 |
90 Simulator::Run (); | 92 Simulator::Run (); |
91 Simulator::Destroy (); | 93 Simulator::Destroy (); |
92 ·· | 94 ·· |
93 NS_LOG_UNCOND (a.Get (0)->GetTotalTimeStarted ()); | 95 NS_LOG_UNCOND (a.Get (0)->GetTotalTimeStarted ()); |
94 NS_LOG_UNCOND (a.Get (0)->GetTotalTimeStopped ()); | 96 NS_LOG_UNCOND (a.Get (0)->GetTotalTimeStopped ()); |
95 return 0; | 97 return 0; |
96 } | 98 } |
LEFT | RIGHT |