nepi-ng A: the basics
In this series we run a few experiments that ping between various
locations, over the networks available to experimenters in R2lab.
The steps A1 to A5 are small incremental changes, so that each concept is introduced one at a time. From A2 on, the code is shown as a diff against the previous step: inserted and deleted lines are highlighted so you can see what is new. The plain code is available in a dropdown.
Preparation¶
Before running these experiments we need
a valid reservation in the booking system;
the 2 nodes
fit01andfit02up and running.
For this first series we assume these 2 steps are performed manually.
Getting a reservation¶
Once logged in on the website, go to the booking page. In a nutshell, in the calendar:
click once in a free slot to create a reservation;
drag a reservation to change it;
double-click a reservation to cancel it;
when you belong to several slices, drag a slice from the left-hand list right into the calendar. The current slice is the one with a back arrow; it is the one used when you single-click to reserve.
The code in this series assumes a slice named r2lab-tutorial, which of
course you need to replace with your actual slice name.
Loading images¶
To load the images manually on the 2 nodes (use your slice name):
ssh your_slicename@faraday.inria.frIf your public key is not at its standard location, add the -i
option with the path to it. On Permission denied, go back to the
registration tutorial to troubleshoot access.
Once on faraday, type the following (explained in the
shell tools tutorial):
# always a good idea to check you currently own the reservation
rleases --check
# turn off the whole testbed - just in case
all-off
# select nodes 1 and 2
n 1 2
# load the default image (on the selected nodes)
rload
# wait for ssh to be up (still on the selected nodes)
rwaitrload takes a couple of minutes. Your output should look like this:
Sample output
your_slicename@faraday:~$ rleases --check
Checking current reservation for your_slicename OK
your_slicename@faraday:~$ all-off
reboot05:already off
reboot19:already off
reboot28:already off
reboot04:already off
... <snip>
reboot12:ok
reboot02:ok
reboot20:ok
reboot13:ok
Turning WiFi OFF
Starting: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.wifi.WifiSettings }
Turning OFF phone : turning on airplane mode
Broadcasting: Intent { act=android.intent.action.AIRPLANE_MODE (has extras) }
Broadcast completed: result=0
your_slicename@faraday:~$ n 1 2
export NODES="fit01 fit02"
export NBNODES=2
your_slicename@faraday:~$ rload
16:12:42 - +000s: Selection: fit01 fit02
16:12:42 - +000s: Loading image /var/lib/rhubarbe-images/default.ndz
16:12:42 - +000s: AUTH: checking for a valid lease
16:12:42 - +000s: AUTH: access granted
16:12:42 - +000s: fit02 reboot = Sending message 'on' to CMC reboot02
16:12:42 - +000s: fit01 reboot = Sending message 'on' to CMC reboot01
16:12:43 - +001s: fit02 reboot = idling for 15s
16:12:43 - +001s: fit01 reboot = idling for 15s
16:12:59 - +017s: started <frisbeed@234.5.6.1:10001 on default.ndz at 500 Mibps>
16:12:59 - +017s: fit01 frisbee_status = trying to telnet..
16:12:59 - +017s: fit02 frisbee_status = trying to telnet..
... <snip>
|############################################################################################|100% |29.56s|Time: 0:00:29
16:13:44 - +062s: fit02 Uploading successful
16:13:44 - +062s: fit02 reboot = Sending message 'reset' to CMC reboot02
16:13:46 - +064s: stopped <frisbeed@234.5.6.1:10001 on default.ndz at 500 Mibps>
your_slicename@faraday:~$ rwait
<Node fit01>:ssh OK
<Node fit02>:ssh OK
Both nodes now run the default image. You can log out of faraday and
go back to your laptop to run the steps below.
Continue with the A1 tab above.
A1: Objective¶
Our first experiment code is designed to run on YOUR computer. From
there we trigger a simple command on the R2lab gateway, that is to say
faraday.inria.fr; namely we simply ping google.fr from faraday, as depicted below.

The A1 scenario
Introduction to nepi-ng¶
This example introduces the following classes:
SshNode- represents an ssh connection; here we create one such object, with
our credentials to enter
faraday; SshJob- describes what commands we want to run in an
SshNode; here a single command is needed; Scheduler- runs a collection of
SshJobs - even with only one job, it will prove useful when several nodes are active at the same time.
You should be able to run this script as-is, except for the slice name that you need to change manually in the code.
#!/usr/bin/env python3
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
##########
# globals - how to reach the gateway
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
# to get feedback on the ssh-connection and see why it fails
verbose_ssh = True
##########
# this SshNode object holds the details of
# the first-leg ssh connection to the gateway
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
# the command we want to run in faraday is as simple as it gets
ping = SshJob(
# on what node do we want to run this:
node = faraday,
# what to run
command = [ 'ping', '-c1', 'google.fr' ],
# add jobs in the scheduler as we create them
scheduler = scheduler,
)
##########
# how to run the same directly with ssh - for troubleshooting
print("""--- for troubleshooting:
ssh -i /dev/null {}@{} ping -c1 google.fr
---""".format(gateway_username, gateway_hostname))
##########
# run the scheduler
ok = scheduler.orchestrate()
print("orchestrate -", ok)
A1-ping.py
Sample output: python3 A1-ping.py
r2lab-tutorial@faraday.inria.fr:========== Connecting (direct) to r2lab-tutorial@faraday.inria.fr
r2lab-tutorial@faraday.inria.fr:========== Authorization OK r2lab-tutorial@faraday.inria.fr
faraday.inria.fr:========== Session started for ping -c1 google.fr
faraday.inria.fr:========== Session ended for ping -c1 google.fr
--- for troubleshooting:
ssh -i /dev/null r2lab-tutorial@faraday.inria.fr ping -c1 google.fr
---
faraday.inria.fr:PING google.fr (216.58.205.163) 56(84) bytes of data.
faraday.inria.fr:64 bytes from mil04s28-in-f163.1e100.net (216.58.205.163): icmp_seq=1 ttl=54 time=9.54 ms
faraday.inria.fr:
faraday.inria.fr:--- google.fr ping statistics ---
faraday.inria.fr:1 packets transmitted, 1 received, 0% packet loss, time 0ms
faraday.inria.fr:rtt min/avg/max/mdev = 9.545/9.545/9.545/0.000 ms
orchestrate - True
Next: the A2 tab - specifying your slice on the command line.
A2: Objectives¶
using the standard
argparsemodule, we let users specify their slice on the command line with--slice your_slicename, without having to edit the source;we introduce the
Runclass, a companion toSshNode, stating thatpingis to be run on the remote side as a standard, preinstalled command. Other kinds of commands exist, like shell scripts or file transfers;finally, a good practice: have your script return a meaningful return code to the OS, using
exit(). A process is expected toexit(0)when everything went fine.
The verbose ssh messages are gone; add -v / --verbose-ssh to get
them back.
#!/usr/bin/env python3
from argparse import ArgumentParser
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
from apssh import Run
##########
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
verbose_ssh = False
# this time we want to be able to specify username and verbose_ssh
parser = ArgumentParser()
parser.add_argument("-s", "--slice", default=gateway_username,
help="specify an alternate slicename, default={}"
.format(gateway_username))
parser.add_argument("-v", "--verbose-ssh", default=False, action='store_true',
help="run ssh in verbose mode")
args = parser.parse_args()
gateway_username = args.slice
verbose_ssh = args.verbose_ssh
##########
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
# the command we want to run in faraday is as simple as it gets
ping = SshJob(
node = faraday,
# let's be more specific about what to run
# we will soon see other things we can do on an ssh connection
command = Run('ping', '-c1', 'google.fr'),
scheduler = scheduler,
)
##########
# how to run the same directly with ssh - for troubleshooting
print("""--- for troubleshooting:
ssh -i /dev/null {}@{} ping -c1 google.fr
---""".format(gateway_username, gateway_hostname))
##########
# run the scheduler
ok = scheduler.orchestrate()
# give details if it failed
ok or scheduler.debrief()
# return something useful to your OS
exit(0 if ok else 1)
A2-ping.py
#!/usr/bin/env python3
+
+from argparse import ArgumentParser
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
+from apssh import Run
##########
-# globals - how to reach the gateway
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
-# to get feedback on the ssh-connection and see why it fails
-verbose_ssh = True
+verbose_ssh = False
+
+# this time we want to be able to specify username and verbose_ssh
+parser = ArgumentParser()
+parser.add_argument("-s", "--slice", default=gateway_username,
+ help="specify an alternate slicename, default={}"
+ .format(gateway_username))
+parser.add_argument("-v", "--verbose-ssh", default=False, action='store_true',
+ help="run ssh in verbose mode")
+args = parser.parse_args()
+
+gateway_username = args.slice
+verbose_ssh = args.verbose_ssh
##########
-# this SshNode object holds the details of
-# the first-leg ssh connection to the gateway
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
# the command we want to run in faraday is as simple as it gets
ping = SshJob(
- # on what node do we want to run this:
node = faraday,
- # what to run
- command = [ 'ping', '-c1', 'google.fr' ],
- # add jobs in the scheduler as we create them
+ # let's be more specific about what to run
+ # we will soon see other things we can do on an ssh connection
+ command = Run('ping', '-c1', 'google.fr'),
scheduler = scheduler,
)
##########
# how to run the same directly with ssh - for troubleshooting
print("""--- for troubleshooting:
ssh -i /dev/null {}@{} ping -c1 google.fr
---""".format(gateway_username, gateway_hostname))
##########
# run the scheduler
ok = scheduler.orchestrate()
-print("orchestrate -", ok)
+# give details if it failed
+ok or scheduler.debrief()
+
+# return something useful to your OS
+exit(0 if ok else 1)
Changes from A1-ping.py to A2-ping.py
Sample output: python3 A2-ping.py -s inria_radiomap
--- for troubleshooting:
ssh -i /dev/null inria_radiomap@faraday.inria.fr ping -c1 google.fr
---
faraday.inria.fr:PING google.fr (216.58.205.99) 56(84) bytes of data.
faraday.inria.fr:64 bytes from mil04s26-in-f99.1e100.net (216.58.205.99): icmp_seq=1 ttl=54 time=9.69 ms
faraday.inria.fr:
faraday.inria.fr:--- google.fr ping statistics ---
faraday.inria.fr:1 packets transmitted, 1 received, 0% packet loss, time 0ms
faraday.inria.fr:rtt min/avg/max/mdev = 9.695/9.695/9.695/0.000 ms
Next: the A3 tab - running commands on a node rather than on the gateway.
A3: Objective:¶
Controlling a node beyond the gateway
This time we want to run the same ping command, but from a node, and
not from the gateway.
To this end we only need a second SshNode, created with the
gateway= argument. This materializes the fact that we reach node
fit01 through the gateway. It also ensures that a single ssh
connection is established to the gateway, regardless of the number of
nodes actually controlled.

