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/linux/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
39 usage = ("usage: %prog -a <hostname1> -b <hostname2> -u <username> -i <ssh-key>")
41 parser = OptionParser(usage = usage)
42 parser.add_option("-a", "--hostname1", dest="hostname1",
43 help="Remote host 1", type="str")
44 parser.add_option("-b", "--hostname2", dest="hostname2",
45 help="Remote host 2", type="str")
46 parser.add_option("-u", "--username", dest="username",
47 help="Username to SSH to remote host", type="str")
48 parser.add_option("-i", "--ssh-key", dest="ssh_key",
49 help="Path to private SSH key to be used for connection",
51 (options, args) = parser.parse_args()
53 hostname1 = options.hostname1
54 hostname2 = options.hostname2
55 username = options.username
56 ssh_key = options.ssh_key
58 ## Create the experiment controller
59 ec = ExperimentController(exp_id = "ccn_simple_transfer")
61 ##### CONFIGURING NODE 1
64 node1 = ec.register_resource("linux::Node")
65 # Set the hostname of the first node to use for the experiment
66 ec.set(node1, "hostname", hostname1)
67 # username should be your SSH user
68 ec.set(node1, "username", username)
69 # Absolute path to the SSH private key
70 ec.set(node1, "identity", ssh_key)
71 # Clean all files, results, etc, from previous experiments wit the same exp_id
72 ec.set(node1, "cleanExperiment", True)
73 # Kill all running processes in the node before running the experiment
74 ec.set(node1, "cleanProcesses", True)
76 ## Register a CCN daemon in node 1
77 ccnd1 = ec.register_resource("linux::CCND")
78 # Set ccnd log level to 7
79 ec.set(ccnd1, "debug", 7)
80 ec.register_connection(ccnd1, node1)
82 ## Register a repository in node 1
83 ccnr1 = ec.register_resource("linux::CCNR")
84 ec.register_connection(ccnr1, ccnd1)
86 ## Push the file into the repository
87 local_path_to_content = os.path.join(
88 os.path.dirname(os.path.realpath(__file__)),
89 "..", "big_buck_bunny_240p_mpeg4_lq.ts")
91 content_name = "ccnx:/test/FILE"
93 # Add a content to the repository
94 co = ec.register_resource("linux::CCNContent")
95 ec.set(co, "contentName", content_name)
96 # NEPI will upload the specified file to the remote node and write it
97 # into the CCN repository
98 ec.set(co, "content", local_path_to_content)
99 ec.register_connection(co, ccnr1)
101 ##### CONFIGURING NODE 2
104 node2 = ec.register_resource("linux::Node")
105 # Set the hostname of the first node to use for the experiment
106 ec.set(node2, "hostname", hostname2)
107 # username should be your SSH user
108 ec.set(node2, "username", username)
109 # Absolute path to the SSH private key
110 ec.set(node2, "identity", ssh_key)
111 # Clean all files, results, etc, from previous experiments wit the same exp_id
112 ec.set(node2, "cleanExperiment", True)
113 # Kill all running processes in the node before running the experiment
114 ec.set(node2, "cleanProcesses", True)
116 ## Register a CCN daemon in node 2
117 ccnd2 = ec.register_resource("linux::CCND")
118 # Set ccnd log level to 7
119 ec.set(ccnd2, "debug", 7)
120 ec.register_connection(ccnd2, node2)
122 ## Retrieve the file stored in node 1 from node 2
123 ccncat = ec.register_resource("linux::CCNCat")
124 ec.set(ccncat, "contentName", content_name)
125 ec.register_connection(ccncat, ccnd2)
127 ##### INTERCONNECTING CCN NODES ...
129 # Register a FIB entry from node 1 to node 2
130 entry1 = ec.register_resource("linux::FIBEntry")
131 ec.set(entry1, "host", hostname2)
132 ec.register_connection(entry1, ccnd1)
134 # Register a FIB entry from node 2 to node 1
135 entry2 = ec.register_resource("linux::FIBEntry")
136 ec.set(entry2, "host", hostname1)
137 ec.register_connection(entry2, ccnd2)
139 ##### STARTING THE EXPERIMENT
141 ## Deploy all resources
144 # Wait until the ccncat is finished
145 ec.wait_finished([ccncat])
147 stdout = ec.trace(ccncat, "stdout")
148 f = open("video.ts", "w")
154 print "Transfered FILE stored localy at video.ts"