//FILE: overlay/overlay.c // //Description: this file implements a ON process //A ON process first connects to all the neighbors and then starts listen_to_neighbor threads each of which keeps receiving the incoming packets from a neighbor and forwarding the received packets to the SNP process. Then ON process waits for the connection from SNP process. After a SNP process is connected, the ON process keeps receiving sendpkt_arg_t structures from the SNP process and sending the received packets out to the overlay network. // //Date: April 28,2008 #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../common/constants.h" #include "../common/pkt.h" #include "overlay.h" #include "../topology/topology.h" #include "neighbortable.h" //you should start the ON processes on all the overlay hosts within this period of time #define OVERLAY_START_DELAY 60 /**************************************************************/ //declare global variables /**************************************************************/ //declare the neighbor table as global variable nbr_entry_t* nt; //declare the TCP connection to SNP process as global variable int network_conn; /**************************************************************/ //implementation overlay functions /**************************************************************/ // This thread opens a TCP port on CONNECTION_PORT and waits for the incoming connection from all the neighbors that have a larger node ID than my nodeID, // After all the incoming connections are established, this thread terminates void* waitNbrs(void* arg) { //put your code here return 0; } // This function connects to all the neighbors that have a smaller node ID than my nodeID // After all the outgoing connections are established, return 1, otherwise return -1 int connectNbrs() { //put your code here return 0; } //Each listen_to_neighbor thread keeps receiving packets from a neighbor. It handles the received packets by forwarding the packets to the SNP process. //all listen_to_neighbor threads are started after all the TCP connections to the neighbors are established void* listen_to_neighbor(void* arg) { //put your code here return 0; } //This function opens a TCP port on OVERLAY_PORT, and waits for the incoming connection from local SNP process. After the local SNP process is connected, this function keeps getting sendpkt_arg_ts from SNP process, and sends the packets to the next hop in the overlay network. If the next hop's nodeID is BROADCAST_NODEID, the packet should be sent to all the neighboring nodes. void waitNetwork() { //put your code here } //this function stops the overlay //it closes all the connections and frees all the dynamically allocated memory //it is called when receiving a signal SIGINT void overlay_stop() { //put your code here } int main() { //start overlay initialization printf("Overlay: Node %d initializing...\n",topology_getMyNodeID()); //create a neighbor table nt = nt_create(); //initialize network_conn to -1, means no SNP process is connected yet network_conn = -1; //register a signal handler which is sued to terminate the process signal(SIGINT, overlay_stop); //print out all the neighbors int nbrNum = topology_getNbrNum(); int i; for(i=0;i