#ifndef __ROUTER_H__ #define __ROUTER_H__ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // added for strerror const int MAX_RECORDS = 100; //maximum number of records per packet //make sure that size of the structure always //remains within limits of the MTU at physical layer //while sending stuff to the other side //we will fill this structure and pass it to //build packet routine /* typedef struct { unsigned long new_member; }INTRA_DATA; typedef struct { }INTER_DATA; */ typedef struct routingTableEntry { unsigned long nid; unsigned long gw; unsigned long cid; unsigned long nextHop; int aliveSince; //field telling since when is this member alive //--03.18.02. Will need the border nodes to be specified as such. int isBorderNode; //1 if it is, 0 otherwise }RTEntry; //design the rcmp query cache, and the query message body //note that we are not keeping anything like a query header. The ddca_header will //serve as the basic header below the IP header. Anything below that can be encapsulated //in term of appropriate type of body. typedef struct query_body { ROUTING_PKT_TYPE type; //This section according to the thesis is the ICRP header unsigned int srcNID; unsigned int srcCID; unsigned int destNID; unsigned int destCID; //This according to ICRP is the body //int type; unsigned int targNID; unsigned int origNID; //How to make a unique SeqNo? Guess will need to use our IP address with some combination int seqNo; }QRY_BODY; /* typedef struct new_child_update { RTEntry rte; }NEW_CHILD_UPDATE; typedef struct routing_pkt { unsigned long seqNum; //to avoid ROUTING_PKT_TYPE rpktType; //dont know what i should put here //connection to //who is our next hop //what is the cost to go through there //alpha, t values?? maybe union { QRY_BODY q_body; NEW_CHILD_UPDATE nc_update; }type; }RPKT; */ //in this class whenever you need to access anything from the DDCA layer //always assume that the variable "machine" points to the ddca state machine //so if you want to have a packet delivered to you(actually it only caused //you to have an event), you just use "machine->getPacketFrmDDCA()". //this should ideally return a character pointer. since we are not going to //do any threading stuff etc til now we will not be bothering about various //threads sharing and garbling up the packet contents class ROUTER { private: //the state machine underlying this router // class DDCA *machine; commenting this out for testing timers RTEntry rTable[MAX_CLUSTER_SIZE]; //the members in our cluster unsigned long numCMembers; //number of valid elements in our array unsigned int seqNumChild; //sequence number to be used when a new child joins us int sockfd; // socket descriptor to add/del kernel table entries public: int index; //max used index in the member array class DDCA *machine; // need to remove this and make it private later ROUTER() { index = -1; //need this for the first time increment in insertEntry //insert yourself in the routing table as the first entry } //maybe we need a getPacketFrmDDCA() to ask the DDCA layer to deliver //packets to us //initialization stuff void setDDCA(class DDCA *d) { machine = d; } RTEntry *existEntry (RTEntry *entry); int insertEntry( RTEntry *entry); int deleteEntry( RTEntry *entry); int updateEntry (RTEntry *entry); //03.19.02 adding function to set ourselves as a border node if we are int setBorderNode(); int flushTable(); int printTable(); int addRoute (unsigned addr, unsigned gateway); int delRoute (unsigned addr, unsigned gateway); int initRouting (); // to open the socket for adding routing entries //remember that the inactive state does not have any routing at all int orphanRouting(EVENT event); int unclusteredRouting(EVENT event); int childRouting(EVENT event); int parentRouting(EVENT event); //int bcastNewChild(RTEntry rte); int dummy(); int checkBcastPkt(); //timer based functions to decide when to change the ip routing table. int updateRoutingTable(); int updateGatewayStatus(); //RCMP, QRY functions int QRY_RCMP(unsigned int ipAddr); }; #endif /*__ROUTER_H__*/