void coacsAgent::send_HELLO_Message(int destination) { //printf("\n\t\t### %d Sending HELLO###", here_.addr_); printf(" Cluster.cc:send_hello_message \n"); Packet* pkt = allocpkt(CONTSIZE); hdr_ip* iph = HDR_IP(pkt); hdr_coacs* ph = hdr_coacs::access(pkt); ph->src = Myaddr(); ph->NDP=NDP; ph->DP=DP; iph->daddr() = destination; iph->dport() = iph->sport(); iph->ttl() = 1; ph->pType = HELLO; //ph->OwnScore = OwnScore; //ph->flag_is_QD = flag_is_QD; send(pkt, (Handler*) 0); printf(" Cluster.cc:send_hello_message 7\n"); fprintf(actionfile,"cluster.cc:send_HELLO_Message -> Hello msg sent\n"); // myHelloTimer.resched(TIMEOUT); } void coacsAgent::receive_HELLO_Message(hdr_coacs* hdr, hdr_ip* hdrip) { //Update neighbors list bool exists = false; fprintf(actionfile,"cluster.cc:send_HELLO_Message -> recieve Helloe from %i\n",hdrip->saddr()); for (int i = 0; i < numNodes; i++) if(neighbors[i]==hdrip->saddr()) //Node already exists { exists = true; // scores[i] = hdr->OwnScore ; //************ Update the list of Priorioty data*********** if exist neighbors_p[hdrip->saddr()]=hdr->DP; neighbors_NDP[hdrip->saddr()]=hdr->NDP; //******************************************************** } if(!exists) //Add { fprintf(actionfile,"cluster.cc:send_HELLO_Message -> rnew nieghber added %i\n",hdrip->saddr()); neighbors[numNodes] = hdrip->saddr(); //************ Add the list of Priorioty data*********** if not exist neighbors_p[numNodes]=hdr->DP; neighbors_NDP[numNodes]=hdr->NDP; //******************************************************** //scores[numNodes] = hdr->OwnScore ; numNodes++; // OwnScore = numNodes; fprintf(actionfile,"cluster.cc:recieve hello: node %i neighboers are:\n",Myaddr()); for (int i = 0; i < numNodes-1; i++) fprintf(actionfile," node:%i\n",neighbors[i]); } printf("\n\t\t### %d Recieved HELLO from %d and has %d neighbors###", here_.addr_, hdrip->saddr(), numNodes); fprintf(TraceFile,"\n\t\t### %d Recieved HELLO from %d and has %d neighbors###", here_.addr_, hdrip->saddr(), numNodes); fprintf(actionfile,"*****************************************************\n"); } /* void coacsAgent::send_CH_Message(int destination) { fprintf(TraceFile,"\n\t\t### %d Sending CH message###", here_.addr_); printf("\n\t\t### %d Sending CH message###", here_.addr_); Packet* pkt = allocpkt(CONTSIZE); hdr_ip* iph = HDR_IP(pkt); hdr_coacs* ph = hdr_coacs::access(pkt); iph->daddr() = destination; iph->dport() = iph->sport(); iph->ttl() = 1; ph->pType = CHEAD; ph->clusterQD = here_.addr_; ph->clusterQDScore = OwnScore; ph->flag_is_QD = flag_is_QD; send(pkt, (Handler*) 0); myHelloTimer.force_cancel(); // chTimer.force_cancel(); // joinTimer.force_cancel(); chTimer.resched(TIMEOUT); } void coacsAgent::receive_CH_Message(hdr_coacs* hdr, hdr_ip* hdrip) { if( flag_is_QD ) return; //CH message from a node other than the I recieved from previously if(clusterQD==0 || (clusterQD != hdr->clusterQD && clusterQDScore < hdr->clusterQDScore) ) { clusterQD = hdr->clusterQD; clusterQDScore = hdr->clusterQDScore; joinTimer.resched(TIMEOUT); } } void coacsAgent::send_JOIN_Message(int destination) { fprintf(TraceFile,"\n\t\t### %d Sending JOIN message###", here_.addr_); printf("\n\t\t### %d Sending JOIN message###", here_.addr_); Packet* pkt = allocpkt(CONTSIZE); hdr_ip* iph = HDR_IP(pkt); hdr_coacs* ph = hdr_coacs::access(pkt); iph->daddr() = destination; iph->dport() = iph->sport(); // iph->ttl() = 1; ph->pType = JOIN; ph->flag_is_QD = flag_is_QD; send(pkt, (Handler*) 0); } void coacsAgent::receive_JOIN_Message(hdr_coacs* hdr, hdr_ip* hdrip) { //Update cluster list bool exists = false; for (int i = 0; i < numCluster; i++) if(cluster[i]==hdrip->saddr()) //Node already exists { exists = true; //cluster[i][1] = hdr->OwnScore ; } if(!exists) //Add { cluster[numCluster] = hdrip->saddr(); //cluster[numCluster][1] = hdr->OwnScore ; numCluster++; } fprintf(TraceFile,"\n\t\t###AT %d: %d Recieved JOIN from %d and has %d members###",now(),here_.addr_,hdrip->saddr(), numCluster); printf("\n\t\t###AT %d: %d Recieved JOIN from %d and has %d members###",now(), here_.addr_, hdrip->saddr(), numCluster); //Send ACK //When recieving ACk cancel_All_Network_Setup_Timers(); } void coacsAgent::cancel_All_Network_Setup_Timers() { myHelloTimer.force_cancel(); chTimer.force_cancel(); joinTimer.force_cancel(); } */