#!/usr/bin/env python

"""
Example using the Ouroboros-aligned layer-centric API.

Shows the naming conventions: Layer, UnicastLayer, EthDixLayer, etc.
"""

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

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

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

import rumba.log as log

log.set_logging_level('DEBUG')

# -----------------------------------------------------------------------
# Layer-centric syntax
# -----------------------------------------------------------------------

# Define layers
top = UnicastLayer("top")
mid = UnicastLayer("mid")
top.add_policy("rmt.pff", "lfa")

# Ethernet layers model point-to-point links
e1 = EthDixLayer("e1")
e2 = EthDixLayer("e2")
e3 = EthDixLayer("e3")

# Define nodes and their layer memberships + registrations
a = Node("a",
         layers=[top, mid, e1, e2],
         registrations={mid: [e1, e2],
                        top: [mid]})

b = Node("b",
         layers=[mid, e1, e3],
         registrations={mid: [e1, e3],
                        })

c = Node("c",
         layers=[top, mid, e2, e3],
         registrations={mid: [e2, e3],
                        top: [mid]})

# Create testbed and experiment
tb = local.Testbed(exp_name="layer-example")
exp = our.Experiment(tb, nodes=[a, b, c])

print(exp)

# Use properties from the API
for layer in exp.layer_ordering:
    print("Layer: %s (type=%s, is_eth=%s, is_shim=%s)" % (
        layer.name, layer.layer_type.value, layer.is_eth, layer.is_shim))

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