📄 test-sctp_n2.c
字号:
/***************************************************************************** @(#) test-sctp_n2.c,v openss7-0_9_2_E(0.9.2.4) 2007/03/15 10:14:59 ----------------------------------------------------------------------------- Copyright (c) 2001-2007 OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@openss7.org> All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------------------- 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 successor regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee. See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2007/03/15 10:14:59 by brian ----------------------------------------------------------------------------- test-sctp_n2.c,v Revision 0.9.2.4 2007/03/15 10:14:59 brian - test case reporting and release date Revision 0.9.2.3 2007/03/12 09:34:00 brian - boosted default test port numbers from 10000 to 18000 Revision 0.9.2.2 2007/03/12 02:23:25 brian - updating tests Revision 0.9.2.1 2006/09/26 00:52:38 brian - rationalized to embedded packages Revision 0.9.2.1 2006/07/29 07:44:38 brian - CVS checkin of changes before leaving for SCTP interop Revision 0.9.2.14 2006/05/06 10:36:10 brian - minor changes Revision 0.9.2.13 2006/03/03 11:47:02 brian - 32/64-bit compatibility *****************************************************************************/#ident "@(#) test-sctp_n2.c,v openss7-0_9_2_E(0.9.2.4) 2007/03/15 10:14:59"static char const ident[] = "test-sctp_n2.c,v openss7-0_9_2_E(0.9.2.4) 2007/03/15 10:14:59";/* * This file is for testing the sctp_n driver. It is provided for the * purpose of testing the OpenSS7 sctp_n driver only. */#include <sys/types.h>#include <stropts.h>#include <stdlib.h>#ifdef HAVE_INTTYPES_H# include <inttypes.h>#else# ifdef HAVE_STDINT_H# include <stdint.h># endif#endif#include <unistd.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/poll.h>#include <stdio.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <signal.h>#include <sys/uio.h>#include <time.h>#ifdef HAVE_SYS_WAIT_H# include <sys/wait.h>#endif#ifdef _GNU_SOURCE#include <getopt.h>#endif#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <sys/npi.h>#include <sys/npi_sctp.h>/* * ------------------------------------------------------------------------- * * Configuration * * ------------------------------------------------------------------------- */static const char *lpkgname = "OpenSS7 SCTP Driver - NPI-SCTP";/* static const char *spkgname = "SCTP"; */static const char *lstdname = "XNS 5.2/NPI Rev 2";static const char *sstdname = "XNS/NPI";static const char *shortname = "SCTP";#ifdef LFSstatic char devname[256] = "/dev/streams/clone/sctp_n";#elsestatic char devname[256] = "/dev/sctp_n";#endifstatic int repeat_verbose = 0;static int repeat_on_success = 0;static int repeat_on_failure = 0;static int exit_on_failure = 0;static int client_port_specified = 0;static int server_port_specified = 0;static int client_host_specified = 0;static int server_host_specified = 0;static int verbose = 1;static int client_exec = 0; /* execute client side */static int server_exec = 0; /* execute server side */static int show_msg = 0;static int show_acks = 0;static int show_timeout = 0;//static int show_data = 1;static int PRIM_type = 0;static int last_event = 0;static int last_errno = 0;static int last_retval = 0;static int last_prio = 0;static int NPI_error = 0;static int CONIND_number = 2;static int TOKEN_value = 0;static int SEQ_number = 1;static int SERV_type = N_CLNS;static int CURRENT_state = NS_UNBND;N_info_ack_t last_info = { 0, };static int DATA_xfer_flags = 0;static int BIND_flags = 0;static int RESET_orig = N_UNDEFINED;static int RESET_reason = 0;static int DISCON_reason = 0;static int CONN_flags = 0;static int ERROR_type = 0;static int RESERVED_field[2] = { 0, 0 };#define TEST_PROTOCOL 132int test_fd[3] = { 0, 0, 0 };#define BUFSIZE 32*4096#define SHORT_WAIT 20 // 100 // 10#define NORMAL_WAIT 100 // 500 // 100#define LONG_WAIT 500 // 5000 // 500#define LONGER_WAIT 1000 // 10000 // 5000#define LONGEST_WAIT 5000 // 20000 // 10000#define TEST_DURATION 20000#define INFINITE_WAIT -1static ulong test_duration = TEST_DURATION; /* wait on other side */ulong seq[10] = { 0, };ulong tok[10] = { 0, };ulong tsn[10] = { 0, };ulong sid[10] = { 0, };ulong ssn[10] = { 0, };ulong ppi[10] = { 0, };ulong exc[10] = { 0, };char cbuf[BUFSIZE];char dbuf[BUFSIZE];struct strbuf ctrl = { BUFSIZE, -1, cbuf };struct strbuf data = { BUFSIZE, -1, dbuf };static int test_pflags = MSG_BAND; /* MSG_BAND | MSG_HIPRI */static int test_pband = 0;static int test_gflags = 0; /* MSG_BAND | MSG_HIPRI */static int test_gband = 0;static int test_timout = 200;static int test_bufsize = 256;static int test_nidu = 256;static int OPTMGMT_flags = 0;static struct sockaddr_in *ADDR_buffer = NULL;static socklen_t ADDR_length = sizeof(*ADDR_buffer);static struct sockaddr_in *DEST_buffer = NULL;static socklen_t DEST_length = 0;static struct sockaddr_in *SRC_buffer = NULL;static socklen_t SRC_length = 0;static unsigned char *PROTOID_buffer = NULL;static size_t PROTOID_length = 0;static char *DATA_buffer = NULL;static size_t DATA_length = 0;static int test_resfd = -1;static void *QOS_buffer = NULL;static int QOS_length = 0;struct strfdinsert fdi = { {BUFSIZE, 0, cbuf}, {BUFSIZE, 0, dbuf}, 0, 0, 0};int flags = 0;int dummy = 0;#if 1#ifndef SCTP_VERSION_2typedef struct addr { uint16_t port __attribute__ ((packed)); struct in_addr addr[3] __attribute__ ((packed));} addr_t;#endif /* SCTP_VERSION_2 */#endifstruct timeval when;/* * ------------------------------------------------------------------------- * * Events and Actions * * ------------------------------------------------------------------------- */enum { __EVENT_EOF = -7, __EVENT_NO_MSG = -6, __EVENT_TIMEOUT = -5, __EVENT_UNKNOWN = -4, __RESULT_DECODE_ERROR = -3, __RESULT_SCRIPT_ERROR = -2, __RESULT_INCONCLUSIVE = -1, __RESULT_SUCCESS = 0, __RESULT_FAILURE = 1, __RESULT_NOTAPPL = 3, __RESULT_SKIPPED = 77,};/* * ------------------------------------------------------------------------- */int show = 1;enum { __TEST_CONN_REQ = 100, __TEST_CONN_RES, __TEST_DISCON_REQ, __TEST_DATA_REQ, __TEST_EXDATA_REQ, __TEST_INFO_REQ, __TEST_BIND_REQ, __TEST_UNBIND_REQ, __TEST_UNITDATA_REQ, __TEST_OPTMGMT_REQ, __TEST_ORDREL_REQ, __TEST_OPTDATA_REQ, __TEST_ADDR_REQ, __TEST_CAPABILITY_REQ, __TEST_CONN_IND, __TEST_CONN_CON, __TEST_DISCON_IND, __TEST_DATA_IND, __TEST_EXDATA_IND, __TEST_INFO_ACK, __TEST_BIND_ACK, __TEST_ERROR_ACK, __TEST_OK_ACK, __TEST_UNITDATA_IND, __TEST_UDERROR_IND, __TEST_OPTMGMT_ACK, __TEST_ORDREL_IND, __TEST_NRM_OPTDATA_IND, __TEST_EXP_OPTDATA_IND, __TEST_ADDR_ACK, __TEST_CAPABILITY_ACK, __TEST_WRITE, __TEST_WRITEV, __TEST_PUTMSG_DATA, __TEST_PUTPMSG_DATA, __TEST_PUSH, __TEST_POP, __TEST_READ, __TEST_READV, __TEST_GETMSG, __TEST_GETPMSG, __TEST_DATA, __TEST_DATACK_REQ, __TEST_DATACK_IND, __TEST_RESET_REQ, __TEST_RESET_IND, __TEST_RESET_RES, __TEST_RESET_CON, __TEST_O_TI_GETINFO, __TEST_O_TI_OPTMGMT, __TEST_O_TI_BIND, __TEST_O_TI_UNBIND, __TEST__O_TI_GETINFO, __TEST__O_TI_OPTMGMT, __TEST__O_TI_BIND, __TEST__O_TI_UNBIND, __TEST__O_TI_GETMYNAME, __TEST__O_TI_GETPEERNAME, __TEST__O_TI_XTI_HELLO, __TEST__O_TI_XTI_GET_STATE, __TEST__O_TI_XTI_CLEAR_EVENT, __TEST__O_TI_XTI_MODE, __TEST__O_TI_TLI_MODE, __TEST_TI_GETINFO, __TEST_TI_OPTMGMT, __TEST_TI_BIND, __TEST_TI_UNBIND, __TEST_TI_GETMYNAME, __TEST_TI_GETPEERNAME, __TEST_TI_SETMYNAME, __TEST_TI_SETPEERNAME, __TEST_TI_SYNC, __TEST_TI_GETADDRS, __TEST_TI_CAPABILITY, __TEST_TI_SETMYNAME_DATA, __TEST_TI_SETPEERNAME_DATA, __TEST_TI_SETMYNAME_DISC, __TEST_TI_SETPEERNAME_DISC, __TEST_TI_SETMYNAME_DISC_DATA, __TEST_TI_SETPEERNAME_DISC_DATA, __TEST_PRIM_TOO_SHORT, __TEST_PRIM_WAY_TOO_SHORT,};/* * ------------------------------------------------------------------------- * * 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;} timer_range_t;enum { t1 = 0, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, tmax};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#if 0/* * 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;}#endifstatic 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);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -