Skip to content

Commit d353d8d

Browse files
hundebollAntonio Quartulli
authored andcommitted
batman-adv: network coding - add the initial infrastructure code
Network coding exploits the 802.11 shared medium to allow multiple packets to be sent in a single transmission. In brief, a relay can XOR two packets, and send the coded packet to two destinations. The receivers can decode one of the original packets by XOR'ing the coded packet with the other original packet. This will lead to increased throughput in topologies where two packets cross one relay. In a simple topology with three nodes, it takes four transmissions without network coding to get one packet from Node A to Node B and one from Node B to Node A: 1. Node A ---- p1 ---> Node R Node B 2. Node A Node R <--- p2 ---- Node B 3. Node A <--- p2 ---- Node R Node B 4. Node A Node R ---- p1 ---> Node B With network coding, the relay only needs one transmission, which saves us one slot of valuable airtime: 1. Node A ---- p1 ---> Node R Node B 2. Node A Node R <--- p2 ---- Node B 3. Node A <- p1 x p2 - Node R - p1 x p2 -> Node B The same principle holds for a topology including five nodes. Here the packets from Node A and Node B are overheard by Node C and Node D, respectively. This allows Node R to send a network coded packet to save one transmission: Node A Node B | \ / | | p1 p2 | | \ / | p1 > Node R < p2 | | | / \ | | p1 x p2 p1 x p2 | v / \ v / \ Node C < > Node D More information is available on the open-mesh.org wiki[1]. This patch adds the initial code to support network coding in batman-adv. It sets up a worker thread to do house keeping and adds a sysfs file to enable/disable network coding. The feature is disabled by default, as it requires a wifi-driver with working promiscuous mode, and also because it adds a small delay at each hop. [1] http://www.open-mesh.org/projects/batman-adv/wiki/Catwoman Signed-off-by: Martin Hundebøll <[email protected]> Signed-off-by: Marek Lindner <[email protected]> Signed-off-by: Antonio Quartulli <[email protected]>
1 parent c1d0743 commit d353d8d

File tree

10 files changed

+184
-1
lines changed

10 files changed

+184
-1
lines changed

Documentation/ABI/testing/sysfs-class-net-mesh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ Description:
6767
Defines the penalty which will be applied to an
6868
originator message's tq-field on every hop.
6969

70+
What: /sys/class/net/<mesh_iface>/mesh/network_coding
71+
Date: Nov 2012
72+
Contact: Martin Hundeboll <[email protected]>
73+
Description:
74+
Controls whether Network Coding (using some magic
75+
to send fewer wifi packets but still the same
76+
content) is enabled or not.
77+
7078
What: /sys/class/net/<mesh_iface>/mesh/orig_interval
7179
Date: May 2010
7280
Contact: Marek Lindner <[email protected]>

net/batman-adv/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ config BATMAN_ADV_DAT
3636
mesh networks. If you think that your network does not need
3737
this option you can safely remove it and save some space.
3838

39+
config BATMAN_ADV_NC
40+
bool "Network Coding"
41+
depends on BATMAN_ADV
42+
default n
43+
help
44+
This option enables network coding, a mechanism that aims to
45+
increase the overall network throughput by fusing multiple
46+
packets in one transmission.
47+
Note that interfaces controlled by batman-adv must be manually
48+
configured to have promiscuous mode enabled in order to make
49+
network coding work.
50+
If you think that your network does not need this feature you
51+
can safely disable it and save some space.
52+
3953
config BATMAN_ADV_DEBUG
4054
bool "B.A.T.M.A.N. debugging"
4155
depends on BATMAN_ADV

net/batman-adv/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ batman-adv-y += hard-interface.o
3030
batman-adv-y += hash.o
3131
batman-adv-y += icmp_socket.o
3232
batman-adv-y += main.o
33+
batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o
3334
batman-adv-y += originator.o
3435
batman-adv-y += ring_buffer.o
3536
batman-adv-y += routing.o

net/batman-adv/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "vis.h"
3636
#include "hash.h"
3737
#include "bat_algo.h"
38+
#include "network-coding.h"
3839

3940

4041
/* List manipulations on hardif_list have to be rtnl_lock()'ed,
@@ -135,6 +136,10 @@ int batadv_mesh_init(struct net_device *soft_iface)
135136
if (ret < 0)
136137
goto err;
137138

139+
ret = batadv_nc_init(bat_priv);
140+
if (ret < 0)
141+
goto err;
142+
138143
atomic_set(&bat_priv->gw.reselect, 0);
139144
atomic_set(&bat_priv->mesh_state, BATADV_MESH_ACTIVE);
140145

@@ -157,6 +162,7 @@ void batadv_mesh_free(struct net_device *soft_iface)
157162

158163
batadv_gw_node_purge(bat_priv);
159164
batadv_originator_free(bat_priv);
165+
batadv_nc_free(bat_priv);
160166

161167
batadv_tt_free(bat_priv);
162168

net/batman-adv/main.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr);
185185
* @BATADV_DBG_TT: translation table messages
186186
* @BATADV_DBG_BLA: bridge loop avoidance messages
187187
* @BATADV_DBG_DAT: ARP snooping and DAT related messages
188+
* @BATADV_DBG_NC: network coding related messages
188189
* @BATADV_DBG_ALL: the union of all the above log levels
189190
*/
190191
enum batadv_dbg_level {
@@ -193,7 +194,8 @@ enum batadv_dbg_level {
193194
BATADV_DBG_TT = BIT(2),
194195
BATADV_DBG_BLA = BIT(3),
195196
BATADV_DBG_DAT = BIT(4),
196-
BATADV_DBG_ALL = 31,
197+
BATADV_DBG_NC = BIT(5),
198+
BATADV_DBG_ALL = 63,
197199
};
198200

199201
#ifdef CONFIG_BATMAN_ADV_DEBUG

net/batman-adv/network-coding.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* Copyright (C) 2012-2013 B.A.T.M.A.N. contributors:
2+
*
3+
* Martin Hundebøll, Jeppe Ledet-Pedersen
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 "network-coding.h"
22+
23+
static void batadv_nc_worker(struct work_struct *work);
24+
25+
/**
26+
* batadv_nc_start_timer - initialise the nc periodic worker
27+
* @bat_priv: the bat priv with all the soft interface information
28+
*/
29+
static void batadv_nc_start_timer(struct batadv_priv *bat_priv)
30+
{
31+
queue_delayed_work(batadv_event_workqueue, &bat_priv->nc.work,
32+
msecs_to_jiffies(10));
33+
}
34+
35+
/**
36+
* batadv_nc_init - initialise coding hash table and start house keeping
37+
* @bat_priv: the bat priv with all the soft interface information
38+
*/
39+
int batadv_nc_init(struct batadv_priv *bat_priv)
40+
{
41+
INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker);
42+
batadv_nc_start_timer(bat_priv);
43+
44+
return 0;
45+
}
46+
47+
/**
48+
* batadv_nc_init_bat_priv - initialise the nc specific bat_priv variables
49+
* @bat_priv: the bat priv with all the soft interface information
50+
*/
51+
void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv)
52+
{
53+
atomic_set(&bat_priv->network_coding, 1);
54+
}
55+
56+
/**
57+
* batadv_nc_worker - periodic task for house keeping related to network coding
58+
* @work: kernel work struct
59+
*/
60+
static void batadv_nc_worker(struct work_struct *work)
61+
{
62+
struct delayed_work *delayed_work;
63+
struct batadv_priv_nc *priv_nc;
64+
struct batadv_priv *bat_priv;
65+
66+
delayed_work = container_of(work, struct delayed_work, work);
67+
priv_nc = container_of(delayed_work, struct batadv_priv_nc, work);
68+
bat_priv = container_of(priv_nc, struct batadv_priv, nc);
69+
70+
/* Schedule a new check */
71+
batadv_nc_start_timer(bat_priv);
72+
}
73+
74+
/**
75+
* batadv_nc_free - clean up network coding memory
76+
* @bat_priv: the bat priv with all the soft interface information
77+
*/
78+
void batadv_nc_free(struct batadv_priv *bat_priv)
79+
{
80+
cancel_delayed_work_sync(&bat_priv->nc.work);
81+
}

net/batman-adv/network-coding.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Copyright (C) 2012-2013 B.A.T.M.A.N. contributors:
2+
*
3+
* Martin Hundebøll, Jeppe Ledet-Pedersen
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_NETWORK_CODING_H_
21+
#define _NET_BATMAN_ADV_NETWORK_CODING_H_
22+
23+
#ifdef CONFIG_BATMAN_ADV_NC
24+
25+
int batadv_nc_init(struct batadv_priv *bat_priv);
26+
void batadv_nc_free(struct batadv_priv *bat_priv);
27+
void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv);
28+
29+
#else /* ifdef CONFIG_BATMAN_ADV_NC */
30+
31+
static inline int batadv_nc_init(struct batadv_priv *bat_priv)
32+
{
33+
return 0;
34+
}
35+
36+
static inline void batadv_nc_free(struct batadv_priv *bat_priv)
37+
{
38+
return;
39+
}
40+
41+
static inline void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv)
42+
{
43+
return;
44+
}
45+
46+
#endif /* ifdef CONFIG_BATMAN_ADV_NC */
47+
48+
#endif /* _NET_BATMAN_ADV_NETWORK_CODING_H_ */

net/batman-adv/soft-interface.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/if_ether.h>
3838
#include "unicast.h"
3939
#include "bridge_loop_avoidance.h"
40+
#include "network-coding.h"
4041

4142

4243
static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
@@ -544,6 +545,8 @@ struct net_device *batadv_softif_create(const char *name)
544545
if (ret < 0)
545546
goto unreg_soft_iface;
546547

548+
batadv_nc_init_bat_priv(bat_priv);
549+
547550
ret = batadv_sysfs_add_meshif(soft_iface);
548551
if (ret < 0)
549552
goto unreg_soft_iface;

net/batman-adv/sysfs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth,
442442
#ifdef CONFIG_BATMAN_ADV_DEBUG
443443
BATADV_ATTR_SIF_UINT(log_level, S_IRUGO | S_IWUSR, 0, BATADV_DBG_ALL, NULL);
444444
#endif
445+
#ifdef CONFIG_BATMAN_ADV_NC
446+
BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR, NULL);
447+
#endif
445448

446449
static struct batadv_attribute *batadv_mesh_attrs[] = {
447450
&batadv_attr_aggregated_ogms,
@@ -463,6 +466,9 @@ static struct batadv_attribute *batadv_mesh_attrs[] = {
463466
&batadv_attr_gw_bandwidth,
464467
#ifdef CONFIG_BATMAN_ADV_DEBUG
465468
&batadv_attr_log_level,
469+
#endif
470+
#ifdef CONFIG_BATMAN_ADV_NC
471+
&batadv_attr_network_coding,
466472
#endif
467473
NULL,
468474
};

net/batman-adv/types.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,14 @@ struct batadv_priv_dat {
427427
};
428428
#endif
429429

430+
/**
431+
* struct batadv_priv_nc - per mesh interface network coding private data
432+
* @work: work queue callback item for cleanup
433+
*/
434+
struct batadv_priv_nc {
435+
struct delayed_work work;
436+
};
437+
430438
/**
431439
* struct batadv_priv - per mesh interface data
432440
* @mesh_state: current status of the mesh (inactive/active/deactivating)
@@ -470,6 +478,8 @@ struct batadv_priv_dat {
470478
* @tt: translation table data
471479
* @vis: vis data
472480
* @dat: distributed arp table data
481+
* @network_coding: bool indicating whether network coding is enabled
482+
* @batadv_priv_nc: network coding data
473483
*/
474484
struct batadv_priv {
475485
atomic_t mesh_state;
@@ -522,6 +532,10 @@ struct batadv_priv {
522532
#ifdef CONFIG_BATMAN_ADV_DAT
523533
struct batadv_priv_dat dat;
524534
#endif
535+
#ifdef CONFIG_BATMAN_ADV_NC
536+
atomic_t network_coding;
537+
struct batadv_priv_nc nc;
538+
#endif /* CONFIG_BATMAN_ADV_NC */
525539
};
526540

527541
/**

0 commit comments

Comments
 (0)