aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-09-20 14:27:34 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-09-20 17:52:36 +0200
commitd8a0cfae620d20b70c668bea66af5f5e2e348379 (patch)
tree1045018edb42d56361352912641dd052ce8d4696 /examples
parent8632ea7a3c0e50c68e1357c18b0398b013fb3a85 (diff)
downloadrumba-d8a0cfae620d20b70c668bea66af5f5e2e348379.tar.gz
rumba-d8a0cfae620d20b70c668bea66af5f5e2e348379.zip
examples: Add snake example
This adds the snake as an example. It forms a single DIF connected node by node. The number of nodes can be passed as parameter.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/snake.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/snake.py b/examples/snake.py
new file mode 100755
index 0000000..c6b67b3
--- /dev/null
+++ b/examples/snake.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+# An example script using the rumba package
+
+from rumba.model import *
+
+# import testbed plugins
+import rumba.testbeds.emulab as emulab
+import rumba.testbeds.jfed as jfed
+import rumba.testbeds.faketestbed as fake
+import rumba.testbeds.qemu as qemu
+
+# import prototype plugins
+import rumba.prototypes.ouroboros as our
+import rumba.prototypes.rlite as rl
+import rumba.prototypes.irati as irati
+
+import argparse
+import sys
+
+description = "Script to create a snake"
+
+argparser = argparse.ArgumentParser(description = description)
+argparser.add_argument('-n', '--nodes', type = int, default = '10',
+ help = "Total number of nodes")
+
+args = argparser.parse_args()
+
+log.set_logging_level('DEBUG')
+
+n01 = NormalDIF("n01")
+
+if (args.nodes < 2):
+ print("Snake must be longer than 2 nodes")
+ sys.exit(-1)
+
+nodes = []
+
+shim_prev = None
+for i in range(0, args.nodes):
+ if i is not (args.nodes - 1):
+ shim = ShimEthDIF("e" + str(i))
+ else:
+ shim = None
+
+ if shim_prev == None and shim != None:
+ node = Node("node" + str(i), difs = [n01, shim],
+ dif_registrations = {n01 : [shim]})
+ elif shim_prev != None and shim != None:
+ node = Node("node" + str(i), difs = [n01, shim, shim_prev],
+ dif_registrations = {n01 : [shim, shim_prev]})
+ else:
+ node = Node("node" + str(i), difs = [n01, shim_prev],
+ dif_registrations = {n01 : [shim_prev]})
+
+ shim_prev = shim
+ nodes.append(node)
+
+tb = qemu.Testbed(exp_name = "snake")
+
+exp = rl.Experiment(tb, nodes = nodes)
+
+print(exp)
+
+try:
+ exp.swap_in()
+ exp.bootstrap_prototype()
+finally:
+ exp.swap_out()