📄 test-sl.c
字号:
void test_read(int fd) { char buf[256]; int i, ret; i = 0; printf("\nAttempting read\n"); for (;;) { ret = read(fd, buf, 256); if ( ret < 0 ) { if ( errno == EAGAIN ) { if ( i++ < 100 ) continue; } printf("error = %d\n", errno); perror(__FUNCTION__); break; } else printf("Read succeeded, read %d bytes!\n", ret); if ( ret > 0 ) { int i; char *c = (char *)buf; printf("Message[%d]: ", ret); for ( i=0; i<ret; i++, c++ ) printf("%c", *c); printf("\n"); } }}int test_ioctl(int fd, int cmd, void *arg, int len) { struct strioctl ctl = { cmd, 0, len, arg }; int ret; ret = ioctl(fd, I_STR, &ctl); if ( ret < 0 ) { printf("return = %d\n", ret); printf("error = %d\n", errno); perror(__FUNCTION__); exit(2); } return ctl.ic_len;}void test_ioctls(int fd) { unsigned char buf[256]; sdl_config_t *c = (sdl_config_t *)buf; sdl_statem_t *s = (sdl_statem_t *)buf; printf("\nAttempting ioctls\n"); test_ioctl(fd, SDL_IOCGCONFIG, buf, sizeof(sdl_config_t)); printf("Config:\n"); printf(" N = %lu\n", c->N); printf(" m = %lu\n", c->m); test_ioctl(fd, SDL_IOCGSTATEM, buf, sizeof(sdl_statem_t)); printf("State:\n"); printf(" daedt_state = %lu\n", s->daedt_state); printf(" daedr_state = %lu\n", s->daedr_state); printf(" octet_counting_mode = %lu\n", s->octet_counting_mode); printf("Iface:\n"); test_ioctl(fd, DEV_IOCGIFFLAGS, buf, sizeof(unsigned long)); printf(" ifflags = %lu\n", *((unsigned long *)buf)); test_ioctl(fd, DEV_IOCGIFTYPE, buf, sizeof(unsigned long)); printf(" iftype = %lu\n", *((unsigned long *)buf)); test_ioctl(fd, DEV_IOCGGRPTYPE, buf, sizeof(unsigned long)); printf(" ifgtype = %lu\n", *((unsigned long *)buf)); test_ioctl(fd, DEV_IOCGIFMODE, buf, sizeof(unsigned long)); printf(" ifmode = %lu\n", *((unsigned long *)buf)); test_ioctl(fd, DEV_IOCGIFRATE, buf, sizeof(unsigned long)); printf(" ifrate = %lu\n", *((unsigned long *)buf)); test_ioctl(fd, DEV_IOCGIFCLOCK, buf, sizeof(unsigned long)); printf(" ifclock = %lu\n", *((unsigned long *)buf)); test_ioctl(fd, DEV_IOCGIFCODING, buf, sizeof(unsigned long)); printf(" ifcoding = %lu\n", *((unsigned long *)buf)); test_ioctl(fd, DEV_IOCGIFLEADS, buf, sizeof(unsigned long)); printf(" ifleads = %lu\n", *((unsigned long *)buf));}void test_config(int fd) { unsigned char buf[sizeof(sl_config_t)]; lmi_option_t *opt = (lmi_option_t *)buf; sl_config_t *slc = (sl_config_t *)buf; sdt_config_t *sdtc = (sdt_config_t *)buf; sdl_config_t *sdlc = (sdl_config_t *)buf; printf("\nAttempting set option\n"); opt->pvar = SS7_PVAR_ITUT_88; opt->popt = SS7_POPT_MPLEV | SS7_POPT_HSL | SS7_POPT_XSN; test_ioctl(fd, SDL_IOCSOPTIONS, buf, sizeof(*opt)); test_ioctl(fd, SDT_IOCSOPTIONS, buf, sizeof(*opt)); test_ioctl(fd, SL_IOCSOPTIONS, buf, sizeof(*opt)); printf("SDL config:\n"); sdlc->N = 16; sdlc->m = 272; test_ioctl(fd, SDL_IOCSCONFIG, buf, sizeof(*sdlc)); test_ioctl(fd, SDL_IOCGCONFIG, buf, sizeof(*sdlc)); printf(" N = %lu\n", sdlc->N); printf(" m = %lu\n", sdlc->m);#ifndef HZ#define HZ 100#endif printf("SDT config:\n"); sdtc->t8 = 100*HZ/1000; /* jiffies */ sdtc->Tin = 4; sdtc->Tie = 1; sdtc->T = 64; sdtc->D = 256; sdtc->Te = 577169; sdtc->De = 9308000; sdtc->Ue = 144292000; test_ioctl(fd, SDT_IOCSCONFIG, buf, sizeof(*sdtc)); test_ioctl(fd, SDT_IOCGCONFIG, buf, sizeof(*sdtc)); printf(" t8 = %lu\n", sdtc->t8); printf(" Tin = %lu\n", sdtc->Tin); printf(" Tie = %lu\n", sdtc->Tie); printf(" T = %lu\n", sdtc->T); printf(" D = %lu\n", sdtc->D); printf(" Te = %lu\n", sdtc->Te); printf(" De = %lu\n", sdtc->De); printf(" Ue = %lu\n", sdtc->Ue); printf("SL config:\n"); slc->t1 = 300*HZ; /* jiffies */ slc->t2 = 50*HZ; /* jiffies */ slc->t2l = 20*HZ; /* jiffies */ slc->t2h = 100*HZ; /* jiffies */ slc->t3 = 1*HZ; /* jiffies */ slc->t4n = 30*HZ; /* jiffies */ slc->t4e = 500*HZ/1000; /* jiffies */ slc->t5 = 100*HZ/1000; /* jiffies */ slc->t6 = 3*HZ; /* jiffies */ slc->t7 = 500*HZ/1000; /* jiffies */ slc->rb_abate = 3; /* messages */ slc->rb_accept = 6; /* messages */ slc->rb_discard = 9; /* messages */ slc->tb_abate_1 = 1*272; /* octets */ slc->tb_onset_1 = 2*272; /* octets */ slc->tb_discd_1 = 3*272; /* octets */ slc->tb_abate_2 = 4*272; /* octets */ slc->tb_onset_2 = 5*272; /* octets */ slc->tb_discd_2 = 6*272; /* octets */ slc->tb_abate_3 = 7*272; /* octets */ slc->tb_onset_3 = 8*272; /* octets */ slc->tb_discd_3 = 9*272; /* octets */ slc->N1 = 127; /* messages */ slc->N2 = 1000; /* octets */ slc->M = 5; test_ioctl(fd, SL_IOCSCONFIG, buf, sizeof(*slc)); printf(" t1 = %lu\n", slc->t1); printf(" t2 = %lu\n", slc->t2); printf(" t2l = %lu\n", slc->t2l); printf(" t2h = %lu\n", slc->t2h); printf(" t3 = %lu\n", slc->t3); printf(" t4n = %lu\n", slc->t4n); printf(" t4e = %lu\n", slc->t4e); printf(" t5 = %lu\n", slc->t5); printf(" t6 = %lu\n", slc->t6); printf(" t7 = %lu\n", slc->t7); printf(" rb_abate = %lu\n", slc->rb_abate); printf(" rb_accept = %lu\n", slc->rb_accept); printf(" rb_discard = %lu\n", slc->rb_discard); printf(" tb_abate_1 = %lu\n", slc->tb_abate_1); printf(" tb_onset_1 = %lu\n", slc->tb_onset_1); printf(" tb_abate_1 = %lu\n", slc->tb_discd_1); printf(" tb_abate_2 = %lu\n", slc->tb_abate_2); printf(" tb_onset_2 = %lu\n", slc->tb_onset_2); printf(" tb_abate_2 = %lu\n", slc->tb_discd_2); printf(" tb_abate_3 = %lu\n", slc->tb_abate_3); printf(" tb_onset_3 = %lu\n", slc->tb_onset_3); printf(" tb_abate_3 = %lu\n", slc->tb_discd_3); printf(" N1 = %lu\n", slc->N1); printf(" N2 = %lu\n", slc->N2); printf(" M = %lu\n", slc->M);}int main () { int fd1, fd2; ppa_t ppa1, ppa2; printf("Simple test program for ss7-sdl-udp driver.\n"); ppa1.loc.sin_family = AF_INET; ppa1.loc.sin_port = 10000; ppa1.loc.sin_addr.s_addr = INADDR_ANY; ppa1.rem.sin_family = AF_INET; ppa1.rem.sin_port = 10001; inet_aton("127.0.0.1",&ppa1.rem.sin_addr); ppa2.loc.sin_family = AF_INET; ppa2.loc.sin_port = 10001; ppa2.loc.sin_addr.s_addr = INADDR_ANY; ppa2.rem.sin_family = AF_INET; ppa2.rem.sin_port = 10000; inet_aton("127.0.0.1",&ppa2.rem.sin_addr); fd1 = test_open(); fd2 = test_open(); ioctl(fd1, I_SRDOPT, RMSGD); ioctl(fd2, I_SRDOPT, RMSGD); test_push(fd1); test_push(fd2); test_info_req(fd1); test_attach_req(fd1, &ppa1); test_info_req(fd1); test_enable_req(fd1); test_info_req(fd1); test_info_req(fd2); test_attach_req(fd2, &ppa2); test_info_req(fd2); test_enable_req(fd2); test_info_req(fd2); test_ioctls(fd1);// test_daedt_start(fd1);// test_daedr_start(fd1);// test_daedt_start(fd2);// test_daedr_start(fd2); test_ioctls(fd2); test_config(fd1); test_config(fd2); test_power_on(fd1); test_power_on(fd2); sleep(3); test_start(fd1); test_start(fd2); { int prim1 = 0, prim2 = 0; int i = 400; while ( --i ) { if ( prim1 != SL_IN_SERVICE_IND && prim1 != SL_OUT_OF_SERVICE_IND ) prim1 = test_getmsg(fd1); if ( prim2 != SL_IN_SERVICE_IND && prim2 != SL_OUT_OF_SERVICE_IND ) prim2 = test_getmsg(fd2); if ( ( prim1 == SL_IN_SERVICE_IND || prim1 == SL_OUT_OF_SERVICE_IND ) && ( prim2 == SL_IN_SERVICE_IND || prim2 == SL_OUT_OF_SERVICE_IND ) ) break; sleep(1); } } test_write(fd1); while ( test_getmsg(fd1) ); while ( test_getmsg(fd2) ); test_read(fd2); test_disable_req(fd1); test_info_req(fd1); test_detach_req(fd1); test_info_req(fd1); test_disable_req(fd2); test_info_req(fd2); test_detach_req(fd2); test_info_req(fd2); test_close(fd1); test_close(fd2); printf("Done.\n"); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -