// Author: Leslie S. Liu (shihuali@usc.edu) // Written on April 22, 2003 // IMSC , University of Southern California // File: pp-app.h // Written for : ns-2.26 // Last updated: April 23, 2003 // #include "timer-handler.h" #include "packet.h" #include "app.h" #include "udp-pp.h" #define MAX_NODE_NUM 256 // maximum peers allowed to connect to each node #define MAX_DELAY 200 // set maximum delay in ms #define MAX_DEGREE 3 // set the maximum node allowed to connect // This is used for receiver's received packet accounting struct pkt_accounting { int last_seq; // sequence number of last received PP pkt int last_scale; // rate (0-4) of last acked int lost_pkts; // number of lost pkts since last ack int recv_pkts; // number of received pkts since last ack double rtt; // round trip time }; class PPApp; // Sender uses this timer to // schedule next voice data packet transmission time // if the node is in talking mode class SendVoiceTimer : public TimerHandler { public: SendVoiceTimer(PPApp* t) : TimerHandler() {t_=t;} inline virtual void expire(Event*); protected: PPApp* t_; }; //Nodes this timer to schedule // next checking time for connection failure class CheckTimer : public TimerHandler { public: CheckTimer(PPApp* t) : TimerHandler(), t_(t) {} inline virtual void expire(Event*); protected: PPApp* t_; }; // PeerToPeer Application Class Definition class PPApp : public Application { public: PPApp(); void send_voice_pkt(); // called by SendVoiceTimer:expire to // deliver the voice stream void send_check_pkt(); // called by CheckTimer:expire for // unexpected failure of connection //list of address of connected nodes nsaddr_t peerlist[MAX_DEGREE]; //maximum allowed peers int peer_n ; //current connected peer number int next_slot(); //return the next available slot for join //Categories of nodes int core; // value==1 if the node is core int RP; // value==1 if the node is Rendezvous Point int firstpeer; // value==1 if the node is First Peer(nodes that // directly connecte to core) int leaf; // value==1 if the node is leaf node int normal; // value==1 if the node is not a special node // named above //Important outer nodes nsaddr_t parent_node; // Address of parent node in the CBT nsaddr_t core_node; // Address of core in case of need nsaddr_t bk_node; // Address of a backup node, this node maybe // the same as the parent_node and not // guarantee to serve as backup protected: int command(int argc, const char*const* argv); void start(); // Start running the program void stop(); // Stop running the program void join(); // Try to Join the nodes that conencted to, // it could be RP but also can be other nodes // The node will start receiving voice stream // void leave(); // leave the CBT group, but keep the program running, // this is almost the same as stop() except that // once a node stopped, it need to call start() again // before it can join() // //Start talking and keep it on for t_time for simulation purpose. void talk(double t_time); private: //status of the node int running_; // value ==1 if the program is running, // set by start() int talking_; // value ==1 if the user of this node is // talking, set by talk() int joined_; // value ==1 if the node has joined in the // chatting group //Parameters of the network int pktsize_; // Application data packet size double rate[5]; // Transmission rates associated to scale values int scale_; // Media scale parameter double interval_; // Time needed to complete one packet transmission double t_timeover; // If talking==1 , it shows time that a user need to stop // talking (this is used to simplify simulation) int random_; // If 1 add randomness to the interval int seq_; // Application data packet sequence number //functions //Major function virtual void recv_msg(int nbytes, const char *msg = 0); // called when there is // new packet coming //Miscellaneous functions void init(); inline double next_snd_time(); // next time to send out // the voice packets // void set_scale(const hdr_pp *mh_buf); // dynamically ajust the // the connecton speed void adjust_scale(void); // (only a place holder now) // void account_recv_pkt(const hdr_pp *mh_buf); // Statistic function void init_recv_pkt_accounting(); // (only a place holder now) void print_peer(); //print out current peer //statisitic variable pkt_accounting p_accnt; //Timer SendVoiceTimer snd_timer_; // SendVoiceTimer CheckTimer chk_timer_; // CheckTimer };