Network Emulation

This tutorial illustrates how network constraints can be enforced using EnOSlib. Another resources can be found in the Netem & SimpleNetem Service Class.

Setting up homogeneous constraints

When all your nodes share the same network limitations you can use the SimpleNetem service.

 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
from enoslib.api import discover_networks
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import Configuration, NetworkConfiguration
from enoslib.service import SimpleNetem

import logging
import os

logging.basicConfig(level=logging.DEBUG)


prod_network = NetworkConfiguration(
    id="n1",
    type="prod",
    roles=["my_network"],
    site="rennes"
)
conf = (
    Configuration.from_settings(job_type="allow_classic_ssh")
    .add_network_conf(prod_network)
    .add_machine(
        roles=["city", "paris"],
        cluster="parapluie",
        nodes=1,
        primary_network=prod_network
    )
    .add_machine(
        roles=["city", "berlin"],
        cluster="parapluie",
        nodes=1,
        primary_network=prod_network
    )
    .finalize()
)
provider = G5k(conf)
roles, networks = provider.init()
roles = discover_networks(roles, networks)

netem = SimpleNetem("delay 10ms", "my_network", hosts=roles["city"])
netem.deploy()
netem.validate()
netem.destroy()

Setting up heterogeneous constraints

You can use the Netem service for this purpose. The example is based on the G5K provider, but can be adapted to another one if desired.

 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
from enoslib.api import discover_networks
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import Configuration, NetworkConfiguration
from enoslib.service import Netem

import logging
import os

logging.basicConfig(level=logging.DEBUG)


prod_network = NetworkConfiguration(
    id="n1",
    type="prod",
    roles=["my_network"],
    site="rennes"
)
conf = (
    Configuration.from_settings(job_name="test", job_type="allow_classic_ssh")
    .add_network_conf(prod_network)
    .add_machine(
        roles=["paris"],
        cluster="parapluie",
        nodes=1,
        primary_network=prod_network
    )
    .add_machine(
        roles=["berlin"],
        cluster="parapluie",
        nodes=1,
        primary_network=prod_network
    )
    .add_machine(
        roles=["londres"],
        cluster="parapluie",
        nodes=1,
        primary_network=prod_network
    )
    .finalize()
)
provider = G5k(conf)
roles, networks = provider.init()
roles = discover_networks(roles, networks)

# Building the network constraints
emulation_conf = {
    "default_delay": "20ms",
    "default_rate": "1gbit",
    "except": [],
    "constraints": [{
        "src": "paris",
        "dst": "londres",
        "symetric": True,
        "delay": "10ms"
    }]
}

logging.info(emulation_conf)

netem = Netem(emulation_conf, roles=roles)
netem.deploy()
netem.validate()
netem.destroy()