2 * OLSR ad-hoc routing table management protocol
3 * Copyright (C) 2004 Thomas Lopatic (thomas@lopatic.de)
5 * This file is part of the olsr.org OLSR daemon.
7 * olsr.org is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * olsr.org is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with olsr.org; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * $Id: lq_mpr.c,v 1.2 2004/11/07 20:09:11 tlopatic Exp $
25 #if defined USE_LINK_QUALITY
27 #include "neighbor_table.h"
28 #include "two_hop_neighbor_table.h"
31 void olsr_calculate_lq_mpr(void)
33 struct neighbor_2_entry *neigh2;
34 struct neighbor_list_entry *walker;
36 struct neighbor_entry *neigh;
38 olsr_bool mpr_changes = OLSR_FALSE;
40 for(i = 0; i < HASHSIZE; i++)
42 for (neigh = neighbortable[i].next;
43 neigh != &neighbortable[i];
46 // memorize previous MPR status
48 neigh->was_mpr = neigh->is_mpr;
50 // clear current MPR status
52 neigh->is_mpr = OLSR_FALSE;
54 // in this pass we are only interested in WILL_ALWAYS neighbours
56 if(neigh->status == NOT_SYM ||
57 neigh->willingness != WILL_ALWAYS)
60 neigh->is_mpr = OLSR_TRUE;
62 if (neigh->is_mpr != neigh->was_mpr)
63 mpr_changes = OLSR_TRUE;
67 for(i = 0; i < HASHSIZE; i++)
69 // loop through all 2-hop neighbours
71 for (neigh2 = two_hop_neighbortable[i].next;
72 neigh2 != &two_hop_neighbortable[i];
73 neigh2 = neigh2->next)
75 // find the connecting 1-hop neighbour with the
76 // best total link quality
81 for (walker = neigh2->neighbor_2_nblist.next;
82 walker != &neigh2->neighbor_2_nblist;
83 walker = walker->next)
84 if (walker->full_link_quality >= best)
86 neigh = walker->neighbor;
87 best = walker->full_link_quality;
90 neigh->is_mpr = OLSR_TRUE;
92 if (neigh->is_mpr != neigh->was_mpr)
93 mpr_changes = OLSR_TRUE;
97 if (mpr_changes && olsr_cnf->tc_redundancy > 0)