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_pushback_h
00038 #define ns_pushback_h
00039
00040 #include "config.h"
00041 #include "packet.h"
00042 #include "ip.h"
00043 #include "agent.h"
00044 #include "address.h"
00045 #include "node.h"
00046 #include "route.h"
00047 #include "timer-handler.h"
00048
00049 #include "pushback-constants.h"
00050 #include "pushback-message.h"
00051
00052 class PushbackQueue;
00053 class PushbackEventList;
00054 class IdentStruct;
00055 class RateLimitSession;
00056
00057 struct hdr_pushback {
00058
00059 PushbackMessage * msg_;
00060
00061 static int offset_;
00062 inline static int& offset() {
00063 return offset_;
00064 }
00065 inline static hdr_pushback * access(Packet *p) {
00066 return (hdr_pushback *) p->access(offset_);
00067 }
00068 };
00069
00070
00071 struct queue_rec {
00072
00073 PushbackQueue * pbq_;
00074 IdentStruct * idTree_;
00075
00076
00077
00078 };
00079
00080 class PushbackEvent;
00081 class PushbackTimer;
00082
00083 class PushbackAgent : public Agent {
00084
00085 public:
00086 PushbackAgent();
00087 int command(int argc, const char*const* argv);
00088 void reportDrop(int qid, Packet * p);
00089 void timeout(PushbackEvent * event);
00090 void identifyAggregate(int qid, double arrRate, double linkBW);
00091 void resetDropLog(int qid);
00092 void recv(Packet *p, Handler *);
00093 void calculateLowerBound(int qid, double arrRate);
00094
00095 int last_index_;
00096 int verbose_;
00097 int intResult_;
00098 int debugLevel;
00099 char prnMsg[500];
00100
00101 static int mergerAccept(int count, int bits, int bitsDiff);
00102 void printMsg(char *msg, int msgLevel);
00103
00104 Node * node_;
00105
00106 protected:
00107 int enable_pushback_;
00108 queue_rec queue_list_[MAX_QUEUES];
00109 double requiredLimit_;
00110
00111
00112 RouteLogic * rtLogic_;
00113 PushbackTimer * timer_;
00114
00115 void initialUpdate(RateLimitSession * rls);
00116 void pushbackCheck(RateLimitSession * rls);
00117 void pushbackStatus(RateLimitSession* rls);
00118 void pushbackRefresh(int qid);
00119 void pushbackCancel(RateLimitSession* rls);
00120
00121 void processPushbackRequest(PushbackRequestMessage * msg);
00122 void processPushbackStatus(PushbackStatusMessage *msg);
00123 void processPushbackRefresh(PushbackRefreshMessage *msg);
00124 void processPushbackCancel(PushbackCancelMessage *msg);
00125
00126 void refreshUpstreamLimits(RateLimitSession * rls);
00127 int getQID(int sender);
00128 int checkQID(int qid);
00129 void sendMsg(PushbackMessage * msg);
00130 };
00131
00132
00133
00134 class PushbackEvent {
00135
00136 public:
00137 double time_;
00138 int eventID_;
00139 RateLimitSession * rls_;
00140 int qid_;
00141
00142 PushbackEvent * next_;
00143
00144 PushbackEvent(double delay, int eventID, RateLimitSession * rls) {
00145 time_ = Scheduler::instance().clock() + delay;
00146 eventID_ = eventID;
00147 rls_ = rls;
00148 qid_= -1;
00149 next_=NULL;
00150 }
00151
00152 PushbackEvent(double delay, int eventID, int qid) {
00153 time_ = Scheduler::instance().clock() + delay;
00154 eventID_ = eventID;
00155 rls_=NULL;
00156 qid_=qid;
00157 next_=NULL;
00158 }
00159
00160 void setSucc(PushbackEvent * event) {
00161 next_=event;
00162 }
00163
00164 static char * type(PushbackEvent * event) {
00165 switch (event->eventID_) {
00166 case PUSHBACK_CHECK_EVENT: return "CHECK";
00167 case PUSHBACK_REFRESH_EVENT: return "REFRESH";
00168 case PUSHBACK_STATUS_EVENT: return "STATUS";
00169 case INITIAL_UPDATE_EVENT: return "INITIAL UPDATE";
00170 default: return "UNKNOWN";
00171 }
00172 }
00173 };
00174
00175 class PushbackTimer: public TimerHandler {
00176
00177 public:
00178 PushbackEvent * firstEvent_;
00179
00180 PushbackTimer(PushbackAgent * agent): firstEvent_(NULL) { agent_ = agent;}
00181 void insert(PushbackEvent * event);
00182 void cancelStatus(RateLimitSession * rls);
00183 void removeEvents(RateLimitSession * rls);
00184 int containsRefresh(int qid);
00185
00186 protected:
00187 PushbackAgent * agent_;
00188 virtual void expire(Event *e);
00189 void schedule();
00190 void sanityCheck();
00191 };
00192
00193 #endif