GraphML to Python Topology Code
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)
[caption id="attachment_1062" align="aligncenter" width="300"] OpenDayLight[/caption]
[caption id="attachment_1063" align="aligncenter" width="300"] OpenDayLight[/caption]
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) )