/*
 * IS-IS Rout(e)ing protocol                  - isis_spf.c
 *                                              The SPT algorithm
 *
 * 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 "thread.h"
#include "linklist.h"
#include "vty.h"
#include "log.h"
#include "command.h"
#include "memory.h"
#include "prefix.h"
#include "hash.h"
#include "if.h"
#include "table.h"

#include "isis_constants.h"
#include "isis_common.h"
#include "isis_flags.h"
#include "dict.h"
#include "isisd.h"
#include "isis_misc.h"
#include "isis_adjacency.h"
#include "isis_circuit.h"
#include "isis_tlv.h"
#include "isis_pdu.h"
#include "isis_lsp.h"
#include "isis_dynhn.h"
#include "isis_spf.h"
#include "isis_route.h"
#include "isis_csm.h"

int isis_run_spf_l1 (struct thread *thread);
int isis_run_spf_l2 (struct thread *thread);

/* 7.2.7 */
static void
remove_excess_adjs (struct list *adjs)
{
  struct listnode *node, *excess = NULL;
  struct isis_adjacency *adj, *candidate = NULL;
  int comp;

  for (ALL_LIST_ELEMENTS_RO (adjs, node, adj)) 
    {
      if (excess == NULL)
	excess = node;
      candidate = listgetdata (excess);

      if (candidate->sys_type < adj->sys_type)
	{
	  excess = node;
	  candidate = adj;
	  continue;
	}
      if (candidate->sys_type > adj->sys_type)
	continue;

      comp = memcmp (candidate->sysid, adj->sysid, ISIS_SYS_ID_LEN);
      if (comp > 0)
	{
	  excess = node;
	  candidate = adj;
	  continue;
	}
      if (comp < 0)
	continue;

      if (candidate->circuit->circuit_id > adj->circuit->circuit_id)
	{
	  excess = node;
	  candidate = adj;
	  continue;
	}

      if (candidate->circuit->circuit_id < adj->circuit->circuit_id)
	continue;

      comp = memcmp (candidate->snpa, adj->snpa, ETH_ALEN);
      if (comp > 0)
	{
	  excess = node;
	  candidate = adj;
	  continue;
	}
    }

  list_delete_node (adjs, excess);

  return;
}

static const char *
vtype2string (enum vertextype vtype)
{
  switch (vtype)
    {
    case VTYPE_PSEUDO_IS:
      return "pseudo_IS";
      break;
    case VTYPE_PSEUDO_TE_IS:
      return "pseudo_TE-IS";
      break;
    case VTYPE_NONPSEUDO_IS:
      return "IS";
      break;
    case VTYPE_NONPSEUDO_TE_IS:
      return "TE-IS";
      break;
    case VTYPE_ES:
      return "ES";
      break;
    case VTYPE_IPREACH_INTERNAL:
      return "IP internal";
      break;
    case VTYPE_IPREACH_EXTERNAL:
      return "IP external";
      break;
    case VTYPE_IPREACH_TE:
      return "IP TE";
      break;
#ifdef HAVE_IPV6
    case VTYPE_IP6REACH_INTERNAL:
      return "IP6 internal";
      break;
    case VTYPE_IP6REACH_EXTERNAL:
      return "IP6 external";
      break;
#endif /* HAVE_IPV6 */
    default:
      return "UNKNOWN";
    }
  return NULL;			/* Not reached */
}

static const char *
vid2string (struct isis_vertex *vertex, u_char * buff)
{
  switch (vertex->type)
    {
    case VTYPE_PSEUDO_IS:
    case VTYPE_PSEUDO_TE_IS:
      return print_sys_hostname (vertex->N.id);
      break;
    case VTYPE_NONPSEUDO_IS:
    case VTYPE_NONPSEUDO_TE_IS:
    case VTYPE_ES:
      return print_sys_hostname (vertex->N.id);
      break;
    case VTYPE_IPREACH_INTERNAL:
    case VTYPE_IPREACH_EXTERNAL:
    case VTYPE_IPREACH_TE:
#ifdef HAVE_IPV6
    case VTYPE_IP6REACH_INTERNAL:
    case VTYPE_IP6REACH_EXTERNAL:
#endif /* HAVE_IPV6 */
      prefix2str ((struct prefix *) &vertex->N.prefix, (char *) buff, BUFSIZ);
      break;
    default:
      return "UNKNOWN";
    }

  return (char *) buff;
}

static struct isis_vertex *
isis_vertex_new (void *id, enum vertextype vtype)
{
  struct isis_vertex *vertex;

  vertex = XCALLOC (MTYPE_ISIS_VERTEX, sizeof (struct isis_vertex));
  if (vertex == NULL)
    {
      zlog_err ("isis_vertex_new Out of memory!");
      return NULL;
    }

  vertex->type = vtype;
  switch (vtype)
    {
    case VTYPE_ES:
    case VTYPE_NONPSEUDO_IS:
    case VTYPE_NONPSEUDO_TE_IS:
      memcpy (vertex->N.id, (u_char *) id, ISIS_SYS_ID_LEN);
      break;
    case VTYPE_PSEUDO_IS:
    case VTYPE_PSEUDO_TE_IS:
      memcpy (vertex->N.id, (u_char *) id, ISIS_SYS_ID_LEN + 1);
      break;
    case VTYPE_IPREACH_INTERNAL:
    case VTYPE_IPREACH_EXTERNAL:
    case VTYPE_IPREACH_TE:
#ifdef HAVE_IPV6
    case VTYPE_IP6REACH_INTERNAL:
    case VTYPE_IP6REACH_EXTERNAL:
#endif /* HAVE_IPV6 */
      memcpy (&vertex->N.prefix, (struct prefix *) id,
	      sizeof (struct prefix));
      break;
    default:
      zlog_err ("WTF!");
    }

  vertex->Adj_N = list_new ();
  vertex->parents = list_new ();
  vertex->children = list_new ();

  return vertex;
}

static void
isis_vertex_del (struct isis_vertex *vertex)
{
  list_delete (vertex->Adj_N);
  vertex->Adj_N = NULL;
  list_delete (vertex->parents);
  vertex->parents = NULL;
  list_delete (vertex->children);
  vertex->children = NULL;

  memset(vertex, 0, sizeof(struct isis_vertex));
  XFREE (MTYPE_ISIS_VERTEX, vertex);

  return;
}

static void
isis_vertex_adj_del (struct isis_vertex *vertex, struct isis_adjacency *adj)
{
  struct listnode *node, *nextnode;
  if (!vertex)
    return;
  for (node = listhead (vertex->Adj_N); node; node = nextnode)
  {
    nextnode = listnextnode(node);
    if (listgetdata(node) == adj)
      list_delete_node(vertex->Adj_N, node);
  }
  return;
}

struct isis_spftree *
isis_spftree_new (struct isis_area *area)
{
  struct isis_spftree *tree;

  tree = XCALLOC (MTYPE_ISIS_SPFTREE, sizeof (struct isis_spftree));
  if (tree == NULL)
    {
      zlog_err ("ISIS-Spf: isis_spftree_new Out of memory!");
      return NULL;
    }

  tree->tents = list_new ();
  tree->paths = list_new ();
  tree->area = area;
  tree->last_run_timestamp = 0;
  tree->last_run_duration = 0;
  tree->runcount = 0;
  tree->pending = 0;
  return tree;
}

