3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
21 from nepi.execution.ec import ExperimentController
22 from nepi.execution.resource import ResourceAction, ResourceState
24 def add_node(ec, host, user):
25 node = ec.register_resource("LinuxNode")
26 ec.set(node, "hostname", host)
27 ec.set(node, "username", user)
28 ec.set(node, "cleanHome", True)
29 ec.set(node, "cleanProcesses", True)
32 def add_app(ec, command, node, sudo=None, video=None, depends=None, forward_x11=None, \
34 app = ec.register_resource("LinuxApplication")
36 ec.set(app, "sudo", sudo)
38 ec.set(app, "sources", video)
39 if depends is not None:
40 ec.set(app, "depends", depends)
41 if forward_x11 is not None:
42 ec.set(app, "forwardX11", forward_x11)
44 ec.set(app, "env", env)
45 ec.set(app, "command", command)
46 ec.register_connection(app, node)
49 exp_id = "transfer_file"
52 ec = ExperimentController(exp_id)
54 # PlanetLab choosen nodes for the experiment, change for PlanetLab nodes in your slice or
56 server_name = "planetlab2.ionio.gr"
57 client_name = "planetlab2.fri.uni-lj.si"
59 slicename = "inria_sfatest"
61 # Location of the video in local machine
62 video= "../big_buck_bunny_240p_mpeg4_lq.ts"
64 # Packets needed for running the experiment
65 depends_server = "pv nc tcpdump"
68 # Add resource managers for the linux nodes
69 server = add_node(ec, server_name, slicename)
70 client = add_node(ec, client_name, slicename)
72 # Add resource managers for the linux applications
73 app_server = add_app(ec, "cat ${SRC}/big_buck_bunny_240p_mpeg4_lq.ts | pv -fbt 2> \
74 bw.txt | nc %s 1234" % client_name, server, video=video, depends=depends_server)
76 # Note: is important to add the -d option in nc command to not attempt to read from the
78 # if not nc in the client side close the socket suddently if runned in background
79 app_client = add_app(ec, "nc -dl 1234 > big_buck_copied_movie.ts", client, \
80 depends=depends_client)
82 capture = add_app(ec, "tcpdump -ni eth0 -w video_transfer.pcap -s0 port 1234 2>&1", \
85 # Register conditions 1. nodes ; 2. start tcpdump capture ; 3. client listen port 1234 ;
86 # 4. server start sending video
87 ec.register_condition(app_server, ResourceAction.START, app_client, ResourceState.STARTED)
88 ec.register_condition(app_client, ResourceAction.START, capture, ResourceState.STARTED)
93 # Wait until the applications are finish to retrive the traces
94 ec.wait_finished([app_server, app_client])
96 bw = ec.trace(app_server, "bw.txt")
97 pcap = ec.trace(capture, "video_transfer.pcap")
99 # Choose a directory to store the traces, example f = open("/home/<user>/bw.txt", "w")
100 f = open("examples/linux/transfer/bw.txt", "w")
103 f = open("examples/linux/transfer/video_transfer.pcap", "w")