移动节点的邻居节点的发现函数实现如下:
//You can use the following methods to discover neighbors: //1. Use Hello Packets for *neighbor* discovery. //2. Use Communication range for neighbour discovery. //3. Use Nodes Positions for *neighbor* discovery. void Node::addNeighbor(Node * neighbor) { int flag=0; neighbor_list_node* my_neighbor_list; my_neighbor_list=neighbor_ list_; //cout <<"MMMMM"<<my_neighbor_list-> nodeid<<endl; //return; while(my_neighbor_list) { if(my_neighbor_list->nodeid == neighbor->nodeid()) { flag = 1; break; } else { my_neighbor_list=my_neighbor_list->next; } } //cout<<"MMM "<<my_neighbor_list->nodeid<<endl; if(flag == 1) { //neighbour already exist do nothing } else { neighbor_list_node* nlistItem = (neighbor_list_node *)malloc(sizeof(neighbor_list_node)); nlistItem->nodeid = neighbor->nodeid(); nlistItem->next = neighbor_list_; neighbor_list_=nlistItem; } } //After that you can easily get access to any node's neighbor list by creating //its object and calling its neighbor list. Node* m_node = Node::get_node_by_address(this->addr()); neighbor_list_node* my_mobile_neighbor_list; my_mobile_neighbor_list = m_node->neighbor_list_; while(my_mobile_neighbor_list) { cout<<"## Mubashir Neighbor ID:"<<my_mobile_neighbor_list->nodeid<<endl; my_mobile_neighbor_list=my_mobile_neighbor_list->next; } cout<<"node id : " <<put here node id<<" Mubashir Neighbor list contains ID:"<<my_mobile_neighbor_list-> nodeid<<endl;