Use Docker containers as hosts in Mininet emulations

Untuk mensimulasikan docker containers sebagai host pada mininet, gunakan containernet.

Containernet is a fork of the famous Mininet network emulator and allows to use Docker containers as hosts in emulated network topologies. This enables interesting functionalities to build networking/cloud emulators and testbeds.

Instalasi

Containernet membutuhkan ubuntu 16.04, jika sudah menginstall mininet, uninstall terlebih dahulu mininetnya

sudo apt-get install ansible git aptitude
git clone https://github.com/containernet/containernet.git
cd containernet/ansible
sudo ansible-playbook -i "localhost," -c local install.yml

Penggunaan

untuk menambahkan docker container sebagai host, perlu menggunakan files python untuk menginisialisasi topology. Berikut adalah contoh file pythonnya :

from mininet.net import Containernet
from mininet.node import RemoteController
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import info, setLogLevel
setLogLevel('info')

net = Containernet(controller=RemoteController)

info('*** Adding controller\n')
net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633)

info( '*** Adding Docker Container\n')
d1 = net.addDocker('d1', ip='1.1.1.1', dimage="ubuntu:trusty")
d2 = net.addDocker('d2', ip='1.1.1.2', dimage="ubuntu:trusty")

info( '*** Adding Hosts\n' )
h1 = net.addHost( 'h1', ip='1.1.1.3', mac='00:00:00:11:00:01' )
h2 = net.addHost( 'h2', ip='1.1.1.4', mac='00:00:00:22:00:02' )

info( '*** Adding switches\n' )
s1 = net.addSwitch('s1')

info( '*** Creating links\n' )
net.addLink(d1, s1)
net.addLink(d2, s1)
net.addLink(h1, s1)
net.addLink(h2, s1)

info('*** Starting network\n')
net.start()

info('*** Running CLI\n')
CLI(net)

info('*** Stopping network')
net.stop()

tidak ada yang berbeda dengan files python untuk mininet biasanya, hanya ada tambahan line berikut untuk menginisialisasi docker container sebagai node/host di mininet:

d1 = net.addDocker('d1', ip='1.1.1.1', dimage="ubuntu:trusty")
d2 = net.addDocker('d2', ip='1.1.1.2', dimage="ubuntu:trusty")

pada script tersebut, saya menggunakan remote controller dengan ip 127.0.0.1, disini saya menggunakan ONOS sebagai controllernya. Setelah controller onos berjalan, eksekusi script python diatas :

root@ubuntu:/home/ubuntu# python script.py 
*** Adding controller
*** Adding Docker Container
d1: kwargs {'ip': '1.1.1.1'}
d1: update resources {'cpu_quota': -1}
d2: kwargs {'ip': '1.1.1.2'}
d2: update resources {'cpu_quota': -1}
*** Adding Hosts
*** Adding switches
*** Creating links
*** Starting network
*** Configuring hosts
d1 d2 h1 h2 
*** Starting controller
c0 
*** Starting 1 switches
s1 ...
*** Running CLI
*** Starting CLI:
containernet> 

Lalu coba testing ping

containernet> pingall
*** Ping: testing ping reachability
d1 -> d2 h1 h2 
d2 -> d1 h1 h2 
h1 -> d1 d2 h2 
h2 -> d1 d2 h1 
*** Results: 0% dropped (12/12 received)

node yang terlihat di ONOS :

 

Comments are closed.