-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcontroller.cc
66 lines (55 loc) · 1.8 KB
/
controller.cc
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
#include <stdio.h>
#include "controller.hh"
#include "timestamp.hh"
using namespace Network;
/* Default constructor */
Controller::Controller( const bool debug )
: debug_( debug )
{
}
/* Get current window size, in packets */
unsigned int Controller::window_size( void )
{
/* Default: fixed window size of one outstanding packet */
int the_window_size = 1;
if ( debug_ ) {
fprintf( stderr, "At time %lu, return window_size = %d.\n",
timestamp(), the_window_size );
}
return the_window_size;
}
/* A packet was sent */
void Controller::packet_was_sent( const uint64_t sequence_number,
/* of the sent packet */
const uint64_t send_timestamp )
/* in milliseconds */
{
/* Default: take no action */
if ( debug_ ) {
fprintf( stderr, "At time %lu, sent packet %lu.\n",
send_timestamp, sequence_number );
}
}
/* An ack was received */
void Controller::ack_received( const uint64_t sequence_number_acked,
/* what sequence number was acknowledged */
const uint64_t send_timestamp_acked,
/* when the acknowledged packet was sent */
const uint64_t recv_timestamp_acked,
/* when the acknowledged packet was received */
const uint64_t timestamp_ack_received )
/* when the ack was received (by sender) */
{
/* Default: take no action */
if ( debug_ ) {
fprintf( stderr, "At time %lu, received ACK for packet %lu",
timestamp_ack_received, sequence_number_acked );
fprintf( stderr, " (sent %lu, received %lu by receiver's clock).\n",
send_timestamp_acked, recv_timestamp_acked );
}
}
/* How long to wait if there are no acks before sending one more packet */
unsigned int Controller::timeout_ms( void )
{
return 1000; /* timeout of one second */
}