This documentation is not the
Latest Release
.
A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
sample-simulator.py
Go to the documentation of this file.
1
# -*- Mode:Python; -*-
2
# /*
3
# * Copyright (c) 2010 INRIA
4
# *
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
7
# * published by the Free Software Foundation;
8
# *
9
# * This program is distributed in the hope that it will be useful,
10
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# * GNU General Public License for more details.
13
# *
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
16
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
# *
18
# * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
# */
20
#
21
# Python version of sample-simulator.cc
22
23
import
ns.core
24
25
class
MyModel
(object):
26
"""Simple model object to illustrate event handling."""
27
28
## \returns None.
29
def
Start
(self):
30
"""Start model execution by scheduling a HandleEvent."""
31
ns.core.Simulator.Schedule(ns.core.Seconds(10.0), self.
HandleEvent
, ns.core.Simulator.Now().GetSeconds())
32
33
## \param [in] value Event argument.
34
## \return None.
35
def
HandleEvent
(self, value):
36
"""Simple event handler."""
37
print
"Member method received event at"
, ns.core.Simulator.Now().GetSeconds(), \
38
"s started at"
, value,
"s"
39
40
def
ExampleFunction
(model):
41
print
"ExampleFunction received event at"
, ns.core.Simulator.Now().GetSeconds(),
"s"
42
model.Start()
43
44
def
RandomFunction
(model):
45
print
"RandomFunction received event at"
, ns.core.Simulator.Now().GetSeconds(),
"s"
46
47
def
CancelledEvent
():
48
print
"I should never be called... "
49
50
def
main(dummy_argv):
51
52
model =
MyModel
()
53
v = ns.core.UniformRandomVariable()
54
v.SetAttribute(
"Min"
, ns.core.DoubleValue (10))
55
v.SetAttribute(
"Max"
, ns.core.DoubleValue (20))
56
57
ns.core.Simulator.Schedule(ns.core.Seconds(10.0), ExampleFunction, model)
58
59
ns.core.Simulator.Schedule(ns.core.Seconds(v.GetValue()), RandomFunction, model)
60
61
id = ns.core.Simulator.Schedule(ns.core.Seconds(30.0), CancelledEvent)
62
ns.core.Simulator.Cancel(id)
63
64
ns.core.Simulator.Run()
65
66
ns.core.Simulator.Destroy()
67
68
if
__name__ ==
'__main__'
:
69
import
sys
70
main(sys.argv)
sample-simulator.RandomFunction
def RandomFunction(model)
Definition:
sample-simulator.py:44
sample-simulator.MyModel.Start
def Start(self)
Definition:
sample-simulator.py:29
sample-simulator.MyModel
Definition:
sample-simulator.py:25
sample-simulator.CancelledEvent
def CancelledEvent()
Definition:
sample-simulator.py:47
sample-simulator.MyModel.HandleEvent
def HandleEvent(self, value)
Definition:
sample-simulator.py:35
sample-simulator.ExampleFunction
def ExampleFunction(model)
Definition:
sample-simulator.py:40
src
core
examples
sample-simulator.py
Generated on Wed Nov 11 2015 20:00:27 for ns-3 by
1.8.9.1