jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_csm.c |
| 3 | * IS-IS circuit state machine |
| 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 | |
| 23 | #include <zebra.h> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 24 | |
| 25 | #include "log.h" |
| 26 | #include "memory.h" |
| 27 | #include "if.h" |
| 28 | #include "linklist.h" |
| 29 | #include "command.h" |
| 30 | #include "thread.h" |
| 31 | #include "hash.h" |
| 32 | #include "prefix.h" |
| 33 | #include "stream.h" |
| 34 | |
| 35 | #include "isisd/dict.h" |
| 36 | #include "isisd/include-netbsd/iso.h" |
| 37 | #include "isisd/isis_constants.h" |
| 38 | #include "isisd/isis_common.h" |
| 39 | #include "isisd/isis_circuit.h" |
| 40 | #include "isisd/isis_tlv.h" |
| 41 | #include "isisd/isis_lsp.h" |
| 42 | #include "isisd/isis_pdu.h" |
| 43 | #include "isisd/isis_network.h" |
| 44 | #include "isisd/isis_misc.h" |
| 45 | #include "isisd/isis_constants.h" |
| 46 | #include "isisd/isis_adjacency.h" |
| 47 | #include "isisd/isis_dr.h" |
| 48 | #include "isisd/isis_flags.h" |
| 49 | #include "isisd/isisd.h" |
| 50 | #include "isisd/isis_csm.h" |
| 51 | #include "isisd/isis_events.h" |
| 52 | |
| 53 | extern struct isis *isis; |
| 54 | |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 55 | static const char *csm_statestr[] = { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 56 | "C_STATE_NA", |
| 57 | "C_STATE_INIT", |
| 58 | "C_STATE_CONF", |
| 59 | "C_STATE_UP" |
| 60 | }; |
| 61 | |
| 62 | #define STATE2STR(S) csm_statestr[S] |
| 63 | |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 64 | static const char *csm_eventstr[] = { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 65 | "NO_STATE", |
| 66 | "ISIS_ENABLE", |
| 67 | "IF_UP_FROM_Z", |
| 68 | "ISIS_DISABLE", |
| 69 | "IF_DOWN_FROM_Z", |
| 70 | }; |
| 71 | |
| 72 | #define EVENT2STR(E) csm_eventstr[E] |
| 73 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 74 | struct isis_circuit * |
| 75 | isis_csm_state_change (int event, struct isis_circuit *circuit, void *arg) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 76 | { |
| 77 | int old_state; |
| 78 | |
| 79 | old_state = circuit ? circuit->state : C_STATE_NA; |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 80 | if (isis->debugs & DEBUG_EVENTS) |
| 81 | zlog_debug ("CSM_EVENT: %s", EVENT2STR (event)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 82 | |
| 83 | switch (old_state) |
| 84 | { |
| 85 | case C_STATE_NA: |
| 86 | if (circuit) |
| 87 | zlog_warn ("Non-null circuit while state C_STATE_NA"); |
| 88 | switch (event) |
| 89 | { |
| 90 | case ISIS_ENABLE: |
| 91 | circuit = isis_circuit_new (); |
| 92 | isis_circuit_configure (circuit, (struct isis_area *) arg); |
| 93 | circuit->state = C_STATE_CONF; |
| 94 | break; |
| 95 | case IF_UP_FROM_Z: |
| 96 | circuit = isis_circuit_new (); |
| 97 | isis_circuit_if_add (circuit, (struct interface *) arg); |
| 98 | listnode_add (isis->init_circ_list, circuit); |
| 99 | circuit->state = C_STATE_INIT; |
| 100 | break; |
| 101 | case ISIS_DISABLE: |
| 102 | zlog_warn ("circuit already disabled"); |
| 103 | case IF_DOWN_FROM_Z: |
| 104 | zlog_warn ("circuit already disconnected"); |
| 105 | break; |
| 106 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 107 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 108 | case C_STATE_INIT: |
| 109 | switch (event) |
| 110 | { |
| 111 | case ISIS_ENABLE: |
| 112 | isis_circuit_configure (circuit, (struct isis_area *) arg); |
| 113 | isis_circuit_up (circuit); |
| 114 | circuit->state = C_STATE_UP; |
Peter Szilagyi | 7fd6cd8 | 2011-10-01 17:11:45 +0400 | [diff] [blame^] | 115 | circuit->connected = 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 116 | isis_event_circuit_state_change (circuit, 1); |
| 117 | listnode_delete (isis->init_circ_list, circuit); |
| 118 | break; |
| 119 | case IF_UP_FROM_Z: |
| 120 | zlog_warn ("circuit already connected"); |
| 121 | break; |
| 122 | case ISIS_DISABLE: |
| 123 | zlog_warn ("circuit already disabled"); |
| 124 | break; |
| 125 | case IF_DOWN_FROM_Z: |
| 126 | isis_circuit_if_del (circuit); |
| 127 | listnode_delete (isis->init_circ_list, circuit); |
| 128 | isis_circuit_del (circuit); |
hasso | 4660687 | 2004-12-29 19:34:22 +0000 | [diff] [blame] | 129 | circuit = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 130 | break; |
| 131 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 132 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 133 | case C_STATE_CONF: |
| 134 | switch (event) |
| 135 | { |
| 136 | case ISIS_ENABLE: |
| 137 | zlog_warn ("circuit already enabled"); |
| 138 | break; |
| 139 | case IF_UP_FROM_Z: |
Peter Szilagyi | 7fd6cd8 | 2011-10-01 17:11:45 +0400 | [diff] [blame^] | 140 | if (!circuit->connected) { |
| 141 | isis_circuit_if_add (circuit, (struct interface *) arg); |
| 142 | isis_circuit_up (circuit); |
| 143 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 144 | circuit->state = C_STATE_UP; |
Peter Szilagyi | 7fd6cd8 | 2011-10-01 17:11:45 +0400 | [diff] [blame^] | 145 | circuit->connected = 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 146 | isis_event_circuit_state_change (circuit, 1); |
| 147 | break; |
| 148 | case ISIS_DISABLE: |
| 149 | isis_circuit_deconfigure (circuit, (struct isis_area *) arg); |
| 150 | isis_circuit_del (circuit); |
hasso | 4660687 | 2004-12-29 19:34:22 +0000 | [diff] [blame] | 151 | circuit = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 152 | break; |
| 153 | case IF_DOWN_FROM_Z: |
| 154 | zlog_warn ("circuit already disconnected"); |
| 155 | break; |
| 156 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 157 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 158 | case C_STATE_UP: |
| 159 | switch (event) |
| 160 | { |
| 161 | case ISIS_ENABLE: |
| 162 | zlog_warn ("circuit already configured"); |
| 163 | break; |
| 164 | case IF_UP_FROM_Z: |
| 165 | zlog_warn ("circuit already connected"); |
| 166 | break; |
| 167 | case ISIS_DISABLE: |
| 168 | isis_circuit_deconfigure (circuit, (struct isis_area *) arg); |
| 169 | listnode_add (isis->init_circ_list, circuit); |
| 170 | circuit->state = C_STATE_INIT; |
| 171 | isis_event_circuit_state_change (circuit, 0); |
| 172 | break; |
| 173 | case IF_DOWN_FROM_Z: |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 174 | circuit->state = C_STATE_CONF; |
| 175 | isis_event_circuit_state_change (circuit, 0); |
| 176 | break; |
| 177 | } |
| 178 | break; |
| 179 | |
| 180 | default: |
| 181 | zlog_warn ("Invalid circuit state %d", old_state); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 182 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 183 | |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 184 | if (isis->debugs & DEBUG_EVENTS) |
| 185 | zlog_debug ("CSM_STATE_CHANGE: %s -> %s ", STATE2STR (old_state), |
| 186 | circuit ? STATE2STR (circuit->state) : STATE2STR (C_STATE_NA)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 187 | |
| 188 | return circuit; |
| 189 | } |