⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tunnel_test.c

📁 mobile ip 在linux下的一种实现
💻 C
📖 第 1 页 / 共 2 页
字号:
		ok = 0;	}	printf("M09 test cases (2) DONE!\n");	/* M10 */	printf("\nTest case M10: Adding the entries again.\n");	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: adding\n",	      inet_ntoa(binding[0].mn_addr));	t[0] = tunnel_add(hash, binding[0].mn_addr, binding[0].tun_dev,			  local, 1, TUNNEL_IPIP, 0);	if (t[0] == NULL || t[0]->ref != 1) {		printf("M10 FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: adding\n",	      inet_ntoa(dst[1]));	t[1] = tunnel_add(hash, binding[1].mn_addr, binding[1].tun_dev,		       local, 1, TUNNEL_IPIP, 0);	if (t[1] == NULL || t[1]->ref != 1) {		printf("M10 FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: adding\n",	      inet_ntoa(dst[2]));	t[2] = tunnel_add(hash, binding[2].mn_addr, binding[2].tun_dev,			    local, 1, TUNNEL_IPIP, 0);	if (t[2] == NULL || t[2]->ref != 1) {		printf("M10 FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: adding\n",	      inet_ntoa(dst[3]));	t[3] = tunnel_add(hash, binding[3].mn_addr, binding[3].tun_dev,			  local, 1, TUNNEL_IPIP, 0);	if (t[3] == NULL || t[3]->ref != 1) {		printf("M10 FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: adding\n",	      inet_ntoa(dst[4]));	t[4] = tunnel_add(hash, binding[4].mn_addr, binding[4].tun_dev,			  local, 1, TUNNEL_IPIP, 0);	if (t[4] == NULL || t[4]->ref != 1) {		printf("M10 FAILED!\n");		ok = 0;	}	printf("M10 test cases (5) DONE!\n");        /* M11a */	printf("\nTest case M11a: Connecting tunnels.\n");	system("echo Tunnels; " IP_PATH " tunnel show");	system("echo Rules; " IP_PATH " rule show");	system("echo Table 1; " IP_PATH " route show table 1");	system("echo Table 2; " IP_PATH " route show table 2");	system("echo Table 3; " IP_PATH " route show table 3");	system("echo Table 4; " IP_PATH " route show table 4");	DEBUG(DEBUG_FLAG, "\ntunnel_test: Connect from %s to",	      inet_ntoa(binding[2].mn_addr));	DEBUG(DEBUG_FLAG, " %s\n", inet_ntoa(binding[3].mn_addr));	if (t[2] == NULL || t[3] == NULL)		res = -1;	else		res = tunnel_connect(t[2], t[3], binding[3].mn_addr, 1, NULL,				     NULL);	if (res != 0) {		printf("M11a FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG,"\ntunnel_test: Connect from %s to",	      inet_ntoa(dst[0]));	DEBUG(DEBUG_FLAG," %s\n", inet_ntoa(binding[1].mn_addr));	if (t[0] == NULL || t[1] == NULL)		res = -1;	else		res = tunnel_connect(t[0], t[1], binding[1].mn_addr, 1, NULL,				     NULL);	if (res != 0) {		printf("M11a FAILED!\n");		ok = 0;	}	system("echo Tunnels; " IP_PATH " tunnel show");	system("echo Rules; " IP_PATH " rule show");	system("echo Table 1; " IP_PATH " route show table 1");	system("echo Table 2; " IP_PATH " route show table 2");	system("echo Table 3; " IP_PATH " route show table 3");	system("echo Table 4; " IP_PATH " route show table 4");	/* test locupd */	DEBUG(DEBUG_FLAG, "Location update: t0<->t1  ==> t0<->t4\n");	if (t[0] == NULL || t[1] == NULL || t[4] == NULL)		res = -1;	else {		res = tunnel_unconnect(t[0], t[1], binding[1].mn_addr, 1, 0,				       NULL, NULL);		res = tunnel_connect(t[0], t[4], binding[1].mn_addr, 1, NULL,				     NULL);		system("echo Tunnels; " IP_PATH " tunnel show");		system("echo Rules; " IP_PATH " rule show");		system("echo Table 1; " IP_PATH " route show table 1");		system("echo Table 2; " IP_PATH " route show table 2");		system("echo Table 3; " IP_PATH " route show table 3");		system("echo Table 4; " IP_PATH " route show table 4");		tunnel_check_delayed(hash, 2);	}	if (res != 0) {		printf("M11a FAILED!\n");		ok = 0;	}	system("echo Tunnels; " IP_PATH " tunnel show");	system("echo Rules; " IP_PATH " rule show");	system("echo Table 1; " IP_PATH " route show table 1");	system("echo Table 2; " IP_PATH " route show table 2");	system("echo Table 3; " IP_PATH " route show table 3");	system("echo Table 4; " IP_PATH " route show table 4");	printf("M11a test cases (2) DONE!\n");        /* M11b */	printf("\nTest case M11b: Unconnecting tunnels.\n");	DEBUG(DEBUG_FLAG, "\ntunnel_test: Unconnect from %s to",	      inet_ntoa(binding[2].mn_addr));	DEBUG(DEBUG_FLAG, " %s\n", inet_ntoa(binding[3].mn_addr));	if (t[2] == NULL || t[3] == NULL)		tester = -1;	else		tester = tunnel_unconnect(t[2], t[3], binding[3].mn_addr, 1,					  1, NULL, NULL);	if (tester == -1) {		printf("M11b FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Unconnect from %s to",	      inet_ntoa(binding[0].mn_addr));	DEBUG(DEBUG_FLAG, " %s\n", inet_ntoa(binding[1].mn_addr));	if (t[0] == NULL || t[4] == NULL)		tester = -1;	else		tester = tunnel_unconnect(t[0], t[4], binding[1].mn_addr, 1,					  1, NULL, NULL);	if (tester == -1) {		printf("M11b FAILED!\n");		ok = 0;	}	system("echo Tunnels; " IP_PATH " tunnel show");	system("echo Rules; " IP_PATH " rule show");	system("echo Table 1; " IP_PATH " route show table 1");	system("echo Table 2; " IP_PATH " route show table 2");	system("echo Table 3; " IP_PATH " route show table 3");	system("echo Table 4; " IP_PATH " route show table 4");	printf("M11b test cases (2) DONE!\n");        /* M12 */	printf("\nTest case M12: Deleting tunnels.\n");	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: deleting\n",	      inet_ntoa(binding[4].mn_addr));	deletion_result = tunnel_delete(hash, binding[4].mn_addr, 1,					TUNNEL_IPIP, 0);	if (deletion_result != 1) {		printf("M12 FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: deleting\n",	      inet_ntoa(binding[3].mn_addr));	deletion_result = tunnel_delete(hash, binding[3].mn_addr, 1,					TUNNEL_IPIP, 0);	if (deletion_result != 1) {		printf("M12 FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: deleting\n",	      inet_ntoa(binding[2].mn_addr));	deletion_result = tunnel_delete(hash, binding[2].mn_addr, 1,					TUNNEL_IPIP, 0);	if (deletion_result != 1) {		printf("M12 FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: deleting\n",	      inet_ntoa(binding[1].mn_addr));	deletion_result = tunnel_delete(hash, binding[1].mn_addr, 1,					TUNNEL_IPIP, 0);	if (deletion_result != 1) {		printf("M12 FAILED!\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "\ntunnel_test: Tunnel to %s: deleting\n",	      inet_ntoa(binding[0].mn_addr));	deletion_result = tunnel_delete(hash, binding[0].mn_addr, 1,					TUNNEL_IPIP, 0);	if (deletion_result != 1) {		printf("M12 FAILED!\n");		ok = 0;	}	system(IP_PATH " tunnel show");	system(IP_PATH " rule show");	system(IP_PATH " route show table 1");	system(IP_PATH " route show table 2");	system(IP_PATH " route show table 3");	system(IP_PATH " route show table 4");	printf("M12 test cases (5) DONE!\n");	/* M13 */	printf("\nTest case M13: Adding 100 virtual tunnels into one "	       "tunnel device.\n");	for (addcount = 0; addcount < 100; addcount++) {		tunl = tunnel_add(hash, dst[4], device, local, 1,				  TUNNEL_IPIP, 0);		if (tunl == NULL) {			printf("M13 FAILED!\n");			ok = 0;			break;		} else {			printf("\tcount=%d, ref=%d\n", addcount, tunl->ref);		}	}	printf("M13 test cases (100) DONE!\n");	/* M14 */	printf("\nTest case M14: Removing virtual tunnels and"	       " finally the tunnel itself.\n");	tester = 0;	deletion_result = 0;	while (deletion_result == 0) {		deletion_result = tunnel_delete(hash, dst[4], 1,						TUNNEL_IPIP, 0);		printf("DELETION_RESULT=%d.", deletion_result);		tester++;		printf(" %d (VIRTUAL)TUNNELS REMOVED.\n", tester);	}	if (deletion_result != 1 || tester != 100) {		printf("M14 FAILED!\n");		ok = 0;	}	printf("M14 test cases (1) DONE!\n");	/* M15 */	printf("\nTest case M15: "	       "Removing a tunnel that does not exist.\n");	deletion_result = tunnel_delete(hash, dst[4], 1, TUNNEL_IPIP, 0);	printf("DELETION_RESULT = %d\n", deletion_result);	if (deletion_result != -1) {		printf("M15 FAILED!\n");		ok = 0;	}	printf("M15 test cases (1) DONE!\n");	/* M16 */	printf("\nTest case M16: GRE tunnels\n");	tunl = tunnel_add(hash, binding[0].mn_addr, binding[0].tun_dev,			  local, 1, TUNNEL_GRE, 1);	if (tunl == NULL || tunl->ref != 1) {		printf("M16 FAILED!\n");		ok = 0;	}		tunl = tunnel_add(hash, binding[1].mn_addr, binding[0].tun_dev,			  local, 1, TUNNEL_GRE, 2);	if (tunl == NULL || tunl->ref != 1) {		printf("M16 FAILED!\n");		ok = 0;	}	tunl = tunnel_add(hash, binding[0].mn_addr, binding[0].tun_dev,			  local, 1, TUNNEL_GRE, 3);	if (tunl == NULL || tunl->ref != 1) {		printf("M16 FAILED!\n");		ok = 0;	}	tunl = tunnel_add(hash, binding[0].mn_addr, binding[0].tun_dev,			  local, 1, TUNNEL_GRE, 1);	if (tunl == NULL || tunl->ref != 2) {		printf("M16 FAILED!\n");		ok = 0;	}	printf("Should have 3 GRE tunnels:\n");	system("/sbin/ip tu");	deletion_result = tunnel_delete(hash, binding[0].mn_addr, 1,					TUNNEL_GRE, 3);	if (deletion_result != 1) {		printf("M16 FAILED!\n");		ok = 0;	}	deletion_result = tunnel_delete(hash, binding[1].mn_addr, 1,					TUNNEL_GRE, 2);	if (deletion_result != 1) {		printf("M16 FAILED!\n");		ok = 0;	}	deletion_result = tunnel_delete(hash, binding[0].mn_addr, 1,					TUNNEL_GRE, 1);	if (deletion_result != 0) {		printf("M16 FAILED!\n");		ok = 0;	}	deletion_result = tunnel_delete(hash, binding[0].mn_addr, 1,					TUNNEL_GRE, 1);	if (deletion_result != 1) {		printf("M16 FAILED!\n");		ok = 0;	}	/* M17 */	printf("\nTest case M17: Destroying the tunnels hastable\n");	tunnel_destroy_hash(hash);	printf("M17 test cases (1) DONE!\n");	if (!ok) {		printf("\nAt least one of the tests failed!\n");	}	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -