/
topofig4.py
129 lines (98 loc) · 2.89 KB
/
topofig4.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
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.util import irange,dumpNodeConnections
from mininet.log import setLogLevel
import re
import numpy
import matplotlib.pyplot as plt
import math
import os
class customTopo(Topo):
def __init__(self, bandwidth, loss, queue):
Topo.__init__(self)
host1 = self.addHost('h1', cpu = 0.5)
host2 = self.addHost('h2', cpu= 0.5)
switch =self.addSwitch('s1')
self.addLink( host1, switch, bw=bandwidth, delay='15ms', loss=loss,max_queue_size=queue, use_htb=True)
self.addLink( host2, switch, bw=bandwidth, delay='15ms', loss=loss,max_queue_size=queue, use_htb=True)
def perfTest(bandwidth, loss, queue):
"Create network and run simple performance test"
topo = customTopo(bandwidth, loss, queue)
net = Mininet(topo=topo, link=TCLink)
net.start()
h1, h2 = net.get('h1', 'h2')
h1.cmd('ping -c 15 %s' %h2.IP())
h2.cmd('ping -c 15 %s' %h1.IP())
#print "RTT between h1 and h2"
f = open('output_fig4.txt', 'a')
h1rtt=h1.cmd('ping -c 100 %s' %h2.IP())
match=re.search('time=([\d.]+)(\w+)',h1rtt)
if match is not None:
rtt1=str(match.group(1)+match.group(2))
else:
rtt1=0
f.write(", {}".format(rtt1))
#print "RTT between h2 and h1"
h2rtt=h2.cmd('ping -c 100 %s' %h1.IP())
match=re.search('time=([\d.]+)(\w+)',h2rtt)
if match is not None:
rtt2=str(match.group(1)+match.group(2))
else:
rtt2=0
f.write(", {}, ".format(rtt2))
bandwidth = net.iperf((h1,h2),fmt='-M 1074 -f M')
f.write(str(bandwidth))
bw1=bandwidth[0].split()
b1=bw1[0]
bw2=bandwidth[1].split()
b2=bw2[0]
cwnd=((float(rtt1)*float(b1)*1000)+(float(rtt2)*float(b2)*1000))/2
cwnd=float(cwnd/1024)
f.close()
net.stop()
return cwnd
if __name__ == '__main__':
setLogLevel('error')
os.system("sysctl -w net.ipv4.tcp_congestion_control=reno")
bandwidth=[10]
#bandwidth=[10,9,8]
#queue = [30,20]
queue=[30]
loss=numpy.logspace(-1.5,0.69,num=100,base=10.0)
x=[]
y=[]
c=[]
count=1
for q in queue:
for b in bandwidth:
for l in loss:
f=open('output_fig4.txt', 'a')
print("============================ count = {}, loss={}".format(count,l))
f.write("\n {}, ".format(q))
f.write(" {}".format(l))
f.close()
cwnd=perfTest(b, l, q)
x.append(l)
y.append(cwnd)
count+=1
f=open('output_fig4_plot_values.txt', 'a')
for i in range(0,len(x),1):
print("{loss},{cwnd}".format(loss=x[i],cwnd=y[i]))
f.write("\n {loss} , {cwnd}".format(loss=x[i],cwnd=y[i]))
f.close()
x1=numpy.log(x)
y1=numpy.log(y)
slope,intercept=numpy.polyfit(x1,y1,1)
for x2 in x1:
c.append(math.exp(slope*x2+intercept))
plt.plot(x,y,'o',x,c,'--')
plt.xlabel('Loss(p)')
plt.ylabel('BW*RTT/MSS')
plt.title('Fig 6: Estimated Window vs Loss')
plt.yscale('log')
plt.xscale('log')
plt.savefig('output_fig4.pdf')
plt.show()