#
# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
#
-# Instructions to run this example:
-#
-# 1. First edit the script file where required (See ASSING messages)
-#
-# 2. Then, run the script:
+
+# Example of how to run this experiment (replace with your information):
#
# $ cd <path-to-nepi>
-# $ PYTHONPATH=$PYTHONPATHS:src python examples/linux/ccn/two_nodes_file_retrieval.py
+# python examples/planetlab/ccn_simple_transfer.py -a <hostname1> -b <hostname2> -u <username> -i <ssh-key>
+
+# CCN topology:
+#
+#
+#
+# content ccncat
+# Linux host Linux host
+# 0 ------- network -------- 1
#
from nepi.execution.ec import ExperimentController
+from optparse import OptionParser, SUPPRESS_HELP
import os
-pl_user = ######### <<< ASSIGN the username used to login to the PlanetLab website >>>
-pl_pass = ######## <<< ASSIGN the password used to login to the PlanetLab website >>>
-pl_ssh_key = ####### <<< ASSING the absolute path to the private SSH key used for Planetlab >>>
-slicename = ####### <<< ASSING the PlanetLab slicename >>>
-
-results_dir = "/tmp/demo_CCN_results"
+usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
+ "-k <pl-ssh-key> -a <hostanme1> -b <hostname2> ")
+
+parser = OptionParser(usage = usage)
+parser.add_option("-s", "--pl-slice", dest="pl_slice",
+ help="PlanetLab slicename", type="str")
+parser.add_option("-u", "--pl-user", dest="pl_user",
+ help="PlanetLab web username", type="str")
+parser.add_option("-p", "--pl-password", dest="pl_password",
+ help="PlanetLab web password", type="str")
+parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
+ help="Path to private SSH key associated with the PL account",
+ type="str")
+parser.add_option("-a", "--hostname1", dest="hostname1",
+ help="Remote host 1", type="str")
+parser.add_option("-b", "--hostname2", dest="hostname2",
+ help="Remote host 2", type="str")
+(options, args) = parser.parse_args()
+
+hostname1 = options.hostname1
+hostname2 = options.hostname2
+pl_slice = options.pl_slice
+pl_ssh_key = options.pl_ssh_key
+pl_user = options.pl_user
+pl_password = options.pl_password
## Create the experiment controller
-ec = ExperimentController(exp_id = "demo_CCN",
- local_dir = results_dir)
+ec = ExperimentController(exp_id = "pl_ccn_simple_transfer")
+
+##### CONFIGURING NODE 1
## Register node 1
node1 = ec.register_resource("PlanetlabNode")
-# Configure NEPI to automatically find and allocate a node in France
-# ec.set(node1, "country", "France")
-# Else, if you want a node in particular set the hostname
-ec.set(node1, "hostname", "peeramidion.irisa.fr")
-# PlanetLab (website) account username
-ec.set(node1, "pluser", pl_user)
-# PlanetLab (website) account password
-ec.set(node1, "plpassword", pl_pass)
-# username should be your PlanetLab slice name
-ec.set(node1, "username", slicename)
-# Absolute path to the SSH private key for PlanetLab
+# Set the hostname of the first node to use for the experiment
+ec.set(node1, "hostname", hostname1)
+# username should be your SSH user
+ec.set(node1, "username", pl_slice)
+# Path to the SSH private key
ec.set(node1, "identity", pl_ssh_key)
+# Planetlab web site user and password
+ec.set(node1, "pluser", pl_user)
+ec.set(node1, "plpassword", pl_password)
# Clean all files, results, etc, from previous experiments wit the same exp_id
ec.set(node1, "cleanExperiment", True)
-# Kill all running processes in the PlanetLab node before running the experiment
+# Kill all running processes in the node before running the experiment
ec.set(node1, "cleanProcesses", True)
-## Register node 2
-node2 = ec.register_resource("PlanetlabNode")
-# Configure NEPI to automatically find and allocate a node in Spain
-#ec.set(node2, "country", "Spain")
-# Else, if you want a node in particular set the hostname
-ec.set(node2, "hostname", "planetlab2.upc.es")
-# PlanetLab (website) account username
-ec.set(node2, "pluser", pl_user)
-# PlanetLab (website) account password
-ec.set(node2, "plpassword", pl_pass)
-# username should be your PlanetLab slice name
-ec.set(node2, "username", slicename)
-# Absolute path to the SSH private key for PlanetLab
-ec.set(node2, "identity", pl_ssh_key)
-# Clean all files, results, etc, from previous experiments wit the same exp_id
-ec.set(node2, "cleanExperiment", True)
-# Kill all running processes in the PlanetLab node before running the experiment
-ec.set(node2, "cleanProcesses", True)
-
## Register a CCN daemon in node 1
ccnd1 = ec.register_resource("LinuxCCND")
# Set ccnd log level to 7
ec.set(ccnd1, "debug", 7)
ec.register_connection(ccnd1, node1)
-## Register a CCN daemon in node 2
-ccnd2 = ec.register_resource("LinuxCCND")
-# Set ccnd log level to 7
-ec.set(ccnd2, "debug", 7)
-ec.register_connection(ccnd2, node2)
-
## Register a repository in node 1
ccnr1 = ec.register_resource("LinuxCCNR")
ec.register_connection(ccnr1, ccnd1)
## Push the file into the repository
local_path_to_content = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
- "..", "..",
- "big_buck_bunny_240p_mpeg4_lq.ts")
+ "..", "big_buck_bunny_240p_mpeg4_lq.ts")
+
+content_name = "ccnx:/test/FILE"
+# Add a content to the repository
co = ec.register_resource("LinuxCCNContent")
-ec.set(co, "contentName", "ccnx:/test/FILE1")
+ec.set(co, "contentName", content_name)
# NEPI will upload the specified file to the remote node and write it
# into the CCN repository
ec.set(co, "content", local_path_to_content)
ec.register_connection(co, ccnr1)
-## Deploy all resources
-ec.deploy()
+##### CONFIGURING NODE 2
-## Wait until node 1 and 2 are deployed, so we can retrieve the hostnames
-## of the nodes automatically allocated in planetlab
-ec.wait_deployed([node1, node2])
+## Register node 2
+node2 = ec.register_resource("PlanetlabNode")
+# Set the hostname of the first node to use for the experiment
+ec.set(node2, "hostname", hostname2)
+# username should be your SSH user
+ec.set(node2, "username", pl_slice)
+# Path to the SSH private key
+ec.set(node2, "identity", pl_ssh_key)
+# Planetlab web site user and password
+ec.set(node2, "pluser", pl_user)
+ec.set(node2, "plpassword", pl_password)
+# Clean all files, results, etc, from previous experiments wit the same exp_id
+ec.set(node2, "cleanExperiment", True)
+# Kill all running processes in the node before running the experiment
+ec.set(node2, "cleanProcesses", True)
-## Get the hostnames of the two PlanetLab nodes
-hostname1 = ec.get(node1, "hostname")
-print "hostname 1: ", hostname1
-hostname2 = ec.get(node2, "hostname")
-print "hostname 2: ", hostname2
+## Register a CCN daemon in node 2
+ccnd2 = ec.register_resource("LinuxCCND")
+# Set ccnd log level to 7
+ec.set(ccnd2, "debug", 7)
+ec.register_connection(ccnd2, node2)
+
+## Retrieve the file stored in node 1 from node 2
+ccncat = ec.register_resource("LinuxCCNCat")
+ec.set(ccncat, "contentName", content_name)
+ec.register_connection(ccncat, ccnd2)
+
+##### INTERCONNECTING CCN NODES ...
# Register a FIB entry from node 1 to node 2
entry1 = ec.register_resource("LinuxFIBEntry")
ec.set(entry1, "host", hostname2)
ec.register_connection(entry1, ccnd1)
-# Register a FIB entry from node 1 to node 2
+# Register a FIB entry from node 2 to node 1
entry2 = ec.register_resource("LinuxFIBEntry")
ec.set(entry2, "host", hostname1)
ec.register_connection(entry2, ccnd2)
-## Retrieve the file stored in node 1 from node 2
-command = "ccncat ccnx:/test/FILE1"
-app = ec.register_resource("LinuxCCNApplication")
-ec.set(app, "command", command)
-ec.register_connection(app, ccnd2)
-
-# Register a collector to automatically collect the ccnd logs
-# to a local directory
-col1 = ec.register_resource("Collector")
-ec.set(col1, "traceName", "stderr")
-ec.set(col1, "subDir", hostname1)
-ec.register_connection(col1, ccnd1)
-
-col2 = ec.register_resource("Collector")
-ec.set(col2, "traceName", "stderr")
-ec.set(col2, "subDir", hostname2)
-ec.register_connection(col2, ccnd2)
-
-## Deploy the rest of the resources
-ec.deploy(guids=[entry1, entry2, app, col1, col2])
+##### STARTING THE EXPERIMENT
+
+## Deploy all resources
+ec.deploy()
# Wait until the ccncat is finished
-ec.wait_finished([app])
+ec.wait_finished([ccncat])
-## CCND logs will be collected to the results_dir upon shutdown.
-## We can aldo get the content of the logs now:
-#print "LOG2", ec.trace(ccnd1, "stderr")
-#print "LOG 1", ec.trace(ccnd2, "stderr")
+stdout = ec.trace(ccncat, "stdout")
+f = open("video.ts", "w")
+f.write(stdout)
+f.close()
ec.shutdown()
+print "Transfered FILE stored localy at video.ts"
+
#
# Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
+# Example of how to run this experiment (replace with your information):
+#
+# $ cd <path-to-nepi>
+# python examples/planetlab/ping_with_filters.py -s <pl-slice> -u <pl-user> -p <pl-password> -k <pl-ssh-key>
+
from nepi.execution.ec import ExperimentController
from nepi.execution.resource import ResourceAction, ResourceState
+from optparse import OptionParser
import os
-def create_node(ec, username, pl_user, pl_password, hostname=None, country=None,
- operatingSystem=None, minBandwidth=None, minCpu=None):
+
+def create_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password,
+ hostname = None, country = None, operatingSystem = None,
+ minBandwidth = None, minCpu = None):
node = ec.register_resource("PlanetlabNode")
- if username:
- ec.set(node, "username", username)
- if pl_user:
- ec.set(node, "pluser", pl_user)
- if pl_password:
- ec.set(node, "plpassword", pl_password)
+ ec.set(node, "username", pl_slice)
+ ec.set(node, "identity", pl_ssh_key)
+ ec.set(node, "pluser", pl_user)
+ ec.set(node, "plpassword", pl_password)
if hostname:
ec.set(node, "hostname", hostname)
return node
-def add_app(ec, command, node, sudo=None, video=None, depends=None, forward_x11=None, \
- env=None):
+def add_app(ec, command, node, newname = None, sudo = None,
+ video = None, depends = None, forward_x11 = None, env = None):
app = ec.register_resource("LinuxApplication")
+
if sudo is not None:
ec.set(app, "sudo", sudo)
if video is not None:
ec.set(app, "forwardX11", forward_x11)
if env is not None:
ec.set(app, "env", env)
+
ec.set(app, "command", command)
ec.register_connection(app, node)
+ # add collector to download application standar output
+ collector = ec.register_resource("Collector")
+ ec.set(collector, "traceName", "stdout")
+ if newname:
+ ec.set(collector, "rename", newname)
+ ec.register_connection(app, collector)
+
return app
-exp_id = "ping_filters_exp"
+usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
+ "-k <pl-ssh-key> -c <country> -o <operating-system> -H <hostname> ")
+
+parser = OptionParser(usage = usage)
+parser.add_option("-s", "--pl-slice", dest="pl_slice",
+ help="PlanetLab slicename", type="str")
+parser.add_option("-u", "--pl-user", dest="pl_user",
+ help="PlanetLab web username", type="str")
+parser.add_option("-p", "--pl-password", dest="pl_password",
+ help="PlanetLab web password", type="str")
+parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
+ help="Path to private SSH key associated with the PL account",
+ type="str")
+parser.add_option("-c", "--country", dest="country",
+ help="Country for the PL hosts",
+ type="str")
+parser.add_option("-o", "--os", dest="os",
+ help="Operating system for the PL hosts", default="f14",
+ type="str")
+parser.add_option("-H", "--hostname", dest="hostname",
+ help="PlanetLab hostname",
+ type="str")
+
+(options, args) = parser.parse_args()
+
+pl_slice = options.pl_slice
+pl_ssh_key = options.pl_ssh_key
+pl_user = options.pl_user
+pl_password = options.pl_password
+hostname = options.hostname
+country = options.country
+os = options.os
# Create the entity Experiment Controller:
-ec = ExperimentController(exp_id)
+ec = ExperimentController("pl_ping_filters")
# Register the nodes resources:
-# The username in this case is the slice name, the one to use for login in
-# via ssh into PlanetLab nodes. Replace with your own slice name.
-username = "inria_sfatest"
-
-# The pluser and plpassword are the ones used to login in the PlanetLab web
-# site. Replace with your own user and password account information.
-pl_user = "lucia.guevgeozian_odizzio@inria.fr"
-pl_password = os.environ.get("PL_PASS")
-
# Choose the PlanetLab nodes for the experiment, in this example 5 nodes are
# used, and they are picked according to different criterias.
# First node will be the one defined by its hostname.
-hostname = "planetlab2.utt.fr"
-node1 = create_node(ec, username, pl_user, pl_password, hostname=hostname)
+node1 = create_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password,
+ hostname = hostname)
-# Second node will be any node in France.
-country = "France"
-node2 = create_node(ec, username, pl_user, pl_password, country=country)
+# Second node will be any node in the selected country.
+node2 = create_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password,
+ country=country)
-# Third node will be a node in France that has Fedora 14 installed.
-operatingSystem = "f14"
-node3 = create_node(ec, username, pl_user, pl_password, country=country,
- operatingSystem=operatingSystem)
+# Third node will be a node in the selected country and with the selected
+# fedora OS
+node3 = create_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password,
+ country = country,
+ operatingSystem = os)
# Forth node will have at least 50% of CPU available
minCpu=50
-node4 = create_node(ec, username, pl_user, pl_password, minCpu=minCpu)
+node4 = create_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password,
+ minCpu = minCpu)
# Fifth node can be any node, constrains are not important.
-node5 = create_node(ec, username, pl_user, pl_password)
+node5 = create_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password)
# Register the applications to run in the nodes, in this case just ping to the
# first node:
-apps_per_node = dict()
apps = []
for node in [node2, node3, node4, node5]:
- command = "ping -c5 %s > ping%s.txt" % (hostname, node)
- app = add_app(ec, command, node)
- apps_per_node[node] = app
+ command = "ping -c5 %s" % hostname
+ trace_name = "%s.ping" % hostname
+ app = add_app(ec, command, node, newname = trace_name)
apps.append(app)
# Register conditions
# before the rest of the nodes. This assures that no other resource will use the
# identified node even if the constraints matchs.
# In this example node2, node3, node4 and node5, are deployed after node1 is
-# provisioned. node1 must be the node planetlab2.utt.fr, meanwhile node2, node3,
+# provisioned. node1 must be the node hostname, meanwhile node2, node3,
# node4 and node5 just need to fulfill certain constraints.
# Applications are always deployed after nodes, so no need to register conditions
# for the apps in this example.
# Wait until the applications are finish to retrive the traces:
ec.wait_finished(apps)
-traces = dict()
-for node, app in apps_per_node.iteritems():
- ping_string = "ping%s.txt" % node
- trace = ec.trace(app, ping_string)
- traces[node]= trace
-
-# Choose a directory to store the traces locally, change to a convenient path for you:
-directory = "examples/planetlab/"
-for node, trace in traces.iteritems():
- trace_file = directory + "ping%s.txt" % node
- f = open(trace_file, "w")
- f.write(trace)
- f.close()
+print "Results stored at", ec.exp_dir
# Do the experiment controller shutdown:
ec.shutdown()