Skip to content

Commit b68fa91

Browse files
author
marek
committed
[batman] add extra hop penalty if incoming and outcoming interface are the same wifi interface
Some setups use multiple radios link on different channels to increase the throughput. This patch allows batman to detect these setups. git-svn-id: http://downloads.open-mesh.org/svn/batman/trunk/batman@1276 45894c77-fb22-0410-b583-ff6e7d5dbf6c
1 parent 9182a1a commit b68fa91

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

batman.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,18 @@
8686
#define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
8787
#define TQ_TOTAL_BIDRECT_LIMIT 1
8888

89-
#define TQ_HOP_PENALTY 10
89+
/**
90+
* hop penalty is applied "twice"
91+
* when the packet comes in and if rebroadcasted via the same interface
92+
*/
93+
#define TQ_HOP_PENALTY 5
9094
#define DEFAULT_ROUTING_CLASS 30
9195

92-
#define MAX_AGGREGATION_BYTES 512 /* should not be bigger than 512 bytes or change the size of forw_node->direct_link_flags */
96+
/**
97+
* should not be bigger than 512 bytes or change the size of
98+
* forw_node->direct_link_flags and forw_node->in_if_num
99+
*/
100+
#define MAX_AGGREGATION_BYTES 512
93101
#define MAX_AGGREGATION_MS 100
94102

95103
#define ROUTE_TYPE_UNICAST 0
@@ -248,6 +256,7 @@ struct forw_node /* structure for forw_list maintaining packets
248256
unsigned char *pack_buff;
249257
uint16_t pack_buff_len;
250258
uint32_t direct_link_flags;
259+
uint8_t in_if_num[32];
251260
uint8_t num_packets;
252261
struct batman_if *if_outgoing;
253262
};
@@ -279,6 +288,7 @@ struct batman_if
279288
struct sockaddr_in broad;
280289
uint32_t netaddr;
281290
uint8_t netmask;
291+
uint8_t is_wifi_if;
282292
struct bat_packet out;
283293
};
284294

linux/kernel.c

+21
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828
#include <sys/ioctl.h>
2929
#include <sys/socket.h>
3030
#include <inttypes.h>
31+
#include <net/if.h>
3132

3233
#include "../os.h"
3334
#include "../batman.h"
3435

3536

3637
#define IOCGETNWDEV 1
3738

39+
#ifndef SIOCGIWNAME
40+
#define SIOCGIWNAME 0x8B01
41+
#endif
3842

3943

4044
static int get_integer_file(const char* filename)
@@ -177,3 +181,20 @@ int32_t use_gateway_module(void)
177181

178182
return fd;
179183
}
184+
185+
int is_wifi_interface(char *dev, int fd)
186+
{
187+
struct ifreq int_req;
188+
char *colon_ptr;
189+
190+
memset(&int_req, 0, sizeof (struct ifreq));
191+
strncpy(int_req.ifr_name, dev, IFNAMSIZ - 1);
192+
193+
if ((colon_ptr = strchr(int_req.ifr_name, ':')) != NULL)
194+
*colon_ptr = '\0';
195+
196+
if (ioctl(fd, SIOCGIWNAME, &int_req) >= 0)
197+
return 1;
198+
199+
return 0;
200+
}

os.h

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void set_forwarding( int32_t state );
7777
int32_t get_forwarding( void );
7878
int8_t bind_to_iface( int32_t sock, char *dev );
7979
int32_t use_gateway_module(void);
80+
int is_wifi_interface(char *dev, int fd);
8081

8182
/* posix.c */
8283
void print_animation( void );

posix/init.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,9 @@ static void activate_interface(struct batman_if *batman_if)
919919
#else
920920
batman_if->if_index = 0;
921921
#endif
922+
batman_if->is_wifi_if = is_wifi_interface(batman_if->dev, batman_if->udp_recv_sock);
922923

923-
if ( ioctl( batman_if->udp_recv_sock, SIOCGIFNETMASK, &int_req ) < 0 ) {
924+
if (ioctl(batman_if->udp_recv_sock, SIOCGIFNETMASK, &int_req) < 0) {
924925

925926
debug_output(3, "Error - can't get netmask address of interface %s: %s\n", batman_if->dev, strerror(errno));
926927
goto error;

schedule.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void schedule_own_packet(struct batman_if *batman_if)
4949
forw_node_new->own = 1;
5050
forw_node_new->num_packets = 0;
5151
forw_node_new->direct_link_flags = 0;
52+
forw_node_new->in_if_num[forw_node_new->num_packets] = 255;
5253

5354
/* non-primary interfaces do not send hna information */
5455
if ((num_hna_local > 0) && (batman_if->if_num == 0)) {
@@ -235,11 +236,14 @@ void schedule_forward_packet(struct orig_node *orig_node, struct bat_packet *in,
235236

236237
/* apply hop penalty */
237238
bat_packet->tq = (bat_packet->tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE);
239+
238240
debug_output(4, "forwarding: tq_orig: %i, tq_avg: %i, tq_forw: %i, ttl_orig: %i, ttl_forw: %i \n", in->tq, tq_avg, bat_packet->tq, in->ttl - 1, bat_packet->ttl);
239241

240242
/* change sequence number to network order */
241243
bat_packet->seqno = htons(bat_packet->seqno);
242244

245+
forw_node_new->in_if_num[forw_node_new->num_packets] = if_outgoing->if_num;
246+
243247
if (directlink)
244248
bat_packet->flags = DIRECTLINK;
245249
else
@@ -299,7 +303,6 @@ void send_outstanding_packets(uint32_t curr_time)
299303
if (((directlink) && (bat_packet->ttl == 1)) ||
300304
((forw_node->own) && (forw_node->if_outgoing->if_num > 0))) {
301305

302-
303306
debug_output(4, "%s packet (originator %s, seqno %d, TTL %d) on interface %s\n", (forw_node->own ? "Sending own" : "Forwarding"), orig_str, ntohs(bat_packet->seqno), bat_packet->ttl, forw_node->if_outgoing->dev);
304307

305308
if (send_udp_packet(forw_node->pack_buff, forw_node->pack_buff_len, &forw_node->if_outgoing->broad, forw_node->if_outgoing->udp_send_sock, forw_node->if_outgoing) < 0)
@@ -328,7 +331,11 @@ void send_outstanding_packets(uint32_t curr_time)
328331
if (curr_packet_num > 0)
329332
addr_to_string(bat_packet->orig, orig_str, ADDR_STR_LEN);
330333

331-
debug_output(4, "%s %spacket (originator %s, seqno %d, TTL %d, IDF %s) on interface %s\n", (curr_packet_num > 0 ? "Forwarding" : (forw_node->own ? "Sending own" : "Forwarding")), (curr_packet_num > 0 ? "aggregated " : ""), orig_str, ntohs(bat_packet->seqno), bat_packet->ttl, (bat_packet->flags & DIRECTLINK ? "on" : "off"), batman_if->dev);
334+
/* if the outgoing interface is a wifi interface and the incoming interface add extra penalty */
335+
if ((batman_if->is_wifi_if) && (forw_node->in_if_num[curr_packet_num] == batman_if->if_num))
336+
bat_packet->tq -= 2 * hop_penalty;
337+
338+
debug_output(4, "%s %spacket (originator %s, seqno %d, TQ %d, TTL %d, IDF %s) on interface %s\n", (curr_packet_num > 0 ? "Forwarding" : (forw_node->own ? "Sending own" : "Forwarding")), (curr_packet_num > 0 ? "aggregated " : ""), orig_str, ntohs(bat_packet->seqno), bat_packet->tq, bat_packet->ttl, (bat_packet->flags & DIRECTLINK ? "on" : "off"), batman_if->dev);
332339

333340
curr_packet_len += sizeof(struct bat_packet) + bat_packet->hna_len * 5;
334341
curr_packet_num++;

0 commit comments

Comments
 (0)