1 /* 2 * The olsr.org Optimized Link-State Routing daemon (olsrd) 3 * 4 * (c) by the OLSR project 5 * 6 * See our Git repository to find out who worked on this file 7 * and thus is a copyright holder on it. 8 * 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 15 * * Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * * Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in 19 * the documentation and/or other materials provided with the 20 * distribution. 21 * * Neither the name of olsr.org, olsrd nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 * 38 * Visit http://www.olsr.org for more information. 39 * 40 * If you find this software useful feel free to make a donation 41 * to the project. For more information see the website or contact 42 * the copyright holders. 43 * 44 */ 45 46 #ifndef LQPLUGIN_H_ 47 #define LQPLUGIN_H_ 48 49 #include "tc_set.h" 50 #include "link_set.h" 51 #include "olsr_spf.h" 52 #include "lq_packet.h" 53 #include "packet.h" 54 #include "common/avl.h" 55 56 #define LINK_COST_BROKEN (1u<<22) 57 #define ROUTE_COST_BROKEN (0xffffffffu) 58 #define ZERO_ROUTE_COST 0u 59 60 #define MINIMAL_USEFUL_LQ 0.1 61 #define LQ_PLUGIN_RELEVANT_COSTCHANGE 16 62 63 #define LQ_QUICKSTART_STEPS 12 64 #define LQ_QUICKSTART_AGING 0.25 65 66 struct lqtextbuffer { 67 char buf[16]; 68 }; 69 70 struct lq_handler { 71 void (*initialize) (void); 72 73 olsr_linkcost (*calc_hello_cost) (const void *lq); 74 olsr_linkcost (*calc_tc_cost) (const void *lq); 75 76 void (*packet_loss_handler) (struct link_entry * entry, void *lq, bool lost); 77 78 void (*memorize_foreign_hello) (void *local, void *foreign); 79 void (*copy_link_lq_into_neigh) (void *target, void *source); 80 void (*copy_link_lq_into_tc) (void *target, void *source); 81 void (*clear_hello) (void *target); 82 void (*clear_tc) (void *target); 83 84 int (*serialize_hello_lq) (unsigned char *buff, void *lq); 85 int (*serialize_tc_lq) (unsigned char *buff, void *lq); 86 void (*deserialize_hello_lq) (const uint8_t ** curr, void *lq); 87 void (*deserialize_tc_lq) (const uint8_t ** curr, void *lq); 88 89 const char *(*print_hello_lq) (void *ptr, char separator, struct lqtextbuffer * buffer); 90 const char *(*print_tc_lq) (void *ptr, char separator, struct lqtextbuffer * buffer); 91 double (*get_cost_scaled) (olsr_linkcost cost); 92 93 size_t hello_lq_size; 94 size_t tc_lq_size; 95 size_t hello_lqdata_size; 96 size_t tc_lqdata_size; 97 }; 98 99 struct lq_handler_node { 100 struct avl_node node; 101 struct lq_handler *handler; 102 char name[0]; 103 }; 104 105 AVLNODE2STRUCT(lq_handler_tree2lq_handler_node, struct lq_handler_node, node); 106 107 #define OLSR_FOR_ALL_LQ_HANDLERS(lq) \ 108 { \ 109 struct avl_node *lq_tree_node, *next_lq_tree_node; \ 110 for (lq_tree_node = avl_walk_first(&lq_handler_tree); \ 111 lq_tree_node; lq_tree_node = next_lq_tree_node) { \ 112 next_lq_tree_node = avl_walk_next(lq_tree_node); \ 113 lq = lq_handler_tree2lq_handler_node(lq_tree_node); 114 #define OLSR_FOR_ALL_LQ_HANDLERS_END(tc) }} 115 116 int avl_strcasecmp(const void *str1, const void *str2); 117 void init_lq_handler_tree(void); 118 119 void register_lq_handler(struct lq_handler *handler, const char *name); 120 121 olsr_linkcost olsr_calc_tc_cost(const struct tc_edge_entry *); 122 123 int olsr_serialize_hello_lq_pair(unsigned char *buff, struct lq_hello_neighbor *neigh); 124 void olsr_deserialize_hello_lq_pair(const uint8_t ** curr, struct hello_neighbor *neigh); 125 int olsr_serialize_tc_lq_pair(unsigned char *buff, struct tc_mpr_addr *neigh); 126 void olsr_deserialize_tc_lq_pair(const uint8_t ** curr, struct tc_edge_entry *edge); 127 128 void olsr_update_packet_loss_worker(struct link_entry *entry, bool lost); 129 void olsr_memorize_foreign_hello_lq(struct link_entry *local, struct hello_neighbor *foreign); 130 131 const char *get_link_entry_text(struct link_entry *entry, char separator, struct lqtextbuffer *buffer); 132 const char *get_tc_edge_entry_text(struct tc_edge_entry *entry, char separator, struct lqtextbuffer *buffer); 133 const char *get_linkcost_text(olsr_linkcost cost, bool route, struct lqtextbuffer *buffer); 134 double get_linkcost_scaled(olsr_linkcost cost, bool route); 135 136 void olsr_clear_hello_lq(struct link_entry */*link*/); 137 void olsr_copy_hello_lq(struct lq_hello_neighbor *target, struct link_entry *source); 138 void olsr_copylq_link_entry_2_tc_mpr_addr(struct tc_mpr_addr *target, struct link_entry *source); 139 void olsr_copylq_link_entry_2_tc_edge_entry(struct tc_edge_entry *target, struct link_entry *source); 140 void olsr_clear_tc_lq(struct tc_mpr_addr *target); 141 142 struct hello_neighbor *olsr_malloc_hello_neighbor(const char *id); 143 struct tc_mpr_addr *olsr_malloc_tc_mpr_addr(const char *id); 144 struct lq_hello_neighbor *olsr_malloc_lq_hello_neighbor(const char *id); 145 struct link_entry *olsr_malloc_link_entry(const char *id); 146 147 size_t olsr_sizeof_hello_lqdata(void); 148 size_t olsr_sizeof_tc_lqdata(void); 149 150 void olsr_relevant_linkcost_change(void); 151 152 /* Externals. */ 153 extern struct lq_handler *active_lq_handler; 154 155 #endif /* LQPLUGIN_H_ */ 156 157 /* 158 * Local Variables: 159 * c-basic-offset: 2 160 * indent-tabs-mode: nil 161 * End: 162 */ 163