sigit.cloud
about gallery street 📸

GraphML to Python Topology Code

2015-02-07

I just read this interesting project on a tool to convert GraphML topology into usable Python code to be simulated with Mininet and OpenFlow based virtual switches.

Very useful to mimic real world networks to be executed on Mininet without having to code the Python scripts from scratch.

I did use 2 core vCPU, 3GB vRAM Ubuntu VM to load and simulate the DFN (from https://topology-zoo.org/dataset.html) network below (with OpenDayLight controller)

DFN

OpenDayLight

OpenDayLight

and the vCPU went 100% instantly. Seems I will need to upgrade my VM.

Try it and have fun!

References: 1. https://graphml.graphdrawing.org 2. https://141.13.92.69/index.php/projects/auto-mininet 3. https://topology-zoo.org/dataset.html

Mininet command:

sudo mn --custom Dfn.graphml-generated-Mininet-Topo.py --topo generated --controller remote,ip=127.0.0.1 --link tc

Dfn.graphml-generated-Mininet-Topo.py

#!/usr/bin/python

"""
Custom topology for Mininet, generated by GraphML-Topo-to-Mininet-Network-Generator.
"""
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.node import Node
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.util import dumpNodeConnections

class GeneratedTopo( Topo ):
 "Internet Topology Zoo Specimen."

def \_\_init\_\_( self, \*\*opts ):
 "Create a topology."

# Initialize Topology
 Topo.\_\_init\_\_( self, \*\*opts )

# add nodes, switches first...
 CHE = self.addSwitch( 's0' )
 LEI = self.addSwitch( 's1' )
 ADH = self.addSwitch( 's2' )
 DRE = self.addSwitch( 's3' )
 GSI = self.addSwitch( 's4' )
 HEI = self.addSwitch( 's5' )
 JEN = self.addSwitch( 's6' )
 ILM = self.addSwitch( 's7' )
 DeCix1 = self.addSwitch( 's8' )
 Geant = self.addSwitch( 's9' )
 FZK = self.addSwitch( 's10' )
 STU = self.addSwitch( 's11' )
 DeCix2 = self.addSwitch( 's12' )
 Telia = self.addSwitch( 's13' )
 BIE = self.addSwitch( 's14' )
 Telekom1 = self.addSwitch( 's15' )
 GOE = self.addSwitch( 's16' )
 BRE = self.addSwitch( 's17' )
 WUP = self.addSwitch( 's18' )
 BIR = self.addSwitch( 's19' )
 BON = self.addSwitch( 's20' )
 MAR = self.addSwitch( 's21' )
 GIE = self.addSwitch( 's22' )
 KAS = self.addSwitch( 's23' )
 PAD = self.addSwitch( 's24' )
 EWE = self.addSwitch( 's25' )
 Telekom2 = self.addSwitch( 's26' )
 MUE = self.addSwitch( 's27' )
 SAA = self.addSwitch( 's28' )
 GC = self.addSwitch( 's29' )
 DES = self.addSwitch( 's30' )
 HAM = self.addSwitch( 's31' )
 KIE = self.addSwitch( 's32' )
 ROS = self.addSwitch( 's33' )
 MAG = self.addSwitch( 's34' )
 BRA = self.addSwitch( 's35' )
 KAI = self.addSwitch( 's36' )
 GRE = self.addSwitch( 's37' )
 DOR = self.addSwitch( 's38' )
 BOC = self.addSwitch( 's39' )
 FHM = self.addSwitch( 's40' )
 REG = self.addSwitch( 's41' )
 AUG = self.addSwitch( 's42' )
 GAR = self.addSwitch( 's43' )
 DUI = self.addSwitch( 's44' )
 FZJ = self.addSwitch( 's45' )
 AAC = self.addSwitch( 's46' )
 WUE = self.addSwitch( 's47' )
 TUB = self.addSwitch( 's48' )
 HUB = self.addSwitch( 's49' )
 HAN = self.addSwitch( 's50' )
 FRA = self.addSwitch( 's51' )
 POT = self.addSwitch( 's52' )
 ERL = self.addSwitch( 's53' )
 BAY = self.addSwitch( 's54' )
 FFO = self.addSwitch( 's55' )
 ZIB = self.addSwitch( 's56' )
 ZEU = self.addSwitch( 's57' )

# ... and now hosts
 CHE\_host = self.addHost( 'h0' )
 LEI\_host = self.addHost( 'h1' )
 ADH\_host = self.addHost( 'h2' )
 DRE\_host = self.addHost( 'h3' )
 GSI\_host = self.addHost( 'h4' )
 HEI\_host = self.addHost( 'h5' )
 JEN\_host = self.addHost( 'h6' )
 ILM\_host = self.addHost( 'h7' )
 DeCix1\_host = self.addHost( 'h8' )
 Geant\_host = self.addHost( 'h9' )
 FZK\_host = self.addHost( 'h10' )
 STU\_host = self.addHost( 'h11' )
 DeCix2\_host = self.addHost( 'h12' )
 Telia\_host = self.addHost( 'h13' )
 BIE\_host = self.addHost( 'h14' )
 Telekom1\_host = self.addHost( 'h15' )
 GOE\_host = self.addHost( 'h16' )
 BRE\_host = self.addHost( 'h17' )
 WUP\_host = self.addHost( 'h18' )
 BIR\_host = self.addHost( 'h19' )
 BON\_host = self.addHost( 'h20' )
 MAR\_host = self.addHost( 'h21' )
 GIE\_host = self.addHost( 'h22' )
 KAS\_host = self.addHost( 'h23' )
 PAD\_host = self.addHost( 'h24' )
 EWE\_host = self.addHost( 'h25' )
 Telekom2\_host = self.addHost( 'h26' )
 MUE\_host = self.addHost( 'h27' )
 SAA\_host = self.addHost( 'h28' )
 GC\_host = self.addHost( 'h29' )
 DES\_host = self.addHost( 'h30' )
 HAM\_host = self.addHost( 'h31' )
 KIE\_host = self.addHost( 'h32' )
 ROS\_host = self.addHost( 'h33' )
 MAG\_host = self.addHost( 'h34' )
 BRA\_host = self.addHost( 'h35' )
 KAI\_host = self.addHost( 'h36' )
 GRE\_host = self.addHost( 'h37' )
 DOR\_host = self.addHost( 'h38' )
 BOC\_host = self.addHost( 'h39' )
 FHM\_host = self.addHost( 'h40' )
 REG\_host = self.addHost( 'h41' )
 AUG\_host = self.addHost( 'h42' )
 GAR\_host = self.addHost( 'h43' )
 DUI\_host = self.addHost( 'h44' )
 FZJ\_host = self.addHost( 'h45' )
 AAC\_host = self.addHost( 'h46' )
 WUE\_host = self.addHost( 'h47' )
 TUB\_host = self.addHost( 'h48' )
 HUB\_host = self.addHost( 'h49' )
 HAN\_host = self.addHost( 'h50' )
 FRA\_host = self.addHost( 'h51' )
 POT\_host = self.addHost( 'h52' )
 ERL\_host = self.addHost( 'h53' )
 BAY\_host = self.addHost( 'h54' )
 FFO\_host = self.addHost( 'h55' )
 ZIB\_host = self.addHost( 'h56' )
 ZEU\_host = self.addHost( 'h57' )

# add edges between switch and corresponding host
 self.addLink( CHE , CHE\_host )
 self.addLink( LEI , LEI\_host )
 self.addLink( ADH , ADH\_host )
 self.addLink( DRE , DRE\_host )
 self.addLink( GSI , GSI\_host )
 self.addLink( HEI , HEI\_host )
 self.addLink( JEN , JEN\_host )
 self.addLink( ILM , ILM\_host )
 self.addLink( DeCix1 , DeCix1\_host )
 self.addLink( Geant , Geant\_host )
 self.addLink( FZK , FZK\_host )
 self.addLink( STU , STU\_host )
 self.addLink( DeCix2 , DeCix2\_host )
 self.addLink( Telia , Telia\_host )
 self.addLink( BIE , BIE\_host )
 self.addLink( Telekom1 , Telekom1\_host )
 self.addLink( GOE , GOE\_host )
 self.addLink( BRE , BRE\_host )
 self.addLink( WUP , WUP\_host )
 self.addLink( BIR , BIR\_host )
 self.addLink( BON , BON\_host )
 self.addLink( MAR , MAR\_host )
 self.addLink( GIE , GIE\_host )
 self.addLink( KAS , KAS\_host )
 self.addLink( PAD , PAD\_host )
 self.addLink( EWE , EWE\_host )
 self.addLink( Telekom2 , Telekom2\_host )
 self.addLink( MUE , MUE\_host )
 self.addLink( SAA , SAA\_host )
 self.addLink( GC , GC\_host )
 self.addLink( DES , DES\_host )
 self.addLink( HAM , HAM\_host )
 self.addLink( KIE , KIE\_host )
 self.addLink( ROS , ROS\_host )
 self.addLink( MAG , MAG\_host )
 self.addLink( BRA , BRA\_host )
 self.addLink( KAI , KAI\_host )
 self.addLink( GRE , GRE\_host )
 self.addLink( DOR , DOR\_host )
 self.addLink( BOC , BOC\_host )
 self.addLink( FHM , FHM\_host )
 self.addLink( REG , REG\_host )
 self.addLink( AUG , AUG\_host )
 self.addLink( GAR , GAR\_host )
 self.addLink( DUI , DUI\_host )
 self.addLink( FZJ , FZJ\_host )
 self.addLink( AAC , AAC\_host )
 self.addLink( WUE , WUE\_host )
 self.addLink( TUB , TUB\_host )
 self.addLink( HUB , HUB\_host )
 self.addLink( HAN , HAN\_host )
 self.addLink( FRA , FRA\_host )
 self.addLink( POT , POT\_host )
 self.addLink( ERL , ERL\_host )
 self.addLink( BAY , BAY\_host )
 self.addLink( FFO , FFO\_host )
 self.addLink( ZIB , ZIB\_host )
 self.addLink( ZEU , ZEU\_host )

# add edges between switches
 self.addLink( CHE , LEI, bw=1, delay='0.348009502297ms')
 self.addLink( CHE , DRE, bw=1, delay='0.376365456561ms')
 self.addLink( LEI , ERL, bw=1, delay='1.16719306649ms')
 self.addLink( LEI , JEN, bw=1, delay='0.355698784117ms')
 self.addLink( LEI , Telekom1, bw=1, delay='0.206869326668ms')
 self.addLink( ADH , ZIB, bw=1, delay='0.0ms')
 self.addLink( ADH , HUB, bw=1, delay='0.0ms')
 self.addLink( DRE , POT, bw=1, delay='0.713579558888ms')
 self.addLink( DRE , ERL, bw=1, delay='1.59379224328ms')
 self.addLink( GSI , FRA, bw=1, delay='0.14028079649ms')
 self.addLink( GSI , HEI, bw=1, delay='0.262213587747ms')
 self.addLink( HEI , FZK, bw=1, delay='0.240625042555ms')
 self.addLink( JEN , ILM, bw=1, delay='0.35622237265ms')
 self.addLink( ILM , ERL, bw=1, delay='0.620413214389ms')
 self.addLink( DeCix1 , FRA, bw=1, delay='1.25421101599ms')
 self.addLink( Geant , FRA, bw=1, delay='1.25421101599ms')
 self.addLink( FZK , STU, bw=1, delay='0.144592339751ms')
 self.addLink( FZK , FRA, bw=1, delay='0.636656987487ms')
 self.addLink( FZK , KAI, bw=1, delay='0.300814574066ms')
 self.addLink( STU , GAR, bw=1, delay='0.214484212673ms')
 self.addLink( DeCix2 , POT, bw=1, delay='1.41957762385ms')
 self.addLink( Telia , POT, bw=1, delay='1.41957762385ms')
 self.addLink( BIE , PAD, bw=1, delay='0.176569917836ms')
 self.addLink( BIE , HAN, bw=1, delay='0.279515994236ms')
 self.addLink( BIE , MUE, bw=1, delay='0.0875559537421ms')
 self.addLink( GOE , HAN, bw=1, delay='0.470763474509ms')
 self.addLink( GOE , KAS, bw=1, delay='0.15434324359ms')
 self.addLink( BRE , EWE, bw=1, delay='0.332944681645ms')
 self.addLink( BRE , HAN, bw=1, delay='0.544897616985ms')
 self.addLink( BRE , HAM, bw=1, delay='0.715773701989ms')
 self.addLink( WUP , BIR, bw=1, delay='0.207267941498ms')
 self.addLink( WUP , DOR, bw=1, delay='0.154355662425ms')
 self.addLink( BIR , FRA, bw=1, delay='1.01149093517ms')
 self.addLink( BIR , BON, bw=1, delay='0.133558978806ms')
 self.addLink( BON , AAC, bw=1, delay='0.502276644953ms')
 self.addLink( MAR , GIE, bw=1, delay='0.144686470973ms')
 self.addLink( MAR , KAS, bw=1, delay='0.392023761068ms')
 self.addLink( GIE , FRA, bw=1, delay='0.264351773171ms')
 self.addLink( KAS , PAD, bw=1, delay='0.248670904867ms')
 self.addLink( EWE , MUE, bw=1, delay='0.692335923494ms')
 self.addLink( Telekom2 , HAN, bw=1, delay='0.760247192466ms')
 self.addLink( MUE , DUI, bw=1, delay='0.279545618516ms')
 self.addLink( SAA , FRA, bw=1, delay='0.847856768154ms')
 self.addLink( SAA , KAI, bw=1, delay='0.276965393733ms')
 self.addLink( GC , FRA, bw=1, delay='0.847856768154ms')
 self.addLink( DES , TUB, bw=1, delay='1.33859282937ms')
 self.addLink( DES , HAM, bw=1, delay='0.0ms')
 self.addLink( KIE , ROS, bw=1, delay='0.715790180937ms')
 self.addLink( KIE , HAN, bw=1, delay='1.11748574584ms')
 self.addLink( ROS , HAN, bw=1, delay='1.44677225693ms')
 self.addLink( ROS , GRE, bw=1, delay='0.527568677262ms')
 self.addLink( MAG , BRA, bw=1, delay='0.231863764378ms')
 self.addLink( MAG , POT, bw=1, delay='0.334637045159ms')
 self.addLink( BRA , HAN, bw=1, delay='0.212435154403ms')
 self.addLink( KAI , FRA, bw=1, delay='0.5842577938ms')
 self.addLink( GRE , POT, bw=1, delay='0.972987536079ms')
 self.addLink( DOR , BOC, bw=1, delay='0.0472829211761ms')
 self.addLink( BOC , DUI, bw=1, delay='0.0448722027004ms')
 self.addLink( FHM , REG, bw=1, delay='0.479518195543ms')
 self.addLink( FHM , GAR, bw=1, delay='0.0667104114277ms')
 self.addLink( REG , ERL, bw=1, delay='0.443948081243ms')
 self.addLink( AUG , GAR, bw=1, delay='0.171249824777ms')
 self.addLink( AUG , ERL, bw=1, delay='0.690016189521ms')
 self.addLink( GAR , FRA, bw=1, delay='0.556658683865ms')
 self.addLink( DUI , HAN, bw=1, delay='0.134024265389ms')
 self.addLink( DUI , FZJ, bw=1, delay='0.354918347811ms')
 self.addLink( FZJ , AAC, bw=1, delay='0.159430386686ms')
 self.addLink( AAC , FRA, bw=1, delay='1.42266490321ms')
 self.addLink( WUE , FRA, bw=1, delay='0.689914750376ms')
 self.addLink( WUE , ERL, bw=1, delay='0.508585024764ms')
 self.addLink( TUB , ZIB, bw=1, delay='0.0ms')
 self.addLink( TUB , HUB, bw=1, delay='0.0ms')
 self.addLink( TUB , POT, bw=1, delay='0.133578022208ms')
 self.addLink( TUB , ZEU, bw=1, delay='0.110939794602ms')
 self.addLink( HAN , FRA, bw=1, delay='1.10678548962ms')
 self.addLink( HAN , POT, bw=1, delay='0.616649296599ms')
 self.addLink( HAN , ERL, bw=1, delay='1.29176975519ms')
 self.addLink( HAN , FFO, bw=1, delay='0.384885409742ms')
 self.addLink( FRA , POT, bw=1, delay='0.861872589539ms')
 self.addLink( FRA , ERL, bw=1, delay='1.1407196248ms')
 self.addLink( POT , ERL, bw=1, delay='1.07937824508ms')
 self.addLink( POT , BAY, bw=1, delay='1.06350177973ms')
 self.addLink( POT , FFO, bw=1, delay='0.399572020017ms')
 self.addLink( POT , ZIB, bw=1, delay='0.133578022208ms')
 self.addLink( ERL , BAY, bw=1, delay='0.346801272227ms')
 self.addLink( FFO , ZIB, bw=1, delay='0.360341909093ms')
 self.addLink( ZIB , ZEU, bw=1, delay='0.110939794602ms')

topos = { 'generated': ( lambda: GeneratedTopo() ) }

# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS

# the following code produces an executable script working with a remote controller and providing ssh access to the the mininet hosts from within the ubuntu vm

controller\_ip = '127.0.0.1'

def setupNetwork(controller\_ip):
 "Create network and run simple performance test"

# check if remote controller's ip was set, else set it to localhost

 topo = GeneratedTopo()
 if controller\_ip == '':

controller\_ip = '10.0.2.2';

# controller\_ip = '127.0.0.1';

net = Mininet(topo=topo, controller=lambda a: RemoteController( a, ip=controller\_ip, port=6633 ), host=CPULimitedHost, link=TCLink)
 return net

def connectToRootNS( network, switch, ip, prefixLen, routes ):
 "Connect hosts to root namespace via switch. Starts network."
 "network: Mininet() network object"
 "switch: switch to connect to root namespace"
 "ip: IP address for root namespace node"
 "prefixLen: IP address prefix length (e.g. 8, 16, 24)"
 "routes: host networks to route to"

# Create a node in root namespace and link to switch 0

 root = Node( 'root', inNamespace=False )
 intf = TCLink( root, switch ).intf1
 root.setIP( ip, prefixLen, intf )

# Start network that now includes link to root namespace

 network.start()

# Add routes from root ns to hosts

 for route in routes:
 root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )

def sshd( network, cmd='/usr/sbin/sshd', opts='-D' ):
 "Start a network, connect it to root ns, and run sshd on all hosts."
 switch = network.switches\[ 0 \] # switch to use
 ip = '10.123.123.1' # our IP address on host network
 routes = \[ '10.0.0.0/8' \] # host networks to route to
 connectToRootNS( network, switch, ip, 8, routes )
 for host in network.hosts:
 host.cmd( cmd + ' ' + opts + '&' )

# DEBUGGING INFO
 print
 print "Dumping host connections"
 dumpNodeConnections(network.hosts)
 print
 print "\*\*\* Hosts are running sshd at the following addresses:"
 print
 for host in network.hosts:
 print host.name, host.IP()
 print
 print "\*\*\* Type 'exit' or control-D to shut down network"
 print
 print "\*\*\* For testing network connectivity among the hosts, wait a bit for the controller to create all the routes, then do 'pingall' on the mininet console."
 print

CLI( network )
 for host in network.hosts:
 host.cmd( 'kill %' + cmd )
 network.stop()

if \_\_name\_\_ == '\_\_main\_\_':
 setLogLevel('info')

setLogLevel('debug')

 sshd( setupNetwork(controller\_ip) )