-
Notifications
You must be signed in to change notification settings - Fork 0
/
competition.py
132 lines (105 loc) · 3.92 KB
/
competition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/python3
# copyright 2017 Peter Dordal
# licensed under the Apache 2.0 license
"""router topology example for TCP competions.
This remains the default version
router between two subnets:
h1----+
|
r ---- h3
|
h2----+
For running a TCP competition, consider the runcompetition.sh script
"""
QUEUE=10
DELAY='0ms' # r--h3 link
BottleneckBW=8 # Mbit/sec
BBR=False
LOSS=5
# reno-bbr parameters:
if BBR:
DELAY='40ms'
QUEUE=267
# QUEUE=25
QUEUE=10
BottleneckBW=10
from mininet.net import Mininet
from mininet.node import Node, OVSKernelSwitch, Controller, RemoteController
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.topo import Topo
from mininet.log import setLogLevel, info
#h1addr = '10.0.1.2/24'
#h2addr = '10.0.2.2/24'
#h3addr = '10.0.3.2/24'
#r1addr1= '10.0.1.1/24'
#r1addr2= '10.0.2.1/24'
#r1addr3= '10.0.3.1/24'
class LinuxRouter( Node ):
"A Node with IP forwarding enabled."
def config( self, **params ):
super( LinuxRouter, self).config( **params )
# Enable forwarding on the router
info ('enabling forwarding on ', self)
self.cmd( 'sysctl net.ipv4.ip_forward=1' )
def terminate( self ):
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
super( LinuxRouter, self ).terminate()
class RTopo(Topo):
#def __init__(self, **kwargs):
#global r
def build(self, **_opts): # special names?
defaultIP = '10.0.1.1/24' # IP address for r0-eth1
r = self.addNode( 'r', cls=LinuxRouter) # , ip=defaultIP )
h1 = self.addHost( 'h1', ip='10.0.1.10/24', defaultRoute='via 10.0.1.1' )
h2 = self.addHost( 'h2', ip='10.0.2.10/24', defaultRoute='via 10.0.2.1' )
h3 = self.addHost( 'h3', ip='10.0.3.10/24', defaultRoute='via 10.0.3.1' )
# h1---80Mbit---r---8Mbit/100ms---h2
# Oct 2020: the params2 method for setting IPv4 addresses
# doesn't always work; see below
self.addLink( h1, r, intfName1 = 'h1-eth', intfName2 = 'r-eth1', bw=80,
params2 = {'ip' : '10.0.1.1/24'})
self.addLink( h2, r, intfName1 = 'h2-eth', intfName2 = 'r-eth2', bw=80,
params2 = {'ip' : '10.0.2.1/24'})
self.addLink( h3, r, intfName1 = 'h3-eth', intfName2 = 'r-eth3',
params2 = {'ip' : '10.0.3.1/24'},
bw=BottleneckBW, delay=DELAY, queue=QUEUE, loss=LOSS) # apparently queue is IGNORED here.
# delay is the ONE-WAY delay, and is applied only to traffic departing h3-eth.
# BBW=8: 1 KB/ms, for 1K packets; 110 KB in transit
# BBW=10: 1.25 KB/ms, or 50 KB in transit if the delay is 40 ms.
# queue = 267: extra 400 KB in transit, or 8x bandwidthxdelay
def main():
rtopo = RTopo()
net = Mininet(topo = rtopo,
link=TCLink,
#switch = OVSKernelSwitch,
#controller = RemoteController,
autoSetMacs = True # --mac
)
net.start()
r = net['r']
r.cmd('ip route list');
# r's IPv4 addresses are set here, not above.
r.cmd('ifconfig r-eth1 10.0.1.1/24')
r.cmd('ifconfig r-eth2 10.0.2.1/24')
r.cmd('ifconfig r-eth3 10.0.3.1/24')
r.cmd('sysctl net.ipv4.ip_forward=1')
r.cmd('tc qdisc change dev r-eth3 handle 10: netem limit {}'.format(QUEUE))
h1 = net['h1']
h2 = net['h2']
h3 = net['h3']
h1.cmd('tc qdisc del dev h1-eth root')
h1.cmd('tc qdisc add dev h1-eth root fq')
h2.cmd('tc qdisc del dev h2-eth root')
h2.cmd('tc qdisc add dev h2-eth root fq')
for h in [r, h1, h2, h3]: h.cmd('/usr/sbin/sshd')
CLI( net)
net.stop()
setLogLevel('info')
main()
"""
This leads to a queuing hierarchy on r with an htb node, 5:0, as the root qdisc.
The class below it is 5:1. Below that is a netem qdisc with handle 10:, with delay 110.0ms.
We can change the limit (maximum queue capacity) with:
tc qdisc change dev r-eth1 handle 10: netem limit 5 delay 110.0ms
"""