void rewire()
{
	int i,j,k,l,m, temp;
	float randnumb;
	int randHost;

	for(j = 0; j < nodes; j++)
	{
		for(k = 0; k < level[j/unit].id[j%unit].myNumNeighbors; k++)
		{
			randnumb = (rand()/(float)RAND_MAX); //random number generation
			
			if((randnumb < swnP) && ((level[j/unit].id[j%unit].neighbor[k].ID - j > 0) || (j >= nodes - neighbors)) && level[j/unit].id[j%unit].neighbor[k].ID>0)
			{
				//	printf("node %d 's %d neighbor must be rewired\n", j, level[j/unit].id[j%unit].neighbor[k]);
					randHost = nodes*(rand()/(float)RAND_MAX);				//get a random host from this city
					while(randHost == j || isANeighbor(j,randHost))			//if it is us or one of our neighbors....
						randHost = nodes*(rand()/(float)RAND_MAX);			//	then get get a different random host
				//	printf("it will be rewired to %d\n",randHost);
					delNeighbor(level[j/unit].id[j%unit].neighbor[k].ID,j);	//delete the host from the original neighbors array
					level[j/unit].id[j%unit].neighbor[k].ID=0-randHost;		//set the neighbor to the negative value of the random host, negative so that we know it has been rewired already
					level[j/unit].id[j%unit].neighbor[k].city = CITY_NUMBER;
					//add the host to the end of the neighbor hosts array
					level[randHost/unit].id[randHost%unit].neighbor[level[randHost/unit].id[randHost%unit].myNumNeighbors].ID=0-j; 
					level[randHost/unit].id[randHost%unit].neighbor[level[randHost/unit].id[randHost%unit].myNumNeighbors++].city = CITY_NUMBER;
					
			}
		}
	}
}//rewire
Exemple #2
0
void
cleanup(void)
{
	wpcap_exit();
	if(clean_addr){
		delAddress(if_name,local_ipaddr);
	}
    if(clean_route){
        delLoWPANRoute(if_name,br_prefix);        
    }
    if(clean_neighb){
        delNeighbor(if_name, rem_ipaddr);
    }
}