#!/usr/bin/env python

# An example script using the rumba package

from rumba.model import *
from rumba.storyboard import *

# import testbed plugins
import rumba.testbeds.local as local

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

import rumba.log as log
from rumba.utils import ExperimentManager

log.set_logging_level('DEBUG')


n1 = UnicastLayer("n1")
n2 = UnicastLayer("n2")
n3 = UnicastLayer("n3")
n4 = UnicastLayer("n4")

e1 = EthDixLayer("e1")
e2 = EthDixLayer("e2")
e3 = EthDixLayer("e3")

a = Node("a",
         layers = [n3, n4, n1, e1],
         registrations = {n4: [n1], n3: [n1], n1 : [e1]})

b = Node("b",
         layers = [n1, e1, e2],
         registrations = {n1 : [e1, e2]})

c = Node("c",
         layers = [n3, n4, n1, n2, e2, e3],
         registrations = {n4: [n1], n3: [n1, n2], n1 : [e2], n2: [e3]})

d = Node("d",
         layers = [n3, n2, e3],
         registrations = {n3: [n2], n2 : [e3]})

tb = local.Testbed(exp_name="twolayers")

exp = our.Experiment(tb, nodes = [a, b, c, d])

print(exp)

with ExperimentManager(exp):
    exp.swap_in()
    exp.bootstrap_prototype()
    sb = StoryBoard(experiment=exp, duration=15, servers=[])
    sb.schedule_command(7.5, a, 'echo "7.5 secs in. We are at $(hostname)"')
    sb.schedule_command(12, b, 'echo "12 secs in. We are at $(hostname)"')
    sb.start()
