File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / quagga / isisd / isis_csm.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Oct 9 09:22:28 2012 UTC (11 years, 8 months ago) by misho
Branches: quagga, MAIN
CVS tags: v0_99_21, HEAD
quagga

    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>
   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_flags.h"
   40: #include "isisd/isis_circuit.h"
   41: #include "isisd/isis_tlv.h"
   42: #include "isisd/isis_lsp.h"
   43: #include "isisd/isis_pdu.h"
   44: #include "isisd/isis_network.h"
   45: #include "isisd/isis_misc.h"
   46: #include "isisd/isis_constants.h"
   47: #include "isisd/isis_adjacency.h"
   48: #include "isisd/isis_dr.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: 
   55: static const char *csm_statestr[] = {
   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: 
   64: static const char *csm_eventstr[] = {
   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: 
   74: struct isis_circuit *
   75: isis_csm_state_change (int event, struct isis_circuit *circuit, void *arg)
   76: {
   77:   int old_state;
   78: 
   79:   old_state = circuit ? circuit->state : C_STATE_NA;
   80:   if (isis->debugs & DEBUG_EVENTS)
   81:     zlog_debug ("CSM_EVENT: %s", EVENT2STR (event));
   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:       assert (circuit == NULL);
   89:       switch (event)
   90: 	{
   91: 	case ISIS_ENABLE:
   92: 	  circuit = isis_circuit_new ();
   93: 	  isis_circuit_configure (circuit, (struct isis_area *) arg);
   94: 	  circuit->state = C_STATE_CONF;
   95: 	  break;
   96: 	case IF_UP_FROM_Z:
   97: 	  circuit = isis_circuit_new ();
   98: 	  isis_circuit_if_add (circuit, (struct interface *) arg);
   99: 	  listnode_add (isis->init_circ_list, circuit);
  100: 	  circuit->state = C_STATE_INIT;
  101: 	  break;
  102: 	case ISIS_DISABLE:
  103: 	  zlog_warn ("circuit already disabled");
  104: 	case IF_DOWN_FROM_Z:
  105: 	  zlog_warn ("circuit already disconnected");
  106: 	  break;
  107: 	}
  108:       break;
  109:     case C_STATE_INIT:
  110:       assert (circuit);
  111:       switch (event)
  112: 	{
  113: 	case ISIS_ENABLE:
  114: 	  isis_circuit_configure (circuit, (struct isis_area *) arg);
  115: 	  if (isis_circuit_up (circuit) != ISIS_OK)
  116: 	    {
  117: 	      isis_circuit_deconfigure (circuit, (struct isis_area *) arg);
  118: 	      break;
  119: 	    }
  120: 	  circuit->state = C_STATE_UP;
  121: 	  isis_event_circuit_state_change (circuit, circuit->area, 1);
  122: 	  listnode_delete (isis->init_circ_list, circuit);
  123: 	  break;
  124: 	case IF_UP_FROM_Z:
  125:           assert (circuit);
  126: 	  zlog_warn ("circuit already connected");
  127: 	  break;
  128: 	case ISIS_DISABLE:
  129: 	  zlog_warn ("circuit already disabled");
  130: 	  break;
  131: 	case IF_DOWN_FROM_Z:
  132: 	  isis_circuit_if_del (circuit, (struct interface *) arg);
  133: 	  listnode_delete (isis->init_circ_list, circuit);
  134: 	  isis_circuit_del (circuit);
  135: 	  circuit = NULL;
  136: 	  break;
  137: 	}
  138:       break;
  139:     case C_STATE_CONF:
  140:       assert (circuit);
  141:       switch (event)
  142: 	{
  143: 	case ISIS_ENABLE:
  144: 	  zlog_warn ("circuit already enabled");
  145: 	  break;
  146: 	case IF_UP_FROM_Z:
  147: 	  isis_circuit_if_add (circuit, (struct interface *) arg);
  148: 	  if (isis_circuit_up (circuit) != ISIS_OK)
  149:             {
  150:               isis_circuit_if_del (circuit, (struct interface *) arg);
  151: 	      break;
  152:             }
  153: 	  circuit->state = C_STATE_UP;
  154: 	  isis_event_circuit_state_change (circuit, circuit->area, 1);
  155: 	  break;
  156: 	case ISIS_DISABLE:
  157: 	  isis_circuit_deconfigure (circuit, (struct isis_area *) arg);
  158: 	  isis_circuit_del (circuit);
  159: 	  circuit = NULL;
  160: 	  break;
  161: 	case IF_DOWN_FROM_Z:
  162: 	  zlog_warn ("circuit already disconnected");
  163: 	  break;
  164: 	}
  165:       break;
  166:     case C_STATE_UP:
  167:       assert (circuit);
  168:       switch (event)
  169: 	{
  170: 	case ISIS_ENABLE:
  171: 	  zlog_warn ("circuit already configured");
  172: 	  break;
  173: 	case IF_UP_FROM_Z:
  174: 	  zlog_warn ("circuit already connected");
  175: 	  break;
  176: 	case ISIS_DISABLE:
  177: 	  isis_circuit_down (circuit);
  178: 	  isis_circuit_deconfigure (circuit, (struct isis_area *) arg);
  179: 	  circuit->state = C_STATE_INIT;
  180: 	  isis_event_circuit_state_change (circuit,
  181:                                            (struct isis_area *)arg, 0);
  182: 	  listnode_add (isis->init_circ_list, circuit);
  183: 	  break;
  184: 	case IF_DOWN_FROM_Z:
  185: 	  isis_circuit_down (circuit);
  186:           isis_circuit_if_del (circuit, (struct interface *) arg);
  187: 	  circuit->state = C_STATE_CONF;
  188: 	  isis_event_circuit_state_change (circuit, circuit->area, 0);
  189: 	  break;
  190: 	}
  191:       break;
  192: 
  193:     default:
  194:       zlog_warn ("Invalid circuit state %d", old_state);
  195:     }
  196: 
  197:   if (isis->debugs & DEBUG_EVENTS)
  198:     zlog_debug ("CSM_STATE_CHANGE: %s -> %s ", STATE2STR (old_state),
  199: 		circuit ? STATE2STR (circuit->state) : STATE2STR (C_STATE_NA));
  200: 
  201:   return circuit;
  202: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>