#!/usr/bin/env python

# Initial scale experiment for converged operator network
# (ARCFIRE T4.3)

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

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

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

log.set_logging_level('DEBUG')

f1 = UnicastLayer("fixed")
l1 = UnicastLayer("LTE")
m1 = UnicastLayer("metro1")
m2 = UnicastLayer("metro2")
m3 = UnicastLayer("metro3")
c1 = UnicastLayer("core")
n1 = UnicastLayer("overlay")

f1e1 = EthDixLayer("f1e1")
f1e2 = EthDixLayer("f1e2")
f1e3 = EthDixLayer("f1e3")

l1e1 = EthDixLayer("l1e1")

m1f1 = EthDixLayer("m1f1")

m1e1 = EthDixLayer("m1e1")
m1e2 = EthDixLayer("m1e2")
m1e3 = EthDixLayer("m1e3")
m1e4 = EthDixLayer("m1e4")
m1e5 = EthDixLayer("m1e5")
m1e6 = EthDixLayer("m1e6")

m2l1 = EthDixLayer("m2l1")

m2e1 = EthDixLayer("m2e1")
m2e2 = EthDixLayer("m2e2")
m2e3 = EthDixLayer("m2e3")
m2e4 = EthDixLayer("m2e4")
m2e5 = EthDixLayer("m2e5")
m2e6 = EthDixLayer("m2e6")

m3e1 = EthDixLayer("m3e1")
m3e2 = EthDixLayer("m3e2")
m3e3 = EthDixLayer("m3e3")
m3e4 = EthDixLayer("m3e4")
m3e5 = EthDixLayer("m3e5")
m3e6 = EthDixLayer("m3e6")

m1c1 = EthDixLayer("m1c1")
m1c2 = EthDixLayer("m1c2")

m2c1 = EthDixLayer("m2c1")
m2c2 = EthDixLayer("m2c2")

m3c1 = EthDixLayer("m3c1")
m3c2 = EthDixLayer("m3c2")

c1e1 = EthDixLayer("c1e1")
c1e2 = EthDixLayer("c1e2")
c1e3 = EthDixLayer("c1e3")
c1e4 = EthDixLayer("c1e4")

f1n1 = Node("f1n1",
            layers = [n1, f1, f1e3],
            registrations = {f1 : [f1e3], n1: [f1]})

f1n2 = Node("f1n2",
            layers = [f1, f1e1, f1e2, f1e3, m1f1],
            registrations = {f1: [f1e1, f1e2, f1e3, m1f1]})

f1n3 = Node("f1n3",
            layers = [n1, f1, f1e1],
            registrations = {f1: [f1e1], n1: [f1]})

f1n4 = Node("f1n4",
            layers = [n1, f1, f1e2],
            registrations = {f1: [f1e2], n1: [f1]})

l1n1 = Node("l1n1",
            layers = [n1, l1, m2l1, l1e1],
            registrations = {l1: [m2l1, l1e1], n1: [l1]})

l1n2 = Node("l1n2",
            layers = [n1, l1, l1e1],
            registrations = {l1: [l1e1], n1: [l1]})

m1n1 = Node("m1n1",
            layers = [m1, m1e1, m1e6],
            registrations = {m1: [m1e1, m1e6]})

m1n2 = Node("m1n2",
            layers = [m1, m1e1, m1e2],
            registrations = {m1: [m1e1, m1e2]})
m1n3 = Node("m1n3",
            layers = [m1, m1e2, m1e3, m1c1],
            registrations = {m1: [m1e2, m1e3, m1c1]})
m1n4 = Node("m1n4",
            layers = [m1, m1e3, m1e4, m1c2],
            registrations = {m1: [m1e3, m1e4, m1c2]})
m1n5 = Node("m1n5",
            layers = [m1, m1e4, m1e5],
            registrations = {m1: [m1e4, m1e5]})
m1n6 = Node("m1n6",
            layers = [n1, m1, f1, m1e5, m1e6, m1f1],
            registrations = {m1: [m1e5, m1e6],
                                 f1: [m1f1], n1: [f1, m1]})

m2n1 = Node("m2n1",
            layers = [m2, m2e1, m2e6],
            registrations = {m2: [m2e1, m2e6]})
m2n2 = Node("m2n2",
            layers = [m2, m2e1, m2e2],
            registrations = {m2: [m2e1, m2e2]})
m2n3 = Node("m2n3",
            layers = [m2, m2e2, m2e3, m2c1],
            registrations = {m2: [m2e2, m2e3, m2c1]})
m2n4 = Node("m2n4",
            layers = [m2, m2e3, m2e4, m2c2],
            registrations = {m2: [m2e3, m2e4, m2c2]})
m2n5 = Node("m2n5",
            layers = [m2, m2e4, m2e5],
            registrations = {m2: [m2e4, m2e5]})
m2n6 = Node("m2n6",
            layers = [n1, m2, l1, m2e5, m2e6, m2l1],
            registrations = {m2: [m2e5, m2e6], l1: [m2l1], n1: [l1, m2]})

m3n1 = Node("m3n1",
            layers = [m3, m3e1, m3e6],
            registrations = {m3: [m3e1, m3e6]})
m3n2 = Node("m3n2",
            layers = [m3, m3e1, m3e2],
            registrations = {m3: [m3e1, m3e2]})
m3n3 = Node("m3n3",
            layers = [m3, m3e2, m3e3, m3c1],
            registrations = {m3: [m3e2, m3e3, m3c1]})
m3n4 = Node("m3n4",
            layers = [m3, m3e3, m3e4, m3c2],
            registrations = {m3: [m3e3, m3e4, m3c2]})
m3n5 = Node("m3n5",
            layers = [m3, m3e4, m3e5],
            registrations = {m3: [m3e4, m3e5]})
m3n6 = Node("m3n6",
            layers = [m3, m3e5, m3e6],
            registrations = {m3: [m3e5, m3e6]})

c1n1 = Node("c1n1",
            layers = [n1, c1, m1, m2, m1c1, m2c1, c1e1, c1e4],
            registrations = {c1: [c1e1, c1e4], m1: [c1, m1c1],
                                 m2: [c1, m2c1], n1: [m1, m2]})
c1n2 = Node("c1n2",
            layers = [n1, c1, m2, m3, m2c2, m3c1, c1e1, c1e2],
            registrations = {c1: [c1e1, c1e2], m2: [c1, m2c2],
                                 m3: [c1, m3c1], n1: [m2, m3]})
c1n3 = Node("c1n3",
            layers = [n1, c1, m3, m3c2, c1e2, c1e3],
            registrations = {c1: [c1e2, c1e3], m3: [c1, m3c2], n1: [m3]})
c1n4 = Node("c1n4",
            layers = [n1, c1, m1, m1c2, c1e3, c1e4],
            registrations = {c1: [c1e3, c1e4], m1: [c1, m1c2], n1: [m1]})

tb = jfed.Testbed(exp_name   = "arcfiret43",
                  proj_name  = "rumba",
                  cert_file  = "/path/to/cert.pem",
                  authority  = "exogeni.net",
                  username   = "username")

exp = our.Experiment(tb, nodes = [f1n1, f1n2, f1n3, f1n4,
                                 l1n1, l1n2,
                                 m1n1, m1n2, m1n3, m1n4, m1n5, m1n6,
                                 m2n1, m2n2, m2n3, m2n4, m2n5, m2n6,
                                 m3n1, m3n2, m3n3, m3n4, m3n5, m3n6,
                                 c1n1, c1n2, c1n3, c1n4])

print(exp)

with ExperimentManager(exp, swap_out_strategy=PAUSE_SWAPOUT):
    exp.swap_in()
    exp.install_prototype()
    exp.bootstrap_prototype()
    c1 = Client("operf", options ="-s 1000 -d 0",
                nodes=[f1n1, f1n3, f1n4, l1n2])
    s1 = Server("operf", arrival_rate=2, mean_duration=5,
                options = "-l", nodes = [c1n1], clients = [c1])
    sb = StoryBoard(experiment=exp, duration=3600, servers = [s1])
    sb.generate_script()
    sb.start()
