Skip to content

Tutorial 101 mininet (English)

Byungjoon Lee edited this page Apr 15, 2014 · 10 revisions

Table of Content

  1. How to create a network topology with mininet
  2. How to create a custom network topology with mininet
  3. How to create a custom network topology with multiple controllers

How to create a network topology with mininet

When you execute mininet, you normally specify the topology with mininet parameters.

sudo mn --controller=remote,127.0.0.1 --topo=tree,4

In the above example, the argument topo is used to create a tree topology, whose height is 4. Besides tree, you can specify linear, minimal, reversed, single. About the detail of each parameter, please consult the Mininet document.

How to create a custom network topology with mininet

Normally, we use a Python program.

#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel, info

def int2dpid( dpid ):
   try:
      dpid = hex( dpid )[ 2: ]
      dpid = '0' * ( 16 - len( dpid ) ) + dpid
      return dpid
   except IndexError:
      raise Exception( 'Unable to derive default datapath ID - '
                       'please either specify a dpid or use a '
		       'canonical switch name such as s23.' )

def emptyNet():
   "Create a simulated network"

   net = Mininet( controller=lambda a: RemoteController(a, ip='127.0.0.1' ))
   info( '*** Adding controller\n' )
   net.addController( 'c0' )
   
   info( '*** Adding hosts\n' )
   h1 = net.addHost( 'h1', ip='10.0.0.1' )
   h2 = net.addHost( 'h2', ip='10.0.0.2' )

   info( '*** Adding switches\n' )
   ovs1 = net.addSwitch( 'ovs1', dpid=int2dpid(1) )
   ovs2 = net.addSwitch( 'ovs2', dpid=int2dpid(2) )
   ovs3 = net.addSwitch( 'ovs3', dpid=int2dpid(3) )
   hp1 = net.addSwitch( 'hp1', dpid=int2dpid(11) )
   hp2 = net.addSwitch( 'hp2', dpid=int2dpid(21) )

   info( '*** Creating links\n' )
   net.addLink( h1, hp1 )
   net.addLink( h2, hp2 )
   net.addLink( hp1, hp2 )
   net.addLink( hp1, ovs1 )
   net.addLink( hp1, ovs2 )
   net.addLink( ovs1, hp2 )
   net.addLink( ovs2, ovs3 )
   net.addLink( ovs3, hp2 )
   
   info( '*** Starting network\n')
   net.start()
   
   info( '*** Running CLI\n' )
   CLI( net )
   
   info( '*** Stopping network' )
   net.stop()
   
if __name__ == '__main__':
   setLogLevel( 'info' )
   emptyNet()

Above program creates a custom network topology, and initiates Mininet CLI automatically. So, it's very convenient. As you can see, we assign an external controller to the topology.

The custom topology that the above program creates is as follows:

                                            +-----+
                         +-----------------+|ovs1 +------------------+
                         |                  +-----+                  |
                         |                                           |
                         |                                           |
                         |                                           |
                         |                                           +
         +---+         +-+-+                                       +----+        +----+
         |h1 +--------+|hp1|---------------------------------------|hp2 +-------+|h2  |
         +---+         +---+                                       +-+--+        +----+
                         +                                           |
                         |                                           |
                         |                                           |
                         |           +-----+          +------+       |
                         +-----------+ovs2 |+---------+ovs3  |+------+
                                     +-----+          +------+

How to create a custom network topology with multiple controllers

Just see the two examples: here and here.

Clone this wiki locally