Files
unison/samples/sample-simulator.py

63 lines
1.9 KiB
Python
Raw Normal View History

2008-07-08 10:43:58 -07:00
# -*- Mode:Python; -*-
# /*
# * Copyright (c) 2010 INRIA
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License version 2 as
# * published by the Free Software Foundation;
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# *
# * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
# */
#
# Python version of sample-simulator.cc
2008-07-08 10:43:58 -07:00
import ns3 as ns
class MyModel(object):
def Start(self):
ns.Simulator.Schedule(ns.Seconds(10.0), self.HandleEvent, ns.Simulator.Now().GetSeconds())
2008-07-08 10:43:58 -07:00
def HandleEvent(self, value):
print "Member method received event at", ns.Simulator.Now().GetSeconds(), \
"s started at", value, "s"
2008-07-08 10:43:58 -07:00
def ExampleFunction(model):
print "ExampleFunction received event at", ns.Simulator.Now().GetSeconds(), "s"
2008-07-08 10:43:58 -07:00
model.Start()
def RandomFunction(model):
print "RandomFunction received event at", ns.Simulator.Now().GetSeconds(), "s"
def CancelledEvent():
print "I should never be called... "
2008-07-08 10:43:58 -07:00
def main(dummy_argv):
2008-07-08 10:43:58 -07:00
model = MyModel()
v = ns.UniformVariable(10,20)
ns.Simulator.Schedule(ns.Seconds(10.0), ExampleFunction, model)
ns.Simulator.Schedule(ns.Seconds(v.GetValue()), RandomFunction, model)
id = ns.Simulator.Schedule(ns.Seconds(30.0), CancelledEvent)
ns.Simulator.Cancel(id)
2008-07-08 10:43:58 -07:00
ns.Simulator.Run()
2008-07-08 10:43:58 -07:00
ns.Simulator.Destroy()
if __name__ == '__main__':
import sys
main(sys.argv)