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.10 2004/11/28 13:43:59 tlopatic 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, *entry_to_delete;
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 entry_to_delete = entry;
94 DEQUEUE_ELEM(entry_to_delete);
96 free(entry_to_delete);
107 *Delete an entry from the two hop neighbor table.
109 *@param two_hop_neighbor the two hop neighbor to delete.
114 olsr_delete_two_hop_neighbor_table(struct neighbor_2_entry *two_hop_neighbor)
116 struct neighbor_list_entry *one_hop_list, *entry_to_delete;
117 struct neighbor_entry *one_hop_entry;
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 one_hop_entry = one_hop_list->neighbor;
125 olsr_delete_neighbor_2_pointer(one_hop_entry, &two_hop_neighbor->neighbor_2_addr);
127 entry_to_delete = one_hop_list;
129 one_hop_list = one_hop_list->next;
131 /* no need to dequeue */
133 free(entry_to_delete);
137 DEQUEUE_ELEM(two_hop_neighbor);
139 free(two_hop_neighbor);
145 *Insert a new entry to the two hop neighbor table.
147 *@param two_hop_neighbor the entry to insert
152 olsr_insert_two_hop_neighbor_table(struct neighbor_2_entry *two_hop_neighbor)
156 //printf("Adding 2 hop neighbor %s\n", olsr_ip_to_string(&two_hop_neighbor->neighbor_2_addr));
158 hash = olsr_hashing(&two_hop_neighbor->neighbor_2_addr);
161 QUEUE_ELEM(two_hop_neighbortable[hash], two_hop_neighbor);
166 *Look up an entry in the two hop neighbor table.
168 *@param dest the IP address of the entry to find
170 *@return a pointer to a neighbor_2_entry struct
171 *representing the two hop neighbor
173 struct neighbor_2_entry *
174 olsr_lookup_two_hop_neighbor_table(union olsr_ip_addr *dest)
177 struct neighbor_2_entry *neighbor_2;
179 struct addresses *adr;
181 //printf("LOOKING FOR %s\n", olsr_ip_to_string(dest));
182 hash = olsr_hashing(dest);
185 for(neighbor_2 = two_hop_neighbortable[hash].next;
186 neighbor_2 != &two_hop_neighbortable[hash];
187 neighbor_2 = neighbor_2->next)
189 //printf("Checking %s\n", olsr_ip_to_string(dest));
190 if (COMP_IP(&neighbor_2->neighbor_2_addr, dest))
193 adr = mid_lookup_aliases(&neighbor_2->neighbor_2_addr);
197 if(COMP_IP(&adr->address, dest))
209 *Look up an entry in the two hop neighbor table.
210 *NO CHECK FOR MAIN ADDRESS OR ALIASES!
212 *@param dest the IP address of the entry to find
214 *@return a pointer to a neighbor_2_entry struct
215 *representing the two hop neighbor
217 struct neighbor_2_entry *
218 olsr_lookup_two_hop_neighbor_table_mid(union olsr_ip_addr *dest)
220 struct neighbor_2_entry *neighbor_2;
223 //printf("LOOKING FOR %s\n", olsr_ip_to_string(dest));
224 hash = olsr_hashing(dest);
226 for(neighbor_2 = two_hop_neighbortable[hash].next;
227 neighbor_2 != &two_hop_neighbortable[hash];
228 neighbor_2 = neighbor_2->next)
230 if (COMP_IP(&neighbor_2->neighbor_2_addr, dest))
240 *Print the two hop neighbor table to STDOUT.
245 olsr_print_two_hop_neighbor_table()
248 struct neighbor_2_entry *neigh2;
249 struct neighbor_list_entry *entry;
250 struct neighbor_entry *neigh;
254 olsr_printf(1, "\n--- %02d:%02d:%02d -------------------------- TWO-HOP NEIGHBORS\n\n",
260 olsr_printf(1, "IP addr (2-hop) IP addr (1-hop) TLQ\n");
262 for (i = 0; i < HASHSIZE; i++)
264 for (neigh2 = two_hop_neighbortable[i].next;
265 neigh2 != &two_hop_neighbortable[i]; neigh2 = neigh2->next)
269 for (entry = neigh2->neighbor_2_nblist.next;
270 entry != &neigh2->neighbor_2_nblist; entry = entry->next)
272 neigh = entry->neighbor;
276 olsr_printf(1, "%-15s ",
277 olsr_ip_to_string(&neigh2->neighbor_2_addr));
284 #if defined USE_LINK_QUALITY
285 total_lq = entry->path_link_quality;
289 olsr_printf(1, "%-15s %5.3f\n",
290 olsr_ip_to_string(&neigh->neighbor_main_addr),