aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Quartulli <ordex@autistici.org>2013-04-08 03:38:12 -0400
committerAntonio Quartulli <ordex@autistici.org>2013-05-28 20:44:54 -0400
commit24a5deeb8a198f0a26ae04485d9976c5e414f723 (patch)
treee4f7ad50fb74495c9f478c6c68eea74eb399d16a
parent7ed4be9523455a061e62236dc3caa9211cd7edda (diff)
batman-adv: move ring_buffer helper functions in bat_iv_ogm
the two lonely ring_buffer helper functions are used by the bat_iv_ogm module only and therefore they can be moved inside it. Reported-by: Marek Lindner <lindner_marek@yahoo.de> Signed-off-by: Antonio Quartulli <ordex@autistici.org> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
-rw-r--r--net/batman-adv/Makefile1
-rw-r--r--net/batman-adv/bat_iv_ogm.c43
-rw-r--r--net/batman-adv/ring_buffer.c51
-rw-r--r--net/batman-adv/ring_buffer.h27
4 files changed, 42 insertions, 80 deletions
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile
index acbac2a9c62f..489bb36f1b94 100644
--- a/net/batman-adv/Makefile
+++ b/net/batman-adv/Makefile
@@ -32,7 +32,6 @@ batman-adv-y += icmp_socket.o
32batman-adv-y += main.o 32batman-adv-y += main.o
33batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o 33batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o
34batman-adv-y += originator.o 34batman-adv-y += originator.o
35batman-adv-y += ring_buffer.o
36batman-adv-y += routing.o 35batman-adv-y += routing.o
37batman-adv-y += send.o 36batman-adv-y += send.o
38batman-adv-y += soft-interface.o 37batman-adv-y += soft-interface.o
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index ef41be49b314..31c2891c2cd0 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -19,7 +19,6 @@
19 19
20#include "main.h" 20#include "main.h"
21#include "translation-table.h" 21#include "translation-table.h"
22#include "ring_buffer.h"
23#include "originator.h" 22#include "originator.h"
24#include "routing.h" 23#include "routing.h"
25#include "gateway_common.h" 24#include "gateway_common.h"
@@ -29,6 +28,48 @@
29#include "bat_algo.h" 28#include "bat_algo.h"
30#include "network-coding.h" 29#include "network-coding.h"
31 30
31/**
32 * batadv_ring_buffer_set - update the ring buffer with the given value
33 * @lq_recv: pointer to the ring buffer
34 * @lq_index: index to store the value at
35 * @value: value to store in the ring buffer
36 */
37static void batadv_ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index,
38 uint8_t value)
39{
40 lq_recv[*lq_index] = value;
41 *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE;
42}
43
44/**
45 * batadv_ring_buffer_set - compute the average of all non-zero values stored
46 * in the given ring buffer
47 * @lq_recv: pointer to the ring buffer
48 *
49 * Returns computed average value.
50 */
51static uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[])
52{
53 const uint8_t *ptr;
54 uint16_t count = 0, i = 0, sum = 0;
55
56 ptr = lq_recv;
57
58 while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) {
59 if (*ptr != 0) {
60 count++;
61 sum += *ptr;
62 }
63
64 i++;
65 ptr++;
66 }
67
68 if (count == 0)
69 return 0;
70
71 return (uint8_t)(sum / count);
72}
32static struct batadv_neigh_node * 73static struct batadv_neigh_node *
33batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, 74batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
34 const uint8_t *neigh_addr, 75 const uint8_t *neigh_addr,
diff --git a/net/batman-adv/ring_buffer.c b/net/batman-adv/ring_buffer.c
deleted file mode 100644
index ccab0bbdbb59..000000000000
--- a/net/batman-adv/ring_buffer.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
2 *
3 * Marek Lindner
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
18 */
19
20#include "main.h"
21#include "ring_buffer.h"
22
23void batadv_ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index,
24 uint8_t value)
25{
26 lq_recv[*lq_index] = value;
27 *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE;
28}
29
30uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[])
31{
32 const uint8_t *ptr;
33 uint16_t count = 0, i = 0, sum = 0;
34
35 ptr = lq_recv;
36
37 while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) {
38 if (*ptr != 0) {
39 count++;
40 sum += *ptr;
41 }
42
43 i++;
44 ptr++;
45 }
46
47 if (count == 0)
48 return 0;
49
50 return (uint8_t)(sum / count);
51}
diff --git a/net/batman-adv/ring_buffer.h b/net/batman-adv/ring_buffer.h
deleted file mode 100644
index 3f92ae248e83..000000000000
--- a/net/batman-adv/ring_buffer.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
2 *
3 * Marek Lindner
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
18 */
19
20#ifndef _NET_BATMAN_ADV_RING_BUFFER_H_
21#define _NET_BATMAN_ADV_RING_BUFFER_H_
22
23void batadv_ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index,
24 uint8_t value);
25uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[]);
26
27#endif /* _NET_BATMAN_ADV_RING_BUFFER_H_ */