Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b5ecc68 authored by Antonio Quartulli's avatar Antonio Quartulli Committed by Antonio Quartulli
Browse files

batman-adv: add throughput override attribute to hard_ifaces



This attribute is exported to user space to disable the link
throughput auto-detection by setting a fixed value.
The throughput override value is used when batman-adv is
computing the link throughput towards a neighbour.

If the value is set to 0 then batman-adv will try to detect
the throughput by itself.

Signed-off-by: default avatarAntonio Quartulli <antonio@open-mesh.com>
Signed-off-by: default avatarMarek Lindner <mareklindner@neomailbox.ch>
parent 9323158e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line

What:		/sys/class/net/<iface>/batman-adv/throughput_override
Date:		Feb 2014
Contact:	Antonio Quartulli <antonio@meshcoding.com>
description:
		Defines the throughput value to be used by B.A.T.M.A.N. V
		when estimating the link throughput using this interface.
		If the value is set to 0 then batman-adv will try to
		estimate the throughput by itself.

What:           /sys/class/net/<iface>/batman-adv/elp_interval
Date:           Feb 2014
Contact:        Linus Lüssing <linus.luessing@web.de>
+6 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "bat_algo.h"
#include "main.h"

#include <linux/atomic.h>
#include <linux/cache.h>
#include <linux/init.h>

@@ -37,6 +38,11 @@ static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)
	if (ret < 0)
		batadv_v_elp_iface_disable(hard_iface);

	/* enable link throughput auto-detection by setting the throughput
	 * override to zero
	 */
	atomic_set(&hard_iface->bat_v.throughput_override, 0);

	return ret;
}

+2 −2
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@
 *
 * Return: false on parse error and true otherwise.
 */
static bool batadv_parse_throughput(struct net_device *net_dev, char *buff,
bool batadv_parse_throughput(struct net_device *net_dev, char *buff,
			     const char *description, u32 *throughput)
{
	enum batadv_bandwidth_units bw_unit_type = BATADV_BW_UNIT_KBIT;
+2 −0
Original line number Diff line number Diff line
@@ -49,5 +49,7 @@ ssize_t batadv_gw_bandwidth_set(struct net_device *net_dev, char *buff,
void batadv_gw_tvlv_container_update(struct batadv_priv *bat_priv);
void batadv_gw_init(struct batadv_priv *bat_priv);
void batadv_gw_free(struct batadv_priv *bat_priv);
bool batadv_parse_throughput(struct net_device *net_dev, char *buff,
			     const char *description, u32 *throughput);

#endif /* _NET_BATMAN_ADV_GATEWAY_COMMON_H_ */
+74 −0
Original line number Diff line number Diff line
@@ -917,12 +917,85 @@ static ssize_t batadv_show_iface_status(struct kobject *kobj,
	return length;
}

#ifdef CONFIG_BATMAN_ADV_BATMAN_V

/**
 * batadv_store_throughput_override - parse and store throughput override
 *  entered by the user
 * @kobj: kobject representing the private mesh sysfs directory
 * @attr: the batman-adv attribute the user is interacting with
 * @buff: the buffer containing the user data
 * @count: number of bytes in the buffer
 *
 * Return: 'count' on success or a negative error code in case of failure
 */
static ssize_t batadv_store_throughput_override(struct kobject *kobj,
						struct attribute *attr,
						char *buff, size_t count)
{
	struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
	struct batadv_hard_iface *hard_iface;
	u32 tp_override;
	u32 old_tp_override;
	bool ret;

	hard_iface = batadv_hardif_get_by_netdev(net_dev);
	if (!hard_iface)
		return -EINVAL;

	if (buff[count - 1] == '\n')
		buff[count - 1] = '\0';

	ret = batadv_parse_throughput(net_dev, buff, "throughput_override",
				      &tp_override);
	if (!ret)
		return count;

	old_tp_override = atomic_read(&hard_iface->bat_v.throughput_override);
	if (old_tp_override == tp_override)
		goto out;

	batadv_info(net_dev, "%s: Changing from: %u.%u MBit to: %u.%u MBit\n",
		    "throughput_override",
		    old_tp_override / 10, old_tp_override % 10,
		    tp_override / 10, tp_override % 10);

	atomic_set(&hard_iface->bat_v.throughput_override, tp_override);

out:
	batadv_hardif_put(hard_iface);
	return count;
}

static ssize_t batadv_show_throughput_override(struct kobject *kobj,
					       struct attribute *attr,
					       char *buff)
{
	struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
	struct batadv_hard_iface *hard_iface;
	u32 tp_override;

	hard_iface = batadv_hardif_get_by_netdev(net_dev);
	if (!hard_iface)
		return -EINVAL;

	tp_override = atomic_read(&hard_iface->bat_v.throughput_override);

	return sprintf(buff, "%u.%u MBit\n", tp_override / 10,
		       tp_override % 10);
}

#endif

static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface,
		   batadv_store_mesh_iface);
static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL);
#ifdef CONFIG_BATMAN_ADV_BATMAN_V
BATADV_ATTR_HIF_UINT(elp_interval, bat_v.elp_interval, S_IRUGO | S_IWUSR,
		     2 * BATADV_JITTER, INT_MAX, NULL);
static BATADV_ATTR(throughput_override, S_IRUGO | S_IWUSR,
		   batadv_show_throughput_override,
		   batadv_store_throughput_override);
#endif

static struct batadv_attribute *batadv_batman_attrs[] = {
@@ -930,6 +1003,7 @@ static struct batadv_attribute *batadv_batman_attrs[] = {
	&batadv_attr_iface_status,
#ifdef CONFIG_BATMAN_ADV_BATMAN_V
	&batadv_attr_elp_interval,
	&batadv_attr_throughput_override,
#endif
	NULL,
};
Loading