#!/usr/bin/env python
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.link import Link, TCLink,Intf
from subprocess import Popen, PIPE
from mininet.log import setLogLevel
import subprocess
if '__main__' == __name__:
setLogLevel('info')
net = Mininet(link=TCLink)
ret = subprocess.run(
["sysctl","-w","net.ipv4.tcp_congestion_control=dctcp"],
capture_output=True,
text=True,
check=True
)
print("stdout:", ret.stdout.strip())
print("stderr:", ret.stderr.strip())
ret = subprocess.run(
["sysctl","-w","net.ipv4.tcp_ecn=1"],
capture_output=True,
text=True,
check=True
)
print("stdout:", ret.stdout.strip())
print("stderr:", ret.stderr.strip())
h1 = net.addHost('h1', hostname='h1')
h2 = net.addHost('h2', hostname='h2')
r1 = net.addHost('r1', hostname='r1')
h1.cmd("sysctl -w net.ipv4.tcp_ecn=1")
h2.cmd("sysctl -w net.ipv4.tcp_ecn=1")
r1.cmd("sysctl -w net.ipv4.tcp_ecn=1")
linkopt={'bw':10}
net.addLink(r1,h1,cls=TCLink, bw = 20, delay = '5ms',loss = 10, enable_ecn=True)
net.addLink(r1,h2,cls=TCLink, bw = 5, delay = '50ms',loss = 10, enable_ecn=True)
net.build()
r1.cmd("ifconfig r1-eth0 0")
r1.cmd("ifconfig r1-eth1 0")
h1.cmd("ifconfig h1-eth0 0")
h2.cmd("ifconfig h2-eth0 0")
r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
r1.cmd("ifconfig r1-eth0 10.0.0.1 netmask 255.255.255.0")
r1.cmd("ifconfig r1-eth1 10.0.1.1 netmask 255.255.255.0")
r1.cmd("tc qdisc del dev r1-eth0 root")
r1.cmd("tc qdisc add dev r1-eth0 root fq_codel limit 10 ecn")
r1.cmd("tc qdisc del dev r1-eth1 root")
r1.cmd("tc qdisc add dev r1-eth1 root fq_codel limit 10 ecn")
h1.cmd("ifconfig h1-eth0 10.0.0.2 netmask 255.255.255.0")
h2.cmd("ifconfig h2-eth0 10.0.1.2 netmask 255.255.255.0")
h1.cmd("ip rule add from 10.0.0.2 table 1")
h1.
cmd(
"ip route add 10.0.0.0/24 dev h1-eth0 scope link table 1")
h1.cmd("ip route add default via 10.0.0.1 dev h1-eth0 table 1")
h1.cmd("ip route add default scope global nexthop via 10.0.0.1 dev h1-eth0")
h2.cmd("ip rule add from 10.0.1.2 table 1")
h2.
cmd(
"ip route add 10.0.1.0/24 dev h2-eth0 scope link table 1")
h2.cmd("ip route add default via 10.0.1.1 dev h2-eth0 table 1")
h2.cmd("ip route add default scope global nexthop via 10.0.1.1 dev h2-eth0")
CLI(net)
net.stop()