Skip to content

Instantly share code, notes, and snippets.

@pgorczak
Created March 14, 2018 11:13
Show Gist options
  • Save pgorczak/c8d12c5625d7c70f507f5d88f6ecd8b7 to your computer and use it in GitHub Desktop.
Save pgorczak/c8d12c5625d7c70f507f5d88f6ecd8b7 to your computer and use it in GitHub Desktop.
Bare bones example for multipath TCP with mininet
import subprocess
from time import sleep
from mininet.net import Mininet
from mininet.node import Host, Switch
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import setLogLevel
from mininet.topo import Topo
def write_sysctl(key, value):
""" Write kernel parameters. """
subprocess.check_output('sysctl -w {}={}'.format(key, value), shell=True)
def setup_mptcp(net):
hosts = [v for v in net.values() if isinstance(v, Host)]
switches = [v for v in net.values() if isinstance(v, Switch)]
for switch_i, switch in enumerate(switches, start=1):
for host_i, host in enumerate(hosts, start=1):
# connectionsTo returns list of (host-interface, switch-interface)
# we want the host interface connected to the switch
interface, _ = host.connectionsTo(switch)[0]
interface.setIP('10.0.{}.{}/24'.format(switch_i, host_i))
class MPTopo(Topo):
def build(self, hostnames, number_of_paths=2, bw=5):
linkopt = dict(bw=bw)
for h in hostnames:
self.addHost(h)
for i_p in range(0, number_of_paths):
s = self.addSwitch('s{}'.format(i_p))
for h in self.hosts():
self.addLink(h, s, **linkopt)
if '__main__' == __name__:
setLogLevel('info')
hostnames = ['h1', 'h2']
net = Mininet(topo=MPTopo(hostnames), link=TCLink)
write_sysctl('net.mptcp.mptcp_enabled', 1)
setup_mptcp(net)
net.start()
# We need to give mptcp some time
print('=========================================================')
print('Set up two paths with 5 MBit each. Running iperf in 3s...')
print('=========================================================')
sleep(3)
# CLI(net)
h1, h2 = [net.get(n) for n in hostnames]
h1.cmd('iperf -s &')
h2.cmdPrint('iperf -c 10.0.1.1 -i 1')
net.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment