⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-m2pa.c

📁 No7信令,我需要交换类似的代码, 请店长审核,谢谢了,急着交换,谢谢
💻 C
📖 第 1 页 / 共 5 页
字号:
 *  ------------------------------------------------------------------------- * *  M2PA Message Definitions * *  ------------------------------------------------------------------------- */#define M2PA_PPI		5#define M2PA_MESSAGE_CLASS	11#define M2PA_VERSION		1#define M2PA_MTYPE_DATA		1#define M2PA_MTYPE_STATUS	2#define M2PA_MTYPE_PROVING	3#define M2PA_MTYPE_ACK		4#define M2PA_DATA_MESSAGE	\	__constant_htonl((M2PA_VERSION<<24)|(M2PA_MESSAGE_CLASS<<8)|M2PA_MTYPE_DATA)#define M2PA_STATUS_MESSAGE	\	__constant_htonl((M2PA_VERSION<<24)|(M2PA_MESSAGE_CLASS<<8)|M2PA_MTYPE_STATUS)#define M2PA_PROVING_MESSAGE	\	__constant_htonl((M2PA_VERSION<<24)|(M2PA_MESSAGE_CLASS<<8)|M2PA_MTYPE_PROVING)#define M2PA_ACK_MESSAGE	\	__constant_htonl((M2PA_VERSION<<24)|(M2PA_MESSAGE_CLASS<<8)|M2PA_MTYPE_ACK)#define M2PA_STATUS_STREAM	0#define M2PA_DATA_STREAM	1#define M2PA_STATUS_OUT_OF_SERVICE		(__constant_htonl(0))#define M2PA_STATUS_ALIGNMENT			(__constant_htonl(1))#define M2PA_STATUS_PROVING_NORMAL		(__constant_htonl(2))#define M2PA_STATUS_PROVING_EMERGENCY		(__constant_htonl(3))#define M2PA_STATUS_IN_SERVICE			(__constant_htonl(4))#define M2PA_STATUS_PROCESSOR_OUTAGE		(__constant_htonl(5))#define M2PA_STATUS_PROCESSOR_OUTAGE_ENDED	(__constant_htonl(6))#define M2PA_STATUS_BUSY			(__constant_htonl(7))#define M2PA_STATUS_BUSY_ENDED			(__constant_htonl(8))#define M2PA_STATUS_INVALID			(__constant_htonl(9))/* *  ------------------------------------------------------------------------- * *  Definitions of signals and events. * *  ------------------------------------------------------------------------- */#define OUT_OF_SERVICE		1   /* M2PA Status signals */#define ALIGNMENT		2#define PROVING_NORMAL		3#define PROVING_EMERG		4#define IN_SERVICE		5#define PROCESSOR_OUTAGE	6#define PROCESSOR_ENDED		7#define BUSY			8#define BUSY_ENDED		9#define INVALID_STATUS		10#define DATA			20  /* Protocol Tester (PT) signals and events */#define PROVING			21#define ACK			22#define TX_BREAK		30#define TX_MAKE			31#define BAD_ACK			32#define MSU_TOO_SHORT		29#if 0#define FISU			20#define FISU_S			21#define FISU_CORRUPT		23#define FISU_CORRUPT_S		24#define MSU_SEVEN_ONES		27#define MSU_TOO_LONG		28#define FISU_FISU_1FLAG		60#define FISU_FISU_2FLAG		61#define MSU_MSU_1FLAG		62#define MSU_MSU_2FLAG		63#endif#define TIMEOUT			40  /* TIMER events */#define COUNT			41#define TRIES			39#define ETC			49#if 0#define SIB_S			42#endif#define IUT_IN_SERVICE		43  /* Implementation Under Test (IUT) events */#define IUT_OUT_OF_SERVICE	44#define IUT_RPO			45#define IUT_RPR			46#define IUT_DATA		47#define POWER_ON		200 /* Implementation Under Test (IUT) signals */#define START			201#define STOP			202#define LPO			203#define LPR			204#define EMERG			205#define CEASE			206#define SEND_MSU		207#define SEND_MSU_S		208#define CONG_A			209#define CONG_D			210#define NO_CONG			211#define CLEARB			212#define CONN_REQ		300 /* MGMT controls */#define CONN_IND		301#define CONN_RES		302#define CONN_CON		303#define DISCON_REQ		304#define DISCON_IND		305#define INFO_REQ		306#define INFO_ACK		307#define BIND_REQ		308#define BIND_ACK		309#define OK_ACK			310#define ERROR_ACK		311#define OPTMGMT_REQ		312#define ENABLE_REQ		400#define ENABLE_CON		401#define DISABLE_REQ		402#define DISABLE_CON		403#define ERROR_IND		404#define UNKNOWN			48#define NO_MSG			-1/* *  ------------------------------------------------------------------------- * *  Globals * *  ------------------------------------------------------------------------- */static int	state	 = 0;static int	count	 = 0;static int	tries	 = 0;static int	expand	 = 0;static int	debug	 = 0;static int	verbose	 = 0;static long	beg_time = 0;static size_t	nacks	 = 1;static unsigned long iut_options = 0;/* listening file descriptor */static int		mgm_fd = 0;static ulong		mgm_tok = 0;static ulong		mgm_seq = 0;static unsigned char	mgm_buf[BUFSIZE];/* protocol tester file descriptor */static int		 pt_fd = 0;static ulong		 pt_tok = 0;static ulong		 pt_seq = 0;static unsigned char	 pt_buf[BUFSIZE];static unsigned char	 pt_fib = 0x80;static unsigned char	 pt_fsn = 0x7f;static unsigned char	 pt_bib = 0x80;static unsigned char	 pt_bsn = 0x7f;//static unsigned char	 pt_li  = 0;//static unsigned char	 pt_sio = 0;/* implementation under test file descriptor */static int		iut_fd = 0;static ulong		iut_tok = 0;static ulong		iut_seq = 0;static unsigned char	iut_buf[BUFSIZE];static unsigned char	iut_fib = 0x80;static unsigned char	iut_fsn = 0x7f;static unsigned char	iut_bib = 0x80;static unsigned char	iut_bsn = 0x7f;#define MSU_LEN 35static int	msu_len = MSU_LEN;/* some globals for compressing events */static int	oldpsb = 0; /* last pt sequence number and indicator bits	*/static int	oldmsg = 0; /* last pt message			*/static int	cntmsg = 0; /* repeats of pt message		*/static int	oldact = 0; /* last iut action			*/static int	cntact = 0; /* repeats of iut action		*/static int	oldisb = 0; /* last iut sequence number and indicator bits	*/static int	oldret = 0;static int	cntret = 0;static int	oldprm = 0;static int	cntprm = 0;static int	oldmgm = 0; /* last management control		*/static int	cntmgm = 0; /* repeats of management control	*/union primitives{	ulong			prim;	union LMI_primitives	lmi;	union SDL_primitives	sdl;	union SDT_primitives	sdt;	union SL_primitives	sl;	union N_primitives	npi;};/* *  ------------------------------------------------------------------------- * *  Send messages from the Protocol Tester * *  ------------------------------------------------------------------------- */#define send pt_sendstatic int send(int msg){	uint32_t status = 0;	char cbuf[BUFSIZE];	struct strbuf ctrl = { sizeof(*  cbuf), 0,   cbuf };	struct strbuf data = { sizeof(*pt_buf), 0, pt_buf };	union primitives *p = (union primitives *)cbuf;	if ( msg != oldmsg )	{		oldmsg = msg;		if ( verbose )		{		if ( cntmsg )		{			printf("             Ct=%5d                                               \n",cntmsg+1);			FFLUSH(stdout);		}		}		cntmsg = 0;	}	else	if ( !expand ) cntmsg++;	switch ( msg )	{		case ALIGNMENT:			if ( !cntmsg )			{				printf("              ALIGNMENT  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_ALIGNMENT;			goto pt_status_putmsg;		case PROVING_NORMAL:			if ( !cntmsg )			{				printf("         PROVING-NORMAL  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_PROVING_NORMAL;			goto pt_status_putmsg;		case PROVING_EMERG:			if ( !cntmsg )			{				printf("      PROVING-EMERGENCY  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_PROVING_EMERGENCY;			goto pt_status_putmsg;		case OUT_OF_SERVICE:			if ( !cntmsg )			{				printf("         OUT-OF-SERVICE  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_OUT_OF_SERVICE;			goto pt_status_putmsg;		case IN_SERVICE:			if ( !cntmsg )			{				printf("             IN-SERVICE  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_IN_SERVICE;			goto pt_status_putmsg;		case PROCESSOR_OUTAGE:			if ( !cntmsg )			{				printf("       PROCESSOR-OUTAGE  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_PROCESSOR_OUTAGE;			goto pt_status_putmsg;		case PROCESSOR_ENDED:			if ( !cntmsg )			{				printf(" PROCESSOR-OUTAGE-ENDED  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_PROCESSOR_OUTAGE_ENDED;			goto pt_status_putmsg;		case BUSY_ENDED:			if ( !cntmsg )			{				printf("             BUSY-ENDED  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_BUSY_ENDED;			goto pt_status_putmsg;		case BUSY:			if ( !cntmsg )			{				printf("                   BUSY  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_BUSY;			goto pt_status_putmsg;		case COUNT:			printf("           Ct = %5d    ----------------->                         \n",count);			return SUCCESS;		case TRIES:			printf("       %5d iterations  ----------------->                         \n",tries);			FFLUSH(stdout);			return SUCCESS;		case ETC:			printf("                    .    ----------------->                         \n");			printf("                    .    ----------------->                         \n");			printf("                    .    ----------------->                         \n");			FFLUSH(stdout);			return SUCCESS;		case INVALID_STATUS:			if ( !cntmsg )			{				printf("       [INVALID-STATUS]  ----------------->                         \n");				FFLUSH(stdout);			}			status = M2PA_STATUS_INVALID;			goto pt_status_putmsg;pt_status_putmsg:			data.len = 3*sizeof(uint32_t);			ctrl.len = sizeof(p->npi.data_req)+sizeof(ptconf.qos_data);			((uint32_t *)pt_buf)[0] = M2PA_STATUS_MESSAGE;			((uint32_t *)pt_buf)[1] = htonl(data.len);			((uint32_t *)pt_buf)[2] = status;			p->npi.type = N_DATA_REQ;			p->npi.data_req.DATA_xfer_flags = 0;			bcopy(&ptconf.qos_data, (&p->npi.data_req)+1, sizeof(ptconf.qos_data));			if ( putmsg(pt_fd, &ctrl, &data, 0) < 0 )			{				printf("****ERROR: putmsg failed!\n");				printf("           %s: %s\n",__FUNCTION__,strerror(errno));				FFLUSH(stdout);				return FAILURE;			}			return SUCCESS;		case MSU_TOO_SHORT:			printf("          1 byte   DATA  ----------------->                         \n");			FFLUSH(stdout);			msu_len = 1;			goto send_data;		case DATA:			if ( msu_len > BUFSIZE-10 ) msu_len = BUFSIZE-10;			if ( !cntmsg )			{				printf("                   DATA  ----------------->                         \n");				FFLUSH(stdout);			}send_data:			data.len = 2*sizeof(uint32_t) + msu_len + 1;			ctrl.len = sizeof(p->npi.data_req)+sizeof(ptconf.qos_data);			((uint32_t *)pt_buf)[0] = M2PA_DATA_MESSAGE;			((uint32_t *)pt_buf)[1] = htonl(data.len);			memset(&(((uint32_t *)pt_buf)[2]), 'B', msu_len+1);			memset(&(((uint32_t *)pt_buf)[2]), 0, 1);			p->npi.type = N_DATA_REQ;#ifdef DRAFT3			p->npi.data_req.DATA_xfer_flags = N_RC_FLAG;#else			p->npi.data_req.DATA_xfer_flags = 0;#endif			bcopy(&ptconf.qos_data, (&p->npi.data_req)+1, sizeof(ptconf.qos_data));			if ( putmsg(pt_fd, &ctrl, &data, 0) < 0 )			{				printf("****ERROR: putmsg failed!\n");				printf("           %s: %s\n",__FUNCTION__,strerror(errno));				FFLUSH(stdout);				return FAILURE;			}			return SUCCESS;		case ACK:		case BAD_ACK:			printf("                    ACK  ----------------->                         \n");			FFLUSH(stdout);			data.len = 3*sizeof(uint32_t);			ctrl.len = sizeof(p->npi.data_req)+sizeof(ptconf.qos_data);			((uint32_t *)pt_buf)[0] = M2PA_ACK_MESSAGE;			((uint32_t *)pt_buf)[1] = htonl(data.len);			((uint32_t *)pt_buf)[2] = htonl(nacks);			p->npi.type = N_EXDATA_REQ;			bcopy(&ptconf.qos_data, (&p->npi.exdata_req)+1, sizeof(ptconf.qos_data));			if ( putmsg(pt_fd, &ctrl, &data, 0) < 0 )			{				printf("****ERROR: putmsg failed!\n");				printf("           %s: %s\n",__FUNCTION__,strerror(errno));				FFLUSH(stdout);				return FAILURE;			}			return SUCCESS;		case STOP:			printf("                  :stop                                             \n");			FFLUSH(stdout);			return SUCCESS;		case POWER_ON:			printf("              :power on                                             \n");			FFLUSH(stdout);			return SUCCESS;		case LPO:			printf("               :set lpo                                             \n");			FFLUSH(stdout);			return SUCCESS;		case LPR:			printf("             :clear lpo                                             \n");			FFLUSH(stdout);			return SUCCESS;		case EMERG:			printf("             :set emerg                                             \n");			FFLUSH(stdout);			return SUCCESS;		case CEASE:			printf("           :clear emerg                                             \n");			FFLUSH(stdout);			return SUCCESS;		case CONG_A:			printf("        :make congested                                             \n");			FFLUSH(stdout);			return SUCCESS;		case CONG_D:			printf("        :make congested                                             \n");			FFLUSH(stdout);			return SUCCESS;		case NO_CONG:			printf("       :clear congested                                             \n");			FFLUSH(stdout);			return SUCCESS;		case START:			printf("                 :start                                             \n");			FFLUSH(stdout);			return SUCCESS;		case TX_BREAK:			printf("              :tx break                                             \n");			FFLUSH(stdout);			p->npi.type = N_DISCON_REQ;			p->npi.discon_req.DISCON_reason = 0;			p->npi.discon_req.RES_length = 0;			p->npi.discon_req.RES_offset = 0;			p->npi.discon_req.SEQ_number = 0;			ctrl.len = sizeof(N_discon_req_t);			goto pt_control_putmsg;		case TX_MAKE:			return SUCCESS;		case ENABLE_REQ:			if ( verbose )			{				printf("                :enable                                             \n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -