Ejemplo n.º 1
0
int main(int argc, char *argv[]) {
	printf("SIP layer is starting, pls wait...\n");

	//初始化全局变量
	nct = nbrcosttable_create();//邻居代价表
	dv = dvtable_create();//距离矢量表
	dv_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));//距离矢量表互斥变量
	pthread_mutex_init(dv_mutex,NULL);
	routingtable = routingtable_create();//路由表
	routingtable_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));//路由表互斥变量
	pthread_mutex_init(routingtable_mutex,NULL);
	son_conn = -1;
	stcp_conn = -1;

	nbrcosttable_print(nct);
	dvtable_print(dv);
	routingtable_print(routingtable);

	//注册用于终止进程的信号句柄
	signal(SIGINT, sip_stop);

	//连接到本地SON进程 
	son_conn = connectToSON();
	if(son_conn<0) {
		printf("can't connect to SON process\n");
		exit(1);		
	}
	
	//启动线程处理来自SON进程的进入报文 
	pthread_t pkt_handler_thread; 
	pthread_create(&pkt_handler_thread,NULL,pkthandler,(void*)0);

	//启动路由更新线程 
	pthread_t routeupdate_thread;
	pthread_create(&routeupdate_thread,NULL,routeupdate_daemon,(void*)0);	

	printf("SIP layer is started...\n");
	printf("waiting for routes to be established\n");
	sleep(SIP_WAITTIME);
	nbrcosttable_print(nct);
	dvtable_print(dv);
	routingtable_print(routingtable);

	//等待来自STCP进程的连接
	printf("waiting for connection from STCP process\n");
	waitSTCP(); 

}
Ejemplo n.º 2
0
int main()
{
	dv_t* dv_table;
	routingtable_t* route_table;
	nbr_cost_entry_t* nbr_ct;

	nbr_ct = nbrcosttable_create();
	nbrcosttable_print(nbr_ct);

	printf("--------------- create dv table--------------------\n");
	dv_table = dvtable_create();
	printf("--------------- create dv table--------------------\n");
	dvtable_print(dv_table);

	printf("--------------- create route table--------------------\n");
	route_table = routingtable_create();
	printf("--------------- create route table--------------------\n");
	routingtable_print(route_table);

	nbrcosttable_destroy(nbr_ct);
	dvtable_destroy(dv_table);
	routingtable_destroy(route_table);

	return 0;
}