hb_h

/*******************************************************************************
**  Copyright 1994, Universities Research Association.  All rights reserved.
*******************************************************************************/
/*
**++
**  FACILITY:  heartbeat
**
**      Central process used to heartbeat other processes (called 'clients').
**	Heartbeat provides notification methods for missing clients.
**
**	Heartbeat will get its clients' registration from a database table.
**	A taskname and ACNET node identify a client in the database table.
**	
**  ABSTRACT:
**
**	hb.h provides definitions for use internal to hearbeat task.
**
**  AUTHORS:  R Joshel
**
**  MODIFICATION HISTORY:
**
**	11 Jan 94	R Joshel
**	created
**      21 Jul 95	R Joshel
**	Added UDP transport for pulses
**--
**/
/******************************************************************************/

#ifndef	_hb_h	/* include only once */
#define	_hb_h

/*******************************************************************************
** macros
*/
#define  _VMSFAIL(sts,mess) \
if ($VMS_FAILURE(sts)) { hb_log(mess); LIB$STOP(sts); }

#define	HB_PULSE_ME	1	/* pulse is from client by ACNET USM */
#define	HB_PULSE_THEM	2	/* pulse is to client by ACNET request-reply */
#define	HB_PULSE_DGRAM	3	/* pulse is from client by (UDP) datagram */

#define	HB_TELL_LEN	30	/* max length of notification address */
#define	HB_MECCA_LEN	32	/* max length of mecca direc */

#define	HB_NOTEBY_MAIL	1	/* notify by mail */
#define	HB_NOTEBY_MESS	2	/* notify by broadcast message */

#define	HB_TASKNAME	"HEARTB"/* Heartbeat ACNET taskname */
#define	HB_NODE		(HEARTB)/* Hearbeat logical node */
#define	HB_LOGFILE	"op$usr1:[vaxappl.heartbeat]hb.log"

#define	HB_NET_ABEAT	1	/* network request: a pulse beat */
#define	HB_NET_PING	2	/* network request: ping heartbeat task */
#define HB_NET_DUMP	3	/* network request: dump log file */
#define HB_NET_STATS	4	/* network request: return statistics */
#define	HB_NET_MODIFY	5	/* network request: modify/add/delete client */
#define	HB_NET_WHOSTS	6	/* network request: retrun client status */
#define	HB_NET_USRINFO	7	/* network request: return a client's specs */
#define	HB_NET_NOOP	8	/* network request: ignore do not reply */
#define HB_NET_0STATS	9	/* network request: clear statistics */

/*******************************************************************************
** data types
*/
typedef	struct	/* registration for Heartbeat client; MUST MATCH DB TABLE */
  {
  unsigned int	 hc_timemod;		/* time table entry added/modified */
  unsigned short hc_trnode;		/* client's ACNET trunk/node */ 
  unsigned int	 hc_r50name;		/* client's rad50 ACNET name */
  unsigned short hc_pulse;		/* hearbeat method */
  unsigned short hc_period;		/* # secs expected between beats */
  unsigned short hc_tries_needed;	/* # consecutive missing beats> death */
  unsigned short hc_reqmess;		/* hearbeat message sent to clients */
  unsigned short hc_death_notice;	/* notification method */
  unsigned short hc_alert;		/* if TRUE. alert on missing beats */
  unsigned short hc_do_alarm;		/* if TRUE-> make alarm on death */
  char		 hc_tell[HB_TELL_LEN];	/* notification address */
  char		 hc_mecca[HB_MECCA_LEN];/* mecca subdirectory */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ hb_client_t;

typedef	struct	/* 'pulse' packet sent to Heartbeat task by a client:
  		   only used by tasks that send USMs for a pulse */
  {
  unsigned short hp_typecode;	/* request typcode HB_NET_ABEAT */
  unsigned short hp_trnode;	/* client's ACNET trunk/node */ 
  unsigned int	 hp_r50name;	/* client's rad50 ACNET name */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ hb_pulse_t;

typedef struct	/* simple request/reply packet */
  {
  short		snr_tc_stat;	/* request typecode/return status */
  short		snr_stc;	/* request subtypecode */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ hb_snr_t;

typedef	struct	/* process statistics */
  {
  unsigned int	st_started;	/* start time() */
  unsigned int	st_timenow;	/* time now time() */
  unsigned int	st_totclient;	/* # of clients ever seen */
  unsigned int	st_active;	/* # of clients active */
  unsigned int	st_alive;	/* # of clients alive */
  unsigned int	st_dead;	/* # of clients dead */
  unsigned int	st_deleted;	/* # of clients deleted */
  unsigned int	st_added;	/* # of clients added */
  unsigned int	st_modified;	/* # of clients modified */
  unsigned int	st_totnet;	/* # of network transaction */
  unsigned int	st_neterr;	/* # of network errors */
  unsigned int	st_totalarm;	/* # of alarms made */
  unsigned int	st_totusm;	/* # of usm pulses received */
  unsigned int	st_totudp;	/* # of udp pulses received */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ hb_stats_t;

typedef	struct	/* modify request sent to Heartbeat task by a client */
  {
  unsigned short hm_typecode;	/* request typcode HB_NET_MODIFY */
  unsigned short hm_trnode;	/* client's ACNET trunk/node */ 
  unsigned int	 hm_r50name;	/* client's rad50 ACNET name */
  unsigned short hm_delete;	/* delete flag */
  hb_client_t	 hm_spec;	/* client specification */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ hb_modify_t;

typedef	struct	/* status for one client */
  {
  unsigned short hw_trnode;	/* trunk/node */ 
  unsigned int	 hw_r50name;	/* acnet rad50 name */ 
  unsigned short hw_alive;	/* TRUE-> client is alive */ 
  unsigned short hw_tries_now;	/* tries now */ 
  unsigned short hw_tries_need;	/* tries needed */ 
  unsigned short hw_do_alarm;	/* alarm active flag */ 
  unsigned int	 hw_totmiss;	/* # missed beats */ 
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ hb_who_t;
typedef	struct	/* reply from Heartbeat: client status */
  {
  unsigned short hs_numof;	/* # clients in list; else an error code */ 
  hb_who_t	 hs_list[1];	/* list of status */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ hb_whosts_t;

#define	VERIFY_ADCALC_BRKTHRU	3
typedef	struct	/* breakthru request sent to VERFIY task */
  {
  unsigned short ht_typecode;	/* request typcode VERIFY_ADCALC_BRKTHRU */
  char		 ht_to_mess[2];	/* send-to & message strings (contiguous ) */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ hb_brkthru_t;

/*******************************************************************************
** global 
*/

#ifdef __cplusplus
extern "C" {
#endif

extern hb_stats_t hbstats;
void dgram_scan(int init);
void hb_log(char *u_mess);
void hb_beat_from(hb_pulse_t * const thisP);

#ifdef __cplusplus
}
#endif

#endif	/* include only once */