/*
 * 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 <stdlib.h>
#include <stdio.h>
#include <zebra.h>
#include <net/ethernet.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 "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"

extern struct isis *isis;
extern struct thread_master *master;
extern struct host host;

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

/* performace issue ???? */
void
union_adjlist( struct list *target, struct list *source )
{
  struct isis_adjacency *adj, *adj2;
  struct listnode *node, *node2;
  
  zlog_info ("Union adjlist!");
  for (node = listhead (source); node; nextnode (node)) {
    adj = getdata (node);
    
    /* lookup adjacency in the source list */
    for (node2 = listhead (target); node2; nextnode (node2)) {
      adj2 = getdata(node2);
      if (adj == adj2) break;
    }
    
    if (!node2) listnode_add (target, adj);
  }
}


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

  for (node = listhead (adjs); node; nextnode (node)) {
    if (excess == NULL) 
      excess = node;
    candidate = getdata (excess);
    adj = getdata (node);
    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;
}

const char *
vtype2string (enum vertextype vtype)
{
  switch (vtype) {
  case  VTYPE_PSEUDO_IS:
    return "pseudo_IS";
    break;
  case VTYPE_NONPSEUDO_IS:
    return "IS";
    break;
  case VTYPE_ES:
    return "ES";
    break;
  case VTYPE_IPREACH_INTERNAL:
    return "IP internal";
    break;
  case VTYPE_IPREACH_EXTERNAL:
    return "IP external";
    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 */
}

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

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

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

  tree->tents = list_new ();
  tree->paths  = list_new ();
  return tree;
}

void
isis_vertex_del (struct isis_vertex *vertex)
{
  
  list_delete (vertex->Adj_N);

  XFREE (MTYPE_ISIS_VERTEX, vertex);
  
  return;
}

void
isis_spftree_del (struct isis_spftree *spftree)
{

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

  XFREE (MTYPE_ISIS_SPFTREE, spftree);

  return;
}

void 
spftree_area_init (struct isis_area *area)
{

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

    /*    thread_add_timer (master, isis_run_spf_l1, area, 
          isis_jitter (PERIODIC_SPF_INTERVAL, 10)); */
  }
  
  if ((area->is_type & IS_LEVEL_2) && area->spftree[1] == NULL) {
    area->spftree[1] = isis_spftree_new ();
#ifdef HAVE_IPV6
    area->spftree6[1] = isis_spftree_new ();
#endif
    /*    thread_add_timer (master, isis_run_spf_l2, area, 
          isis_jitter (PERIODIC_SPF_INTERVAL, 10)); */
  }

  return;
}

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

  vertex = XMALLOC (MTYPE_ISIS_VERTEX, sizeof (struct isis_vertex));
  if (vertex == NULL) {
    zlog_err ("isis_vertex_new Out of memory!");
    return NULL;
  } 
  
  memset (vertex, 0, sizeof (struct isis_vertex));
  vertex->type = vtype;
  switch (vtype) {
  case VTYPE_ES:
  case VTYPE_NONPSEUDO_IS:
    memcpy (vertex->N.id, (u_char *)id, ISIS_SYS_ID_LEN);
    break;
  case VTYPE_PSEUDO_IS:
    memcpy (vertex->N.id, (u_char *)id, ISIS_SYS_ID_LEN + 1);
    break;
  case VTYPE_IPREACH_INTERNAL:
  case VTYPE_IPREACH_EXTERNAL:
#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 ();
  
  return vertex;
}

/*
 * Add this IS to the root of SPT
 */
