Created
February 13, 2017 18:11
-
-
Save henry-thompson/34dabf10f5550e58b7fbcb8ed160589f to your computer and use it in GitHub Desktop.
Answers the Chapter 5, Question 26 in Peterson and Davie's "Networking: A Systems Approach"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* OCaml program to answer this question *) | |
let delta = 0.125 | |
let mu = 1.0 | |
let phi = 4.0 | |
let timeout (estimate_rtt, deviation) = mu *. estimate_rtt +. phi *. deviation;; | |
let calculate_estimate (old_estimate_rtt, old_deviation, sample_rtt) = | |
let difference = sample_rtt -. old_estimate_rtt in | |
let new_estimate_rtt = old_estimate_rtt +. (delta *. difference) in | |
let new_deviation = old_deviation +. ((delta *. (abs_float difference)) -. old_deviation) in | |
(new_estimate_rtt, new_deviation);; | |
let time_till_target (start_estimate_rtt, start_deviation, rtt, target_timeout) = | |
let rec iter estimate_rtt deviation time = | |
let current_time = time +. rtt in | |
let (new_estimate_rtt, new_deviation) = calculate_estimate (estimate_rtt, deviation, rtt) in | |
if timeout (new_estimate_rtt, new_deviation) < target_timeout then | |
current_time | |
else | |
iter new_estimate_rtt new_deviation current_time | |
in | |
iter start_estimate_rtt start_deviation 0.0;; | |
(* Find out the time required to reach when the timeout < 4 seconds *) | |
let () = Printf.printf "%F" (time_till_target ((*estimate_rtt*) 4.0, (*deviation*) 1.0, (*rtt*) 1.0, (*target*) 4.0));; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment