Skip to content

Commit ea5890f

Browse files
Merge pull request #96 from nealcardwell/master
Add neper --congestion-control option to set TCP congestion control algorithm
2 parents 37b4bac + f0a1696 commit ea5890f

5 files changed

Lines changed: 11 additions & 0 deletions

File tree

common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ void set_tcp_tx_delay(int fd, int delay, struct callbacks *cb)
233233
PLOG_ERROR(cb, "setsockopt(TCP_TX_DELAY)");
234234
}
235235

236+
void set_congestion_control(int fd, const char *cc, struct callbacks *cb)
237+
{
238+
if (setsockopt(fd, SOL_TCP, TCP_CONGESTION, cc, strlen(cc)))
239+
PLOG_ERROR(cb, "setsockopt(TCP_CONGESTION)");
240+
}
241+
236242
void set_tcp_no_delay(int fd, struct callbacks *cb)
237243
{
238244
int value = true;

common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ void set_freebind(int fd, struct callbacks *cb);
157157
void set_debug(int fd, int onoff, struct callbacks *cb);
158158
void set_mark(int fd, int mark, struct callbacks *cb);
159159
void set_tcp_tx_delay(int fd, int delay, struct callbacks *cb);
160+
void set_congestion_control(int fd, const char *cc, struct callbacks *cb);
160161
void set_tcp_no_delay(int fd, struct callbacks *cb);
161162
void fill_random(char *buf, int size);
162163
int do_close(int fd);

define_all_flags.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct flags_parser *add_flags_tcp(struct flags_parser *fp)
7272
#endif
7373
DEFINE_FLAG(fp, int, tcp_tx_delay, 0, 't', "Force usec delay in TCP flows");
7474
DEFINE_FLAG(fp, bool, no_delay, false, 0, "Set TCP_NODELAY sockopt on data sockets to disable Nagle's algorithm");
75+
DEFINE_FLAG(fp, const char *, congestion_control, NULL, 0, "TCP congestion control algorithm to control connection sending rate");
7576

7677
/* Return the updated fp */
7778
return (fp);

lib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct options {
9696
bool time_wait;
9797
double interval;
9898
long long max_pacing_rate;
99+
const char *congestion_control;
99100
const char *local_hosts;
100101
const char *host;
101102
const char *control_port;

socket.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ static void socket_init_established(struct thread *t, int s)
8080
uint64_t m = opts->max_pacing_rate;
8181
setsockopt(s, SOL_SOCKET, SO_MAX_PACING_RATE, &m, sizeof(m));
8282
}
83+
if (opts->congestion_control)
84+
set_congestion_control(s, opts->congestion_control, cb);
8385
if (opts->tcp_tx_delay)
8486
set_tcp_tx_delay(s, opts->tcp_tx_delay, cb);
8587
set_nonblocking(s, cb);

0 commit comments

Comments
 (0)