2 * OLSR ad-hoc routing table management protocol
3 * Copyright (C) 2003 Andreas Tønnesen (andreto@ifi.uio.no)
5 * This file is part of olsrd-unik.
7 * olsrd-unik 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 * olsrd-unik 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 olsrd-unik; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "two_hop_neighbor_table.h"
32 *Initialize 2 hop neighbor table
35 olsr_init_two_hop_table()
39 for(index=0;index<HASHSIZE;index++)
41 two_hop_neighbortable[index].next = &two_hop_neighbortable[index];
42 two_hop_neighbortable[index].prev = &two_hop_neighbortable[index];
49 *Remove a one hop neighbor from a two hop neighbors
52 *@param two_hop_entry the two hop neighbor to remove the
53 *one hop neighbor from
54 *@param address the address of the one hop neighbor to remove
60 olsr_delete_neighbor_pointer(struct neighbor_2_entry *two_hop_entry, union olsr_ip_addr *address)
62 struct neighbor_list_entry *entry, *entry_to_delete;
64 entry = two_hop_entry->neighbor_2_nblist.next;
67 while(entry != &two_hop_entry->neighbor_2_nblist)
69 if(COMP_IP(&entry->neighbor->neighbor_main_addr, address))
71 entry_to_delete = entry;
75 DEQUEUE_ELEM(entry_to_delete);
76 //entry_to_delete->prev->next = entry_to_delete->next;
77 //entry_to_delete->next->prev = entry_to_delete->prev;
79 free(entry_to_delete);
90 *Delete an entry from the two hop neighbor table.
92 *@param two_hop_neighbor the two hop neighbor to delete.
97 olsr_delete_two_hop_neighbor_table(struct neighbor_2_entry *two_hop_neighbor)
99 struct neighbor_list_entry *one_hop_list, *entry_to_delete;
100 struct neighbor_entry *one_hop_entry;
102 one_hop_list = two_hop_neighbor->neighbor_2_nblist.next;
104 /* Delete one hop links */
105 while(one_hop_list != &two_hop_neighbor->neighbor_2_nblist)
107 one_hop_entry = one_hop_list->neighbor;
108 olsr_delete_neighbor_2_pointer(one_hop_entry, &two_hop_neighbor->neighbor_2_addr);
110 entry_to_delete = one_hop_list;
112 one_hop_list = one_hop_list->next;
114 /* no need to dequeue */
116 free(entry_to_delete);
120 DEQUEUE_ELEM(two_hop_neighbor);
121 //two_hop_neighbor->prev->next = two_hop_neighbor->next;
122 //two_hop_neighbor->next->prev = two_hop_neighbor->prev;
124 free(two_hop_neighbor);
130 *Insert a new entry to the two hop neighbor table.
132 *@param two_hop_neighbor the entry to insert
137 olsr_insert_two_hop_neighbor_table(struct neighbor_2_entry *two_hop_neighbor)
141 //printf("Adding 2 hop neighbor %s\n", olsr_ip_to_string(&two_hop_neighbor->neighbor_2_addr));
143 hash = olsr_hashing(&two_hop_neighbor->neighbor_2_addr);
146 QUEUE_ELEM(two_hop_neighbortable[hash], two_hop_neighbor);
148 two_hop_neighbortable[hash].next->prev = two_hop_neighbor;
149 two_hop_neighbor->next = two_hop_neighbortable[hash].next;
150 two_hop_neighbortable[hash].next = two_hop_neighbor;
151 two_hop_neighbor->prev = &two_hop_neighbortable[hash];
157 *Look up an entry in the two hop neighbor table.
159 *@param dest the IP address of the entry to find
161 *@return a pointer to a neighbor_2_entry struct
162 *representing the two hop neighbor
164 struct neighbor_2_entry *
165 olsr_lookup_two_hop_neighbor_table(union olsr_ip_addr *dest)
168 struct neighbor_2_entry *neighbor_2;
170 struct addresses *adr;
172 //printf("LOOKING FOR %s\n", olsr_ip_to_string(dest));
173 hash = olsr_hashing(dest);
176 for(neighbor_2 = two_hop_neighbortable[hash].next;
177 neighbor_2 != &two_hop_neighbortable[hash];
178 neighbor_2 = neighbor_2->next)
180 //printf("Checking %s\n", olsr_ip_to_string(dest));
181 if (COMP_IP(&neighbor_2->neighbor_2_addr, dest))
184 adr = mid_lookup_aliases(&neighbor_2->neighbor_2_addr);
188 if(COMP_IP(&adr->address, dest))
200 *Look up an entry in the two hop neighbor table.
201 *NO CHECK FOR MAIN ADDRESS OR ALIASES!
203 *@param dest the IP address of the entry to find
205 *@return a pointer to a neighbor_2_entry struct
206 *representing the two hop neighbor
208 struct neighbor_2_entry *
209 olsr_lookup_two_hop_neighbor_table_mid(union olsr_ip_addr *dest)
211 struct neighbor_2_entry *neighbor_2;
214 //printf("LOOKING FOR %s\n", olsr_ip_to_string(dest));
215 hash = olsr_hashing(dest);
217 for(neighbor_2 = two_hop_neighbortable[hash].next;
218 neighbor_2 != &two_hop_neighbortable[hash];
219 neighbor_2 = neighbor_2->next)
221 if (COMP_IP(&neighbor_2->neighbor_2_addr, dest))
231 *Print the two hop neighbor table to STDOUT.
236 olsr_print_two_hop_neighbor_table()
239 struct neighbor_2_entry *neighbor_2;
241 struct neighbor_list_entry *list_1=NULL;
243 printf("THE TWO HOP NEIGHBORS\n");
245 for(index=0;index<HASHSIZE;index++)
248 for(neighbor_2 = two_hop_neighbortable[index].next;
249 neighbor_2 != &two_hop_neighbortable[index];
250 neighbor_2 = neighbor_2->next)
253 printf("ADDRESS TWO HOP NEIGHBORS\n");
254 printf("%s \n", olsr_ip_to_string(&neighbor_2->neighbor_2_addr));
255 printf("---------------------\n");
257 printf("POINTED BY\n");
258 for(list_1 = neighbor_2->neighbor_2_nblist.next;
259 list_1 != &neighbor_2->neighbor_2_nblist;
260 list_1 = list_1->next)
262 printf("%s \n", olsr_ip_to_string(&list_1->neighbor->neighbor_main_addr));
264 printf("---------------------\n");