📄 test-m2pa.c
字号:
/***************************************************************************** @(#) test-m2pa.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:16:14 ----------------------------------------------------------------------------- Copyright (c) 2001 OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@dallas.net> All Rights Reserved. Unauthorized distribution or duplication is prohibited. This software and related documentation is protected by copyright and distributed under licenses restricting its use, copying, distribution and decompilation. No part of this software or related documentation may be reproduced in any form by any means without the prior written authorization of the copyright holder, and licensors, if any. The recipient of this document, by its retention and use, warrants that the recipient will protect this information and keep it confidential, and will not disclose the information contained in this document without the written permission of its owner. The author reserves the right to revise this software and documentation for any reason, including but not limited to, conformity with standards promulgated by various agencies, utilization of advances in the state of the technical arts, or the reflection of changes in the design of any techniques, or procedures embodied, described, or referred to herein. The author is under no obligation to provide any feature listed herein. ----------------------------------------------------------------------------- U.S. GOVERNMENT RESTRICTED RIGHTS. If you are licensing this Software on behalf of the U.S. Government ("Government"), the following provisions apply to you. If the Software is supplied by the Department of Defense ("DoD"), it is classified as "Commercial Computer Software" under paragraph 252.227-7014 of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any successor regulations) and the Government is acquiring only the license rights granted herein (the license rights customarily provided to non-Government users). If the Software is supplied to any unit or agency of the Government other than DoD, it is classified as "Restricted Computer Software" and the Government's rights in the Software are defined in paragraph 52.227-19 of the Federal Acquisition Regulations ("FAR") (or any success regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Last Modified 2001/12/11 13:16:14 by <bidulock@openss7.org> *****************************************************************************/#ident "@(#) test-m2pa.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:16:14"static char const ident[] = "test-m2pa.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:16:14";#include <stropts.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/poll.h>#include <linux/poll.h>#include <stdio.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <signal.h>#include <features.h>#include <limits.h>#include <stdint.h>#include <sys/types.h>#include <asm/byteorder.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#include <ss7/devi.h>#include <ss7/devi_ioctl.h>#include <ss7/sdti.h>#include <ss7/sdti_ioctl.h>#include <ss7/sli.h>#include <ss7/sli_ioctl.h>#include <sys/npi.h>#include <sys/npi_sctp.h>#define SUCCESS 0#define FAILURE 1#define INCONCLUSIVE -1#define NOTAPPLICABLE -2#define SCRIPTERROR -3#define BUFSIZE 300#define FFLUSH(_stream) fflush((_stream))#define SHORT_WAIT 10#define NORMAL_WAIT 100#define LONG_WAIT 500#define MAXIMUM_WAIT 1000#ifndef HZ#define HZ 100#endif/* * ------------------------------------------------------------------------- * * Configuration * * ------------------------------------------------------------------------- */typedef struct addr{ uint16_t port __attribute__((packed)); uint32_t addr[3] __attribute__((packed));} addr_t;static struct{ addr_t loc; addr_t rem; N_qos_sel_info_sctp_t qos; N_qos_sel_data_sctp_t qos_data;} ptconf ={ { __constant_htons(10001), { __constant_htonl(0x7f000001), __constant_htonl(0x7f000002), __constant_htonl(0x7f000003) } }, /* loc */ { __constant_htons(10000), { __constant_htonl(0x7f000001), __constant_htonl(0x7f000002), __constant_htonl(0x7f000003) } }, /* rem */ { N_QOS_SEL_INFO_SCTP, /* n_qos_type */ 2, /* i_streams */ 2, /* o_streams */ 5, /* ppi */ 0, /* sid */ -1L, /* max_in */ -1L, /* max_retran */ -1L, /* ck_life */ -1L, /* ck_inc */ -1L, /* hmac */ -1L, /* thrott */ -1L, /* max_sack */ -1L, /* rto_ini */ -1L, /* rto_min */ -1L, /* rto_max */ -1L, /* rtx_path */ -1L, /* hb_itvl */ 0 /* options */ }, { N_QOS_SEL_DATA_SCTP, /* n_qos_type */ 5, /* ppi */ 1, /* sid */ 0, /* ssn */ 0, /* tsn */ 0 /* more */ }};static struct{ addr_t loc; addr_t rem; N_qos_sel_info_sctp_t qos; dev_ulong ifclock; lmi_option_t opt; sdl_config_t sdl; sdt_config_t sdt; sl_config_t sl;} iutconf ={ { __constant_htons(10000), { __constant_htonl(0x7f000001), __constant_htonl(0x7f000002), __constant_htonl(0x7f000003) } }, /* loc */ { __constant_htons(10001), { __constant_htonl(0x7f000001), __constant_htonl(0x7f000002), __constant_htonl(0x7f000003) } }, /* rem */ { N_QOS_SEL_INFO_SCTP, /* n_qos_type */ 2, /* i_streams */ 2, /* o_streams */ 5, /* ppi */ 0, /* sid */ -1L, /* max_in */ -1L, /* max_retran */ -1L, /* ck_life */ -1L, /* ck_inc */ -1L, /* hmac */ -1L, /* thrott */ -1L, /* max_sack */ -1L, /* rto_ini */ -1L, /* rto_min */ -1L, /* rto_max */ -1L, /* rtx_path */ -1L, /* hb_itvl */ 0 /* options */ }, /* qos */ DEV_CLOCK_SHAPER, /* ifclock */ { SS7_PVAR_ITUT_96, /* pvar */ 0 /* popt */ }, /* opt */ { 16, /* N */ 272 /* m */ }, /* sdl */ { 100*HZ/1000, /* t8 - T8 timeout */ 4, /* Tin - AERM normal proving threshold */ 1, /* Tie - AERM emergency proving threshold */ 64, /* T - SUERM error threshold */ 256, /* D - SUERM error rate parameter */ 577169, /* Te - EIM error threshold */ 9308000, /* De - EIM correct decrement */ 144292000 /* Ue - EIM error increment */ }, /* sdt */ { 45*HZ, /* t1 - timer t1 duration (ticks) */ 5*HZ, /* t2 - timer t2 duration (ticks) */ 20*HZ, /* t2l - timer t2l duration (ticks) */ 100*HZ, /* t2h - timer t2h duration (ticks) */ 1*HZ, /* t3 - timer t3 duration (ticks) */ 8*HZ, /* t4n - timer t4n duration (ticks) */ 500*HZ/1000, /* t4e - timer t4e duration (ticks) */ 100*HZ/1000, /* t5 - timer t5 duration (ticks) */ 4*HZ, /* t6 - timer t6 duration (ticks) */ 1*HZ, /* t7 - timer t7 duration (ticks) */ 3, /* rb_abate - RB cong abatement (#msgs) */ 6, /* rb_accept - RB cong onset accept (#msgs) */ 9, /* rb_discard - RB cong discard (#msgs) */ 128*272, /* tb_abate_1 - lev 1 cong abate (#bytes) */ 256*272, /* tb_onset_1 - lev 1 cong onset (#bytes) */ 384*272, /* tb_discd_1 - lev 1 cong discard (#bytes) */ 512*272, /* tb_abate_2 - lev 1 cong abate (#bytes) */ 640*272, /* tb_onset_2 - lev 1 cong onset (#bytes) */ 768*272, /* tb_discd_2 - lev 1 cong discard (#bytes) */ 896*272, /* tb_abate_3 - lev 1 cong abate (#bytes) */ 1024*272, /* tb_onset_3 - lev 1 cong onset (#bytes) */ 1152*272, /* tb_discd_3 - lev 1 cong discard (#bytes) */ 127, /* N1 - PCR/RTBmax messages (#msg) */ 8192, /* N2 - PCR/RTBmax octets (#bytes) */ 5 /* M - IAC normal proving periods */ } /* sl */};static struct{ addr_t loc; addr_t rem; N_qos_sel_info_sctp_t qos;} mgmconf ={ { __constant_htons(10001), { __constant_htonl(0x7f000001), __constant_htonl(0x7f000002), __constant_htonl(0x7f000003) } }, /* loc */ { __constant_htons(10000), { __constant_htonl(0x7f000001), __constant_htonl(0x7f000002), __constant_htonl(0x7f000003) } }, /* rem */ { N_QOS_SEL_INFO_SCTP, /* n_qos_type */ 2, /* i_streams */ 2, /* o_streams */ 5, /* ppi */ 0, /* sid */ -1L, /* max_in */ -1L, /* max_retran */ -1L, /* ck_life */ -1L, /* ck_inc */ -1L, /* hmac */ -1L, /* thrott */ -1L, /* max_sack */ -1L, /* rto_ini */ -1L, /* rto_min */ -1L, /* rto_max */ -1L, /* rtx_path */ -1L, /* hb_itvl */ 0 /* options */ } /* qos */};/* * ------------------------------------------------------------------------- * * Timer Functions * * ------------------------------------------------------------------------- *//* * Timer values for tests: each timer has a low range (minus error margin) and * a high range (plus error margin). */typedef struct timer_range{ long lo; long hi;} timer_range_t;enum { t1 = 0, t2, t3, t4n, t4e, t5, t6, t7, tmax };static timer_range_t timer[tmax] ={ { 40000, 50000 }, /* Timer T1 30000 */ { 5000, 150000 }, /* Timer T2 5000 */ { 1000, 1500 }, /* Timer T3 100 */ { 7500, 9500 }, /* Timer T4n 3000 */ { 400, 600 }, /* Timer T4e 50 */ { 125, 125 }, /* Timer T5 10 */ { 3000, 6000 }, /* Timer T6 300 */ { 500, 2000 } /* Timer T7 50 */};long test_start = 0;/* * Return the current time in milliseconds. */static long milliseconds(char *t){ long ret; struct timeval now; printf(" ! \n"); printf(" ! %-6s \n",t); printf(" ! \n"); FFLUSH(stdout); gettimeofday(&now, NULL); if ( !test_start ) /* avoid blowing over precision */ test_start = now.tv_sec; ret = (now.tv_sec - test_start) * 1000; ret += (now.tv_usec + 500L) / 1000; return ret;}/* * Check the current time against the beginning time provided as an argnument * and see if the time inverval falls between the low and high values for the * timer as specified by arguments. Return SUCCESS if the interval is within * the allowable range and FAILURE otherwise. */static int check_time(const char* t, long beg, long lo, long hi){ long i; struct timeval now; if ( gettimeofday(&now, NULL) ) { printf("****ERROR: gettimeofday\n"); printf(" %s: %s\n",__FUNCTION__,strerror(errno)); FFLUSH(stdout); return FAILURE; } i = (now.tv_sec - test_start) * 1000; i += (now.tv_usec + 500L)/1000; i -= beg; printf(" check timeout %-3s(%4ld<=%4ld<=%6ld)\n",t,lo-100,i,hi+100); FFLUSH(stdout); if ( lo - 100 <= i && i <= hi + 100 ) return SUCCESS; else return FAILURE;}static int timer_timeout = 0;static void timer_handler(int signum){ if ( signum == SIGALRM ) timer_timeout = 1; return;}static int timer_sethandler(void){ sigset_t mask; struct sigaction act; act.sa_handler = timer_handler; act.sa_flags = SA_RESTART|SA_ONESHOT; act.sa_restorer = NULL; sigemptyset(&act.sa_mask); if ( sigaction(SIGALRM, &act, NULL) ) return FAILURE; sigemptyset(&mask); sigaddset(&mask,SIGALRM); sigprocmask(SIG_UNBLOCK,&mask,NULL); return SUCCESS;}/* * Start an interval timer as the overall test timer. */static int start_tt(long duration){ struct itimerval setting = { { 0, 0 }, { duration/1000, (duration%1000)*1000 } }; if ( timer_sethandler() ) return FAILURE; if ( setitimer(ITIMER_REAL, &setting, NULL) ) return FAILURE; timer_timeout = 0; return SUCCESS;}/* * Stop overall test timer. */static int stop_tt(void){ sigset_t mask; struct sigaction act; act.sa_handler = SIG_DFL; act.sa_flags = 0; act.sa_restorer = NULL; sigemptyset(&act.sa_mask); if ( sigaction(SIGALRM, &act, NULL) ) return FAILURE; timer_timeout = 0; sigemptyset(&mask); sigaddset(&mask,SIGALRM); sigprocmask(SIG_BLOCK,&mask,NULL); return SUCCESS;}/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -