xorp

parser_direct_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_direct_cmds.hh,v 1.26 2008/10/02 21:58:10 bms Exp $
00021 
00022 #ifndef __RIB_PARSER_DIRECT_CMDS_HH__
00023 #define __RIB_PARSER_DIRECT_CMDS_HH__
00024 
00025 #include "parser.hh"
00026 
00027 // ----------------------------------------------------------------------------
00028 // Direct RIB Commands (operate on an instance of a RIB<IPv4>).
00029 
00030 class DirectTableOriginCommand : public TableOriginCommand {
00031 public:
00032     DirectTableOriginCommand(RIB<IPv4>& rib)
00033     : TableOriginCommand(), _rib(rib) {}
00034     int execute() {
00035     cout << "TableOriginCommand::execute " << _tablename << "\n";
00036     // On the context of this test code, we don't care whether it's an
00037     // IGP or an EGP, because we do the plumbing explicitly.  So it's
00038     // safe to just say it's an IGP, even if its not.
00039     return _rib.new_origin_table(_tablename, "", "", _admin_distance, IGP);
00040     }
00041 private:
00042     RIB<IPv4>& _rib;
00043 };
00044 
00045 class DirectRouteAddCommand : public RouteAddCommand {
00046 public:
00047     DirectRouteAddCommand(RIB<IPv4>& rib)
00048     : RouteAddCommand(), _rib(rib) {}
00049     int execute() {
00050     cout << "RouteAddCommand::execute " << _tablename << " ";
00051     cout << _net.str() << " " << _nexthop.str() << " "
00052          << c_format("%u", XORP_UINT_CAST(_metric)) << "\n";
00053     return _rib.add_route(_tablename, _net, _nexthop, "", "",
00054                   _metric, PolicyTags());
00055     }
00056 private:
00057     RIB<IPv4>& _rib;
00058 };
00059 
00060 class DirectRouteVifAddCommand : public RouteVifAddCommand {
00061 public:
00062     DirectRouteVifAddCommand(RIB<IPv4>& rib)
00063     : RouteVifAddCommand(), _rib(rib) {}
00064     int execute() {
00065     cout << "RouteVifAddCommand::execute " << _tablename << " ";
00066     cout << _net.str() << " " << _vifname << " " << _nexthop.str() << " "
00067          << c_format("%u", XORP_UINT_CAST(_metric)) << "\n";
00068     return _rib.add_route(_tablename, _net, _nexthop, "", _vifname,
00069                   _metric, PolicyTags());
00070     }
00071 private:
00072     RIB<IPv4>& _rib;
00073 };
00074 
00075 class DirectRouteDeleteCommand : public RouteDeleteCommand {
00076 public:
00077     DirectRouteDeleteCommand(RIB<IPv4>& rib)
00078     : RouteDeleteCommand(), _rib(rib) {}
00079     int execute() {
00080     cout << "RouteDeleteCommand::execute " << _tablename << " "
00081          << _net.str() << endl;
00082     return _rib.delete_route(_tablename, _net);
00083     }
00084 private:
00085     RIB<IPv4>& _rib;
00086 };
00087 
00088 class DirectRouteVerifyCommand : public RouteVerifyCommand {
00089 public:
00090     DirectRouteVerifyCommand(RIB<IPv4>& rib)
00091     : RouteVerifyCommand(), _rib(rib) {}
00092     int execute() {
00093     cout << "RouteVerifyCommand::execute " << _type
00094          << " " << _lookupaddr.str()
00095          << " " << _ifname
00096          << " " << _nexthop.str()
00097          << " " << c_format("%u", XORP_UINT_CAST(_metric))
00098          << "\n";
00099 
00100     RibVerifyType verifytype;
00101     if (_type == "miss")
00102         verifytype = RibVerifyType(MISS);
00103     else if (_type == "discard")
00104         verifytype = RibVerifyType(DISCARD);
00105     else if (_type == "unreachable")
00106         verifytype = RibVerifyType(UNREACHABLE);
00107     else if (_type == "ip")
00108         verifytype = RibVerifyType(IP);
00109     else {
00110         cerr <<
00111 "RouteVerify Failed: invalid match type specification " << _type << "\n";
00112 #ifndef TESTING_INTERACTIVELY
00113         // XXX stub this out if interactive
00114         abort();
00115 #endif
00116     }
00117 
00118     int dummy = _rib.verify_route(_lookupaddr, _ifname, _nexthop,
00119                       _metric, verifytype);
00120     if (dummy != XORP_OK) {
00121         cerr << "RouteVerify Failed!\n";
00122 #ifndef TESTING_INTERACTIVELY
00123         // XXX stub this out if interactive
00124         abort();
00125 #endif
00126     }
00127 #ifndef TESTING_INTERACTIVELY
00128         // XXX stub this out if interactive
00129     return dummy;
00130 #else
00131     return XORP_OK;
00132 #endif
00133     }
00134 private:
00135     RIB<IPv4>& _rib;
00136 };
00137 
00138 class DirectDiscardVifCommand : public DiscardVifCommand {
00139 public:
00140     DirectDiscardVifCommand(RIB<IPv4>& rib)
00141     : DiscardVifCommand(), _rib(rib) {}
00142     int execute() {
00143     cout << "DiscardVifCommand::execute " << _ifname << " ";
00144     cout << _addr.str() << "\n";
00145 
00146     Vif vif(_ifname);
00147     IPv4Net subnet(_addr, _prefix_len);
00148     VifAddr vifaddr(_addr, subnet, IPv4::ZERO(), IPv4::ZERO());
00149     vif.add_address(vifaddr);
00150     vif.set_discard(true);
00151     vif.set_underlying_vif_up(true);
00152     cout << "**** Vif: " << vif.str() << endl;
00153 
00154     return _rib.new_vif(_ifname, vif);
00155     }
00156 private:
00157     RIB<IPv4>& _rib;
00158 };
00159 
00160 class DirectUnreachableVifCommand : public UnreachableVifCommand {
00161 public:
00162     DirectUnreachableVifCommand(RIB<IPv4>& rib)
00163     : UnreachableVifCommand(), _rib(rib) {}
00164     int execute() {
00165     cout << "UnreachableVifCommand::execute " << _ifname << " ";
00166     cout << _addr.str() << "\n";
00167 
00168     Vif vif(_ifname);
00169     IPv4Net subnet(_addr, _prefix_len);
00170     VifAddr vifaddr(_addr, subnet, IPv4::ZERO(), IPv4::ZERO());
00171     vif.add_address(vifaddr);
00172     vif.set_unreachable(true);
00173     vif.set_underlying_vif_up(true);
00174     cout << "**** Vif: " << vif.str() << endl;
00175 
00176     return _rib.new_vif(_ifname, vif);
00177     }
00178 private:
00179     RIB<IPv4>& _rib;
00180 };
00181 
00182 class DirectManagementVifCommand : public ManagementVifCommand {
00183 public:
00184     DirectManagementVifCommand(RIB<IPv4>& rib)
00185     : ManagementVifCommand(), _rib(rib) {}
00186     int execute() {
00187     cout << "ManagementVifCommand::execute " << _ifname << " ";
00188     cout << _addr.str() << "\n";
00189 
00190     Vif vif(_ifname);
00191     IPv4Net subnet(_addr, _prefix_len);
00192     VifAddr vifaddr(_addr, subnet, IPv4::ZERO(), IPv4::ZERO());
00193     vif.add_address(vifaddr);
00194     vif.set_management(true);
00195     vif.set_underlying_vif_up(true);
00196     cout << "**** Vif: " << vif.str() << endl;
00197 
00198     return _rib.new_vif(_ifname, vif);
00199     }
00200 private:
00201     RIB<IPv4>& _rib;
00202 };
00203 
00204 class DirectEtherVifCommand : public EtherVifCommand {
00205 public:
00206     DirectEtherVifCommand(RIB<IPv4>& rib)
00207     : EtherVifCommand(), _rib(rib) {}
00208     int execute() {
00209     cout << "EtherVifCommand::execute " << _ifname << " ";
00210     cout << _addr.str() << "\n";
00211 
00212     Vif vif(_ifname);
00213     IPv4Net subnet(_addr, _prefix_len);
00214     VifAddr vifaddr(_addr, subnet, IPv4::ZERO(), IPv4::ZERO());
00215     vif.add_address(vifaddr);
00216     vif.set_underlying_vif_up(true);
00217     cout << "**** Vif: " << vif.str() << endl;
00218 
00219     return _rib.new_vif(_ifname, vif);
00220     }
00221 private:
00222     RIB<IPv4>& _rib;
00223 };
00224 
00225 class DirectLoopbackVifCommand : public LoopbackVifCommand {
00226 public:
00227     DirectLoopbackVifCommand(RIB<IPv4>& rib)
00228     : LoopbackVifCommand(), _rib(rib) {}
00229     int execute() {
00230     cout << "LoopbackVifCommand::execute " << _ifname << " ";
00231     cout << _addr.str() << "\n";
00232 
00233     Vif vif(_ifname);
00234     IPv4Net subnet(_addr, _prefix_len);
00235     VifAddr vifaddr(_addr, subnet, IPv4::ZERO(), IPv4::ZERO());
00236     vif.add_address(vifaddr);
00237     vif.set_loopback(true);
00238     vif.set_underlying_vif_up(true);
00239     cout << "**** Vif: " << vif.str() << endl;
00240 
00241     return _rib.new_vif(_ifname, vif);
00242     }
00243 private:
00244     RIB<IPv4>& _rib;
00245 };
00246 
00247 class DirectAddIGPTableCommand : public AddIGPTableCommand {
00248 public:
00249     DirectAddIGPTableCommand(RIB<IPv4>& rib) :
00250     AddIGPTableCommand(), _rib(rib) {}
00251     int execute() {
00252     cout << "AddIGPTableCommand::execute " << _tablename << "\n";
00253     return _rib.add_igp_table(_tablename, "", "");
00254     }
00255 private:
00256     RIB<IPv4>& _rib;
00257 };
00258 
00259 class DirectDeleteIGPTableCommand : public DeleteIGPTableCommand {
00260 public:
00261     DirectDeleteIGPTableCommand(RIB<IPv4>& rib) :
00262     DeleteIGPTableCommand(), _rib(rib) {}
00263     int execute() {
00264     cout << "DeleteIGPTableCommand::execute " << _tablename << "\n";
00265     return _rib.delete_igp_table(_tablename, "", "");
00266     }
00267 private:
00268     RIB<IPv4>& _rib;
00269 };
00270 
00271 class DirectAddEGPTableCommand : public AddEGPTableCommand {
00272 public:
00273     DirectAddEGPTableCommand(RIB<IPv4>& rib) :
00274     AddEGPTableCommand(), _rib(rib) {}
00275     int execute() {
00276     cout << "AddEGPTableCommand::execute " << _tablename << "\n";
00277     return _rib.add_egp_table(_tablename, "", "");
00278     }
00279 private:
00280     RIB<IPv4>& _rib;
00281 };
00282 
00283 class DirectDeleteEGPTableCommand : public DeleteEGPTableCommand {
00284 public:
00285     DirectDeleteEGPTableCommand(RIB<IPv4>& rib) :
00286     DeleteEGPTableCommand(), _rib(rib) {}
00287     int execute() {
00288     cout << "DeleteEGPTableCommand::execute " << _tablename << "\n";
00289     return _rib.delete_egp_table(_tablename, "", "");
00290     }
00291 private:
00292     RIB<IPv4>& _rib;
00293 };
00294 
00295 #endif // __RIB_PARSER_DIRECT_CMDS_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations