Multi Path Routing Complete
diff --git a/Makefile b/Makefile
index 1897130..2498b17 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,6 @@
 CC = cc
-CFLAGS = -g -Wall 
-#-Wpointer-arith -Wreturn-type -Wstrict-prototypes
-LIBS = -lccn -lcrypto
+CFLAGS = -g -Wall -Wpointer-arith -Wreturn-type -Wstrict-prototypes
+LIBS = -lcrypto -lccn
 
 PROGRAMS = nlsr
 
diff --git a/nlsr.c b/nlsr.c
index fc5320d..345635b 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -364,6 +364,34 @@
 }
 
 void 
+process_command_multi_path_face_num(char *command)
+{
+	if(command==NULL)
+	{
+		printf(" Wrong Command Format ( multi-path-face-num n )\n");
+		return;
+	}
+	char *rem;
+	const char *sep=" \t\n";
+	char *num;
+	long int number;
+	
+	num=strtok_r(command,sep,&rem);
+	if(num==NULL)
+	{
+		printf(" Wrong Command Format ( multi-path-face-num n)\n");
+		return;
+	}
+
+	number=atoi(num);
+	if ( number >= 0 && number <= 60 )
+	{
+		nlsr->multi_path_face_num=number;
+	}
+
+}
+
+void 
 process_conf_command(char *command)
 {
 	const char *separators=" \t\n";
@@ -407,6 +435,10 @@
 	{
 		process_command_router_dead_interval(remainder);
 	}
+	else if(!strcmp(cmd_type,"multi-path-face-num") )
+	{
+		process_command_multi_path_face_num(remainder);
+	}
 	else 
 	{
 		printf("Wrong configuration Command %s \n",cmd_type);
@@ -457,6 +489,9 @@
 	hashtb_destroy(&nlsr->lsdb->name_lsdb);
 	hashtb_destroy(&nlsr->lsdb->adj_lsdb);
 	hashtb_destroy(&nlsr->pit_alsa);
+
+	//To Do: has to destroy the face_list one by one 	
+
 	hashtb_destroy(&nlsr->routing_table);
 
 
@@ -469,7 +504,8 @@
 	for(i=0;i<npt_element;i++)
 	{
 		ne=e->data;
-		hashtb_destroy(&ne->name_list);	
+		hashtb_destroy(&ne->name_list);
+		hashtb_destroy(&ne->face_list);	
 		hashtb_next(e);		
 	}
 
@@ -555,6 +591,7 @@
 	nlsr->interest_resend_time = INTEREST_RESEND_TIME;
 	nlsr->lsa_refresh_time=LSA_REFRESH_TIME;
 	nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL;
+	nlsr->multi_path_face_num=MULTI_PATH_FACE_NUM;
 
 
 	nlsr->semaphor=NLSR_UNLOCKED;
diff --git a/nlsr.h b/nlsr.h
index 719e91a..7a57c9f 100644
--- a/nlsr.h
+++ b/nlsr.h
@@ -9,6 +9,7 @@
 #define NLSR_UNLOCKED 0
 #define LSA_REFRESH_TIME 1800
 #define ROUTER_DEAD_INTERVAL 3600
+#define MULTI_PATH_FACE_NUM 0
 
 #define LINK_METRIC 10
 
@@ -76,6 +77,7 @@
 	long int interest_resend_time;
 	long int lsa_refresh_time;
 	long int router_dead_interval;
+	long int multi_path_face_num;
 
 	int semaphor;
 	
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index cb24794..982fef4 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -256,7 +256,7 @@
 				if ( name_lsa->header->isValid == 0 )
 				{
 					// have to call to delete npt table entry
-					delete_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
+					delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
 				
 					if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
 					{
@@ -281,7 +281,7 @@
 					if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 )
 					{
 						is_npt_update=1;
-						delete_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
+						delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
 					}
 
 					// copying LSA content with header
@@ -1221,13 +1221,11 @@
 	if( res == HT_OLD_ENTRY )
 	{
 		nlsa=e->data;
-		delete_npt_entry(nlsa->header->orig_router->name, nlsa->name_prefix->name);
+		delete_npt_entry_by_router_and_name_prefix(nlsa->header->orig_router->name, nlsa->name_prefix->name);
 		hashtb_delete(e);
 	}
-	else if( res == HT_OLD_ENTRY )
+	else if( res == HT_NEW_ENTRY )
 	{
-		nlsa=e->data;	
-		delete_npt_entry(nlsa->header->orig_router->name, nlsa->name_prefix->name);
 		hashtb_delete(e);
 	}
 	hashtb_end(e);
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index 6c95460..99bc66d 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -733,6 +733,7 @@
 		struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
 		get_nbr(nbr,selfp,info);
 		update_lsdb_interest_timed_out_zero_to_adl(nbr);
+		free(nbr);
 	}
 }
 
diff --git a/nlsr_npt.c b/nlsr_npt.c
index 5f6ee26..d5ce2cc 100644
--- a/nlsr_npt.c
+++ b/nlsr_npt.c
@@ -24,6 +24,7 @@
 #include "nlsr_npt.h"
 #include "nlsr_fib.h"
 #include "nlsr_route.h"
+#include "nlsr_adl.h"
 
 int
 add_npt_entry(char *orig_router, char *name_prefix, int num_face, int *faces, int *route_costs)
@@ -32,7 +33,7 @@
 	{
 		return -1;
 	}
-	
+
 	struct npt_entry *ne=(struct npt_entry*)malloc(sizeof(struct npt_entry ));
 	
 	int res,res_nle,res_fle;
@@ -87,7 +88,7 @@
     			hashtb_start(ne->face_list, ef);
 			int i;						
 
-			for ( i=0; i< num_face ; i ++)
+			for ( i=0; i < num_face ; i++)
 			{
 				int face=faces[i];
 				res_fle = hashtb_seek(ef, &face, sizeof(face), 0);
@@ -104,15 +105,6 @@
 			hashtb_end(ef);
 		}
 		
-
-		//ne->next_hop_face=face;
-
-		/*
-		if ( face != NO_FACE )
-		{
-			add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_REG, face);
-		}
-		*/
 	}
 	else if (res == HT_OLD_ENTRY)
 	{
@@ -134,12 +126,6 @@
 			nle->name=(char *)malloc(strlen(name_prefix)+1);
 			memset(nle->name,0,strlen(name_prefix)+1);
 			memcpy(nle->name,name_prefix,strlen(name_prefix));
-			/*
-			if ( face != NO_FACE )
-			{
-				add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_REG, face);
-			}
-			*/
 		}
 		else if(res_nle == HT_OLD_ENTRY )
 		{
@@ -175,11 +161,106 @@
 
 	}
 	hashtb_end(e);
+
+	update_ccnd_fib_for_orig_router(orig_router);
+
 	return res;
 }
 
+void 
+update_ccnd_fib_for_orig_router(char *orig_router)
+{
+
+	int res;	
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee; 	
+    
+
+   	hashtb_start(nlsr->npt, e);
+    	res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
+
+	if(res == HT_NEW_ENTRY)
+	{
+		hashtb_delete(e);
+	}
+	else if ( res == HT_OLD_ENTRY )
+	{
+		struct npt_entry *ne;
+		ne=e->data;
+		int num_face=hashtb_n(ne->face_list);
+		int last_face,first_face;
+
+		int *faces=(int *)malloc(num_face*sizeof(int));
+		int *route_costs=(int *)malloc(num_face*sizeof(int));
+		
+		get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
+		sort_faces_by_distance(faces,route_costs,0,num_face);
+		
+
+		first_face=num_face-1;		
+	
+		if ( nlsr->multi_path_face_num == 0 )
+		{
+			last_face=first_face;
+		}
+		else 
+		{
+			if ( num_face <= nlsr->multi_path_face_num)
+			{
+				last_face=0;
+			}
+			else if ( nlsr->multi_path_face_num == 0)
+			{
+				last_face=num_face-nlsr->multi_path_face_num;
+			}
+		}
+
+		int i,j, nl_element;
+		struct name_list_entry *nle;		
+		struct hashtb_enumerator eenle;
+    		struct hashtb_enumerator *enle = &eenle;
+
+		hashtb_start(ne->name_list, enle);
+		nl_element=hashtb_n(ne->name_list);	
+
+		for (i=0;i<nl_element;i++)
+		{
+			nle=enle->data;
+			
+			for( j=first_face; j>= last_face; j--)
+			{
+				if ( j == last_face )
+				{
+					if( is_neighbor(nle->name) == 0 )
+					{
+						add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]);
+					}
+				}
+				else 
+				{
+					if ( num_face-nlsr->multi_path_face_num > 0 && is_neighbor(orig_router) == 0 )
+					{
+						add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]);
+					}
+				}
+			}
+
+			hashtb_next(enle);
+		}
+		hashtb_end(enle);
+		
+
+
+		free(faces);
+		free(route_costs);
+
+	}
+	hashtb_end(e);
+
+}
+
 int 
-delete_npt_entry(char *orig_router, char *name_prefix)
+delete_npt_entry_by_router_and_name_prefix(char *orig_router, char *name_prefix)
 {
 	if ( strcmp(orig_router,nlsr->router_name)== 0)
 	{
@@ -217,12 +298,60 @@
 		}
 		else if(res_nle == HT_OLD_ENTRY )
 		{
-			/*
-			if (ne->next_hop_face != NO_FACE )
+			struct name_list_entry *nle;
+
+			nle=enle->data;
+	
+			int j;
+			int num_face=hashtb_n(ne->face_list);
+			int last_face,first_face;
+
+			int *faces=(int *)malloc(num_face*sizeof(int));
+			int *route_costs=(int *)malloc(num_face*sizeof(int));
+		
+			get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
+			sort_faces_by_distance(faces,route_costs,0,num_face);
+		
+
+			first_face=num_face-1;		
+	
+			if ( nlsr->multi_path_face_num == 0 )
 			{
-				add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_UNREG, ne->next_hop_face);
+				last_face=first_face;
 			}
-			*/
+			else 
+			{
+				if ( num_face <= nlsr->multi_path_face_num)
+				{
+					last_face=0;
+				}
+				else if ( nlsr->multi_path_face_num == 0)
+				{
+					last_face=num_face-nlsr->multi_path_face_num;
+				}
+			}			
+
+			for( j=first_face; j>= last_face; j--)
+			{
+				if ( j == last_face )
+				{
+					if( is_neighbor(nle->name) == 0 )
+					{
+						add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
+					}
+				}
+				else 
+				{
+					if ( num_face-nlsr->multi_path_face_num > 0 && is_neighbor(orig_router) == 0 )
+					{
+						add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
+					}
+				}
+			}
+			
+			
+			
+
 			hashtb_delete(enle);
 		}
 
@@ -342,26 +471,9 @@
 				for (j=0;j<nl_element;j++)
 				{
 					nle=enle->data;
-		
-					int k,face_list_element;
-					struct face_list_entry *fle;
-
-					struct hashtb_enumerator eef;
-    					struct hashtb_enumerator *ef = &eef;
-    	
-    					hashtb_start(ne->face_list, ef);
-					face_list_element=hashtb_n(ne->face_list);
-					for(k=0;k<face_list_element;k++)
-					{
-						fle=ef->data;
-						//printf(" 	Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
-						//add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG , next_hop_face);
-						hashtb_next(ef);	
-					}
-					hashtb_end(ef);
-
-						//add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG , next_hop_face);
 					
+					delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name);		
+	
 					hashtb_next(enle);
 				}
 				hashtb_end(enle);				
@@ -380,61 +492,6 @@
 	hashtb_end(e);	
 }
 
-/*
-
-void 
-update_npt_with_new_route(char * orig_router,int next_hop_face)
-{
-	int res;
-	struct npt_entry *ne;
-
-	struct hashtb_enumerator ee;
-    	struct hashtb_enumerator *e = &ee;
-    	
-    	hashtb_start(nlsr->npt, e);
-	res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
-
-	if ( res == HT_OLD_ENTRY )
-	{
-		ne=e->data;
-
-		if ( next_hop_face != ne->next_hop_face )
-		{
-			int j, nl_element;
-			struct name_list_entry *nle;		
-			struct hashtb_enumerator eenle;
-    			struct hashtb_enumerator *enle = &eenle;
-
-			hashtb_start(ne->name_list, enle);
-			nl_element=hashtb_n(ne->name_list);	
-
-			for (j=0;j<nl_element;j++)
-			{
-				nle=enle->data;
-				if (ne->next_hop_face != NO_FACE )
-				{
-					add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG , ne->next_hop_face);
-				}
-				if (next_hop_face != NO_FACE )
-				{
-					add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG , next_hop_face);
-				}
-				hashtb_next(enle);
-			}
-			hashtb_end(enle);
-			ne->next_hop_face=next_hop_face;	
-		}
-		
-	}
-	else if ( res == HT_NEW_ENTRY )
-	{
-		hashtb_delete(e);
-	}
-	hashtb_end(e);
-}
-
-*/
-
 
 void
 add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost)
@@ -491,7 +548,7 @@
 
 
 void
-add_new_fib_entries_to_npt()
+add_new_fib_entries_to_npt(void)
 {
 	printf("add_new_fib_entries_to_npt called\n");
 	int i,j, rt_element,face_list_element;
@@ -506,10 +563,7 @@
 
 	for(i=0;i<rt_element;i++)
 	{
-		//printf("----------Routing Table Entry %d------------------\n",i+1);
 		rte=e->data;
-		//printf(" Destination Router: %s \n",rte->dest_router);
-		//rte->next_hop_face == NO_NEXT_HOP ? printf(" Next Hop Face: NO_NEXT_HOP \n") : printf(" Next Hop Face: %d \n", rte->next_hop_face);
 
 		struct face_list_entry *fle;
 
@@ -527,7 +581,6 @@
 			for(j=0;j<face_list_element;j++)
 			{
 				fle=ef->data;
-				//printf(" 	Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
 				add_face_to_npt_by_face_id(rte->dest_router,fle->next_hop_face,fle->route_cost);
 				hashtb_next(ef);	
 			}
@@ -622,7 +675,7 @@
 }
 
 void 
-clean_old_fib_entries_from_npt()
+clean_old_fib_entries_from_npt(void)
 {
 	
 	printf("clean_old_fib_entries_from_npt called\n\n");
@@ -671,7 +724,12 @@
 					{
 						nle=enle->data;
 
-						//delete all the fib entries here		
+						//delete all the fib entries here
+						if( is_neighbor(nle->name) == 0 )
+						{
+							add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face);
+						}						
+		
 
 						hashtb_next(enle);
 					}
@@ -704,10 +762,193 @@
 }
 
 void
-update_npt_with_new_route()
+update_npt_with_new_route(void)
 {
 	clean_old_fib_entries_from_npt();
 	add_new_fib_entries_to_npt();
+	
+	int i, npt_element;
+	
+	struct npt_entry *ne;
+
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee;
+    	
+    	hashtb_start(nlsr->npt, e);
+	npt_element=hashtb_n(nlsr->npt);
+
+	for(i=0;i<npt_element;i++)
+	{
+	
+		ne=e->data;
+		update_ccnd_fib_for_orig_router(ne->orig_router);
+		hashtb_next(e);
+	}
+	
+	hashtb_end(e);
+}
+
+
+
+void 
+sort_faces_by_distance(int *faces,int *route_costs,int start,int element)
+{
+	int i,j;
+	int temp_cost;
+	int temp_face;
+
+	for ( i=start ; i < element ; i ++) 
+	{
+		for( j=i+1; j<element; j ++)
+		{
+			if (route_costs[j] < route_costs[i] )
+			{
+				temp_cost=route_costs[j];
+				route_costs[j]=route_costs[i];
+				route_costs[i]=temp_cost;
+
+				temp_face=faces[j];
+				faces[j]=faces[i];
+				faces[i]=temp_face;
+			}
+		}
+	}
+	
+}
+
+void
+get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces)
+{
+
+	int res,face_list_element,j;	
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee; 	
+    
+
+   	hashtb_start(nlsr->npt, e);
+    	res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
+
+	if(res == HT_NEW_ENTRY)
+	{
+		hashtb_delete(e);
+	}
+	else if ( res == HT_OLD_ENTRY )
+	{
+		struct npt_entry *ne;
+		ne=e->data;
+		
+		struct face_list_entry *fle;
+
+		struct hashtb_enumerator eef;
+    		struct hashtb_enumerator *ef = &eef;
+    	
+    		hashtb_start(ne->face_list, ef);
+		face_list_element=hashtb_n(ne->face_list);
+		for(j=0;j<face_list_element;j++)
+		{
+			fle=ef->data;
+			faces[j]=fle->next_hop_face;
+			route_costs[j]=fle->route_cost;
+			hashtb_next(ef);	
+		}
+		hashtb_end(ef);
+		
+
+	}
+	hashtb_end(e);
+
+}
+
+void 
+destroy_faces_by_orig_router(char *orig_router)
+{
+
+	int res;	
+	struct hashtb_enumerator ee;
+    	struct hashtb_enumerator *e = &ee; 	
+    
+
+   	hashtb_start(nlsr->npt, e);
+    	res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
+
+	if(res == HT_NEW_ENTRY)
+	{
+		hashtb_delete(e);
+	}
+	else if ( res == HT_OLD_ENTRY )
+	{
+		struct npt_entry *ne;
+		ne=e->data;
+		int num_face=hashtb_n(ne->face_list);
+		int last_face,first_face;
+
+		int *faces=(int *)malloc(num_face*sizeof(int));
+		int *route_costs=(int *)malloc(num_face*sizeof(int));
+		
+		get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
+		sort_faces_by_distance(faces,route_costs,0,num_face);
+		
+
+		first_face=num_face-1;		
+	
+		if ( nlsr->multi_path_face_num == 0 )
+		{
+			last_face=first_face;
+		}
+		else 
+		{
+			if ( num_face <= nlsr->multi_path_face_num)
+			{
+				last_face=0;
+			}
+			else if ( nlsr->multi_path_face_num == 0)
+			{
+				last_face=num_face-nlsr->multi_path_face_num;
+			}
+		}
+
+		int i,j, nl_element;
+		struct name_list_entry *nle;		
+		struct hashtb_enumerator eenle;
+    		struct hashtb_enumerator *enle = &eenle;
+
+		hashtb_start(ne->name_list, enle);
+		nl_element=hashtb_n(ne->name_list);	
+
+		for (i=0;i<nl_element;i++)
+		{
+			nle=enle->data;
+			
+			for( j=first_face; j>= last_face; j--)
+			{
+				if ( j == last_face )
+				{
+					if( is_neighbor(nle->name) == 0 )
+					{
+						add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
+					}
+				}
+				else 
+				{
+					if ( num_face-nlsr->multi_path_face_num > 0 && is_neighbor(orig_router) == 0 )
+					{
+						add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
+					}
+				}
+			}
+
+			hashtb_next(enle);
+		}
+		hashtb_end(enle);
+		
+
+
+		free(faces);
+		free(route_costs);
+
+	}
+	hashtb_end(e);
+
 }
 
 void 
@@ -726,29 +967,7 @@
 	for(i=0;i<npt_element;i++)
 	{
 		ne=e->data;
-		
-		int j, nl_element;
-		struct name_list_entry *nle;		
-		struct hashtb_enumerator eenle;
-    		struct hashtb_enumerator *enle = &eenle;
-
-		hashtb_start(ne->name_list, enle);
-		nl_element=hashtb_n(ne->name_list);	
-
-		for (j=0;j<nl_element;j++)
-		{
-			nle=enle->data;
-			/*
-			if ( ne->next_hop_face != NO_FACE)
-			{
-				add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG , ne->next_hop_face);
-			}
-			*/
-			//printf(" Name Prefix: %s Face: %d \n",nle->name,ne->next_hop_face);
-			hashtb_next(enle);
-		}
-		hashtb_end(enle);
-			
+		destroy_faces_by_orig_router(ne->orig_router);
 		hashtb_next(e);		
 	}
 
diff --git a/nlsr_npt.h b/nlsr_npt.h
index ae4f123..c191579 100644
--- a/nlsr_npt.h
+++ b/nlsr_npt.h
@@ -18,11 +18,14 @@
 
 
 int add_npt_entry(char *orig_router, char *name_prefix, int num_face, int *faces, int *route_costs);
-int delete_npt_entry(char *orig_router, char *name_prefix);
+int delete_npt_entry_by_router_and_name_prefix(char *orig_router, char *name_prefix);
 void print_npt(void);
 void delete_orig_router_from_npt(char *orig_router);
 //void update_npt_with_new_route(char * orig_router,int next_hop_face);
-void update_npt_with_new_route();
+void update_npt_with_new_route(void);
 void destroy_all_face_by_nlsr(void);
+void sort_faces_by_distance(int *faces,int *route_costs,int start,int element);
+void update_ccnd_fib_for_orig_router(char *orig_router);
+void get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces);
 
 #endif
diff --git a/nlsr_route.c b/nlsr_route.c
index fcdea08..17bfafc 100644
--- a/nlsr_route.c
+++ b/nlsr_route.c
@@ -74,14 +74,14 @@
 
 		int num_link=get_no_link_from_adj_matrix(adj_matrix, map_element ,source);
 		
-		if ( num_link == 0 )
+		if ( (num_link == 0) || (nlsr->multi_path_face_num == 0 ) )
 		{	
 			calculate_path(adj_matrix,parent,dist, map_element, source);		
 			print_all_path_from_source(parent,source);
 			print_all_next_hop(parent,source);		
 			update_routing_table_with_new_route(parent, dist,source);
 		}
-		else
+		else if ( (num_link != 0) && (nlsr->multi_path_face_num != 0 ) )
 		{
 			long int *links=(long int *)malloc(num_link*sizeof(long int));
 			long int *link_costs=(long int *)malloc(num_link*sizeof(long int));
@@ -1003,7 +1003,7 @@
 }
 
 void 
-clear_old_routing_table()
+clear_old_routing_table(void)
 {
 	printf("clear_old_routing_table called\n");
 	int i,rt_element;
@@ -1031,7 +1031,7 @@
 
 
 void 
-do_old_routing_table_updates()
+do_old_routing_table_updates(void)
 {
 	printf("do_old_routing_table_updates called\n");
 	int i, rt_element;
diff --git a/nlsr_route.h b/nlsr_route.h
index cd023e5..b0eef14 100644
--- a/nlsr_route.h
+++ b/nlsr_route.h
@@ -56,8 +56,8 @@
 void add_next_hop_router(char *dest_router);
 void add_next_hop_from_lsa_adj_body(char *body, int no_link);
 void print_routing_table(void);
-void do_old_routing_table_updates();
-void clear_old_routing_table();
+void do_old_routing_table_updates(void);
+void clear_old_routing_table(void);
 void update_routing_table_with_new_route(long int *parent,long int *dist, long int source);
 
 long int get_next_hop_from_calculation(long int *parent, long int dest,long int source);