/*
 * IS-IS Rout(e)ing protocol - isis_adjacency.c   
 *                             handling of IS-IS adjacencies
 *
 * 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 <stdio.h>
#include <limits.h>
#include <string.h>
#include <zebra.h>

#include "log.h"
#include "memory.h"
#include "hash.h"
#include "vty.h"
#include "linklist.h"
#include "thread.h"
#include "if.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/isisd.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_dr.h"
#include "isisd/isis_dynhn.h"
#include "isisd/isis_pdu.h"

extern struct isis *isis;

struct isis_adjacency *
adj_alloc (u_char * id)
{
  struct isis_adjacency *adj;

  adj = XMALLOC (MTYPE_ISIS_ADJACENCY, sizeof (struct isis_adjacency));
  memset (adj, 0, sizeof (struct isis_adjacency));
  memcpy (adj->sysid, id, ISIS_SYS_ID_LEN);

  return adj;
}

struct isis_adjacency *
isis_new_adj (u_char * id, u_char * snpa, int level,
	      struct isis_circuit *circuit)
{
  struct isis_adjacency *adj;
  int i;

  adj = adj_alloc (id);		/* P2P kludge */

  if (adj == NULL)
    {
      zlog_err ("Out of memory!");
      return NULL;
    }

  memcpy (adj->snpa, snpa, 6);
  adj->circuit = circuit;
  adj->level = level;
  adj->flaps = 0;
  adj->last_flap = time (NULL);
  if (circuit->circ_type == CIRCUIT_T_BROADCAST)
    {
      listnode_add (circuit->u.bc.adjdb[level - 1], adj);
      adj->dischanges[level - 1] = 0;
      for (i = 0; i < DIS_RECORDS; i++)	/* clear N DIS state change records */
	{
	  adj->dis_record[(i * ISIS_LEVELS) + level - 1].dis
	    = ISIS_UNKNOWN_DIS;
	  adj->dis_record[(i * ISIS_LEVELS) + level - 1].last_dis_change
	    = time (NULL);
	}
    }

  return adj;
}

struct isis_adjacency *
isis_adj_lookup (u_char * sysid, struct list *adjdb)
{
  struct isis_adjacency *adj;
  struct listnode *node;

  for (node = listhead (adjdb); node; nextnode (node))
    {
      adj = getdata (node);
      if (memcmp (adj->sysid, sysid, ISIS_SYS_ID_LEN) == 0)
	return adj;
    }

  return NULL;
}


struct isis_adjacency *
isis_adj_lookup_snpa (u_char * ssnpa, struct list *adjdb)
{
  struct listnode *node;
  struct isis_adjacency *adj;

  for (node = listhead (adjdb); node; nextnode (node))
    {
      adj = getdata (node);
      if (memcmp (adj->snpa, ssnpa, ETH_ALEN) == 0)
	return adj;
    }

  return NULL;
}

/*
 * When we recieve a NULL list, we will know its p2p
 */
void
isis_delete_adj (struct isis_adjacency *adj, struct list *adjdb)
{
  struct isis_adjacency *adj2;
  struct listnode *node;

  if (adjdb)
    {
      for (node = listhead (adjdb); node; nextnode (node))
	{
	  adj2 = getdata (node);
	  if (adj2 == adj)
	    break;
	}
      listnode_delete (adjdb, adj);
    }

  if (adj->ipv4_addrs)
    list_delete (adj->ipv4_addrs);
#ifdef HAVE_IPV6
  if (adj->ipv6_addrs)
    list_delete (adj->ipv6_addrs);
#endif
  if (adj)
    {
      XFREE (MTYPE_ISIS_ADJACENCY, adj);
    }
  else
    {
      zlog_info ("tried to delete a non-existent adjacency");
    }

  return;
}

void
isis_adj_state_change (struct isis_adjacency *adj, enum isis_adj_state state,
		       char *reason)
{
  int old_state;
  int level = adj->level;
  struct isis_circuit *circuit;

  old_state = adj->adj_state;
  adj->adj_state = state;

  circuit = adj->circuit;

  if (isis->debugs & DEBUG_ADJ_PACKETS)
    {
      zlog_info ("ISIS-Adj (%s): Adjacency state change %d->%d: %s",
		 circuit->area->area_tag,
		 old_state, state, reason ? reason : "unspecified");
    }

  if (circuit->circ_type == CIRCUIT_T_BROADCAST)
    {
      if (state == ISIS_ADJ_UP)
	circuit->upadjcount[level - 1]++;
      if (state == ISIS_ADJ_DOWN)
	{
	  isis_delete_adj (adj, adj->circuit->u.bc.adjdb[level - 1]);
	  circuit->upadjcount[level - 1]--;
	}

      list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
      isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
				 circuit->u.bc.lan_neighs[level - 1]);
    }
  else if (state == ISIS_ADJ_UP)
    {				/* p2p interface */
      if (adj->sys_type == ISIS_SYSTYPE_UNKNOWN)
	send_hello (circuit, 1);

      /* update counter & timers for debugging purposes */
      adj->last_flap = time (NULL);
      adj->flaps++;

      /* 7.3.17 - going up on P2P -> send CSNP */
      /* FIXME: yup, I know its wrong... but i will do it! (for now) */
      send_csnp (circuit, 1);
      send_csnp (circuit, 2);
    }
  else if (state == ISIS_ADJ_DOWN)
    {				/* p2p interface */
      adj->circuit->u.p2p.neighbor = NULL;
      isis_delete_adj (adj, NULL);
    }
  return;
}


void
isis_adj_print (struct isis_adjacency *adj)
{
  struct isis_dynhn *dyn;
  struct listnode *node;
  struct in_addr *ipv4_addr;
#ifdef HAVE_IPV6
  struct in6_addr *ipv6_addr;
  u_char ip6[INET6_ADDRSTRLEN];
#endif /* HAVE_IPV6 */

  if (!adj)
    return;
  dyn = dynhn_find_by_id (adj->sysid);
  if (dyn)
    zlog_info ("%s", dyn->name.name);

  zlog_info ("SystemId %20s SNPA %s, level %d\nHolding Time %d",
	     adj->sysid ? sysid_print (adj->sysid) : "unknown",
	     snpa_print (adj->snpa), adj->level, adj->hold_time);
  if (adj->ipv4_addrs && listcount (adj->ipv4_addrs) > 0)
    {
      zlog_info ("IPv4 Addresses:");

      for (node = listhead (adj->ipv4_addrs); node; nextnode (node))
	{
	  ipv4_addr = getdata (node);
	  zlog_info ("%s", inet_ntoa (*ipv4_addr));
	}
    }

#ifdef HAVE_IPV6
  if (adj->ipv6_addrs && listcount (adj->ipv6_addrs) > 0)
    {
      zlog_info ("IPv6 Addresses:");
      for (node = listhead (adj->ipv6_addrs); node; nextnode (node))
	{
	  ipv6_addr = getdata (node);
	  inet_ntop (AF_INET6, ipv6_addr, ip6, INET6_ADDRSTRLEN);
	  zlog_info ("%s", ip6);
	}
    }
#endif /* HAVE_IPV6 */
  zlog_info ("Speaks: %s", nlpid2string (&adj->nlpids));

  return;
}

int
isis_adj_expire (struct thread *thread)
{
  struct isis_adjacency *adj;
  int level;

  /*
   * Get the adjacency
   */
  adj = THREAD_ARG (thread);
  assert (adj);
  level = adj->level;
  adj->t_expire = NULL;

  /* trigger the adj expire event */
  isis_adj_state_change (adj, ISIS_ADJ_DOWN, "holding time expired");

  return 0;
}

const char *
adj_state2string (int state)
{

  switch (state)
    {
    case ISIS_ADJ_INITIALIZING:
      return "Initializing";
    case ISIS_ADJ_UP:
      return "Up";
    case ISIS_ADJ_DOWN:
      return "Down";
    default:
      return "Unknown";
    }

  return NULL;			/* not reached */
}

/*
 * show clns/isis neighbor (detail)
 */
void
isis_adj_print_vty2 (struct isis_adjacency *adj, struct vty *vty, char detail)
{

#ifdef HAVE_IPV6
  struct in6_addr *ipv6_addr;
  u_char ip6[INET6_ADDRSTRLEN];
#endif /* HAVE_IPV6 */
  struct in_addr *ip_addr;
  time_t now;
  struct isis_dynhn *dyn;
  int level;
  struct listnode *node;

  dyn = dynhn_find_by_id (adj->sysid);
  if (dyn)
    vty_out (vty, "  %-20s", dyn->name.name);
  else if (adj->sysid)
    {
      vty_out (vty, "  %-20s", sysid_print (adj->sysid));
    }
  else
    {
      vty_out (vty, "  unknown ");
    }

  if (detail == ISIS_UI_LEVEL_BRIEF)
    {
      if (adj->circuit)
	vty_out (vty, "%-12s", adj->circuit->interface->name);
      else
	vty_out (vty, "NULL circuit!");
      vty_out (vty, "%-3u", adj->level);	/* level */
      vty_out (vty, "%-13s", adj_state2string (adj->adj_state));
      now = time (NULL);
      if (adj->last_upd)
	vty_out (vty, "%-9lu", adj->last_upd + adj->hold_time - now);
      else
	vty_out (vty, "-        ");
      vty_out (vty, "%-10s", snpa_print (adj->snpa));
      vty_out (vty, "%s", VTY_NEWLINE);
    }

  if (detail == ISIS_UI_LEVEL_DETAIL)
    {
      level = adj->level;
      if (adj->circuit)
	vty_out (vty, "%s    Interface: %s", VTY_NEWLINE, adj->circuit->interface->name);	/* interface name */
      else
	vty_out (vty, "NULL circuit!%s", VTY_NEWLINE);
      vty_out (vty, ", Level: %u", adj->level);	/* level */
      vty_out (vty, ", State: %s", adj_state2string (adj->adj_state));
      now = time (NULL);
      if (adj->last_upd)
	vty_out (vty, ", Expires in %s",
		 time2string (adj->last_upd + adj->hold_time - now));
      else
	vty_out (vty, ", Expires in %s", time2string (adj->hold_time));
      vty_out (vty, "%s    Adjacency flaps: %u", VTY_NEWLINE, adj->flaps);
      vty_out (vty, ", Last: %s ago", time2string (now - adj->last_flap));
      vty_out (vty, "%s    Circuit type: %s",
	       VTY_NEWLINE, circuit_t2string (adj->circuit_t));
      vty_out (vty, ", Speaks: %s", nlpid2string (&adj->nlpids));
      vty_out (vty, "%s    SNPA: %s", VTY_NEWLINE, snpa_print (adj->snpa));
      dyn = dynhn_find_by_id (adj->lanid);
      if (dyn)
	vty_out (vty, ", LAN id: %s.%02x",
		 dyn->name.name, adj->lanid[ISIS_SYS_ID_LEN]);
      else
	vty_out (vty, ", LAN id: %s.%02x",
		 sysid_print (adj->lanid), adj->lanid[ISIS_SYS_ID_LEN]);

      vty_out (vty, "%s    Priority: %u",
	       VTY_NEWLINE, adj->prio[adj->level - 1]);

      vty_out (vty, ", %s, DIS flaps: %u, Last: %s ago%s",
	       isis_disflag2string (adj->dis_record[ISIS_LEVELS + level - 1].
				    dis), adj->dischanges[level - 1],
	       time2string (now -
			    (adj->dis_record[ISIS_LEVELS + level - 1].
			     last_dis_change)), VTY_NEWLINE);

      if (adj->ipv4_addrs && listcount (adj->ipv4_addrs) > 0)
	{
	  vty_out (vty, "    IPv4 Addresses:%s", VTY_NEWLINE);
	  for (node = listhead (adj->ipv4_addrs); node; nextnode (node))
	    {
	      ip_addr = getdata (node);
	      vty_out (vty, "      %s%s", inet_ntoa (*ip_addr), VTY_NEWLINE);
	    }
	}
#ifdef HAVE_IPV6
      if (adj->ipv6_addrs && listcount (adj->ipv6_addrs) > 0)
	{
	  vty_out (vty, "    IPv6 Addresses:%s", VTY_NEWLINE);
	  for (node = listhead (adj->ipv6_addrs); node; nextnode (node))
	    {
	      ipv6_addr = getdata (node);
	      inet_ntop (AF_INET6, ipv6_addr, ip6, INET6_ADDRSTRLEN);
	      vty_out (vty, "      %s%s", ip6, VTY_NEWLINE);
	    }
	}
#endif /* HAVE_IPV6 */
      vty_out (vty, "%s", VTY_NEWLINE);
    }
  return;
}

void
isis_adj_print_vty (struct isis_adjacency *adj, struct vty *vty)
{
  isis_adj_print_vty2 (adj, vty, ISIS_UI_LEVEL_BRIEF);
}

void
isis_adj_print_vty_detail (struct isis_adjacency *adj, struct vty *vty)
{
  isis_adj_print_vty2 (adj, vty, ISIS_UI_LEVEL_DETAIL);
}

void
isis_adj_print_vty_extensive (struct isis_adjacency *adj, struct vty *vty)
{
  isis_adj_print_vty2 (adj, vty, ISIS_UI_LEVEL_EXTENSIVE);
}

void
isis_adj_p2p_print_vty (struct isis_adjacency *adj, struct vty *vty)
{
  isis_adj_print_vty2 (adj, vty, ISIS_UI_LEVEL_BRIEF);
}

void
isis_adj_p2p_print_vty_detail (struct isis_adjacency *adj, struct vty *vty)
{
  isis_adj_print_vty2 (adj, vty, ISIS_UI_LEVEL_DETAIL);
}

void
isis_adj_p2p_print_vty_extensive (struct isis_adjacency *adj, struct vty *vty)
{
  isis_adj_print_vty2 (adj, vty, ISIS_UI_LEVEL_EXTENSIVE);
}

void
isis_adjdb_iterate (struct list *adjdb, void (*func) (struct isis_adjacency *,
						      void *), void *arg)
{
  struct listnode *node;
  struct isis_adjacency *adj;
  for (node = listhead (adjdb); node; nextnode (node))
    {
      adj = getdata (node);
      (*func) (adj, arg);
    }
}

void
isis_adj_build_neigh_list (struct list *adjdb, struct list *list)
{
  struct isis_adjacency *adj;
  struct listnode *node;

  if (!list)
    {
      zlog_warn ("isis_adj_build_neigh_list(): NULL list");
      return;
    }

  for (node = listhead (adjdb); node; nextnode (node))
    {
      adj = getdata (node);
      if (!adj)
	{
	  zlog_warn ("isis_adj_build_neigh_list(): NULL adj");
	  return;
	}

      if ((adj->adj_state == ISIS_ADJ_UP ||
	   adj->adj_state == ISIS_ADJ_INITIALIZING))
	listnode_add (list, adj->snpa);
    }
  return;
}

void
isis_adj_build_up_list (struct list *adjdb, struct list *list)
{
  struct isis_adjacency *adj;
  struct listnode *node;

  if (!list)
    {
      zlog_warn ("isis_adj_build_up_list(): NULL list");
      return;
    }

  for (node = listhead (adjdb); node; nextnode (node))
    {
      adj = getdata (node);

      if (!adj)
	{
	  zlog_warn ("isis_adj_build_up_list(): NULL adj");
	  return;
	}

      if (adj->adj_state == ISIS_ADJ_UP)
	listnode_add (list, adj);
    }

  return;
}
