Add a fixed rate mode
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
23
mud.c
23
mud.c
@@ -125,6 +125,7 @@ struct mud_msg {
|
|||||||
unsigned char timeout[MUD_TIME_SIZE];
|
unsigned char timeout[MUD_TIME_SIZE];
|
||||||
unsigned char mtu[2];
|
unsigned char mtu[2];
|
||||||
unsigned char loss;
|
unsigned char loss;
|
||||||
|
unsigned char fixed_rate;
|
||||||
struct mud_addr addr;
|
struct mud_addr addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1124,6 +1125,7 @@ mud_send_msg(struct mud *mud, struct mud_path *path, uint64_t now,
|
|||||||
MUD_STORE_MSG(msg->timeout, path->conf.msg_timeout);
|
MUD_STORE_MSG(msg->timeout, path->conf.msg_timeout);
|
||||||
|
|
||||||
msg->loss = (unsigned char)path->tx.loss;
|
msg->loss = (unsigned char)path->tx.loss;
|
||||||
|
msg->fixed_rate = path->conf.fixed_rate;
|
||||||
|
|
||||||
const struct mud_crypto_opt opt = {
|
const struct mud_crypto_opt opt = {
|
||||||
.dst = dst,
|
.dst = dst,
|
||||||
@@ -1193,9 +1195,11 @@ mud_update_window(struct mud *mud, struct mud_path *path, uint64_t now,
|
|||||||
uint64_t rx_dt, uint64_t rx_bytes, uint64_t rx_pkt)
|
uint64_t rx_dt, uint64_t rx_bytes, uint64_t rx_pkt)
|
||||||
{
|
{
|
||||||
if (rx_dt && rx_dt > tx_dt + (tx_dt >> 3)) {
|
if (rx_dt && rx_dt > tx_dt + (tx_dt >> 3)) {
|
||||||
path->tx.rate = 1 + ((rx_bytes * MUD_ONE_SEC) - 1) / rx_dt;
|
if (!path->conf.fixed_rate) {
|
||||||
if (path->tx.rate > path->conf.tx_max_rate)
|
path->tx.rate = 1 + ((rx_bytes * MUD_ONE_SEC) - 1) / rx_dt;
|
||||||
path->tx.rate = path->conf.tx_max_rate;
|
if (path->tx.rate > path->conf.tx_max_rate)
|
||||||
|
path->tx.rate = path->conf.tx_max_rate;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
uint64_t tx_acc = path->msg.tx.acc + tx_pkt;
|
uint64_t tx_acc = path->msg.tx.acc + tx_pkt;
|
||||||
uint64_t rx_acc = path->msg.rx.acc + rx_pkt;
|
uint64_t rx_acc = path->msg.rx.acc + rx_pkt;
|
||||||
@@ -1302,10 +1306,11 @@ mud_recv_msg(struct mud *mud, struct mud_path *path,
|
|||||||
|
|
||||||
const uint64_t max_rate = MUD_LOAD_MSG(msg->max_rate);
|
const uint64_t max_rate = MUD_LOAD_MSG(msg->max_rate);
|
||||||
|
|
||||||
if (path->conf.tx_max_rate != max_rate) {
|
if (path->conf.tx_max_rate != max_rate || msg->fixed_rate)
|
||||||
path->conf.tx_max_rate = max_rate;
|
|
||||||
path->tx.rate = max_rate;
|
path->tx.rate = max_rate;
|
||||||
}
|
|
||||||
|
path->conf.tx_max_rate = max_rate;
|
||||||
|
path->conf.fixed_rate = msg->fixed_rate;
|
||||||
|
|
||||||
path->msg.sent++;
|
path->msg.sent++;
|
||||||
path->msg.time = now;
|
path->msg.time = now;
|
||||||
@@ -1503,7 +1508,8 @@ mud_set_state(struct mud *mud, struct sockaddr *addr,
|
|||||||
enum mud_state state,
|
enum mud_state state,
|
||||||
unsigned long tx_max_rate,
|
unsigned long tx_max_rate,
|
||||||
unsigned long rx_max_rate,
|
unsigned long rx_max_rate,
|
||||||
unsigned long msg_timeout)
|
unsigned long msg_timeout,
|
||||||
|
unsigned char fixed_rate)
|
||||||
{
|
{
|
||||||
if (!mud->peer.set || state > MUD_UP) {
|
if (!mud->peer.set || state > MUD_UP) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@@ -1530,6 +1536,9 @@ mud_set_state(struct mud *mud, struct sockaddr *addr,
|
|||||||
if (msg_timeout)
|
if (msg_timeout)
|
||||||
path->conf.msg_timeout = msg_timeout;
|
path->conf.msg_timeout = msg_timeout;
|
||||||
|
|
||||||
|
if (fixed_rate)
|
||||||
|
path->conf.fixed_rate = fixed_rate >> 1;
|
||||||
|
|
||||||
if (state && path->state != state) {
|
if (state && path->state != state) {
|
||||||
path->state = state;
|
path->state = state;
|
||||||
mud_reset_path(path);
|
mud_reset_path(path);
|
||||||
|
|||||||
3
mud.h
3
mud.h
@@ -56,6 +56,7 @@ struct mud_path {
|
|||||||
uint64_t tx_max_rate;
|
uint64_t tx_max_rate;
|
||||||
uint64_t rx_max_rate;
|
uint64_t rx_max_rate;
|
||||||
uint64_t msg_timeout;
|
uint64_t msg_timeout;
|
||||||
|
unsigned char fixed_rate;
|
||||||
} conf;
|
} conf;
|
||||||
unsigned char ok;
|
unsigned char ok;
|
||||||
};
|
};
|
||||||
@@ -88,7 +89,7 @@ int mud_set_tc (struct mud *, int);
|
|||||||
int mud_set_aes (struct mud *);
|
int mud_set_aes (struct mud *);
|
||||||
|
|
||||||
int mud_set_state (struct mud *, struct sockaddr *, enum mud_state,
|
int mud_set_state (struct mud *, struct sockaddr *, enum mud_state,
|
||||||
unsigned long, unsigned long, unsigned long);
|
unsigned long, unsigned long, unsigned long, unsigned char);
|
||||||
|
|
||||||
int mud_peer (struct mud *, struct sockaddr *);
|
int mud_peer (struct mud *, struct sockaddr *);
|
||||||
|
|
||||||
|
|||||||
2
test.c
2
test.c
@@ -52,7 +52,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
// ...from loopback at 1MBps (not 1Mbps)
|
// ...from loopback at 1MBps (not 1Mbps)
|
||||||
if (mud_set_state(mud, (struct sockaddr *)&local,
|
if (mud_set_state(mud, (struct sockaddr *)&local,
|
||||||
MUD_UP, 1000 * 1000, 1000 * 1000, 0)) {
|
MUD_UP, 1000 * 1000, 1000 * 1000, 0, 0)) {
|
||||||
perror("mud_set_state");
|
perror("mud_set_state");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user