• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/pushback/rate-limit.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_rate_limit_h
00038 #define ns_rate_limit_h
00039 
00040 #include "node.h"
00041 #include "packet.h"
00042 #include "route.h"
00043 
00044 #include "agg-spec.h"
00045 #include "rate-limit-strategy.h"
00046 #include "logging-data-struct.h"
00047 
00048 class RateLimitSession {
00049 
00050  public:
00051   int pushbackON_;  //whether pushback has been called/propagated on this aggregate 
00052                     //  if pushback is ON, the node needs to send pushback refresh messages
00053   int origin_;      //id of the node who requested rate limiting; either itself or 
00054                     // one hop downstream (send status in latter case).
00055 
00056   //snapshot view taken once pushback is invoked/propagated.
00057   //used to report status before arrival of status messages from upstream.
00058   //double snapshotArrivalRate_;
00059  
00060   //Queue ID of the rate limiting session
00061   int localQID_;
00062   int remoteQID_; //qid downstream
00063   
00064   //session ID of rate limiting
00065   int localID_;   
00066   int remoteID_;  //id downstream;
00067 
00068   AggSpec * aggSpec_;
00069   
00070   //meaningful only for sessions started on this node.
00071   double lowerBound_;       // the specified lower bound for this aggregate.
00072   int merged_;              // whether merged or not
00073   int initialPhase_;        // the initial probability increasing phase.
00074 
00075   //position of this RLS in tree.
00076   int heightInPTree_; //from leaf.
00077   int depthInPTree_;  //from root.
00078   
00079   double startTime_;
00080   double expiryTime_;  //time when this rate-limiting should expire;
00081   double refreshTime_;
00082   RateLimitSession * next_; //next session in the list;
00083 
00084   RateLimitStrategy * rlStrategy_;
00085   LoggingDataStruct * logData_;
00086 
00087   //constructor for locally started sessions.
00088   RateLimitSession(AggSpec * aggSpec, double estimate, int initial,  double limit, int origin, 
00089                    int locQid, 
00090                    double delay, double lowerBound, Node *node, RouteLogic * rtLogic_);
00091 
00092   //for sessions started on pushback request.
00093   RateLimitSession(AggSpec * aggSpec, double limit, int originID,  int locQid, int remQid, 
00094                    int remoteID, int depth, double delay, double lowerBound, Node *node, RouteLogic * rtLogic_);
00095 
00096   ~RateLimitSession();
00097 
00098   void setSucc(RateLimitSession * session) {next_ =  session;}
00099   double log(Packet *p, int lowDemand);
00100   double getDropRate();
00101   void pushbackOn();
00102   void refreshed();
00103   void setAggSpec(AggSpec * aggSpec);
00104   void setLimit(double limit);
00105   double getArrivalRateForStatus();
00106   static RateLimitSession * merge(RateLimitSession *, RateLimitSession *, int bits);
00107  
00108  private:
00109   static double pick4merge(double, double, int);
00110 };
00111 
00112 
00113 class RateLimitSessionList {
00114 
00115  public:
00116   RateLimitSession * first_;
00117   int noSessions_;
00118   
00119   int IDCounter_;
00120 
00121   RateLimitSessionList(): first_(NULL), noSessions_(0), IDCounter_(0){};
00122   int insert(RateLimitSession * session); 
00123   int filter(Packet * p, int lowDemand);
00124   int containsAggSpec(AggSpec *);
00125   RateLimitSession * containsLocalAggSpec(AggSpec * spec, int myID);
00126   void mergeSessions(int myID);
00127   int noMySessions(int myID);
00128   void endSession(RateLimitSession *);
00129   int getMySubsetCount(int prefix, int bits, int myID);
00130   void merge(int prefix, int bits, int myID);
00131   RateLimitSession * getSessionByLocalID(int localID);
00132   RateLimitSession * getSessionByRemoteID(int remoteID);
00133   
00134   //returns number of sessions with sending rate strictly more than this rate.
00135         int rankRate(int myID, double rate);    
00136         int rankSession(int myID, RateLimitSession * session);
00137 };
00138 
00139 
00140 #endif

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