void
isis_spf_add_self (struct isis_spftree *spftree, struct isis_area *area,
                   int level)
{
  struct isis_vertex *vertex;
  struct isis_lsp *lsp;
  u_char lspid[ISIS_SYS_ID_LEN + 2];
#ifdef EXTREME_DEBUG
  u_char buff[BUFSIZ];
#endif /* EXTREME_DEBUG */
  memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
  LSP_PSEUDO_ID(lspid) = 0;
  LSP_FRAGMENT(lspid) = 0;
  
  lsp = lsp_search (lspid, area->lspdb[level - 1]);
  
  if (lsp == NULL)
    zlog_warn ("ISIS-Spf: could not find own l%d LSP!", level);
  
  vertex = isis_vertex_new (isis->sysid, VTYPE_NONPSEUDO_IS);
  vertex->lsp = lsp;

  listnode_add (spftree->paths, vertex);

#ifdef EXTREME_DEBUG
  zlog_info ("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;
}

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 (node = listhead (list); node; nextnode (node)) {
    vertex = getdata (node);
    if (vertex->type != vtype)
      continue;
    switch (vtype) {
    case VTYPE_ES:
    case VTYPE_NONPSEUDO_IS:
      if (memcmp ((u_char *)id, vertex->N.id, ISIS_SYS_ID_LEN) == 0)
        return vertex;
      break;
    case VTYPE_PSEUDO_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:
#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
 */
struct isis_vertex *
isis_spf_add2tent (struct isis_spftree *spftree, enum vertextype vtype, 
                   void *id, struct isis_adjacency *adj, u_int16_t cost,
                   int depth, int family)
{
  struct isis_vertex *vertex, *v;
  struct listnode *node;
#ifdef EXTREME_DEBUG 
  u_char buff[BUFSIZ];
#endif

  vertex = isis_vertex_new (id, vtype);
  vertex->d_N = cost;
  vertex->depth = depth;
  
  if (adj)
    listnode_add (vertex->Adj_N, adj);
#ifdef EXTREME_DEBUG 
  zlog_info ("ISIS-Spf: add to TENT  %s %s depth %d dist %d",
             vtype2string(vertex->type), vid2string(vertex, buff),
             vertex->depth, vertex->d_N);
#endif /* EXTREME_DEBUG */
  listnode_add (spftree->tents, vertex); 
  if (list_isempty (spftree->tents)) {
    listnode_add (spftree->tents, vertex); 
    return vertex;
  }
  for (node = listhead (spftree->tents); node; nextnode (node)) {
    v = getdata (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) {
      /*  Tie break, add according to type */
      while (v  && v->d_N == vertex->d_N && v->type > vertex->type) {
        if (v->type > vertex->type) {
          break;
        }
        nextnode (node);
        (node) ? (v = getdata (node)) : (v = NULL);
      }
      list_add_node_prev (spftree->tents, node, vertex);
      break; 
    } else  if (node->next == NULL) {
      list_add_node_next (spftree->tents, node, vertex);
      break;
    }
  }
  return vertex;
}

struct isis_vertex *
isis_spf_add_local (struct isis_spftree *spftree, enum vertextype vtype, 
                    void *id, struct isis_adjacency *adj, u_int16_t cost,
                    int family)
{
  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);
    }
    /*         f) */
    else if (vertex->d_N > cost) {
      listnode_delete (spftree->tents, vertex);
      goto add2tent;
    }
    /*       e) do nothing */
    return vertex;
  }

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

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

  /* C.2.6 b)    */
  if (dist > MAX_PATH_METRIC)
    return;
  /*       c)    */
  vertex = isis_find_vertex (spftree->paths, id, vtype);
  if (vertex) {
#ifdef EXTREME_DEBUG
    zlog_info ("ISIS-Spf: process_N  %s %s dist %d already found from PATH",
	       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_info ("ISIS-Spf: process_N  %s %s dist %d",
	       vtype2string(vtype), vid2string(vertex, buff), dist);
#endif /* EXTREME_DEBUG */
    if (vertex->d_N == dist) {
      if (adj)
        listnode_add (vertex->Adj_N, adj);
      /*      2) */
      if (listcount(vertex->Adj_N) > ISIS_MAX_PATH_SPLITS)
        remove_excess_adjs (vertex->Adj_N);
      /*      3) */
      return;
    } else if (vertex->d_N < dist) {
      return;
      /*      4) */
    } else {
      listnode_delete (spftree->tents, vertex);
    }
  }
  
  isis_spf_add2tent (spftree, vtype, id, adj, dist, depth, family);
  return;
}

/*
 * C.2.6 Step 1
 */
int
isis_spf_process_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp, 
                      uint16_t cost, uint16_t depth, int family)
{
  struct listnode *node, *fragnode = NULL;
  u_int16_t dist;
  struct is_neigh *is_neigh;
  struct ipv4_reachability *ipreach;
  enum vertextype vtype;
  struct prefix prefix;
#ifdef HAVE_IPV6
  struct ipv6_reachability *ip6reach;
#endif /* HAVE_IPV6 */
  

  if (!lsp->adj)
    return ISIS_WARNING;
  if (lsp->tlv_data.nlpids == NULL || 
      !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"
	       " - do not process");
    return ISIS_WARNING;
  }

  if (!ISIS_MASK_LSP_OL_BIT(lsp->lsp_header->lsp_bits)) {
    if (lsp->tlv_data.is_neighs) {
      for (node = listhead (lsp->tlv_data.is_neighs); node; nextnode (node)) {
        is_neigh = getdata (node);
        /* C.2.6 a) */       
	/* Two way connectivity */
	if (!memcmp (is_neigh->neigh_id, isis->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, 
                   lsp->adj, family);
      }
    }
    if (family == AF_INET && lsp->tlv_data.ipv4_int_reachs) {
      prefix.family = AF_INET;
      for (node = listhead (lsp->tlv_data.ipv4_int_reachs); node; 
           nextnode (node)) {
        ipreach = getdata (node);
        dist = cost + ipreach->metrics.metric_default;
        vtype = VTYPE_IPREACH_INTERNAL;
        prefix.u.prefix4 = ipreach->prefix;
        prefix.prefixlen = ip_masklen (ipreach->mask);
        process_N (spftree, vtype, (void *)&prefix, dist, depth + 1,
                   lsp->adj, family);
      }
    }
    
    if (family == AF_INET && lsp->tlv_data.ipv4_ext_reachs) {
      prefix.family = AF_INET;
      for (node = listhead (lsp->tlv_data.ipv4_ext_reachs); node; 
           nextnode (node)) {
        ipreach = getdata (node);
        dist = cost + ipreach->metrics.metric_default;
        vtype = VTYPE_IPREACH_EXTERNAL;
        prefix.u.prefix4 = ipreach->prefix;
        prefix.prefixlen = ip_masklen (ipreach->mask);
        process_N (spftree, vtype, (void *)&prefix, dist, depth + 1,
                   lsp->adj, family);
      }
    }
#ifdef HAVE_IPV6
    if (family == AF_INET6 && lsp->tlv_data.ipv6_reachs) {
      prefix.family = AF_INET6;
      for (node = listhead (lsp->tlv_data.ipv6_reachs); node; 
           nextnode (node)) {
        ip6reach = getdata (node);
        dist = cost + 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));
        process_N (spftree, vtype, (void *)&prefix, dist, depth + 1,
                   lsp->adj, family);
      }
    }
#endif /* HAVE_IPV6 */
  }
  
  if (fragnode == NULL)
    fragnode = listhead (lsp->lspu.frags);
  else 
    fragnode = nextnode (fragnode);

  if (fragnode) {
    lsp = getdata (fragnode);
    goto lspfragloop;
  }
  
  return ISIS_OK;
}

int
isis_spf_process_pseudo_lsp (struct isis_spftree *spftree,struct isis_lsp *lsp,
                             uint16_t cost, uint16_t depth, int family)
{
  struct listnode *node, *fragnode = NULL;
  struct is_neigh *is_neigh;
  enum vertextype vtype;
  
 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;
  }
    
  for (node = (lsp->tlv_data.is_neighs ? 
               listhead (lsp->tlv_data.is_neighs) : NULL); 
       node; nextnode (node)) {
    is_neigh = getdata (node);
    vtype = LSP_PSEUDO_ID(is_neigh->neigh_id) ? VTYPE_PSEUDO_IS 
                                              : VTYPE_NONPSEUDO_IS;
    /* Two way connectivity */
    if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN))
      continue;
    if (isis_find_vertex (spftree->tents, (void *)is_neigh->neigh_id, vtype) 
	== NULL &&
        isis_find_vertex (spftree->paths, (void *)is_neigh->neigh_id, vtype)
        == NULL) {
        /* C.2.5 i) */
        isis_spf_add2tent (spftree, vtype, is_neigh->neigh_id, lsp->adj, 
                           cost, depth, family);
    }
  }
  
  if (fragnode == NULL)
    fragnode = listhead (lsp->lspu.frags);
  else 
    fragnode = nextnode (fragnode);

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

  
  return ISIS_OK;
}
      
int
isis_spf_preload_tent (struct isis_spftree *spftree, 
                       struct isis_area *area, int level, int family)
{
  struct isis_vertex *vertex;
  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];
#ifdef HAVE_IPV6
  struct prefix_ipv6 *ipv6;
#endif /* HAVE_IPV6 */
  
  for (cnode = listhead (area->circuit_list); cnode; nextnode (cnode)) {
    circuit = getdata (cnode);
    if (circuit->state != C_STATE_UP)
      continue;
    if (!(circuit->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 (ipnode = (circuit->ip_addrs ? listhead (circuit->ip_addrs) : NULL); 
           ipnode; nextnode (ipnode)) {
        ipv4 = getdata (ipnode);
        prefix.u.prefix4 = ipv4->prefix;
        prefix.prefixlen = ipv4->prefixlen;
        isis_spf_add_local (spftree, VTYPE_IPREACH_INTERNAL, &prefix, NULL, 0,
                            family);
      }
    }
#ifdef HAVE_IPV6
    if (family == AF_INET6) {
      prefix.family = AF_INET6;
      for (ipnode = (circuit->ipv6_non_link ? listhead 
                     (circuit->ipv6_non_link) : NULL); ipnode; 
           nextnode (ipnode)) {
        ipv6 = getdata (ipnode);
        prefix.prefixlen = ipv6->prefixlen;
        prefix.u.prefix6 = ipv6->prefix;
        isis_spf_add_local (spftree, VTYPE_IP6REACH_INTERNAL, 
                            &prefix, NULL, 0, family);
      }
    }
#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);
        zlog_warn ("ISIS-Spf: no L%d adjacencies on circuit %s",
                   level, circuit->interface->name);
	continue;
      }
      anode = listhead (adj_list);
      while (anode) {
        adj = getdata (anode);
        if (!speaks (&adj->nlpids, family)) {
          anode = nextnode (anode); 
          continue;
        }
        switch (adj->sys_type) {
        case ISIS_SYSTYPE_ES:
          isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj, 
                              circuit->metrics[level - 1].metric_default,
                              family);
        break;
        case ISIS_SYSTYPE_IS:
        case ISIS_SYSTYPE_L1_IS:
        case ISIS_SYSTYPE_L2_IS:
          vertex = 
            isis_spf_add_local (spftree, VTYPE_NONPSEUDO_IS, 
                                adj->sysid, adj,
                                circuit->metrics[level - 1].metric_default,
                                family);
          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, area->lspdb[level - 1]);
          if (!lsp)
            zlog_warn ("No lsp found for IS adjacency");
          /*          else {
	    isis_spf_process_lsp (spftree, lsp, vertex->d_N, 1, family);
            } */
          break;
        case ISIS_SYSTYPE_UNKNOWN:
        default:
          zlog_warn ("isis_spf_preload_tent unknow adj type");
        }
        anode = nextnode (anode); 
      }
      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);
      lsp = lsp_search (lsp_id, area->lspdb[level - 1]);
      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 for DR");
      }
      if (lsp ==  NULL || lsp->lsp_header->rem_lifetime == 0) {
        zlog_warn ("ISIS-Spf: No lsp found for DR");
      } else {
        isis_spf_process_pseudo_lsp 
          (spftree, lsp, circuit->metrics[level - 1].metric_default, 0,
           family);
        
      }
    } 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->metrics[level - 1].metric_default,
                            family);
        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, VTYPE_NONPSEUDO_IS, adj->sysid, adj,
                              circuit->metrics[level - 1].metric_default,
                              family);
        break;
      case ISIS_SYSTYPE_UNKNOWN:
      default:
        zlog_warn ("isis_spf_preload_tent unknow adj type");
        break;
      }
    } 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
 */
void
add_to_paths (struct isis_spftree *spftree, struct isis_vertex *vertex,
              struct isis_area *area)
{

#ifdef EXTREME_DEBUG
  u_char buff[BUFSIZ];
#endif /* EXTREME_DEBUG */
  listnode_add (spftree->paths, vertex);

#ifdef EXTREME_DEBUG  
  zlog_info ("ISIS-Spf: added  %s %s depth %d dist %d to PATHS",
             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, area);
    else if (isis->debugs & DEBUG_SPF_EVENTS)
      zlog_info ("ISIS-Spf: no adjacencies do not install route");
  }
  
  return;
}


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

int
isis_run_spf (struct isis_area *area, int level, int family)
{
  int retval = ISIS_OK;
  struct listnode *node;
  struct isis_vertex *vertex;
  struct isis_spftree *spftree = NULL; 
  u_char lsp_id[ISIS_SYS_ID_LEN + 2];
  struct isis_lsp *lsp;
  
  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);

  /*
   * C.2.5 Step 0
   */
  init_spt (spftree);
  /*              a) */
  isis_spf_add_self (spftree, area, level);
  /*              b) */
  retval = isis_spf_preload_tent (spftree, area, level, family);
  
  /*
   * C.2.7 Step 2
   */
  if (listcount (spftree->tents) == 0) {
    zlog_warn ("ISIS-Spf: TENT is empty");
    spftree->lastrun = time (NULL);
    return retval;
  }

  while (listcount (spftree->tents) > 0) {
    node = listhead (spftree->tents);
    vertex = getdata (node);
    /* Remove from tent list */
    list_delete_node (spftree->tents, node);
    if (isis_find_vertex (spftree->paths, vertex->N.id, vertex->type))
      continue;
    add_to_paths (spftree, vertex, area);
    if (vertex->type == VTYPE_PSEUDO_IS || 
        vertex->type == VTYPE_NONPSEUDO_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) {
	if (LSP_PSEUDO_ID (lsp_id)) {
          isis_spf_process_pseudo_lsp (spftree, lsp, vertex->d_N, 
                                       vertex->depth, family);
        
        } else {
	  isis_spf_process_lsp (spftree, lsp, vertex->d_N, vertex->depth, 
                                family);
	}
      } else {
        zlog_warn ("ISIS-Spf: No LSP found for %s", rawlspid_print (lsp_id));
      }
    }
  }
  
  thread_add_event (master, isis_route_validate, area, 0);
  spftree->lastrun = time (NULL);
  spftree->pending = 0;
  
  if (level == 1)
    spftree->t_spf_periodic =  thread_add_timer (master, 
						 isis_run_spf_l1, area, 
						 isis_jitter 
						 (PERIODIC_SPF_INTERVAL, 10));
  else 
    spftree->t_spf_periodic =  thread_add_timer (master, 
						 isis_run_spf_l2, area, 
						 isis_jitter 
						 (PERIODIC_SPF_INTERVAL, 10));

  return retval;
}

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

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

  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_info ("ISIS-Spf (%s) L1 SPF needed, periodic SPF",
               area->area_tag);
  }
  
  if (area->ip_circuits)
    retval = isis_run_spf (area, 1, AF_INET);
#ifdef HAVE_IPV6
  if (area->ipv6_circuits)
    retval = isis_run_spf (area, 1, AF_INET6);
#endif
  return retval;
}

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

  area = THREAD_ARG(thread);
  assert (area);
  
  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_info ("ISIS-Spf (%s) L2 SPF needed, periodic SPF",
               area->area_tag);
  }

  if (area->ip_circuits)
    retval = isis_run_spf (area, 2, AF_INET);
#ifdef HAVE_IPV6
  if (area->ipv6_circuits)
    retval = isis_run_spf (area, 2, AF_INET6);
