congure.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
29 #include <stdbool.h>
30 #include <stdlib.h>
31 
32 #include "congure.h"
33 #include "modules.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 #define GNRC_SIXLOWPAN_FRAG_SFR_CONGURE_UNIT (1U)
44 
45 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE) || DOXYGEN
65 #else
67 {
68  return NULL;
69 }
70 #endif
71 
87 {
88 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
89  c->driver = NULL;
90 #else
91  (void)c;
92 #endif
93 }
94 
105 {
106 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
108  fb->sfr.congure = NULL;
109 #else
110  (void)fb;
111 #endif
112 }
113 
123 {
124 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
125  fb->sfr.congure->driver->init(fb->sfr.congure, fb);
126 #else
127  (void)fb;
128 #endif
129 }
130 
141 {
142 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
143  if (fb->sfr.congure == NULL) {
144  fb->sfr.congure = gnrc_sixlowpan_frag_sfr_congure_snd_get();
145  assert(fb->sfr.congure);
147  if (fb->sfr.congure->cwnd > CONFIG_GNRC_SIXLOWPAN_SFR_MAX_WIN_SIZE) {
148  fb->sfr.congure->cwnd = CONFIG_GNRC_SIXLOWPAN_SFR_MAX_WIN_SIZE;
149  }
150  }
151 #else
152  (void)fb;
153 #endif
154 }
155 
173 {
174 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
175  return fb->sfr.frags_sent < fb->sfr.congure->cwnd;
176 #else
177  return fb->sfr.frags_sent < CONFIG_GNRC_SIXLOWPAN_SFR_OPT_WIN_SIZE;
178 #endif
179 }
180 
198 {
199 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
200  return (fb->sfr.frags_sent + GNRC_SIXLOWPAN_FRAG_SFR_CONGURE_UNIT)
201  < fb->sfr.congure->cwnd;
202 #else
203  return (fb->sfr.frags_sent + GNRC_SIXLOWPAN_FRAG_SFR_CONGURE_UNIT)
205 #endif
206 }
207 
218 {
220  IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE);
221 }
222 
244  )
245 {
246 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
247  if (fb != NULL) {
248  congure_snd_t *c = fb->sfr.congure;
249  int32_t res = c->driver->inter_msg_interval(
251  );
252 
253  if ((res >= 0) &&
255  return (uint32_t)res;
256  }
257  }
258 #else
259  (void)fb;
260 #endif
262 }
263 
277  )
278 {
279 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
280  congure_snd_t *c = fb->sfr.congure;
281 
283 #else
284  (void)fb;
285 #endif
286 }
287 
301  )
302 {
303 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
304  congure_snd_t *c = fb->sfr.congure;
305 
307 #else
308  (void)fb;
309 #endif
310 }
311 
325  )
326 {
327 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
328  congure_snd_t *c = fb->sfr.congure;
329 
330  c->driver->report_msgs_timeout(c, (congure_snd_msg_t *)(&fb->sfr.window));
331 #else
332  (void)fb;
333 #endif
334 }
335 
351  )
352 {
353 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
354  congure_snd_t *c = fb->sfr.congure;
355 
356  c->driver->report_msgs_lost(c, frags);
357 #else
358  (void)fb;
359  (void)frags;
360 #endif
361 }
362 
378  congure_snd_msg_t *frag,
379  congure_snd_ack_t *ack
380  )
381 {
382 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
383  congure_snd_t *c = fb->sfr.congure;
384 
385  c->driver->report_msg_acked(c, frag, ack);
388  }
389 #else
390  (void)fb;
391  (void)frag;
392  (void)ack;
393 #endif
394 }
395 
410  gnrc_sixlowpan_frag_fb_t *fb, uint32_t time
411  )
412 {
413 #if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_CONGURE)
414  congure_snd_t *c = fb->sfr.congure;
415 
416  c->driver->report_ecn_ce(c, (ztimer_now_t)time);
417 #else
418  (void)fb;
419  (void)time;
420 #endif
421 }
422 
423 #ifdef __cplusplus
424 }
425 #endif
426 
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:143
6LoWPAN selective fragment recovery definitions for GNRC
#define CONFIG_GNRC_SIXLOWPAN_SFR_OPT_WIN_SIZE
Default value of window size that the sender should start with (OptWindowSize)
Definition: config.h:248
#define CONFIG_GNRC_SIXLOWPAN_SFR_INTER_FRAME_GAP_US
Default minimum amount of time between transmissions in microseconds (InterFrameGap)
Definition: config.h:264
#define CONFIG_GNRC_SIXLOWPAN_SFR_MAX_WIN_SIZE
Default maximum value of window size that the sender can use (MaxWindowSize)
Definition: config.h:236
static void gnrc_sixlowpan_frag_sfr_congure_snd_report_frags_timeout(gnrc_sixlowpan_frag_fb_t *fb)
Report to CongURE that the ACK for a fragment timed out.
Definition: congure.h:323
static bool gnrc_sixlowpan_frag_sfr_congure_snd_next_in_cwnd(gnrc_sixlowpan_frag_fb_t *fb)
Checks if given fragmentation buffer entry would still be within congestion window after next send.
Definition: congure.h:197
static void gnrc_sixlowpan_frag_sfr_congure_snd_setup(gnrc_sixlowpan_frag_fb_t *fb)
Retrieve CongURE state object when not retrieved and initialize it for a fragmentation buffer entry.
Definition: congure.h:140
static void gnrc_sixlowpan_frag_sfr_congure_snd_report_frags_lost(gnrc_sixlowpan_frag_fb_t *fb, congure_snd_msg_t *frags)
Report to CongURE that a number of fragments are known to be lost.
Definition: congure.h:349
static void gnrc_sixlowpan_frag_sfr_congure_snd_free(congure_snd_t *c)
Frees the CongURE state object.
Definition: congure.h:86
static bool gnrc_sixlowpan_frag_sfr_congure_snd_has_inter_frame_gap(void)
Checks if inter-frame gap is provided.
Definition: congure.h:217
static void gnrc_sixlowpan_frag_sfr_congure_snd_report_frag_sent(gnrc_sixlowpan_frag_fb_t *fb)
Report to CongURE that a fragment was sent.
Definition: congure.h:275
static void gnrc_sixlowpan_frag_sfr_congure_snd_destroy(gnrc_sixlowpan_frag_fb_t *fb)
Frees the CongURE state object of a fragmentation buffer and set's it to NULL
Definition: congure.h:104
static void gnrc_sixlowpan_frag_sfr_congure_snd_report_frag_discard(gnrc_sixlowpan_frag_fb_t *fb)
Report to CongURE that a fragment as discarded.
Definition: congure.h:299
congure_snd_t * gnrc_sixlowpan_frag_sfr_congure_snd_get(void)
Retrieve CongURE state object from a pool of free objects.
static void gnrc_sixlowpan_frag_sfr_congure_snd_init(gnrc_sixlowpan_frag_fb_t *fb)
Initializes a CongURE state object in a fragmentation buffer entry.
Definition: congure.h:122
static uint32_t gnrc_sixlowpan_frag_sfr_congure_snd_inter_frame_gap(gnrc_sixlowpan_frag_fb_t *fb)
Returns inter-frame gap if provided by CongURE implementation.
Definition: congure.h:242
static void gnrc_sixlowpan_frag_sfr_congure_snd_report_ecn(gnrc_sixlowpan_frag_fb_t *fb, uint32_t time)
Report to CongURE that ECN bit was set in an ACK.
Definition: congure.h:409
static bool gnrc_sixlowpan_frag_sfr_congure_snd_in_cwnd(gnrc_sixlowpan_frag_fb_t *fb)
Checks if given fragmentation buffer entry is within congestion window.
Definition: congure.h:172
static void gnrc_sixlowpan_frag_sfr_congure_snd_report_frag_acked(gnrc_sixlowpan_frag_fb_t *fb, congure_snd_msg_t *frag, congure_snd_ack_t *ack)
Report to CongURE that a number of fragments are known to be lost.
Definition: congure.h:376
#define GNRC_SIXLOWPAN_FRAG_SFR_CONGURE_UNIT
The user-defined window unit for congure is one fragment with SFR.
Definition: congure.h:43
uint32_t ztimer_now_t
type for ztimer_now() result
Definition: ztimer.h:308
Common macros and compiler attributes/pragmas configuration.
#define IS_USED(module)
Checks whether a module is being used or not.
Definition: modules.h:67
Congure definitions for 6LoWPAN selective fragment recovery.
Object to represent an ACK to a message.
Definition: congure.h:83
void(* report_msg_sent)(congure_snd_t *c, unsigned msg_size)
Report that a message was sent.
Definition: congure.h:147
void(* report_msgs_lost)(congure_snd_t *c, congure_snd_msg_t *msgs)
Report that a collection of messages that is known to be lost.
Definition: congure.h:193
void(* report_ecn_ce)(congure_snd_t *c, ztimer_now_t time)
Report that "congestion encountered" CE signals were received for a message by means of explicit cong...
Definition: congure.h:214
void(* report_msgs_timeout)(congure_snd_t *c, congure_snd_msg_t *msgs)
Report that the ACKs for a collection of messages timed out.
Definition: congure.h:174
int32_t(* inter_msg_interval)(congure_snd_t *c, unsigned msg_size)
Get current interval between messages for pacing.
Definition: congure.h:139
void(* report_msg_discarded)(congure_snd_t *c, unsigned msg_size)
Report message as discarded.
Definition: congure.h:159
void(* report_msg_acked)(congure_snd_t *c, congure_snd_msg_t *msg, congure_snd_ack_t *ack)
Report that the ACK for a message was received.
Definition: congure.h:202
Object to represent a collection of sent messages.
Definition: congure.h:65
Base state object for CongURE implementations.
Definition: congure.h:48
const congure_snd_driver_t * driver
Driver for the state object.
Definition: congure.h:52
congure_wnd_size_t cwnd
Congestion window size.
Definition: congure.h:59
6LoWPAN fragmentation buffer entry.
Definition: fb.h:44