The A3 scenario
#!/usr/bin/env python3
from argparse import ArgumentParser
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
from apssh import Run
##########
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
verbose_ssh = False
# this time we want to be able to specify username and verbose_ssh
parser = ArgumentParser()
parser.add_argument("-s", "--slice", default=gateway_username,
help="specify an alternate slicename, default={}"
.format(gateway_username))
parser.add_argument("-v", "--verbose-ssh", default=False, action='store_true',
help="run ssh in verbose mode")
args = parser.parse_args()
gateway_username = args.slice
verbose_ssh = args.verbose_ssh
##########
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
# saying gateway = faraday means to tunnel ssh through the gateway
node1 = SshNode(gateway = faraday, hostname = "fit01", username = "root",
verbose = verbose_ssh)
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
# the command we want to run in node1 is as simple as it gets
ping = SshJob(
node = node1,
# let's be more specific about what to run
# we will soon see other things we can do on an ssh connection
command = Run('ping', '-c1', 'google.fr'),
scheduler = scheduler,
)
##########
# how to run the same directly with ssh - for troubleshooting
print("""--- for troubleshooting:
ssh -i /dev/null {}@{} ssh root@fit01 ping -c1 google.fr
---""".format(gateway_username, gateway_hostname))
##########
# run the scheduler
ok = scheduler.orchestrate()
# give details if it failed
ok or scheduler.debrief()
# return something useful to your OS
exit(0 if ok else 1)
A3-ping.py
#!/usr/bin/env python3
from argparse import ArgumentParser
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
from apssh import Run
##########
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
verbose_ssh = False
# this time we want to be able to specify username and verbose_ssh
parser = ArgumentParser()
parser.add_argument("-s", "--slice", default=gateway_username,
help="specify an alternate slicename, default={}"
.format(gateway_username))
parser.add_argument("-v", "--verbose-ssh", default=False, action='store_true',
help="run ssh in verbose mode")
args = parser.parse_args()
gateway_username = args.slice
verbose_ssh = args.verbose_ssh
##########
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
+# saying gateway = faraday means to tunnel ssh through the gateway
+node1 = SshNode(gateway = faraday, hostname = "fit01", username = "root",
+ verbose = verbose_ssh)
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
-# the command we want to run in faraday is as simple as it gets
+# the command we want to run in node1 is as simple as it gets
ping = SshJob(
- node = faraday,
+ node = node1,
# let's be more specific about what to run
# we will soon see other things we can do on an ssh connection
command = Run('ping', '-c1', 'google.fr'),
scheduler = scheduler,
)
##########
# how to run the same directly with ssh - for troubleshooting
print("""--- for troubleshooting:
-ssh -i /dev/null {}@{} ping -c1 google.fr
+ssh -i /dev/null {}@{} ssh root@fit01 ping -c1 google.fr
---""".format(gateway_username, gateway_hostname))
##########
# run the scheduler
ok = scheduler.orchestrate()
# give details if it failed
ok or scheduler.debrief()
# return something useful to your OS
exit(0 if ok else 1)
Changes from A2-ping.py to A3-ping.py
Sample output: python3 A3-ping.py -v
r2lab-tutorial@faraday.inria.fr:========== Connecting (direct) to r2lab-tutorial@faraday.inria.fr
r2lab-tutorial@faraday.inria.fr:========== Authorization OK r2lab-tutorial@faraday.inria.fr
root@fit01:========== Connecting (tunnelled) to root@fit01
root@fit01:========== Authorization OK root@fit01
fit01:========== Session started for ping -c1 google.fr
fit01:========== Session ended for ping -c1 google.fr
--- for troubleshooting:
ssh -i /dev/null r2lab-tutorial@faraday.inria.fr ssh root@fit01 ping -c1 google.fr
---
fit01:PING google.fr (216.58.205.163) 56(84) bytes of data.
fit01:64 bytes from mil04s28-in-f163.1e100.net (216.58.205.163): icmp_seq=1 ttl=53 time=9.76 ms
fit01:
fit01:--- google.fr ping statistics ---
fit01:1 packets transmitted, 1 received, 0% packet loss, time 0ms
fit01:rtt min/avg/max/mdev = 9.768/9.768/9.768/0.000 ms
Next: the A4 tab - checking for leases before running.
A4: Objectives¶
Our experiment performs the exact same thing, but before it does anything, it checks that we do have a valid reservation. This
implements a good practice: ssh access to the gateway is essentially open once and for good, so it is wise to check for the reservation early, rather than get obscure errors later on;
gives us a first glimpse at running one command on the gateway and one on the node.
asynciojobs basics¶
a
Scheduleris filled with any number of jobs; the order in which jobs are defined and added has no meaning whatsoever;what truly matters is the set of
requiredrelationships between jobs. Here we run 2 jobs in sequence, sopingis defined withrequired = check_lease;a
Schedulerdoes not propagate result values from one job to its successors. The only logic it knows about is that if a job raises an exception and that job iscritical, the scheduler bails out immediately;here
rhubarbe leases --checkreturns 0 when you currently own the reservation, and 1 otherwise; declaringcheck_leaseascriticalensures the scenario fails right away if you do not.
Graphical view¶
For the first time we use export_as_dotfile on the Scheduler to
produce a graphical representation of the jobs’ required
dependencies, shown in the Graph tab of the code below.
The code only produces a dot file, so it runs even without the
graphviz library installed. Turn it into a png with any program
that supports the dot format,
e.g. the dot binary from the graphviz package.

