aboutsummaryrefslogtreecommitdiff
path: root/examples/script-example.py
blob: 6cfaf4201c12a8692ebdc7d12269bc078390b637 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python

# An example script leveraging the storyboard scripting functionality
from functools import partial

from rumba.storyboard import *
from rumba.model import *
import rumba.log as log
import rumba.testbeds.qemu as qemu
import rumba.prototypes.rlite as rl
from rumba.utils import ExperimentManager
import rumba.utils as utils

log.set_logging_level(log.DEBUG)


n1 = NormalDIF("n1")

n1.add_policy("rmt.pff", "lfa")
n1.add_policy("security-manager", "passwd")

e1 = ShimEthDIF("e1")

node_a = Node("node_a",
              difs=[n1, e1],
              dif_registrations={n1: [e1]})

node_b = Node("node_b",
              difs=[e1, n1],
              dif_registrations={n1: [e1]})

tb = qemu.Testbed(exp_name="script_test",
                  username="root",
                  password="root")

exp = rl.Experiment(tb, nodes=[node_a, node_b])


client_a = Client(
    "rinaperf",
    options="-t perf -s 1000 -D <duration>",
    shutdown="",
    c_id='rinaperf_a'
)

client_b = Client(
    "rinaperf",
    options="-t perf -s 1000 -D <duration> -z rinaperfb",
    shutdown="",
    c_id='rinaperf_b'
)

client_c = Client(
    "rinaperf",
    options="-t perf -s 1000 -D <duration> -z rinaperfc",
    shutdown="",
    c_id='rinaperf_c'
)

server_a = Server(
    "rinaperf",
    options="-l",
    arrival_rate=1,
    mean_duration=5,
    clients=[client_a],
    s_id='server_a'
)

server_b = Server(
    "rinaperf",
    options="-l -z rinaperfb",
    arrival_rate=0.5,
    mean_duration=10,
    clients=[client_b],
    s_id='server_b'
)

server_c = Server(
    "rinaperf",
    options="-l -z rinaperfc",
    arrival_rate=1.6,
    mean_duration=3,
    clients=[client_c],
    s_id='server_c'
)

typewriter = Client(
    "touch test_file",
    shutdown=""
)


if __name__ == '__main__':
    story = StoryBoard(30)
    story.set_experiment(exp)
    story.add_server_on_node(server_a, node_a)
    story.add_server_on_node(server_b, node_a)
    story.add_server_on_node(server_c, node_a)
    client_a.add_node(node_b)
    client_b.add_node(node_b)
    client_c.add_node(node_b)
    script_file = os.path.join(
        os.path.dirname(__file__),
        'example-script.rsb'
    )
    story.parse_script_file(script_file)
    cb = partial(story.run_command, node_a, "ls -l test_file")
    # This will return a file, because it will run after
    # Triggering_event
    action = partial(story.run_client, typewriter, 0.2, node=node_a, callback=cb)
    story.add_event(Event(action, ev_time=12, ev_id='Triggering_event'))
    log.flush_log()
    with ExperimentManager(exp):
        exp.swap_in()
        exp.bootstrap_prototype()
        story.start()