xorp

fibconfig_transaction.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/fea/fibconfig_transaction.hh,v 1.9 2008/10/02 21:56:46 bms Exp $
00021 
00022 #ifndef __FEA_FIBCONFIG_TRANSACTION_HH__
00023 #define __FEA_FIBCONFIG_TRANSACTION_HH__
00024 
00025 #include "libxorp/ipv4.hh"
00026 #include "libxorp/ipv4net.hh"
00027 #include "libxorp/ipv6.hh"
00028 #include "libxorp/ipv6net.hh"
00029 #include "libxorp/transaction.hh"
00030 
00031 #include "fibconfig.hh"
00032 
00033 
00040 class FibConfigTransactionManager : public TransactionManager {
00041 public:
00049     FibConfigTransactionManager(EventLoop& eventloop, FibConfig& fibconfig)
00050     : TransactionManager(eventloop, TIMEOUT_MS, MAX_PENDING),
00051       _fibconfig(fibconfig)
00052     {}
00053 
00060     FibConfig& fibconfig() { return _fibconfig; }
00061 
00068     const string& error() const     { return _first_error; }
00069 
00075     size_t max_ops() const { return MAX_OPS; }
00076 
00077 protected:
00086     virtual void pre_commit(uint32_t tid);
00087 
00096     virtual void post_commit(uint32_t tid);
00097 
00106     virtual void operation_result(bool success,
00107                   const TransactionOperation& op);
00108 
00109 private:
00118     int set_error(const string& error);
00119 
00123     void reset_error()          { _first_error.erase(); }
00124 
00125     FibConfig&  _fibconfig;     // The FibConfig to use
00126     string  _first_error;       // The string with the first error
00127 
00128     enum { TIMEOUT_MS = 5000, MAX_PENDING = 10, MAX_OPS = 200 };
00129 };
00130 
00134 class FibConfigTransactionOperation : public TransactionOperation {
00135 public:
00136     FibConfigTransactionOperation(FibConfig& fibconfig)
00137     : _fibconfig(fibconfig) {}
00138     virtual ~FibConfigTransactionOperation() {}
00139 
00140 protected:
00141     FibConfig& fibconfig() { return _fibconfig; }
00142 
00143 private:
00144     FibConfig& _fibconfig;
00145 };
00146 
00151 class FibAddEntry4 : public FibConfigTransactionOperation {
00152 public:
00153     FibAddEntry4(FibConfig& fibconfig,
00154          const IPv4Net& net,
00155          const IPv4&    nexthop,
00156          const string&  ifname,
00157          const string&  vifname,
00158          uint32_t   metric,
00159          uint32_t   admin_distance,
00160          bool       xorp_route,
00161          bool       is_connected_route)
00162     : FibConfigTransactionOperation(fibconfig),
00163       _fte(net, nexthop, ifname, vifname, metric, admin_distance,
00164            xorp_route) {
00165     if (is_connected_route)
00166         _fte.mark_connected_route();
00167     }
00168 
00169     bool dispatch() {
00170     if (fibconfig().add_entry4(_fte) != XORP_OK)
00171         return (false);
00172     return (true);
00173     }
00174 
00175     string str() const {
00176     return c_format("AddEntry4: %s",  _fte.str().c_str());
00177     }
00178 
00179 private:
00180     Fte4 _fte;
00181 };
00182 
00187 class FibDeleteEntry4 : public FibConfigTransactionOperation {
00188 public:
00189     FibDeleteEntry4(FibConfig&      fibconfig,
00190             const IPv4Net&  net,
00191             const IPv4&     nexthop,
00192             const string&   ifname,
00193             const string&   vifname,
00194             uint32_t        metric,
00195             uint32_t        admin_distance,
00196             bool        xorp_route,
00197             bool        is_connected_route)
00198     : FibConfigTransactionOperation(fibconfig),
00199       _fte(net, nexthop, ifname, vifname, metric, admin_distance,
00200            xorp_route) {
00201     if (is_connected_route)
00202         _fte.mark_connected_route();
00203     }
00204 
00205     bool dispatch() {
00206     if (fibconfig().delete_entry4(_fte) != XORP_OK)
00207         return (false);
00208     return (true);
00209     }
00210 
00211     string str() const {
00212     return c_format("DeleteEntry4: %s", _fte.str().c_str());
00213     }
00214 
00215 private:
00216     Fte4 _fte;
00217 };
00218 
00223 class FibDeleteAllEntries4 : public FibConfigTransactionOperation {
00224 public:
00225     FibDeleteAllEntries4(FibConfig& fibconfig)
00226     : FibConfigTransactionOperation(fibconfig) {}
00227 
00228     bool dispatch() {
00229     if (fibconfig().delete_all_entries4() != XORP_OK)
00230         return (false);
00231     return (true);
00232     }
00233 
00234     string str() const { return c_format("DeleteAllEntries4"); }
00235 };
00236 
00241 class FibAddEntry6 : public FibConfigTransactionOperation {
00242 public:
00243     FibAddEntry6(FibConfig& fibconfig,
00244          const IPv6Net& net,
00245          const IPv6&    nexthop,
00246          const string&  ifname,
00247          const string&  vifname,
00248          uint32_t   metric,
00249          uint32_t   admin_distance,
00250          bool       xorp_route,
00251          bool       is_connected_route)
00252     : FibConfigTransactionOperation(fibconfig),
00253       _fte(net, nexthop, ifname, vifname, metric, admin_distance,
00254            xorp_route) {
00255     if (is_connected_route)
00256         _fte.mark_connected_route();
00257     }
00258 
00259     bool dispatch() {
00260     if (fibconfig().add_entry6(_fte) != XORP_OK)
00261         return (false);
00262     return (true);
00263     }
00264 
00265     string str() const { 
00266     return c_format("AddEntry6: %s", _fte.str().c_str());
00267     }
00268 
00269 private:
00270     Fte6 _fte;
00271 };
00272 
00277 class FibDeleteEntry6 : public FibConfigTransactionOperation {
00278 public:
00279     FibDeleteEntry6(FibConfig&      fibconfig,
00280             const IPv6Net&  net,
00281             const IPv6&     nexthop,
00282             const string&   ifname,
00283             const string&   vifname,
00284             uint32_t        metric,
00285             uint32_t        admin_distance,
00286             bool        xorp_route,
00287             bool        is_connected_route)
00288     : FibConfigTransactionOperation(fibconfig),
00289       _fte(net, nexthop, ifname, vifname, metric, admin_distance,
00290            xorp_route) {
00291     if (is_connected_route)
00292         _fte.mark_connected_route();
00293     }
00294 
00295     bool dispatch() {
00296     if (fibconfig().delete_entry6(_fte) != XORP_OK)
00297         return (false);
00298     return (true);
00299     }
00300 
00301     string str() const {
00302     return c_format("DeleteEntry6: %s", _fte.str().c_str());
00303     }
00304 
00305 private:
00306     Fte6 _fte;
00307 };
00308 
00313 class FibDeleteAllEntries6 : public FibConfigTransactionOperation {
00314 public:
00315     FibDeleteAllEntries6(FibConfig& fibconfig)
00316     : FibConfigTransactionOperation(fibconfig) {}
00317 
00318     bool dispatch() {
00319     if (fibconfig().delete_all_entries6() != XORP_OK)
00320         return (false);
00321     return (true);
00322     }
00323 
00324     string str() const { return c_format("DeleteAllEntries6"); }
00325 };
00326 
00327 #endif // __FEA_FIBCONFIG_TRANSACTION_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations