/*  link_util_support.h							*/
/*	Definitions for Link Utilization Feature.	*/
/************************************************/
/*        Copyright (c) 1994                    */
/*          by MIL 3, Inc.                      */
/*      (A Delaware Corporation)                */
/*  3400 International Drive,  N.W.             */
/*      Washington, D.C., U.S.A.                */
/*          All Rights Reserved.                */
/************************************************/

/* Possible link object types for Link utilization.	*/
typedef enum
	{
	LuC_Objtype_BUS,	
	LuC_Objtype_RING,
	LuC_Objtype_FDDI,	
	LuC_Objtype_HUB,
	LuC_Objtype_PTP
	} LuC_Objtype;

/* Possible states for utilization.  Either above or below the threshold. */
typedef enum
	{
	BELOW_TH, 
	ABOVE_TH
	} LuC_Threshold_State;

/* This structure is created for each link in the network model. */
/* For HUBs, & Rings, there are many links connected with one	*/
/* objindex.  In these cases the objindex is the RING_ID or the */
/* HUB_ID with all connected links stored in the objid_lptr list */
typedef struct 
	{
	/* List of links connected to this object. */
	List*	links_lptr;	

	/* Index number to keep track of object with this list node */
	int		objindex;

	/* Keep object type for quick reference.	*/
	LuC_Objtype	objtype;

	/* For PTP links, this keeps track if it's duplex or simplex	*/
	int		link_duplex;
	
	/* Current threshold state (ABOVE/BELOW)    */
	LuC_Threshold_State	th_state;	

	/* Threshold set for the protocol used for this link  */
	double	max_th;		

	/* value to be displayed in animation */
	double	current_utilization;

	/* recorded for final report    */
	double	cumm_time_over_th;

	/* used to calculate cumm_time_over_th */
	double	time_of_last_state_change;

	/* recorded for final report */
	int		num_times_th_broken;

	/* cummulative busy/transmit time for all packets within this time window	*/
	double	current_txtime;		

	/* when current_txtime is greater than WindowTime, this holds the overflow	*/
	double	next_txtime;

	/* When last packet was processed.   */
	double	last_sim_time; 

	/* Total transmit time for entire simulation. Used for testing.   */
	double	total_txtime;

	/* Total number of signals sent. Used for testing.   */
	int		total_txmts; 

	/* Can a link connected to this object be animated? */
	int		animate;	

	/* utilization % string sent to animation */
	char	output[16];	
	} LuT_Linkobj_Info;

/* Global structure holding important animation information	*/
typedef struct
	{	
	/* Viewer ID	*/
	Anvid	anvid;		

	/* Macro ID */
	Anmid	anmid;

	/* Subnet this animation is viewing	*/
	Objid	subnetid;

	/* ID of the custom probe for this animation	*/
	Objid	probeid;

	/* Required for animation KPs	*/
	char	net_name[256];

	/* used in KPs as well as testing to see if we need to call animation KPs in the first place.	*/
	char	subnet_name[256];

	/* Dont animate outside these ranges Start/Stop */
	double	anim_start_time;
	double	anim_stop_time;

	/* User wants animation to change link color as well.	*/
	int		animate_links;
	} LuT_Anim_Info;

/* Each link whether on it's own, or as part of a HUB/RING,	*/
/* has it's ID, and full subnet name placed here.  This node	*/
/* is then added to the objid_lptr list within the LU_Link_Info	*/
/* structure.												*/
typedef struct
	{
	/* Actual ID of link to have animation rendered on	*/
	Objid	link_id;

	/* full subnet name for display on screen & in report	*/
	char	*link_name;

	/* name of the link itself.	*/
	char	*link_base_name;

	/* Should this link be animated?	*/
	int		animate;

	/* used to erase previously drawn animation.			*/
	Andid	andid;
	} LuT_Link_Node;

/* This structure hold poointers to the object node, and the actual link	*/
/* node.  The list created by thes node is used for printing of the final 	*/
/* report, and gets sorted by the name contained in the LinkNode pointer.	*/
/* The Link_Info pointer is for the threshold information held there.		*/
typedef struct
	{
	LuT_Link_Node		*link_node_ptr;
	LuT_Linkobj_Info	*linkobj_info_ptr;
	} LuT_Name_List;

/* Function Protoypes.	*/
LuT_Linkobj_Info	*lu_link_ptr_get (LuC_Objtype type, Objid linkid, int objindex, char *th_sim_attr);
LuT_Linkobj_Info	*lu_list_search (List *list_ptr, int objindex);
void				lu_list_insert (List *list_ptr, LuT_Linkobj_Info *linkobj_info_ptr);
void				lu_link_ptr_init (LuT_Linkobj_Info *lu_ptr, Objid objid, int objindex);
void				lu_link_add (LuT_Linkobj_Info *lu_ptr, Objid linkid);
void				lu_utilization_add (double tx_time, LuT_Linkobj_Info *lu_ptr);
void				lu_check_threshold (double *threshold);
void				lu_full_object_name_get (Objid objid, char *full_name);
void				lu_scan_list (List *list_ptr);
void				lu_scan_links ();
void				lu_draw_anim (LuT_Linkobj_Info *lu_ptr);
void				lu_report ();
int					lu_name_compare_proc (LuT_Name_List *name_ptr1, LuT_Name_List *name_ptr2);
void				lu_name_list_merge (List *lu_lptr, List *name_lptr);
LuT_Name_List		*lu_name_node_create (LuT_Link_Node *link_node_ptr, LuT_Linkobj_Info *lu_ptr);
void				lu_links_name_print (LuT_Linkobj_Info *linkobj_info_ptr, int n);
void				lu_setup ();


