aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/bat_iv_ogm.c
diff options
context:
space:
mode:
authorSven Eckelmann <sven@narfation.org>2012-06-03 16:19:17 -0400
committerAntonio Quartulli <ordex@autistici.org>2012-06-28 02:45:05 -0400
commit42d0b044b7c9e5821f1bf3e2b4ea7861417c11c2 (patch)
tree3dedf87facfbc4dd0392256e93088c18509e1391 /net/batman-adv/bat_iv_ogm.c
parentedbf7ff72312afcc502014ccf3c72c49fa55722a (diff)
batman-adv: Prefix main defines with BATADV_
Reported-by: Martin Hundebøll <martin@hundeboll.net> Signed-off-by: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/bat_iv_ogm.c')
-rw-r--r--net/batman-adv/bat_iv_ogm.c103
1 files changed, 61 insertions, 42 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 245bb2d7647c..bbe0f123d2a5 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -74,8 +74,8 @@ static int batadv_iv_ogm_iface_enable(struct hard_iface *hard_iface)
74 batman_ogm_packet->header.packet_type = BAT_IV_OGM; 74 batman_ogm_packet->header.packet_type = BAT_IV_OGM;
75 batman_ogm_packet->header.version = BATADV_COMPAT_VERSION; 75 batman_ogm_packet->header.version = BATADV_COMPAT_VERSION;
76 batman_ogm_packet->header.ttl = 2; 76 batman_ogm_packet->header.ttl = 2;
77 batman_ogm_packet->flags = NO_FLAGS; 77 batman_ogm_packet->flags = BATADV_NO_FLAGS;
78 batman_ogm_packet->tq = TQ_MAX_VALUE; 78 batman_ogm_packet->tq = BATADV_TQ_MAX_VALUE;
79 batman_ogm_packet->tt_num_changes = 0; 79 batman_ogm_packet->tt_num_changes = 0;
80 batman_ogm_packet->ttvn = 0; 80 batman_ogm_packet->ttvn = 0;
81 81
@@ -108,29 +108,37 @@ static void batadv_iv_ogm_primary_iface_set(struct hard_iface *hard_iface)
108 108
109 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; 109 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
110 batman_ogm_packet->flags = PRIMARIES_FIRST_HOP; 110 batman_ogm_packet->flags = PRIMARIES_FIRST_HOP;
111 batman_ogm_packet->header.ttl = TTL; 111 batman_ogm_packet->header.ttl = BATADV_TTL;
112} 112}
113 113
114/* when do we schedule our own ogm to be sent */ 114/* when do we schedule our own ogm to be sent */
115static unsigned long 115static unsigned long
116batadv_iv_ogm_emit_send_time(const struct bat_priv *bat_priv) 116batadv_iv_ogm_emit_send_time(const struct bat_priv *bat_priv)
117{ 117{
118 return jiffies + msecs_to_jiffies( 118 unsigned int msecs;
119 atomic_read(&bat_priv->orig_interval) - 119
120 JITTER + (random32() % 2*JITTER)); 120 msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
121 msecs += (random32() % 2 * BATADV_JITTER);
122
123 return jiffies + msecs_to_jiffies(msecs);
121} 124}
122 125
123/* when do we schedule a ogm packet to be sent */ 126/* when do we schedule a ogm packet to be sent */
124static unsigned long batadv_iv_ogm_fwd_send_time(void) 127static unsigned long batadv_iv_ogm_fwd_send_time(void)
125{ 128{
126 return jiffies + msecs_to_jiffies(random32() % (JITTER/2)); 129 return jiffies + msecs_to_jiffies(random32() % (BATADV_JITTER / 2));
127} 130}
128 131
129/* apply hop penalty for a normal link */ 132/* apply hop penalty for a normal link */
130static uint8_t batadv_hop_penalty(uint8_t tq, const struct bat_priv *bat_priv) 133static uint8_t batadv_hop_penalty(uint8_t tq, const struct bat_priv *bat_priv)
131{ 134{
132 int hop_penalty = atomic_read(&bat_priv->hop_penalty); 135 int hop_penalty = atomic_read(&bat_priv->hop_penalty);
133 return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE); 136 int new_tq;
137
138 new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty);
139 new_tq /= BATADV_TQ_MAX_VALUE;
140
141 return new_tq;
134} 142}
135 143
136/* is there another aggregated packet here? */ 144/* is there another aggregated packet here? */
@@ -143,7 +151,7 @@ static int batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
143 next_buff_pos += batadv_tt_len(tt_num_changes); 151 next_buff_pos += batadv_tt_len(tt_num_changes);
144 152
145 return (next_buff_pos <= packet_len) && 153 return (next_buff_pos <= packet_len) &&
146 (next_buff_pos <= MAX_AGGREGATION_BYTES); 154 (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
147} 155}
148 156
149/* send a batman ogm to a given interface */ 157/* send a batman ogm to a given interface */
@@ -290,8 +298,11 @@ batadv_iv_ogm_can_aggregate(const struct batman_ogm_packet *new_bat_ogm_packet,
290 int aggregated_bytes = forw_packet->packet_len + packet_len; 298 int aggregated_bytes = forw_packet->packet_len + packet_len;
291 struct hard_iface *primary_if = NULL; 299 struct hard_iface *primary_if = NULL;
292 bool res = false; 300 bool res = false;
301 unsigned long aggregation_end_time;
293 302
294 batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data; 303 batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
304 aggregation_end_time = send_time;
305 aggregation_end_time += msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS);
295 306
296 /* we can aggregate the current packet to this aggregated packet 307 /* we can aggregate the current packet to this aggregated packet
297 * if: 308 * if:
@@ -301,9 +312,8 @@ batadv_iv_ogm_can_aggregate(const struct batman_ogm_packet *new_bat_ogm_packet,
301 * MAX_AGGREGATION_BYTES 312 * MAX_AGGREGATION_BYTES
302 */ 313 */
303 if (time_before(send_time, forw_packet->send_time) && 314 if (time_before(send_time, forw_packet->send_time) &&
304 time_after_eq(send_time + msecs_to_jiffies(MAX_AGGREGATION_MS), 315 time_after_eq(aggregation_end_time, forw_packet->send_time) &&
305 forw_packet->send_time) && 316 (aggregated_bytes <= BATADV_MAX_AGGREGATION_BYTES)) {
306 (aggregated_bytes <= MAX_AGGREGATION_BYTES)) {
307 317
308 /* check aggregation compatibility 318 /* check aggregation compatibility
309 * -> direct link packets are broadcasted on 319 * -> direct link packets are broadcasted on
@@ -367,6 +377,7 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
367 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 377 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
368 struct forw_packet *forw_packet_aggr; 378 struct forw_packet *forw_packet_aggr;
369 unsigned char *skb_buff; 379 unsigned char *skb_buff;
380 unsigned int skb_size;
370 381
371 if (!atomic_inc_not_zero(&if_incoming->refcount)) 382 if (!atomic_inc_not_zero(&if_incoming->refcount))
372 return; 383 return;
@@ -388,12 +399,12 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
388 } 399 }
389 400
390 if ((atomic_read(&bat_priv->aggregated_ogms)) && 401 if ((atomic_read(&bat_priv->aggregated_ogms)) &&
391 (packet_len < MAX_AGGREGATION_BYTES)) 402 (packet_len < BATADV_MAX_AGGREGATION_BYTES))
392 forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES + 403 skb_size = BATADV_MAX_AGGREGATION_BYTES + ETH_HLEN;
393 ETH_HLEN);
394 else 404 else
395 forw_packet_aggr->skb = dev_alloc_skb(packet_len + ETH_HLEN); 405 skb_size = packet_len + ETH_HLEN;
396 406
407 forw_packet_aggr->skb = dev_alloc_skb(skb_size);
397 if (!forw_packet_aggr->skb) { 408 if (!forw_packet_aggr->skb) {
398 if (!own_packet) 409 if (!own_packet)
399 atomic_inc(&bat_priv->batman_queue_left); 410 atomic_inc(&bat_priv->batman_queue_left);
@@ -411,7 +422,7 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
411 forw_packet_aggr->own = own_packet; 422 forw_packet_aggr->own = own_packet;
412 forw_packet_aggr->if_incoming = if_incoming; 423 forw_packet_aggr->if_incoming = if_incoming;
413 forw_packet_aggr->num_packets = 0; 424 forw_packet_aggr->num_packets = 0;
414 forw_packet_aggr->direct_link_flags = NO_FLAGS; 425 forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS;
415 forw_packet_aggr->send_time = send_time; 426 forw_packet_aggr->send_time = send_time;
416 427
417 /* save packet direct link flag status */ 428 /* save packet direct link flag status */
@@ -466,9 +477,11 @@ static void batadv_iv_ogm_queue_add(struct bat_priv *bat_priv,
466 struct hlist_node *tmp_node; 477 struct hlist_node *tmp_node;
467 struct batman_ogm_packet *batman_ogm_packet; 478 struct batman_ogm_packet *batman_ogm_packet;
468 bool direct_link; 479 bool direct_link;
480 unsigned long max_aggregation_jiffies;
469 481
470 batman_ogm_packet = (struct batman_ogm_packet *)packet_buff; 482 batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
471 direct_link = batman_ogm_packet->flags & DIRECTLINK ? 1 : 0; 483 direct_link = batman_ogm_packet->flags & DIRECTLINK ? 1 : 0;
484 max_aggregation_jiffies = msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS);
472 485
473 /* find position for the packet in the forward queue */ 486 /* find position for the packet in the forward queue */
474 spin_lock_bh(&bat_priv->forw_bat_list_lock); 487 spin_lock_bh(&bat_priv->forw_bat_list_lock);
@@ -498,9 +511,8 @@ static void batadv_iv_ogm_queue_add(struct bat_priv *bat_priv,
498 * we hold it back for a while, so that it might be aggregated 511 * we hold it back for a while, so that it might be aggregated
499 * later on 512 * later on
500 */ 513 */
501 if ((!own_packet) && 514 if (!own_packet && atomic_read(&bat_priv->aggregated_ogms))
502 (atomic_read(&bat_priv->aggregated_ogms))) 515 send_time += max_aggregation_jiffies;
503 send_time += msecs_to_jiffies(MAX_AGGREGATION_MS);
504 516
505 batadv_iv_ogm_aggregate_new(packet_buff, packet_len, 517 batadv_iv_ogm_aggregate_new(packet_buff, packet_len,
506 send_time, direct_link, 518 send_time, direct_link,
@@ -603,7 +615,7 @@ static void batadv_iv_ogm_schedule(struct hard_iface *hard_iface)
603 batman_ogm_packet->gw_flags = 615 batman_ogm_packet->gw_flags =
604 (uint8_t)atomic_read(&bat_priv->gw_bandwidth); 616 (uint8_t)atomic_read(&bat_priv->gw_bandwidth);
605 else 617 else
606 batman_ogm_packet->gw_flags = NO_FLAGS; 618 batman_ogm_packet->gw_flags = BATADV_NO_FLAGS;
607 619
608 batadv_slide_own_bcast_window(hard_iface); 620 batadv_slide_own_bcast_window(hard_iface);
609 batadv_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff, 621 batadv_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
@@ -772,8 +784,10 @@ static int batadv_iv_ogm_calc_tq(struct orig_node *orig_node,
772 struct neigh_node *neigh_node = NULL, *tmp_neigh_node; 784 struct neigh_node *neigh_node = NULL, *tmp_neigh_node;
773 struct hlist_node *node; 785 struct hlist_node *node;
774 uint8_t total_count; 786 uint8_t total_count;
775 uint8_t orig_eq_count, neigh_rq_count, tq_own; 787 uint8_t orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
776 int tq_asym_penalty, ret = 0; 788 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
789 int tq_asym_penalty, inv_asym_penalty, ret = 0;
790 unsigned int combined_tq;
777 791
778 /* find corresponding one hop neighbor */ 792 /* find corresponding one hop neighbor */
779 rcu_read_lock(); 793 rcu_read_lock();
@@ -824,32 +838,33 @@ static int batadv_iv_ogm_calc_tq(struct orig_node *orig_node,
824 /* if we have too few packets (too less data) we set tq_own to zero 838 /* if we have too few packets (too less data) we set tq_own to zero
825 * if we receive too few packets it is not considered bidirectional 839 * if we receive too few packets it is not considered bidirectional
826 */ 840 */
827 if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) || 841 if (total_count < BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM ||
828 (neigh_rq_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM)) 842 neigh_rq_count < BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM)
829 tq_own = 0; 843 tq_own = 0;
830 else 844 else
831 /* neigh_node->real_packet_count is never zero as we 845 /* neigh_node->real_packet_count is never zero as we
832 * only purge old information when getting new 846 * only purge old information when getting new
833 * information 847 * information
834 */ 848 */
835 tq_own = (TQ_MAX_VALUE * total_count) / neigh_rq_count; 849 tq_own = (BATADV_TQ_MAX_VALUE * total_count) / neigh_rq_count;
836 850
837 /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does 851 /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
838 * affect the nearly-symmetric links only a little, but 852 * affect the nearly-symmetric links only a little, but
839 * punishes asymmetric links more. This will give a value 853 * punishes asymmetric links more. This will give a value
840 * between 0 and TQ_MAX_VALUE 854 * between 0 and TQ_MAX_VALUE
841 */ 855 */
842 tq_asym_penalty = TQ_MAX_VALUE - (TQ_MAX_VALUE * 856 neigh_rq_inv = BATADV_TQ_LOCAL_WINDOW_SIZE - neigh_rq_count;
843 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) * 857 neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv;
844 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) * 858 neigh_rq_max_cube = BATADV_TQ_LOCAL_WINDOW_SIZE *
845 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count)) / 859 BATADV_TQ_LOCAL_WINDOW_SIZE *
846 (TQ_LOCAL_WINDOW_SIZE * 860 BATADV_TQ_LOCAL_WINDOW_SIZE;
847 TQ_LOCAL_WINDOW_SIZE * 861 inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube;
848 TQ_LOCAL_WINDOW_SIZE); 862 inv_asym_penalty /= neigh_rq_max_cube;
849 863 tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty;
850 batman_ogm_packet->tq = ((batman_ogm_packet->tq * tq_own 864
851 * tq_asym_penalty) / 865 combined_tq = batman_ogm_packet->tq * tq_own * tq_asym_penalty;
852 (TQ_MAX_VALUE * TQ_MAX_VALUE)); 866 combined_tq /= BATADV_TQ_MAX_VALUE * BATADV_TQ_MAX_VALUE;
867 batman_ogm_packet->tq = combined_tq;
853 868
854 batadv_dbg(DBG_BATMAN, bat_priv, 869 batadv_dbg(DBG_BATMAN, bat_priv,
855 "bidirectional: orig = %-15pM neigh = %-15pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, total tq: %3i\n", 870 "bidirectional: orig = %-15pM neigh = %-15pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, total tq: %3i\n",
@@ -860,7 +875,7 @@ static int batadv_iv_ogm_calc_tq(struct orig_node *orig_node,
860 /* if link has the minimum required transmission quality 875 /* if link has the minimum required transmission quality
861 * consider it bidirectional 876 * consider it bidirectional
862 */ 877 */
863 if (batman_ogm_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT) 878 if (batman_ogm_packet->tq >= BATADV_TQ_TOTAL_BIDRECT_LIMIT)
864 ret = 1; 879 ret = 1;
865 880
866out: 881out:
@@ -928,7 +943,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
928 943
929 tmp_neigh_node->real_packet_count = 944 tmp_neigh_node->real_packet_count =
930 bitmap_weight(tmp_neigh_node->real_bits, 945 bitmap_weight(tmp_neigh_node->real_bits,
931 TQ_LOCAL_WINDOW_SIZE); 946 BATADV_TQ_LOCAL_WINDOW_SIZE);
932 } 947 }
933 rcu_read_unlock(); 948 rcu_read_unlock();
934 949
@@ -1050,6 +1065,8 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
1050 unsigned long *word; 1065 unsigned long *word;
1051 int offset; 1066 int offset;
1052 int32_t bit_pos; 1067 int32_t bit_pos;
1068 int16_t if_num;
1069 uint8_t *weight;
1053 1070
1054 orig_neigh_node = batadv_get_orig_node(bat_priv, 1071 orig_neigh_node = batadv_get_orig_node(bat_priv,
1055 ethhdr->h_source); 1072 ethhdr->h_source);
@@ -1063,15 +1080,17 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
1063 if (has_directlink_flag && 1080 if (has_directlink_flag &&
1064 batadv_compare_eth(if_incoming->net_dev->dev_addr, 1081 batadv_compare_eth(if_incoming->net_dev->dev_addr,
1065 batman_ogm_packet->orig)) { 1082 batman_ogm_packet->orig)) {
1066 offset = if_incoming->if_num * NUM_WORDS; 1083 if_num = if_incoming->if_num;
1084 offset = if_num * BATADV_NUM_WORDS;
1067 1085
1068 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock); 1086 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock);
1069 word = &(orig_neigh_node->bcast_own[offset]); 1087 word = &(orig_neigh_node->bcast_own[offset]);
1070 bit_pos = if_incoming_seqno - 2; 1088 bit_pos = if_incoming_seqno - 2;
1071 bit_pos -= ntohl(batman_ogm_packet->seqno); 1089 bit_pos -= ntohl(batman_ogm_packet->seqno);
1072 batadv_set_bit(word, bit_pos); 1090 batadv_set_bit(word, bit_pos);
1073 orig_neigh_node->bcast_own_sum[if_incoming->if_num] = 1091 weight = &orig_neigh_node->bcast_own_sum[if_num];
1074 bitmap_weight(word, TQ_LOCAL_WINDOW_SIZE); 1092 *weight = bitmap_weight(word,
1093 BATADV_TQ_LOCAL_WINDOW_SIZE);
1075 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock); 1094 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock);
1076 } 1095 }
1077 1096