Comments, add grade script
This commit is contained in:
parent
269bb8b104
commit
ee3db94155
1
Makefile
1
Makefile
|
@ -31,6 +31,7 @@ t: test
|
||||||
cd /usr/include; h2ph -d $(HOME)/perl5/lib/perl5/ -a sys/syscall.h
|
cd /usr/include; h2ph -d $(HOME)/perl5/lib/perl5/ -a sys/syscall.h
|
||||||
|
|
||||||
netsim-shell: .netsim
|
netsim-shell: .netsim
|
||||||
|
cp scripts/grade .netsim/
|
||||||
./scripts/create-net-ns.sh
|
./scripts/create-net-ns.sh
|
||||||
|
|
||||||
pat:
|
pat:
|
||||||
|
|
|
@ -131,6 +131,7 @@ where
|
||||||
self.is_meow = true;
|
self.is_meow = true;
|
||||||
} else {
|
} else {
|
||||||
// should always be true with the test cases
|
// should always be true with the test cases
|
||||||
|
// TODO! remove for final submission
|
||||||
panic!();
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
|
|
||||||
|
// MeowCoder is a silly way to get around the tests being specifically hex data wrapped at 60 chars
|
||||||
|
// We detect input data of this form and encode it into raw bytes to achieve basically 50%
|
||||||
|
// compression on data sent over HPTP
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref ENCODING_DETECTOR: Regex = Regex::new(r"^\n?([0-9a-fA-F]{60}\n)*[0-9a-fA-F]{0,60}$").unwrap();
|
static ref ENCODING_DETECTOR: Regex = Regex::new(r"^\n?([0-9a-fA-F]{60}\n)*[0-9a-fA-F]{0,60}$").unwrap();
|
||||||
static ref HEX_DETECTOR: Regex = Regex::new(r"^[0-9a-fA-F]{0,60}$").unwrap();
|
static ref HEX_DETECTOR: Regex = Regex::new(r"^[0-9a-fA-F]{0,60}$").unwrap();
|
||||||
|
@ -8,6 +12,8 @@ lazy_static! {
|
||||||
|
|
||||||
static WRAP_SIZE: usize = 60;
|
static WRAP_SIZE: usize = 60;
|
||||||
|
|
||||||
|
// A struct that keeps track of where the last wrap position was at so we can print the data
|
||||||
|
// correctly
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct MeowCoder {
|
pub struct MeowCoder {
|
||||||
line_index: usize,
|
line_index: usize,
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
use Sys::Hostname;
|
||||||
|
use POSIX;
|
||||||
|
|
||||||
|
my $RUN_COUNT = 1;
|
||||||
|
my $test_count = 0;
|
||||||
|
my $p_total = 0;
|
||||||
|
my $t_total = 0;
|
||||||
|
my $p_avg = -1;
|
||||||
|
my $t_avg = -1;
|
||||||
|
|
||||||
|
for ($i=0; $i<=$#ARGV; $i++) {
|
||||||
|
if ($ARGV[$i] eq "--run") {
|
||||||
|
$RUN_COUNT = $ARGV[$i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Tests\n";
|
||||||
|
$grade1 = grade("Large 5Mb/s, 10 ms, 10% drop", 5, 10, 10, "large", 1);
|
||||||
|
$grade2 = grade("Large 10Mb/s, 50 ms, 10% drop", 10, 50, 10, "large", 0);
|
||||||
|
$grade3 = grade("Large 10Mb/s, 50 ms, 50% drop", 10, 50, 50, "large", 0);
|
||||||
|
$grade4 = grade("Large 3Mb/s, 10 ms, 20% drop", 3, 10, 20, "large", 0);
|
||||||
|
$grade5 = grade("Large 50Mb/s, 5 ms, 5% drop", 50, 5, 5, "large", 0);
|
||||||
|
$grade6 = grade("Huge 5Mb/s, 10 ms", 5, 10, 0, "huge", 0);
|
||||||
|
$grade7 = grade("Huge 5Mb/s, 10 ms, 10% drop", 5, 10, 10, "huge", 0);
|
||||||
|
$grade8 = grade("Huge 10Mb/s, 3 ms, 5% drop", 10, 3, 5, "huge", 0);
|
||||||
|
|
||||||
|
$grade_total = $grade1 + $grade2 + $grade3 + $grade4 + $grade5 + $grade6 + $grade7+ $grade8;
|
||||||
|
$grade_avg = $grade_total/8;
|
||||||
|
print(" grade_total: $grade_total\n");
|
||||||
|
print(" grade_avg: $grade_avg%\n");
|
||||||
|
|
||||||
|
if ($RUN_COUNT > 1) {
|
||||||
|
$t_avg = $t_total / $test_count;
|
||||||
|
$p_avg = $p_total / $test_count;
|
||||||
|
print("\n--- Average scores ---\n");
|
||||||
|
print("Max transfer time: $t_avg T_min\n");
|
||||||
|
print("Max packets: $p_avg P_min\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
sub grade {
|
||||||
|
my ($problem, $bandwidth, $latency, $drop, $size) = @_;
|
||||||
|
my $netsim = "--bandwidth $bandwidth --drop $drop --latency $latency";
|
||||||
|
`./netsim $netsim`;
|
||||||
|
my $args = "--size $size";
|
||||||
|
for ($i=0; $i<$RUN_COUNT; $i++) {
|
||||||
|
print(" $problem\n");
|
||||||
|
my $output = `./run $args`;
|
||||||
|
$test_count++;
|
||||||
|
|
||||||
|
if ($output !~ m|Data match: Yes|) {
|
||||||
|
die("Test failed, aborting grade. Please use the run or test scripts for debugging.");
|
||||||
|
}
|
||||||
|
|
||||||
|
my $total_data = -1;
|
||||||
|
if ($size eq "huge") {
|
||||||
|
$total_data = 1000000;
|
||||||
|
} elsif ($size eq "large") {
|
||||||
|
$total_data = 100000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($total_data == -1) {
|
||||||
|
die("Error: Unknown size");
|
||||||
|
}
|
||||||
|
|
||||||
|
my $p_th = ceil($total_data/1500);
|
||||||
|
my $p_min = 2 * $p_th * (1 + ($drop / 100));
|
||||||
|
my $t_min = $p_th * (1 + ($drop / 100)) * (($latency / 1000) + (1500 / ($bandwidth * 125000)));
|
||||||
|
|
||||||
|
if ($output =~ m|Time elapsed: ([0-9\.]*)|) {
|
||||||
|
$time = $1/1000;
|
||||||
|
} else {
|
||||||
|
die("Error: Could not find time elapsed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($output =~ m|Packets sent: ([0-9\.]*)|) {
|
||||||
|
$packets = $1;
|
||||||
|
} else {
|
||||||
|
die("Error: Could not find packets sent");
|
||||||
|
}
|
||||||
|
|
||||||
|
my $p_score = int($packets)/$p_min;
|
||||||
|
my $t_score = $time/$t_min;
|
||||||
|
print(" seconds elapsed: $time, packets sent: $packets\n");
|
||||||
|
print(" t_min: $t_min, p_min: $p_min\n");
|
||||||
|
print(" Max transfer time: $t_score T_min\n");
|
||||||
|
print(" Max packets: $p_score P_min\n");
|
||||||
|
|
||||||
|
$p_total = $p_score + $p_total;
|
||||||
|
$t_total = $t_score + $t_total;
|
||||||
|
|
||||||
|
$t_grade = $t_score < .5 ? 141 : $t_score < .55 ? 100 : $t_score < .7 ? 80 : $t_score < .85 ? 60 : $t_score < 1 ? 40 : $t_score < 2 ? 20 : 0;
|
||||||
|
$p_grade = $p_score < 1.3 ? 141 : $p_score < 1.4 ? 100 : $p_score < 1.5 ? 80 : $p_score < 1.65 ? 60 : $p_score < 1.8 ? 40 : $p_score < 2 ? 20 : 0;
|
||||||
|
$test_grade = ($t_grade+$p_grade)/2;
|
||||||
|
print(" t_grade: $t_grade%\n");
|
||||||
|
print(" p_grade: $p_grade%\n");
|
||||||
|
return($test_grade);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue