• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/pushback/pushback.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 2000  International Computer Science Institute
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by ACIRI, the AT&T 
00017  *      Center for Internet Research at ICSI (the International Computer
00018  *      Science Institute).
00019  * 4. Neither the name of ACIRI nor of ICSI may be used
00020  *    to endorse or promote products derived from this software without
00021  *    specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY ICSI AND CONTRIBUTORS ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL ICSI OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
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 // a structure to store details of each link on the node.
00071 struct queue_rec {
00072 
00073   PushbackQueue * pbq_;             //pointer to the queue object
00074   IdentStruct * idTree_;              // this queues prefix tree
00075 
00076   // other required variables go here
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];  //hopefully long enough
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; //rls->localQID_;
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 

Generated on Tue Aug 10 2010 16:16:07 for ns-2.33 by  doxygen 1.7.1