-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added open exercises for reliablity section
- Loading branch information
1 parent
9030d0c
commit 04eec31
Showing
17 changed files
with
848 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#emacs backups | ||
*~ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/python3 | ||
|
||
|
||
from inginious import input, feedback, rst | ||
|
||
# random input | ||
b = int(input.get_input("@random")[0] * 200 + 100) #kbps | ||
d = int(input.get_input("@random")[1] * 20 + 20) #msec | ||
|
||
|
||
def isfloat(value): | ||
try: | ||
float(value) | ||
return True | ||
except: | ||
return False | ||
|
||
def almost(answer,value): | ||
if((answer<=(value+value/20)) and (answer>=(value-value/20))): | ||
return True | ||
else: | ||
return False | ||
|
||
bandwidth=b*1000 | ||
dframe=10000 | ||
cframe=100 | ||
delay=d/1000 | ||
throughput=dframe/(dframe/bandwidth+delay+cframe/bandwidth+delay)/8 # bytes/sec | ||
answer = input.get_input("q1") | ||
if(isfloat(answer)): | ||
if (almost(float(answer),throughput)): | ||
feedback.set_problem_result("success","q1") | ||
feedback.set_problem_feedback("Correct","q1") | ||
feedback.set_grade(100) | ||
feedback.set_global_result("success") | ||
else: | ||
feedback.set_problem_result("failed","q1") | ||
response="Your answer is incorrect.\n" | ||
if(almost(float(answer),8*throughput)): | ||
response+="Remember that a byte contains 8 bits. Your answer is close to a throughput expressed in bits/second and not bytes/seconds\n" | ||
if(almost(float(answer),throughput/2)): | ||
response+="Remember that the propagation delay affects the transmission of both the data and control frames\n" | ||
feedback.set_problem_feedback(response,"q1") | ||
feedback.set_grade(0) | ||
feedback.set_global_result("failed") | ||
else: | ||
feedback.set_problem_result("failed","q1") | ||
feedback.set_problem_feedback("Your answer is not a number","q1") | ||
feedback.set_grade(0) | ||
feedback.set_global_result("failed") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
accessible: true | ||
author: Olivier Bonaventure | ||
categories: [] | ||
context: |- | ||
The alternating bit protocol is described in section `Recovering from transmission errors <http://cnp3book.info.ucl.ac.be/2nd/html/principles/reliability.html#reliable-data-transfer-on-top-of-an-imperfect-link>`_ | ||
.. raw:: html | ||
<script defer> | ||
bodyHeight = 0; | ||
function postSize() { | ||
if (document.body.scrollHeight != bodyHeight) { | ||
bodyHeight = document.body.scrollHeight; | ||
window.parent.postMessage({height: document.body.scrollHeight}, "*"); | ||
} | ||
}; | ||
var target = document.querySelector('body'); | ||
var observer = new MutationObserver(postSize); | ||
var config = { attributes: true, subtree: true } | ||
observer.observe(target, config); | ||
$(document).ready(function(){ | ||
setTimeout(postSize, 0); | ||
}); | ||
</script> | ||
environment: pyjavacpp | ||
evaluate: best | ||
file: '' | ||
groups: false | ||
input_random: '2' | ||
limits: | ||
time: '30' | ||
output: '2' | ||
memory: '100' | ||
name: Alternating Bit Protocol | ||
network_grading: false | ||
order: 16 | ||
problems: | ||
q1: | ||
name: Performance of the alternating bit protocol | ||
default: '' | ||
header: |4- | ||
.. raw:: html | ||
Consider an implementation of the alternating bit protocol that is used on between two hosts that are connected via a direct link. That link has a bandwidth of <b><span id="ipr1"></span></b> kbps and a propagation delay of <b><span id="ipr2"></span></b> msec. | ||
<script> | ||
var bw = parseInt(input["@random"][0] * 200 + 100); | ||
var de = parseInt(input["@random"][1] * 20 + 20); | ||
document.getElementById("ipr1").innerHTML = bw; | ||
document.getElementById("ipr2").innerHTML = de; | ||
</script> | ||
If the data frames are 10,000 bits long and the control frames 100 bits long, what is the maximum throughput achieved by this protocol expressed in bytes/sec? | ||
type: code_single_line | ||
run_cmd: '' | ||
stored_submissions: 0 | ||
submission_limit: | ||
amount: -1 | ||
period: -1 | ||
weight: 1.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/python3 | ||
|
||
|
||
from inginious import input, feedback | ||
|
||
# random input | ||
delay = int(input.get_input("@random")[0] * 7 + 2) | ||
timer = int(input.get_input("@random")[1] * 200 + 100) | ||
|
||
|
||
def isfloat(value): | ||
try: | ||
float(value) | ||
return True | ||
except: | ||
return False | ||
|
||
def almost(answer,value): | ||
if((answer<=(value+value/20)) and (answer>=(value-value/20))): | ||
return True | ||
else: | ||
return False | ||
|
||
sol=11*delay*2+timer | ||
|
||
answer = input.get_input("q1") | ||
if(isfloat(answer)): | ||
if (almost(float(answer),sol)): | ||
feedback.set_problem_result("success","q1") | ||
feedback.set_problem_feedback("Correct","q1") | ||
feedback.set_grade(100) | ||
feedback.set_global_result("success") | ||
else: | ||
feedback.set_problem_result("failed","q1") | ||
response="Your answer is incorrect.\n" | ||
if(float(answer)<10): | ||
response+="Remember that a byte contains 8 bits. To transmit 15000 bytes, the sender needs to send 10 frames.\n" | ||
if(almost(float(answer),10*delay)): | ||
response+="If the third frame is lost, it needs to be retransmitted. Your answer does not consider this retransmission.\n" | ||
feedback.set_problem_feedback(response,"q1") | ||
feedback.set_grade(0) | ||
feedback.set_global_result("failed") | ||
else: | ||
feedback.set_problem_result("failed","q1") | ||
feedback.set_problem_feedback("Your answer is not a number","q1") | ||
feedback.set_grade(0) | ||
feedback.set_global_result("failed") | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
accessible: true | ||
author: Olivier Bonaventure | ||
categories: [] | ||
context: |- | ||
.. raw:: html | ||
<script defer> | ||
bodyHeight = 0; | ||
function postSize() { | ||
if (document.body.scrollHeight != bodyHeight) { | ||
bodyHeight = document.body.scrollHeight; | ||
window.parent.postMessage({height: document.body.scrollHeight}, "*"); | ||
} | ||
}; | ||
var target = document.querySelector('body'); | ||
var observer = new MutationObserver(postSize); | ||
var config = { attributes: true, subtree: true } | ||
observer.observe(target, config); | ||
$(document).ready(function(){ | ||
setTimeout(postSize, 0); | ||
}); | ||
</script> | ||
environment: default | ||
evaluate: best | ||
file: '' | ||
groups: false | ||
input_random: '2' | ||
limits: | ||
time: '30' | ||
output: '2' | ||
memory: '100' | ||
name: Alternating Bit Protocol | ||
network_grading: false | ||
order: 18 | ||
problems: | ||
q1: | ||
name: Alternating Bit Protocol in the presence of losses. | ||
default: '' | ||
header: |4+ | ||
.. raw:: html | ||
Consider the utilisation of the Alternating Bit Protocol to transfer 15000 bytes of data. Both hosts are connected via a 1 Gbps link and there is a one-way delay of <b><span id="ipr1"></span></b> msec between the two hosts. The sender sends data frames that are 12000 bits long. Assuming that the retransmission timer is set to <b><span id="ipr2"></span></b> msec, how long does it take to transfer the 15000 bytes if the third data frame is lost ? | ||
<script> | ||
var delay = parseInt(input["@random"][0] * 7 + 2); | ||
var timer = parseInt(input["@random"][1] * 200 + 100); | ||
document.getElementById("ipr1").innerHTML = delay; | ||
document.getElementById("ipr2").innerHTML = timer; | ||
</script> | ||
type: code_single_line | ||
run_cmd: '' | ||
stored_submissions: 0 | ||
submission_limit: | ||
amount: -1 | ||
period: -1 | ||
weight: 1.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
_id: 5d7815efeadd8a8905fff132 | ||
archive: 5d7815f0eadd8a8905fff133 | ||
courseid: cnp3 | ||
custom: {} | ||
grade: 100.0 | ||
input: | ||
'@lang': en | ||
'@random': | ||
- 0.8060389968499849 | ||
- 0.4098167679928465 | ||
'@random_0': '0.8060389968499849' | ||
'@random_1': '0.4098167679928465' | ||
'@state': '' | ||
'@username': obonaventure | ||
q1: '333' | ||
problems: | ||
q1: | ||
- success | ||
- Correct | ||
response_type: rst | ||
result: success | ||
state: '' | ||
status: done | ||
stderr: '' | ||
stdout: '' | ||
submitted_on: 2019-09-10 23:30:23.215000 | ||
taskid: q-rel-alt-bit-2 | ||
tests: {} | ||
text: '' | ||
username: | ||
- obonaventure |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
_id: 5d7815efeadd8a8905fff132 | ||
archive: 5d7815f0eadd8a8905fff133 | ||
courseid: cnp3 | ||
custom: {} | ||
grade: 100.0 | ||
input: | ||
'@lang': en | ||
'@random': | ||
- 0.8060389968499849 | ||
- 0.4098167679928465 | ||
'@random_0': '0.8060389968499849' | ||
'@random_1': '0.4098167679928465' | ||
'@state': '' | ||
'@username': obonaventure | ||
q1: '333' | ||
problems: | ||
q1: | ||
- success | ||
- Correct | ||
response_type: rst | ||
result: success | ||
state: '' | ||
status: done | ||
stderr: '' | ||
stdout: '' | ||
submitted_on: 2019-09-10 23:30:23.215000 | ||
taskid: q-rel-alt-bit-2 | ||
tests: {} | ||
text: '' | ||
username: | ||
- obonaventure |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/python3 | ||
|
||
|
||
from inginious import input, feedback, rst | ||
import array | ||
|
||
# random input | ||
|
||
f = int(input.get_input("@random")[0] * 1000000000 + 1000000000) | ||
|
||
# source: https://stackoverflow.com/questions/1767910/checksum-udp-calculation-python | ||
def checksum(pkt): | ||
if len(pkt) % 2 == 1: | ||
pkt += "\0" | ||
s = sum(array.array("H", pkt)) | ||
s = (s >> 16) + (s & 0xffff) | ||
s += s >> 16 | ||
s = ~s | ||
return (((s>>8)&0xff)|s<<8) & 0xffff | ||
|
||
#source https://wiki.python.org/moin/BitManipulation | ||
def bin(s): | ||
return str(s) if s<=1 else bin(s>>1) + str(s&1) | ||
|
||
answer = input.get_input("q1") | ||
a=int(answer,2) | ||
|
||
|
||
fs=f.to_bytes(4,byteorder='big') | ||
fa=a.to_bytes(4,byteorder='big') | ||
|
||
if(f==a): | ||
feedback.set_problem_result("failed","q1") | ||
feedback.set_grade(0) | ||
feedback.set_global_result("failed") | ||
feedback.set_problem_feedback("This is the same frame, you did not modify any bit. The checksum of this frame is "+str(bin(checksum(fs))),"q1") | ||
else: | ||
|
||
if(len(bin(f))!=len(answer)): | ||
feedback.set_problem_result("failed","q1") | ||
feedback.set_grade(0) | ||
feedback.set_global_result("failed") | ||
feedback.set_problem_feedback("The frame that you proposed that does not have the same length as the original one.","q1") | ||
else: | ||
if(checksum(fs)==checksum(fa)): | ||
feedback.set_problem_result("success","q1") | ||
feedback.set_grade(100) | ||
feedback.set_global_result("success") | ||
feedback.set_problem_feedback("The checksum of this frame is "+bin(checksum(fs))+" and the checksum of your answer is "+bin(checksum(fa)),"q1") | ||
else: | ||
feedback.set_problem_result("failed","q1") | ||
feedback.set_grade(0) | ||
feedback.set_global_result("failed") | ||
ret="The checksum of this frame is "+bin(checksum(fs))+" while the checksum of your answer is "+bin(checksum(fa)) | ||
feedback.set_problem_feedback(ret,"q1") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
accessible: false | ||
author: Olivier Bonaventure | ||
context: 'Internet checksums and CRCs have different error detection capabilities. ' | ||
environment: pyjavacpp | ||
evaluate: best | ||
groups: false | ||
input_random: '1' | ||
limits: | ||
memory: '100' | ||
output: '2' | ||
time: '30' | ||
name: Checksums and CRCs | ||
network_grading: false | ||
problems: | ||
q1: | ||
header: |+ | ||
.. raw:: html | ||
Consider a simple frame that is represented as the following bitstring : <b><span id="ipr1"></span></b> | ||
Can you find a bitstring that is different from this frame but has the same checksum ? | ||
<script> | ||
var frame = parseInt(input["@random"][0] * 1000000000 + 1000000000); | ||
document.getElementById("ipr1").innerHTML = frame.toString(2); | ||
</script> | ||
name: Internet checksum | ||
default: '' | ||
type: code_single_line | ||
stored_submissions: 0 | ||
submission_limit: | ||
amount: -1 | ||
period: -1 | ||
tags: {} | ||
weight: 1.0 | ||
order: 5 |
Oops, something went wrong.