📄 test-xnet.c
字号:
/***************************************************************************** @(#) test-xnet.c,v strxnet-0_9_2-4(0.9) 2004/04/03 22:37:08 ----------------------------------------------------------------------------- Copyright (c) 2001-2004 OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@openss7.org> 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. As an exception to the above, this software may be distributed under the GNU General Public License (GPL) Version 2 or later, so long as the software is distributed with, and only used for the testing of, OpenSS7 modules, drivers, and libraries. ----------------------------------------------------------------------------- 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 2004/04/03 22:37:08 by <bidulock@openss7.org> *****************************************************************************/#ident "@(#) test-xnet.c,v strxnet-0_9_2-4(0.9) 2004/04/03 22:37:08"static char const ident[] = "test-xnet.c,v strxnet-0_9_2-4(0.9) 2004/04/03 22:37:08";/* * This is a ferry-clip XTI/TLI conformance test program for testing the * OpenSS7 XTI/TLI Library. * * GENERAL OPERATION: * * The test program opens STREAMS pipe and pushes the "timod" module onto one * side of the pipe. * * The test program exchanges TPI primitives with one side of the open pipe * and performs XTI/TLI Library Calls on a file descriptor at the other end * of the pipe. The side with the XTI/TLI Library represents the XTI user; * the other side, the test harness, as shown below: * * USER SPACE * TEST PROGRAM * ___________________________________ _________________________________ * | | \ / | * | | \ / | * | | | | * | | | | * | XTI/TLI | | | * | Library | | | * | | | | * | | | | * | | | | * |___________________________________| | | * \ / | | | * \ / | | | * | / \ | | * ____________|__/___\__________ | | * | | | | * | | | | * | TIMOD | | | * | | | | * | STREAMS MODULE | | | * | | | | * | | | | * |______________________________| | | * \ / | | | * \ / | | | * | | | | * | / \ | | * ____________|__/___\____________________________|____|_____________ * | | * | | * | PIPE | * | | * |___________________________________________________________________| * * * This test arrangement results in a a ferry-clip around the XTI/TLI Library * and TIMOD module, where TPI primitives are injected and removed beneath * the module as well XTI/TLI Library calls peformed above the module. * * To preserve the environment and ensure that the tests are repeatable in * any order, the entire test harness (pipe) is assembled and disassembled * for each test. A test preamble is used to place the module in the correct * state for a test case to begin and then a postable is used to ensure that * the module can be removed correctly. */#include <stropts.h>#include <stdlib.h>#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>#ifdef _GNU_SOURCE#include <getopt.h>#endif#define NEED_T_USCALAR_T#include <xti.h>#include <tihdr.h>#include <timod.h>#include <xti_inet.h>/* * ------------------------------------------------------------------------- * * Configuration * * ------------------------------------------------------------------------- */static int verbose = 1;static int show_msg = 0;static int show_acks = 0;static int show_timeout = 0;static int show_data = 1;static int last_event = 0;static int last_errno = 0;static int last_t_errno = 0;static int last_prim = 0;static int last_tevent = 0;static int last_qlen = 2;static int last_sequence = 1;static int last_servtype = T_COTS_ORD;static int last_provflag = T_SENDZERO | T_ORDRELDATA | T_XPG4_1;static int last_tstate = TS_UNBND;static int MORE_flag = 0;static int top_fd = 0;static int bot_fd = 0;static int test_sndflags = 0; /* T_MORE | T_EXPEDITED | T_PUSH */static int test_rcvflags = 0; /* T_MORE | T_EXPEDITED */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_bufsize = 256;static int test_tidu = 256;char test_opt[256], test_udata[256], test_locadd[256], test_remadd[256];struct t_unitdata test_sndudata = { {256, 256, test_remadd}, {256, 256, test_opt}, {256, 256, test_udata}};struct t_unitdata test_rcvudata = { {256, 0, test_remadd}, {256, 0, test_opt}, {256, 0, test_udata}};struct t_uderr test_uderr = { {256, 0, test_remadd}, {256, 0, test_opt}, 0};/* listen call used in t_listen */struct t_call test_liscall = { {256, 0, test_remadd}, {256, 0, test_opt}, {256, 0, test_udata}, 1};/* accepted call used in t_accept */struct t_call test_acccall = { {256, 256, test_locadd}, {256, 256, test_opt}, {256, 256, test_udata}, 1};/* send to call used in t_connect */struct t_call test_sndcall = { {256, 256, test_remadd}, {256, 256, test_opt}, {256, 256, test_udata}, 0};/* receive call used in t_connect an t_rcvconnect */struct t_call test_rcvcall = { {256, 0, test_remadd}, {256, 0, test_opt}, {256, 0, test_udata}, 0};struct t_call test_discall = { {256, 256, test_locadd}, {256, 256, test_opt}, {256, 256, test_udata}, 1};struct t_optmgmt test_req = { {256, 256, test_opt}, T_NEGOTIATE};struct t_optmgmt test_ret = { {256, 0, test_opt}, 0};struct t_discon test_rcvdis = { {256, 0, test_udata}, 0};struct t_discon test_snddis = { {256, 256, test_udata}, 0, 1};struct t_bind test_bindreq = { {256, 256, test_locadd}, 2};struct t_bind test_bindret = { {256, 0, test_locadd}, 2};struct t_bind test_addrloc = { {256, 0, test_locadd}, 0};struct t_bind test_addrrem = { {256, 0, test_remadd}, 0};struct t_info test_info;struct iovec test_iov[4] = { [0] = {test_udata, 64}, [1] = {test_udata + 64, 64}, [2] = {test_udata + 64 + 64, 64}, [3] = {test_udata + 64 + 64 + 64, 64},};struct t_iovec test_t_iov[4] = { [0] = {test_udata, 64}, [1] = {test_udata + 64, 64}, [2] = {test_udata + 64 + 64, 64}, [3] = {test_udata + 64 + 64 + 64, 64},};unsigned int test_iovcount = 4;#define BUFSIZE 4096/* * ------------------------------------------------------------------------- * * Events and Actions * * ------------------------------------------------------------------------- */enum { NO_MSG = -6, TIMEOUT = -5, UNKNOWN = -4, DECODEERROR = -3, SCRIPTERROR = -2, INCONCLUSIVE = -1, SUCCESS = 0, FAILURE = 1,};enum { __TEST_CONN_REQ = 2, __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_O_NONBLOCK, __TEST_O_BLOCK, __TEST_PUTMSG_DATA, __TEST_PUTPMSG_DATA, __TEST_PUSH, __TEST_POP, __TEST_READ, __TEST_READV, __TEST_GETMSG, __TEST_GETPMSG, __TEST_DATA, __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_T_ACCEPT, __TEST_T_BIND, __TEST_T_CLOSE, __TEST_T_CONNECT, __TEST_T_GETINFO, __TEST_T_GETPROTADDR, __TEST_T_GETSTATE, __TEST_T_LISTEN, __TEST_T_LOOK, __TEST_T_OPTMGMT, __TEST_T_RCV, __TEST_T_RCVCONNECT, __TEST_T_RCVDIS, __TEST_T_RCVREL, __TEST_T_RCVRELDATA, __TEST_T_RCVUDATA, __TEST_T_RCVUDERR, __TEST_T_RCVV, __TEST_T_RCVVUDATA, __TEST_T_SND, __TEST_T_SNDDIS, __TEST_T_SNDREL, __TEST_T_SNDRELDATA, __TEST_T_SNDUDATA, __TEST_T_SNDV, __TEST_T_SNDVUDATA, __TEST_T_SYNC, __TEST_T_UNBIND,};/* * ------------------------------------------------------------------------- * * 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};#undef HZ#define HZ 1000/* *INDENT-OFF* */static timer_range_t timer[tmax] = {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -