#!/usr/bin/env python

# An example script using the rumba package

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

# 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.visualizer import draw_network, get_network_from_rumba_experiment

log.set_logging_level('DEBUG')


n01 = UnicastLayer("n01")

e01 = EthDixLayer("e01")
e02 = EthDixLayer("e02")
e03 = EthDixLayer("e03")
e04 = EthDixLayer("e04")
e05 = EthDixLayer("e05")
e06 = EthDixLayer("e06")
e07 = EthDixLayer("e07")
e08 = EthDixLayer("e08")
e09 = EthDixLayer("e09")
e10 = EthDixLayer("e10")
e11 = EthDixLayer("e11")
e12 = EthDixLayer("e12")
e13 = EthDixLayer("e13")
e14 = EthDixLayer("e14")
e15 = EthDixLayer("e15")
e16 = EthDixLayer("e16")
e17 = EthDixLayer("e17")


a = Node("a",
         layers = [n01, e01, e06, e13 ],
         registrations = {n01 : [e01, e06, e13]})

b = Node("b",
         layers = [n01, e01, e02, e04],
         registrations = {n01 : [e01, e02, e04]})

c = Node("c",
         layers = [n01, e02, e03],
         registrations = {n01 : [e02, e03]})

d = Node("d",
         layers = [n01, e03, e04, e05],
         registrations = {n01 : [e03, e04, e05]})

e = Node("e",
         layers = [n01, e05, e06, e07],
         registrations = {n01 : [e05, e06, e07]})

f = Node("f",
         layers = [n01, e07, e08],
         registrations = {n01 : [e07, e08]})

g = Node("g",
         layers = [n01, e08, e09, e14],
         registrations = {n01 : [e08, e09, e14]})

h = Node("h",
         layers = [n01, e09, e10, e15],
         registrations = {n01 : [e09, e10, e15]})

i = Node("i",
         layers = [n01, e10, e11, e16],
         registrations = {n01 : [e10, e11, e16]})

j = Node("j",
         layers = [n01, e11, e12],
         registrations = {n01 : [e11, e12]})

k = Node("k",
         layers = [n01, e12, e13],
         registrations = {n01 : [e12, e13]})

l = Node("l",
         layers = [n01, e14, e15],
         registrations = {n01 : [e14, e15]})

m = Node("m",
         layers = [n01, e16, e17],
         registrations = {n01 : [e16, e17]})

n = Node("n",
         layers = [n01, e17],
         registrations = {n01 : [e17]})

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

exp = our.Experiment(tb, nodes = [a, b, c, d, e, f, g, h, i, j, k, l, m, n])

print(exp)

with ExperimentManager(exp, swap_out_strategy=PROMPT_SWAPOUT):
    nw = get_network_from_rumba_experiment(exp)
    draw_network(nw)
    exp.swap_in()
    exp.bootstrap_prototype()
