xorp

redist_xrl.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2009 XORP, Inc.
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/rib/redist_xrl.hh,v 1.18 2008/10/02 21:58:11 bms Exp $
00021 
00022 #ifndef __RIB_REDIST_XRL_HH__
00023 #define __RIB_REDIST_XRL_HH__
00024 
00025 #include "rt_tab_redist.hh"
00026 #include "libxorp/profile.hh"
00027 
00028 class XrlRouter;
00029 
00030 template <typename A> class RedistXrlTask;
00031 
00036 template <typename A>
00037 class RedistXrlOutput : public RedistOutput<A>
00038 {
00039 public:
00040     typedef RedistXrlTask<A>    Task;
00041     typedef list<Task*>     TaskQueue;
00042 
00043 public:
00056     RedistXrlOutput(Redistributor<A>*   redistributor,
00057             XrlRouter&      xrl_router,
00058             Profile&        profile,
00059             const string&   from_protocol,
00060             const string&   xrl_target_name,
00061             const IPNet<A>& network_prefix,
00062             const string&   cookie);
00063     ~RedistXrlOutput();
00064 
00065     void add_route(const IPRouteEntry<A>& ipr);
00066     void delete_route(const IPRouteEntry<A>& ipr);
00067 
00068     void starting_route_dump();
00069     void finishing_route_dump();
00070 
00071     virtual void task_completed(Task* task);
00072     void task_failed_fatally(Task* task);
00073 
00074     const string& xrl_target_name() const;
00075     const string& cookie() const;
00076 
00077 public:
00078     static const uint32_t HI_WATER   = 100;
00079     static const uint32_t LO_WATER   =   5;
00080     static const uint32_t RETRY_PAUSE_MS =  10;
00081 
00082 protected:
00083     void start_next_task();
00084 
00085     void    incr_inflight();
00086     void    decr_inflight();
00087 
00088     void    enqueue_task(Task* task);
00089     void    dequeue_task(Task* task);
00090 
00091 protected:
00092     XrlRouter&  _xrl_router;
00093     Profile&    _profile;
00094     string  _from_protocol;
00095     string  _target_name;
00096     IPNet<A>    _network_prefix;
00097     string  _cookie;
00098 
00099     TaskQueue   _taskq;
00100     uint32_t    _queued;
00101 
00102     TaskQueue   _flyingq;
00103     uint32_t    _inflight;
00104 
00105     bool    _flow_controlled;
00106     bool    _callback_pending;
00107 };
00108 
00114 template <typename A>
00115 class RedistTransactionXrlOutput : public RedistXrlOutput<A>
00116 {
00117 public:
00118     typedef typename RedistXrlOutput<A>::Task Task;
00119 
00120 public:
00121     RedistTransactionXrlOutput(Redistributor<A>*    redistributor,
00122                    XrlRouter&       xrl_router,
00123                    Profile&         profile,
00124                    const string&        from_protocol,
00125                    const string&        xrl_target_name,
00126                    const IPNet<A>&      network_prefix,
00127                    const string&        cookie);
00128 
00129     void add_route(const IPRouteEntry<A>& ipr);
00130     void delete_route(const IPRouteEntry<A>& ipr);
00131 
00132     void starting_route_dump();
00133     void finishing_route_dump();
00134 
00135     void task_completed(Task* task);
00136 
00137     void set_callback_pending(bool v);
00138 
00139     uint32_t tid() const;
00140     void set_tid(uint32_t v);
00141 
00142     bool transaction_in_progress() const;
00143     void set_transaction_in_progress(bool v);
00144 
00145     bool transaction_in_error() const;
00146     void set_transaction_in_error(bool v);
00147 
00148     // The size of the transaction that is build-in-progress
00149     size_t transaction_size() const { return _transaction_size; }
00150     void reset_transaction_size() { _transaction_size = 0; }
00151     void incr_transaction_size() { _transaction_size++; }
00152 
00153     static const size_t MAX_TRANSACTION_SIZE     = 100;
00154 
00155 protected:
00156     uint32_t    _tid;           // Send-in-progress transaction ID
00157     bool    _transaction_in_progress;
00158     bool    _transaction_in_error;
00159     size_t  _transaction_size;  // Build-in-progress transaction size
00160 };
00161 
00162 
00163 // ----------------------------------------------------------------------------
00164 // Globally accessible RedistXrlOutput inline methods
00165 
00166 template <typename A>
00167 const string&
00168 RedistXrlOutput<A>::xrl_target_name() const
00169 {
00170     return _target_name;
00171 }
00172 
00173 template <typename A>
00174 const string&
00175 RedistXrlOutput<A>::cookie() const
00176 {
00177     return _cookie;
00178 }
00179 
00180 
00181 // ----------------------------------------------------------------------------
00182 // Protected RedistXrlOutput inline methods
00183 
00184 template <typename A>
00185 void
00186 RedistXrlOutput<A>::incr_inflight()
00187 {
00188     if (_inflight == HI_WATER - 1)
00189     _flow_controlled = true;
00190     _inflight++;
00191 }
00192 
00193 template <typename A>
00194 void
00195 RedistXrlOutput<A>::decr_inflight()
00196 {
00197     if (_flow_controlled && _inflight < LO_WATER)
00198     _flow_controlled = false;
00199     _inflight--;
00200 }
00201 
00202 
00203 // ----------------------------------------------------------------------------
00204 // Inline RedistrTransactionXrlOutput methods
00205 
00206 template <typename A>
00207 inline uint32_t
00208 RedistTransactionXrlOutput<A>::tid() const
00209 {
00210     return _tid;
00211 }
00212 
00213 template <typename A>
00214 inline void
00215 RedistTransactionXrlOutput<A>::set_tid(uint32_t v)
00216 {
00217     _tid = v;
00218 }
00219 
00220 template <typename A>
00221 inline void
00222 RedistTransactionXrlOutput<A>::set_callback_pending(bool v)
00223 {
00224     this->_callback_pending = v;
00225 }
00226 
00227 template <typename A>
00228 inline bool
00229 RedistTransactionXrlOutput<A>::transaction_in_progress() const
00230 {
00231     return _transaction_in_progress;
00232 }
00233 
00234 template <typename A>
00235 inline void
00236 RedistTransactionXrlOutput<A>::set_transaction_in_progress(bool v)
00237 {
00238     _transaction_in_progress = v;
00239 }
00240 
00241 template <typename A>
00242 inline bool
00243 RedistTransactionXrlOutput<A>::transaction_in_error() const
00244 {
00245     return _transaction_in_error;
00246 }
00247 
00248 template <typename A>
00249 inline void
00250 RedistTransactionXrlOutput<A>::set_transaction_in_error(bool v)
00251 {
00252     _transaction_in_error = v;
00253 }
00254 
00255 #endif // __RIB_REDIST_XRL_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations