# openleon distributed edge data centers with containers import unittest import sys import time import os import random import subprocess sys.path.append('.') from time import sleep from mininet.net import Containernet from mininet.node import Ryu, OVSSwitch from mininet.node import Node, Host from mininet.node import Controller from mininet.node import Docker from mininet.clean import cleanup from mininet.link import TCLink, Link from mininet.cli import CLI from mininet.term import cleanUpScreens, makeTerms from mininet.log import setLogLevel, info from sys import exit import os.path from subprocess import Popen, STDOUT, PIPE def topology(): "Create a network with some docker containers acting as hosts." net = Containernet(controller=Controller,switch=OVSSwitch, link=TCLink, waitConnected=True) info('*** Adding controller\n') net.addController('c0') info('*** Adding switches\n') s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') s3 = net.addSwitch('s3') info('*** Adding docker containers and hosts\n') ###### FIRST edge data center hepc = net.addHost('hepc', ip='10.0.0.1/24', mac="00:00:00:00:00:01") h1 = net.addHost('h1', ip='10.0.0.2/24', mac="00:00:00:00:00:02") d1 = net.addDocker('d1', ip='10.0.0.3/24', dimage="furiousgeorge/cpuload", cpu_period=50000,cpu_quota=25000) #d1.sendCmd("./CPULoadGenerator.py -c 0 -l 0.3 -d 30") d2 = net.addDocker('d2', ip='10.0.0.4/24', dimage="furiousgeorge/cpuload", cpu_period=50000,cpu_quota=25000) d3 = net.addDocker('d3', ip='10.0.0.5/24', dimage="ubuntu:trusty") d4 = net.addDocker('d4', ip='10.0.0.6/24', dimage="ubuntu:trusty") h2 = net.addHost('h2', ip='10.0.0.7/24',mac="00:00:00:00:00:03") ###### SECOND edge data center h3 = net.addHost('h3', ip='10.0.0.101/24',mac="00:00:00:00:00:04") d5 = net.addDocker('d5', ip='10.0.0.102/24', dimage="sofianinho/iperf3:3.6-ubuntu18.04")# this sets up a iperf3 docker d6 = net.addDocker('d6', ip='10.0.0.103/24', dimage="ubuntu:trusty") d7 = net.addDocker('d7', ip='10.0.0.104/24', dimage="ubuntu:trusty") h4 = net.addHost('h4', ip='10.0.0.105/24',mac="00:00:00:00:00:05") info('*** Creating links\n') net.addLink(hepc, s1,bw=1000)# port 2 of s1, link at 1 Gbps net.addLink(h1, s2,bw=1000)# port 3 of s1, link at 1 Gbps net.addLink(h2, s2,bw=1000)# port 4 of s1, link at 1 Gbps net.addLink(d1, s1) net.addLink(d2, s1) net.addLink(d3, s1) net.addLink(d4, s1) net.addLink(s1, s2) net.addLink(s1, s3, cls=TCLink, delay='4ms') net.addLink(s3, h3,bw=1000)# port 2 of s2 net.addLink(s3, h4,bw=1000)# port 3 of s2 net.addLink(s3, d5) net.addLink(s3, d6) net.addLink(s3, d7) # router configuration # building the network net.build() # to work, recall to include the NAT right after having created all the links and build the network net.addNAT().configDefault() net.hosts[0].cmd('sysctl net.ipv4.ip_forward=1') net.hosts[0].cmd('iptables -t nat -A POSTROUTING -j MASQUERADE') for i in range (len(net.hosts)-1): #print(net.hosts[i+1]) net.hosts[1+i].cmd("sudo ip route add 10.16.0.0/12 via 10.0.0.1") info('*** Starting network\n') net.start() info('*** Running CLI\n') CLI(net) info('*** Stopping network\n') net.stop() if __name__ == '__main__': setLogLevel('info') topology()