Last active
August 29, 2015 14:13
-
-
Save tribela/cf137029bbe2a93abc4c to your computer and use it in GitHub Desktop.
Mininet custom topologies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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