|
@@ -19,7 +19,6 @@
|
|
|
|
|
|
#include "main.h"
|
|
|
#include "translation-table.h"
|
|
|
-#include "ring_buffer.h"
|
|
|
#include "originator.h"
|
|
|
#include "routing.h"
|
|
|
#include "gateway_common.h"
|
|
@@ -29,6 +28,48 @@
|
|
|
#include "bat_algo.h"
|
|
|
#include "network-coding.h"
|
|
|
|
|
|
+/**
|
|
|
+ * batadv_ring_buffer_set - update the ring buffer with the given value
|
|
|
+ * @lq_recv: pointer to the ring buffer
|
|
|
+ * @lq_index: index to store the value at
|
|
|
+ * @value: value to store in the ring buffer
|
|
|
+ */
|
|
|
+static void batadv_ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index,
|
|
|
+ uint8_t value)
|
|
|
+{
|
|
|
+ lq_recv[*lq_index] = value;
|
|
|
+ *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * batadv_ring_buffer_set - compute the average of all non-zero values stored
|
|
|
+ * in the given ring buffer
|
|
|
+ * @lq_recv: pointer to the ring buffer
|
|
|
+ *
|
|
|
+ * Returns computed average value.
|
|
|
+ */
|
|
|
+static uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[])
|
|
|
+{
|
|
|
+ const uint8_t *ptr;
|
|
|
+ uint16_t count = 0, i = 0, sum = 0;
|
|
|
+
|
|
|
+ ptr = lq_recv;
|
|
|
+
|
|
|
+ while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) {
|
|
|
+ if (*ptr != 0) {
|
|
|
+ count++;
|
|
|
+ sum += *ptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ i++;
|
|
|
+ ptr++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (count == 0)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ return (uint8_t)(sum / count);
|
|
|
+}
|
|
|
static struct batadv_neigh_node *
|
|
|
batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
|
|
|
const uint8_t *neigh_addr,
|