📄 test-m2pa.c
字号:
* * Configuration * * ------------------------------------------------------------------------- */static int ss7_pvar = SS7_PVAR_ITUT_00;struct test_stats { sdl_stats_t sdl; sdt_stats_t sdt; sl_stats_t sl;} iutstat;#if TEST_M2PA#define M2PA_VERSION_DRAFT3 0x30#define M2PA_VERSION_DRAFT3_1 0x31#define M2PA_VERSION_DRAFT4 0x40#define M2PA_VERSION_DRAFT4_1 0x41#define M2PA_VERSION_DRAFT4_9 0x49#define M2PA_VERSION_DRAFT5 0x50#define M2PA_VERSION_DRAFT5_1 0x51#define M2PA_VERSION_DRAFT6 0x60#define M2PA_VERSION_DRAFT6_1 0x61#define M2PA_VERSION_DRAFT6_9 0x69#define M2PA_VERSION_DRAFT7 0x70#define M2PA_VERSION_DRAFT9 0x90#define M2PA_VERSION_DRAFT10 0xa0#define M2PA_VERSION_DRAFT11 0xb0#define M2PA_VERSION_RFC4165 0xc1#define M2PA_VERSION_DEFAULT M2PA_VERSION_RFC4165static int m2pa_version = M2PA_VERSION_DEFAULT;struct { N_qos_sel_info_sctp_t info; N_qos_sel_data_sctp_t data; N_qos_sel_conn_sctp_t conn;} qos[3] = { { { 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 */ },}, { { 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 */ },}, {},};#endif /* TEST_M2PA */struct test_config { lmi_option_t opt; sdl_config_t sdl; sdt_config_t sdt; sl_config_t sl;} iutconf = { { SS7_PVAR_ITUT_96, /* pvar */ 0, /* popt */ }, /* opt */ { .ifname = NULL, /* */ .ifflags = 0, /* */#if TEST_X400 || TEST_M2UA .iftype = SDL_TYPE_DS0, /* */ .ifrate = 64000, /* */ .ifgtype = SDL_GTYPE_NONE, /* */ .ifgrate = 0, /* */ .ifmode = SDL_MODE_NONE, /* */#endif /* TEST_X400 */#if TEST_M2PA .iftype = SDL_TYPE_PACKET, /* */ .ifrate = 10000000, /* */ .ifgtype = SDL_GTYPE_SCTP, /* */ .ifgrate = 10000000, /* */ .ifmode = SDL_MODE_PEER, /* */#endif /* TEST_M2PA */ .ifgmode = SDL_GMODE_NONE, /* */ .ifgcrc = SDL_GCRC_NONE, /* */ .ifclock = SDL_CLOCK_NONE, /* */ .ifcoding = SDL_CODING_NONE, /* */ .ifframing = SDL_FRAMING_NONE, /* */ .ifblksize = 0, /* */ .ifleads = 0, /* */ .ifbpv = 0, /* */ .ifalarms = 0, /* */ .ifrxlevel = 0, /* */ .iftxlevel = 0, /* */ .ifsync = 0, /* */ }, /* sdl */ { .t8 = 100, /* t8 - T8 timeout (milliseconds) */ .Tin = 4, /* Tin - AERM normal proving threshold */ .Tie = 1, /* Tie - AERM emergency proving threshold */ .T = 64, /* T - SUERM error threshold */ .D = 256, /* D - SUERM error rate parameter */ .Te = 577169, /* Te - EIM error threshold */ .De = 9308000, /* De - EIM correct decrement */ .Ue = 144292000, /* Ue - EIM error increment */ .N = 16, /* N */ .m = 272, /* m */ .b = 64, /* b */ .f = SDT_FLAGS_ONE, /* f */ }, /* sdt */ { .t1 = 45 * 1000, /* t1 - timer t1 duration (milliseconds) */ .t2 = 5 * 1000, /* t2 - timer t2 duration (milliseconds) */ .t2l = 20 * 1000, /* t2l - timer t2l duration (milliseconds) */ .t2h = 100 * 1000, /* t2h - timer t2h duration (milliseconds) */ .t3 = 1 * 1000, /* t3 - timer t3 duration (milliseconds) */ .t4n = 8 * 1000, /* t4n - timer t4n duration (milliseconds) */ .t4e = 500 * 1000 / 1000, /* t4e - timer t4e duration (milliseconds) */ .t5 = 125 * 1000 / 1000, /* t5 - timer t5 duration (milliseconds) */ .t6 = 4 * 1000, /* t6 - timer t6 duration (milliseconds) */ .t7 = 2 * 1000, /* t7 - timer t7 duration (milliseconds) */ .rb_abate = 3, /* rb_abate - RB cong abatement (#msgs) */ .rb_accept = 6, /* rb_accept - RB cong onset accept (#msgs) */ .rb_discard = 9, /* rb_discard - RB cong discard (#msgs) */ .tb_abate_1 = 128 * 272, /* tb_abate_1 - lev 1 cong abate (#bytes) */ .tb_onset_1 = 256 * 272, /* tb_onset_1 - lev 1 cong onset (#bytes) */ .tb_discd_1 = 384 * 272, /* tb_discd_1 - lev 1 cong discard (#bytes) */ .tb_abate_2 = 512 * 272, /* tb_abate_2 - lev 1 cong abate (#bytes) */ .tb_onset_2 = 640 * 272, /* tb_onset_2 - lev 1 cong onset (#bytes) */ .tb_discd_2 = 768 * 272, /* tb_discd_2 - lev 1 cong discard (#bytes) */ .tb_abate_3 = 896 * 272, /* tb_abate_3 - lev 1 cong abate (#bytes) */ .tb_onset_3 = 1024 * 272, /* tb_onset_3 - lev 1 cong onset (#bytes) */ .tb_discd_3 = 1152 * 272, /* tb_discd_3 - lev 1 cong discard (#bytes) */ .N1 = 31, /* N1 - PCR/RTBmax messages (#msg) */ .N2 = 8192, /* N2 - PCR/RTBmax octets (#bytes) */ .M = 5 /* M - IAC normal proving periods */} /* sl */ };struct test_config *config = &iutconf;struct test_stats *stats = &iutstat;/* * ------------------------------------------------------------------------- * * Timer Functions * * ------------------------------------------------------------------------- *//* * Timer values for tests: each timer has a low range (minus error margin) * and a high range (plus error margin). */static long timer_scale = 1;#define TEST_TIMEOUT 5000typedef struct timer_range { long lo; long hi; char *name;} timer_range_t;enum { t1 = 0, t2, t3, t4n, t4e, t5, t6, t7, tmax };static timer_range_t timer[tmax] = { {40000, 50000, "T1"}, /* Timer T1 30000 */ {5000, 150000, "T2"}, /* Timer T2 5000 */ {1000, 1500, "T3"}, /* Timer T3 100 */ {7500, 9500, "T4(Pn)"}, /* Timer T4n 3000 */ {200, 800, "T4(Pe)"}, /* Timer T4e 50 */ {125, 125, "T5"}, /* Timer T5 10 */ {3000, 6000, "T6"}, /* Timer T6 300 */ {500, 2000, "T7"} /* Timer T7 50 */};long test_start = 0;static int state = 0;static const char *failure_string = NULL;#define __stringify_1(x) #x#define __stringify(x) __stringify_1(x)#define FAILURE_STRING(string) "[" __stringify(__LINE__) "] " string#if 1#undef lockf#define lockf(x,y,z) 0#endif/* * Return the current time in milliseconds. */static longdual_milliseconds(int child, int t1, int t2){ long ret; struct timeval now; static const char *msgs[] = { " %1$-6.6s ! %2$3ld.%3$03ld <= %4$-2.2s <= %5$3ld.%6$03ld : [%7$d:%8$03d]\n", " : %2$3ld.%3$03ld <= %4$-2.2s <= %5$3ld.%6$03ld ! %1$-6.6s [%7$d:%8$03d]\n", " : %2$3ld.%3$03ld <= %4$-2.2s <= %5$3ld.%6$03ld ! : %1$-6.6s [%7$d:%8$03d]\n", " ! %1$-6.6s %2$3ld.%3$03ld <= %4$-2.2s <= %5$3ld.%6$03ld ! [%7$d:%8$03d]\n", }; static const char *blank[] = { " ! : \n", " : ! \n", " : ! : \n", " ! ! \n", }; static const char *plus[] = { " + ! : \n", " : ! + \n", " : ! : + \n", " ! + ! \n", }; 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 + 500) / 1000; if (show && verbose > 0) { dummy = lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, blank[child]); fprintf(stdout, msgs[child], timer[t1].name, timer[t1].lo / 1000, timer[t1].lo - ((timer[t1].lo / 1000) * 1000), timer[t1].name, timer[t1].hi / 1000, timer[t1].hi - ((timer[t1].hi / 1000) * 1000), child, state); fprintf(stdout, plus[child]); fprintf(stdout, msgs[child], timer[t2].name, timer[t2].lo / 1000, timer[t2].lo - ((timer[t2].lo / 1000) * 1000), timer[t2].name, timer[t2].hi / 1000, timer[t2].hi - ((timer[t2].hi / 1000) * 1000), child, state); fprintf(stdout, blank[child]); fflush(stdout); dummy = lockf(fileno(stdout), F_ULOCK, 0); } return ret;}/* * Return the current time in milliseconds. */static longmilliseconds(int child, int t){ long ret; struct timeval now; static const char *msgs[] = { " %1$-6.6s ! %2$3ld.%3$03ld <= %4$-2.2s <= %5$3ld.%6$03ld : [%7$d:%8$03d]\n", " : %2$3ld.%3$03ld <= %4$-2.2s <= %5$3ld.%6$03ld ! %1$-6.6s [%7$d:%8$03d]\n", " : %2$3ld.%3$03ld <= %4$-2.2s <= %5$3ld.%6$03ld ! : %1$-6.6s [%7$d:%8$03d]\n", " ! %1$-6.6s %2$3ld.%3$03ld <= %4$-2.2s <= %5$3ld.%6$03ld ! [%7$d:%8$03d]\n", }; static const char *blank[] = { " ! : \n", " : ! \n", " : ! : \n", " ! ! \n", }; 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 + 500) / 1000; if (show && verbose > 0) { dummy = lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, blank[child]); fprintf(stdout, msgs[child], timer[t].name, timer[t].lo / 1000, timer[t].lo - ((timer[t].lo / 1000) * 1000), timer[t].name, timer[t].hi / 1000, timer[t].hi - ((timer[t].hi / 1000) * 1000), child, state); fprintf(stdout, blank[child]); fflush(stdout); dummy = lockf(fileno(stdout), F_ULOCK, 0); } 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 intcheck_time(int child, const char *t, long beg, long lo, long hi){ long i; struct timeval now; static const char *msgs[] = { " check %1$-6.6s ? [%2$3ld.%3$03ld <= %4$3ld.%5$03ld <= %6$3ld.%7$03ld] | [%8$d:%9$03d]\n", " | [%2$3ld.%3$03ld <= %4$3ld.%5$03ld <= %6$3ld.%7$03ld] ? %1$-6.6s check [%8$d:%9$03d]\n", " | [%2$3ld.%3$03ld <= %4$3ld.%5$03ld <= %6$3ld.%7$03ld]? | %1$-6.6s check [%8$d:%9$03d]\n", " check %1$-6.6s ? [%2$3ld.%3$03ld <= %4$3ld.%5$03ld <= %6$3ld.%7$03ld] ? [%8$d:%9$03d]\n", }; if (gettimeofday(&now, NULL)) { printf("****ERROR: gettimeofday\n"); printf(" %s: %s\n", __FUNCTION__, strerror(errno)); fflush(stdout); return __RESULT_FAILURE; } i = (now.tv_sec - test_start) * 1000; i += (now.tv_usec + 500) / 1000; i -= beg; if (show && verbose > 0) { dummy = lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, msgs[child], t, (lo - 100) / 1000, (lo - 100) - (((lo - 100) / 1000) * 1000), i / 1000, i - ((i / 1000) * 1000), (hi + 100) / 1000, (hi + 100) - (((hi + 100) / 1000) * 1000), child, state); fflush(stdout); dummy = lockf(fileno(stdout), F_ULOCK, 0); } if (lo - 100 <= i && i <= hi + 100) return __RESULT_SUCCESS; else return __RESULT_FAILURE;}static inttime_event(int child, int event){ static const char *msgs[] = { " ! %11.6g | <%d:%03d>\n", " | %11.6g ! <%d:%03d>\n", " | %11.6g ! | <%d:%03d>\n", " ! %11.6g ! <%d:%03d>\n", }; if ((verbose > 4 && show) || (verbose > 5 && show_msg)) { float t, m; struct timeval now; gettimeofday(&now, NULL); if (!test_start) test_start = now.tv_sec; t = (now.tv_sec - test_start); m = now.tv_usec; m = m / 1000000; t += m; dummy = lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, msgs[child], t, child, state); fflush(stdout); dummy = lockf(fileno(stdout), F_ULOCK, 0); } return (event);}static int timer_timeout = 0;static int last_signum = 0;static voidsignal_handler(int signum){ last_signum = signum; if (signum == SIGALRM) timer_timeout = 1; return;}static intstart_signals(void){ sigset_t mask; struct sigaction act; act.sa_handler = signal_handler;// act.sa_flags = SA_RESTART | SA_ONESHOT; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, NULL)) return __RESULT_FAILURE; if (sigaction(SIGPOLL, &act, NULL)) return __RESULT_FAILURE; if (sigaction(SIGURG, &act, NULL)) return __RESULT_FAILURE; if (sigaction(SIGPIPE, &act, NULL)) return __RESULT_FAILURE; if (sigaction(SIGHUP, &act, NULL)) return __RESULT_FAILURE; sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigaddset(&mask, SIGPOLL); sigaddset(&mask, SIGURG); sigaddset(&mask, SIGPIPE); sigaddset(&mask, SIGHUP); sigprocmask(SIG_UNBLOCK, &mask, NULL); siginterrupt(SIGALRM, 1); siginterrupt(SIGPOLL, 1); siginterrupt(SIGURG, 1); siginterrupt(SIGPIPE, 1); siginterrupt(SIGHUP, 1); return __RESULT_SUCCESS;}/* * Start an interval timer as the overall test timer. */static intstart_tt(long duration){ struct itimerval setting = { {0, 0}, {duration / 1000, (duration % 1000) * 1000} }; if (duration == (long) INFINITE_WAIT) return __RESULT_SUCCESS; if (start_signals()) return __RESULT_FAILURE; if (setitimer(ITIMER_REAL, &setting, NULL)) return __RESULT_FAILURE; timer_timeout = 0; return __RESULT_SUCCESS;}#if 0static intstart_st(long duration){ long sdur = (duration + timer_scale - 1) / timer_scale; return start_tt(sdur);}#endifstatic intstop_signals(void){ int result = __RESULT_SUCCESS; sigset_t mask; struct sigaction act; act.sa_handler = SIG_DFL; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, NULL)) result = __RESULT_FAILURE; if (sigaction(SIGPOLL, &act, NULL)) result = __RESULT_FAILURE; if (sigaction(SIGURG, &act, NULL)) result = __RESULT_FAILURE; if (sigaction(SIGPIPE, &act, NULL)) result = __RESULT_FAILURE; if (sigaction(SIGHUP, &act, NULL)) result = __RESULT_FAILURE; sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigaddset(&mask, SIGPOLL); sigaddset(&mask, SIGURG); sigaddset(&mask, SIGPIPE); sigaddset(&mask, SIGHUP); sigprocmask(SIG_BLOCK, &mask, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -