xorp

parser_xrl_cmds.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/parser_xrl_cmds.hh,v 1.20 2008/10/02 21:58:10 bms Exp $
00021 
00022 #ifndef __RIB_PARSER_XRL_CMDS_HH__
00023 #define __RIB_PARSER_XRL_CMDS_HH__
00024 
00025 #include "xrl/interfaces/rib_xif.hh"
00026 
00027 #include "parser.hh"
00028 
00029 
00030 enum XrlCompletion {
00031     XRL_PENDING = 0,    // hack - corresponds with success for Parser::execute
00032     SUCCESS     = 1,
00033     XRL_FAILED  = -1
00034 };
00035 
00036 // Simple handler - most of RIB interface just returns true/false
00037 
00038 static void
00039 pass_fail_handler(const XrlError& e, XrlCompletion* c)
00040 {
00041     if (e == XrlError::OKAY()) {
00042     *c = SUCCESS;
00043     } else {
00044     *c = XRL_FAILED;
00045     cerr << "Xrl Failed: " << e.str() << endl;
00046     }
00047     cout << "PassFailHander " << *c << endl;
00048 }
00049 
00050 // ----------------------------------------------------------------------------
00051 // XRL Commands (NB fewer than number of direct commands)
00052 
00053 class XrlRouteAddCommand : public RouteAddCommand {
00054 public:
00055     XrlRouteAddCommand(EventLoop&    e,
00056                XrlRibV0p1Client& xrl_client,
00057                XrlCompletion&    completion)
00058     : RouteAddCommand(),
00059       _eventloop(e), _xrl_client(xrl_client), _completion(completion) {}
00060 
00061     int execute() {
00062     cout << "RouteAddCommand::execute " << _tablename << " " << _net.str()
00063          << " " << _nexthop.str() << endl;
00064 
00065     _completion = XRL_PENDING;
00066     bool unicast = true, multicast = false;
00067 
00068     PolicyTags pt;
00069 
00070     _xrl_client.send_add_route4(
00071         "rib", _tablename, unicast, multicast, _net, _nexthop, _metric,
00072         pt.xrl_atomlist(),  // XXX: no policy
00073         callback(&pass_fail_handler, &_completion));
00074 
00075     return _completion;
00076     }
00077 
00078 private:
00079     EventLoop&        _eventloop;
00080     XrlRibV0p1Client& _xrl_client;
00081     XrlCompletion&    _completion;
00082 };
00083 
00084 class XrlRouteDeleteCommand : public RouteDeleteCommand {
00085 public:
00086     XrlRouteDeleteCommand(EventLoop&        e,
00087               XrlRibV0p1Client& xrl_client,
00088               XrlCompletion&    completion)
00089     : RouteDeleteCommand(),
00090       _eventloop(e), _xrl_client(xrl_client), _completion(completion) {}
00091 
00092     int execute() {
00093     cout << "RouteDeleteCommand::execute " << _tablename << " "
00094          << _net.str() << endl;
00095 
00096     _completion = XRL_PENDING;
00097     bool unicast = true, multicast = false;
00098 
00099     _xrl_client.send_delete_route4(
00100         "rib", _tablename, unicast, multicast, _net,
00101         callback(&pass_fail_handler, &_completion));
00102 
00103     return _completion;
00104     }
00105 
00106 private:
00107     EventLoop&        _eventloop;
00108     XrlRibV0p1Client& _xrl_client;
00109     XrlCompletion&     _completion;
00110 };
00111 
00112 class XrlAddIGPTableCommand : public AddIGPTableCommand {
00113 public:
00114     XrlAddIGPTableCommand(EventLoop&        e,
00115               XrlRibV0p1Client& xrl_client,
00116               XrlCompletion&    completion) :
00117     AddIGPTableCommand(), _eventloop(e), _xrl_client(xrl_client),
00118     _completion(completion) {}
00119 
00120     int execute() {
00121     cout << "AddIGPTableCommand::execute " << _tablename << endl;
00122 
00123     _completion = XRL_PENDING;
00124     bool unicast = true, multicast = false;
00125 
00126     _xrl_client.send_add_igp_table4(
00127         "rib", _tablename, "", "", unicast, multicast,
00128         callback(&pass_fail_handler, &_completion));
00129 
00130     return _completion;
00131     }
00132 
00133 private:
00134     EventLoop&        _eventloop;
00135     XrlRibV0p1Client& _xrl_client;
00136     XrlCompletion&    _completion;
00137 };
00138 
00139 class XrlDeleteIGPTableCommand : public DeleteIGPTableCommand {
00140 public:
00141     XrlDeleteIGPTableCommand(EventLoop&     e,
00142                  XrlRibV0p1Client&  xrl_client,
00143                  XrlCompletion& completion) :
00144     DeleteIGPTableCommand(),
00145     _eventloop(e), _xrl_client(xrl_client), _completion(completion) {}
00146 
00147     int execute() {
00148     cout << "DeleteIGPTableCommand::execute " << _tablename << endl;
00149 
00150     _completion = XRL_PENDING;
00151     bool unicast = true, multicast = false;
00152 
00153     _xrl_client.send_delete_igp_table4(
00154         "rib", _tablename, "", "", unicast, multicast,
00155         callback(&pass_fail_handler, &_completion)
00156         );
00157 
00158     return _completion;
00159     }
00160 
00161 private:
00162     EventLoop&        _eventloop;
00163     XrlRibV0p1Client& _xrl_client;
00164     XrlCompletion&    _completion;
00165 };
00166 
00167 class XrlAddEGPTableCommand : public AddEGPTableCommand {
00168 public:
00169     XrlAddEGPTableCommand(EventLoop&        e,
00170               XrlRibV0p1Client& xrl_client,
00171               XrlCompletion&    completion) :
00172     AddEGPTableCommand(), _eventloop(e), _xrl_client(xrl_client),
00173     _completion(completion) {}
00174     int execute() {
00175     cout << "AddEGPTableCommand::execute " << _tablename << endl;
00176 
00177     _completion = XRL_PENDING;
00178 
00179     bool unicast = true, multicast = false;
00180     _xrl_client.send_add_egp_table4(
00181         "rib", _tablename, "", "", unicast, multicast,
00182         callback(&pass_fail_handler, &_completion));
00183 
00184     return _completion;
00185     }
00186 
00187 private:
00188     EventLoop&        _eventloop;
00189     XrlRibV0p1Client& _xrl_client;
00190     XrlCompletion&    _completion;
00191 };
00192 
00193 class XrlDeleteEGPTableCommand : public DeleteEGPTableCommand {
00194 public:
00195     XrlDeleteEGPTableCommand(EventLoop&     e,
00196                  XrlRibV0p1Client&  xrl_client,
00197                  XrlCompletion& completion) :
00198     DeleteEGPTableCommand(), _eventloop(e), _xrl_client(xrl_client),
00199     _completion(completion) {}
00200     int execute() {
00201     cout << "DeleteEGPTableCommand::execute " << _tablename << endl;
00202 
00203     _completion = XRL_PENDING;
00204     bool unicast = true, multicast = false;
00205     _xrl_client.send_delete_egp_table4(
00206         "rib", _tablename, "", "", unicast, multicast,
00207         callback(&pass_fail_handler, &_completion));
00208 
00209     return _completion;
00210     }
00211 
00212 private:
00213     EventLoop&        _eventloop;
00214     XrlRibV0p1Client& _xrl_client;
00215     XrlCompletion&    _completion;
00216 };
00217 
00218 #endif // __RIB_PARSER_XRL_CMDS_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations