Exemplo n.º 1
0
void recv_ett_info(task * tmp_packet) {

	aodv_neigh *tmp_neigh;
	ett_info *tmp_ett_info;

	tmp_neigh = find_aodv_neigh(tmp_packet->src_ip);
	if (tmp_neigh == NULL) {
#ifdef DEBUG
		printk ("Error: Source %s of an incoming ett_info message belongs to any neighbour\n", inet_ntoa(tmp_packet->src_ip));
#endif
		return;
	}

	//Update neighbor timelife
	delete_timer(tmp_neigh->ip, tmp_neigh->ip, NO_TOS, TASK_NEIGHBOR);
	insert_timer_simple(TASK_NEIGHBOR, HELLO_INTERVAL
			* (1 + ALLOWED_HELLO_LOSS) + 100, tmp_neigh->ip);
	update_timer_queue();
	tmp_neigh->lifetime = HELLO_INTERVAL * (1 + ALLOWED_HELLO_LOSS) + 20
			+ getcurrtime();

	tmp_ett_info =tmp_packet->data;

	tmp_neigh->recv_rate = ntohs(tmp_ett_info->my_rate);
	
	if (tmp_ett_info->fixed_rate==TRUE){
		tmp_neigh->ett.fixed_rate = TRUE;
		delete_timer(tmp_neigh->ip, tmp_neigh->ip, NO_TOS, TASK_ETT_CLEANUP);
					insert_timer_simple(TASK_ETT_CLEANUP, ETT_INTERVAL * (1 + ALLOWED_ETT_LOSS)
							+ 100, tmp_neigh->ip);
					update_timer_queue();
				delay_vector_add(tmp_neigh, ntohl(tmp_ett_info->last_meas_delay));
	

	if (g_fixed_rate == 0) { //this neigh does not send pair-packets - Lets use the estimation in ETT_INFO
		//NEW ETT-PAIR received - Timer is reloaded
			
#ifdef DEBUG
		printk("Received Delay to %s: %d Usecs\n",inet_ntoa(tmp_neigh->ip) ,ntohl(tmp_ett_info->last_meas_delay));
#endif
		compute_estimation(tmp_neigh);
	}
	}
	
	if ((tmp_neigh->recv_rate == 0) || (tmp_neigh->send_rate == 0))
		tmp_neigh->ett.interval = ETT_FAST_INTERVAL;
	else
		tmp_neigh->ett.interval = ETT_INTERVAL;

	return;
}
Exemplo n.º 2
0
int delete_aodv_neigh_2h(u_int32_t ip) {

	aodv_neigh_2h *tmp_neigh_2h;
	aodv_neigh_2h *prev_neigh_2h = NULL;
	neigh_write_lock(); //to avoid conflicts with read_neigh_proc (uncontrolled interruption)
	tmp_neigh_2h = aodv_neigh_list_2h;

	while (tmp_neigh_2h != NULL) {
		if (tmp_neigh_2h->ip == ip) {

			if (prev_neigh_2h != NULL) {
				prev_neigh_2h->next = tmp_neigh_2h->next;
			} else {
				aodv_neigh_list_2h = tmp_neigh_2h->next;
			}

			neigh_write_unlock();
			kfree(tmp_neigh_2h);

			update_timer_queue();
			return 1;
		}
		prev_neigh_2h = tmp_neigh_2h;
		tmp_neigh_2h = tmp_neigh_2h->next;

	}
	neigh_write_unlock();

	return 0;
}
Exemplo n.º 3
0
void reset_ett(aodv_neigh *reset_neigh) {
	u_int64_t jitter;
	int rand;

	delete_timer(reset_neigh->ip, reset_neigh->ip, NO_TOS, TASK_SEND_ETT);
	reset_neigh->ett.last_count = reset_neigh->ett.count_rcv
			= reset_neigh->ett.sec = reset_neigh->ett.usec
					= reset_neigh->ett.reset = 0;
	reset_neigh->ett.meas_delay = DEFAULT_ETT_METRIC;
	reset_neigh->ett.ett_window = ETT_PROBES_MIN+1; //Initially to MIN value + 1
	reset_neigh->ett.interval = ETT_FAST_INTERVAL;
	reset_neigh->ett.fixed_rate = 0;
	delay_vector_init(&(reset_neigh->ett.recv_delays[0]));
	reset_neigh->send_rate = 0;

	get_random_bytes(&rand, sizeof (rand));
	jitter = (u_int64_t)((rand*reset_neigh->ip)%2000);
	insert_timer_simple(TASK_SEND_ETT, 1000 + 10*jitter, reset_neigh->ip);
	insert_timer_simple(TASK_ETT_CLEANUP, ETT_INTERVAL * (1 + ALLOWED_ETT_LOSS)
			+ 100, reset_neigh->ip);
	update_timer_queue();

#ifdef DEBUG
	printk("Reseting the ETT metric of %s\n",inet_ntoa(reset_neigh->ip));
#endif
	gen_rerr(reset_neigh->ip);

	return;

}
Exemplo n.º 4
0
aodv_neigh_2h *create_aodv_neigh_2h(u_int32_t ip) {
	aodv_neigh_2h *new_neigh_2h;
	aodv_neigh_2h *prev_neigh_2h = NULL;
	aodv_neigh_2h *tmp_neigh_2h = NULL;

	if ((new_neigh_2h = kmalloc(sizeof(aodv_neigh_2h), GFP_ATOMIC)) == NULL) {
#ifdef DEBUG
		printk("NEIGHBOR_LIST_2H: Can't allocate new entry\n");
#endif
		return NULL;
	}

	tmp_neigh_2h = aodv_neigh_list_2h;
	while ((tmp_neigh_2h != NULL) && (tmp_neigh_2h->ip < ip)) {
		prev_neigh_2h = tmp_neigh_2h;
		tmp_neigh_2h = tmp_neigh_2h->next;
	}

	if (tmp_neigh_2h && (tmp_neigh_2h->ip == ip)) {
#ifdef DEBUG
		printk("NEIGHBOR_LIST_2H: Creating a duplicate 2h neighbor entry\n");
#endif
		kfree(new_neigh_2h);
		return NULL;
	}

	neigh_write_lock(); //to avoid conflicts with read_neigh_proc (uncontrolled interruption)

	printk("NEW NEIGHBOR_2HOPS DETECTED: %s\n", inet_ntoa(ip));

	new_neigh_2h->ip = ip;
	new_neigh_2h->lifetime = getcurrtime() + NEIGHBOR_2H_TIMEOUT;
	new_neigh_2h->next = NULL;
	new_neigh_2h->load = 0;
	new_neigh_2h->load_seq = 0;
	
	if (prev_neigh_2h == NULL) {
		new_neigh_2h->next = aodv_neigh_list_2h;
		aodv_neigh_list_2h = new_neigh_2h;
	} else {
		new_neigh_2h->next = prev_neigh_2h->next;
		prev_neigh_2h->next = new_neigh_2h;
	}

	neigh_write_unlock();

	insert_timer_simple(TASK_NEIGHBOR_2H, NEIGHBOR_2H_TIMEOUT + 100, ip);
	update_timer_queue();

	return new_neigh_2h;
}
Exemplo n.º 5
0
void timer_queue_signal() {
	task *tmp_task;
	u_int64_t currtime;

	// Get the first due entry in the queue /
	currtime = getcurrtime();
	tmp_task = first_timer_due(currtime);

	// While there is still events that has timed out
	while (tmp_task != NULL) {
		insert_task_from_timer(tmp_task);
		tmp_task = first_timer_due(currtime);
	}
	update_timer_queue();
}
Exemplo n.º 6
0
int recv_rrep(task * tmp_packet) {
	aodv_route *send_route;
	aodv_route *recv_route;
	aodv_neigh *tmp_neigh = NULL;
	rrep *tmp_rrep;
	u_int32_t path_metric;
	int iam_destination = 0;
#ifdef DEBUG
	char dst_ip[16];
	char src_ip[16];
#endif
	tmp_rrep = tmp_packet->data;
	convert_rrep_to_host(tmp_rrep);
	tmp_neigh = find_aodv_neigh(tmp_packet->src_ip);

	if (tmp_neigh == NULL) {
#ifdef DEBUG
		printk("Ignoring RREP received from unknown neighbor\n");
#endif
		return 1;
	}
	
	//Update neighbor timelife
		delete_timer(tmp_neigh->ip, tmp_neigh->ip, NO_TOS, TASK_NEIGHBOR);
		insert_timer_simple(TASK_NEIGHBOR, HELLO_INTERVAL
				* (1 + ALLOWED_HELLO_LOSS) + 100, tmp_neigh->ip);
		update_timer_queue();
		tmp_neigh->lifetime = HELLO_INTERVAL * (1 + ALLOWED_HELLO_LOSS) + 20
				+ getcurrtime();

	tmp_rrep->num_hops++;
	
#ifdef DEBUG

	strcpy(src_ip, inet_ntoa(tmp_rrep->src_ip));
	strcpy(dst_ip, inet_ntoa(tmp_rrep->dst_ip));

	printk("received new rrep from %s to %s with ToS: %u - last hop: %s\n", dst_ip, src_ip, tmp_rrep->tos, inet_ntoa(tmp_packet->src_ip));
#endif

	if (tmp_rrep->src_ip == g_mesh_ip || (tmp_rrep->src_ip == g_null_ip && tmp_rrep->gateway == g_mesh_ip))
	iam_destination = 1;

	if (iam_destination) { //I'm the source of the flow (the destination of the RREP)
			delete_timer(tmp_rrep->src_ip, tmp_rrep->dst_ip, tmp_rrep->tos,
					TASK_RESEND_RREQ);
	
		update_timer_queue();
		path_metric = tmp_rrep->path_metric;
		//Create (or update) the first hop of the route
		rreq_aodv_route(tmp_rrep->src_ip, tmp_rrep->dst_ip, tmp_rrep->tos, tmp_neigh, tmp_rrep->num_hops,
				tmp_rrep->dst_id, tmp_packet->dev, path_metric);
		
		send_route = find_aodv_route_by_id(tmp_rrep->dst_ip, tmp_rrep->dst_id);

		if (!send_route) {
#ifdef DEBUG
			printk("No reverse-route for RREP from: %s to: %s with TOS %u\n", dst_ip, src_ip, tmp_rrep->tos);
#endif
			return 0;
		}
		rrep_aodv_route(send_route);
		send_route->last_hop = g_mesh_ip;

	}

	else {
		recv_route = find_aodv_route_by_id(tmp_rrep->src_ip, tmp_rrep->src_id); //the route created by the RREQ

		if (!recv_route) {
#ifdef DEBUG
			printk("Reverse Route has timed out! - RREP is not forwarded!\n");
#endif
			return 1;
		}

		path_metric = tmp_rrep->path_metric - recv_route->path_metric;
		//Create (or update) the route from source to destination
		rreq_aodv_route(tmp_rrep->src_ip, tmp_rrep->dst_ip, tmp_rrep->tos,
				tmp_neigh, tmp_rrep->num_hops,
				tmp_rrep->dst_id, tmp_packet->dev, path_metric);
		send_route = find_aodv_route_by_id(tmp_rrep->dst_ip, tmp_rrep->dst_id);

		if (!send_route) {
#ifdef DEBUG

			printk("No reverse-route for RREP from: %s to: %s with TOS %u\n", dst_ip, src_ip, tmp_rrep->tos);
			printk("Not Forwarding RREP!\n");
#endif
			return 0;
		}
		rrep_aodv_route(recv_route);
		rrep_aodv_route(send_route);
		send_route->last_hop = recv_route->next_hop;
		recv_route->last_hop = send_route->next_hop;
		
		convert_rrep_to_network(tmp_rrep);
		send_message(recv_route->next_hop, NET_DIAMETER, tmp_rrep, sizeof(rrep));
		
	}

	return 0;
}
Exemplo n.º 7
0
static int __init init_fbaodv_module(void) {
	char *tmp_str = NULL;
	inet_aton("0.0.0.0", &g_null_ip);

	if (mesh_dev==NULL)
	{
		printk("You need to specify the mesh network device ie:\n");
		printk("    insmod fbaodv_protocol mesh_dev=wlan0    \n");
		return(-1);
	}
	
	strcpy(g_aodv_dev, mesh_dev);
	
	if(aodv_gateway) {
		g_aodv_gateway = (u_int8_t)aodv_gateway;
		printk("\n\nSet as AODV-ST gateway\n");
	} else
	g_aodv_gateway = 0;

	if (network_ip == NULL) {
		printk("You need to specify aodv network ip range, ie: \n");
		printk("network_ip=192.168.0.12/255.255.255.0\n");
		return(-1);
	}
	inet_aton("255.255.255.255",&g_broadcast_ip);
	printk("Miguel Catalan Cid\nImplementation built on top of aodv-st by Krishna Ramachandran, UC Santa Barbara\n");
	printk("---------------------------------------------\n");

	
	/*ROUTING METRICS*/
	if (routing_metric == NULL || strcmp(routing_metric, "HOPS") == 0){
		g_routing_metric = HOPS;
		printk("Hop count routing\n\n");
	}

	else if (strcmp(routing_metric, "ETT") == 0) {
		g_routing_metric = ETT;
		printk("ETT routing: Expected Transmission Time\n\n");
		
		if (nominal_rate && get_nominalrate(nominal_rate))
			g_fixed_rate = nominal_rate;
		
		if (!nominal_rate || g_fixed_rate == 0) {
				g_fixed_rate = 0;
				printk("Nominal rate estimation using packet-pair probe messages: ACTIVE\n\n");
		}
		else
			printk("Nominal rate estimation using packet-pair probe messages: INACTIVE\n\n");

	}
	else if (strcmp(routing_metric, "WCIM") == 0) {
		g_routing_metric = WCIM;
		printk("WCIM routing: Weighted Contention and Interference Model\n\n");
		
		if (nominal_rate && get_nominalrate(nominal_rate))
					g_fixed_rate = nominal_rate;
				
		if (!nominal_rate || g_fixed_rate == 0) {
					g_fixed_rate = 0;
					printk("Nominal rate estimation using packet-pair probe messages: ACTIVE\n\n");
		}
		else
					printk("Nominal rate estimation using packet-pair probe messages: INACTIVE\n\n");


	}

	
	if (network_ip!=NULL)
	{
		tmp_str = strchr(network_ip,'/');
		if (tmp_str)
		{	(*tmp_str)='\0';
			tmp_str++;
			printk("* Network IP - %s/%s\n", network_ip, tmp_str);
			inet_aton(network_ip, &g_mesh_ip);
			inet_aton(tmp_str, &g_mesh_netmask);
		}
	}
		
	
	if (init_packet_queue() < 0) {
			printk("Netlink queue error!!!\n");
			printk("Shutdown complete!\n");
			return(-1);
	}
	
#ifdef BLACKLIST
	if (aodv_blacksize) {
		printk("AODV BLACK LIST:\n");
		int k;
		for (k = 0; k < aodv_blacksize; k++) {
			printk("           %s\n", aodv_blacklist[k]);
			inet_aton(aodv_blacklist[k], &aodv_blacklist_ip[k]);
		}
	}
	if (dtn_blacksize) {
		printk("DTN BLACK LIST:\n");
		int k;
		for (k = 0; k < dtn_blacksize; k++) {
			printk("           %s\n", dtn_blacklist[k]);
			inet_aton(dtn_blacklist[k], &dtn_blacklist_ip[k]);
		}
	}
#endif


	init_aodv_route_table();
	init_task_queue();
	init_timer_queue();
	init_aodv_neigh_list();
	init_aodv_neigh_list_2h();
	init_src_list();
	init_gw_list();
	init_flow_type_table();

	printk("\n*Initialicing mesh device  - %s\n", mesh_dev);	
	if (init_aodv_dev(mesh_dev))
		goto out1;
	

	startup_aodv();


	if (g_aodv_gateway) {
		printk("initiating st_rreq dissemination\n");
		insert_timer_simple(TASK_ST, HELLO_INTERVAL, g_mesh_ip); // start first st_rreq immediately
	}

	//MCC 21/07/2008- UPDATE TIMER ahora en insert_timer
	insert_timer_simple(TASK_HELLO, HELLO_INTERVAL,g_mesh_ip );
	insert_timer_simple(TASK_GW_CLEANUP, ACTIVE_GWROUTE_TIMEOUT, g_mesh_ip);
	insert_timer_simple(TASK_CLEANUP, HELLO_INTERVAL+HELLO_INTERVAL/2, g_mesh_ip);
	update_timer_queue();

	aodv_dir = proc_mkdir("fbaodv",NULL);
	if (aodv_dir == NULL) {
		goto out2;
	}
///*
#ifdef KERNEL2_6_26
	aodv_dir->owner = THIS_MODULE;
#endif

	route_table_proc=create_proc_read_entry("routes", 0, aodv_dir, read_route_table_proc, NULL);
#ifdef KERNEL2_6_26
	route_table_proc->owner=THIS_MODULE;
#endif

	if (route_table_proc == NULL) goto out2;

	neigh_proc=create_proc_read_entry("neigh", 0, aodv_dir, read_neigh_proc, NULL);
	if (neigh_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	neigh_proc->owner=THIS_MODULE;
#endif

	timers_proc=create_proc_read_entry("timers", 0, aodv_dir, read_timer_queue_proc, NULL);
	if (timers_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	timers_proc->owner=THIS_MODULE;
#endif

	reliability_proc=create_proc_read_entry("reliability", 0, aodv_dir, read_rel_list_proc, NULL);
	if (reliability_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	reliability_proc->owner=THIS_MODULE;
#endif

	ett_proc=create_proc_read_entry("bw_estimation", 0, aodv_dir, read_ett_list_proc, NULL);
	if (ett_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	ett_proc->owner=THIS_MODULE;
#endif

	sources_proc=create_proc_read_entry("sources", 0, aodv_dir, read_src_list_proc, NULL);
	if (sources_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	sources_proc->owner=THIS_MODULE;
#endif

	node_load_proc=create_proc_read_entry("node_load", 0, aodv_dir, read_node_load_proc, NULL);
	if (node_load_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	node_load_proc->owner=THIS_MODULE;
#endif

	gw_proc=create_proc_read_entry("gateways", 0, aodv_dir, read_gw_list, NULL);
	if (gw_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	gw_proc->owner=THIS_MODULE;
#endif

	tos_proc=create_proc_read_entry("tos_available", 0, aodv_dir, read_flow_type_table_proc, NULL);
	if (ett_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	ett_proc->owner=THIS_MODULE;
#endif
//*/
	//netfilter stuff
	// input hook
	input_filter.list.next = NULL;
	input_filter.list.prev = NULL;
	input_filter.hook = input_handler;
	input_filter.pf = PF_INET; // IPv4
	input_filter.hooknum = NF_INET_LOCAL_IN;

	//MCC- output hook
	output_filter.list.next = NULL;
	output_filter.list.prev = NULL;
	output_filter.hook = output_handler;
	output_filter.pf = PF_INET; // IPv4
	output_filter.hooknum = NF_INET_POST_ROUTING;

	nf_register_hook(&output_filter);
	nf_register_hook(&input_filter);

	printk("\n\n****FBAODV_PROTO module initialization complete****\n\n");
	return 0;

	out1:
	close_sock();

	del_timer(&aodv_timer);
	printk("Removed timer...\n");

	cleanup_packet_queue();
	printk("Cleaned up AODV Queues...\n");

	if (aodv_route_table != NULL)
	cleanup_aodv_route_table();

	flush_src_list();
	printk("Cleaned up Route and Rule Tables...\n");

	printk("Shutdown complete!\n");

	return(-1);

	out2:

	remove_proc_entry("fbaodv/routes",NULL);
	remove_proc_entry("fbaodv/timers",NULL);
	remove_proc_entry("fbaodv/neigh",NULL);
	remove_proc_entry("fbaodv/reliability", NULL);
	remove_proc_entry("fbaodv/sources", NULL);
	remove_proc_entry("fbaodv/node_load", NULL);

	remove_proc_entry("fbaodv/gateways", NULL);

	remove_proc_entry("fbaodv/user_gateway", NULL);
	remove_proc_entry("fbaodv/gateways_assigned", NULL);
	remove_proc_entry("fbaodv/bw_estimation", NULL);
	remove_proc_entry("fbaodv/tos_available", NULL);
	remove_proc_entry("fbaodv", NULL);

	printk("\n\nShutting down...\n");

	printk("Unregistered NetFilter hooks...\n");

	close_sock();
	printk("Closed sockets...\n");

	del_timer(&aodv_timer);
	printk("Removed timer...\n");

	kill_aodv();
	printk("Killed router thread...\n");

	cleanup_task_queue();
	cleanup_packet_queue();
	printk("Cleaned up AODV Queues...\n");

	cleanup_neigh_routes();
	cleanup_aodv_route_table();
	flush_src_list();
	printk("Cleaned up Route and Rule Tables...\n");

	//Eliminando listas
	delete_aodv_neigh_list();
	delete_aodv_neigh_list_2h();
	delete_gw_list();
	flush_flow_type_table();
	printk("Cleaned up Lists...\n");

	printk("Shutdown complete!\n");

	return(-1);
}
Exemplo n.º 8
0
unsigned int input_handler(unsigned int hooknum, struct sk_buff *skb,
		const struct net_device *in, const struct net_device *out, int (*okfn) (struct sk_buff *)) {
	struct timeval tv;

	u_int8_t aodv_type;
	int start_point = sizeof(struct udphdr) + sizeof(struct iphdr);
	aodv_type = (int) skb->data[start_point];

	struct iphdr *ip = ip_hdr(skb);
	struct in_device *tmp_indev = (struct in_device *) in->ip_ptr;

	void *p = (uint32_t *) ip + ip->ihl;
	struct udphdr *udp = (struct udphdr *) p;

	if (!initialized) { // this is required otherwise kernel calls this function without insmod completing the module loading process.
		return NF_ACCEPT;
	}


	char src[16];
	char dst[16];
	strcpy(src, inet_ntoa(ip->saddr));
	strcpy(dst, inet_ntoa(ip->daddr));
 

#ifdef DTN
	static int t = 1;
	//DTN register
	if (t && !dtn_register && udp->dest == htons(DTNREGISTER)){
		dtn_register = 1;
		t = 0;
		printk("*************DTN registered*************\n");
	}
	
	extern u_int32_t g_mesh_ip;	
	if( dtn_register && udp->dest == htons(GET_DTN_HELLO) ){
		insert_timer_simple(TASK_DTN_HELLO, 0, g_mesh_ip);
		update_timer_queue();
		printk("*************GOT DTN HELLO TASK*************\n");
	}

	if( dtn_register && udp->dest == htons(AODV_LOCATION_PORT)){
		extern u_int32_t dtn_hello_ip;
		extern u_int32_t longitude;
		extern u_int32_t latitude;
		void *loc_data;
		loc_data = &(skb->data[start_point]);
		u_int32_t src_ip = ((u_int32_t *)loc_data)[0];
		u_int32_t tos = ((u_int32_t *)loc_data)[1];
		u_int32_t x = ((u_int32_t *)loc_data)[2];
		u_int32_t y = ((u_int32_t *)loc_data)[3];
		longitude = x;
		latitude = y;
		/*u_int32_t src_ip = ((u_int32_t *)skb->data)[0];
		u_int32_t tos = ((u_int32_t *)skb->data)[1];
		u_int32_t x = ((u_int32_t *)skb->data)[2];
		u_int32_t y = ((u_int32_t *)skb->data)[3];*/
#ifdef CaiDebug
		printk("*********GOT Location Info%s  %ld  %ld**********\n",inet_ntoa(src_ip),ntohl(x),ntohl(y));
#endif
		//gen_rrep(src_ip,dtn_hello_ip,(unsigned char)tos);
		insert_timer_directional(TASK_SEND_RREP, RREP_TIMER, 0,
						src_ip, dtn_hello_ip,(unsigned char)tos);
		update_timer_queue();
}
#ifdef BLACKLIST
	int k = 0;
	if (udp->dest == htons(9556)) {
		for(k=0; k<dtn_blacksize; k++) {
			if (!strcmp("192.168.1.255",dst) && dtn_blacklist_ip[k] == ip->saddr) {
				return NF_DROP;
			}
		}
	}
#endif

#endif
#ifdef DEBUGC
char name[30];
unsigned char if_port;
int ifindex;
unsigned short type;
unsigned short dev_id;
struct net_device *dev = skb->dev;
if( (strcmp(dev->name,"lo")!=0) && (aodv_type != HELLO_MESSAGE)){

strcpy(name,dev->name);
if_port = dev->if_port;
ifindex = dev->ifindex;
type = dev->type;
dev_id = dev->dev_id;
char port[20];
switch(if_port){
	case IF_PORT_UNKNOWN:strcpy(port,"UNKNOWN");break;
	case IF_PORT_10BASE2:strcpy(port,"10BASE2");break;
	case IF_PORT_10BASET:strcpy(port,"10BASET");break;
	case IF_PORT_AUI:strcpy(port,"AUI");break;
        case IF_PORT_100BASET:strcpy(port,"100BASET");break;
        case IF_PORT_100BASETX:strcpy(port,"100BASETX");break;
        case IF_PORT_100BASEFX:strcpy(port,"100BASEFX");break;
}
printk("------------------------------------\ndev->name:%s\ndev->ifindex:%d\ndev->type:%d\ndev->dev_id:%d\ndev->if_port:%s\n----------------------------------\n",name,ifindex,type,dev_id,port);
}
#endif

#ifdef DEBUG
	if (ip->protocol == IPPROTO_ICMP) {
		printk("input_handler: Recv a ICMP from %s to %s\n", src, dst);
	} else if (aodv_type != HELLO_MESSAGE) {
		printk("input_handler: Recv a %d Packet, from %s to %s\n",ip->protocol, src, dst);
	}
#endif
	if (udp != NULL && ip->protocol == IPPROTO_UDP && skb->protocol == htons(ETH_P_IP) && udp->dest == htons(AODVPORT) && tmp_indev->ifa_list->ifa_address != ip->saddr) {

		do_gettimeofday(&tv); //MCC - capture the time of arrival needed for ett_probes
		return packet_in((skb), tv);

	}

#ifdef DEBUG
	if (aodv_type != HELLO_MESSAGE)
		printk("input_handler: input without process.\n");
#endif

	return NF_ACCEPT;

}
Exemplo n.º 9
0
static int __init init_fbaodv_module(void) {
	char *tmp_str = NULL;
	inet_aton("0.0.0.0", &g_null_ip);

#ifdef DTN_HELLO
	//inet_aton("192.168.2.2",&dtn_hello_ip);
	inet_aton("127.127.127.127",&dtn_hello_ip);
	//printk("%s",inet_ntoa(dtn_hello_ip));
	longitude = 0;
	latitude = 0;
#endif




	if (mesh_dev==NULL)
	{
		printk("You need to specify the mesh network device ie:\n");
		printk("    insmod fbaodv_protocol mesh_dev=wlan0    \n");
		return(-1);
	}
	
	strcpy(g_aodv_dev, mesh_dev);
	
	if(aodv_gateway) {
		g_aodv_gateway = (u_int8_t)aodv_gateway;
		printk("\n\nSet as AODV-ST gateway\n");
	} else
	g_aodv_gateway = 0;

	if (network_ip == NULL) {
		printk("You need to specify aodv network ip range, ie: \n");
		printk("network_ip=192.168.0.12/255.255.255.0\n");
		return(-1);
	}
	inet_aton("255.255.255.255",&g_broadcast_ip);
	printk("Miguel Catalan Cid\nImplementation built on top of aodv-st by Krishna Ramachandran, UC Santa Barbara\n");
	printk("---------------------------------------------\n");

	
	/*ROUTING METRICS*/
	if (routing_metric == NULL || strcmp(routing_metric, "HOPS") == 0){
		g_routing_metric = HOPS;
		printk("Hop count routing\n\n");
	}
	//delete the metrics of ETT & WCIM
	
	if (network_ip!=NULL)
	{
		tmp_str = strchr(network_ip,'/');
		if (tmp_str)
		{	(*tmp_str)='\0';
			tmp_str++;
			printk("* Network IP - %s/%s\n", network_ip, tmp_str);
			inet_aton(network_ip, &g_mesh_ip);
			inet_aton(tmp_str, &g_mesh_netmask);
		}
	}
		
	
	if (init_packet_queue() < 0) {
			printk("Netlink queue error!!!\n");
			printk("Shutdown complete!\n");
			return(-1);
	}
	
#ifdef BLACKLIST
	if (aodv_blacksize) {
		printk("AODV BLACK LIST:\n");
		int k;
		for (k = 0; k < aodv_blacksize; k++) {
			printk("           %s\n", aodv_blacklist[k]);
			inet_aton(aodv_blacklist[k], &aodv_blacklist_ip[k]);
		}
	}
	if (dtn_blacksize) {
		printk("DTN BLACK LIST:\n");
		int k;
		for (k = 0; k < dtn_blacksize; k++) {
			printk("           %s\n", dtn_blacklist[k]);
			inet_aton(dtn_blacklist[k], &dtn_blacklist_ip[k]);
		}
	}
#endif



	init_aodv_route_table();
#ifdef RECOVERYPATH
        ///////////brk_list//////////////
	init_brk_list();
#endif

	init_task_queue();
	init_timer_queue();
	init_aodv_neigh_list();
	init_aodv_neigh_list_2h();
	init_src_list();
	init_gw_list();
	init_flow_type_table();


	printk("\n*Initialicing mesh device  - %s\n", mesh_dev);	
	extern aodv_dev* net_dev_list;
	net_dev_list = NULL;
	dev_num = 0;
	//if (init_aodv_dev(mesh_dev))
//	if(init_net_dev(mesh_dev))
//		goto out1;
//printk("---------------init adhoc0-------------------\n");

//#ifdef DEBUGC
     //try to get net list when initialling.
	struct net_device *pdev;
	struct list_head *dev_base = &(init_net.dev_base_head);
	//struct list_head *phead;
	struct in_device *ip;
	struct in_ifaddr *ifaddr;
	//int i ;
	list_for_each_entry(pdev,dev_base,dev_list)//list_for_each(phead,&dev_base)
	{
		if( ((pdev->name[0]=='e')&&(pdev->name[1]=='t')&&(pdev->name[2]=='h')) ||
			(strcmp(pdev->name,"adhoc0")==0) )
		{
			char dev_name[IFNAMSIZ];
			strcpy(dev_name,pdev->name);
			if(init_net_dev(dev_name))
				continue;
			dev_num ++;
			printk("------------------------------------\ndev->name:%s\ndev->ifindex:%d\ndev->type:%d\ndev->dev_id:%d\n----------------------------------\n",pdev->name,pdev->ifindex,pdev->type,pdev->dev_id);
			
			
		}

		/*
		//i =0;
		ip = pdev->ip_ptr;
		ifaddr = ip->ifa_list;
		while(ifaddr){
			printk("-------ip:%s---------\n",inet_ntoa(ifaddr->ifa_address));
			ifaddr = ifaddr->ifa_next;
		//	printk("=========iiiiiii:%d========\n",i++);
		}
		//printk("ip:%s\n",inet_ntoa(ip->ifa_list->ifa_address));
		
		if(strcmp(pdev->name,"eth0")==0){
			char eth_dev[8];
			printk("=========iiiiiii========\n");
			strcpy(eth_dev,pdev->name);
			printk("=========istgreii========\n");
			init_eth_dev(eth_dev);
		}
		*/
	}


//#endif
	startup_aodv();

	if (g_aodv_gateway) {
		printk("initiating st_rreq dissemination\n");
		insert_timer_simple(TASK_ST, HELLO_INTERVAL, g_mesh_ip); // start first st_rreq immediately
	}

	//MCC 21/07/2008- UPDATE TIMER ahora en insert_timer
	insert_timer_simple(TASK_HELLO, HELLO_INTERVAL,g_mesh_ip );
	insert_timer_simple(TASK_GW_CLEANUP, ACTIVE_GWROUTE_TIMEOUT, g_mesh_ip);
	insert_timer_simple(TASK_CLEANUP, HELLO_INTERVAL+HELLO_INTERVAL/2, g_mesh_ip);

	update_timer_queue();

	aodv_dir = proc_mkdir("fbaodv",NULL);
	if (aodv_dir == NULL) {
		goto out2;
	}
///*
#ifdef KERNEL2_6_26
	aodv_dir->owner = THIS_MODULE;
#endif

	route_table_proc=create_proc_read_entry("routes", 0, aodv_dir, read_route_table_proc, NULL);
#ifdef KERNEL2_6_26
	route_table_proc->owner=THIS_MODULE;
#endif

	if (route_table_proc == NULL) goto out2;

	neigh_proc=create_proc_read_entry("neigh", 0, aodv_dir, read_neigh_proc, NULL);
	if (neigh_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	neigh_proc->owner=THIS_MODULE;
#endif

	timers_proc=create_proc_read_entry("timers", 0, aodv_dir, read_timer_queue_proc, NULL);
	if (timers_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	timers_proc->owner=THIS_MODULE;
#endif

	reliability_proc=create_proc_read_entry("reliability", 0, aodv_dir, read_rel_list_proc, NULL);
	if (reliability_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	reliability_proc->owner=THIS_MODULE;
#endif

	ett_proc=create_proc_read_entry("bw_estimation", 0, aodv_dir, read_ett_list_proc, NULL);
	if (ett_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	ett_proc->owner=THIS_MODULE;
#endif

	sources_proc=create_proc_read_entry("sources", 0, aodv_dir, read_src_list_proc, NULL);
	if (sources_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	sources_proc->owner=THIS_MODULE;
#endif

	node_load_proc=create_proc_read_entry("node_load", 0, aodv_dir, read_node_load_proc, NULL);
	if (node_load_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	node_load_proc->owner=THIS_MODULE;
#endif

	gw_proc=create_proc_read_entry("gateways", 0, aodv_dir, read_gw_list, NULL);
	if (gw_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	gw_proc->owner=THIS_MODULE;
#endif

	tos_proc=create_proc_read_entry("tos_available", 0, aodv_dir, read_flow_type_table_proc, NULL);
	if (ett_proc == NULL) goto out2;
#ifdef KERNEL2_6_26
	ett_proc->owner=THIS_MODULE;
#endif
//*/
	//netfilter stuff
	// input hook
	input_filter.list.next = NULL;
	input_filter.list.prev = NULL;
	input_filter.hook = input_handler;
	input_filter.pf = PF_INET; // IPv4
	input_filter.hooknum = NF_INET_LOCAL_IN;

	//MCC- output hook
	output_filter.list.next = NULL;
	output_filter.list.prev = NULL;
	output_filter.hook = output_handler;
	output_filter.pf = PF_INET; // IPv4
	output_filter.hooknum = NF_INET_POST_ROUTING;

	nf_register_hook(&output_filter);
	nf_register_hook(&input_filter);

	printk("\n\n****FBAODV_PROTO module initialization complete****\n\n");
	return 0;

	out1:
	close_sock();

	del_timer(&aodv_timer);
	printk("Removed timer...\n");

	cleanup_packet_queue();
	printk("Cleaned up AODV Queues...\n");

	if (aodv_route_table != NULL)
	cleanup_aodv_route_table();

	flush_src_list();
	printk("Cleaned up Route and Rule Tables...\n");

	printk("Shutdown complete!\n");

	return(-1);

	out2:

	remove_proc_entry("fbaodv/routes",NULL);
	remove_proc_entry("fbaodv/timers",NULL);
	remove_proc_entry("fbaodv/neigh",NULL);
	remove_proc_entry("fbaodv/reliability", NULL);
	remove_proc_entry("fbaodv/sources", NULL);
	remove_proc_entry("fbaodv/node_load", NULL);

	remove_proc_entry("fbaodv/gateways", NULL);

	remove_proc_entry("fbaodv/user_gateway", NULL);
	remove_proc_entry("fbaodv/gateways_assigned", NULL);
	remove_proc_entry("fbaodv/bw_estimation", NULL);
	remove_proc_entry("fbaodv/tos_available", NULL);
	remove_proc_entry("fbaodv", NULL);

	printk("\n\nShutting down...\n");

	printk("Unregistered NetFilter hooks...\n");

	close_sock();
	printk("Closed sockets...\n");

	del_timer(&aodv_timer);
	printk("Removed timer...\n");

	kill_aodv();
	printk("Killed router thread...\n");

	cleanup_task_queue();
	cleanup_packet_queue();
	printk("Cleaned up AODV Queues...\n");

	cleanup_neigh_routes();
	cleanup_aodv_route_table();
	flush_src_list();
	printk("Cleaned up Route and Rule Tables...\n");

	//Eliminando listas
	delete_aodv_neigh_list();
	delete_aodv_neigh_list_2h();
	delete_gw_list();
	flush_flow_type_table();
	printk("Cleaned up Lists...\n");

	printk("Shutdown complete!\n");

	return(-1);
}
Exemplo n.º 10
0
void recv_lprobe(task * tmp_packet) {
	aodv_neigh *tmp_neigh;
	l_probe *tmp_lprobe;
	u_int32_t res_sec, res_usec, sec, usec;

	tmp_lprobe = tmp_packet->data;

	tmp_neigh = find_aodv_neigh(tmp_packet->src_ip);
	if (tmp_neigh == NULL) {
#ifdef DEBUG
		printk ("Error: Source %s of an incoming large probe-packet belongs to any neighbour\n", inet_ntoa(tmp_packet->src_ip));
#endif
		return;
	}

	
	//Update neighbor timelife
	delete_timer(tmp_neigh->ip, tmp_neigh->ip, NO_TOS, TASK_NEIGHBOR);
	insert_timer_simple(TASK_NEIGHBOR, HELLO_INTERVAL
			* (1 + ALLOWED_HELLO_LOSS) + 100, tmp_neigh->ip);
	update_timer_queue();
	tmp_neigh->lifetime = HELLO_INTERVAL * (1 + ALLOWED_HELLO_LOSS) + 20
			+ getcurrtime();

	if (tmp_lprobe->n_probe != tmp_neigh->ett.last_count) //if not equal, the don't belong to the same pair.
	{
#ifdef DEBUG
		printk("Error: Invalid pair of probe-packets from %s\n",inet_ntoa(tmp_packet->src_ip) );
#endif
		return;
	}

	//NEW ETT-PAIR received - Timer is reloaded
	delete_timer(tmp_neigh->ip, tmp_neigh->ip, NO_TOS, TASK_ETT_CLEANUP);
	insert_timer_simple(TASK_ETT_CLEANUP, ETT_INTERVAL * (1 + ALLOWED_ETT_LOSS)
			+ 100, tmp_neigh->ip);
	update_timer_queue();

	sec = tmp_lprobe->sec;
	usec = tmp_lprobe->usec;
	res_sec = sec - tmp_neigh->ett.sec;
	if (res_sec == 0)
		//large packet still received  on same the second-value to the small one, only usec was incremented
		res_usec = usec - tmp_neigh->ett.usec;
	else if (res_sec == 1) //large packet received in a new second-value
		res_usec=1000000 + usec - tmp_neigh->ett.sec;
	else {
#ifdef DEBUG
		printk ("Too high delay between the probe-packets, difference in seconds of %d\n", res_sec);
#endif
		res_usec = DEFAULT_ETT_METRIC;
	}
	tmp_neigh->ett.meas_delay = res_usec;
	tmp_neigh->recv_rate = ntohs(tmp_lprobe->my_rate);

	if (g_fixed_rate == 0) {
		delay_vector_add(tmp_neigh, ntohl(tmp_lprobe->last_meas_delay));
#ifdef DEBUG
		printk("Received Delay to %s: %d Usecs\n",inet_ntoa(tmp_neigh->ip) ,ntohl(tmp_lprobe->last_meas_delay));
#endif
		compute_estimation(tmp_neigh);
	}

	if (tmp_neigh->recv_rate == 0 || tmp_neigh->send_rate == 0) //Estimation is still undone! Fast_interval!
		tmp_neigh->ett.interval = ETT_FAST_INTERVAL;
	else
		tmp_neigh->ett.interval = ETT_INTERVAL;

	return;

}
Exemplo n.º 11
0
void send_probe(u_int32_t ip) {

	s_probe *tmp_sprobe;
	l_probe *tmp_lprobe;

	aodv_neigh *tmp_neigh = find_aodv_neigh(ip);
	if (tmp_neigh==NULL) {
#ifdef DEBUG
		printk ("ERROR - Sending a ETT PROBE : %s is no more a neighbour\n", inet_ntoa(ip));
#endif
		return;
	}

	count_send++;

	if (count_send == 100) {
		count_send=0;
	}

	if (g_fixed_rate != 0) //Fixed rate - No estimation is needed! Send a ETT info message!
		send_ett_info(tmp_neigh, g_fixed_rate, TRUE);

	else {
		if ((tmp_sprobe = (s_probe *) kmalloc(sizeof(s_probe), GFP_ATOMIC))
				== NULL) {
#ifdef DEBUG
			printk(" Can't allocate new ETT-PROBE\n");
#endif
			return;
		}
		if ((tmp_lprobe = (l_probe *) kmalloc(sizeof(l_probe), GFP_ATOMIC))
				== NULL) {
#ifdef DEBUG
			printk(" Can't allocate new ETT-PROBE\n");
#endif
			kfree(tmp_sprobe);
			return;
		}
		tmp_sprobe->type = ETT_S_MESSAGE;
		tmp_sprobe->n_probe = count_send; // only to assure that the small and large packets recieved were sended at the same time
		tmp_sprobe->src_ip = g_mesh_ip;
		tmp_sprobe->dst_ip = ip;
		tmp_sprobe->reserved1 = 0;

		tmp_lprobe->type = ETT_L_MESSAGE;
		tmp_lprobe->n_probe = count_send;
		tmp_lprobe->src_ip = g_mesh_ip;
		tmp_lprobe->dst_ip = ip;
		tmp_lprobe->last_meas_delay = htonl(tmp_neigh->ett.meas_delay);
		tmp_lprobe->my_rate = htons(tmp_neigh->send_rate);

		//estimations are based on Unicast messages, so the transmission rate will be the data one
		send_ett_probe(ip, tmp_sprobe, sizeof(s_probe), tmp_lprobe,
				sizeof(l_probe));

		kfree(tmp_lprobe);
		kfree(tmp_sprobe);
	}

	insert_timer_simple(TASK_SEND_ETT, tmp_neigh->ett.interval, ip);
	update_timer_queue();
	return;

}
Exemplo n.º 12
0
void aodv(void) {
	//The queue holding all the events to be dealt with
	task *tmp_task;

	//Initalize the variables
	init_waitqueue_head(&aodv_wait);
	atomic_set(&kill_thread, 0);
	atomic_set(&aodv_is_dead, 0);


	//Name our thread
	/*lock_kernel();
	 sprintk(current->comm, "aodv-mcc");
	 //exit_mm(current); --> equivale a: current->mm = NULL;
	 //we are in a kthread? aren't we?
	 unlock_kernel();*/

	//add_wait_queue_exclusive(event_socket->sk->sleep,&(aodv_wait));
	//	add_wait_queue(&(aodv_wait),event_socket->sk->sleep);


	//why would I ever want to stop ? :)
	for (;;) {
		//should the thread exit?
		if (atomic_read(&kill_thread)) {
			goto exit;
		}
		//goto sleep until we recieve an interupt
		interruptible_sleep_on(&aodv_wait);

		//should the thread exit?
		if (atomic_read(&kill_thread)) {
			goto exit;
		}
		//While the buffer is not empty
		extern dtn_hello_ip;
		while ((tmp_task = get_task()) != NULL) {
			
			u_int32_t dst;

			//takes a different action depending on what type of event is recieved
			switch (tmp_task->type) {

			//remove following case when DTN hell test end
			case TASK_DTN_HELLO:
				//inet_aton("127.127.127.127",&dst);
				
				//extern u_int32_t dtn_hello_ip;
				gen_rreq(g_mesh_ip,dtn_hello_ip,tmp_task->tos);
#ifdef CaiDebug
				printk("-------DTN HELLO TASK---------\n");
#endif
				//insert_timer_simple(TASK_DTN_HELLO, 300*HELLO_INTERVAL, g_mesh_ip);
				//update_timer_queue();
				break;

			//RREP
			case TASK_RECV_RREP:
				recv_rrep(tmp_task);
				kfree(tmp_task->data);
				break;

				//RERR
			case TASK_RECV_RERR:
				//printk("-----------\nget RERR from %s----------\n",inet_ntoa(tmp_task->src_ip));
				recv_rerr(tmp_task);
				kfree(tmp_task->data);
				break;

			case TASK_RECV_HELLO:
				//printk("get HELLO from %s\n",inet_ntoa(tmp_task->src_ip));
				recv_hello(tmp_task);
				kfree(tmp_task->data);
				break;

           		 /****************添加接收到通路包的任务***************/
			#ifdef RECOVERYPATH
            		case TASK_RECV_RCVP:
               			//printk("Receive a RCVP\n");
               			recv_rcvp(tmp_task);
                		kfree(tmp_task->data);
                		break;
			case TASK_RECV_RRDP:
               			//printk("Receive a RRDP\n");
               			recv_rrdp(tmp_task);
                		kfree(tmp_task->data);
                		break;
			#endif

				//Cleanup  the Route Table and Flood ID queue
			case TASK_CLEANUP:
				flush_aodv_route_table();
				break;

			case TASK_HELLO:
				//printk("gen HELLO\n");
				gen_hello();
				break;

			case TASK_ST:
				gen_st_rreq();
				break;

			case TASK_GW_CLEANUP:
				update_gw_lifetimes();
				insert_timer_simple(TASK_GW_CLEANUP, ACTIVE_GWROUTE_TIMEOUT,
						g_mesh_ip);
				update_timer_queue();
				break;

			case TASK_NEIGHBOR:
			//printk("get NEIGHBOR TASH,delete neigh %s\n",inet_ntoa(tmp_task->src_ip));
			delete_aodv_neigh(tmp_task->src_ip);
				break;

			case TASK_ROUTE_CLEANUP:
				flush_aodv_route_table();
				break;

			case TASK_SEND_ETT:
				send_probe(tmp_task->dst_ip);
				break;
				//A small probe packet is received
			case TASK_RECV_S_ETT:
				recv_sprobe(tmp_task);
				kfree(tmp_task->data);
				break;
				//A large probe packet is received
			case TASK_RECV_L_ETT:
				recv_lprobe(tmp_task);
				kfree(tmp_task->data);
				break;
			case TASK_ETT_CLEANUP:
				reset_ett(find_aodv_neigh(tmp_task->src_ip));
				printk("Reseting ETT-Info from neighbour %s\n",
						inet_ntoa(tmp_task->src_ip));
				break;

			case TASK_NEIGHBOR_2H:
				delete_aodv_neigh_2h(tmp_task->src_ip);
				break;

			case TASK_RECV_RREQ:
				recv_rreq(tmp_task);
				kfree(tmp_task->data);
				break;


			case TASK_RESEND_RREQ:
				resend_rreq(tmp_task);
				break;


			case TASK_ETT_INFO:
				recv_ett_info(tmp_task);
				kfree(tmp_task->data);
				break;
			case TASK_SEND_RREP:
				gen_rrep(tmp_task->src_ip, tmp_task->dst_ip, tmp_task->tos);
				break;

			case TASK_RECV_STRREQ:
				recv_rreq_st(tmp_task);
				kfree(tmp_task->data);
				break;

			case TASK_UPDATE_LOAD:
				update_my_load();
				break;

			case TASK_GEN_RREQ:
				gen_rreq(tmp_task->src_ip, tmp_task->dst_ip, tmp_task->tos);
				break;

			default:
				break;
			}

			kfree(tmp_task);

		}

	}

	exit:
	//Set the flag that shows you are dead
	atomic_set(&aodv_is_dead, 1);

}