void
isis_spftree_del (struct isis_spftree *spftree)
{
  THREAD_TIMER_OFF (spftree->t_spf);

  spftree->tents->del = (void (*)(void *)) isis_vertex_del;
  list_delete (spftree->tents);
  spftree->tents = NULL;

  spftree->paths->del = (void (*)(void *)) isis_vertex_del;
  list_delete (spftree->paths);
  spftree->paths = NULL;

  XFREE (MTYPE_ISIS_SPFTREE, spftree);

  return;
}

void
isis_spftree_adj_del (struct isis_spftree *spftree, struct isis_adjacency *adj)
{
  struct listnode *node;
  if (!adj)
    return;
  for (node = listhead (spftree->tents); node; node = listnextnode (node))
    isis_vertex_adj_del (listgetdata (node), adj);
  for (node = listhead (spftree->paths); node; node = listnextnode (node))
    isis_vertex_adj_del (listgetdata (node), adj);
  return;
}

void
spftree_area_init (struct isis_area *area)
{
  if (area->is_type & IS_LEVEL_1)
  {
    if (area->spftree[0] == NULL)
      area->spftree[0] = isis_spftree_new (area);
#ifdef HAVE_IPV6
    if (area->spftree6[0] == NULL)
      area->spftree6[0] = isis_spftree_new (area);
#endif
  }

  if (area->is_type & IS_LEVEL_2)
  {
    if (area->spftree[1] == NULL)
      area->spftree[1] = isis_spftree_new (area);
#ifdef HAVE_IPV6
    if (area->spftree6[1] == NULL)
      area->spftree6[1] = isis_spftree_new (area);
#endif
  }

  return;
}

void
spftree_area_del (struct isis_area *area)
{
  if (area->is_type & IS_LEVEL_1)
  {
    if (area->spftree[0] != NULL)
    {
      isis_spftree_del (area->spftree[0]);
      area->spftree[0] = NULL;
    }
#ifdef HAVE_IPV6
    if (area->spftree6[0])
    {
      isis_spftree_del (area->spftree6[0]);
      area->spftree6[0] = NULL;
    }
#endif
  }

  if (area->is_type & IS_LEVEL_2)
  {
    if (area->spftree[1] != NULL)
    {
      isis_spftree_del (area->spftree[1]);
      area->spftree[1] = NULL;
    }
#ifdef HAVE_IPV6
    if (area->spftree6[1] != NULL)
    {
      isis_spftree_del (area->spftree6[1]);
      area->spftree6[1] = NULL;
    }
#endif
  }

  return;
}

void
spftree_area_adj_del (struct isis_area *area, struct isis_adjacency *adj)
{
  if (area->is_type & IS_LEVEL_1)
  {
    if (area->spftree[0] != NULL)
      isis_spftree_adj_del (area->spftree[0], adj);
#ifdef HAVE_IPV6
    if (area->spftree6[0] != NULL)
      isis_spftree_adj_del (area->spftree6[0], adj);
#endif
  }

  if (area->is_type & IS_LEVEL_2)
  {
    if (area->spftree[1] != NULL)
      isis_spftree_adj_del (area->spftree[1], adj);
#ifdef HAVE_IPV6
    if (area->spftree6[1] != NULL)
      isis_spftree_adj_del (area->spftree6[1], adj);
#endif
  }

  return;
}

/* 
 * Find the system LSP: returns the LSP in our LSP database 
 * associated with the given system ID.
 */
static struct isis_lsp *
isis_root_system_lsp (struct isis_area *area, int level, u_char *sysid)
{
  struct isis_lsp *lsp;
  u_char lspid[ISIS_SYS_ID_LEN + 2];

  memcpy (lspid, sysid, ISIS_SYS_ID_LEN);
  LSP_PSEUDO_ID (lspid) = 0;
  LSP_FRAGMENT (lspid) = 0;
  lsp = lsp_search (lspid, area->lspdb[level - 1]);
  if (lsp && lsp->lsp_header->rem_lifetime != 0)
    return lsp;
  return NULL;
}

/*
 * Add this IS to the root of SPT
 */
static struct isis_vertex *
isis_spf_add_root (struct isis_spftree *spftree, int level, u_char *sysid)
{
  struct isis_vertex *vertex;
  struct isis_lsp *lsp;
#ifdef EXTREME_DEBUG
  u_char buff[BUFSIZ];
#endif /* EXTREME_DEBUG */

  lsp = isis_root_system_lsp (spftree->area, level, sysid);
  if (lsp == NULL)
    zlog_warn ("ISIS-Spf: could not find own l%d LSP!", level);

  if (!spftree->area->oldmetric)
    vertex = isis_vertex_new (sysid, VTYPE_NONPSEUDO_TE_IS);
  else
    vertex = isis_vertex_new (sysid, VTYPE_NONPSEUDO_IS);

  listnode_add (spftree->paths, vertex);

#ifdef EXTREME_DEBUG
  zlog_debug ("ISIS-Spf: added this IS  %s %s depth %d dist %d to PATHS",
	      vtype2string (vertex->type), vid2string (vertex, buff),
	      vertex->depth, vertex->d_N);
#endif /* EXTREME_DEBUG */

  return vertex;
}

static struct isis_vertex *
isis_find_vertex (struct list *list, void *id, enum vertextype vtype)
{
  struct listnode *node;
  struct isis_vertex *vertex;
  struct prefix *p1, *p2;

  for (ALL_LIST_ELEMENTS_RO (list, node, vertex))
    {
      if (vertex->type != vtype)
	continue;
      switch (vtype)
	{
	case VTYPE_ES:
	case VTYPE_NONPSEUDO_IS:
	case VTYPE_NONPSEUDO_TE_IS:
	  if (memcmp ((u_char *) id, vertex->N.id, ISIS_SYS_ID_LEN) == 0)
	    return vertex;
	  break;
	case VTYPE_PSEUDO_IS:
	case VTYPE_PSEUDO_TE_IS:
	  if (memcmp ((u_char *) id, vertex->N.id, ISIS_SYS_ID_LEN + 1) == 0)
	    return vertex;
	  break;
	case VTYPE_IPREACH_INTERNAL:
	case VTYPE_IPREACH_EXTERNAL:
	case VTYPE_IPREACH_TE:
#ifdef HAVE_IPV6
	case VTYPE_IP6REACH_INTERNAL:
	case VTYPE_IP6REACH_EXTERNAL:
#endif /* HAVE_IPV6 */
	  p1 = (struct prefix *) id;
	  p2 = (struct prefix *) &vertex->N.id;
	  if (p1->family == p2->family && p1->prefixlen == p2->prefixlen &&
	      memcmp (&p1->u.prefix, &p2->u.prefix,
		      PSIZE (p1->prefixlen)) == 0)
	    return vertex;
	  break;
	}
    }

  return NULL;
}

/*
 * Add a vertex to TENT sorted by cost and by vertextype on tie break situation
 */
static struct isis_vertex *
isis_spf_add2tent (struct isis_spftree *spftree, enum vertextype vtype,
		   void *id, uint32_t cost, int depth, int family,
		   struct isis_adjacency *adj, struct isis_vertex *parent)
{
  struct isis_vertex *vertex, *v;
  struct listnode *node;
  struct isis_adjacency *parent_adj;
#ifdef EXTREME_DEBUG
  u_char buff[BUFSIZ];
#endif

  assert (isis_find_vertex (spftree->paths, id, vtype) == NULL);
  assert (isis_find_vertex (spftree->tents, id, vtype) == NULL);
  vertex = isis_vertex_new (id, vtype);
  vertex->d_N = cost;
  vertex->depth = depth;

  if (parent) {
    listnode_add (vertex->parents, parent);
    if (listnode_lookup (parent->children, vertex) == NULL)
      listnode_add (parent->children, vertex);
  }

  if (parent && parent->Adj_N && listcount(parent->Adj_N) > 0) {
    for (ALL_LIST_ELEMENTS_RO (parent->Adj_N, node, parent_adj))
      listnode_add (vertex->Adj_N, parent_adj);
  } else if (adj) {
    listnode_add (vertex->Adj_N, adj);
  }

#ifdef EXTREME_DEBUG
  zlog_debug ("ISIS-Spf: add to TENT %s %s %s depth %d dist %d adjcount %d",
              print_sys_hostname (vertex->N.id),
	      vtype2string (vertex->type), vid2string (vertex, buff),
	      vertex->depth, vertex->d_N, listcount(vertex->Adj_N));
#endif /* EXTREME_DEBUG */

  if (list_isempty (spftree->tents))
    {
      listnode_add (spftree->tents, vertex);
      return vertex;
    }

  /* XXX: This cant use the standard ALL_LIST_ELEMENTS macro */
  for (node = listhead (spftree->tents); node; node = listnextnode (node))
    {
      v = listgetdata (node);
      if (v->d_N > vertex->d_N)
	{
	  list_add_node_prev (spftree->tents, node, vertex);
	  break;
	}
      else if (v->d_N == vertex->d_N && v->type > vertex->type)
	{
	  /*  Tie break, add according to type */
          list_add_node_prev (spftree->tents, node, vertex);
	  break;
	}
    }

  if (node == NULL)
      listnode_add (spftree->tents, vertex);

  return vertex;
}

static void
isis_spf_add_local (struct isis_spftree *spftree, enum vertextype vtype,
		    void *id, struct isis_adjacency *adj, uint32_t cost,
		    int family, struct isis_vertex *parent)
{
  struct isis_vertex *vertex;

  vertex = isis_find_vertex (spftree->tents, id, vtype);

  if (vertex)
    {
      /* C.2.5   c) */
      if (vertex->d_N == cost)
	{
	  if (adj)
	    listnode_add (vertex->Adj_N, adj);
	  /*       d) */
	  if (listcount (vertex->Adj_N) > ISIS_MAX_PATH_SPLITS)
	    remove_excess_adjs (vertex->Adj_N);
	  if (parent && (listnode_lookup (vertex->parents, parent) == NULL))
	    listnode_add (vertex->parents, parent);
	  if (parent && (listnode_lookup (parent->children, vertex) == NULL))
	    listnode_add (parent->children, vertex);
	  return;
	}
      else if (vertex->d_N < cost)
	{
	  /*       e) do nothing */
	  return;
	}
      else {  /* vertex->d_N > cost */
	  /*         f) */
	  struct listnode *pnode, *pnextnode;
	  struct isis_vertex *pvertex;
	  listnode_delete (spftree->tents, vertex);
	  assert (listcount (vertex->children) == 0);
	  for (ALL_LIST_ELEMENTS (vertex->parents, pnode, pnextnode, pvertex))
	    listnode_delete(pvertex->children, vertex);
	  isis_vertex_del (vertex);
      }
    }

  isis_spf_add2tent (spftree, vtype, id, cost, 1, family, adj, parent);
  return;
}

static void
process_N (struct isis_spftree *spftree, enum vertextype vtype, void *id,
	   uint32_t dist, uint16_t depth, int family,
	   struct isis_vertex *parent)
{
  struct isis_vertex *vertex;
#ifdef EXTREME_DEBUG
  u_char buff[255];
#endif

  assert (spftree && parent);

  /* RFC3787 section 5.1 */
  if (spftree->area->newmetric == 1)
    {
      if (dist > MAX_WIDE_PATH_METRIC)
        return;
    }
  /* C.2.6 b)    */
  else if (spftree->area->oldmetric == 1)
    {
      if (dist > MAX_NARROW_PATH_METRIC)
        return;
    }

  /*       c)    */
  vertex = isis_find_vertex (spftree->paths, id, vtype);
  if (vertex)
    {
#ifdef EXTREME_DEBUG
      zlog_debug ("ISIS-Spf: process_N %s %s %s dist %d already found from PATH",
	          print_sys_hostname (vertex->N.id),
		  vtype2string (vtype), vid2string (vertex, buff), dist);
#endif /* EXTREME_DEBUG */
      assert (dist >= vertex->d_N);
      return;
    }

  vertex = isis_find_vertex (spftree->tents, id, vtype);
  /*       d)    */
  if (vertex)
    {
      /*        1) */
#ifdef EXTREME_DEBUG
      zlog_debug ("ISIS-Spf: process_N %s %s %s dist %d parent %s adjcount %d",
	          print_sys_hostname (vertex->N.id),
                  vtype2string (vtype), vid2string (vertex, buff), dist,
                  (parent ? print_sys_hostname (parent->N.id) : "null"),
                  (parent ? listcount (parent->Adj_N) : 0));
#endif /* EXTREME_DEBUG */
      if (vertex->d_N == dist)
	{
	  struct listnode *node;
	  struct isis_adjacency *parent_adj;
	  for (ALL_LIST_ELEMENTS_RO (parent->Adj_N, node, parent_adj))
	    if (listnode_lookup(vertex->Adj_N, parent_adj) == NULL)
	      listnode_add (vertex->Adj_N, parent_adj);
	  /*      2) */
	  if (listcount (vertex->Adj_N) > ISIS_MAX_PATH_SPLITS)
	    remove_excess_adjs (vertex->Adj_N);
	  if (listnode_lookup (vertex->parents, parent) == NULL)
	    listnode_add (vertex->parents, parent);
	  if (listnode_lookup (parent->children, vertex) == NULL)
	    listnode_add (parent->children, vertex);
	  /*      3) */
	  return;
	}
      else if (vertex->d_N < dist)
	{
	  return;
	  /*      4) */
	}
      else
	{
	  struct listnode *pnode, *pnextnode;
	  struct isis_vertex *pvertex;
	  listnode_delete (spftree->tents, vertex);
	  assert (listcount (vertex->children) == 0);
	  for (ALL_LIST_ELEMENTS (vertex->parents, pnode, pnextnode, pvertex))
	    listnode_delete(pvertex->children, vertex);
	  isis_vertex_del (vertex);
	}
    }

#ifdef EXTREME_DEBUG
  zlog_debug ("ISIS-Spf: process_N add2tent %s %s dist %d parent %s",
              print_sys_hostname(id), vtype2string (vtype), dist,
              (parent ? print_sys_hostname (parent->N.id) : "null"));
#endif /* EXTREME_DEBUG */

  isis_spf_add2tent (spftree, vtype, id, dist, depth, family, NULL, parent);
  return;
}

/*
 * C.2.6 Step 1
 */
static int
isis_spf_process_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp,
		      uint32_t cost, uint16_t depth, int family,
		      u_char *root_sysid, struct isis_vertex *parent)
{
  struct listnode *node, *fragnode = NULL;
  uint32_t dist;
  struct is_neigh *is_neigh;
  struct te_is_neigh *te_is_neigh;
  struct ipv4_reachability *ipreach;
  struct te_ipv4_reachability *te_ipv4_reach;
  enum vertextype vtype;
  struct prefix prefix;
#ifdef HAVE_IPV6
  struct ipv6_reachability *ip6reach;
#endif /* HAVE_IPV6 */
  static const u_char null_sysid[ISIS_SYS_ID_LEN];

  if (!speaks (lsp->tlv_data.nlpids, family))
    return ISIS_OK;

lspfragloop:
  if (lsp->lsp_header->seq_num == 0)
    {
      zlog_warn ("isis_spf_process_lsp(): lsp with 0 seq_num - ignore");
      return ISIS_WARNING;
    }

#ifdef EXTREME_DEBUG
      zlog_debug ("ISIS-Spf: process_lsp %s", print_sys_hostname(lsp->lsp_header->lsp_id));
#endif /* EXTREME_DEBUG */

  if (!ISIS_MASK_LSP_OL_BIT (lsp->lsp_header->lsp_bits))
  {
    if (lsp->tlv_data.is_neighs)
    {
      for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, node, is_neigh))
      {
        /* C.2.6 a) */
        /* Two way connectivity */
        if (!memcmp (is_neigh->neigh_id, root_sysid, ISIS_SYS_ID_LEN))
          continue;
        if (!memcmp (is_neigh->neigh_id, null_sysid, ISIS_SYS_ID_LEN))
          continue;
        dist = cost + is_neigh->metrics.metric_default;
        vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS
          : VTYPE_NONPSEUDO_IS;
        process_N (spftree, vtype, (void *) is_neigh->neigh_id, dist,
            depth + 1, family, parent);
      }
    }
    if (lsp->tlv_data.te_is_neighs)
    {
      for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, node,
            te_is_neigh))
      {
        if (!memcmp (te_is_neigh->neigh_id, root_sysid, ISIS_SYS_ID_LEN))
          continue;
        if (!memcmp (te_is_neigh->neigh_id, null_sysid, ISIS_SYS_ID_LEN))
          continue;
        dist = cost + GET_TE_METRIC(te_is_neigh);
        vtype = LSP_PSEUDO_ID (te_is_neigh->neigh_id) ? VTYPE_PSEUDO_TE_IS
          : VTYPE_NONPSEUDO_TE_IS;
        process_N (spftree, vtype, (void *) te_is_neigh->neigh_id, dist,
            depth + 1, family, parent);
      }
    }
  }

  if (family == AF_INET && lsp->tlv_data.ipv4_int_reachs)
  {
    prefix.family = AF_INET;
    for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, node, ipreach))
    {
      dist = cost + ipreach->metrics.metric_default;
      vtype = VTYPE_IPREACH_INTERNAL;
      prefix.u.prefix4 = ipreach->prefix;
      prefix.prefixlen = ip_masklen (ipreach->mask);
      apply_mask (&prefix);
      process_N (spftree, vtype, (void *) &prefix, dist, depth + 1,
                 family, parent);
    }
  }
  if (family == AF_INET && lsp->tlv_data.ipv4_ext_reachs)
  {
    prefix.family = AF_INET;
    for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, node, ipreach))
    {
      dist = cost + ipreach->metrics.metric_default;
      vtype = VTYPE_IPREACH_EXTERNAL;
      prefix.u.prefix4 = ipreach->prefix;
      prefix.prefixlen = ip_masklen (ipreach->mask);
      apply_mask (&prefix);
      process_N (spftree, vtype, (void *) &prefix, dist, depth + 1,
                 family, parent);
    }
  }
  if (family == AF_INET && lsp->tlv_data.te_ipv4_reachs)
  {
    prefix.family = AF_INET;
    for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs,
                               node, te_ipv4_reach))
    {
      assert ((te_ipv4_reach->control & 0x3F) <= IPV4_MAX_BITLEN);

      dist = cost + ntohl (te_ipv4_reach->te_metric);
      vtype = VTYPE_IPREACH_TE;
      prefix.u.prefix4 = newprefix2inaddr (&te_ipv4_reach->prefix_start,
                                           te_ipv4_reach->control);
      prefix.prefixlen = (te_ipv4_reach->control & 0x3F);
      apply_mask (&prefix);
      process_N (spftree, vtype, (void *) &prefix, dist, depth + 1,
                 family, parent);
    }
  }
#ifdef HAVE_IPV6
  if (family == AF_INET6 && lsp->tlv_data.ipv6_reachs)
  {
    prefix.family = AF_INET6;
    for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, node, ip6reach))
    {
      assert (ip6reach->prefix_len <= IPV6_MAX_BITLEN);

      dist = cost + ntohl(ip6reach->metric);
      vtype = (ip6reach->control_info & CTRL_INFO_DISTRIBUTION) ?
        VTYPE_IP6REACH_EXTERNAL : VTYPE_IP6REACH_INTERNAL;
      prefix.prefixlen = ip6reach->prefix_len;
      memcpy (&prefix.u.prefix6.s6_addr, ip6reach->prefix,
              PSIZE (ip6reach->prefix_len));
      apply_mask (&prefix);
      process_N (spftree, vtype, (void *) &prefix, dist, depth + 1,
                 family, parent);
    }
  }
#endif /* HAVE_IPV6 */

  if (fragnode == NULL)
    fragnode = listhead (lsp->lspu.frags);
  else
    fragnode = listnextnode (fragnode);

  if (fragnode)
    {
      lsp = listgetdata (fragnode);
      goto lspfragloop;
    }

  return ISIS_OK;
}

static int
isis_spf_process_pseudo_lsp (struct isis_spftree *spftree,
			     struct isis_lsp *lsp, uint32_t cost,
			     uint16_t depth, int family,
			     u_char *root_sysid,
			     struct isis_vertex *parent)
{
  struct listnode *node, *fragnode = NULL;
  struct is_neigh *is_neigh;
  struct te_is_neigh *te_is_neigh;
  enum vertextype vtype;
  uint32_t dist;

pseudofragloop:

  if (lsp->lsp_header->seq_num == 0)
    {
      zlog_warn ("isis_spf_process_pseudo_lsp(): lsp with 0 seq_num"
		 " - do not process");
      return ISIS_WARNING;
    }

#ifdef EXTREME_DEBUG
      zlog_debug ("ISIS-Spf: process_pseudo_lsp %s",
                  print_sys_hostname(lsp->lsp_header->lsp_id));
#endif /* EXTREME_DEBUG */

  /* RFC3787 section 4 SHOULD ignore overload bit in pseudo LSPs */

  if (lsp->tlv_data.is_neighs)
    for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, node, is_neigh))
      {
	/* Two way connectivity */
	if (!memcmp (is_neigh->neigh_id, root_sysid, ISIS_SYS_ID_LEN))
	  continue;
        dist = cost + is_neigh->metrics.metric_default;
        vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS
          : VTYPE_NONPSEUDO_IS;
        process_N (spftree, vtype, (void *) is_neigh->neigh_id, dist,
            depth + 1, family, parent);
      }
  if (lsp->tlv_data.te_is_neighs)
    for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, node, te_is_neigh))
      {
	/* Two way connectivity */
	if (!memcmp (te_is_neigh->neigh_id, root_sysid, ISIS_SYS_ID_LEN))
	  continue;
        dist = cost + GET_TE_METRIC(te_is_neigh);
        vtype = LSP_PSEUDO_ID (te_is_neigh->neigh_id) ? VTYPE_PSEUDO_TE_IS
          : VTYPE_NONPSEUDO_TE_IS;
        process_N (spftree, vtype, (void *) te_is_neigh->neigh_id, dist,
            depth + 1, family, parent);
      }

  if (fragnode == NULL)
    fragnode = listhead (lsp->lspu.frags);
  else
    fragnode = listnextnode (fragnode);

  if (fragnode)
    {
      lsp = listgetdata (fragnode);
      goto pseudofragloop;
    }

  return ISIS_OK;
}

static int
isis_spf_preload_tent (struct isis_spftree *spftree, int level,
		       int family, u_char *root_sysid,
		       struct isis_vertex *parent)
{
  struct isis_circuit *circuit;
  struct listnode *cnode, *anode, *ipnode;
  struct isis_adjacency *adj;
  struct isis_lsp *lsp;
  struct list *adj_list;
  struct list *adjdb;
  struct prefix_ipv4 *ipv4;
  struct prefix prefix;
  int retval = ISIS_OK;
  u_char lsp_id[ISIS_SYS_ID_LEN + 2];
  static u_char null_lsp_id[ISIS_SYS_ID_LEN + 2];
#ifdef HAVE_IPV6
  struct prefix_ipv6 *ipv6;
#endif /* HAVE_IPV6 */

  for (ALL_LIST_ELEMENTS_RO (spftree->area->circuit_list, cnode, circuit))
    {
      if (circuit->state != C_STATE_UP)
	continue;
      if (!(circuit->is_type & level))
	continue;
      if (family == AF_INET && !circuit->ip_router)
	continue;
#ifdef HAVE_IPV6
      if (family == AF_INET6 && !circuit->ipv6_router)
	continue;
#endif /* HAVE_IPV6 */
      /* 
       * Add IP(v6) addresses of this circuit
       */
      if (family == AF_INET)
	{
	  prefix.family = AF_INET;
          for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
	    {
	      prefix.u.prefix4 = ipv4->prefix;
	      prefix.prefixlen = ipv4->prefixlen;
              apply_mask (&prefix);
	      isis_spf_add_local (spftree, VTYPE_IPREACH_INTERNAL, &prefix,
				  NULL, 0, family, parent);
	    }
	}
#ifdef HAVE_IPV6
      if (family == AF_INET6)
	{
	  prefix.family = AF_INET6;
	  for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
	    {
	      prefix.prefixlen = ipv6->prefixlen;
	      prefix.u.prefix6 = ipv6->prefix;
              apply_mask (&prefix);
	      isis_spf_add_local (spftree, VTYPE_IP6REACH_INTERNAL,
				  &prefix, NULL, 0, family, parent);
	    }
	}
#endif /* HAVE_IPV6 */
      if (circuit->circ_type == CIRCUIT_T_BROADCAST)
	{
	  /*
	   * Add the adjacencies
	   */
	  adj_list = list_new ();
	  adjdb = circuit->u.bc.adjdb[level - 1];
	  isis_adj_build_up_list (adjdb, adj_list);
	  if (listcount (adj_list) == 0)
	    {
	      list_delete (adj_list);
	      if (isis->debugs & DEBUG_SPF_EVENTS)
		zlog_debug ("ISIS-Spf: no L%d adjacencies on circuit %s",
			    level, circuit->interface->name);
	      continue;
	    }
          for (ALL_LIST_ELEMENTS_RO (adj_list, anode, adj))
	    {
	      if (!speaks (&adj->nlpids, family))
		  continue;
	      switch (adj->sys_type)
		{
		case ISIS_SYSTYPE_ES:
		  isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj,
				      circuit->te_metric[level - 1],
				      family, parent);
		  break;
		case ISIS_SYSTYPE_IS:
		case ISIS_SYSTYPE_L1_IS:
		case ISIS_SYSTYPE_L2_IS:
		  isis_spf_add_local (spftree,
                                      spftree->area->oldmetric ?
                                      VTYPE_NONPSEUDO_IS :
                                      VTYPE_NONPSEUDO_TE_IS,
                                      adj->sysid, adj,
                                      circuit->te_metric[level - 1],
                                      family, parent);
		  memcpy (lsp_id, adj->sysid, ISIS_SYS_ID_LEN);
		  LSP_PSEUDO_ID (lsp_id) = 0;
		  LSP_FRAGMENT (lsp_id) = 0;
		  lsp = lsp_search (lsp_id, spftree->area->lspdb[level - 1]);
                  if (lsp == NULL || lsp->lsp_header->rem_lifetime == 0)
                    zlog_warn ("ISIS-Spf: No LSP %s found for IS adjacency "
                        "L%d on %s (ID %u)",
			rawlspid_print (lsp_id), level,
			circuit->interface->name, circuit->circuit_id);
		  break;
		case ISIS_SYSTYPE_UNKNOWN:
		default:
		  zlog_warn ("isis_spf_preload_tent unknow adj type");
		}
	    }
	  list_delete (adj_list);
	  /*
	   * Add the pseudonode 
	   */
	  if (level == 1)
	    memcpy (lsp_id, circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
	  else
	    memcpy (lsp_id, circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
	  /* can happen during DR reboot */
	  if (memcmp (lsp_id, null_lsp_id, ISIS_SYS_ID_LEN + 1) == 0)
	    {
	      if (isis->debugs & DEBUG_SPF_EVENTS)
		zlog_debug ("ISIS-Spf: No L%d DR on %s (ID %d)",
		    level, circuit->interface->name, circuit->circuit_id);
	      continue;
	    }
	  adj = isis_adj_lookup (lsp_id, adjdb);
	  /* if no adj, we are the dis or error */
	  if (!adj && !circuit->u.bc.is_dr[level - 1])
	    {
              zlog_warn ("ISIS-Spf: No adjacency found from root "
                  "to L%d DR %s on %s (ID %d)",
		  level, rawlspid_print (lsp_id),
		  circuit->interface->name, circuit->circuit_id);
              continue;
	    }
	  lsp = lsp_search (lsp_id, spftree->area->lspdb[level - 1]);
	  if (lsp == NULL || lsp->lsp_header->rem_lifetime == 0)
	    {
	      zlog_warn ("ISIS-Spf: No lsp (%p) found from root "
                  "to L%d DR %s on %s (ID %d)",
                  (void *)lsp, level, rawlspid_print (lsp_id),
                  circuit->interface->name, circuit->circuit_id);
              continue;
	    }
	  isis_spf_process_pseudo_lsp (spftree, lsp,
                                       circuit->te_metric[level - 1], 0,
                                       family, root_sysid, parent);
	}
      else if (circuit->circ_type == CIRCUIT_T_P2P)
	{
	  adj = circuit->u.p2p.neighbor;
	  if (!adj)
	    continue;
	  switch (adj->sys_type)
	    {
	    case ISIS_SYSTYPE_ES:
	      isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj,
				  circuit->te_metric[level - 1], family,
				  parent);
	      break;
	    case ISIS_SYSTYPE_IS:
	    case ISIS_SYSTYPE_L1_IS:
	    case ISIS_SYSTYPE_L2_IS:
	      if (speaks (&adj->nlpids, family))
		isis_spf_add_local (spftree,
				    spftree->area->oldmetric ?
                                    VTYPE_NONPSEUDO_IS :
				    VTYPE_NONPSEUDO_TE_IS,
                                    adj->sysid,
				    adj, circuit->te_metric[level - 1],
				    family, parent);
	      break;
	    case ISIS_SYSTYPE_UNKNOWN:
	    default:
	      zlog_warn ("isis_spf_preload_tent unknown adj type");
	      break;
	    }
	}
      else if (circuit->circ_type == CIRCUIT_T_LOOPBACK)
	{
          continue;
        }
      else
	{
	  zlog_warn ("isis_spf_preload_tent unsupported media");
	  retval = ISIS_WARNING;
	}
    }

  return retval;
}

/*
 * The parent(s) for vertex is set when added to TENT list
 * now we just put the child pointer(s) in place
 */
static void
add_to_paths (struct isis_spftree *spftree, struct isis_vertex *vertex,
	      int level)
{
  u_char buff[BUFSIZ];

  if (isis_find_vertex (spftree->paths, vertex->N.id, vertex->type))
    return;
  listnode_add (spftree->paths, vertex);

#ifdef EXTREME_DEBUG
  zlog_debug ("ISIS-Spf: added %s %s %s depth %d dist %d to PATHS",
              print_sys_hostname (vertex->N.id),
	      vtype2string (vertex->type), vid2string (vertex, buff),
	      vertex->depth, vertex->d_N);
#endif /* EXTREME_DEBUG */

  if (vertex->type > VTYPE_ES)
    {
      if (listcount (vertex->Adj_N) > 0)
	isis_route_create ((struct prefix *) &vertex->N.prefix, vertex->d_N,
			   vertex->depth, vertex->Adj_N, spftree->area, level);
      else if (isis->debugs & DEBUG_SPF_EVENTS)
	zlog_debug ("ISIS-Spf: no adjacencies do not install route for "
                    "%s depth %d dist %d", vid2string (vertex, buff),
                    vertex->depth, vertex->d_N);
    }

  return;
}

static void
init_spt (struct isis_spftree *spftree)
{
  spftree->tents->del = spftree->paths->del = (void (*)(void *)) isis_vertex_del;
  list_delete_all_node (spftree->tents);
  list_delete_all_node (spftree->paths);
  spftree->tents->del = spftree->paths->del = NULL;
  return;
}

static int
isis_run_spf (struct isis_area *area, int level, int family, u_char *sysid)
{
  int retval = ISIS_OK;
  struct listnode *node;
  struct isis_vertex *vertex;
  struct isis_vertex *root_vertex;
  struct isis_spftree *spftree = NULL;
  u_char lsp_id[ISIS_SYS_ID_LEN + 2];
  struct isis_lsp *lsp;
  struct route_table *table = NULL;
  struct timeval time_now;
  unsigned long long start_time, end_time;

  /* Get time that can't roll backwards. */
  quagga_gettime(QUAGGA_CLK_MONOTONIC, &time_now);
  start_time = time_now.tv_sec;
  start_time = (start_time * 1000000) + time_now.tv_usec;

  if (family == AF_INET)
    spftree = area->spftree[level - 1];
#ifdef HAVE_IPV6
  else if (family == AF_INET6)
    spftree = area->spftree6[level - 1];
#endif
  assert (spftree);
  assert (sysid);

  /* Make all routes in current route table inactive. */
  if (family == AF_INET)
    table = area->route_table[level - 1];
#ifdef HAVE_IPV6
  else if (family == AF_INET6)
    table = area->route_table6[level - 1];
#endif

  isis_route_invalidate_table (area, table);

  /*
   * C.2.5 Step 0
   */
  init_spt (spftree);
  /*              a) */
  root_vertex = isis_spf_add_root (spftree, level, sysid);
  /*              b) */
  retval = isis_spf_preload_tent (spftree, level, family, sysid, root_vertex);
  if (retval != ISIS_OK)
    {
      zlog_warn ("ISIS-Spf: failed to load TENT SPF-root:%s", print_sys_hostname(sysid));
      goto out;
    }

  /*
   * C.2.7 Step 2
   */
  if (listcount (spftree->tents) == 0)
    {
      zlog_warn ("ISIS-Spf: TENT is empty SPF-root:%s", print_sys_hostname(sysid));
      goto out;
    }

  while (listcount (spftree->tents) > 0)
    {
      node = listhead (spftree->tents);
      vertex = listgetdata (node);

#ifdef EXTREME_DEBUG
  zlog_debug ("ISIS-Spf: get TENT node %s %s depth %d dist %d to PATHS",
              print_sys_hostname (vertex->N.id),
	      vtype2string (vertex->type), vertex->depth, vertex->d_N);
#endif /* EXTREME_DEBUG */

      /* Remove from tent list and add to paths list */
      list_delete_node (spftree->tents, node);
      add_to_paths (spftree, vertex, level);
      switch (vertex->type)
        {
	case VTYPE_PSEUDO_IS:
	case VTYPE_NONPSEUDO_IS:
	case VTYPE_PSEUDO_TE_IS:
	case VTYPE_NONPSEUDO_TE_IS:
	  memcpy (lsp_id, vertex->N.id, ISIS_SYS_ID_LEN + 1);
	  LSP_FRAGMENT (lsp_id) = 0;
	  lsp = lsp_search (lsp_id, area->lspdb[level - 1]);
	  if (lsp && lsp->lsp_header->rem_lifetime != 0)
	    {
	      if (LSP_PSEUDO_ID (lsp_id))
		{
		  isis_spf_process_pseudo_lsp (spftree, lsp, vertex->d_N,
					       vertex->depth, family, sysid,
					       vertex);
		}
	      else
		{
		  isis_spf_process_lsp (spftree, lsp, vertex->d_N,
					vertex->depth, family, sysid, vertex);
		}
	    }
	  else
	    {
	      zlog_warn ("ISIS-Spf: No LSP found for %s",
			 rawlspid_print (lsp_id));
	    }
	  break;
	default:;
	}
    }

out:
  isis_route_validate (area);
  spftree->pending = 0;
  spftree->runcount++;
  spftree->last_run_timestamp = time (NULL);
  quagga_gettime(QUAGGA_CLK_MONOTONIC, &time_now);
  end_time = time_now.tv_sec;
  end_time = (end_time * 1000000) + time_now.tv_usec;
  spftree->last_run_duration = end_time - start_time;


  return retval;
}

int
isis_run_spf_l1 (struct thread *thread)
{
  struct isis_area *area;
  int retval = ISIS_OK;

  area = THREAD_ARG (thread);
  assert (area);

  area->spftree[0]->t_spf = NULL;
  area->spftree[0]->pending = 0;

  if (!(area->is_type & IS_LEVEL_1))
    {
      if (isis->debugs & DEBUG_SPF_EVENTS)
	zlog_warn ("ISIS-SPF (%s) area does not share level",
		   area->area_tag);
      return ISIS_WARNING;
    }

  if (isis->debugs & DEBUG_SPF_EVENTS)
    zlog_debug ("ISIS-Spf (%s) L1 SPF needed, periodic SPF", area->area_tag);

  if (area->ip_circuits)
    retval = isis_run_spf (area, 1, AF_INET, isis->sysid);

  return retval;
}

int
isis_run_spf_l2 (struct thread *thread)
{
  struct isis_area *area;
  int retval = ISIS_OK;

  area = THREAD_ARG (thread);
  assert (area);

  area->spftree[1]->t_spf = NULL;
  area->spftree[1]->pending = 0;

  if (!(area->is_type & IS_LEVEL_2))
    {
      if (isis->debugs & DEBUG_SPF_EVENTS)
	zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag);
      return ISIS_WARNING;
    }

  if (isis->debugs & DEBUG_SPF_EVENTS)
    zlog_debug ("ISIS-Spf (%s) L2 SPF needed, periodic SPF", area->area_tag);

  if (area->ip_circuits)
    retval = isis_run_spf (area, 2, AF_INET, isis->sysid);

  return retval;
}

int
isis_spf_schedule (struct isis_area *area, int level)
{
  struct isis_spftree *spftree = area->spftree[level - 1];
  time_t now = time (NULL);
  int diff = now - spftree->last_run_timestamp;

  assert (diff >= 0);
  assert (area->is_type & level);

  if (isis->debugs & DEBUG_SPF_EVENTS)
    zlog_debug ("ISIS-Spf (%s) L%d SPF schedule called, lastrun %d sec ago",
                area->area_tag, level, diff);

  if (spftree->pending)
    return ISIS_OK;

  THREAD_TIMER_OFF (spftree->t_spf);

  /* wait configured min_spf_interval before doing the SPF */
  if (diff >= area->min_spf_interval[level-1])
      return isis_run_spf (area, level, AF_INET, isis->sysid);

  if (level == 1)
    THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l1, area,
                     area->min_spf_interval[0] - diff);
  else
    THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l2, area,
                     area->min_spf_interval[1] - diff);

  if (isis->debugs & DEBUG_SPF_EVENTS)
    zlog_debug ("ISIS-Spf (%s) L%d SPF scheduled %d sec from now",
                area->area_tag, level, area->min_spf_interval[level-1] - diff);

  spftree->pending = 1;

  return ISIS_OK;
}

#ifdef HAVE_IPV6
static int
isis_run_spf6_l1 (struct thread *thread)
{
  struct isis_area *area;
  int retval = ISIS_OK;

  area = THREAD_ARG (thread);
  assert (area);

  area->spftree6[0]->t_spf = NULL;
  area->spftree6[0]->pending = 0;

  if (!(area->is_type & IS_LEVEL_1))
    {
      if (isis->debugs & DEBUG_SPF_EVENTS)
        zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag);
      return ISIS_WARNING;
    }

  if (isis->debugs & DEBUG_SPF_EVENTS)
    zlog_debug ("ISIS-Spf (%s) L1 SPF needed, periodic SPF", area->area_tag);

  if (area->ipv6_circuits)
    retval = isis_run_spf (area, 1, AF_INET6, isis->sysid);

  return retval;
}

static int
isis_run_spf6_l2 (struct thread *thread)
{
  struct isis_area *area;
  int retval = ISIS_OK;

  area = THREAD_ARG (thread);
  assert (area);

  area->spftree6[1]->t_spf = NULL;
  area->spftree6[1]->pending = 0;

  if (!(area->is_type & IS_LEVEL_2))
    {
      if (isis->debugs & DEBUG_SPF_EVENTS)
        zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag);
      return ISIS_WARNING;
    }

  if (isis->debugs & DEBUG_SPF_EVENTS)
    zlog_debug ("ISIS-Spf (%s) L2 SPF needed, periodic SPF.", area->area_tag);

  if (area->ipv6_circuits)
    retval = isis_run_spf (area, 2, AF_INET6, isis->sysid);

  return retval;
}

int
isis_spf_schedule6 (struct isis_area *area, int level)
{
  int retval = ISIS_OK;
  struct isis_spftree *spftree = area->spftree6[level - 1];
  time_t now = time (NULL);
  time_t diff = now - spftree->last_run_timestamp;

  assert (diff >= 0);
  assert (area->is_type & level);

  if (isis->debugs & DEBUG_SPF_EVENTS)
    zlog_debug ("ISIS-Spf (%s) L%d SPF schedule called, lastrun %lld sec ago",
                area->area_tag, level, (long long)diff);

  if (spftree->pending)
    return ISIS_OK;

  THREAD_TIMER_OFF (spftree->t_spf);

  /* wait configured min_spf_interval before doing the SPF */
  if (diff >= area->min_spf_interval[level-1])
      return isis_run_spf (area, level, AF_INET6, isis->sysid);

  if (level == 1)
    THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l1, area,
                     area->min_spf_interval[0] - diff);
  else
    THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l2, area,
                     area->min_spf_interval[1] - diff);

  if (isis->debugs & DEBUG_SPF_EVENTS)
    zlog_debug ("ISIS-Spf (%s) L%d SPF scheduled %lld sec from now",
                area->area_tag, level,
                (long long)(area->min_spf_interval[level-1] - diff));

  spftree->pending = 1;

  return retval;
}
#endif

static void
isis_print_paths (struct vty *vty, struct list *paths, u_char *root_sysid)
{
  struct listnode *node;
  struct listnode *anode;
  struct isis_vertex *vertex;
  struct isis_adjacency *adj;
  u_char buff[BUFSIZ];

  vty_out (vty, "Vertex               Type         Metric "
                "Next-Hop             Interface Parent%s", VTY_NEWLINE);

  for (ALL_LIST_ELEMENTS_RO (paths, node, vertex)) {
      if (memcmp (vertex->N.id, root_sysid, ISIS_SYS_ID_LEN) == 0) {
	vty_out (vty, "%-20s %-12s %-6s", print_sys_hostname (root_sysid),
	         "", "");
	vty_out (vty, "%-30s", "");
      } else {
	int rows = 0;
	vty_out (vty, "%-20s %-12s %-6u ", vid2string (vertex, buff),
	         vtype2string (vertex->type), vertex->d_N);
	for (ALL_LIST_ELEMENTS_RO (vertex->Adj_N, anode, adj)) {
	  if (adj) {
	    if (rows) {
		vty_out (vty, "%s", VTY_NEWLINE);
		vty_out (vty, "%-20s %-12s %-6s ", "", "", "");
	    }
	    vty_out (vty, "%-20s %-9s ",
		     print_sys_hostname (adj->sysid),
		     adj->circuit->interface->name);
	    ++rows;
	  }
	}
	if (rows == 0)
	  vty_out (vty, "%-30s ", "");
      }

      /* Print list of parents for the ECMP DAG */
      if (listcount (vertex->parents) > 0) {
	struct listnode *pnode;
	struct isis_vertex *pvertex;
	int rows = 0;
	for (ALL_LIST_ELEMENTS_RO (vertex->parents, pnode, pvertex)) {
	  if (rows) {
	    vty_out (vty, "%s", VTY_NEWLINE);
	    vty_out (vty, "%-72s", "");
	  }
	  vty_out (vty, "%s(%d)",
	           vid2string (pvertex, buff), pvertex->type);
	  ++rows;
	}
      } else {
	vty_out (vty, "  NULL ");
      }

#if 0
      if (listcount (vertex->children) > 0) {
	  struct listnode *cnode;
	  struct isis_vertex *cvertex;
	  for (ALL_LIST_ELEMENTS_RO (vertex->children, cnode, cvertex)) {
	      vty_out (vty, "%s", VTY_NEWLINE);
	      vty_out (vty, "%-72s", "");
	      vty_out (vty, "%s(%d) ", 
	               vid2string (cvertex, buff), cvertex->type);
	    }
	}
#endif
      vty_out (vty, "%s", VTY_NEWLINE);
    }
}

DEFUN (show_isis_topology,
       show_isis_topology_cmd,
       "show isis topology",
       SHOW_STR
       "IS-IS information\n"
       "IS-IS paths to Intermediate Systems\n")
{
  struct listnode *node;
  struct isis_area *area;
  int level;

  if (!isis->area_list || isis->area_list->count == 0)
    return CMD_SUCCESS;

  for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area))
    {
      vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null",
	       VTY_NEWLINE);

      for (level = 0; level < ISIS_LEVELS; level++)
	{
	  if (area->ip_circuits > 0 && area->spftree[level]
	      && area->spftree[level]->paths->count > 0)
	    {
	      vty_out (vty, "IS-IS paths to level-%d routers that speak IP%s",
		       level + 1, VTY_NEWLINE);
	      isis_print_paths (vty, area->spftree[level]->paths, isis->sysid);
	      vty_out (vty, "%s", VTY_NEWLINE);
	    }
#ifdef HAVE_IPV6
	  if (area->ipv6_circuits > 0 && area->spftree6[level]
	      && area->spftree6[level]->paths->count > 0)
	    {
	      vty_out (vty,
		       "IS-IS paths to level-%d routers that speak IPv6%s",
		       level + 1, VTY_NEWLINE);
	      isis_print_paths (vty, area->spftree6[level]->paths, isis->sysid);
	      vty_out (vty, "%s", VTY_NEWLINE);
	    }
#endif /* HAVE_IPV6 */
	}

      vty_out (vty, "%s", VTY_NEWLINE);
    }

  return CMD_SUCCESS;
}

DEFUN (show_isis_topology_l1,
       show_isis_topology_l1_cmd,
       "show isis topology level-1",
       SHOW_STR
       "IS-IS information\n"
       "IS-IS paths to Intermediate Systems\n"
       "Paths to all level-1 routers in the area\n")
{
  struct listnode *node;
  struct isis_area *area;

  if (!isis->area_list || isis->area_list->count == 0)
    return CMD_SUCCESS;

  for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area))
    {
      vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null",
	       VTY_NEWLINE);

      if (area->ip_circuits > 0 && area->spftree[0]
	  && area->spftree[0]->paths->count > 0)
	{
	  vty_out (vty, "IS-IS paths to level-1 routers that speak IP%s",
		   VTY_NEWLINE);
	  isis_print_paths (vty, area->spftree[0]->paths, isis->sysid);
	  vty_out (vty, "%s", VTY_NEWLINE);
	}
#ifdef HAVE_IPV6
      if (area->ipv6_circuits > 0 && area->spftree6[0]
	  && area->spftree6[0]->paths->count > 0)
	{
	  vty_out (vty, "IS-IS paths to level-1 routers that speak IPv6%s",
		   VTY_NEWLINE);
	  isis_print_paths (vty, area->spftree6[0]->paths, isis->sysid);
	  vty_out (vty, "%s", VTY_NEWLINE);
	}
#endif /* HAVE_IPV6 */
      vty_out (vty, "%s", VTY_NEWLINE);
    }

  return CMD_SUCCESS;
}

DEFUN (show_isis_topology_l2,
       show_isis_topology_l2_cmd,
       "show isis topology level-2",
       SHOW_STR
       "IS-IS information\n"
       "IS-IS paths to Intermediate Systems\n"
       "Paths to all level-2 routers in the domain\n")
{
  struct listnode *node;
  struct isis_area *area;

  if (!isis->area_list || isis->area_list->count == 0)
    return CMD_SUCCESS;

  for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area))
    {
      vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null",
	       VTY_NEWLINE);

      if (area->ip_circuits > 0 && area->spftree[1]
	  && area->spftree[1]->paths->count > 0)
	{
	  vty_out (vty, "IS-IS paths to level-2 routers that speak IP%s",
		   VTY_NEWLINE);
	  isis_print_paths (vty, area->spftree[1]->paths, isis->sysid);
	  vty_out (vty, "%s", VTY_NEWLINE);
	}
#ifdef HAVE_IPV6
      if (area->ipv6_circuits > 0 && area->spftree6[1]
	  && area->spftree6[1]->paths->count > 0)
	{
	  vty_out (vty, "IS-IS paths to level-2 routers that speak IPv6%s",
		   VTY_NEWLINE);
	  isis_print_paths (vty, area->spftree6[1]->paths, isis->sysid);
	  vty_out (vty, "%s", VTY_NEWLINE);
	}
#endif /* HAVE_IPV6 */
      vty_out (vty, "%s", VTY_NEWLINE);
    }

  return CMD_SUCCESS;
}

void
isis_spf_cmds_init ()
{
  install_element (VIEW_NODE, &show_isis_topology_cmd);
  install_element (VIEW_NODE, &show_isis_topology_l1_cmd);
  install_element (VIEW_NODE, &show_isis_topology_l2_cmd);

  install_element (ENABLE_NODE, &show_isis_topology_cmd);
  install_element (ENABLE_NODE, &show_isis_topology_l1_cmd);
  install_element (ENABLE_NODE, &show_isis_topology_l2_cmd);
}
