2 * The olsr.org Optimized Link-State Routing daemon(olsrd)
3 * Copyright (c) 2004, Thomas Lopatic (thomas@lopatic.de)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of olsr.org, olsrd nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * Visit http://www.olsr.org for more information.
35 * If you find this software useful feel free to make a donation
36 * to the project. For more information see the website or contact
37 * the copyright holders.
39 * $Id: lq_mpr.c,v 1.8 2004/12/04 17:06:57 tlopatic Exp $
43 #include "neighbor_table.h"
44 #include "two_hop_neighbor_table.h"
47 void olsr_calculate_lq_mpr(void)
49 struct neighbor_2_entry *neigh2;
50 struct neighbor_list_entry *walker;
52 struct neighbor_entry *neigh;
54 olsr_bool mpr_changes = OLSR_FALSE;
56 for(i = 0; i < HASHSIZE; i++)
58 for (neigh = neighbortable[i].next;
59 neigh != &neighbortable[i];
62 // memorize previous MPR status
64 neigh->was_mpr = neigh->is_mpr;
66 // clear current MPR status
68 neigh->is_mpr = OLSR_FALSE;
70 // in this pass we are only interested in WILL_ALWAYS neighbours
72 if(neigh->status == NOT_SYM ||
73 neigh->willingness != WILL_ALWAYS)
76 neigh->is_mpr = OLSR_TRUE;
78 if (neigh->is_mpr != neigh->was_mpr)
79 mpr_changes = OLSR_TRUE;
83 for(i = 0; i < HASHSIZE; i++)
85 // loop through all 2-hop neighbours
87 for (neigh2 = two_hop_neighbortable[i].next;
88 neigh2 != &two_hop_neighbortable[i];
89 neigh2 = neigh2->next)
91 // check whether this 2-hop neighbour is also a neighbour
93 neigh = olsr_lookup_neighbor_table(&neigh2->neighbor_2_addr);
95 // it it's a neighbour and also symmetric, then skip it
97 if (neigh != NULL && neigh->status == SYM)
100 // find the connecting 1-hop neighbours with the
101 // best total link qualities
103 // mark all 1-hop neighbours as not selected
105 for (walker = neigh2->neighbor_2_nblist.next;
106 walker != &neigh2->neighbor_2_nblist;
107 walker = walker->next)
108 walker->neighbor->skip = OLSR_FALSE;
110 for (k = 0; k < olsr_cnf->mpr_coverage; k++)
112 // look for the best 1-hop neighbour that we haven't
118 for (walker = neigh2->neighbor_2_nblist.next;
119 walker != &neigh2->neighbor_2_nblist;
120 walker = walker->next)
121 if (walker->neighbor->status == SYM &&
122 !walker->neighbor->skip &&
123 walker->path_link_quality > best)
125 neigh = walker->neighbor;
126 best = walker->path_link_quality;
131 neigh->is_mpr = OLSR_TRUE;
132 neigh->skip = OLSR_TRUE;
134 if (neigh->is_mpr != neigh->was_mpr)
135 mpr_changes = OLSR_TRUE;
138 // no neighbour found => the requested MPR coverage cannot
139 // be satisfied => stop
147 if (mpr_changes && olsr_cnf->tc_redundancy > 0)