00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef ns_snoop_h
00038 #define ns_snoop_h
00039
00040 #include "scheduler.h"
00041 #include "packet.h"
00042 #include "ip.h"
00043 #include "tcp.h"
00044 #include "ll.h"
00045 #include "mac.h"
00046 #include "flags.h"
00047 #include "template.h"
00048
00049
00050 #define SNOOP_ACTIVE 0x01
00051 #define SNOOP_CLOSED 0x02
00052 #define SNOOP_NOACK 0x04
00053 #define SNOOP_FULL 0x08
00054 #define SNOOP_RTTFLAG 0x10
00055 #define SNOOP_ALIVE 0x20
00056 #define SNOOP_WLALIVE 0x40
00057 #define SNOOP_WLEMPTY 0x80
00058
00059 #define SNOOP_MAXWIND 100
00060 #define SNOOP_WLSEQS 8
00061 #define SNOOP_MIN_TIMO 0.100
00062 #define SNOOP_MAX_RXMIT 10
00063 #define SNOOP_PROPAGATE 1
00064 #define SNOOP_SUPPRESS 2
00065
00066 #define SNOOP_MAKEHANDLER 1
00067 #define SNOOP_TAIL 1
00068
00069 struct hdr_seq {
00070 int seq;
00071 int num;
00072 };
00073
00074 struct hdr_snoop {
00075 int seqno_;
00076 int numRxmit_;
00077 int senderRxmit_;
00078 double sndTime_;
00079
00080 static int offset_;
00081 inline static int& offset() { return offset_; }
00082 inline static hdr_snoop* access(const Packet* p) {
00083 return (hdr_snoop*) p->access(offset_);
00084 }
00085
00086 inline int& seqno() { return seqno_; }
00087 inline int& numRxmit() { return numRxmit_; }
00088 inline int& senderRxmit() { return senderRxmit_; }
00089 inline double& sndTime() { return sndTime_; }
00090 };
00091
00092 class LLSnoop : public LL {
00093 public:
00094 LLSnoop() : LL() { bind("integrate_", &integrate_);}
00095 void recv(Packet *, Handler *);
00096 void snoop_rtt(double);
00097 inline double timeout() {
00098 return max(srtt_+4*rttvar_, snoopTick_);
00099 }
00100 inline int integrate() { return integrate_; }
00101 protected:
00102 int integrate_;
00103 double srtt_;
00104 double rttvar_;
00105 double g_;
00106 double snoopTick_;
00107 };
00108
00109
00110 class SnoopRxmitHandler;
00111 class SnoopPersistHandler;
00112
00113 class Snoop : public NsObject {
00114 friend class SnoopRxmitHandler;
00115 friend class SnoopPersistHandler;
00116 public:
00117 Snoop();
00118 void recv(Packet *, Handler *);
00119 void handle(Event *);
00120 int snoop_rxmit(Packet *);
00121 inline int next(int i) { return (i+1) % maxbufs_; }
00122 inline int prev(int i) { return ((i == 0) ? maxbufs_-1 : i-1); };
00123 inline int wl_next(int i) { return (i+1) % SNOOP_WLSEQS; }
00124 inline int wl_prev(int i) { return ((i == 0) ? SNOOP_WLSEQS-1 : i-1);};
00125
00126 protected:
00127 int command(int argc, const char*const* argv);
00128 void reset();
00129 void wlreset();
00130 void snoop_data(Packet *);
00131 int snoop_ack(Packet *);
00132 void snoop_wless_data(Packet *);
00133 void snoop_wired_ack(Packet *);
00134 int snoop_wlessloss(int);
00135 double snoop_cleanbufs_(int);
00136 void snoop_rtt(double);
00137 int snoop_qlong();
00138 int snoop_insert(Packet *);
00139 inline int empty_()
00140 {return (bufhead_==buftail_ &&!(fstate_&SNOOP_FULL));}
00141 void savepkt_(Packet *, int, int);
00142 void update_state_();
00143 inline double timeout() {
00144 if (!parent_->integrate())
00145 return max(srtt_+4*rttvar_, snoopTick_);
00146 else
00147 return parent_->timeout();
00148 }
00149 void snoop_cleanup();
00150
00151 LLSnoop *parent_;
00152 NsObject* recvtarget_;
00153 Handler *callback_;
00154 SnoopRxmitHandler *rxmitHandler_;
00155 SnoopPersistHandler *persistHandler_;
00156 int snoopDisable_;
00157 u_short fstate_;
00158 int lastSeen_;
00159 int lastAck_;
00160 int expNextAck_;
00161 short expDupacks_;
00162 double srtt_;
00163 double rttvar_;
00164 double tailTime_;
00165 int rxmitStatus_;
00166 short bufhead_;
00167 Event *toutPending_;
00168 short buftail_;
00169 Packet *pkts_[SNOOP_MAXWIND];
00170
00171 int wl_state_;
00172 int wl_lastSeen_;
00173 int wl_lastAck_;
00174 int wl_bufhead_;
00175 int wl_buftail_;
00176 hdr_seq *wlseqs_[SNOOP_WLSEQS];
00177
00178 int maxbufs_;
00179 double snoopTick_;
00180 double g_;
00181 int integrate_;
00182 int lru_;
00183 };
00184
00185 class SnoopRxmitHandler : public Handler {
00186 public:
00187 SnoopRxmitHandler(Snoop *s) : snoop_(s) {}
00188 void handle(Event *event);
00189 protected:
00190 Snoop *snoop_;
00191 };
00192
00193 class SnoopPersistHandler : public Handler {
00194 public:
00195 SnoopPersistHandler(Snoop *s) : snoop_(s) {}
00196
00197 protected:
00198 Snoop *snoop_;
00199 };
00200
00201 #endif