• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ParentSelection.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /*****************************************************************************
00025  *
00026  *  ParentSelection.h - Interface to Parent Selection System
00027  *
00028  *
00029  ****************************************************************************/
00030 
00031 #ifndef _PARENT_SELECTION_H_
00032 #define _PARENT_SELECTION_H_
00033 
00034 #include "Main.h"
00035 #include "ProxyConfig.h"
00036 #include "ControlBase.h"
00037 #include "ControlMatcher.h"
00038 
00039 #include "ink_apidefs.h"
00040 
00041 #include "P_RecProcess.h"
00042 
00043 #include "libts.h"
00044 
00045 #define MAX_PARENTS 64
00046 
00047 struct RequestData;
00048 
00049 struct matcher_line;
00050 struct ParentResult;
00051 class ParentRecord;
00052 
00053 enum ParentResultType
00054 {
00055   PARENT_UNDEFINED, PARENT_DIRECT,
00056   PARENT_SPECIFIED, PARENT_AGENT, PARENT_FAIL
00057 };
00058 
00059 typedef ControlMatcher<ParentRecord, ParentResult> P_table;
00060 
00061 //
00062 // API to outside world
00063 //
00064 struct ParentResult
00065 {
00066   ParentResult()
00067     : r(PARENT_UNDEFINED), hostname(NULL), port(0), line_number(0), epoch(NULL), rec(NULL),
00068       last_parent(0), start_parent(0), wrap_around(false), retry(false)
00069   { memset(foundParents, 0, sizeof(foundParents)); };
00070 
00071   // For outside consumption
00072   ParentResultType r;
00073   const char *hostname;
00074   int port;
00075 
00076   // Internal use only
00077   //   Not to be modified by HTTP
00078   int line_number;
00079   P_table *epoch;               // A pointer to the table used.
00080   ParentRecord *rec;
00081   uint32_t last_parent;
00082   uint32_t start_parent;
00083   bool wrap_around;
00084   bool retry;
00085   //Arena *a;
00086   ATSConsistentHashIter chashIter;
00087   bool foundParents[MAX_PARENTS];
00088 };
00089 
00090 class HttpRequestData;
00091 
00092 struct ParentConfigParams:public ConfigInfo
00093 {
00094   ParentConfigParams();
00095   ~ParentConfigParams();
00096 
00097   // void findParent(RequestData* rdata, ParentResult* result)
00098   //
00099   //   Does initial parent lookup
00100   //
00101   inkcoreapi void findParent(HttpRequestData *rdata, ParentResult *result);
00102 
00103   // void markParentDown(ParentResult* rsult)
00104   //
00105   //    Marks the parent pointed to by result as down
00106   //
00107   inkcoreapi void markParentDown(ParentResult *result);
00108 
00109   // void recordRetrySuccess
00110   //
00111   //    After a successful retry, http calls this function
00112   //      to clear the bits indicating the parent is down
00113   //
00114   void recordRetrySuccess(ParentResult *result);
00115 
00116   // void nextParent(RequestData* rdata, ParentResult* result);
00117   //
00118   //    Marks the parent pointed to by result as down and attempts
00119   //      to find the next parent
00120   //
00121   inkcoreapi void nextParent(HttpRequestData *rdata, ParentResult *result);
00122 
00123   // bool parentExists(HttpRequestData* rdata)
00124   //
00125   //   Returns true if there is a parent matching the request data and
00126   //   false otherwise
00127   bool parentExists(HttpRequestData *rdata);
00128 
00129   // bool apiParentExists(HttpRequestData* rdata)
00130   //
00131   //   Retures true if a parent has been set through the api
00132   bool apiParentExists(HttpRequestData *rdata);
00133 
00134   P_table *ParentTable;
00135   ParentRecord *DefaultParent;
00136   int32_t ParentRetryTime;
00137   int32_t ParentEnable;
00138   int32_t FailThreshold;
00139   int32_t DNS_ParentOnly;
00140 };
00141 
00142 struct ParentConfig
00143 {
00144 public:
00145   static void startup();
00146   static void reconfigure();
00147   static void print();
00148 
00149   inkcoreapi static ParentConfigParams *acquire() { return (ParentConfigParams *) configProcessor.get(ParentConfig::m_id); }
00150   inkcoreapi static void release(ParentConfigParams *params) { configProcessor.release(ParentConfig::m_id, params); }
00151 
00152 
00153   static int m_id;
00154 };
00155 //
00156 // End API to outside world
00157 //
00158 
00159 
00160 // struct pRecord
00161 //
00162 //    A record for an invidual parent
00163 //
00164 struct pRecord : ATSConsistentHashNode
00165 {
00166   char hostname[MAXDNAME + 1];
00167   int port;
00168   time_t failedAt;
00169   int failCount;
00170   int32_t upAt;
00171   const char *scheme;           // for which parent matches (if any)
00172   int idx;
00173   float weight;
00174 };
00175 
00176 enum ParentRR_t
00177 {
00178   P_NO_ROUND_ROBIN = 0,
00179   P_STRICT_ROUND_ROBIN,
00180   P_HASH_ROUND_ROBIN,
00181   P_CONSISTENT_HASH
00182 };
00183 
00184 // class ParentRecord : public ControlBase
00185 //
00186 //   A record for a configuration line in the parent.config
00187 //    file
00188 //
00189 class ParentRecord: public ControlBase
00190 {
00191 public:
00192   ParentRecord()
00193     : parents(NULL), num_parents(0), round_robin(P_NO_ROUND_ROBIN), rr_next(0), go_direct(true), chash(NULL)
00194   { }
00195 
00196   ~ParentRecord();
00197 
00198   char *Init(matcher_line *line_info);
00199   bool DefaultInit(char *val);
00200   void UpdateMatch(ParentResult *result, RequestData *rdata);
00201   void FindParent(bool firstCall, ParentResult *result, RequestData *rdata, ParentConfigParams *config);
00202   void Print();
00203   pRecord *parents;
00204   int num_parents;
00205 
00206   bool bypass_ok() const { return go_direct; }
00207 
00208   const char *scheme;
00209   //private:
00210   const char *ProcessParents(char *val);
00211   void buildConsistentHash(void);
00212   ParentRR_t round_robin;
00213   volatile uint32_t rr_next;
00214   bool go_direct;
00215   ATSConsistentHash *chash;
00216 };
00217 
00218 // Helper Functions
00219 ParentRecord *createDefaultParent(char *val);
00220 void reloadDefaultParent(char *val);
00221 void reloadParentFile();
00222 int parentSelection_CB(const char *name, RecDataT data_type, RecData data, void *cookie);
00223 
00224 // Unit Test Functions
00225 void show_result(ParentResult *aParentResult);
00226 void br(HttpRequestData *h, const char *os_hostname, sockaddr const* dest_ip = NULL);       // short for build request
00227 int verify(ParentResult *r, ParentResultType e, const char *h, int p);
00228 
00229 /*
00230   For supporting multiple Socks servers, we essentially use the
00231   ParentSelection infrastructure. Only the initialization is different.
00232   If needed, we will have to implement most of the functions in
00233   ParentSection.cc for Socks as well. For right now we will just use
00234   ParentSelection
00235 
00236   All the members in ParentConfig are static. Right now
00237   we will duplicate the code for these static functions.
00238 */
00239 struct SocksServerConfig
00240 {
00241   static void startup();
00242   static void reconfigure();
00243   static void print();
00244 
00245   static ParentConfigParams *acquire() { return (ParentConfigParams *) configProcessor.get(SocksServerConfig::m_id); }
00246   static void release(ParentConfigParams *params) { configProcessor.release(SocksServerConfig::m_id, params); }
00247 
00248   static int m_id;
00249 };
00250 
00251 #endif

Generated by  doxygen 1.7.1