Skip to contentSkip to conversation

batman-adv: throughput meter

PATCH Superseded Sven Eckelmann 3 participants 7 messages May 17, 2016 – May 18, 2016

Subsystems (2)

v9 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v9 cover batman-adv: throughput meter

Hi,

Antonio was kind enough to provide some feedback about the patchset. I have taken his suggestion and integrated all of them in the patchset.

batman-adv:

* rebase on top of current master+"batman-adv: Include main.h in all files"+ "batman-adv: Keep includes ordered by filename"
* adjust BATADV_DBG_TP_METER to bit 7 to avoid conflicts with mcast
* Renamed BATADV_TP_SIGINT to BATADV_TP_REASON_CANCEL
* Renamed batadv_tp_meter_reason enumerals to BATADV_TP_REASON*
* Remove unrelated patch chunk in batadv_iv_ogm_orig_add_if
* Re-add accidentally removed empty line from batadv_recv_my_icmp_packet
* define BATADV_TP_PLEN via BATADV_TP_PACKET_LEN (increases it to 1476)
* fixed whitespace problems in compat code
* remove double "a" in kerneldoc for batadv_tp_meter_reason

batctl:

* rebase on top of current master
* added include guards to tp_meter.h
* imported newest batman_adv.h and packet.h from batman-adv
* move iw/genl.c functions into own file "genl.c"
* adjust result handling based on new BATADV_TP_REASON_* names

The patchset lost one patch because it was merged in the meantime.

Kind regards,
Sven

#1 lore raw

PATCH v9 1/2 batman-adv: return netdev status in the TX path

From: Antonio Quartulli <[email protected]>

Return the proper netdev TX status along the TX path so that the tp_meter can understand when the queue is full and should stop sending packets.

---
v9:
* rebase on top of current master+"batman-adv: Include main.h in all files"+ "batman-adv: Keep includes ordered by filename"
v8:
* rebase on top of current master

---
 net/batman-adv/fragmentation.c | 41 +++++++++++++++++++++++++----------------
 net/batman-adv/fragmentation.h |  6 +++---
 net/batman-adv/main.c          |  4 +++-
 net/batman-adv/routing.c       | 23 ++++++++++++++---------
 net/batman-adv/send.c          | 25 +++++++++++++------------
 5 files changed, 58 insertions(+), 41 deletions(-)
net/batman-adv/fragmentation.c +25 -16
index 9f41a0a..0934730 100644
@@ -433,11 +433,12 @@ err:
  * @orig_node: final destination of the created fragments
  * @neigh_node: next-hop of the created fragments
  *
- * Return: true on success, false otherwise.
+ * Return: the netdev tx status or -1 in case of error.
+ * When -1 is returned the skb is not consumed.
  */
-bool batadv_frag_send_packet(struct sk_buff *skb,
-			     struct batadv_orig_node *orig_node,
-			     struct batadv_neigh_node *neigh_node)
+int batadv_frag_send_packet(struct sk_buff *skb,
+			    struct batadv_orig_node *orig_node,
+			    struct batadv_neigh_node *neigh_node)
 {
 	struct batadv_priv *bat_priv;
 	struct batadv_hard_iface *primary_if = NULL;
@@ -446,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
 	unsigned int mtu = neigh_node->if_incoming->net_dev->mtu;
 	unsigned int header_size = sizeof(frag_header);
 	unsigned int max_fragment_size, max_packet_size;
-	bool ret = false;
+	int ret = -1;
 
 	/* To avoid merge and refragmentation at next-hops we never send
 	 * fragments larger than BATADV_FRAG_MAX_FRAG_SIZE
@@ -457,12 +458,12 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
 
 	/* Don't even try to fragment, if we need more than 16 fragments */
 	if (skb->len > max_packet_size)
-		goto out_err;
+		goto out;
 
 	bat_priv = orig_node->bat_priv;
 	primary_if = batadv_primary_if_get_selected(bat_priv);
 	if (!primary_if)
-		goto out_err;
+		goto out;
 
 	/* Create one header to be copied to all fragments */
 	frag_header.packet_type = BATADV_UNICAST_FRAG;
@@ -488,23 +489,33 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
 	while (skb->len > max_fragment_size) {
 		skb_fragment = batadv_frag_create(skb, &frag_header, mtu);
 		if (!skb_fragment)
-			goto out_err;
+			goto out;
 
 		batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_TX);
 		batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES,
 				   skb_fragment->len + ETH_HLEN);
-		batadv_send_unicast_skb(skb_fragment, neigh_node);
+		ret = batadv_send_unicast_skb(skb_fragment, neigh_node);
+		if (ret != NET_XMIT_SUCCESS) {
+			/* return -1 so that the caller can free the original
+			 * skb
+			 */
+			ret = -1;
+			goto out;
+		}
+
 		frag_header.no++;
 
 		/* The initial check in this function should cover this case */
-		if (frag_header.no == BATADV_FRAG_MAX_FRAGMENTS - 1)
-			goto out_err;
+		if (frag_header.no == BATADV_FRAG_MAX_FRAGMENTS - 1) {
+			ret = -1;
+			goto out;
+		}
 	}
 
 	/* Make room for the fragment header. */
 	if (batadv_skb_head_push(skb, header_size) < 0 ||
 	    pskb_expand_head(skb, header_size + ETH_HLEN, 0, GFP_ATOMIC) < 0)
-		goto out_err;
+		goto out;
 
 	memcpy(skb->data, &frag_header, header_size);
 
@@ -512,11 +523,9 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
 	batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_TX);
 	batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES,
 			   skb->len + ETH_HLEN);
-	batadv_send_unicast_skb(skb, neigh_node);
+	ret = batadv_send_unicast_skb(skb, neigh_node);
 
-	ret = true;
-
-out_err:
+out:
 	if (primary_if)
 		batadv_hardif_put(primary_if);
 
net/batman-adv/fragmentation.h +3 -3
index 9ff77c7..3202fe3 100644
@@ -34,9 +34,9 @@ bool batadv_frag_skb_fwd(struct sk_buff *skb,
 			 struct batadv_orig_node *orig_node_src);
 bool batadv_frag_skb_buffer(struct sk_buff **skb,
 			    struct batadv_orig_node *orig_node);
-bool batadv_frag_send_packet(struct sk_buff *skb,
-			     struct batadv_orig_node *orig_node,
-			     struct batadv_neigh_node *neigh_node);
+int batadv_frag_send_packet(struct sk_buff *skb,
+			    struct batadv_orig_node *orig_node,
+			    struct batadv_neigh_node *neigh_node);
 
 /**
  * batadv_frag_check_entry - check if a list of fragments has timed out
net/batman-adv/main.c +3 -1
index e78b318..d12506b 100644
@@ -1194,6 +1194,7 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
 	unsigned char *tvlv_buff;
 	unsigned int tvlv_len;
 	ssize_t hdr_len = sizeof(*unicast_tvlv_packet);
+	int res;
 
 	orig_node = batadv_orig_hash_find(bat_priv, dst);
 	if (!orig_node)
@@ -1226,7 +1227,8 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
 	tvlv_buff += sizeof(*tvlv_hdr);
 	memcpy(tvlv_buff, tvlv_value, tvlv_value_len);
 
-	if (batadv_send_skb_to_orig(skb, orig_node, NULL) == NET_XMIT_DROP)
+	res = batadv_send_skb_to_orig(skb, orig_node, NULL);
+	if (!(res != -1 && dev_xmit_complete(res)))
 		kfree_skb(skb);
 out:
 	batadv_orig_node_put(orig_node);
net/batman-adv/routing.c +14 -9
index 93ee5c7..f27fb1d 100644
@@ -268,7 +268,10 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
 		icmph->ttl = BATADV_TTL;
 
 		res = batadv_send_skb_to_orig(skb, orig_node, NULL);
-		if (res != NET_XMIT_DROP)
+		if (res == -1)
+			goto out;
+
+		if (dev_xmit_complete(res))
 			ret = NET_RX_SUCCESS;
 
 		break;
@@ -290,7 +293,7 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
 	struct batadv_hard_iface *primary_if = NULL;
 	struct batadv_orig_node *orig_node = NULL;
 	struct batadv_icmp_packet *icmp_packet;
-	int ret = NET_RX_DROP;
+	int res, ret = NET_RX_DROP;
 
 	icmp_packet = (struct batadv_icmp_packet *)skb->data;
 
@@ -321,7 +324,8 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
 	icmp_packet->msg_type = BATADV_TTL_EXCEEDED;
 	icmp_packet->ttl = BATADV_TTL;
 
-	if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
+	res = batadv_send_skb_to_orig(skb, orig_node, NULL);
+	if (res != -1 && dev_xmit_complete(res))
 		ret = NET_RX_SUCCESS;
 
 out:
@@ -341,7 +345,7 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
 	struct ethhdr *ethhdr;
 	struct batadv_orig_node *orig_node = NULL;
 	int hdr_size = sizeof(struct batadv_icmp_header);
-	int ret = NET_RX_DROP;
+	int res, ret = NET_RX_DROP;
 
 	/* drop packet if it has not necessary minimum size */
 	if (unlikely(!pskb_may_pull(skb, hdr_size)))
@@ -407,7 +411,8 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
 	icmph->ttl--;
 
 	/* route it */
-	if (batadv_send_skb_to_orig(skb, orig_node, recv_if) != NET_XMIT_DROP)
+	res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
+	if (res != -1 && dev_xmit_complete(res))
 		ret = NET_RX_SUCCESS;
 
 out:
@@ -644,6 +649,8 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
 
 	len = skb->len;
 	res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
+	if (res == -1)
+		goto out;
 
 	/* translate transmit result into receive result */
 	if (res == NET_XMIT_SUCCESS) {
@@ -651,12 +658,10 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
 		batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
 		batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
 				   len + ETH_HLEN);
+	}
 
+	if (dev_xmit_complete(res))
 		ret = NET_RX_SUCCESS;
-	} else if (res == NET_XMIT_POLICED) {
-		/* skb was buffered and consumed */
-		ret = NET_RX_SUCCESS;
-	}
 
 out:
 	if (orig_node)