The A4 scenario
#!/usr/bin/env python3
from argparse import ArgumentParser
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
from apssh import Run
##########
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
verbose_ssh = False
parser = ArgumentParser()
parser.add_argument("-s", "--slice", default=gateway_username,
help="specify an alternate slicename, default={}"
.format(gateway_username))
parser.add_argument("-v", "--verbose-ssh", default=False, action='store_true',
help="run ssh in verbose mode")
args = parser.parse_args()
gateway_username = args.slice
verbose_ssh = args.verbose_ssh
##########
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
# saying gateway = faraday means to tunnel ssh through the gateway
node1 = SshNode(gateway = faraday, hostname = "fit01", username = "root",
verbose = verbose_ssh)
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
check_lease = SshJob(
# checking the lease is done on the gateway
node = faraday,
# this means that a failure in any of the commands
# will cause the scheduler to bail out immediately
critical = True,
command = Run("rhubarbe leases --check"),
scheduler = scheduler,
)
# the command we want to run in node1 is as simple as it gets
ping = SshJob(
node = node1,
# this says that we wait for check_lease to finish before we start ping
required = check_lease,
# let's be more specific about what to run
# we will soon see other things we can do on an ssh connection
command = Run('ping', '-c1', 'google.fr'),
scheduler = scheduler,
)
##########
# run the scheduler
ok = scheduler.orchestrate()
# give details if it failed
ok or scheduler.debrief()
# producing a dot file for illustration
scheduler.export_as_dotfile("A4.dot")
# return something useful to your OS
exit(0 if ok else 1)
A4-ping.py
#!/usr/bin/env python3
from argparse import ArgumentParser
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
from apssh import Run
##########
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
verbose_ssh = False
-# this time we want to be able to specify username and verbose_ssh
parser = ArgumentParser()
parser.add_argument("-s", "--slice", default=gateway_username,
help="specify an alternate slicename, default={}"
.format(gateway_username))
parser.add_argument("-v", "--verbose-ssh", default=False, action='store_true',
help="run ssh in verbose mode")
args = parser.parse_args()
gateway_username = args.slice
verbose_ssh = args.verbose_ssh
##########
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
# saying gateway = faraday means to tunnel ssh through the gateway
node1 = SshNode(gateway = faraday, hostname = "fit01", username = "root",
verbose = verbose_ssh)
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
+check_lease = SshJob(
+ # checking the lease is done on the gateway
+ node = faraday,
+ # this means that a failure in any of the commands
+ # will cause the scheduler to bail out immediately
+ critical = True,
+ command = Run("rhubarbe leases --check"),
+ scheduler = scheduler,
+)
+
# the command we want to run in node1 is as simple as it gets
ping = SshJob(
node = node1,
+ # this says that we wait for check_lease to finish before we start ping
+ required = check_lease,
# let's be more specific about what to run
# we will soon see other things we can do on an ssh connection
command = Run('ping', '-c1', 'google.fr'),
scheduler = scheduler,
)
-
-##########
-# how to run the same directly with ssh - for troubleshooting
-print("""--- for troubleshooting:
-ssh -i /dev/null {}@{} ssh root@fit01 ping -c1 google.fr
----""".format(gateway_username, gateway_hostname))
##########
# run the scheduler
ok = scheduler.orchestrate()
# give details if it failed
ok or scheduler.debrief()
+# producing a dot file for illustration
+scheduler.export_as_dotfile("A4.dot")
+
# return something useful to your OS
exit(0 if ok else 1)
Changes from A3-ping.py to A4-ping.py
Sample output: python3 A4-ping.py
faraday.inria.fr:Checking current reservation for r2lab-tutorial : OK
fit01:PING google.fr (216.58.205.163) 56(84) bytes of data.
fit01:64 bytes from mil04s28-in-f163.1e100.net (216.58.205.163): icmp_seq=1 ttl=53 time=9.77 ms
fit01:
fit01:--- google.fr ping statistics ---
fit01:1 packets transmitted, 1 received, 0% packet loss, time 0ms
fit01:rtt min/avg/max/mdev = 9.777/9.777/9.777/0.000 ms
Or, with a slice that is valid but does not have the reservation right now:
$ python3 A4-ping.py -s inria_inria.oai.oai_build
faraday.inria.fr:Checking current reservation for inria_inria.oai.oai_build WARNING: Access currently deniedNext: the A5 tab - using other network interfaces.
A5: Objectives¶
This time we run ping between two nodes of the testbed, over the
data wired network.
Each R2lab node has 4 network interfaces (not counting the special
reboot interface, which can reset the node but is not visible from
linux). With the images we offer, they are managed as follows:
control- a wired interface, the one you use when you first ssh into the node;
turned on automatically at boot; known as e.g.
fit01, on the192.168.3.0/24subnet; data- another wired interface, NOT turned on at boot; it is dedicated
to your usage, so you can turn it on or off as you please, even using
DHCP, in which case its address is on
192.168.2.x/24and known to DNS as e.g.data01; atherosandintel- the 2 WiFi interfaces, also NOT turned on at boot - setting them up is entirely your responsibility (see the B-series).
Worth noticing in the code:
every node has a command named
turn-on-data, not a standard command but preinstalled for your convenience: it turns on the data interface using DHCP. Typehelpon any node to see the available commands; similar utilities are in r2lab-embedded;to run
pingonce BOTH nodes have configured their data interface, the ping job simply lists 2 jobs in itsrequired;in the epilogue we check that ping actually succeeded, using
result()on anSshJobinstance.

