/* ospf_defs.h: Data type definitions for OSPF process models. */

/* Prevent multiple includes. */
#ifndef		HEADER_FILE_ospf_defs_h

#define		HEADER_FILE_ospf_defs_h

/* OspfT_Router_Id: OSPF Router ID, implemented as IpT_Address. */
typedef IpT_Address		OspfT_Router_Id;

/* OspfT_Area_Id: OSPF Area ID, implemented as IpT_Address. */
typedef IpT_Address		OspfT_Area_Id;

/* OspfT_Rte_Table: OSPF Routing Table. */
typedef struct OspfT_Rte_Table
	{
	List *				entry_list_ptr;			/* List of entries representing table. */
	Boolean				dirty_flag;				/* Flag indicating table needs to be recalculated. */
	double				last_calc_time;			/* Last time routing table was calculated. */
	} OspfT_Rte_Table;

/* OspfT_Router: Representation of an OSPF router. */
typedef struct OspfT_Router
	{
	OspfT_Router_Id				router_id;				/* Unique ID for router. */
	OmsT_Pr_Handle				proc_reg_handle;		/* Process registry handle used to access router variables. */
	Prohandle					proc_handle;			/* Process handle (used to invoke root process). */
	int							ip_outstrm;				/* Stream index to IP. */
	int							options;				/* Flag board indicating optional capabilities. */
	OspfT_Rte_Table *			rte_table_ptr;			/* Pointer to OSPF routing table. */
	Stathandle					load_stat;				/* Stat handle to load statistic. */
	double						bits_accum;				/* Total accumulated bits router has sent. */
	} OspfT_Router;

/* OspfT_Area: Representation of an OSPF Area. */
typedef struct OspfT_Area
	{
	OspfT_Area_Id		area_id;				/* Unique ID for area. */
	List *				router_lsa_list_ptr;	/* List of Router Link State Advertisements. */
	List *				network_lsa_list_ptr;	/* List of Network Link State Advertisements. */
	List *				summary_lsa_list_ptr;	/* List of Summary Link State Advertisements. */
	List *				interface_list_ptr;		/* List of OSPF Interfaces connected to area. */
	List *				address_list_ptr;		/* List of address ranges belonging to the area. */
	List *				hidden_addr_list_ptr;	/* List of address ranges not to be advertised outside of area. */
	OspfT_Router *		parent_router_ptr;		/* Pointer to parent router. */
	} OspfT_Area;

/* OspfT_Area_Range: Representation of an OSPF area range. */
typedef struct OspfT_Area_Range
	{
	IpT_Address_Range *	addr_range_ptr;
	Boolean				active;
	} OspfT_Area_Range;

/* OspfT_Interface_Type: Type of network interface is connected to. */
typedef enum OspfT_Interface_Type
	{
	OspfC_Interface_Type_Pt_To_Pt,	
	OspfC_Interface_Type_Broadcast,
	OspfC_Interface_Type_Non_Broadcast
	} OspfT_Interface_Type;

/* OspfT_Interface: Representation of an OSPF interface.  State variables are */
/* accessed through the process registry; also includes associated process.   */
typedef struct OspfT_Interface
	{
	OmsT_Pr_Handle			proc_reg_handle;	/* Process registry handle used to access interface variables. */
	Prohandle				proc_handle;		/* Process handle (used to invoke interface process). */
	OspfT_Area *			parent_area_ptr;	/* Pointer to area interface belongs to. */

	/* The variables below represent static state of the interface.  Dynamic */
	/* state should be accessed via the process registry, through the        */
	/* process registry handle provided above.                               */

	OspfT_Interface_Type	interface_type;
	IpT_Address				interface_address;
	IpT_Address				interface_mask;
	int						mtu;
	OspfT_Area_Id			area_id;
	double					hello_interval;
	double					router_dead_interval;
	double					transmit_delay;
	int						router_priority;
	int						cost;
	double					retransmit_interval;
	Evhandle				wait_timer_handle;
	List *					delayed_ack_list_ptr;
	} OspfT_Interface;

/* OspfT_Interface_State: Operational states of OSPF interface process. */
/* Defined in section 9.1 of RFC 1247.                                  */
typedef enum OspfT_Interface_State
	{
	OspfC_Interface_State_Down,
	OspfC_Interface_State_Loopback,
	OspfC_Interface_State_Waiting,
	OspfC_Interface_State_Pt_To_Pt,
	OspfC_Interface_State_DR_Other,
	OspfC_Interface_State_Backup,
	OspfC_Interface_State_DR
	} OspfT_Interface_State;

/* OspfT_Interface_Event: OSPF events that cause interface state changes. */
/* Defined in section 9.2 of RFC 1247.                                    */
typedef enum OspfT_Interface_Event
	{
	OspfC_Interface_Event_Intf_Up,
	OspfC_Interface_Event_Wait,
	OspfC_Interface_Event_Bkup_Seen,
	OspfC_Interface_Event_Nbr_Change,
	OspfC_Interface_Event_Loop_Ind,
	OspfC_Interface_Event_Unloop_Ind,
	OspfC_Interface_Event_Intf_Down
	} OspfT_Interface_Event;

/* OspfT_Interface_Invoke_Info: Information passed to interface process during invocation. */
typedef struct OspfT_Interface_Invoke_Info
	{
	Objid					interface_objid;
	OspfT_Interface *		interface_ptr;
	IpT_Interface_Info *	ip_interface_ptr;
	OspfT_Interface_Event	interface_event;
	} OspfT_Interface_Invoke_Info;

/* OspfT_Interface_State_Event_Proc:  Function type used to handle state/event combinations. */
typedef void (* OspfT_Interface_State_Event_Proc) (OspfT_Interface *intf_ptr, OspfT_Interface_Event intf_event);

/* OspfT_Neighbor: Representation of an OSPF neighbor.  State variables are */
/* accessed through the process registry; also includes associated process. */
typedef struct OspfT_Neighbor
	{
	OmsT_Pr_Handle				proc_reg_handle;		/* Process registry handle used to access neighbor variables. */
	Prohandle					proc_handle;			/* Process handle (used to invoke neighbor process). */
	OspfT_Interface *			parent_interface_ptr;	/* Pointer to interface neighbor belongs to. */

	/* The variables below represent static state of the neighbor.  Dynamic */
	/* state should be accessed via the process registry, through the       */
	/* process registry handle provided above.                              */

	Evhandle					inactive_timer;
	int							options;
	IpT_Address					ip_address;
	Packet *					last_message_ptr;
	Evhandle					rxmt_timer;
	Evhandle					lsa_rxmt_timer;
	struct OspfT_Lsa_Header *	pending_req_ptr;
	} OspfT_Neighbor;

/* OspfT_Neighbor_State: Operational states of OSPF neighbor process. */
/* Defined in section 10.1 of RFC 1247.                               */
typedef enum OspfT_Neighbor_State
	{
	OspfC_Neighbor_State_Down,
	OspfC_Neighbor_State_Attempt,
	OspfC_Neighbor_State_Init,
	OspfC_Neighbor_State_Two_Way,
	OspfC_Neighbor_State_Ex_Start,
	OspfC_Neighbor_State_Exchange,
	OspfC_Neighbor_State_Loading,
	OspfC_Neighbor_State_Full
	} OspfT_Neighbor_State;

/* OspfT_Neighbor_Event: OSPF events that cause neighbor state changes. */
/* Defined in section 10.2 of RFC 1247.                                 */
typedef enum OspfT_Neighbor_Event
	{
	OspfC_Neighbor_Event_Hello_Rcvd,
	OspfC_Neighbor_Event_Start,
	OspfC_Neighbor_Event_Two_Way_Rcvd,
	OspfC_Neighbor_Event_Neg_Done,
	OspfC_Neighbor_Event_Exchg_Done,
	OspfC_Neighbor_Event_Bad_Ls_Req,
	OspfC_Neighbor_Event_Load_Done,
	OspfC_Neighbor_Event_Adj_OK,
	OspfC_Neighbor_Event_Seq_Num_Mismatch,
	OspfC_Neighbor_Event_One_Way_Rcvd,
	OspfC_Neighbor_Event_Kill_Nbr,
	OspfC_Neighbor_Event_Inactive_Timer,
	OspfC_Neighbor_Event_Ll_Down
	} OspfT_Neighbor_Event;

/* OspfT_Neighbor_Invoke_Info: Information passed to neighbor process during invocation. */
typedef struct OspfT_Neighbor_Invoke_Info
	{
	OspfT_Neighbor *		neighbor_ptr;
	OspfT_Neighbor_Event	neighbor_event;
	IpT_Address				neighbor_addr;
	int						neighbor_priority;
	} OspfT_Neighbor_Invoke_Info;

/* OspfT_Neighbor_State_Event_Proc:  Function type used to handle state/event combinations. */
typedef void (* OspfT_Neighbor_State_Event_Proc) (OspfT_Neighbor *nbr_ptr, OspfT_Neighbor_Event nbr_event);

#endif
