-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.timer.html
More file actions
409 lines (326 loc) · 17.4 KB
/
Copy pathnode.timer.html
File metadata and controls
409 lines (326 loc) · 17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>node.timer module — PyMoSim v0.8 Manual</title>
<link href="_static/css/theme.css" rel="stylesheet" />
<link href="_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />
<link rel="stylesheet"
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/basic.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
<link rel="preload" as="script" href="_static/js/index.1c5a1a01449ed65a7b51.js">
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="node.type module" href="node.type.html" />
<link rel="prev" title="node.routemobi module" href="node.routemobi.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<div class="container-fluid" id="banner"></div>
<nav class="navbar navbar-light navbar-expand-lg bg-light fixed-top bd-navbar" id="navbar-main"><div class="container-xl">
<div id="navbar-start">
<a class="navbar-brand" href="index.html">
<img src="_static/icon.png" class="logo" alt="logo">
</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapsible" aria-controls="navbar-collapsible" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar-collapsible" class="col-lg-9 collapse navbar-collapse">
<div id="navbar-center" class="mr-auto">
<div class="navbar-center-item">
<ul id="navbar-main-elements" class="navbar-nav">
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="comm.html">
comm package
</a>
</li>
<li class="toctree-l1 current active nav-item">
<a class="reference internal nav-link" href="node.html">
node package
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="sim.html">
sim package
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="map.html">
map package
</a>
</li>
</ul>
</div>
</div>
<div id="navbar-end">
<div class="navbar-end-item">
<form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" >
</form>
</div>
<div class="navbar-end-item">
<ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
<li class="nav-item">
<a class="nav-link" href="https://github.com/cfoh/pymosim" rel="noopener" target="_blank" title="GitHub">
<span><i class="fab fa-github-square"></i></span>
<label class="sr-only">GitHub</label>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
<div class="container-xl">
<div class="row">
<!-- Only show if we have sidebars configured, else just a small margin -->
<div class="col-12 col-md-3 bd-sidebar"><form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="node.draw.html">
node.draw module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="node.mobility.html">
node.mobility module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="node.mobility2.html">
node.mobility2 module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="node.mobility2b.html">
node.mobility2b module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="node.mobility3.html">
node.mobility3 module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="node.node.html">
node.node module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="node.obstacle.html">
node.obstacle module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="node.routemobi.html">
node.routemobi module
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
node.timer module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="node.type.html">
node.type module
</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="d-none d-xl-block col-xl-2 bd-toc">
<div class="toc-item">
<nav id="bd-toc-nav">
</nav>
</div>
<div class="toc-item">
</div>
</div>
<main class="col-12 col-md-9 col-xl-7 py-md-5 pl-md-5 pr-md-4 bd-content" role="main">
<div>
<div class="section" id="module-node.timer">
<span id="node-timer-module"></span><h1>node.timer module<a class="headerlink" href="#module-node.timer" title="Permalink to this headline">¶</a></h1>
<p>Module <cite>timer</cite> contains <a class="reference internal" href="#node.timer.NodeTimer" title="node.timer.NodeTimer"><code class="xref py py-class docutils literal notranslate"><span class="pre">node.timer.NodeTimer</span></code></a> class which allows nodes
to create timers. Creating a timer from a node is simple, the following is an example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1">## create a timer within a node</span>
<span class="n">my_node</span><span class="o">.</span><span class="n">timer</span> <span class="o">=</span> <span class="n">NodeTimer</span><span class="p">(</span><span class="n">my_node</span><span class="p">,</span> <span class="n">duration</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="n">my_node</span><span class="o">.</span><span class="n">timer</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="o">...</span>
<span class="c1">## in own Scenario class, on_event() callback</span>
<span class="k">def</span> <span class="nf">on_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sim_time</span><span class="p">,</span> <span class="n">event_obj</span><span class="p">):</span>
<span class="k">if</span> <span class="n">event_obj</span><span class="o">==</span><span class="n">Event</span><span class="o">.</span><span class="n">TIMER_EXPIRED</span><span class="p">:</span> <span class="c1"># a timer expired?</span>
<span class="n">this_node</span> <span class="o">=</span> <span class="n">event_obj</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"node"</span><span class="p">)</span> <span class="c1"># get the node that started the timer</span>
<span class="n">the_timer</span> <span class="o">=</span> <span class="n">event_obj</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"timer"</span><span class="p">)</span> <span class="c1"># get the timer instance if needed</span>
<span class="c1"># then do something...</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p>Created by: CH Foh (2021)</p></li>
</ul>
</div>
<dl class="py class">
<dt id="node.timer.NodeTimer">
<em class="property">class </em><code class="sig-prename descclassname">node.timer.</code><code class="sig-name descname">NodeTimer</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">node</span></em>, <em class="sig-param"><span class="n">duration</span></em><span class="sig-paren">)</span><a class="headerlink" href="#node.timer.NodeTimer" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>This is the class specifying a node timer. A timer is in an
idle state when created. Use start() method to trigger
the timer, and the timer transits to running state. Use
is_running() method to check if the timer is still running.
Once expired, the timer will transit back to idle state.
To stop a running timer, use kill() method to force the
timer to transit to killed state. While a killed timer is
still running, it will automatically return back to idle state
when it expires, and will not trigger an event since the
timer is already killed.</p>
<p class="rubric">Methods</p>
<table class="longtable table autosummary">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#node.timer.NodeTimer.get_hosting_node" title="node.timer.NodeTimer.get_hosting_node"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_hosting_node</span></code></a>()</p></td>
<td><p>Use this method to return the node that hosts this timer.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#node.timer.NodeTimer.is_killed" title="node.timer.NodeTimer.is_killed"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_killed</span></code></a>()</p></td>
<td><p>Use this method to check if this timer is killed.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#node.timer.NodeTimer.is_running" title="node.timer.NodeTimer.is_running"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_running</span></code></a>()</p></td>
<td><p>Use this method to check if this timer is currently running.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#node.timer.NodeTimer.kill" title="node.timer.NodeTimer.kill"><code class="xref py py-obj docutils literal notranslate"><span class="pre">kill</span></code></a>()</p></td>
<td><p>Use this method to kill a running timer.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#node.timer.NodeTimer.sim__set_running_flag" title="node.timer.NodeTimer.sim__set_running_flag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sim__set_running_flag</span></code></a>(running_flag)</p></td>
<td><p>This method is used by simulation engine to set the running flag.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#node.timer.NodeTimer.start" title="node.timer.NodeTimer.start"><code class="xref py py-obj docutils literal notranslate"><span class="pre">start</span></code></a>([delay])</p></td>
<td><p>Use this method to start this timer.</p></td>
</tr>
</tbody>
</table>
<dl class="py method">
<dt id="node.timer.NodeTimer.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">node</span></em>, <em class="sig-param"><span class="n">duration</span></em><span class="sig-paren">)</span><a class="headerlink" href="#node.timer.NodeTimer.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the default constructor.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl>
<dt><strong>node</strong><span class="classifier"><a class="reference internal" href="node.node.html#node.node.BaseNode" title="node.node.BaseNode"><code class="xref py py-class docutils literal notranslate"><span class="pre">node.node.BaseNode</span></code></a> subclass</span></dt><dd><p>The node that hosts this timer.</p>
</dd>
<dt><strong>duration</strong><span class="classifier">float</span></dt><dd><p>The run duration of this timer.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="node.timer.NodeTimer.start">
<code class="sig-name descname">start</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">delay</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="headerlink" href="#node.timer.NodeTimer.start" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this method to start this timer. A killed timer can be restarted
by using this method.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>delay</strong><span class="classifier">float, optional, default=0</span></dt><dd><p>Specify a delay start.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="node.timer.NodeTimer.get_hosting_node">
<code class="sig-name descname">get_hosting_node</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#node.timer.NodeTimer.get_hosting_node" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this method to return the node that hosts this timer.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><dl class="simple">
<dt>node.node.BaseNode subclass</dt><dd><p>It returns the node instance hosting this timer.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="node.timer.NodeTimer.kill">
<code class="sig-name descname">kill</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#node.timer.NodeTimer.kill" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this method to kill a running timer. To be effective, this method
must be called before the timer has expired. When a timer is started,
a corresponding process is scheduled in the event queue.
Killing the timer won’t remove the process from the event queue.
Internally, the method will set a flag in this class indicating that the
timer is killed. Once the corresponding process is called, if the timer
is killed, the event simply stops relaying the event to the user
simulation to achieve the same effect of getting the timer killed.</p>
</dd></dl>
<dl class="py method">
<dt id="node.timer.NodeTimer.is_killed">
<code class="sig-name descname">is_killed</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#node.timer.NodeTimer.is_killed" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this method to check if this timer is killed.</p>
</dd></dl>
<dl class="py method">
<dt id="node.timer.NodeTimer.is_running">
<code class="sig-name descname">is_running</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#node.timer.NodeTimer.is_running" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this method to check if this timer is currently running.</p>
</dd></dl>
<dl class="py method">
<dt id="node.timer.NodeTimer.sim__set_running_flag">
<code class="sig-name descname">sim__set_running_flag</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">running_flag</span></em><span class="sig-paren">)</span><a class="headerlink" href="#node.timer.NodeTimer.sim__set_running_flag" title="Permalink to this definition">¶</a></dt>
<dd><p>This method is used by simulation engine to set the running flag.
It should not be used by user simulation.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>running_flag</strong><span class="classifier">bool</span></dt><dd><p>The the running flag.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
</div>
</main>
</div>
</div>
<script src="_static/js/index.1c5a1a01449ed65a7b51.js"></script>
<footer class="footer mt-5 mt-md-0">
<div class="container">
<div class="footer-item">
<p class="copyright">
© Copyright 2021, cfoh.<br/>
</p>
</div>
<div class="footer-item">
<p class="sphinx-version">
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 3.4.3.<br/>
</p>
</div>
</div>
</footer>
</body>
</html>