The A5 scenario
#!/usr/bin/env python3
from argparse import ArgumentParser
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
from apssh import Run
##########
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
verbose_ssh = False
parser = ArgumentParser()
parser.add_argument("-s", "--slice", default=gateway_username,
help="specify an alternate slicename, default={}"
.format(gateway_username))
parser.add_argument("-v", "--verbose-ssh", default=False, action='store_true',
help="run ssh in verbose mode")
args = parser.parse_args()
gateway_username = args.slice
verbose_ssh = args.verbose_ssh
##########
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
node1 = SshNode(gateway = faraday, hostname = "fit01", username = "root",
verbose = verbose_ssh)
node2 = SshNode(gateway = faraday, hostname = "fit02", username = "root",
verbose = verbose_ssh)
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
check_lease = SshJob(
# checking the lease is done on the gateway
node = faraday,
# this means that a failure in any of the commands
# will cause the scheduler to bail out immediately
critical = True,
command = Run("rhubarbe leases --check"),
scheduler = scheduler,
)
##########
# setting up the data interface on both fit01 and fit02
init_node_01 = SshJob(
node = node1,
command = Run("turn-on-data"),
required = check_lease,
scheduler = scheduler,
)
init_node_02 = SshJob(
node = node2,
command = Run("turn-on-data"),
required = check_lease,
scheduler = scheduler,
)
# the command we want to run in node1 is as simple as it gets
ping = SshJob(
node = node1,
# wait for the 2 init jobs instead
# check_release is guaranteed to have completed anyway
required = (init_node_01, init_node_02),
# let's be more specific about what to run
# we will soon see other things we can do on an ssh connection
command = Run('ping', '-c1', '-I', 'data', 'data02'),
scheduler = scheduler,
)
##########
# run the scheduler
ok = scheduler.orchestrate()
# give details if it failed
ok or scheduler.debrief()
# we say this is a success if the ping command succeeded
# the result() of the SshJob is the value that the command
# returns to the OS
# so it's a success if this value is 0
success = ok and ping.result() == 0
# producing a dot file for illustration
scheduler.export_as_dotfile("A5.dot")
# return something useful to your OS
exit(0 if success else 1)
A5-ping.py
#!/usr/bin/env python3
from argparse import ArgumentParser
from asynciojobs import Scheduler
from apssh import SshNode, SshJob
from apssh import Run
##########
gateway_hostname = 'faraday.inria.fr'
gateway_username = 'r2lab-tutorial'
verbose_ssh = False
parser = ArgumentParser()
parser.add_argument("-s", "--slice", default=gateway_username,
help="specify an alternate slicename, default={}"
.format(gateway_username))
parser.add_argument("-v", "--verbose-ssh", default=False, action='store_true',
help="run ssh in verbose mode")
args = parser.parse_args()
gateway_username = args.slice
verbose_ssh = args.verbose_ssh
##########
faraday = SshNode(hostname = gateway_hostname, username = gateway_username,
verbose = verbose_ssh)
-# saying gateway = faraday means to tunnel ssh through the gateway
node1 = SshNode(gateway = faraday, hostname = "fit01", username = "root",
verbose = verbose_ssh)
+node2 = SshNode(gateway = faraday, hostname = "fit02", username = "root",
+ verbose = verbose_ssh)
+
##########
# create an orchestration scheduler
scheduler = Scheduler()
##########
check_lease = SshJob(
# checking the lease is done on the gateway
node = faraday,
# this means that a failure in any of the commands
# will cause the scheduler to bail out immediately
critical = True,
command = Run("rhubarbe leases --check"),
scheduler = scheduler,
)
+##########
+# setting up the data interface on both fit01 and fit02
+init_node_01 = SshJob(
+ node = node1,
+ command = Run("turn-on-data"),
+ required = check_lease,
+ scheduler = scheduler,
+)
+init_node_02 = SshJob(
+ node = node2,
+ command = Run("turn-on-data"),
+ required = check_lease,
+ scheduler = scheduler,
+)
+
# the command we want to run in node1 is as simple as it gets
ping = SshJob(
node = node1,
- # this says that we wait for check_lease to finish before we start ping
- required = check_lease,
+ # wait for the 2 init jobs instead
+ # check_release is guaranteed to have completed anyway
+ required = (init_node_01, init_node_02),
# let's be more specific about what to run
# we will soon see other things we can do on an ssh connection
- command = Run('ping', '-c1', 'google.fr'),
+ command = Run('ping', '-c1', '-I', 'data', 'data02'),
scheduler = scheduler,
)
##########
# run the scheduler
ok = scheduler.orchestrate()
# give details if it failed
ok or scheduler.debrief()
+# we say this is a success if the ping command succeeded
+# the result() of the SshJob is the value that the command
+# returns to the OS
+# so it's a success if this value is 0
+success = ok and ping.result() == 0
+
# producing a dot file for illustration
-scheduler.export_as_dotfile("A4.dot")
+scheduler.export_as_dotfile("A5.dot")
# return something useful to your OS
-exit(0 if ok else 1)
+exit(0 if success else 1)
Changes from A4-ping.py to A5-ping.py
Sample output: python3 A5-ping.py
fit02:turn-on-data: data network on interface data
fit01:turn-on-data: data network on interface data
faraday.inria.fr:Checking current reservation for r2lab-tutorial : OK
fit02:data
fit01:data
fit01:PING data02 (192.168.2.2) from 192.168.2.1 data: 56(84) bytes of data.
fit01:64 bytes from data02 (192.168.2.2): icmp_seq=1 ttl=64 time=0.363 ms
fit01:
fit01:--- data02 ping statistics ---
fit01:1 packets transmitted, 1 received, 0% packet loss, time 0ms
fit01:rtt min/avg/max/mdev = 0.363/0.363/0.363/0.000 ms
Next: the WRAP UP tab.
Summary¶
At this point you should have a good grasp of these R2lab fundamentals.
Interfaces¶
Each node has 4 network interfaces; control is reserved for testbed
administration, the others are for the experimenter, who is in charge of
setting them up.
nepi-ng¶
By leveraging the standard asyncio library, and combining asynciojobs
and apssh on top of it, you can write scripts that are
reasonably simple and short;
able to run as many jobs as needed simultaneously, in a single thread;
able to deal with simple synchronization constraints.
Next¶
The B-series deals with the more complex task of setting up a wireless
network; the C-series addresses file transfers to and from SshNodes.
(Links to be added as these get ported.)