/*
 * IS-IS Rout(e)ing protocol - isis_csm.c
 *                             IS-IS circuit state machine
 * Copyright (C) 2001,2002    Sampo Saaristo
 *                            Tampere University of Technology      
 *                            Institute of Communications Engineering
 *
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU General Public Licenseas published by the Free 
 * Software Foundation; either version 2 of the License, or (at your option) 
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
 * more details.
 *
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include <zebra.h>

#include "log.h"
#include "memory.h"
#include "if.h"
#include "linklist.h"
#include "command.h"
#include "thread.h"
#include "hash.h"
#include "prefix.h"
#include "stream.h"

#include "isisd/dict.h"
#include "isisd/include-netbsd/iso.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_tlv.h"
#include "isisd/isis_lsp.h"
#include "isisd/isis_pdu.h"
#include "isisd/isis_network.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_dr.h"
#include "isisd/isis_flags.h"
#include "isisd/isisd.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"

extern struct isis *isis;

static char *csm_statestr[] = 
{
  "C_STATE_NA",
  "C_STATE_INIT",
  "C_STATE_CONF",
  "C_STATE_UP"
};

#define STATE2STR(S) csm_statestr[S]

static char *csm_eventstr[] =
{
  "NO_STATE",
  "ISIS_ENABLE",
  "IF_UP_FROM_Z",
  "ISIS_DISABLE",
  "IF_DOWN_FROM_Z",
};

#define EVENT2STR(E) csm_eventstr[E]


struct isis_circuit*
isis_csm_state_change (int event, struct isis_circuit *circuit, 
                       void *arg)
{
  int old_state;

  old_state = circuit ? circuit->state : C_STATE_NA;
  
  zlog_info ("CSM_EVENT: %s", EVENT2STR(event));
  
  switch (old_state) {
  case C_STATE_NA:
    if (circuit)
      zlog_warn ("Non-null circuit while state C_STATE_NA");
    switch (event) {
    case ISIS_ENABLE:
      circuit = isis_circuit_new ();
      isis_circuit_configure (circuit, (struct isis_area *)arg);
      circuit->state = C_STATE_CONF;
      break;
    case IF_UP_FROM_Z:
      circuit = isis_circuit_new ();
      isis_circuit_if_add (circuit, (struct interface *)arg);
      listnode_add (isis->init_circ_list, circuit);
      circuit->state = C_STATE_INIT;
      break;
    case ISIS_DISABLE:
      zlog_warn ("circuit already disabled");
    case IF_DOWN_FROM_Z:
      zlog_warn ("circuit already disconnected");
      break;
    }
    break;
  case C_STATE_INIT:
    switch (event) {
    case ISIS_ENABLE:
      isis_circuit_configure (circuit, (struct isis_area *)arg);
      isis_circuit_up (circuit);
      circuit->state = C_STATE_UP;
      isis_event_circuit_state_change (circuit, 1);
      listnode_delete (isis->init_circ_list, circuit);
      break;
    case IF_UP_FROM_Z:
      zlog_warn ("circuit already connected");
      break;
    case ISIS_DISABLE:
      zlog_warn ("circuit already disabled");
      break;
    case IF_DOWN_FROM_Z:
      isis_circuit_if_del (circuit);
      listnode_delete (isis->init_circ_list, circuit);
      isis_circuit_del (circuit);
      break;
    }
    break;
  case C_STATE_CONF:
    switch (event) {
    case ISIS_ENABLE:
      zlog_warn ("circuit already enabled");
      break;
    case IF_UP_FROM_Z:
      isis_circuit_if_add (circuit, (struct interface *)arg);
      isis_circuit_up (circuit);
      circuit->state = C_STATE_UP;
      isis_event_circuit_state_change (circuit, 1);
      break;
    case ISIS_DISABLE:
      isis_circuit_deconfigure (circuit, (struct isis_area *)arg);
      isis_circuit_del (circuit);
      break;
    case IF_DOWN_FROM_Z:
      zlog_warn ("circuit already disconnected");
      break;
    }
    break;
  case C_STATE_UP:
    switch (event) {
    case ISIS_ENABLE:
      zlog_warn ("circuit already configured");
      break;
    case IF_UP_FROM_Z:
      zlog_warn ("circuit already connected");
      break;
    case ISIS_DISABLE:
      isis_circuit_deconfigure (circuit, (struct isis_area *)arg);
      listnode_add (isis->init_circ_list, circuit);
      circuit->state = C_STATE_INIT;
      isis_event_circuit_state_change (circuit, 0);
      break;
    case IF_DOWN_FROM_Z:
      isis_circuit_if_del (circuit);
      circuit->state = C_STATE_CONF;
      isis_event_circuit_state_change (circuit, 0);
      break;
    }
    break;
    
  default:
    zlog_warn ("Invalid circuit state %d", old_state);
  }
  
  zlog_info ("CSM_STATE_CHANGE: %s -> %s ", STATE2STR (old_state), 
             circuit ? STATE2STR (circuit->state) : STATE2STR (C_STATE_NA));

  return circuit;
}



