-
Notifications
You must be signed in to change notification settings - Fork 39
Docker Containers
MaxiNet can also run Docker containers instead of the default shell-based hosts. This addition is purely optional and does not interfere with normal usage.
To use MaxiNet with Docker containers simply select "Yes" if the install.sh script asks whether to install support for Docker containers.
Alternatively, manually replace the Mininet installation with https://github.com/containernet/containernet on all hosts following the provided installation instructions.
To test the installation start the MaxiNetFrontendServer and MaxiNetWorkers as usual. Run the example script:
~/MaxiNet/Maxinet/Frontend/examples$ python dockerSimplePing.py
The experiment starts two Docker containers and lets them ping each other. The output should contain something like
ping -c 5 10.0.0.252
PING 10.0.0.252 (10.0.0.252) 56(84) bytes of data.
64 bytes from 10.0.0.252: icmp_seq=1 ttl=64 time=61.5 ms
64 bytes from 10.0.0.252: icmp_seq=2 ttl=64 time=1.15 ms
64 bytes from 10.0.0.252: icmp_seq=3 ttl=64 time=0.417 ms
64 bytes from 10.0.0.252: icmp_seq=4 ttl=64 time=0.456 ms
64 bytes from 10.0.0.252: icmp_seq=5 ttl=64 time=0.441 ms
--- 10.0.0.252 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 0.417/12.809/61.576/24.385 ms
PING 10.0.0.251 (10.0.0.251) 56(84) bytes of data.
64 bytes from 10.0.0.251: icmp_seq=1 ttl=64 time=43.5 ms
64 bytes from 10.0.0.251: icmp_seq=2 ttl=64 time=0.961 ms
64 bytes from 10.0.0.251: icmp_seq=3 ttl=64 time=0.462 ms
64 bytes from 10.0.0.251: icmp_seq=4 ttl=64 time=0.428 ms
64 bytes from 10.0.0.251: icmp_seq=5 ttl=64 time=0.481 ms
--- 10.0.0.251 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.428/9.170/43.519/17.175 ms
This may take a while during the first run, because the hosts have to fetch the Docker images first.
Writing MaxiNet experiments containing Docker containers is pretty straightforward. First, include the required class:
from MaxiNet.Frontend.container import Docker
Now create and add new hosts as follows:
d1 = topo.addHost("d1", cls=Docker, ip="10.0.0.251", dimage="ubuntu:trusty")
Of course any valid Docker image can be used here. A complete example can be found under MaxiNet/Frontend/examples/dockerSimplePing.py
If an Experiment object is not stopped properly (for example, because of an exception) the Docker containers on the workers will not be removed. The experiment cannot be re-run until these containers are removed manually. Therefore it is a good practice to enclose the actual experiment in a try-block and to stop the experiment in the finally-catch:
exp.setup()
try:
# some experiments ...
finally:
exp.stop()
The Docker host class has a few additional attributes and methods to the default host class, for example to set the CPU time or memory limit. These are available via the corresponding NodeWrapper. A complete example containing all available methods and attributed can be found under MaxiNet/Frontend/examples/dockerNodeWrapper.py
If in an experiment some containers produce a high computational load it might be useful to describe the placement of hosts to workers manually.
This can be done by specifying a node mapping. In the following example the switch "s1" is mapped to worker 0 and "s2" is mapped to worker 1 (workers are enumerated consecutively, starting with 0)
mapping = {
"s1": 0,
"s2": 1
}
exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch, nodemapping=mapping)
Unfortunately, hosts cannot be placed separately from switches. Therefore, in order to have only one host on a worker it might be necessary to add an additional switch. For example to place host "h1" on a separate worker create a topology like this:
h1 -- s1 -- {Net}
Then create a node mapping that maps only the switch "s1" to the designated worker. The host "h1" will be placed on the same worker.
In some cases it might me be useful to set up a cache for Docker images, so they only have to be fetched once. This is a link to the official documentation https://docs.docker.com/registry/recipes/mirror/