jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_events.h |
| 3 | * |
| 4 | * Copyright (C) 2001,2002 Sampo Saaristo |
| 5 | * Tampere University of Technology |
| 6 | * Institute of Communications Engineering |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public Licenseas published by the Free |
| 10 | * Software Foundation; either version 2 of the License, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful,but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
| 17 | |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | #include <stdlib.h> |
| 23 | #include <stdio.h> |
| 24 | #include <ctype.h> |
| 25 | #include <zebra.h> |
| 26 | #include <net/ethernet.h> |
| 27 | |
| 28 | #include "log.h" |
| 29 | #include "memory.h" |
| 30 | #include "if.h" |
| 31 | #include "linklist.h" |
| 32 | #include "command.h" |
| 33 | #include "thread.h" |
| 34 | #include "hash.h" |
| 35 | #include "prefix.h" |
| 36 | #include "stream.h" |
| 37 | |
| 38 | #include "isisd/dict.h" |
| 39 | #include "isisd/include-netbsd/iso.h" |
| 40 | #include "isisd/isis_constants.h" |
| 41 | #include "isisd/isis_common.h" |
| 42 | #include "isisd/isis_circuit.h" |
| 43 | #include "isisd/isis_tlv.h" |
| 44 | #include "isisd/isis_lsp.h" |
| 45 | #include "isisd/isis_pdu.h" |
| 46 | #include "isisd/isis_network.h" |
| 47 | #include "isisd/isis_misc.h" |
| 48 | #include "isisd/isis_constants.h" |
| 49 | #include "isisd/isis_adjacency.h" |
| 50 | #include "isisd/isis_dr.h" |
| 51 | #include "isisd/isis_flags.h" |
| 52 | #include "isisd/isisd.h" |
| 53 | #include "isisd/isis_csm.h" |
| 54 | #include "isisd/isis_events.h" |
| 55 | #include "isisd/isis_spf.h" |
| 56 | |
| 57 | extern struct thread_master *master; |
| 58 | extern struct isis *isis; |
| 59 | |
| 60 | /* debug isis-spf spf-events |
| 61 | 4w4d: ISIS-Spf (tlt): L2 SPF needed, new adjacency, from 0x609229F4 |
| 62 | 4w4d: ISIS-Spf (tlt): L2, 0000.0000.0042.01-00 TLV contents changed, code 0x2 |
| 63 | 4w4d: ISIS-Spf (tlt): L2, new LSP 0 DEAD.BEEF.0043.00-00 |
| 64 | 4w5d: ISIS-Spf (tlt): L1 SPF needed, periodic SPF, from 0x6091C844 |
| 65 | 4w5d: ISIS-Spf (tlt): L2 SPF needed, periodic SPF, from 0x6091C844 |
| 66 | */ |
| 67 | |
| 68 | void |
| 69 | isis_event_circuit_state_change (struct isis_circuit *circuit, int up) |
| 70 | { |
| 71 | struct isis_area *area; |
| 72 | |
| 73 | area = circuit->area; |
| 74 | assert (area); |
| 75 | area->circuit_state_changes++; |
| 76 | |
| 77 | if (isis->debugs & DEBUG_EVENTS) |
| 78 | zlog_info ("ISIS-Evt (%s) circuit %s", circuit->area->area_tag, |
| 79 | up ? "up" : "down"); |
| 80 | |
| 81 | /* |
| 82 | * Regenerate LSPs this affects |
| 83 | */ |
| 84 | lsp_regenerate_schedule (area); |
| 85 | |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | void |
| 90 | isis_event_system_type_change (struct isis_area *area, int newtype) |
| 91 | { |
| 92 | struct listnode *node; |
| 93 | struct isis_circuit *circuit; |
| 94 | |
| 95 | if (isis->debugs & DEBUG_EVENTS) |
| 96 | zlog_info ("ISIS-Evt (%s) system type change %s -> %s", area->area_tag, |
| 97 | circuit_t2string (area->is_type), circuit_t2string (newtype)); |
| 98 | |
| 99 | if (area->is_type == newtype) |
| 100 | return; /* No change */ |
| 101 | |
| 102 | switch (area->is_type) { |
| 103 | case IS_LEVEL_1: |
| 104 | if (area->lspdb[1] == NULL) |
| 105 | area->lspdb[1] = lsp_db_init (); |
| 106 | lsp_l2_generate (area); |
| 107 | break; |
| 108 | case IS_LEVEL_1_AND_2: |
| 109 | if (newtype == IS_LEVEL_1) { |
| 110 | lsp_db_destroy (area->lspdb[1]); |
| 111 | } |
| 112 | else { |
| 113 | lsp_db_destroy (area->lspdb[0]); |
| 114 | } |
| 115 | break; |
| 116 | case IS_LEVEL_2: |
| 117 | if (area->lspdb[0] == NULL) |
| 118 | area->lspdb[0] = lsp_db_init (); |
| 119 | lsp_l1_generate (area); |
| 120 | break; |
| 121 | default: |
| 122 | break; |
| 123 | } |
| 124 | |
| 125 | area->is_type = newtype; |
| 126 | for (node = listhead (area->circuit_list); node; nextnode (node)) { |
| 127 | circuit = getdata (node); |
| 128 | isis_event_circuit_type_change (circuit, newtype); |
| 129 | } |
| 130 | |
| 131 | spftree_area_init (area); |
| 132 | lsp_regenerate_schedule (area); |
| 133 | |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | |
| 139 | void |
| 140 | isis_event_area_addr_change (struct isis_area *area) |
| 141 | { |
| 142 | |
| 143 | } |
| 144 | |
| 145 | void |
| 146 | circuit_commence_level (struct isis_circuit *circuit, int level) |
| 147 | { |
| 148 | uint32_t interval; |
| 149 | |
| 150 | if (level == 1) { |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 151 | THREAD_TIMER_ON(master, circuit->t_send_psnp[0], send_l1_psnp, circuit, |
| 152 | isis_jitter(circuit->psnp_interval[0], PSNP_JITTER)); |
| 153 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 154 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { |
| 155 | interval = circuit->hello_multiplier[0] * (circuit->hello_interval[0]); |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 156 | |
| 157 | THREAD_TIMER_ON(master, circuit->u.bc.t_run_dr[0], isis_run_dr_l1, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 158 | circuit, interval); |
| 159 | |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 160 | THREAD_TIMER_ON(master, circuit->u.bc.t_send_lan_hello[0], |
| 161 | send_lan_l1_hello, circuit, |
| 162 | isis_jitter(circuit->hello_interval[0], IIH_JITTER)); |
| 163 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 164 | circuit->u.bc.lan_neighs[0] = list_new (); |
| 165 | } |
| 166 | } else { |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 167 | THREAD_TIMER_ON(master, circuit->t_send_psnp[1], send_l2_psnp, circuit, |
| 168 | isis_jitter(circuit->psnp_interval[1], PSNP_JITTER)); |
| 169 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 170 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { |
| 171 | interval = circuit->hello_multiplier[1] * (circuit->hello_interval[1]); |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 172 | |
| 173 | THREAD_TIMER_ON(master, circuit->u.bc.t_run_dr[1], isis_run_dr_l2, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 174 | circuit, interval); |
| 175 | |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 176 | THREAD_TIMER_ON(master, circuit->u.bc.t_send_lan_hello[1], |
| 177 | send_lan_l2_hello, circuit, |
| 178 | isis_jitter(circuit->hello_interval[1], IIH_JITTER)); |
| 179 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 180 | circuit->u.bc.lan_neighs[1] = list_new (); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | void |
| 188 | circuit_resign_level (struct isis_circuit *circuit, int level) |
| 189 | { |
| 190 | int idx = level - 1; |
| 191 | |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 192 | THREAD_TIMER_OFF(circuit->t_send_csnp[idx]); |
| 193 | THREAD_TIMER_OFF(circuit->t_send_psnp[idx]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 194 | |
| 195 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 196 | THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[idx]); |
| 197 | THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[idx]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 198 | circuit->u.bc.run_dr_elect[idx] = 0; |
| 199 | } |
| 200 | |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | void |
| 205 | isis_event_circuit_type_change (struct isis_circuit *circuit, int newtype) |
| 206 | { |
| 207 | |
| 208 | if (isis->debugs & DEBUG_EVENTS) |
| 209 | zlog_info ("ISIS-Evt (%s) circuit type change %s -> %s", |
| 210 | circuit->area->area_tag, |
| 211 | circuit_t2string (circuit->circuit_is_type), |
| 212 | circuit_t2string (newtype)); |
| 213 | |
| 214 | if (circuit->circuit_is_type == newtype) |
| 215 | return; /* No change */ |
| 216 | |
| 217 | if (!(newtype & circuit->area->is_type)) { |
| 218 | zlog_err ("ISIS-Evt (%s) circuit type change - invalid level %s because" |
| 219 | " area is %s", circuit->area->area_tag, |
| 220 | circuit_t2string (newtype), |
| 221 | circuit_t2string (circuit->area->is_type)); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | switch (circuit->circuit_is_type) { |
| 226 | case IS_LEVEL_1: |
| 227 | if (newtype == IS_LEVEL_2) |
| 228 | circuit_resign_level (circuit, 1); |
| 229 | circuit_commence_level (circuit, 2); |
| 230 | break; |
| 231 | case IS_LEVEL_1_AND_2: |
| 232 | if (newtype == IS_LEVEL_1) |
| 233 | circuit_resign_level (circuit, 2); |
| 234 | else |
| 235 | circuit_resign_level (circuit, 1); |
| 236 | break; |
| 237 | case IS_LEVEL_2: |
| 238 | if (newtype == IS_LEVEL_1) |
| 239 | circuit_resign_level (circuit, 2); |
| 240 | circuit_commence_level (circuit, 1); |
| 241 | break; |
| 242 | default: |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | circuit->circuit_is_type = newtype; |
| 247 | lsp_regenerate_schedule (circuit->area); |
| 248 | |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | /* 04/18/2002 by Gwak. */ |
| 253 | /************************************************************************** |
| 254 | * |
| 255 | * EVENTS for LSP generation |
| 256 | * |
| 257 | * 1) an Adajacency or Circuit Up/Down event |
| 258 | * 2) a chnage in Circuit metric |
| 259 | * 3) a change in Reachable Address metric |
| 260 | * 4) a change in manualAreaAddresses |
| 261 | * 5) a change in systemID |
| 262 | * 6) a change in DIS status |
| 263 | * 7) a chnage in the waiting status |
| 264 | * |
| 265 | * *********************************************************************** |
| 266 | * |
| 267 | * current support event |
| 268 | * |
| 269 | * 1) Adjacency Up/Down event |
| 270 | * 6) a change in DIS status |
| 271 | * |
| 272 | * ***********************************************************************/ |
| 273 | |
| 274 | void |
| 275 | isis_event_adjacency_state_change (struct isis_adjacency *adj, int newstate) |
| 276 | { |
| 277 | /* adjacency state change event. |
| 278 | * - the only proto-type was supported */ |
| 279 | |
| 280 | /* invalid arguments */ |
| 281 | if ( !adj || !adj->circuit || !adj->circuit->area ) return; |
| 282 | |
| 283 | zlog_info ("ISIS-Evt (%s) Adjacency State change", |
| 284 | adj->circuit->area->area_tag ); |
| 285 | |
| 286 | /* LSP generation again */ |
| 287 | lsp_regenerate_schedule (adj->circuit->area); |
| 288 | |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | /* events supporting code */ |
| 293 | |
| 294 | int |
| 295 | isis_event_dis_status_change (struct thread *thread) |
| 296 | { |
| 297 | struct isis_circuit *circuit; |
| 298 | |
| 299 | circuit = THREAD_ARG (thread); |
| 300 | |
| 301 | /* invalid arguments */ |
| 302 | if (!circuit || !circuit->area) return 0; |
| 303 | |
| 304 | zlog_info ("ISIS-Evt (%s) DIS status change", circuit->area->area_tag); |
| 305 | |
| 306 | /* LSP generation again */ |
| 307 | lsp_regenerate_schedule (circuit->area); |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | void |
| 314 | isis_event_auth_failure (char *area_tag, char *error_string, char *sysid) |
| 315 | { |
| 316 | zlog_info ("ISIS-Evt (%s) Authentication failure %s from %s", |
| 317 | area_tag, error_string, sysid_print (sysid)); |
| 318 | |
| 319 | return; |
| 320 | } |
| 321 | |