📄 test.c
字号:
/**************************************************************************
* FILE NAME:
* test.c
*
* DESCRIPTION:
* This file is for the test of SCTP
*
* EDIT HISTORY
* $Log: test.c,v $
* Revision 1.7 2003/09/05 08:30:29 rexyan
* Tested the cli-srv communication
*
* Revision 1.6 2003/09/04 05:53:27 rexyan
* Added trace enable
*
* Revision 1.5 2003/09/03 06:38:10 rexyan
* Added all files for SCTP project
*
* Revision 1.4 2003/08/29 06:53:11 rexyan
* first create docu.
*
* Revision 1.3 2003/08/27 05:28:54 rexyan
* Added comments
*
* Revision 1.2 2003/08/26 04:04:17 rexyan
* Added EDIT HISTORY
*
*
**************************************************************************
*/
#include <stdio.h>
#include <sockLib.h>
#include <hostLib.h>
#include <inetLib.h>
#include <strLib.h>
#include <ioLib.h>
#include <timers.h>
#include <string.h>
#include <sysLib.h>
#include "s_cotyps.h"
#include "s_uismty.h"
#include "s_in.h"
#include "s_dbg.h"
#define M3UA_SCTP_MAX_TOTAL_APPLICATION 2
#define M3UA_SCTP_MAX_ASSOCATION 10
#define M3UA_SCTP_MAX_STREAMS 20
#define M3UA_SCTP_STANDARD_UDP_PORT 5000
#define HOST_NAME "vxTarget"
void m3ua_sctp_callback_fn(sctp_indication_t event, sctp_notice_t *event_data)
{
return;
}
void init_stack( sctp_u16bit *m3ua_app_id, sctp_u8bit *local_addr )
{
sctp_error_enum_t sctp_ecode;
sctp_init_options_t sctp_init;
sctp_u32bit address;
sctp_struct_addr_list_t sctp_addr;
sctp_return_t sctp_ret;
if((address = inet_addr(local_addr)) == -1)
{
printf("init_stack: error getting ip address \n");
exit(0);
}
sctp_init.max_total_applications = M3UA_SCTP_MAX_TOTAL_APPLICATION;
sctp_init.max_total_associations = M3UA_SCTP_MAX_ASSOCATION;
sctp_init.max_streams_per_association = M3UA_SCTP_MAX_STREAMS;
sctp_init.max_tx_buffers = 1000;
sctp_init.max_rx_buffers = 1000;
sctp_init.no_of_local_addrs = 1;
sctp_addr[0].address_type = SCTP_IPv4_ADDR;
sctp_addr[0].network_address = address;
sctp_init.list_of_local_addrs = &sctp_addr;
/* sctp_init.list_of_local_addrs = (void *)0; */
sctp_init.stack_type = SCTP_OVER_IP; /* SCTP_OVER_IP or SCTP_OVER_UDP */
sctp_init.raw_socket_option = SCTP_TRUE; /* SCTP_FALSE; */
sctp_init.standard_udp_port = M3UA_SCTP_STANDARD_UDP_PORT;
sctp_init.stale_cookie_policy = 0;
sctp_init.ack_policy = 0;
sctp_init.ecn_capable = 0;
sctp_init.hostname = NULL;
/** init the SCTP stack */
if(sctp_api_init_stack(&sctp_init, &sctp_ecode) != SCTP_SUCCESS)
{
SCTP_PRINT_TRACE("Error initializing the SCTP stack\n");
printf("init_stack: error initializing the sctp stack\n");
exit(0);
}
printf("SCTP init SUCCESSED\n");
/* register M3UA as a User with SCTP */
if(sctp_api_register_su(
m3ua_app_id,
(void*) m3ua_sctp_callback_fn,
&sctp_ecode) == SCTP_FAILURE)
{
printf("M3UA:ES: Error registering M3UA with Sctp\n");
exit(0);
}
printf("M3UA register eith SCTP SUCCESSED\n");
sctp_ret = sctp_api_enable_assoc_trc(
0 , /* sctp_u32bit assoc_id,*/
SCTP_TRUE , /*sctp_Boolean_t trc_all_assoc */
SCTPTRACE_FLAG_SU , /*sctp_trc_flag_t trace_flag,*/
SCTPTRACE_LEVEL_HIGH , /*sctp_trc_level_t trace_level,*/
&sctp_ecode) ; /* sctp_error_t *p_ecode ) */
if (sctp_ret == SCTP_SUCCESS)
printf("\n SCTPTRACE_FLAG_SU SUCCESS" );
else
printf("\n SCTPTRACE_FLAG_SU FAILED " );
sctp_ret = sctp_api_enable_assoc_trc(
0 ,
SCTP_TRUE ,
SCTPTRACE_FLAG_TL ,
SCTPTRACE_LEVEL_HIGH ,
&sctp_ecode) ;
if (sctp_ret == SCTP_SUCCESS)
printf("\n SCTPTRACE_FLAG_TL SUCCESS" );
else
printf("\n SCTPTRACE_FLAG_TL FAILED " );
printf("\n Calling enable trace MH .... " );
sctp_ret = sctp_api_enable_assoc_trc(
0 ,
SCTP_TRUE ,
SCTPTRACE_FLAG_MH ,
SCTPTRACE_LEVEL_HIGH ,
&sctp_ecode) ;
if (sctp_ret == SCTP_SUCCESS)
printf("\n SCTPTRACE_FLAG_MH SUCCESS" );
else
printf("\n SCTPTRACE_FLAG_MH FAILED " );
printf("\n Calling enable trace FSM .... " );
sctp_ret = sctp_api_enable_assoc_trc(
0 ,
SCTP_TRUE ,
SCTPTRACE_FLAG_FSM ,
SCTPTRACE_LEVEL_HIGH ,
&sctp_ecode) ;
if (sctp_ret == SCTP_SUCCESS)
printf("\n SCTPTRACE_FLAG_FSM SUCCESS" );
else
printf("\n SCTPTRACE_FLAG_FSM FAILED " );
}
#if 0
pthread_mutex_t count_lock;
pthread_cond_t count_nonzero;
unsigned count = 0;
void decrement_count(void )
{
printf("SFSFSFSSF\n");
pthread_mutex_lock(&count_lock);
while(count==0)
pthread_cond_wait( &count_nonzero, &count_lock);
count=count -1;
pthread_mutex_unlock (&count_lock);
}
void increment_count( void )
{
printf("SDSSDSDSDSDSDSDSD___\n");
pthread_mutex_lock(&count_lock);
if(count==0)
pthread_cond_signal(&count_nonzero);
count=count+1;
pthread_mutex_unlock(&count_lock);
}
void test( void )
{
if(pthread_mutex_init(&count_lock, NULL)==ERROR) printf("ERROR: mutex init\n");
if(pthread_cond_init(&count_nonzero, NULL) == ERROR)printf("ERROR: cond init\n");
printf("SSSSSSSSSSS");
if(taskSpawn("dec", 90,
0,
12000,
(FUNCPTR)decrement_count,
0,0,0,0,0,0,0,0,0,0) == ERROR)
{
printf("Error in spawning the L3 simulator task.\n");
/* return ERROR;*/
};
if(taskSpawn("inc", 90,
0,
12000,
(FUNCPTR)increment_count,
0,0,0,0,0,0,0,0,0,0) == ERROR)
{
printf("Error in spawning the L3 simulator task.\n");
/* return ERROR;*/
};
printf("DDDDDDDDDDDDDDD");
}
#endif /* pthread */
int getName( void )
{
int ip;
struct in_addr iaddr;
if((ip = hostGetByName("vxTarget"))==ERROR)
{
printf("get host by name error\n");
return -1;
};
iaddr.s_addr = ip;
printf("%s\n", inet_ntoa(iaddr));
return 0;
}
void getTime( void )
{
struct timespec t;
int prev, now, tick_prev, tick_now;
clock_gettime(CLOCK_REALTIME, &t);
tick_now = tickGet();
prev = 0;
tick_prev = 0;
now = t.tv_sec*1000+t.tv_nsec/1000000;
printf("clock_gettimt=%d\n", now-prev);
printf("tickGet()=%d\n", tick_now-tick_prev);
prev = now;
tick_prev = tick_now;
taskDelay(10);
clock_gettime(CLOCK_REALTIME, &t);
now = t.tv_sec*1000 + t.tv_nsec/1000000;
tick_now = tickGet();
printf("clock_gettimt=%d\n", now-prev);
printf("tickGet()=%d\n", tick_now-tick_prev);
}
typedef struct {
int value;
char string[128];
} thread_parm_t;
void *threadfunc(void *parm)
{
thread_parm_t *p = (thread_parm_t *)parm;
printf("%s, parm = %d\n", p->string, p->value);
free(p);
return NULL;
}
void test_thr( void )
{
pthread_t thread;
pthread_attr_t attr;
thread_parm_t parm;
parm.value = 10;
sprintf(parm.string, "%s","123asd");
attr.pri = 100;
attr.stack = 1000;
pthread_create(&thread, &attr, threadfunc, (void *)&parm);
}
void sna( int s, int n)
{
int ss;
if(s > 15 || s < 0) return -1;
if(n > 15 || n < 0) return -1;
ss = (s+n)%16;
printf("%d\n",ss);
}
void evname( sctp_u8bit evt_id)
{
printf("%s\n",sctp_dbg_evt_id2name(evt_id));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -