aodv.h

00001 /* Copyright 2008 Michael Marsh, University of Maryland.
00002  *
00003  * This file is part of pydtn.
00004  *
00005  * pydtn is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * pydtn is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with pydtn.  If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * The views and conclusions contained in the software and documentation
00019  * are those of the authors and should not be interpreted as representing
00020  * official policies, either expressed or implied, of the University
00021  * of Maryland.
00022  *
00023  * pydtn extends and embeds the Python interpreter, which is
00024  * Copyright 2001-2006 Python Software Foundation, All Rights Reserved,
00025  * and is released under the PSF License Agreement.
00026  *
00027  * RANLUX random number generation uses the Boost library,
00028  * Copyright 1994-2006 by various authors (details in individual files),
00029  * which is released under the Boost Software License, Version 1.0.
00030  */
00031 
00032 #ifndef __AODV_H__
00033 #define __AODV_H__
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <stdint.h>
00042 
00043 /* We're using POSIX types, rather than ISO C99 types. */
00044 #include <sys/types.h>
00045 
00053 extern const uint16_t k_aodv_udp_port; 
00055 extern const uint16_t kAodvRreqD; 
00056 extern const uint16_t kAodvRreqG; 
00058 extern const uint16_t kAodvRrepA; 
00060 extern const unsigned int k_aodv_rreq_min_len; 
00061 extern const unsigned int k_aodv_rrep_min_len; 
00062 extern const unsigned int k_aodv_rerr_min_len; 
00063 extern const unsigned int k_aodv_rrep_ack_len; 
00066 enum
00067 {
00068    AODV_GR_OK, 
00069    AODV_GR_NULLSTATE, 
00070    AODV_GR_PENDING, 
00071    AODV_GR_NOROUTE, 
00072    AODV_GR_ERROR 
00073 };
00074 
00076 typedef struct aodv_addr
00077 {
00078       uint16_t       length; 
00079       unsigned char*  data; 
00080 } aodv_addr_t; 
00083 typedef struct aodv_chunk
00084 {
00085       unsigned int        length; 
00086       unsigned char*      data; 
00087       struct aodv_chunk*  next; 
00088 } aodv_chunk_t; 
00091 typedef struct aodv_msghdr
00092 {
00093       aodv_addr_t    addr; 
00094       unsigned char  ttl; 
00095       int            interface; 
00096 } aodv_msghdr_t; 
00099 typedef struct aodv_prefix
00100 {
00101       aodv_addr_t  addr; 
00102       uint16_t     prefix; 
00103 } aodv_prefix_t; 
00106 typedef struct aodv_node_list
00107 {
00108       struct aodv_node_list*  next; 
00109       struct aodv_node_list*  prev; 
00111       aodv_addr_t  node; 
00112       uint32_t    seq; 
00113 } aodv_node_list_t; 
00116 typedef struct aodv_rreq
00117 {
00118       struct aodv_rreq*  next; 
00119       struct aodv_rreq*  prev; 
00120       struct timeval     buffer_time; 
00122       unsigned int       ntries; 
00124       unsigned int       ttl; 
00126       unsigned char      dest_only_flag; 
00128       unsigned char      grat_rrep_flag; 
00131       unsigned char      hop_count; 
00133       uint32_t           rreq_id; 
00134       aodv_addr_t        destination; 
00135       uint32_t           dest_seq; 
00137       aodv_addr_t        originator; 
00138       uint32_t           orig_seq; 
00139       aodv_node_list_t*  path; 
00140 } aodv_rreq_t; 
00143 typedef struct aodv_rrep
00144 {
00145       unsigned char      ack_flag; 
00146       unsigned char      apn_count; 
00148       unsigned char      hop_count; 
00150       aodv_prefix_t      destination; 
00152       uint32_t           dest_seq; 
00153       aodv_addr_t        originator; 
00154       uint32_t           orig_seq; 
00155       aodv_node_list_t*  path; 
00157 } aodv_rrep_t; 
00160 typedef struct aodv_rerr
00161 {
00162       unsigned char      dest_count; 
00164       aodv_node_list_t*  unreachable; 
00165 } aodv_rerr_t; 
00172 typedef struct aodv_table_entry
00173 {
00174       struct aodv_table_entry*  next; 
00176       struct aodv_table_entry*  prev; 
00178       aodv_prefix_t             destination; 
00179       uint32_t                  dest_seq; 
00181       aodv_addr_t               next_hop; 
00183       struct timeval            lifetime; 
00184       unsigned char             hop_count; 
00186       int                       interface; 
00187       unsigned char             valid_route; 
00188 } aodv_table_entry_t; 
00191 typedef struct aodv_routing_table
00192 {
00193       aodv_table_entry_t*  head; 
00194 } aodv_routing_table_t; 
00197 typedef struct aodv_parameters
00198 {
00199       unsigned int  node_traversal_time; 
00201       unsigned int  net_diameter; 
00203       unsigned int  net_traversal_time; 
00205       unsigned int  path_discovery_time; 
00207       unsigned int  active_route_timeout; 
00209       unsigned int  delete_period; 
00212       unsigned int  rreq_tries; 
00214       unsigned int  rreq_ratelimit; 
00216       unsigned int  rerr_ratelimit; 
00218       unsigned int  hello_interval; 
00220       unsigned int  allowed_hello_loss; 
00224       unsigned int  next_hop_wait; 
00226       unsigned int  blacklist_timeout; 
00229 } aodv_parameters_t; 
00236 typedef struct aodv_time_ring
00237 {
00238       struct timeval*  ring; 
00239       unsigned int     size; 
00240       unsigned int     offset; 
00241 } aodv_time_ring_t; 
00244 typedef struct aodv_interfaces
00245 {
00246       int*          interfaces; 
00248       unsigned int  nifaces; 
00249       unsigned int  lifaces; 
00251 } aodv_interfaces_t; 
00254 typedef struct aodv_state
00255 {
00256       aodv_parameters_t     params; 
00257       aodv_addr_t           self; 
00258       unsigned char         subnet_size; 
00260       uint32_t              sequence_number; 
00261       uint32_t              rreq_id; 
00262       aodv_rreq_t*          rreq_buffer; 
00263       aodv_rreq_t*          rcvd_rreq_buffer; 
00264       aodv_time_ring_t*     rreq_time_ring; 
00266       aodv_time_ring_t*     rerr_time_ring; 
00268       unsigned char         use_acks; 
00269       aodv_interfaces_t     interfaces; 
00270       aodv_routing_table_t  routing_table; 
00271 } aodv_state_t; 
00276 int
00277 aodv_gettime(struct timeval* tv);
00278 
00279 void
00280 aodv_route_notify( const aodv_state_t* state, const aodv_addr_t* dest );
00281 
00282 void
00283 aodv_set_bcast_addr( aodv_addr_t* a );
00284 
00285 void
00286 aodv_send_message( aodv_state_t* state,
00287                    const aodv_msghdr_t* headers,
00288                    const aodv_chunk_t* message );
00289 
00290 void
00291 aodv_log_rreq_s( const aodv_state_t* state,
00292                  const aodv_rreq_t* rreq,
00293                  const aodv_msghdr_t* hdrs );
00294 
00295 void
00296 aodv_log_rrep_c( const aodv_state_t* state,
00297                  const aodv_rrep_t* rrep );
00298 
00299 void
00300 aodv_log_rrep_s( const aodv_state_t* state,
00301                  const aodv_rrep_t* rrep,
00302                  const aodv_msghdr_t* hdrs );
00303 
00304 void
00305 aodv_log_rerr_s( const aodv_state_t* state,
00306                  const aodv_rerr_t* rerr,
00307                  const aodv_msghdr_t* hdrs );
00308 
00309 void
00310 aodv_log_rrep_ack_s( const aodv_state_t* state,
00311                      const aodv_msghdr_t* hdrs );
00312 
00313 void
00314 aodv_log_rreq_r( const aodv_state_t* state,
00315                  const aodv_rreq_t* rreq,
00316                  const aodv_msghdr_t* hdrs );
00317 
00318 void
00319 aodv_log_rrep_r( const aodv_state_t* state,
00320                  const aodv_rrep_t* rrep,
00321                  const aodv_msghdr_t* hdrs );
00322 
00323 void
00324 aodv_log_rerr_r( const aodv_state_t* state,
00325                  const aodv_rerr_t* rerr,
00326                  const aodv_msghdr_t* hdrs );
00327 
00328 void
00329 aodv_log_rrep_ack_r( const aodv_state_t* state,
00330                      const aodv_msghdr_t* hdrs );
00331 
00338 aodv_table_entry_t*
00339 aodv_get_route( aodv_state_t* state,
00340                 const aodv_addr_t* source,
00341                 const aodv_addr_t* destination,
00342                 int* ecode );
00343 
00344 void
00345 clear_aodv_routing_table( aodv_routing_table_t* table );
00346 
00347 aodv_table_entry_t*
00348 add_aodv_table_entry( aodv_routing_table_t* table,
00349                       const aodv_addr_t* destination,
00350                       uint16_t prefix_size );
00351 
00352 void
00353 remove_aodv_table_entry( aodv_routing_table_t* table,
00354                          aodv_table_entry_t* entry );
00355 
00356 aodv_table_entry_t*
00357 update_aodv_table_entry( aodv_state_t* state,
00358                          const aodv_msghdr_t* hdrs,
00359                          const aodv_node_list_t* node,
00360                          unsigned char hop_count );
00361 
00362 aodv_table_entry_t*
00363 new_aodv_table_entry();
00364 
00365 void
00366 free_aodv_table_entry( aodv_table_entry_t* entry );
00367 
00368 aodv_table_entry_t*
00369 aodv_lookup( const aodv_routing_table_t* table,
00370              const aodv_addr_t* destination );
00371 
00372 void
00373 aodv_invalidate_route( aodv_state_t* state, const aodv_addr_t* destination );
00374 
00375 void
00376 aodv_invalidate_routing_entry( aodv_state_t* state,
00377                                aodv_table_entry_t* entry );
00378 
00379 unsigned char
00380 aodv_table_entry_is_expired( const aodv_table_entry_t* entry );
00381 
00382 void
00383 aodv_update_route_expiry( const aodv_state_t* state,
00384                           aodv_table_entry_t* entry );
00385 
00386 void
00387 aodv_update_invalid_route_lifetime( const aodv_state_t* state,
00388                                     aodv_table_entry_t* entry );
00389 
00390 void
00391 aodv_broken_link( aodv_state_t* state, const aodv_addr_t* bad_hop );
00392 
00399 int
00400 aodv_generate_rreq( aodv_state_t* state, const aodv_addr_t* destination );
00401 
00405 int
00406 aodv_handle_message( aodv_state_t* state,
00407                      const aodv_msghdr_t* headers,
00408                      const aodv_chunk_t* message );
00409 
00414 void
00415 aodv_bcast_rreq( aodv_state_t* state, const aodv_rreq_t* request );
00416 
00417 void
00418 aodv_unicast_rrep( aodv_state_t* state, const aodv_rrep_t* response );
00419 
00420 void
00421 aodv_bcast_rerr( aodv_state_t* state, const aodv_rerr_t* rerr );
00422 
00423 void
00424 aodv_unicast_rrep_ack( aodv_state_t* state,
00425                        const aodv_msghdr_t* inhdrs );
00426 
00433 unsigned char
00434 aodv_pasttime( const struct timeval* tv );
00435 
00436 aodv_state_t*
00437 new_aodv_state( const aodv_addr_t* self, uint16_t prefix );
00438 
00439 void
00440 init_aodv_state( aodv_state_t* state,
00441                  const aodv_addr_t* self,
00442                  uint16_t prefix );
00443 
00444 void
00445 configure_aodv_state( aodv_state_t* state );
00446 
00447 void
00448 free_aodv_state( aodv_state_t* state );
00449 
00450 void
00451 clear_aodv_state( aodv_state_t* state );
00452 
00453 void
00454 set_aodv_param_defaults( aodv_state_t* state );
00455 
00456 void
00457 recompute_aodv_params( aodv_state_t* state );
00458 
00459 uint32_t
00460 aodv_incr_seq_base( uint32_t* seq );
00461 
00462 uint32_t
00463 aodv_incr_seq( aodv_state_t* state );
00464 
00465 uint32_t
00466 aodv_incr_rreq_id( aodv_state_t* state );
00467 
00468 char
00469 aodv_cmp_seq( uint32_t a, uint32_t b );
00470 
00471 char
00472 aodv_cmp_addr( const aodv_addr_t* a, const aodv_addr_t* b );
00473 
00474 void
00475 buffer_aodv_rreq( aodv_state_t* state, aodv_rreq_t* rreq );
00476 
00477 void
00478 buffer_rcvd_aodv_rreq( aodv_state_t* state, aodv_rreq_t* rreq );
00479 
00480 aodv_rreq_t*
00481 unbuffer_aodv_rreq( aodv_state_t* state, aodv_rreq_t* rreq );
00482 
00483 aodv_rreq_t*
00484 unbuffer_rcvd_aodv_rreq( aodv_state_t* state, aodv_rreq_t* rreq );
00485 
00486 int
00487 is_buffered_aodv_rreq( aodv_state_t* state, aodv_rreq_t* rreq );
00488 
00489 int
00490 is_buffered_rcvd_aodv_rreq( aodv_state_t* state, aodv_rreq_t* rreq );
00491 
00492 aodv_rreq_t*
00493 find_buffered_aodv_rreq( aodv_state_t* state, const aodv_addr_t* dest );
00494 
00495 void
00496 aodv_initialize_time_ring( aodv_time_ring_t* ring, unsigned int size );
00497 
00498 int
00499 aodv_insert_time( aodv_time_ring_t* ring );
00500 
00501 int
00502 aodv_add_interface( aodv_state_t* state, int iface );
00503 
00504 int
00505 aodv_add_to_node_list( aodv_node_list_t** path,
00506                        const aodv_addr_t* addr,
00507                        uint32_t seq );
00508 
00509 const aodv_node_list_t*
00510 aodv_find_in_node_list( const aodv_node_list_t* nodes,
00511                         const aodv_addr_t* addr );
00512 
00513 int
00514 aodv_get8( unsigned char** pData, unsigned int* pLength, uint8_t* b );
00515 
00516 int
00517 aodv_get16( unsigned char** pData, unsigned int* pLength, uint16_t* s );
00518 
00519 int
00520 aodv_get32( unsigned char** pData, unsigned int* pLength, uint32_t* l );
00521 
00522 int
00523 aodv_get_addr( unsigned char** pData, unsigned int* pLength, aodv_addr_t* a );
00524 
00525 void
00526 set_aodv_addr( aodv_addr_t* dest, const aodv_addr_t* src );
00527 
00528 aodv_chunk_t*
00529 new_aodv_chunk( unsigned int length );
00530 
00531 void
00532 free_aodv_chunk( aodv_chunk_t* chunk );
00533 
00534 aodv_chunk_t*
00535 collapse_chunk( const aodv_chunk_t* bigchunk );
00536 
00537 void
00538 free_aodv_node_list( aodv_node_list_t* head );
00539 
00540 void
00541 free_aodv_time_ring( aodv_time_ring_t* ring );
00542 
00543 void
00544 free_aodv_rreq( aodv_rreq_t* r );
00545 
00546 void
00547 free_aodv_rrep( aodv_rrep_t* r );
00548 
00549 void
00550 free_aodv_rerr( aodv_rerr_t* r );
00551 
00556 #ifdef __cplusplus
00557 }
00558 #endif
00559 
00560 #endif /* __AODV_H__ */

Generated on Mon Mar 24 11:15:45 2008 for Pydtn Simulator by  doxygen 1.5.4