diff options
author | Dimitri Staessens <[email protected]> | 2020-12-01 19:19:04 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2020-12-02 19:21:29 +0100 |
commit | 8e1c0e62feb4832dca2b53e51ab0e1cb8f48e5b1 (patch) | |
tree | ce90e18277c38e7ee592d441ae4de197081c6476 /src/ipcpd/unicast/dt.c | |
parent | aef6bdb1eadf8779173145710306ea5b6d81b8ec (diff) | |
download | ouroboros-8e1c0e62feb4832dca2b53e51ab0e1cb8f48e5b1.tar.gz ouroboros-8e1c0e62feb4832dca2b53e51ab0e1cb8f48e5b1.zip |
ipcpd: Add congestion avoidance policies
This adds congestion avoidance policies to the unicast IPCP. The
default policy is a multi-bit explicit congestion avoidance algorithm
based on data-center TCP congestion avoidance (DCTCP) to relay
information about the maximum queue depth that packets experienced to
the receiver. There's also a "nop" policy to disable congestion
avoidance for testing and benchmarking purposes.
The (initial) API for congestion avoidance policies is:
void * (* ctx_create)(void);
void (* ctx_destroy)(void * ctx);
These calls create / and or destroy a context for congestion control
for a specific flow. Thread-safety of the context is the
responsability of the flow allocator (operations on the ctx should be
performed under a lock).
ca_wnd_t (* ctx_update_snd)(void * ctx,
size_t len);
This is the sender call to update the context, and should be called
for every packet that is sent on the flow. The len parameter in this
API is the packet length, which allows calculating the bandwidth. It
returns an opaque union type that is used for the call to check/wait
if the congestion window is open or closed (and allowing to release
locks before waiting).
bool (* ctx_update_rcv)(void * ctx,
size_t len,
uint8_t ecn,
uint16_t * ece);
This is the call to update the flow congestion context on the receiver
side. It should be called for every received packet. It gets the ecn
value from the packet and its length, and returns the ECE (explicit
congestion experienced) value to be sent to the sender in case of
congestion. The boolean returned signals whether or not a congestion
update needs to be sent.
void (* ctx_update_ece)(void * ctx,
uint16_t ece);
This is the call for the sending side top update the context when it
receives an ECE update from the receiver.
void (* wnd_wait)(ca_wnd_t wnd);
This is a (blocking) call that waits for the congestion window to
clear. It should be stateless (to avoid waiting under locks). This may
change later on if passing the context is needed for different algorithms.
uint8_t (* calc_ecn)(int fd,
size_t len);
This is the call that intermediate IPCPs(routers) should use to update
the ECN field on passing packets.
The multi-bit ECN policy bases the value for the ECN field on the
depth of the rbuff queue packets will be sent on. I created another
call to grab the queue depth as fccntl is write-locking the
application. We can further optimize this to avoid most locking on the
rbuff.
Signed-off-by: Dimitri Staessens <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/ipcpd/unicast/dt.c')
-rw-r--r-- | src/ipcpd/unicast/dt.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/ipcpd/unicast/dt.c b/src/ipcpd/unicast/dt.c index 7db766a5..53accba3 100644 --- a/src/ipcpd/unicast/dt.c +++ b/src/ipcpd/unicast/dt.c @@ -41,6 +41,7 @@ #include <ouroboros/fccntl.h> #endif +#include "ca.h" #include "connmgr.h" #include "ipcp.h" #include "dt.h" @@ -115,16 +116,12 @@ static void dt_pci_ser(uint8_t * head, } -static void dt_pci_des(struct shm_du_buff * sdb, - struct dt_pci * dt_pci) +static void dt_pci_des(uint8_t * head, + struct dt_pci * dt_pci) { - uint8_t * head; - - assert(sdb); + assert(head); assert(dt_pci); - head = shm_du_buff_head(sdb); - /* Decrease TTL */ --*(head + dt_pci_info.ttl_o); @@ -226,7 +223,6 @@ static int dt_stat_read(const char * path, "Queued packets (rx): %20zu\n" "Queued packets (tx): %20zu\n\n", tmstr, addrstr, rxqlen, txqlen); - for (i = 0; i < QOS_CUBE_MAX; ++i) { sprintf(str, "Qos cube %3d:\n" @@ -434,13 +430,14 @@ static void packet_handler(int fd, struct dt_pci dt_pci; int ret; int ofd; -#ifndef IPCP_FLOW_STATS - (void) fd; -#else + uint8_t * head; size_t len; len = shm_du_buff_tail(sdb) - shm_du_buff_head(sdb); +#ifndef IPCP_FLOW_STATS + (void) fd; +#else pthread_mutex_lock(&dt.stat[fd].lock); ++dt.stat[fd].rcv_pkt[qc]; @@ -449,7 +446,10 @@ static void packet_handler(int fd, pthread_mutex_unlock(&dt.stat[fd].lock); #endif memset(&dt_pci, 0, sizeof(dt_pci)); - dt_pci_des(sdb, &dt_pci); + + head = shm_du_buff_head(sdb); + + dt_pci_des(head, &dt_pci); if (dt_pci.dst_addr != ipcpi.dt_addr) { if (dt_pci.ttl == 0) { log_dbg("TTL was zero."); @@ -481,6 +481,8 @@ static void packet_handler(int fd, return; } + *(head + dt_pci_info.ecn_o) |= ca_calc_ecn(ofd, len); + ret = ipcp_flow_write(ofd, sdb); if (ret < 0) { log_dbg("Failed to write packet to fd %d.", ofd); @@ -508,6 +510,9 @@ static void packet_handler(int fd, } else { dt_pci_shrink(sdb); if (dt_pci.eid >= PROG_RES_FDS) { + uint8_t ecn = *(head + dt_pci_info.ecn_o); + fa_ecn_update(dt_pci.eid, ecn, len); + if (ipcp_flow_write(dt_pci.eid, sdb)) { ipcp_sdb_release(sdb); #ifdef IPCP_FLOW_STATS @@ -792,15 +797,15 @@ int dt_write_packet(uint64_t dst_addr, int fd; int ret; uint8_t * head; -#ifdef IPCP_FLOW_STATS size_t len; -#endif + assert(sdb); assert(dst_addr != ipcpi.dt_addr); -#ifdef IPCP_FLOW_STATS len = shm_du_buff_tail(sdb) - shm_du_buff_head(sdb); +#ifdef IPCP_FLOW_STATS + pthread_mutex_lock(&dt.stat[np1_fd].lock); ++dt.stat[np1_fd].lcl_r_pkt[qc]; @@ -829,15 +834,15 @@ int dt_write_packet(uint64_t dst_addr, goto fail_write; } + len = shm_du_buff_tail(sdb) - shm_du_buff_head(sdb); + dt_pci.dst_addr = dst_addr; dt_pci.qc = qc; dt_pci.eid = np1_fd; - dt_pci.ecn = 0; + dt_pci.ecn = ca_calc_ecn(fd, len); dt_pci_ser(head, &dt_pci); -#ifdef IPCP_FLOW_STATS - len = shm_du_buff_tail(sdb) - shm_du_buff_head(sdb); -#endif + ret = ipcp_flow_write(fd, sdb); if (ret < 0) { log_dbg("Failed to write packet to fd %d.", fd); |