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.
44 #include "olsr_protocol.h"
45 #include "hysteresis.h"
50 #include "scheduler.h"
52 #define hscaling olsr_cnf->hysteresis_param.scaling
53 #define hhigh olsr_cnf->hysteresis_param.thr_high
54 #define hlow olsr_cnf->hysteresis_param.thr_low
57 olsr_hyst_calc_stability(float old_quality)
59 return (((1 - hscaling) * old_quality) + hscaling);
65 olsr_hyst_calc_instability(float old_quality)
67 return ((1 - hscaling) * old_quality);
73 olsr_process_hysteresis(struct link_entry *entry)
75 //printf("PROCESSING QUALITY: %f\n", entry->L_link_quality);
76 if(entry->L_link_quality > hhigh)
78 if(entry->L_link_pending == 1)
80 struct ipaddr_str buf;
81 OLSR_PRINTF(1, "HYST[%s] link set to NOT pending!\n",
82 olsr_ip_to_string(&buf, &entry->neighbor_iface_addr));
83 changes_neighborhood = OLSR_TRUE;
87 entry->L_link_pending = 0;
89 if(!TIMED_OUT(entry->L_LOST_LINK_time))
90 changes_neighborhood = OLSR_TRUE;
93 entry->L_LOST_LINK_time = now_times - 1;
98 if(entry->L_link_quality < hlow)
100 if(entry->L_link_pending == 0)
102 struct ipaddr_str buf;
103 OLSR_PRINTF(1, "HYST[%s] link set to pending!\n",
104 olsr_ip_to_string(&buf, &entry->neighbor_iface_addr));
105 changes_neighborhood = OLSR_TRUE;
109 entry->L_link_pending = 1;
111 if(TIMED_OUT(entry->L_LOST_LINK_time))
112 changes_neighborhood = OLSR_TRUE;
114 /* Timer = min (L_time, current time + NEIGHB_HOLD_TIME) */
115 entry->L_LOST_LINK_time = MIN(GET_TIMESTAMP(NEIGHB_HOLD_TIME * MSEC_PER_SEC),
116 entry->link_timer->timer_clock);
118 /* (the link is then considered as lost according to section
119 8.5 and this may produce a neighbor loss).
126 *If we get here then:
127 *(HYST_THRESHOLD_LOW <= entry->L_link_quality <= HYST_THRESHOLD_HIGH)
130 /* L_link_pending and L_LOST_LINK_time remain unchanged. */
137 *Update the hello timeout of a hysteresis link
140 *@param entry the link entry to update
141 *@param htime the hello interval to use
146 olsr_update_hysteresis_hello(struct link_entry *entry, olsr_reltime htime)
148 struct ipaddr_str buf;
149 OLSR_PRINTF(3, "HYST[%s]: HELLO update vtime %u ms\n",
150 olsr_ip_to_string(&buf, &entry->neighbor_iface_addr), htime+htime/2);
152 olsr_set_timer(&entry->link_hello_timer, htime + htime/2, OLSR_LINK_HELLO_JITTER,
153 OLSR_TIMER_PERIODIC, &olsr_expire_link_hello_timer, entry, 0);
161 update_hysteresis_incoming(union olsr_ip_addr *remote, struct interface *local, olsr_u16_t seqno)
163 struct link_entry *lnk = lookup_link_entry(remote, NULL, local);
165 /* Calculate new quality */
169 struct ipaddr_str buf;
171 lnk->L_link_quality = olsr_hyst_calc_stability(lnk->L_link_quality);
173 OLSR_PRINTF(3, "HYST[%s]: %f\n", olsr_ip_to_string(&buf, remote), lnk->L_link_quality);
177 * see how many packets we have missed and update the link quality
178 * for each missed packet; HELLOs have already been accounted for by
179 * the timeout function and the number of missed HELLOs has already
180 * been added to olsr_seqno there
183 if (lnk->olsr_seqno_valid &&
184 (unsigned short)(seqno - lnk->olsr_seqno) < 100)
185 while (lnk->olsr_seqno != seqno)
187 lnk->L_link_quality = olsr_hyst_calc_instability(lnk->L_link_quality);
189 OLSR_PRINTF(5, "HYST[%s] PACKET LOSS! %f\n",
190 olsr_ip_to_string(&buf, remote), lnk->L_link_quality);
192 if(lnk->L_link_quality < olsr_cnf->hysteresis_param.thr_low)
199 lnk->olsr_seqno = seqno + 1;
200 lnk->olsr_seqno_valid = OLSR_TRUE;
202 //printf("Updating seqno to: %d\n", lnk->olsr_seqno);