diff options
author | Marco Capitani <m.capitani@nextworks.it> | 2018-03-28 15:46:38 +0200 |
---|---|---|
committer | Marco Capitani <m.capitani@nextworks.it> | 2018-03-28 16:30:06 +0200 |
commit | a95c3b376053ed00f0e7184dbd228598a9aaf50f (patch) | |
tree | 994e3ccbb7ce8baf08dc9b934c63beefa87215f5 /rumba/storyboard.py | |
parent | 9d42e50b99993c3fa5b9724c09dd28be4c528add (diff) | |
download | rumba-a95c3b376053ed00f0e7184dbd228598a9aaf50f.tar.gz rumba-a95c3b376053ed00f0e7184dbd228598a9aaf50f.zip |
model: make link quality changes scriptable
Added method accepting only ints and floats to allow
scripting link quality changes
(see example-script additions)
Also added general purpose `sb.schedule_action` method
Diffstat (limited to 'rumba/storyboard.py')
-rw-r--r-- | rumba/storyboard.py | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/rumba/storyboard.py b/rumba/storyboard.py index 9aff375..ba6883d 100644 --- a/rumba/storyboard.py +++ b/rumba/storyboard.py @@ -423,6 +423,39 @@ class StoryBoard(SBEntity): del self.server_apps[server.id] self._build_nodes_lists() + def schedule_action(self, + call, + args=None, + kwargs=None, + c_time=None, + trigger=None, + ev_id=None,): + """ + Calls a function with the specified triggers and arguments. + :param call: the function to run + :type call: function (methods included) + :param c_time: the function will not be called before `c_time` + seconds have passed + :type c_time: :py:class:`float` + :param trigger: the function must not be called before the event + `trigger` has completed + :type trigger: :py:class:`.Event` or :py:class:`str` + :param ev_id: the ID to assign to the generated event + :type ev_id: :py:class:`str` + :param args: arguments to pass to the function + :param kwargs: keyword arguments to be passed + :return: the event representing the calling of the function + :rtype: :py:class:`.Event` + """ + if args is None: + args = [] + if kwargs is None: + kwargs = {} + action = functools.partial(call, *args, **kwargs) + event = Event(action, ev_id=ev_id, ev_time=c_time, trigger=trigger) + self.add_event(event) + return event + def schedule_command(self, t, node, command): """ Schedules the given command to be run at t seconds from the start. @@ -846,14 +879,19 @@ class StoryBoard(SBEntity): str(uuid.uuid4())[0:4] + ".pcap" tcpd_client = Client(ap="tcpdump", options="-i %s -w %s" \ - % (ipcp.ifname, pcap_file)) - duration = end - start - cb = functools.partial(node.fetch_file, pcap_file, - self.experiment.log_dir, sudo=True) - action = functools.partial(self.run_client, tcpd_client, - duration=duration, node=node, - callback = cb) - self._script.add_event(Event(action, ev_time=start)) + % (ipcp.ifname, pcap_file))\ + .process(end-start, node, 'tcpdump_proc') + + self.schedule_action(tcpd_client.run, c_time=start) + end_event = self.schedule_action(tcpd_client.stop, c_time=end) + + self.schedule_action( + node.fetch_file, + args=[pcap_file, self.experiment.log_dir], + kwargs={'sudo': True}, + trigger=end_event + ) + class Event(object): |