aboutsummaryrefslogtreecommitdiff
path: root/examples/docker-ouroboros.py
blob: 1c6009c31ac4d9cd788a4bf13a515c63673a2875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python

# An example script using the rumba package

from rumba.model import *
from rumba.utils import ExperimentManager

# import testbed plugins
import rumba.testbeds.dockertb as docker

# import prototype plugins
import rumba.prototypes.ouroboros as our

import argparse
import sys


description = "Script to create an ouroboros"

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 < 3):
    print("The ouroboros must be longer than 2 nodes")
    sys.exit(-1)

nodes = []

shim_prev = None
for i in range(0, args.nodes):
    shim = ShimEthDIF("e" + str(i))

    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)

nodes[0].add_dif(shim_prev)
nodes[0].add_dif_registration(n01, shim_prev)

tb = docker.Testbed(exp_name = "ouroboros",
                    base_image = "ouroborosrumba/prototype")

exp = our.Experiment(tb, nodes = nodes)

print(exp)

with ExperimentManager(exp):
    exp.swap_in()
    exp.bootstrap_prototype()