Skip to content

Instantly share code, notes, and snippets.

@tribela
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tribela/cf137029bbe2a93abc4c to your computer and use it in GitHub Desktop.
Save tribela/cf137029bbe2a93abc4c to your computer and use it in GitHub Desktop.
Mininet custom topologies
from mininet.topo import Topo
class RingTopo(Topo):
def __init__(self, switch_count=4, host_count=1):
Topo.__init__(self)
switches = [self.addSwitch('s{0}'.format(i+1))
for i in range(switch_count)]
hosts = [self.addHost('h{0}'.format(i+1))
for i in range(switch_count * host_count)]
for i in range(switch_count):
self.addLink(switches[i-1], switches[i])
for j in range(i * host_count, (i + 1) * host_count):
self.addLink(switches[i], hosts[j])
class WebTopo(Topo):
def __init__(self, switch_count=4, host_count=1):
Topo.__init__(self)
switches = [self.addSwitch('s{0}'.format(i+1))
for i in range(switch_count)]
hosts = [self.addHost('h{0}'.format(i+1))
for i in range(switch_count * host_count)]
for i in range(switch_count):
for j in range(i+1, switch_count):
self.addLink(switches[i], switches[j])
for j in range(i * host_count, (i + 1) * host_count):
self.addLink(switches[i], hosts[j])
class IslandTopo(Topo):
def __init__(self, switch_count=2, host_count=1):
Topo.__init__(self)
switches = [self.addSwitch('s{0}'.format(i+1))
for i in range(switch_count)]
hosts = [self.addHost('h{0}'.format(i+1))
for i in range(switch_count * host_count)]
for i in range(switch_count * host_count):
sw = switches[i / host_count]
host = hosts[i]
self.addLink(sw, host)
topos = {
'ring': RingTopo,
'web': WebTopo,
'island': IslandTopo,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment