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 olsr.org.
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
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);
77 free(entry_to_delete);
88 *Delete an entry from the two hop neighbor table.
90 *@param two_hop_neighbor the two hop neighbor to delete.
95 olsr_delete_two_hop_neighbor_table(struct neighbor_2_entry *two_hop_neighbor)
97 struct neighbor_list_entry *one_hop_list, *entry_to_delete;
98 struct neighbor_entry *one_hop_entry;
100 one_hop_list = two_hop_neighbor->neighbor_2_nblist.next;
102 /* Delete one hop links */
103 while(one_hop_list != &two_hop_neighbor->neighbor_2_nblist)
105 one_hop_entry = one_hop_list->neighbor;
106 olsr_delete_neighbor_2_pointer(one_hop_entry, &two_hop_neighbor->neighbor_2_addr);
108 entry_to_delete = one_hop_list;
110 one_hop_list = one_hop_list->next;
112 /* no need to dequeue */
114 free(entry_to_delete);
118 DEQUEUE_ELEM(two_hop_neighbor);
120 free(two_hop_neighbor);
126 *Insert a new entry to the two hop neighbor table.
128 *@param two_hop_neighbor the entry to insert
133 olsr_insert_two_hop_neighbor_table(struct neighbor_2_entry *two_hop_neighbor)
137 //printf("Adding 2 hop neighbor %s\n", olsr_ip_to_string(&two_hop_neighbor->neighbor_2_addr));
139 hash = olsr_hashing(&two_hop_neighbor->neighbor_2_addr);
142 QUEUE_ELEM(two_hop_neighbortable[hash], two_hop_neighbor);
147 *Look up an entry in the two hop neighbor table.
149 *@param dest the IP address of the entry to find
151 *@return a pointer to a neighbor_2_entry struct
152 *representing the two hop neighbor
154 struct neighbor_2_entry *
155 olsr_lookup_two_hop_neighbor_table(union olsr_ip_addr *dest)
158 struct neighbor_2_entry *neighbor_2;
160 struct addresses *adr;
162 //printf("LOOKING FOR %s\n", olsr_ip_to_string(dest));
163 hash = olsr_hashing(dest);
166 for(neighbor_2 = two_hop_neighbortable[hash].next;
167 neighbor_2 != &two_hop_neighbortable[hash];
168 neighbor_2 = neighbor_2->next)
170 //printf("Checking %s\n", olsr_ip_to_string(dest));
171 if (COMP_IP(&neighbor_2->neighbor_2_addr, dest))
174 adr = mid_lookup_aliases(&neighbor_2->neighbor_2_addr);
178 if(COMP_IP(&adr->address, dest))
190 *Look up an entry in the two hop neighbor table.
191 *NO CHECK FOR MAIN ADDRESS OR ALIASES!
193 *@param dest the IP address of the entry to find
195 *@return a pointer to a neighbor_2_entry struct
196 *representing the two hop neighbor
198 struct neighbor_2_entry *
199 olsr_lookup_two_hop_neighbor_table_mid(union olsr_ip_addr *dest)
201 struct neighbor_2_entry *neighbor_2;
204 //printf("LOOKING FOR %s\n", olsr_ip_to_string(dest));
205 hash = olsr_hashing(dest);
207 for(neighbor_2 = two_hop_neighbortable[hash].next;
208 neighbor_2 != &two_hop_neighbortable[hash];
209 neighbor_2 = neighbor_2->next)
211 if (COMP_IP(&neighbor_2->neighbor_2_addr, dest))
221 *Print the two hop neighbor table to STDOUT.
226 olsr_print_two_hop_neighbor_table()
229 struct neighbor_2_entry *neighbor_2;
231 struct neighbor_list_entry *list_1=NULL;
233 printf("THE TWO HOP NEIGHBORS\n");
235 for(index=0;index<HASHSIZE;index++)
238 for(neighbor_2 = two_hop_neighbortable[index].next;
239 neighbor_2 != &two_hop_neighbortable[index];
240 neighbor_2 = neighbor_2->next)
243 printf("ADDRESS TWO HOP NEIGHBORS\n");
244 printf("%s \n", olsr_ip_to_string(&neighbor_2->neighbor_2_addr));
245 printf("---------------------\n");
247 printf("POINTED BY\n");
248 for(list_1 = neighbor_2->neighbor_2_nblist.next;
249 list_1 != &neighbor_2->neighbor_2_nblist;
250 list_1 = list_1->next)
252 printf("%s \n", olsr_ip_to_string(&list_1->neighbor->neighbor_main_addr));
254 printf("---------------------\n");