2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
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;
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 # Example of how to run this experiment (replace with your information):
23 # python examples/planetlab/ccn_simple_transfer.py -a <hostname1> -b <hostname2> -u <username> -i <ssh-key>
30 # Linux host Linux host
31 # 0 ------- network -------- 1
34 from nepi.execution.ec import ExperimentController
36 from optparse import OptionParser, SUPPRESS_HELP
39 usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
40 "-k <pl-ssh-key> -a <hostanme1> -b <hostname2> ")
42 parser = OptionParser(usage = usage)
43 parser.add_option("-s", "--pl-slice", dest="pl_slice",
44 help="PlanetLab slicename", type="str")
45 parser.add_option("-u", "--pl-user", dest="pl_user",
46 help="PlanetLab web username", type="str")
47 parser.add_option("-p", "--pl-password", dest="pl_password",
48 help="PlanetLab web password", type="str")
49 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
50 help="Path to private SSH key associated with the PL account",
52 parser.add_option("-a", "--hostname1", dest="hostname1",
53 help="Remote host 1", type="str")
54 parser.add_option("-b", "--hostname2", dest="hostname2",
55 help="Remote host 2", type="str")
56 (options, args) = parser.parse_args()
58 hostname1 = options.hostname1
59 hostname2 = options.hostname2
60 pl_slice = options.pl_slice
61 pl_ssh_key = options.pl_ssh_key
62 pl_user = options.pl_user
63 pl_password = options.pl_password
65 ## Create the experiment controller
66 ec = ExperimentController(exp_id = "pl_ccn_simple_transfer")
68 ##### CONFIGURING NODE 1
71 node1 = ec.register_resource("planetlab::Node")
72 # Set the hostname of the first node to use for the experiment
73 ec.set(node1, "hostname", hostname1)
74 # username should be your SSH user
75 ec.set(node1, "username", pl_slice)
76 # Path to the SSH private key
77 ec.set(node1, "identity", pl_ssh_key)
78 # Planetlab web site user and password
79 ec.set(node1, "pluser", pl_user)
80 ec.set(node1, "plpassword", pl_password)
81 # Clean all files, results, etc, from previous experiments wit the same exp_id
82 ec.set(node1, "cleanExperiment", True)
83 # Kill all running processes in the node before running the experiment
84 ec.set(node1, "cleanProcesses", True)
86 ## Register a CCN daemon in node 1
87 ccnd1 = ec.register_resource("linux::CCND")
88 # Set ccnd log level to 7
89 ec.set(ccnd1, "debug", 7)
90 ec.register_connection(ccnd1, node1)
92 ## Register a repository in node 1
93 ccnr1 = ec.register_resource("linux::CCNR")
94 ec.register_connection(ccnr1, ccnd1)
96 ## Push the file into the repository
97 local_path_to_content = os.path.join(
98 os.path.dirname(os.path.realpath(__file__)),
99 "..", "big_buck_bunny_240p_mpeg4_lq.ts")
101 content_name = "ccnx:/test/FILE"
103 # Add a content to the repository
104 co = ec.register_resource("linux::CCNContent")
105 ec.set(co, "contentName", content_name)
106 # NEPI will upload the specified file to the remote node and write it
107 # into the CCN repository
108 ec.set(co, "content", local_path_to_content)
109 ec.register_connection(co, ccnr1)
111 ##### CONFIGURING NODE 2
114 node2 = ec.register_resource("planetlab::Node")
115 # Set the hostname of the first node to use for the experiment
116 ec.set(node2, "hostname", hostname2)
117 # username should be your SSH user
118 ec.set(node2, "username", pl_slice)
119 # Path to the SSH private key
120 ec.set(node2, "identity", pl_ssh_key)
121 # Planetlab web site user and password
122 ec.set(node2, "pluser", pl_user)
123 ec.set(node2, "plpassword", pl_password)
124 # Clean all files, results, etc, from previous experiments wit the same exp_id
125 ec.set(node2, "cleanExperiment", True)
126 # Kill all running processes in the node before running the experiment
127 ec.set(node2, "cleanProcesses", True)
129 ## Register a CCN daemon in node 2
130 ccnd2 = ec.register_resource("linux::CCND")
131 # Set ccnd log level to 7
132 ec.set(ccnd2, "debug", 7)
133 ec.register_connection(ccnd2, node2)
135 ## Retrieve the file stored in node 1 from node 2
136 ccncat = ec.register_resource("linux::CCNCat")
137 ec.set(ccncat, "contentName", content_name)
138 ec.register_connection(ccncat, ccnd2)
140 ##### INTERCONNECTING CCN NODES ...
142 # Register a FIB entry from node 1 to node 2
143 entry1 = ec.register_resource("linux::FIBEntry")
144 ec.set(entry1, "host", hostname2)
145 ec.register_connection(entry1, ccnd1)
147 # Register a FIB entry from node 2 to node 1
148 entry2 = ec.register_resource("linux::FIBEntry")
149 ec.set(entry2, "host", hostname1)
150 ec.register_connection(entry2, ccnd2)
152 ##### STARTING THE EXPERIMENT
154 ## Deploy all resources
157 # Wait until the ccncat is finished
158 ec.wait_finished([ccncat])
160 stdout = ec.trace(ccncat, "stdout")
161 f = open("video.ts", "w")
167 print "Transfered FILE stored localy at video.ts"