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

📄 route_test.c

📁 mobile ip 在linux下的一种实现
💻 C
字号:
/* $Id: route_test.c,v 1.25 2001/02/16 18:05:40 jm Exp $ * * Route module tests  (Dan Forsberg) * * Dynamic hierarchial IP tunnel * Copyright (C) 1998-2001, Dynamics group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See README and COPYING for * more details. */#define DEBUG_FLAG 'R'#include <stdio.h>#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#include <syslog.h>#include <net/if.h>#include <assert.h>#include "tunnel.h"#include "dyn_ip.h"#include "debug.h"#include "message.h"#include <assert.h>/* defines */#define ASSERT assert#ifndef TRUE#define TRUE 1#endif#ifndef FALSE#define FALSE 0#endif#define M02_LOOPCOUNT 20/****************************************** *                                        * *     Route module test main function    * *                                        * ******************************************/intmain(void){	struct hashtable *hash;	struct in_addr local,dst1,dst2,dst3;	char device1[IFNAMSIZ];	char device2[IFNAMSIZ];	int i;	char addr[16];	int ok;	char devices[M02_LOOPCOUNT][IFNAMSIZ];	ok = 1;        printf("\n\t **********************************\n"               "\t    STARTING ROUTE MODULE TESTS!\n"	       "\t **********************************\n");        /* ASSIGNING TEST DATA VALUES: */        printf("\n\t ASSIGNING TEST DATA VALUES:\n\n");	memset((char *) &local, 0, sizeof(local));	inet_aton((char *)"127.0.0.1", &local);	memset((char *) &dst1, 0, sizeof(dst1));	inet_aton((char *)"10.0.0.1", &dst1);	memset((char *) &dst2, 0, sizeof(dst2));	inet_aton((char *)"10.0.0.2", &dst2);	memset((char *) &dst3, 0, sizeof(dst3)); /* To be assigned later. */	/* INITIALIZE THE TUNNEL */	DEBUG(DEBUG_FLAG,"\n\t route_TEST: Tunnel hashtable initializing\n");	hash = tunnel_init("TUNL", 1,  253);	/* M01 */	/* ADDING TUNNELS - AND ROUTES VIA TUNNELS */	printf("\n\tTest case M01: Adding tunnels - and routes via tunnels\n"	       "\n");	DEBUG(DEBUG_FLAG,"route_TEST: Tunnel to %s: adding\n",	      inet_ntoa(dst1));	if (tunnel_add(hash, dst1, device1, local, 1, TUNNEL_IPIP, 0) != 0) {		ok = 0;		fprintf(stderr, "tunnel_add failed\n");	}	DEBUG(DEBUG_FLAG,"route_TEST:"	      " Adding route to %s via device %s\n", inet_ntoa(dst1), device1);	if (dyn_ip_route_add(dst1, device1) != 0) {		fprintf(stderr, "dyn_ip_route_add failed\n");		ok = 0;	}	DEBUG(DEBUG_FLAG,"route_TEST: Tunnel to %s: adding\n",	      inet_ntoa(dst2));	if (tunnel_add(hash, dst2, device2, local, 1, TUNNEL_IPIP, 0) != 0) {		ok = 0;		fprintf(stderr, "tunnel_add failed\n");	}	DEBUG(DEBUG_FLAG,"route_TEST:"	      " Adding route to %s via device %s\n", inet_ntoa(dst2), device2);	if (dyn_ip_route_add(dst2, device2) != 0) {		fprintf(stderr, "dyn_ip_route_add failed\n");		ok = 0;	}	printf("\n M01 test cases (2) OK!\n");	/* M02 */	/* ADDING SEVERAL ROUTES VIA TUNNELS 1 & 2 IN A LOOP */	printf("\n\t Test case: M02:\n"	       "\t  Adding several (%d) routes via tunnels 1 & 2 in a loop\n",	       M02_LOOPCOUNT-3);	for (i = 3; i < M02_LOOPCOUNT; i++) {		sprintf(addr,"%s%d", "10.0.0.", i);		printf("\n addr: %s\n", addr);		inet_aton(addr, &dst3);		if ((i % 2) == 0) {			DEBUG(DEBUG_FLAG,"route_TEST M02:"			      " Adding route to %s via device %s\n",			      inet_ntoa(dst3), device2);			if (dyn_ip_route_add(dst3, device2) != 0) {				fprintf(stderr, "dyn_ip_route_add failed\n");				ok = 0;			}		} else {			DEBUG(DEBUG_FLAG,"route_TEST M02:"			      " Adding route to %s via device %s\n",			      inet_ntoa(dst3), device1);			if (dyn_ip_route_add(dst3, device1) != 0) {				fprintf(stderr, "dyn_ip_route_add failed\n");				ok = 0;			}		}	}	printf("\n M02 test cases (1) OK!\n");	/* M03 */	/* DELETING THE ROUTES ADDED IN M02 */	printf("\n\t Test case M03:"	       "\n\t  Deleting the routes added in M02.\n");	for (i = 3; i < M02_LOOPCOUNT; i++) {		sprintf(addr,"10.0.0.%d",i);		printf("\n addr: %s\n",addr);		inet_aton(addr, &dst3);		if (i % 2 == 0) {			DEBUG(DEBUG_FLAG,"route_TEST M03:"			      " Deleting route to %s via device %s\n",			      inet_ntoa(dst3), device2);			if (dyn_ip_route_del(dst3, device2) != 0) {				fprintf(stderr, "dyn_ip_route_del failed\n");				ok = 0;			}		} else {			DEBUG(DEBUG_FLAG,"route_TEST M03:"			      " Deleting route to %s via device %s\n",			      inet_ntoa(dst3),device1);			if (dyn_ip_route_del(dst3, device1) != 0) {				fprintf(stderr, "dyn_ip_route_del failed\n");				ok = 0;			}		}	}	printf("\n M03 test cases (1) OK!\n");	/* M04 */	/* DELETING THE ROUTES AND TUNNELS ADDED IN M01. */	printf("\n\t Test case M04:"	       "\n\t  Deleting the routes and tunnels added in M01.\n\n");	DEBUG(DEBUG_FLAG, "route_TEST: Tunnel to %s: deleting\n",	      inet_ntoa(dst1));	if (dyn_ip_route_del(dst1, device1) != 0) {		fprintf(stderr, "dyn_ip_route_del failed\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "route_TEST: Tunnel to %s: deleting\n",	      inet_ntoa(dst2));	if (dyn_ip_route_del(dst2, device2) != 0) {		fprintf(stderr, "dyn_ip_route_del failed\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "route_TEST:"	      " Deleting route to %s via device %s\n", inet_ntoa(dst1),	      device1);	if (tunnel_delete(hash, dst1, 1, TUNNEL_IPIP, 0) != 1) {		fprintf(stderr, "tunnel_delete failed\n");		ok = 0;	}	DEBUG(DEBUG_FLAG, "route_TEST:"	      " Deleting route to %s via device %s\n", inet_ntoa(dst2),	      device2);	if (tunnel_delete(hash, dst2, 1, TUNNEL_IPIP, 0) != 1) {		fprintf(stderr, "tunnel_delete failed\n");		ok = 0;	}	printf("\n M04 test cases (2) OK!\n");	/* M05 */	/* ADDING SEVERAL ROUTES VIA DISTINCT TUNNELS IN A LOOP */	printf("\n\t Test case: M05:"	       "\n\t  Adding several (%d) routes via distinct tunnels in a "	       "loop\n",	       M02_LOOPCOUNT-3);	for (i = 3; i < M02_LOOPCOUNT; i++) {		sprintf(addr, "%s%d", "10.0.0.", i);		printf("\n addr: %s\n", addr);		inet_aton(addr, &dst3);		if (tunnel_add(hash, dst3, devices[i], local, 1, TUNNEL_IPIP,			       0) != 0) {			ok = 0;			fprintf(stderr, "tunnel_add failed\n");		}		DEBUG(DEBUG_FLAG,"route_TEST M05:"		      " Adding route to %s via device %s\n",		      inet_ntoa(dst3), devices[i]);		if (dyn_ip_route_add(dst3, devices[i]) != 0) {			fprintf(stderr, "dyn_ip_route_add failed\n");			ok = 0;		}	}	printf("\n M05 test cases (1) OK!\n");	/* M06 */	/* DELETING SEVERAL ROUTES AND TUNNELS (added in M05) IN A LOOP */	printf("\n\t Test case: M06:"	       "\n\t  Deleting several (%d) routes and tunnels"	       " (added in M05) in a loop\n",	       M02_LOOPCOUNT-3);	for (i = M02_LOOPCOUNT-1 ; i >= 3 ; i--) {		sprintf(addr, "10.0.0.%d", i);		printf("\n addr: %s\n", addr);		inet_aton(addr, &dst3);		DEBUG(DEBUG_FLAG, "route_TEST M06:"		      " Deleting route to %s via device %s\n",		      inet_ntoa(dst3), devices[i]);		if (dyn_ip_route_del(dst3, devices[i]) != 0) {			fprintf(stderr, "dyn_ip_route_del failed\n");			ok = 0;		}		if (tunnel_delete(hash, dst3, 1, TUNNEL_IPIP, 0) != 1) {			fprintf(stderr, "tunnel_delete failed\n");			ok = 0;		}	}	printf("\n M06 tests cases (1) OK!\n");	if (tunnel_destroy_hash(hash) != 0) {		fprintf(stderr, "tunnel_destroy_hash failed\n");		ok = 0;	}        printf("\n\t*****************************************\n"               "\t*                                       *\n"               "\t*    ROUTE MODULE TEST FINISHED         *\n"               "\t*                                       *\n"               "\t*****************************************\n\n");	if (ok) {		fprintf(stderr, "\nAll tests OK\n");	} else {		fprintf(stderr, "\nNOTE! Some of the tests failed!\n");	}	return 0;}

⌨️ 快捷键说明

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