/***** Selective Repeat ARQ protocol SRN in NS2 Muhammad Hanif Abdul Wahid 0428935 hanifw@yahoo.com 29/02/2008 *****/ #include #include "agent.h" #include "packet.h" #include "tclcl.h" #include "address.h" #include "ip.h" //header for selective repeat class hdr_srn { public: double ts_; int seqno_; int ptype_;//ptype_=0 for DATA pkt; //ptype_= 1 for ACK pkt; //ptype_ = 2 for NAK pkt; double send_time; /*Packet header offset*/ static int offset_; //function that return the header offset inline static int& offset(){ return offset_; }; //function to access selective packet header inline static hdr_srn* access(Packet* p) { return (hdr_srn*) p->access(offset_); } //function that return the packet's sequence no int& seqno() { return (seqno_); } }; //initialization of class SRNAgent class SRNAgent; //class SRNAgentTimer that inherit from class timerhandler to handle selective repeat timer class SRNAgentTimer : public TimerHandler { public: SRNAgentTimer(SRNAgent* a) : TimerHandler() { a_=a; }; protected: virtual void expire(Event* e);//executed when timeout SRNAgent* a_; }; //class SRNAgent that inherit from class Agent from Agent.h class SRNAgent : public Agent { public: SRNAgent(); //constructor int command(int argc, const char*const* argv); // export the C++ control to OTcl void output(int,int,double); //producing the packet void recv(Packet*, Handler*); //action when packet received void sendpkt(); //function to send packet void resendpkt(); //function to resend unACKed packet when timeout occured private: int bytestosend; //no of byte to be send int packetSize_; //size of the DATA packet int ackpacketSize_; //size of the ACK packet int nakpacketSize_; //size of the NAK packet double rto_; //retranmission time out-timer SRNAgentTimer rto_timer_; //SRNAgentTimer object int windowSize; //window Size int m; };