net/batman-adv/send.c +13 -12
index 45ca6ac..09f44cb 100644
@@ -155,8 +155,11 @@ int batadv_send_unicast_skb(struct sk_buff *skb,
  * host, NULL can be passed as recv_if and no interface alternating is
  * attempted.
  *
- * Return: NET_XMIT_SUCCESS on success, NET_XMIT_DROP on failure, or
- * NET_XMIT_POLICED if the skb is buffered for later transmit.
+ * Return: -1 on failure (and the skb is not consumed), NET_XMIT_POLICED if the
+ * skb is buffered for later transmit or the NET_XMIT status returned by the
+ * lower routine if the packet has been passed down.
+ *
+ * If the returning value is not -1 the skb has been consumed.
  */
 int batadv_send_skb_to_orig(struct sk_buff *skb,
 			    struct batadv_orig_node *orig_node,
@@ -164,7 +167,7 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
 {
 	struct batadv_priv *bat_priv = orig_node->bat_priv;
 	struct batadv_neigh_node *neigh_node;
-	int ret = NET_XMIT_DROP;
+	int ret = -1;
 
 	/* batadv_find_router() increases neigh_nodes refcount if found. */
 	neigh_node = batadv_find_router(bat_priv, orig_node, recv_if);
@@ -177,8 +180,7 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
 	if (atomic_read(&bat_priv->fragmentation) &&
 	    skb->len > neigh_node->if_incoming->net_dev->mtu) {
 		/* Fragment and send packet. */
-		if (batadv_frag_send_packet(skb, orig_node, neigh_node))
-			ret = NET_XMIT_SUCCESS;
+		ret = batadv_frag_send_packet(skb, orig_node, neigh_node);
 
 		goto out;
 	}
@@ -187,12 +189,10 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
 	 * (i.e. being forwarded). If the packet originates from this node or if
 	 * network coding fails, then send the packet as usual.
 	 */
-	if (recv_if && batadv_nc_skb_forward(skb, neigh_node)) {
+	if (recv_if && batadv_nc_skb_forward(skb, neigh_node))
 		ret = NET_XMIT_POLICED;
-	} else {
-		batadv_send_unicast_skb(skb, neigh_node);
-		ret = NET_XMIT_SUCCESS;
-	}
+	else
+		ret = batadv_send_unicast_skb(skb, neigh_node);
 
 out:
 	if (neigh_node)
@@ -318,7 +318,7 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
 {
 	struct batadv_unicast_packet *unicast_packet;
 	struct ethhdr *ethhdr;
-	int ret = NET_XMIT_DROP;
+	int res, ret = NET_XMIT_DROP;
 
 	if (!orig_node)
 		goto out;
@@ -355,7 +355,8 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
 	if (batadv_tt_global_client_is_roaming(bat_priv, ethhdr->h_dest, vid))
 		unicast_packet->ttvn = unicast_packet->ttvn - 1;
 
-	if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
+	res = batadv_send_skb_to_orig(skb, orig_node, NULL);
+	if (res != -1 && dev_xmit_complete(res))
 		ret = NET_XMIT_SUCCESS;
 
 out:
Signature · 1 line
2.8.1
#2 lore raw

PATCH v9 2/2 batman-adv: throughput meter implementation

In reply to Sven Eckelmann

From: Antonio Quartulli <[email protected]>

The throughput meter module is a simple, kernel-space replacement for throughtput measurements tool like iperf and netperf. It is intended to approximate TCP behaviour.

It is invoked through batctl: the protocol is connection oriented, with cumulative acknowledgment and a dynamic-size sliding window.

The test *can* be interrupted by batctl. A receiver side timeout avoids unlimited waitings for sender packets: after one second of inactivity, the receiver abort the ongoing test.

Based on a prototype from Edo Monticelli <[email protected]>

---
v9:
* rebase on top of current master+"batman-adv: Include main.h in all files"+ "batman-adv: Keep includes ordered by filename"
* adjust BATADV_DBG_TP_METER to bit 7 to avoid conflicts with mcast
* Renamed BATADV_TP_SIGINT to BATADV_TP_REASON_CANCEL
* Renamed batadv_tp_meter_reason enumerals to BATADV_TP_REASON*
* Remove unrelated patch chunk in batadv_iv_ogm_orig_add_if
* Re-add accidentally removed empty line from batadv_recv_my_icmp_packet
* define BATADV_TP_PLEN via BATADV_TP_PACKET_LEN (increases it to 1476)
* fixed whitespace problems in compat code
* remove double "a" in kerneldoc for batadv_tp_meter_reason
v8:
* rebase on top of current master
v7:
* add compatibility code for v3.13
* make batadv_netlink_mcgrps non-const because v3.12 needs it writable
v6:
* increase total_bytes to 64 bit to allow higher speeds/longer test times

---
 compat-include/net/genetlink.h  |  127 +++-
 include/uapi/linux/batman_adv.h |   41 ++
 net/batman-adv/Makefile         |    1 +
 net/batman-adv/icmp_socket.c    |    2 +
 net/batman-adv/main.c           |    2 +
 net/batman-adv/main.h           |   26 +-
 net/batman-adv/netlink.c        |  233 +++++-
 net/batman-adv/netlink.h        |    6 +
 net/batman-adv/packet.h         |   54 ++
 net/batman-adv/routing.c        |    8 +
 net/batman-adv/soft-interface.c |    2 +
 net/batman-adv/tp_meter.c       | 1503 +++++++++++++++++++++++++++++++++++++++
 net/batman-adv/tp_meter.h       |   34 +
 net/batman-adv/types.h          |  112 +++
 14 files changed, 2139 insertions(+), 12 deletions(-)
 create mode 100644 net/batman-adv/tp_meter.c
 create mode 100644 net/batman-adv/tp_meter.h
compat-include/net/genetlink.h +125 -2
index bf1ba3d..cd1cf36 100644
@@ -26,8 +26,131 @@
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
 
-#define genl_register_family_with_ops(family, ops)     \
-	genl_register_family_with_ops((family), (ops), ARRAY_SIZE(ops))
+#include <linux/export.h>
+
+struct batadv_genl_family {
+	/* data handled by the actual kernel */
+	struct genl_family family;
+
+	/* data which has to be copied to family by
+	 * batadv_genlmsg_multicast_netns
+	 */
+	unsigned int		id;
+	unsigned int		hdrsize;
+	char			name[GENL_NAMSIZ];
+	unsigned int		version;
+	unsigned int		maxattr;
+	bool			netnsok;
+	bool			parallel_ops;
+	int			(*pre_doit)(struct genl_ops *ops,
+					    struct sk_buff *skb,
+					    struct genl_info *info);
+	void			(*post_doit)(struct genl_ops *ops,
+					     struct sk_buff *skb,
+					     struct genl_info *info);
+	/* WARNING not supported
+	 * int			(*mcast_bind)(struct net *net, int group);
+	 * void			(*mcast_unbind)(struct net *net, int group);
+	 */
+	struct nlattr		**attrbuf;	/* private */
+	struct genl_ops		*ops;		/* private */
+	struct genl_multicast_group *mcgrps; /* private */
+	unsigned int		n_ops;		/* private */
+	unsigned int		n_mcgrps;	/* private */
+	/* unsigned int		mcgrp_offset;	private, WARNING unsupported */
+	struct list_head	family_list;	/* private */
+	struct module		*module;
+};
+
+#define genl_family batadv_genl_family
+
+#define genlmsg_multicast_netns batadv_genlmsg_multicast_netns
+
+static inline int
+batadv_genlmsg_multicast_netns(struct batadv_genl_family *family,
+			       struct net *net,
+			       struct sk_buff *skb,
+			       u32 portid, unsigned int group,
+			       gfp_t flags)
+{
+	group = family->mcgrps[group].id;
+	return nlmsg_multicast(
+		net->genl_sock,
+		skb, portid, group, flags);
+}
+
+#define genlmsg_put(_skb, _pid, _seq, _family, _flags, _cmd) \
+	genlmsg_put(_skb, _pid, _seq, &(_family)->family, _flags, _cmd)
+
+#define genl_unregister_family(_family) \
+	genl_unregister_family(&(_family)->family)
+
+#define genl_register_family_with_ops_groups(family, ops, grps) \
+	batadv_genl_register_family_with_ops_grps((family), \
+						  (ops), ARRAY_SIZE(ops), \
+						  (grps), ARRAY_SIZE(grps))
+
+static inline int batadv_genl_register_family(struct genl_family *family)
+{
+	unsigned int i;
+	int ret;
+
+	family->family.id = family->id;
+	family->family.hdrsize = family->hdrsize;
+	strncpy(family->family.name, family->name, sizeof(family->family.name));
+	family->family.version = family->version;
+	family->family.maxattr = family->maxattr;
+	family->family.netnsok = family->netnsok;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
+	family->family.parallel_ops = family->parallel_ops;
+#endif
+	family->family.pre_doit = family->pre_doit;
+	family->family.post_doit = family->post_doit;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)
+	family->family.module = family->module;
+#endif
+
+	ret = batadv_real_genl_register_family(&family->family);
+	if (ret < 0)
+		return ret;
+
+	family->attrbuf = family->family.attrbuf;
+	family->id = family->family.id;
+
+	for (i = 0; i < family->n_ops; i++) {
+		ret = genl_register_ops(&family->family, &family->ops[i]);
+		if (ret < 0)
+			goto err;
+	}
+
+	for (i = 0; i < family->n_mcgrps; i++) {
+		ret = genl_register_mc_group(&family->family,
+					     &family->mcgrps[i]);
+		if (ret)
+			goto err;
+	}
+
+	return 0;
+
+ err:
+	genl_unregister_family(family);
+	return ret;
+}
+
+static inline int
+batadv_genl_register_family_with_ops_grps(struct genl_family *family,
+					  struct genl_ops *ops, size_t n_ops,
+					  struct genl_multicast_group *mcgrps,
+					  size_t n_mcgrps)
+{
+	family->ops = ops;
+	family->n_ops = n_ops;
+	family->mcgrps = mcgrps;
+	family->n_mcgrps = n_mcgrps;
+	family->module = THIS_MODULE;
+
+	return batadv_genl_register_family(family);
+}
 
 #endif /* < KERNEL_VERSION(3, 13, 0) */
 
include/uapi/linux/batman_adv.h +41 -0

74 lines not on this page · raw message

net/batman-adv/Makefile +1 -0
index 4e5adba..91c96c3 100644
@@ -40,4 +40,5 @@ batman-adv-y += routing.o
 batman-adv-y += send.o
 batman-adv-y += soft-interface.o
 batman-adv-y += sysfs.o
+batman-adv-y += tp_meter.o
 batman-adv-y += translation-table.o
net/batman-adv/icmp_socket.c +2 -0
index 777aea1..5da3afa 100644
@@ -48,6 +48,7 @@
 #include "originator.h"
 #include "packet.h"
 #include "send.h"
+#include "tp_meter.h"
 
 static struct batadv_socket_client *batadv_socket_client_hash[256];
 
@@ -58,6 +59,7 @@ static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
 void batadv_socket_init(void)
 {
 	memset(batadv_socket_client_hash, 0, sizeof(batadv_socket_client_hash));
+	batadv_tp_meter_init();
 }
 
 static int batadv_socket_open(struct inode *inode, struct file *file)
net/batman-adv/main.c +2 -0
index d12506b..7dd3bbd 100644
@@ -144,6 +144,7 @@ int batadv_mesh_init(struct net_device *soft_iface)
 	spin_lock_init(&bat_priv->tvlv.container_list_lock);
 	spin_lock_init(&bat_priv->tvlv.handler_list_lock);
 	spin_lock_init(&bat_priv->softif_vlan_list_lock);
+	spin_lock_init(&bat_priv->tp_list_lock);
 
 	INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
 	INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
@@ -162,6 +163,7 @@ int batadv_mesh_init(struct net_device *soft_iface)
 	INIT_HLIST_HEAD(&bat_priv->tvlv.container_list);
 	INIT_HLIST_HEAD(&bat_priv->tvlv.handler_list);
 	INIT_HLIST_HEAD(&bat_priv->softif_vlan_list);
+	INIT_HLIST_HEAD(&bat_priv->tp_list);
 
 	ret = batadv_v_mesh_init(bat_priv);
 	if (ret < 0)
net/batman-adv/main.h +18 -8
index 94bf4f8..57258e0 100644
@@ -100,6 +100,9 @@
 #define BATADV_NUM_BCASTS_WIRELESS 3
 #define BATADV_NUM_BCASTS_MAX 3
 
+/* length of the single packet used by the TP meter */
+#define BATADV_TP_PACKET_LEN ETH_DATA_LEN
+
 /* msecs after which an ARP_REQUEST is sent in broadcast as fallback */
 #define ARP_REQ_DELAY 250
 /* numbers of originator to contact for any PUT/GET DHT operation */
@@ -131,6 +134,11 @@
 
 #define BATADV_NC_NODE_TIMEOUT 10000 /* Milliseconds */
 
+/**
+ * BATADV_TP_MAX_NUM - maximum number of simultaneously active tp sessions
+ */
+#define BATADV_TP_MAX_NUM 5
+
 enum batadv_mesh_state {
 	BATADV_MESH_INACTIVE,
 	BATADV_MESH_ACTIVE,
@@ -232,17 +240,19 @@ __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr);
  * @BATADV_DBG_DAT: ARP snooping and DAT related messages
  * @BATADV_DBG_NC: network coding related messages
  * @BATADV_DBG_MCAST: multicast related messages
+ * @BATADV_DBG_TP_METER: throughput meter messages
  * @BATADV_DBG_ALL: the union of all the above log levels
  */
 enum batadv_dbg_level {
-	BATADV_DBG_BATMAN = BIT(0),
-	BATADV_DBG_ROUTES = BIT(1),
-	BATADV_DBG_TT	  = BIT(2),
-	BATADV_DBG_BLA    = BIT(3),
-	BATADV_DBG_DAT    = BIT(4),
-	BATADV_DBG_NC	  = BIT(5),
-	BATADV_DBG_MCAST  = BIT(6),
-	BATADV_DBG_ALL    = 127,
+	BATADV_DBG_BATMAN	= BIT(0),
+	BATADV_DBG_ROUTES	= BIT(1),
+	BATADV_DBG_TT		= BIT(2),
+	BATADV_DBG_BLA		= BIT(3),
+	BATADV_DBG_DAT		= BIT(4),
+	BATADV_DBG_NC		= BIT(5),
+	BATADV_DBG_MCAST	= BIT(6),
+	BATADV_DBG_TP_METER	= BIT(7),
+	BATADV_DBG_ALL		= 127,
 };
 
 #ifdef CONFIG_BATMAN_ADV_DEBUG
net/batman-adv/netlink.c +231 -2

275 lines not on this page · raw message

net/batman-adv/netlink.h +6 -0
index 39044cc..945653a 100644
@@ -20,7 +20,13 @@
 
 #include "main.h"
 
+#include <linux/types.h>
+
 void batadv_netlink_register(void);
 void batadv_netlink_unregister(void);
 
+int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst,
+				  u8 result, u32 test_time, u64 total_bytes,
+				  u32 cookie);
+
 #endif /* _NET_BATMAN_ADV_NETLINK_H_ */
net/batman-adv/packet.h +54 -0

78 lines not on this page · raw message

net/batman-adv/routing.c +8 -0
index f27fb1d..b8c61fd 100644
@@ -45,6 +45,7 @@
 #include "packet.h"
 #include "send.h"
 #include "soft-interface.h"
+#include "tp_meter.h"
 #include "translation-table.h"
 
 static int batadv_route_unicast_packet(struct sk_buff *skb,
@@ -275,6 +276,13 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
 			ret = NET_RX_SUCCESS;
 
 		break;
+	case BATADV_TP:
+		if (!pskb_may_pull(skb, sizeof(struct batadv_icmp_tp_packet)))
+			goto out;
+
+		batadv_tp_meter_recv(bat_priv, skb);
+		ret = NET_RX_SUCCESS;
+		goto out;
 	default:
 		/* drop unknown type */
 		goto out;
net/batman-adv/soft-interface.c +2 -0
index b60999d..f518404 100644
@@ -841,6 +841,8 @@ static int batadv_softif_init_late(struct net_device *dev)
 #ifdef CONFIG_BATMAN_ADV_BLA
 	atomic_set(&bat_priv->bla.num_requests, 0);
 #endif
+	atomic_set(&bat_priv->tp_num, 0);
+
 	bat_priv->tt.last_changeset = NULL;
 	bat_priv->tt.last_changeset_len = 0;
 	bat_priv->isolation_mark = 0;
net/batman-adv/tp_meter.c new file +1503 -0

1,503 lines not on this page · raw message

net/batman-adv/tp_meter.h new file +34 -0
new file mode 100644
index 0000000..ba922c4
@@ -0,0 +1,34 @@
+/* Copyright (C) 2012-2016 B.A.T.M.A.N. contributors:
+ *
+ * Edo Monticelli, Antonio Quartulli
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _NET_BATMAN_ADV_TP_METER_H_
+#define _NET_BATMAN_ADV_TP_METER_H_
+
+#include "main.h"
+
+#include <linux/types.h>
+
+struct sk_buff;
+
+void batadv_tp_meter_init(void);
+void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
+		     u32 test_length, u32 *cookie);
+void batadv_tp_stop(struct batadv_priv *bat_priv, const u8 *dst,
+		    u8 return_value);
+void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb);
+
+#endif /* _NET_BATMAN_ADV_TP_METER_H_ */
net/batman-adv/types.h +112 -0

142 lines not on this page · raw message

Signature · 1 line
2.8.1
#3 lore raw

Re: [B.A.T.M.A.N.] [PATCH v9 2/2] batman-adv: throughput meter implementation

On Tue, May 17, 2016 at 07:32:32PM +0200, Sven Eckelmann wrote:

[...]

net/batman-adv/icmp_socket.c static void batadv_socket_add_packet(struct batadv_socket_client *socket_client, · line 62

Quoted 5 lines
net/batman-adv/icmp_socket.c +1 -0
@@ -58,6 +59,7 @@ static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
 void batadv_socket_init(void)
 {
 	memset(batadv_socket_client_hash, 0, sizeof(batadv_socket_client_hash));
+	batadv_tp_meter_init();

Sven,
one very last question (sorry for not spotting this earlier): if we don't handle the TP meter with the icmp_socket anymore, why do we tight the TP initialization to the socket initialization ?

Is there any reason to have it here ? Or we should move the batadv_tp_meter_init() call to somewhere else ?

[...]

net/batman-adv/netlink.c batadv_netlink_get_mesh_info(struct sk_buff *skb, struct genl_info *info) · line 207

Quoted 10 lines
net/batman-adv/netlink.c +10 -0
+/**
+ * batadv_netlink_tpmeter_notify - send tp_meter result via netlink to client
+ * @bat_priv: the bat priv with all the soft interface information
+ * @dst: destination of tp_meter session
+ * @result: reason for tp meter session stop
+ * @test_time: total time ot the tp_meter session
+ * @total_bytes: bytes acked to the receiver
+ * @cookie: cookie of tp_meter session
+ *
+ * Return: 0 on success, <0 on error

you forgot the space between < and 0 ;P but if the rest is ok, I am sure Marek could add it :)

The rest looks good. Thanks !

Signature · 1 line
Antonio Quartulli
maintainer
#4 lore raw

Re: [B.A.T.M.A.N.] [PATCH v9 2/2] batman-adv: throughput meter implementation

On Wednesday 18 May 2016 10:16:11 Antonio Quartulli wrote:
[...]

Quoted 6 lines

one very last question (sorry for not spotting this earlier): if we don't handle the TP meter with the icmp_socket anymore, why do we tight the TP initialization to the socket initialization ?

Is there any reason to have it here ? Or we should move the batadv_tp_meter_init() call to somewhere else ?

It was basically just because it is still bound to the ICMP stuff (even when it is not using the socket itself). But when thinking about it, then you are right. This should be moved to the global initialization. Not all ICMP handling is done in icmp_socket.c and thus this also doesn't have to be added here. main.c (batadv_init) is a better place for it.

[...]

Quoted 4 lines
Quoted 1 line

+ * Return: 0 on success, <0 on error

you forgot the space between < and 0 ;P but if the rest is ok, I am sure Marek could add it :)

Can I just say that it is an copy+paste error from your comment in bat_v_ogm.c ;)

Kind regards,
Sven

#5 lore raw

PATCH v9 1/1 batctl: introduce throughput meter support

In reply to Sven Eckelmann

From: Antonio Quartulli <[email protected]>

Add command to launch the throughput meter test. The throughput meter is a batman kernelspace tool for throughput measurements. The syntax is:

batctl tp <MAC>

The test is interruptible with SIGINT or SIGTERM; if the test succeeds with no error the throughput and the elapsed time are printed to stdout, otherwise occurred an error message is displayed (on stdout) accordingly.

Based on a prototype from Edo Monticelli <[email protected]>

---
v9:
- rebase on top of current master
- added include guards to tp_meter.h
- imported newest batman_adv.h and packet.h from batman-adv
- move iw/genl.c functions into own file "genl.c"
- adjust result handling based on new BATADV_TP_REASON_* names
v8:
- rebase on top of current master

---
 Makefile     |   2 +
 batman_adv.h |  41 +++++
 genl.c       | 140 ++++++++++++++++
 genl.h       |  31 ++++
 main.c       |   6 +
 main.h       |   2 +
 man/batctl.8 |  24 ++-
 netlink.c    |   7 +
 packet.h     |  54 ++++++
 tcpdump.c    |  14 +-
 tp_meter.c   | 540 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tp_meter.h   |  27 +++
 12 files changed, 885 insertions(+), 3 deletions(-)
 create mode 100644 genl.c
 create mode 100644 genl.h
 create mode 100644 tp_meter.c
 create mode 100644 tp_meter.h
Makefile +2 -0
index 3fa21f4..0cec413 100755
@@ -28,6 +28,7 @@ OBJ += bat-hosts.o
 OBJ += debugfs.o
 OBJ += debug.o
 OBJ += functions.o
+OBJ += genl.o
 OBJ += hash.o
 OBJ += ioctl.o
 OBJ += list-batman.o
@@ -36,6 +37,7 @@ OBJ += netlink.o
 OBJ += ping.o
 OBJ += sys.o
 OBJ += tcpdump.o
+OBJ += tp_meter.o
 OBJ += traceroute.o
 OBJ += translate.o
 OBJ_BISECT = bisect_iv.o
batman_adv.h +41 -0

74 lines not on this page · raw message

genl.c new file +140 -0

140 lines not on this page · raw message

genl.h new file +31 -0
new file mode 100644
index 0000000..0b622bb
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2009-2016  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ */
+
+#ifndef _BATCTL_GENL_H
+#define _BATCTL_GENL_H
+
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+
+int nl_get_multicast_id(struct nl_sock *sock, const char *family,
+			const char *group);
+
+#endif /* _BATCTL_GENL_H */
main.c +6 -0
index a2cda5b..5e1ecc7 100644
@@ -33,6 +33,7 @@
 #include "translate.h"
 #include "traceroute.h"
 #include "tcpdump.h"
+#include "tp_meter.h"
 #include "bisect_iv.h"
 #include "ioctl.h"
 #include "functions.h"
@@ -82,6 +83,7 @@ static void print_usage(void)
 	fprintf(stderr, " \tping|p                     <destination>     \tping another batman adv host via layer 2\n");
 	fprintf(stderr, " \ttraceroute|tr              <destination>     \ttraceroute another batman adv host via layer 2\n");
 	fprintf(stderr, " \ttcpdump|td                 <interface>       \ttcpdump layer 2 traffic on the given interface\n");
+	printf(" \tthroughputmeter|tp         <destination>     \tstart a throughput measurement\n");
 	fprintf(stderr, " \ttranslate|t                <destination>     \ttranslate a destination to the originator responsible for it\n");
 #ifdef BATCTL_BISECT
 	fprintf(stderr, " \tbisect_iv                  <file1> .. <fileN>\tanalyze given batman iv log files for routing stability\n");
@@ -162,6 +164,10 @@ int main(int argc, char **argv)
 
 		ret = ping(mesh_iface, argc - 1, argv + 1);
 
+	} else if ((strcmp(argv[1], "throughputmeter") == 0) || (strcmp(argv[1], "tp") == 0)) {
+
+		ret = tp_meter (mesh_iface, argc -1, argv + 1);
+
 	} else if ((strcmp(argv[1], "traceroute") == 0) || (strcmp(argv[1], "tr") == 0)) {
 
 		ret = traceroute(mesh_iface, argc - 1, argv + 1);
main.h +2 -0
index e94fc33..0e57f32 100644
@@ -47,10 +47,12 @@
 #endif
 
 #define __packed __attribute((packed))   /* linux kernel compat */
+#define __unused __attribute__((unused))
 #define BIT(nr)                 (1UL << (nr)) /* linux kernel compat */
 
 typedef uint8_t u8; /* linux kernel compat */
 typedef uint16_t u16; /* linux kernel compat */
+typedef uint32_t u32; /* linux kernel compat */
 
 extern char module_ver_path[];
 
man/batctl.8 +22 -2
index 05f68d3..8bac727 100644
@@ -36,9 +36,11 @@ B.A.T.M.A.N. advanced operates on layer 2. Thus all hosts participating in the v
 connected together for all protocols above layer 2. Therefore the common diagnosis tools do not work as expected. To
 overcome these problems batctl contains the commands \fBping\fP, \fBtraceroute\fP, \fBtcpdump\fP which provide similar
 functionality to the normal \fBping\fP(1), \fBtraceroute\fP(1), \fBtcpdump\fP(1) commands, but modified to layer 2
-behaviour or using the B.A.T.M.A.N. advanced protocol.
-.PP
+behaviour or using the B.A.T.M.A.N. advanced protocol. For similar reasons, \fBthroughputmeter\fP, a command to test network
+performances, is also included.
+
 .PP
+.Pp
 .SH OPTIONS
 .TP
 .I \fBoptions:
@@ -322,6 +324,24 @@ for routing loops. Use "\-t" to trace OGMs of a host throughout the network. Use
 nodes. The option "\-s" can be used to limit the output to a range of sequence numbers, between min and max, or to one
 specific sequence number, min. Furthermore using "\-o" you can filter the output to a specified originator. If "\-n" is
 given batctl will not replace the MAC addresses with bat\-host names in the output.
+.RE
+.br
+.IP "\fBthroughputmeter\fP|\fBtp\fP \fBMAC\fP"
+This command starts a throughput test entirely controlled by batman module in
+kernel space: the computational resources needed to align memory and copy data
+between user and kernel space that are required by other user space tools may
+represent a bootleneck on some low profile device.
+
+The test consist of the transfer of 14 MB of data between the two nodes. The
+protocol used to transfer the data is somehow similar to TCP, but simpler: some
+TCP features are still missing, thus protocol performances could be worst. Since
+a fixed amount of data is transferred the experiment duration depends on the
+network conditions. The experiment can be interrupted with CTRL + C. At the end
+of a succesful experiment the throughput in KBytes per second is returned,
+togheter with the experiment duration in millisecond and the amount of bytes
+transferred. If too many packets are lost or the specified MAC address is not
+reachable, a message notifing the error is returned instead of the result.
+.RE
 .br
 .SH FILES
 .TP
netlink.c +7 -0
index 74d7566..afb7122 100644
@@ -41,4 +41,11 @@ struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
 	[BATADV_ATTR_HARD_ADDRESS]	= { .type = NLA_UNSPEC,
 					    .minlen = ETH_ALEN,
 					    .maxlen = ETH_ALEN },
+	[BATADV_ATTR_ORIG_ADDRESS]	= { .type = NLA_UNSPEC,
+					    .minlen = ETH_ALEN,
+					    .maxlen = ETH_ALEN },
+	[BATADV_ATTR_TPMETER_RESULT]	= { .type = NLA_U8 },
+	[BATADV_ATTR_TPMETER_TEST_TIME]	= { .type = NLA_U32 },
+	[BATADV_ATTR_TPMETER_BYTES]	= { .type = NLA_U64 },
+	[BATADV_ATTR_TPMETER_COOKIE]	= { .type = NLA_U32 },
 };
packet.h +54 -0

78 lines not on this page · raw message

tcpdump.c +13 -1
index 363e9e4..be0c4f0 100644
@@ -808,11 +808,14 @@ static void dump_batman_elp(unsigned char *packet_buff, ssize_t buff_len,
 static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed)
 {
 	struct batadv_icmp_packet *icmp_packet;
+	struct batadv_icmp_tp_packet *tp;
+
 	char *name;
 
 	LEN_CHECK((size_t)buff_len - sizeof(struct ether_header), sizeof(struct batadv_icmp_packet), "BAT ICMP");
 
 	icmp_packet = (struct batadv_icmp_packet *)(packet_buff + sizeof(struct ether_header));
+	tp = (struct batadv_icmp_tp_packet *)icmp_packet;
 
 	if (!time_printed)
 		print_time();
@@ -820,7 +823,8 @@ static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int r
 	printf("BAT %s > ",
 	       get_name_by_macaddr((struct ether_addr *)icmp_packet->orig, read_opt));
 
-	name = get_name_by_macaddr((struct ether_addr *)icmp_packet->dst, read_opt);
+	name = get_name_by_macaddr((struct ether_addr *)icmp_packet->dst,
+				    read_opt);
 
 	switch (icmp_packet->msg_type) {
 	case BATADV_ECHO_REPLY:
@@ -841,6 +845,14 @@ static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int r
 			icmp_packet->ttl, icmp_packet->version,
 			(size_t)buff_len - sizeof(struct ether_header));
 		break;
+	case BATADV_TP:
+		printf("%s: ICMP TP type %s (%hhu), id %hhu, seq %u, ttl %2d, v %d, length %zu\n",
+		       name, tp->subtype == BATADV_TP_MSG ? "MSG" :
+			     tp->subtype == BATADV_TP_ACK ? "ACK" : "N/A",
+		       tp->subtype, tp->uid, ntohl(tp->seqno), tp->ttl,
+		       tp->version,
+		       (size_t)buff_len - sizeof(struct ether_header));
+		break;
 	default:
 		printf("%s: ICMP type %hhu, length %zu\n",
 			name, icmp_packet->msg_type,
tp_meter.c new file +540 -0

540 lines not on this page · raw message

tp_meter.h new file +27 -0
new file mode 100644
index 0000000..aef4dbc
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2013-2016 B.A.T.M.A.N. contributors:
+ *
+ * Antonio Quartulli <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ */
+
+#ifndef _BATCTL_TP_METER_H
+#define _BATCTL_TP_METER_H
+
+int tp_meter(char *mesh_iface, int argc, char **argv);
+
+#endif /* _BATCTL_TP_METER_H */
Signature · 1 line
2.8.1
#6 lore raw

PATCH v10 1/1 batctl: introduce throughput meter support

From: Antonio Quartulli <[email protected]>

Add command to launch the throughput meter test. The throughput meter is a batman kernelspace tool for throughput measurements. The syntax is:

batctl tp <MAC>

The test is interruptible with SIGINT or SIGTERM; if the test succeeds with no error the throughput and the elapsed time are printed to stdout, otherwise occurred an error message is displayed (on stdout) accordingly.

Based on a prototype from Edo Monticelli <[email protected]>

---
v10:
- fix "a a" typo in batman_adv.h
v9:
- rebase on top of current master
- added include guards to tp_meter.h
- imported newest batman_adv.h and packet.h from batman-adv
- move iw/genl.c functions into own file "genl.c"
- adjust result handling based on new BATADV_TP_REASON_* names
v8:
- rebase on top of current master

---
 Makefile     |   2 +
 batman_adv.h |  41 +++++
 genl.c       | 140 ++++++++++++++++
 genl.h       |  31 ++++
 main.c       |   6 +
 main.h       |   2 +
 man/batctl.8 |  24 ++-
 netlink.c    |   7 +
 packet.h     |  54 ++++++
 tcpdump.c    |  14 +-
 tp_meter.c   | 540 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tp_meter.h   |  27 +++
 12 files changed, 885 insertions(+), 3 deletions(-)
 create mode 100644 genl.c
 create mode 100644 genl.h
 create mode 100644 tp_meter.c
 create mode 100644 tp_meter.h
Makefile +2 -0
index 3fa21f4..0cec413 100755
@@ -28,6 +28,7 @@ OBJ += bat-hosts.o
 OBJ += debugfs.o
 OBJ += debug.o
 OBJ += functions.o
+OBJ += genl.o
 OBJ += hash.o
 OBJ += ioctl.o
 OBJ += list-batman.o
@@ -36,6 +37,7 @@ OBJ += netlink.o
 OBJ += ping.o
 OBJ += sys.o
 OBJ += tcpdump.o
+OBJ += tp_meter.o
 OBJ += traceroute.o
 OBJ += translate.o
 OBJ_BISECT = bisect_iv.o
batman_adv.h +41 -0

74 lines not on this page · raw message

genl.c new file +140 -0

140 lines not on this page · raw message

genl.h new file +31 -0
new file mode 100644
index 0000000..0b622bb
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2009-2016  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ */
+
+#ifndef _BATCTL_GENL_H
+#define _BATCTL_GENL_H
+
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+
+int nl_get_multicast_id(struct nl_sock *sock, const char *family,
+			const char *group);
+
+#endif /* _BATCTL_GENL_H */
main.c +6 -0
index a2cda5b..5e1ecc7 100644
@@ -33,6 +33,7 @@
 #include "translate.h"
 #include "traceroute.h"
 #include "tcpdump.h"
+#include "tp_meter.h"
 #include "bisect_iv.h"
 #include "ioctl.h"
 #include "functions.h"
@@ -82,6 +83,7 @@ static void print_usage(void)
 	fprintf(stderr, " \tping|p                     <destination>     \tping another batman adv host via layer 2\n");
 	fprintf(stderr, " \ttraceroute|tr              <destination>     \ttraceroute another batman adv host via layer 2\n");
 	fprintf(stderr, " \ttcpdump|td                 <interface>       \ttcpdump layer 2 traffic on the given interface\n");
+	printf(" \tthroughputmeter|tp         <destination>     \tstart a throughput measurement\n");
 	fprintf(stderr, " \ttranslate|t                <destination>     \ttranslate a destination to the originator responsible for it\n");
 #ifdef BATCTL_BISECT
 	fprintf(stderr, " \tbisect_iv                  <file1> .. <fileN>\tanalyze given batman iv log files for routing stability\n");
@@ -162,6 +164,10 @@ int main(int argc, char **argv)
 
 		ret = ping(mesh_iface, argc - 1, argv + 1);
 
+	} else if ((strcmp(argv[1], "throughputmeter") == 0) || (strcmp(argv[1], "tp") == 0)) {
+
+		ret = tp_meter (mesh_iface, argc -1, argv + 1);
+
 	} else if ((strcmp(argv[1], "traceroute") == 0) || (strcmp(argv[1], "tr") == 0)) {
 
 		ret = traceroute(mesh_iface, argc - 1, argv + 1);
main.h +2 -0
index e94fc33..0e57f32 100644
@@ -47,10 +47,12 @@
 #endif
 
 #define __packed __attribute((packed))   /* linux kernel compat */
+#define __unused __attribute__((unused))
 #define BIT(nr)                 (1UL << (nr)) /* linux kernel compat */
 
 typedef uint8_t u8; /* linux kernel compat */
 typedef uint16_t u16; /* linux kernel compat */
+typedef uint32_t u32; /* linux kernel compat */
 
 extern char module_ver_path[];
 
man/batctl.8 +22 -2
index 05f68d3..8bac727 100644
@@ -36,9 +36,11 @@ B.A.T.M.A.N. advanced operates on layer 2. Thus all hosts participating in the v
 connected together for all protocols above layer 2. Therefore the common diagnosis tools do not work as expected. To
 overcome these problems batctl contains the commands \fBping\fP, \fBtraceroute\fP, \fBtcpdump\fP which provide similar
 functionality to the normal \fBping\fP(1), \fBtraceroute\fP(1), \fBtcpdump\fP(1) commands, but modified to layer 2
-behaviour or using the B.A.T.M.A.N. advanced protocol.
-.PP
+behaviour or using the B.A.T.M.A.N. advanced protocol. For similar reasons, \fBthroughputmeter\fP, a command to test network
+performances, is also included.
+
 .PP
+.Pp
 .SH OPTIONS
 .TP
 .I \fBoptions:
@@ -322,6 +324,24 @@ for routing loops. Use "\-t" to trace OGMs of a host throughout the network. Use
 nodes. The option "\-s" can be used to limit the output to a range of sequence numbers, between min and max, or to one
 specific sequence number, min. Furthermore using "\-o" you can filter the output to a specified originator. If "\-n" is
 given batctl will not replace the MAC addresses with bat\-host names in the output.
+.RE
+.br
+.IP "\fBthroughputmeter\fP|\fBtp\fP \fBMAC\fP"
+This command starts a throughput test entirely controlled by batman module in
+kernel space: the computational resources needed to align memory and copy data
+between user and kernel space that are required by other user space tools may
+represent a bootleneck on some low profile device.
+
+The test consist of the transfer of 14 MB of data between the two nodes. The
+protocol used to transfer the data is somehow similar to TCP, but simpler: some
+TCP features are still missing, thus protocol performances could be worst. Since
+a fixed amount of data is transferred the experiment duration depends on the
+network conditions. The experiment can be interrupted with CTRL + C. At the end
+of a succesful experiment the throughput in KBytes per second is returned,
+togheter with the experiment duration in millisecond and the amount of bytes
+transferred. If too many packets are lost or the specified MAC address is not
+reachable, a message notifing the error is returned instead of the result.
+.RE
 .br
 .SH FILES
 .TP
netlink.c +7 -0
index 74d7566..afb7122 100644
@@ -41,4 +41,11 @@ struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
 	[BATADV_ATTR_HARD_ADDRESS]	= { .type = NLA_UNSPEC,
 					    .minlen = ETH_ALEN,
 					    .maxlen = ETH_ALEN },
+	[BATADV_ATTR_ORIG_ADDRESS]	= { .type = NLA_UNSPEC,
+					    .minlen = ETH_ALEN,
+					    .maxlen = ETH_ALEN },
+	[BATADV_ATTR_TPMETER_RESULT]	= { .type = NLA_U8 },
+	[BATADV_ATTR_TPMETER_TEST_TIME]	= { .type = NLA_U32 },
+	[BATADV_ATTR_TPMETER_BYTES]	= { .type = NLA_U64 },
+	[BATADV_ATTR_TPMETER_COOKIE]	= { .type = NLA_U32 },
 };
packet.h +54 -0

78 lines not on this page · raw message

tcpdump.c +13 -1
index 363e9e4..be0c4f0 100644
@@ -808,11 +808,14 @@ static void dump_batman_elp(unsigned char *packet_buff, ssize_t buff_len,
 static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed)
 {
 	struct batadv_icmp_packet *icmp_packet;
+	struct batadv_icmp_tp_packet *tp;
+
 	char *name;
 
 	LEN_CHECK((size_t)buff_len - sizeof(struct ether_header), sizeof(struct batadv_icmp_packet), "BAT ICMP");
 
 	icmp_packet = (struct batadv_icmp_packet *)(packet_buff + sizeof(struct ether_header));
+	tp = (struct batadv_icmp_tp_packet *)icmp_packet;
 
 	if (!time_printed)
 		print_time();
@@ -820,7 +823,8 @@ static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int r
 	printf("BAT %s > ",
 	       get_name_by_macaddr((struct ether_addr *)icmp_packet->orig, read_opt));
 
-	name = get_name_by_macaddr((struct ether_addr *)icmp_packet->dst, read_opt);
+	name = get_name_by_macaddr((struct ether_addr *)icmp_packet->dst,
+				    read_opt);
 
 	switch (icmp_packet->msg_type) {
 	case BATADV_ECHO_REPLY:
@@ -841,6 +845,14 @@ static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int r
 			icmp_packet->ttl, icmp_packet->version,
 			(size_t)buff_len - sizeof(struct ether_header));
 		break;
+	case BATADV_TP:
+		printf("%s: ICMP TP type %s (%hhu), id %hhu, seq %u, ttl %2d, v %d, length %zu\n",
+		       name, tp->subtype == BATADV_TP_MSG ? "MSG" :
+			     tp->subtype == BATADV_TP_ACK ? "ACK" : "N/A",
+		       tp->subtype, tp->uid, ntohl(tp->seqno), tp->ttl,
+		       tp->version,
+		       (size_t)buff_len - sizeof(struct ether_header));
+		break;
 	default:
 		printf("%s: ICMP type %hhu, length %zu\n",
 			name, icmp_packet->msg_type,
tp_meter.c new file +540 -0

540 lines not on this page · raw message

tp_meter.h new file +27 -0
new file mode 100644
index 0000000..aef4dbc
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2013-2016 B.A.T.M.A.N. contributors:
+ *
+ * Antonio Quartulli <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ */
+
+#ifndef _BATCTL_TP_METER_H
+#define _BATCTL_TP_METER_H
+
+int tp_meter(char *mesh_iface, int argc, char **argv);
+
+#endif /* _BATCTL_TP_METER_H */
Signature · 1 line
2.8.1