2 * The olsr.org Optimized Link-State Routing daemon(olsrd)
3 * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
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: two_hop_neighbor_table.c,v 1.12 2005/01/17 20:18:22 kattemat Exp $
45 #include "two_hop_neighbor_table.h"
51 *Initialize 2 hop neighbor table
54 olsr_init_two_hop_table()
58 for(index=0;index<HASHSIZE;index++)
60 two_hop_neighbortable[index].next = &two_hop_neighbortable[index];
61 two_hop_neighbortable[index].prev = &two_hop_neighbortable[index];
68 *Remove a one hop neighbor from a two hop neighbors
71 *@param two_hop_entry the two hop neighbor to remove the
72 *one hop neighbor from
73 *@param address the address of the one hop neighbor to remove
79 olsr_delete_neighbor_pointer(struct neighbor_2_entry *two_hop_entry, union olsr_ip_addr *address)
81 struct neighbor_list_entry *entry;
83 entry = two_hop_entry->neighbor_2_nblist.next;
86 while(entry != &two_hop_entry->neighbor_2_nblist)
88 if(COMP_IP(&entry->neighbor->neighbor_main_addr, address))
90 struct neighbor_list_entry *entry_to_delete = entry;
94 DEQUEUE_ELEM(entry_to_delete);
96 free(entry_to_delete);
108 *Delete an entry from the two hop neighbor table.
110 *@param two_hop_neighbor the two hop neighbor to delete.
115 olsr_delete_two_hop_neighbor_table(struct neighbor_2_entry *two_hop_neighbor)
117 struct neighbor_list_entry *one_hop_list;
119 one_hop_list = two_hop_neighbor->neighbor_2_nblist.next;
121 /* Delete one hop links */
122 while(one_hop_list != &two_hop_neighbor->neighbor_2_nblist)
124 struct neighbor_entry *one_hop_entry = one_hop_list->neighbor;
125 struct neighbor_list_entry *entry_to_delete = one_hop_list;
127 olsr_delete_neighbor_2_pointer(one_hop_entry, &two_hop_neighbor->neighbor_2_addr);
128 one_hop_list = one_hop_list->next;
129 /* no need to dequeue */
130 free(entry_to_delete);
134 DEQUEUE_ELEM(two_hop_neighbor);
135 free(two_hop_neighbor);
141 *Insert a new entry to the two hop neighbor table.
143 *@param two_hop_neighbor the entry to insert
148 olsr_insert_two_hop_neighbor_table(struct neighbor_2_entry *two_hop_neighbor)
152 //printf("Adding 2 hop neighbor %s\n", olsr_ip_to_string(&two_hop_neighbor->neighbor_2_addr));
154 hash = olsr_hashing(&two_hop_neighbor->neighbor_2_addr);
157 QUEUE_ELEM(two_hop_neighbortable[hash], two_hop_neighbor);
162 *Look up an entry in the two hop neighbor table.
164 *@param dest the IP address of the entry to find
166 *@return a pointer to a neighbor_2_entry struct
167 *representing the two hop neighbor
169 struct neighbor_2_entry *
170 olsr_lookup_two_hop_neighbor_table(union olsr_ip_addr *dest)
173 struct neighbor_2_entry *neighbor_2;
176 //printf("LOOKING FOR %s\n", olsr_ip_to_string(dest));
177 hash = olsr_hashing(dest);
180 for(neighbor_2 = two_hop_neighbortable[hash].next;
181 neighbor_2 != &two_hop_neighbortable[hash];
182 neighbor_2 = neighbor_2->next)
184 struct addresses *adr;
186 //printf("Checking %s\n", olsr_ip_to_string(dest));
187 if (COMP_IP(&neighbor_2->neighbor_2_addr, dest))
190 adr = mid_lookup_aliases(&neighbor_2->neighbor_2_addr);
194 if(COMP_IP(&adr->address, dest))
206 *Look up an entry in the two hop neighbor table.
207 *NO CHECK FOR MAIN ADDRESS OR ALIASES!
209 *@param dest the IP address of the entry to find
211 *@return a pointer to a neighbor_2_entry struct
212 *representing the two hop neighbor
214 struct neighbor_2_entry *
215 olsr_lookup_two_hop_neighbor_table_mid(union olsr_ip_addr *dest)
217 struct neighbor_2_entry *neighbor_2;
220 //printf("LOOKING FOR %s\n", olsr_ip_to_string(dest));
221 hash = olsr_hashing(dest);
223 for(neighbor_2 = two_hop_neighbortable[hash].next;
224 neighbor_2 != &two_hop_neighbortable[hash];
225 neighbor_2 = neighbor_2->next)
227 if (COMP_IP(&neighbor_2->neighbor_2_addr, dest))
237 *Print the two hop neighbor table to STDOUT.
242 olsr_print_two_hop_neighbor_table()
246 olsr_printf(1, "\n--- %02d:%02d:%02d -------------------------- TWO-HOP NEIGHBORS\n\n",
252 olsr_printf(1, "IP addr (2-hop) IP addr (1-hop) TLQ\n");
254 for (i = 0; i < HASHSIZE; i++)
256 struct neighbor_2_entry *neigh2;
257 for (neigh2 = two_hop_neighbortable[i].next;
258 neigh2 != &two_hop_neighbortable[i]; neigh2 = neigh2->next)
260 struct neighbor_list_entry *entry;
261 olsr_bool first = OLSR_TRUE;
263 for (entry = neigh2->neighbor_2_nblist.next;
264 entry != &neigh2->neighbor_2_nblist; entry = entry->next)
267 struct neighbor_entry *neigh = entry->neighbor;
271 olsr_printf(1, "%-15s ",
272 olsr_ip_to_string(&neigh2->neighbor_2_addr));
279 total_lq = entry->path_link_quality;
281 olsr_printf(1, "%-15s %5.3f\n",
282 olsr_ip_to_string(&neigh->neighbor_main_addr),