#include "mtpconst.h"

typedef	struct ls_info{
	BYTE		links_available;
	BYTE		links_available_t;
	BYTE		adjacentsp_acessible;
	BYTE		adjacentsp_restarting;
	WORD		adjacent_sp_place;
	BYTE		linksNum_configured;


	WORD		influ_dstnum_asNLS;
	WORD		influ_dstnum_asALS;

	WORD		influ_dstplace_intable_asNLS[MAX_LS_DPC];
	WORD		influ_dstplace_intable_asALS[MAX_LS_DPC];

	BYTE		links_nls_asp_ac_send_flag[MAX_ROUTE+1];
	BYTE		links_als_asp_ac_send_flag[MAX_ROUTE+1];
	WORD		send_asp_ac_link_id;
	
}ls_info;

typedef	struct mtp3_flow{
	ulong		UtoM[5];
	ulong		MtoI[5];
	ulong		ItoM[5];
	ulong		MtoU[5];
	ulong		stp[5];
	ulong		UtoM_throwed[5];
	ulong		MtoI_throwed[5];
	ulong		ItoM_throwed[5];
	ulong		MtoU_throwed[5];
	ulong		stp_throwed[5];
    ulong       stp_loop[5];
	ulong		isup_detail[32];
}mtp3_flow;

typedef	struct network{
	BYTE		routine[MAX_ROUTE]; /* bit0-1: normal route available
							bit2-3: alternative route available
							bit4-5: acessible 
			  				bit6-7: current route */
	BYTE		rtpc_state[MAX_ROUTE];
	BYTE		rtpc_input[MAX_ROUTE];
	BYTE		rtac_state[MAX_ROUTE];
	BYTE		rtac_input[MAX_ROUTE];
	BYTE		rsrt_state[MAX_ROUTE];
	BYTE		rsrt_input[MAX_ROUTE];
	BYTE		rsrt_t10[MAX_ROUTE];
	BYTE		m3ua_rc_status[MAX_ROUTE];
	mtp3_flow	flow;
}network;

typedef struct _nw_route
{
	ulong	dpc;
	WORD	normal_ls;
	WORD	alternative_ls;
	BYTE		mtp3_t8;
	BYTE		mtp3_t15;
	BYTE		mtp3_t16;
	BYTE		acn[MAX_ACN_NUM];
	BYTE		ansi_remote;
	ulong	rc;
	ulong 	opc;
	char		title[16+1];
}nw_route;

typedef struct nw_para{
	ulong	opc24;
	ulong 	opc14;
	BYTE		pc_len;//0=14bit, 1=24bit
	BYTE		pc_type;//0= itu, 1=ansi
	
	BYTE	ansi_local14b;
	BYTE	ansi_local24b;
	BYTE		local_acn[MAX_ACN_NUM];
	nw_route routing[MAX_ROUTE];
}nw_para;

typedef struct lk_pro
{
	WORD  e1_to_linkset	__attribute__((packed));
	BYTE  e1_to_slc;//		__attribute__((packed));
	ulong e1_to_mtp3	__attribute__((packed));
	BYTE  e1_lk_type;//	__attribute__((packed));//( old struct mains Bit0:0=ss7,1=m2ua
												//Bit1:1=reserved
												//Bit2:0=MTP3,1=MTP3LITE
												//BIT3:0=server,1=client)
	WORD  e1_to_sg		__attribute__((packed));
	BYTE  e1_to_iid;//		__attribute__((packed));
	ulong remote_ip		__attribute__((packed));
	BYTE  inactive;//		__attribute__((packed));// Inactivity timer
	BYTE  inactive_tm;//	__attribute__((packed));// Allowed inactivity timeouts
	ulong e1_to_alterMTP3		__attribute__((packed));//alternative MTP3
	BYTE mtp3lite_apl_mode;
	BYTE admin_state;
	char title[16+1];
}lk_pro;

typedef struct lk_timer
{
	BYTE	t1;/* 500ms-1200ms */
	BYTE	t2;/* 700ms-2000ms */
	BYTE	t3;/* 500ms-1200ms */
	BYTE	t4;/* 500ms-1200ms */
	BYTE	t5;/* 500ms-1200ms */
	BYTE	t7;/* 1s-2s */
	BYTE	t8;/* 800ms-1200ms */
	BYTE	t12;/* 800ms-1500ms */
	BYTE	t13;/* 800ms-1500ms */
	BYTE	t14;/* 2s-3s */
	BYTE	t22;
	BYTE	t23;
}lk_timer;

typedef struct sg_para
{
	BYTE	enable;//							__attribute__((packed));
	BYTE	server;//							__attribute__((packed));
	BYTE	data_ack;//						__attribute__((packed));
	u32	ip								__attribute__((packed));
	u32	source_ip;		// client source ip, 0=getHostName, other=value
	WORD	source_port;		// client source port, 0=Radom 
        WORD    dst_port;
}sg_para;

typedef struct _ls_para
{
	int index;
	char title[16+1];
	BYTE admin_state;
	BYTE ls_state;
	BYTE nw_id;
	BYTE loopback_opt;
	ulong ls_op_pc;
	char ls_reserved[16];
	ulong ls_opc;
	
}ls_para;

typedef struct MTP3Parameter
{
	lk_pro	 lk[MAX_LK];
	lk_timer lt[MAX_LK];
	sg_para	 sg[256];
	BYTE	nw_pro;
//	ulong	ls_op_pc[MAX_LS];/* for 128 linkset */
	ls_para	ls_pro[MAX_LS];
	//char	ls_reserved[MAX_LS][16];//each linkset reserved 16 bytes for omc
	BYTE	mtp3_t10;
	BYTE	mtp3_t18;
	BYTE	mtp3_t19;
	BYTE	mtp3_t20;
	WORD	mtp3_t21;
	WORD	mtp3lite_port;
	nw_para	nw[4];
	BYTE	localAcn[MAX_ACN_NUM];
	ull		MTP3SerialNum;
	//ulong	ls_opc[MAX_LS];/*for 128 linkset opc*/
}MTP3Parameter;

typedef	struct mtp{
	ls_info		ls[MAX_LS];
	network		nw[4];
}mtp;

typedef	struct measure_of_mtp3{
	long	time_stamp;
	ulong	lk_measure1[MAX_LK][9];/* link measure oid=*.1 */
	ulong	ls_measure[MAX_LS][8];/* linkset measure oid=*.3 */
/*** traffic */
//	ulong	tf_measure1[6][20];/* traffic octets */
	ulong	tf_measure2[6][20];/* traffic MSUs */
	ulong	tf_measure5[3];
}measure_of_mtp3;

typedef	struct mtp3_csta{
	measure_of_mtp3		measure[96];
}mtp3_csta;

typedef struct heartbeat_compoent_of_mtp3
{
	BYTE	version[3];
	BYTE	state;
//	BYTE	link_state[64];
	BYTE	link_state[256];
	BYTE	linkset_state[128];
	BYTE	masterMTP3[32];
	BYTE	SubState[2];
}heartbeat_compoent_of_mtp3;

typedef struct mtp2_heartbeat
{
	BYTE	systemid;
	BYTE	moduleid;
	BYTE	timestamp[4];
	BYTE	led_ctl_code[8];
	BYTE	alarm_component;
	BYTE	alarm_code;
	BYTE	reserved;
	BYTE	l1_state;
	BYTE	l2_state[8];
	BYTE	e1_dstip[8];
	BYTE	retrieved_bsnt[8];
}mtp2_heartbeat;

typedef struct mtp3DPCIndex
{
	u_long	sortedNum;	
//	u_long	dpc[256];	
	ull		dpc[MAX_ROUTE];//dpc = (opc<<32) | dpc
	u_long	index[MAX_ROUTE];
}mtp3DPCIndex;

typedef struct mtp3_dpc_index
{
	mtp3DPCIndex	nw[4];
}mtp3_dpc_index;
extern mtp3_dpc_index	mtp3SortRoutine;

typedef struct _mtp3_state
{
	BYTE link_l1_state[MAX_LK];
	BYTE link_l2_state[MAX_LK];
	BYTE link_l3_state[MAX_LK];
	BYTE lk_configured[MAX_LK];
	BYTE lk_command[MAX_LK];
	BYTE link_type[MAX_LK];
	ulong lk_mtp3[MAX_LK];
	BYTE lk_NMTP3_ok[MAX_LK];//normal mtp3 ok
	BYTE lk_AMTP3_ok[MAX_LK];//alternative mtp3 ok
	
	BYTE lk_SpecANSI_flag[MAX_LK];
	//special ANSI, use the Signalling network testing and maintenance special message

	BYTE lsac_state[MAX_LK];
	BYTE tlac_state[MAX_LK];
	BYTE tcoc_state[MAX_LK];
	BYTE tcbc_state[MAX_LK];
	BYTE tsrc_state[MAX_LK];
	BYTE sltc_state[MAX_LK];
	BYTE tprc_state;

	BYTE MTP3WatchDog[MAX_LK];

	BYTE link_enable_sent_flag[MAX_LK];
}_mtp3_state;
extern _mtp3_state	mtp3ObjState;

typedef struct _mtp3_input
{
	BYTE lsac_input_from_l2[MAX_LK];
	BYTE lsac_input_from_sltc[MAX_LK];
	BYTE lsac_input_from_stm[MAX_LK];
	BYTE lsac_input_from_tcoc[MAX_LK];
	BYTE lsac_input_from_mgmt[MAX_LK];
	BYTE tlac_input_from_slm[MAX_LK];
	BYTE tlac_input_from_mgmt[MAX_LK];
	BYTE tlac_input_from_stm[MAX_LK];
	BYTE tlac_input_from_hmdt[MAX_LK];
	BYTE tlac_input_from_Tctl[MAX_LK];/* input from timer control center*/
	BYTE tsrc_input_from_tcoc[MAX_LK];
	BYTE tsrc_input_from_tcbc[MAX_LK];
	BYTE tsrc_input_from_stm[MAX_LK];
	BYTE tsrc_input_from_tlac[MAX_LK];
	BYTE tcoc_input_from_tsrc[MAX_LK];
	BYTE tcoc_input_from_stm[MAX_LK];
	BYTE tcoc_input_from_hmdt[MAX_LK];
	BYTE tcbc_input[MAX_LK];
	BYTE tcbc_input_from_tsrc[MAX_LK];
	BYTE sltc_input[MAX_LK];
	BYTE tprc_input;
	BYTE taprc_input[MAX_LS];
}_mtp3_input;
extern _mtp3_input	mtp3ObjInput;

typedef struct _mtp3_IPMng
{
	BYTE	mtp3_flag_new[MAX_MTP3_NUM];
	BYTE	mtp3_flag_old[MAX_MTP3_NUM];
	ulong	mtp3_flag_ip[MAX_MTP3_NUM];

	BYTE	LinkIPNum;
	ulong	LinkIP[MAX_MTP3_NUM];
	BYTE	LinkIPSubSta[MAX_MTP3_NUM][2];
}_mtp3_IPMng;

typedef struct _mtp3_dynamic_opc
{
	BYTE 	opc_num[4];
	ulong	opc[4][MTP3_MAX_DYNAMIC_OPC_PER_NW];
}mtp3_dynamic_opc;

extern _mtp3_IPMng	MTP3IPMng;
