diff options
author | Sander Vrijders <sander.vrijders@ugent.be> | 2018-03-26 12:11:32 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2018-03-27 15:24:50 +0200 |
commit | d8747a7b810421d4a1c5aa88e85012558890e577 (patch) | |
tree | d99f6bcdfabeff005ceb7b1f28ca095f3dcae5ab /rumba/storyboard.py | |
parent | 9e499fec0ca6e2940717bce45388c59960f9bdc3 (diff) | |
download | rumba-d8747a7b810421d4a1c5aa88e85012558890e577.tar.gz rumba-d8747a7b810421d4a1c5aa88e85012558890e577.zip |
storyboard: Add capturing of traffic
This adds the functionality to capture traffic on certain interfaces
so that it can be inspected with tools like wireshark. A user needs to
pass a start and end time and a node and DIF. Rumba will then
determine the correct interface to capture on.
Implements #41
Diffstat (limited to 'rumba/storyboard.py')
-rw-r--r-- | rumba/storyboard.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/rumba/storyboard.py b/rumba/storyboard.py index ea0c51e..61dd8cc 100644 --- a/rumba/storyboard.py +++ b/rumba/storyboard.py @@ -34,6 +34,7 @@ import math import os import random import time +import uuid import rumba.model as model import rumba.ssh_support as ssh_support @@ -821,6 +822,39 @@ class StoryBoard(SBEntity): buffer = StringIO(string) self.parse_script(buffer, clean) + def capture_traffic(self, start, end, node, dif): + """ + Captures the traffic of an interface on a certain node. + + :param start: The time to start capturing. + :param end: The time to stop capturing. + :param node: The node to capture on. + :param dif: The Shim Ethernet DIF of the node, Rumba + automatically resolves the correct interface. + """ + for ipcp in dif.ipcps: + if ipcp.node is not node: + continue + # In case tcpdump is not present, this assumes a testbed + # with Ubuntu/Debian just like the rest of installation + if not node.has_tcpdump: + ssh_support.aptitude_install(self.experiment.testbed, + node, ["tcpdump"]) + node.has_tcpdump = True + + # Create random string + pcap_file = node.name + '_' + dif.name + '_' + \ + 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)) class Event(object): |