-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusage.py
More file actions
executable file
·60 lines (50 loc) · 1.41 KB
/
usage.py
File metadata and controls
executable file
·60 lines (50 loc) · 1.41 KB
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
#!/usr/bin/python3
'''
Written for networking class. With some given values,
calculates the percent-utilization by a stop-and-wait
protocol, and the window size in packets required to
reach 98% utilization during a pipelined transfer.
'''
def maxWindow(RTT, dtrans):
'''
gives the window for 100% utilization to start
a binary search.
(N * dtrans)/(RTT + dtrans) = 1
(N * dtrans) = (RTT + dtrans)
N = (RTT + dtrans) * (1/dtrans)
N = (RTT/dtrans + 1)
Want a whole number, so use integer division
'''
return (1 + (RTT//dtrans))
def window(RTT, dtrans):
'''
finds window size to result in 98% utilization
by establishing a binary search window and executing
'''
percent = .00001
low = 1
high = maxWindow(RTT, dtrans)
while True:
window = (high + low)//2
#print(window)
percent = ((window * dtrans)/(dtrans + RTT))
if percent < .98:
low = window
elif percent > .9801:
high = window
else:
print(percent)
return window
def pipelineDiff():
'''
calculates the utilization of stop and wait
then makes a tuple of that and the window size
for 98% utilization
'''
dprop = (2*(10**8))/(10000 * 1000)
rate = 1000000000
packetSize = 1000 * 8
dtrans = packetSize/rate
stopWait = dtrans/((2 * dprop) + dtrans)
return (stopWait, window((2 * dprop), dtrans))
print(pipelineDiff())