def createNet(self, nswitches=1, nhosts=0, ndockers=0, autolinkswitches=False): """ Creates a Mininet instance and automatically adds some nodes to it. """ self.net = Containernet(controller=Controller) self.net.addController('c0') # add some switches for i in range(0, nswitches): self.s.append(self.net.addSwitch('s%d' % i)) # if specified, chain all switches if autolinkswitches: for i in range(0, len(self.s) - 1): self.net.addLink(self.s[i], self.s[i + 1]) # add some hosts for i in range(0, nhosts): self.h.append(self.net.addHost('h%d' % i)) # add some dockers for i in range(0, ndockers): self.d.append(self.net.addDocker('d%d' % i, dimage="ubuntu:trusty"))
def topology(): "Create a network with some docker containers acting as hosts." net = Containernet(controller=Controller) info('*** Adding controller\n') net.addController('c0') info('*** Adding docker containers\n') d1 = net.addDocker('d1', ip='10.0.0.251', dimage="mpeuster/stress", cpuset_cpus="0,1") d1.sendCmd("./start.sh") info('*** Starting network\n') net.start() info('*** Running CLI\n') CLI(net) info('*** Stopping network') net.stop()
def topology(): net = Containernet() info('*** Adding docker containers\n') sta1 = net.addStation('sta1', ip='10.0.0.3', mac='00:02:00:00:00:10', cls=DockerSta, dimage="ubuntu:trusty", cpu_shares=20) sta2 = net.addStation('sta2', ip='10.0.0.4', mac='00:02:00:00:00:11', cls=DockerSta, dimage="ubuntu:trusty", cpu_shares=20) ap1 = net.addAccessPoint('ap1') c0 = net.addController('c0') info('*** Configuring WiFi nodes\n') net.configureWifiNodes() info('*** Starting network\n') net.start() ap1.start([c0]) makeTerm(sta1, cmd="bash -c 'apt-get update && apt-get install iw;'") makeTerm(sta2, cmd="bash -c 'apt-get update && apt-get install iw;'") #sta1.cmd('iw dev sta1-wlan0 connect new-ssid') #sta2.cmd('iw dev sta2-wlan0 connect new-ssid') info('*** Running CLI\n') CLI(net) info('*** Stopping network\n') net.stop()
#!/usr/bin/python """ This is the most simple example to showcase Containernet. """ from mininet.node import Controller from mininet.log import info, setLogLevel from containernet.cli import CLI from containernet.link import TCLink from containernet.net import Containernet setLogLevel('info') net = Containernet(controller=Controller) info('*** Adding controller\n') net.addController('c0') info('*** Adding docker containers\n') server = net.addDocker('server', ip='10.0.0.251', dcmd="python app.py", dimage="server_example:latest") client = net.addDocker('client', ip='10.0.0.252', dimage="curl_example:latest") info('*** Adding switches\n') s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') info('*** Creating links\n') net.addLink(server, s1) net.addLink(s1, s2, cls=TCLink, delay='100ms', bw=1) net.addLink(s2, client) info('*** Starting network\n') net.start() info('\nclient.cmd("time curl 10.0.0.251/9999"):\n')
from mininet.node import Controller from mininet.log import info, setLogLevel from containernet.cli import CLI from containernet.link import TCLink from containernet.net import Containernet setLogLevel('info') net = Containernet(controller=Controller) info('*** Adding controller\n') net.addController('c0') info('*** Adding docker containers\n') d1 = net.addDocker('d1', volumes=["/home/user/vol1:/vol1"], ip='10.0.0.251', dimage="ubuntu:trusty") d2 = net.addDocker('d2', volumes=["/home/user/vol1:/vol1"], ip='10.0.0.252', dimage="ubuntu:trusty") info('*** Adding switches\n') s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') info('*** Creating links\n') net.addLink(d1, d2) net.addLink(s1, s2, cls=TCLink, delay='100ms', bw=1) net.addLink(s2, d2) info('*** Starting network\n') net.start() info('*** Testing connectivity\n') net.ping([d1, d2])
class simpleTestTopology(unittest.TestCase): """ Helper class to do basic test setups. s1 -- s2 -- s3 -- ... -- sN """ def __init__(self, *args, **kwargs): self.net = None self.s = [] # list of switches self.h = [] # list of hosts self.d = [] # list of docker containers self.docker_cli = None super(simpleTestTopology, self).__init__(*args, **kwargs) def createNet(self, nswitches=1, nhosts=0, ndockers=0, autolinkswitches=False): """ Creates a Mininet instance and automatically adds some nodes to it. """ self.net = Containernet(controller=Controller) self.net.addController('c0') # add some switches for i in range(0, nswitches): self.s.append(self.net.addSwitch('s%d' % i)) # if specified, chain all switches if autolinkswitches: for i in range(0, len(self.s) - 1): self.net.addLink(self.s[i], self.s[i + 1]) # add some hosts for i in range(0, nhosts): self.h.append(self.net.addHost('h%d' % i)) # add some dockers for i in range(0, ndockers): self.d.append(self.net.addDocker('d%d' % i, dimage="ubuntu:trusty")) def startNet(self): self.net.start() def stopNet(self): self.net.stop() self.s = [] self.h = [] self.d = [] def getDockerCli(self): """ Helper to interact with local docker instance. """ if self.docker_cli is None: self.docker_cli = docker.APIClient( base_url='unix://var/run/docker.sock') return self.docker_cli @staticmethod def setUp(): pass @staticmethod def tearDown(): cleanup() # make sure that all pending docker containers are killed with open(os.devnull, 'w') as devnull: subprocess.call( "docker rm -f $(docker ps --filter 'label=com.containernet' -a -q)", stdout=devnull, stderr=devnull, shell=True) def getContainernetContainers(self): """ List the containers managed by containernet """ return self.getDockerCli().containers( filters={"label": "com.containernet"})
#!/usr/bin/python """ This topology is used to test the compatibility of different Docker images. The images to be tested can be found in 'examples/example-containers'. They are build with './build.sh' """ from mininet.node import Controller from mininet.log import info, setLogLevel from containernet.cli import CLI from containernet.net import Containernet setLogLevel('info') net = Containernet(controller=Controller) info('*** Adding controller\n') net.addController('c0') info('*** Adding docker containers\n') d1 = net.addDocker('d1', dimage="ubuntu:trusty") d2 = net.addDocker('d2', dimage="containernet_example:ubuntu1404") d3 = net.addDocker('d3', dimage="containernet_example:ubuntu1604") d4 = net.addDocker('d4', dimage="containernet_example:ubuntu1804") d5 = net.addDocker('d5', dimage="containernet_example:centos6") d6 = net.addDocker('d6', dimage="containernet_example:centos7") info('*** Adding switches\n') s1 = net.addSwitch('s1') info('*** Creating links\n') net.addLink(d1, s1) net.addLink(d2, s1)
#!/usr/bin/python """ Example to test the automated CMD field execution feature. """ from mininet.node import Controller from mininet.log import info, setLogLevel from containernet.cli import CLI from containernet.link import TCLink from containernet.net import Containernet setLogLevel('info') net = Containernet(controller=Controller) info('*** Adding controller\n') net.addController('c0') info('*** Adding docker containers\n') # normal container without CMD d1 = net.addDocker('d1', ip='10.0.0.251', dimage="ubuntu:trusty") # HTTPD container with CMD that starts httpd in foreground d2 = net.addDocker('d2', ip='10.0.0.252', dimage="httpd:latest") info('*** Adding switches\n') s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') info('*** Creating links\n') net.addLink(d1, s1) net.addLink(s1, s2, cls=TCLink, delay='100ms', bw=1) net.addLink(s2, d2) info('*** Starting network\n') net.start() d2.start() info('*** Running CLI\n')
def topology(): "Create a network with some docker containers acting as hosts." net = Containernet(controller=Controller) info('*** Adding controller\n') net.addController('c0') info('*** Adding hosts\n') h1 = net.addHost('h1') h2 = net.addHost('h2') info('*** Adding docker containers\n') d1 = net.addDocker('d1', ip='10.0.0.251', dimage="ubuntu:trusty") d2 = net.addDocker('d2', ip='10.0.0.252', dimage="ubuntu:trusty", cpu_period=50000, cpu_quota=25000) d3 = net.addHost('d3', ip='11.0.0.253', cls=Docker, dimage="ubuntu:trusty", cpu_shares=20) # using advanced features like volumes and exposed ports net.addDocker('d5', dimage="ubuntu:trusty", volumes=["/:/mnt/vol1:rw"], ports=[9999], port_bindings={9999: 9999}, publish_all_ports=True) info('*** Adding switch\n') s1 = net.addSwitch('s1') s2 = net.addSwitch('s2', cls=OVSSwitch) s3 = net.addSwitch('s3') info('*** Creating links\n') net.addLink(h1, s1) net.addLink(s1, d1) net.addLink(h2, s2) net.addLink(d2, s2) net.addLink(s1, s2) #net.addLink(s1, s2, cls=TCLink, delay="100ms", bw=1, loss=10) # try to add a second interface to a docker container net.addLink(d2, s3, params1={"ip": "11.0.0.254/8"}) net.addLink(d3, s3) info('*** Starting network\n') net.start() net.ping([d1, d2]) # our extended ping functionality net.ping([d1], manualdestip="10.0.0.252") net.ping([d2, d3], manualdestip="11.0.0.254") info('*** Dynamically add a container at runtime\n') d4 = net.addDocker('d4', dimage="ubuntu:trusty") # we have to specify a manual ip when we add a link at runtime net.addLink(d4, s1, params1={"ip": "10.0.0.254/8"}) # other options to do this #d4.defaultIntf().ifconfig("10.0.0.254 up") #d4.setIP("10.0.0.254") net.ping([d1], manualdestip="10.0.0.254") info('*** Running CLI\n') CLI(net) info('*** Stopping network') net.stop()