#endif

  return retval;
}

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

  if (spftree->pending)
    return retval;

  diff = now - spftree->lastrun; 

  /* FIXME: let's wait a minute before doing the SPF */
  if (now - isis->uptime < 60 || isis->uptime == 0) {
    if (level == 1)
      thread_add_timer (master, isis_run_spf_l1, area, 
                        60);
    else
      thread_add_timer (master, isis_run_spf_l2, area, 
                        60);

    spftree->pending = 1;
    return retval;
  }
  if (spftree->t_spf_periodic)
    thread_cancel (spftree->t_spf_periodic);

  if (diff < MINIMUM_SPF_INTERVAL) {
    if (level == 1)
      thread_add_timer (master, isis_run_spf_l1, area, 
                        MINIMUM_SPF_INTERVAL - diff);
    else
      thread_add_timer (master, isis_run_spf_l2, area, 
                        MINIMUM_SPF_INTERVAL - diff);

    spftree->pending = 1;
  } else {
    spftree->pending = 0;
    retval = isis_run_spf (area, level, AF_INET);
  }

  return retval;
}

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

  if (spftree->pending)
    return retval;

  diff = now - spftree->lastrun; 
  
  if (spftree->t_spf_periodic)
    thread_cancel (spftree->t_spf_periodic);
  
  /* FIXME: let's wait a minute before doing the SPF */
  if (now - isis->uptime < 60 || isis->uptime == 0) {
    if (level == 1)
      thread_add_timer (master, isis_run_spf_l1, area, 
                        60);
    else
      thread_add_timer (master, isis_run_spf_l2, area, 
                        60);

    spftree->pending = 1;
    return retval;
  }


  if (diff < MINIMUM_SPF_INTERVAL) {
    if (level == 1)
      thread_add_timer (master, isis_run_spf_l1, area, 
                        MINIMUM_SPF_INTERVAL - diff);
    else
      thread_add_timer (master, isis_run_spf_l2, area, 
                        MINIMUM_SPF_INTERVAL - diff);

    spftree->pending = 1;
  } else {
    spftree->pending = 0;
    retval = isis_run_spf (area, level, AF_INET6);
  }

  return retval;
}

#endif

void
isis_print_paths (struct vty *vty, struct list *paths)
{
  struct listnode *node, *anode;
  struct isis_vertex *vertex;
  struct isis_dynhn *dyn, *nh_dyn = NULL;
  struct isis_adjacency *adj;
#ifdef EXTREME_DEBUG
  u_char buff[255];
#endif 

  vty_out (vty, "System Id            Metric     Next-Hop"
           "             Interface   SNPA%s", VTY_NEWLINE);
  for (node = listhead (paths); node; nextnode (node)) {
    vertex = getdata (node);
    if (vertex->type != VTYPE_NONPSEUDO_IS)
      continue;
    if (memcmp (vertex->N.id, isis->sysid, ISIS_SYS_ID_LEN) == 0) {
      vty_out (vty, "%s             --%s", host.name, VTY_NEWLINE);
    } else {
      dyn = dynhn_find_by_id ((u_char *)vertex->N.id);
      anode = listhead (vertex->Adj_N);
      adj = getdata (anode);
      if (adj) {
        nh_dyn = dynhn_find_by_id (adj->sysid);
        vty_out (vty, "%-20s %-10u %-20s %-11s %-5s%s", 
                 (dyn != NULL) ? dyn->name.name : 
                 (u_char *)rawlspid_print ((u_char *)vertex->N.id),
                 vertex->d_N, (nh_dyn != NULL) ? nh_dyn->name.name : 
                 (u_char *)rawlspid_print (adj->sysid), 
                 adj->circuit->interface->name,
                 snpa_print (adj->snpa), VTY_NEWLINE);
      } else {
        vty_out (vty, "%s              %u %s", dyn ? dyn->name.name : 
                 (u_char *)rawlspid_print (vertex->N.id), 
                 vertex->d_N, VTY_NEWLINE);
      }
        
    }
#if 0
    vty_out (vty, "%s %s %u %s", vtype2string(vertex->type), 
             vid2string(vertex, buff), vertex->d_N, VTY_NEWLINE);
#endif
  }

  
}

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 (node = listhead (isis->area_list); node; nextnode (node)) {
    area = getdata (node);

    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);
      }
#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);
      }
#endif /* HAVE_IPV6 */
    }
  }

  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 (node = listhead (isis->area_list); node; nextnode (node)) {
    area = getdata (node);

    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);
    }
#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);
      }
#endif /* HAVE_IPV6 */
    }


  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 (node = listhead (isis->area_list); node; nextnode (node)) {
    area = getdata (node);

    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);
    }
#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);
      }
#endif /* HAVE_IPV6 */
    }


  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);
}
