xorp

xrl_target_common.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License, Version 2, June
00008 // 1991 as published by the Free Software Foundation. Redistribution
00009 // and/or modification of this program under the terms of any other
00010 // version of the GNU General Public License is not permitted.
00011 // 
00012 // This program is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00015 // see the GNU General Public License, Version 2, a copy of which can be
00016 // found in the XORP LICENSE.gpl file.
00017 // 
00018 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00019 // http://xorp.net
00020 
00021 
00022 #ifndef __RIP_XRL_TARGET_COMMON_HH__
00023 #define __RIP_XRL_TARGET_COMMON_HH__
00024 
00025 #include "libxorp/status_codes.h"
00026 
00027 #include "peer.hh"
00028 
00029 class XrlProcessSpy;
00030 template <typename A> class XrlPortManager;
00031 template <typename A> class System;
00032 template <typename A> class XrlRedistManager;
00033 
00040 template <typename A>
00041 class XrlRipCommonTarget {
00042 public:
00043     XrlRipCommonTarget(XrlProcessSpy&       xps,
00044                XrlPortManager<A>&   xpm,
00045                XrlRedistManager<A>& xrm,
00046                System<A>&       rip_system);
00047 
00048     ~XrlRipCommonTarget();
00049 
00050     void set_status(ProcessStatus ps, const string& annotation = "");
00051 
00052     XrlCmdError common_0_1_get_status(uint32_t& status, string& reason);
00053 
00054     XrlCmdError common_0_1_shutdown();
00055     XrlCmdError common_0_1_startup();
00056 
00057     XrlCmdError
00058     finder_event_observer_0_1_xrl_target_birth(const string& class_name,
00059                            const string& instance_name);
00060 
00061     XrlCmdError
00062     finder_event_observer_0_1_xrl_target_death(const string& class_name,
00063                            const string& instance_name);
00064 
00065     XrlCmdError
00066     ripx_0_1_add_rip_address(const string&  ifname,
00067                  const string&  vifname,
00068                  const A&       addr);
00069 
00070     XrlCmdError
00071     ripx_0_1_remove_rip_address(const string&   ifname,
00072                 const string&   vifname,
00073                 const A&    addr);
00074 
00075     XrlCmdError
00076     ripx_0_1_set_rip_address_enabled(const string&  ifname,
00077                      const string&  vifname,
00078                      const A&       addr,
00079                      const bool&    enabled);
00080 
00081     XrlCmdError
00082     ripx_0_1_rip_address_enabled(const string&  ifname,
00083                  const string&  vifname,
00084                  const A&   addr,
00085                  bool&      enabled);
00086 
00087     XrlCmdError ripx_0_1_set_cost(const string&     ifname,
00088                   const string&     vifname,
00089                   const A&      addr,
00090                   const uint32_t&   cost);
00091 
00092     XrlCmdError ripx_0_1_cost(const string& ifname,
00093                   const string& vifname,
00094                   const A&      addr,
00095                   uint32_t&     cost);
00096 
00097     XrlCmdError ripx_0_1_set_horizon(const string&  ifname,
00098                      const string&  vifname,
00099                      const A&       addr,
00100                      const string&  horizon);
00101 
00102     XrlCmdError ripx_0_1_horizon(const string&  ifname,
00103                  const string&  vifname,
00104                  const A&   addr,
00105                  string&    horizon);
00106 
00107     XrlCmdError ripx_0_1_set_passive(const string&  ifname,
00108                      const string&  vifname,
00109                      const A&       addr,
00110                      const bool&    passive);
00111 
00112     XrlCmdError ripx_0_1_passive(const string&  ifname,
00113                  const string&  vifname,
00114                  const A&   addr,
00115                  bool&      passive);
00116 
00117     XrlCmdError
00118     ripx_0_1_set_accept_non_rip_requests(const string&  ifname,
00119                      const string&  vifname,
00120                      const A&   addr,
00121                      const bool&    accept);
00122 
00123     XrlCmdError ripx_0_1_accept_non_rip_requests(const string&  ifname,
00124                          const string&  vifname,
00125                          const A&   addr,
00126                          bool&      accept);
00127 
00128     XrlCmdError ripx_0_1_set_accept_default_route(const string& ifname,
00129                           const string& vifname,
00130                           const A&  addr,
00131                           const bool&   accept);
00132 
00133     XrlCmdError ripx_0_1_accept_default_route(const string& ifname,
00134                           const string& vifname,
00135                           const A&      addr,
00136                           bool&     accept);
00137 
00138     XrlCmdError
00139     ripx_0_1_set_advertise_default_route(const string&  ifname,
00140                      const string&  vifname,
00141                      const A&   addr,
00142                      const bool&    advertise);
00143 
00144     XrlCmdError ripx_0_1_advertise_default_route(const string&  ifname,
00145                          const string&  vifname,
00146                          const A&   addr,
00147                          bool&      advertise);
00148 
00149     XrlCmdError
00150     ripx_0_1_set_route_timeout(const string&    ifname,
00151                    const string&    vifname,
00152                    const A&     addr,
00153                    const uint32_t&  t_secs);
00154 
00155     XrlCmdError
00156     ripx_0_1_route_timeout(const string&    ifname,
00157                const string&    vifname,
00158                const A&     addr,
00159                uint32_t&        t_secs);
00160 
00161     XrlCmdError
00162     ripx_0_1_set_deletion_delay(const string&   ifname,
00163                 const string&   vifname,
00164                 const A&    addr,
00165                 const uint32_t& t_secs);
00166 
00167     XrlCmdError
00168     ripx_0_1_deletion_delay(const string&   ifname,
00169                 const string&   vifname,
00170                 const A&        addr,
00171                 uint32_t&       t_secs);
00172 
00173     XrlCmdError
00174     ripx_0_1_set_request_interval(const string&     ifname,
00175                   const string&     vifname,
00176                   const A&      addr,
00177                   const uint32_t&   t_secs);
00178 
00179     XrlCmdError
00180     ripx_0_1_request_interval(const string& ifname,
00181                   const string& vifname,
00182                   const A&      addr,
00183                   uint32_t&     t_secs);
00184 
00185     XrlCmdError
00186     ripx_0_1_set_update_interval(const string&  ifname,
00187                  const string&  vifname,
00188                  const A&   addr,
00189                  const uint32_t& t_secs);
00190 
00191     XrlCmdError
00192     ripx_0_1_update_interval(const string&  ifname,
00193                  const string&  vifname,
00194                  const A&       addr,
00195                  uint32_t&      t_secs);
00196 
00197     XrlCmdError
00198     ripx_0_1_set_update_jitter(const string&    ifname,
00199                    const string&    vifname,
00200                    const A& addr,
00201                    const uint32_t&  t_jitter);
00202 
00203     XrlCmdError
00204     ripx_0_1_update_jitter(const string&    ifname,
00205                const string&    vifname,
00206                const A&     addr,
00207                uint32_t&        t_secs);
00208 
00209     XrlCmdError
00210     ripx_0_1_set_triggered_update_delay(const string&   ifname,
00211                     const string&   vifname,
00212                     const A&    addr,
00213                     const uint32_t& t_secs);
00214 
00215     XrlCmdError
00216     ripx_0_1_triggered_update_delay(const string&   ifname,
00217                     const string&   vifname,
00218                     const A&        addr,
00219                     uint32_t&       t_secs);
00220 
00221     XrlCmdError
00222     ripx_0_1_set_triggered_update_jitter(const string&  ifname,
00223                      const string&  vifname,
00224                      const A&   addr,
00225                      const uint32_t& t_secs);
00226 
00227     XrlCmdError
00228     ripx_0_1_triggered_update_jitter(const string&  ifname,
00229                      const string&  vifname,
00230                      const A&       addr,
00231                      uint32_t&      t_secs);
00232 
00233     XrlCmdError
00234     ripx_0_1_set_interpacket_delay(const string&    ifname,
00235                    const string&    vifname,
00236                    const A&     addr,
00237                    const uint32_t&  t_msecs);
00238 
00239     XrlCmdError
00240     ripx_0_1_interpacket_delay(const string&    ifname,
00241                    const string&    vifname,
00242                    const A&     addr,
00243                    uint32_t&    t_msecs);
00244 
00245     XrlCmdError ripx_0_1_rip_address_status(const string&   ifname,
00246                         const string&   vifname,
00247                         const A&        addr,
00248                         string&     status);
00249 
00250     XrlCmdError ripx_0_1_get_all_addresses(XrlAtomList& ifnames,
00251                        XrlAtomList& vifnames,
00252                        XrlAtomList& addrs);
00253 
00254     XrlCmdError ripx_0_1_get_peers(const string& ifname,
00255                    const string& vifname,
00256                    const A&  addr,
00257                    XrlAtomList&  peers);
00258 
00259     XrlCmdError ripx_0_1_get_all_peers(XrlAtomList& peers,
00260                        XrlAtomList& ifnames,
00261                        XrlAtomList& vifnames,
00262                        XrlAtomList& addrs);
00263 
00264     XrlCmdError ripx_0_1_get_counters(const string& ifname,
00265                       const string& vifname,
00266                       const A&      addr,
00267                       XrlAtomList&  descriptions,
00268                       XrlAtomList&  values);
00269 
00270     XrlCmdError ripx_0_1_get_peer_counters(const string&    ifname,
00271                        const string&    vifname,
00272                        const A&     addr,
00273                        const A&     peer,
00274                        XrlAtomList&     descriptions,
00275                        XrlAtomList&     values,
00276                        uint32_t&        peer_last_pkt);
00277 
00278     XrlCmdError trace(bool enable);
00279 
00280     XrlCmdError socketx_user_0_1_recv_event(const string&   sockid,
00281                         const string&   if_name,
00282                         const string&   vif_name,
00283                         const A&        src_host,
00284                         const uint32_t& src_port,
00285                         const vector<uint8_t>& pdata);
00286 
00287     XrlCmdError socketx_user_0_1_inbound_connect_event(
00288     const string&   sockid,
00289     const A&    src_host,
00290     const uint32_t& src_port,
00291     const string&   new_sockid,
00292     bool&       accept);
00293 
00294     XrlCmdError socketx_user_0_1_outgoing_connect_event(
00295     const string&   sockid);
00296 
00297     XrlCmdError socketx_user_0_1_error_event(const string&  sockid,
00298                          const string&  reason,
00299                          const bool&    fatal);
00300 
00301     XrlCmdError socketx_user_0_1_disconnect_event(const string& sockid);
00302 
00303     XrlCmdError policy_backend_0_1_configure(const uint32_t& filter,
00304                          const string& conf);
00305 
00306     XrlCmdError policy_backend_0_1_reset(const uint32_t& filter);
00307 
00308     XrlCmdError policy_backend_0_1_push_routes();
00309 
00310 
00311     XrlCmdError policy_redistx_0_1_add_routex(const IPNet<A>&       net,
00312                           const bool&       unicast,
00313                           const bool&       multicast,
00314                           const A&          nexthop,
00315                           const uint32_t&       metric,
00316                           const XrlAtomList&    policytags);
00317 
00318     XrlCmdError policy_redistx_0_1_delete_routex(const IPNet<A>&    net,
00319                          const bool&        unicast,
00320                          const bool&        multicast);
00321 
00331     pair<Port<A>*,XrlCmdError> find_port(const string&  ifname,
00332                      const string&  vifname,
00333                      const A&   addr);
00334 
00335 protected:
00336     XrlProcessSpy&      _xps;
00337     XrlPortManager<A>&      _xpm;
00338     XrlRedistManager<A>&    _xrm;
00339 
00340     ProcessStatus       _status;
00341     string          _status_note;
00342 
00343     System<A>&          _rip_system;
00344 };
00345 
00346 
00347 // ----------------------------------------------------------------------------
00348 // Inline implementation of XrlRipCommonTarget
00349 
00350 template <typename A>
00351 XrlRipCommonTarget<A>::XrlRipCommonTarget(XrlProcessSpy&    xps,
00352                       XrlPortManager<A>&    xpm,
00353                       XrlRedistManager<A>&  xrm,
00354                       System<A>&        rip_system)
00355     : _xps(xps), _xpm(xpm), _xrm(xrm),
00356       _status(PROC_NULL), _status_note(""),
00357       _rip_system(rip_system)
00358 {
00359 }
00360 
00361 template <typename A>
00362 XrlRipCommonTarget<A>::~XrlRipCommonTarget()
00363 {
00364 }
00365 
00366 template <typename A>
00367 void
00368 XrlRipCommonTarget<A>::set_status(ProcessStatus status, const string& note)
00369 {
00370     debug_msg("Status Update %d -> %d: %s\n", _status, status, note.c_str());
00371     _status      = status;
00372     _status_note = note;
00373 }
00374 
00375 template <typename A>
00376 XrlCmdError
00377 XrlRipCommonTarget<A>::common_0_1_get_status(uint32_t& status,
00378                          string&   reason)
00379 {
00380     status = _status;
00381     reason = _status_note;
00382     return XrlCmdError::OKAY();
00383 }
00384 
00385 template <typename A>
00386 XrlCmdError
00387 XrlRipCommonTarget<A>::common_0_1_shutdown()
00388 {
00389     debug_msg("Shutdown requested.\n");
00390     xorp_do_run = 0;
00391     return XrlCmdError::OKAY();
00392 }
00393 
00394 template <typename A>
00395 XrlCmdError
00396 XrlRipCommonTarget<A>::common_0_1_startup()
00397 {
00398     debug_msg("Startup requested.\n");
00399     return XrlCmdError::OKAY();
00400 }
00401 
00402 template <typename A>
00403 XrlCmdError
00404 XrlRipCommonTarget<A>::finder_event_observer_0_1_xrl_target_birth(
00405                             const string& cname,
00406                             const string& iname
00407                             )
00408 {
00409     _xps.birth_event(cname, iname);
00410     return XrlCmdError::OKAY();
00411 }
00412 
00413 template <typename A>
00414 XrlCmdError
00415 XrlRipCommonTarget<A>::finder_event_observer_0_1_xrl_target_death(
00416                             const string& cname,
00417                             const string& iname
00418                             )
00419 {
00420     _xps.death_event(cname, iname);
00421     return XrlCmdError::OKAY();
00422 }
00423 
00424 template <typename A>
00425 XrlCmdError
00426 XrlRipCommonTarget<A>::ripx_0_1_add_rip_address(const string&   ifname,
00427                            const string&    vifname,
00428                            const A&     addr)
00429 {
00430     debug_msg("rip_x_1_add_rip_address %s/%s/%s\n",
00431           ifname.c_str(), vifname.c_str(), addr.str().c_str());
00432     if (_xpm.add_rip_address(ifname, vifname, addr) == false) {
00433     return XrlCmdError::COMMAND_FAILED();
00434     }
00435     return XrlCmdError::OKAY();
00436 }
00437 
00438 template <typename A>
00439 XrlCmdError
00440 XrlRipCommonTarget<A>::ripx_0_1_remove_rip_address(const string& ifname,
00441                      const string&       vifname,
00442                      const A&            addr)
00443 {
00444     debug_msg("ripx_0_1_remove_rip_address %s/%s/%s\n",
00445           ifname.c_str(), vifname.c_str(), addr.str().c_str());
00446     if (_xpm.remove_rip_address(ifname, vifname, addr) == false) {
00447     return XrlCmdError::COMMAND_FAILED();
00448     }
00449     return XrlCmdError::OKAY();
00450 }
00451 
00452 
00453 // ----------------------------------------------------------------------------
00454 // Utility methods
00455 
00456 template <typename A>
00457 pair<Port<A>*, XrlCmdError>
00458 XrlRipCommonTarget<A>::find_port(const string&  ifn,
00459                  const string&  vifn,
00460                  const A&   addr)
00461 {
00462     Port<A>* p = _xpm.find_port(ifn, vifn, addr);
00463     if (p == 0) {
00464     string e = c_format("RIP not running on %s/%s/%s",
00465                 ifn.c_str(), vifn.c_str(), addr.str().c_str());
00466     return make_pair(p, XrlCmdError::COMMAND_FAILED(e));
00467     }
00468     return make_pair(p, XrlCmdError::OKAY());
00469 }
00470 
00471 
00472 // ----------------------------------------------------------------------------
00473 // Port configuration accessors and modifiers
00474 
00475 template <typename A>
00476 XrlCmdError
00477 XrlRipCommonTarget<A>::ripx_0_1_set_rip_address_enabled(const string&   ifn,
00478                             const string&   vifn,
00479                             const A&    addr,
00480                             const bool& en)
00481 {
00482     pair<Port<A>*, XrlCmdError> pp = find_port(ifn, vifn, addr);
00483     if (pp.first == 0)
00484     return pp.second;
00485 
00486     Port<A>* p = pp.first;
00487     p->set_enabled(en);
00488     return XrlCmdError::OKAY();
00489 }
00490 
00491 template <typename A>
00492 XrlCmdError
00493 XrlRipCommonTarget<A>::ripx_0_1_rip_address_enabled(const string& ifn,
00494                             const string& vifn,
00495                             const A&      addr,
00496                             bool&     en)
00497 {
00498     pair<Port<A>*, XrlCmdError> pp = find_port(ifn, vifn, addr);
00499     if (pp.first == 0)
00500     return pp.second;
00501 
00502     Port<A>* p = pp.first;
00503     en = p->enabled();
00504 
00505     return XrlCmdError::OKAY();
00506 }
00507 
00508 template <typename A>
00509 XrlCmdError
00510 XrlRipCommonTarget<A>::ripx_0_1_set_cost(const string&  ifname,
00511                    const string&        vifname,
00512                    const A&         addr,
00513                    const uint32_t&      cost)
00514 {
00515     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00516     if (pp.first == 0)
00517     return pp.second;
00518 
00519     Port<A>* p = pp.first;
00520 
00521     if (cost > RIP_INFINITY) {
00522     string e = c_format("Cost must be less that RIP infinity (%u)",
00523                 XORP_UINT_CAST(RIP_INFINITY));
00524     return XrlCmdError::COMMAND_FAILED(e);
00525     }
00526 
00527     p->set_cost(cost);
00528 
00529     return XrlCmdError::OKAY();
00530 }
00531 
00532 template <typename A>
00533 XrlCmdError
00534 XrlRipCommonTarget<A>::ripx_0_1_cost(const string&  ifname,
00535                      const string&  vifname,
00536                      const A&       addr,
00537                      uint32_t&      cost)
00538 {
00539     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00540     if (pp.first == 0)
00541     return pp.second;
00542 
00543     Port<A>* p = pp.first;
00544     cost = p->cost();
00545 
00546     return XrlCmdError::OKAY();
00547 }
00548 
00549 template <typename A>
00550 XrlCmdError
00551 XrlRipCommonTarget<A>::ripx_0_1_set_horizon(const string&   ifname,
00552                         const string&   vifname,
00553                         const A&        addr,
00554                         const string&   horizon)
00555 {
00556     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00557     if (pp.first == 0)
00558     return pp.second;
00559 
00560     Port<A>* p = pp.first;
00561 
00562     RipHorizon rh[3] = { NONE, SPLIT, SPLIT_POISON_REVERSE };
00563     for (uint32_t i = 0; i < 3; ++i) {
00564     if (string(rip_horizon_name(rh[i])) == horizon) {
00565         p->set_horizon(rh[i]);
00566         return XrlCmdError::OKAY();
00567     }
00568     }
00569     return XrlCmdError::COMMAND_FAILED(
00570             c_format("Horizon type \"%s\" not recognized.",
00571                  horizon.c_str()));
00572 }
00573 
00574 template <typename A>
00575 XrlCmdError
00576 XrlRipCommonTarget<A>::ripx_0_1_horizon(const string&   ifname,
00577                     const string&   vifname,
00578                     const A&    addr,
00579                     string&     horizon)
00580 {
00581     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00582     if (pp.first == 0)
00583     return pp.second;
00584 
00585     Port<A>* p = pp.first;
00586     horizon = rip_horizon_name(p->horizon());
00587     return XrlCmdError::OKAY();
00588 }
00589 
00590 template <typename A>
00591 XrlCmdError
00592 XrlRipCommonTarget<A>::ripx_0_1_set_passive(const string&   ifname,
00593                         const string&   vifname,
00594                         const A&        addr,
00595                         const bool&     passive)
00596 {
00597     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00598     if (pp.first == 0)
00599     return pp.second;
00600 
00601     Port<A>* p = pp.first;
00602     p->set_passive(passive);
00603     return XrlCmdError::OKAY();
00604 }
00605 
00606 template <typename A>
00607 XrlCmdError
00608 XrlRipCommonTarget<A>::ripx_0_1_passive(const string&   ifname,
00609                     const string&   vifname,
00610                     const A&    addr,
00611                     bool&       passive)
00612 {
00613     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00614     if (pp.first == 0)
00615     return pp.second;
00616 
00617     Port<A>* p = pp.first;
00618     passive = p->passive();
00619     return XrlCmdError::OKAY();
00620 }
00621 
00622 template <typename A>
00623 XrlCmdError
00624 XrlRipCommonTarget<A>::ripx_0_1_set_accept_non_rip_requests(
00625                         const string&   ifname,
00626                         const string&   vifname,
00627                         const A&    addr,
00628                         const bool& accept
00629                         )
00630 {
00631     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00632     if (pp.first == 0)
00633     return pp.second;
00634 
00635     Port<A>* p = pp.first;
00636     p->set_accept_non_rip_requests(accept);
00637     return XrlCmdError::OKAY();
00638 }
00639 
00640 template <typename A>
00641 XrlCmdError
00642 XrlRipCommonTarget<A>::ripx_0_1_accept_non_rip_requests(
00643                         const string&   ifname,
00644                         const string&   vifname,
00645                         const A&    addr,
00646                         bool&       accept
00647                         )
00648 {
00649     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00650     if (pp.first == 0)
00651     return pp.second;
00652 
00653     Port<A>* p = pp.first;
00654     accept = p->accept_non_rip_requests();
00655     return XrlCmdError::OKAY();
00656 }
00657 
00658 template <typename A>
00659 XrlCmdError
00660 XrlRipCommonTarget<A>::ripx_0_1_set_accept_default_route(
00661                         const string&   ifname,
00662                         const string&   vifname,
00663                         const A&    addr,
00664                         const bool& accept
00665                         )
00666 {
00667     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00668     if (pp.first == 0)
00669     return pp.second;
00670 
00671     Port<A>* p = pp.first;
00672     p->set_accept_default_route(accept);
00673     return XrlCmdError::OKAY();
00674 }
00675 
00676 template <typename A>
00677 XrlCmdError
00678 XrlRipCommonTarget<A>::ripx_0_1_accept_default_route(
00679                         const string&   ifname,
00680                         const string&   vifname,
00681                         const A&    addr,
00682                         bool&       accept
00683                         )
00684 {
00685     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00686     if (pp.first == 0)
00687     return pp.second;
00688 
00689     Port<A>* p = pp.first;
00690     accept = p->accept_default_route();
00691     return XrlCmdError::OKAY();
00692 }
00693 
00694 template <typename A>
00695 XrlCmdError
00696 XrlRipCommonTarget<A>::ripx_0_1_set_advertise_default_route(
00697                         const string&   ifname,
00698                         const string&   vifname,
00699                         const A&    addr,
00700                         const bool& advertise
00701                         )
00702 {
00703     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00704     if (pp.first == 0)
00705     return pp.second;
00706 
00707     Port<A>* p = pp.first;
00708     p->set_advertise_default_route(advertise);
00709     return XrlCmdError::OKAY();
00710 }
00711 
00712 template <typename A>
00713 XrlCmdError
00714 XrlRipCommonTarget<A>::ripx_0_1_advertise_default_route(
00715                         const string&   ifname,
00716                         const string&   vifname,
00717                         const A&    addr,
00718                         bool&       advertise
00719                         )
00720 {
00721     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);
00722     if (pp.first == 0)
00723     return pp.second;
00724 
00725     Port<A>* p = pp.first;
00726     advertise = p->advertise_default_route();
00727     return XrlCmdError::OKAY();
00728 }
00729 
00730 
00731 // ----------------------------------------------------------------------------
00732 // The following pair of macros are used in setting timer constants on
00733 // RIP ports.
00734 
00735 #define PORT_TIMER_SET_HANDLER(field, t, min_val, max_val, method)  \
00736 do {                                    \
00737     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);  \
00738     if (pp.first == 0)                          \
00739     return pp.second;                       \
00740     Port<A>* p = pp.first;                      \
00741                                     \
00742     if (static_cast<int32_t>(t) < min_val)              \
00743     return XrlCmdError::COMMAND_FAILED(c_format(            \
00744         "value supplied less than permitted minimum (%u < %u)",     \
00745         XORP_UINT_CAST(t), XORP_UINT_CAST(min_val)));       \
00746     if (t > max_val)                            \
00747     return XrlCmdError::COMMAND_FAILED(c_format(            \
00748         "value supplied greater than permitted maximum (%u > %u)",  \
00749         XORP_UINT_CAST(t), XORP_UINT_CAST(max_val)));       \
00750     if (p->constants().set_##field (t) == false)            \
00751     return XrlCmdError::COMMAND_FAILED(             \
00752         "Failed to set value.");                    \
00753     p->reschedule_##method ();                      \
00754     return XrlCmdError::OKAY();                     \
00755 } while (0)
00756 
00757 #define PORT_TIMER_GET_HANDLER(field, t)                \
00758 do {                                    \
00759     pair<Port<A>*, XrlCmdError> pp = find_port(ifname, vifname, addr);  \
00760     if (pp.first == 0)                          \
00761     return pp.second;                       \
00762     Port<A>* p = pp.first;                      \
00763     t = p->constants(). field ();                   \
00764     return XrlCmdError::OKAY();                     \
00765 } while (0)
00766 
00767 
00768 template <typename A>
00769 XrlCmdError
00770 XrlRipCommonTarget<A>::ripx_0_1_set_route_timeout(
00771                         const string&   ifname,
00772                         const string&   vifname,
00773                         const A&    addr,
00774                         const uint32_t& t
00775                         )
00776 {
00777     PORT_TIMER_SET_HANDLER(expiry_secs, t, 10, 10000, dummy_timer);
00778 }
00779 
00780 template <typename A>
00781 XrlCmdError
00782 XrlRipCommonTarget<A>::ripx_0_1_route_timeout(
00783                          const string&  ifname,
00784                          const string&  vifname,
00785                          const A&       addr,
00786                          uint32_t&      t
00787                          )
00788 {
00789     PORT_TIMER_GET_HANDLER(expiry_secs, t);
00790 }
00791 
00792 template <typename A>
00793 XrlCmdError
00794 XrlRipCommonTarget<A>::ripx_0_1_set_deletion_delay(
00795                         const string&   ifname,
00796                         const string&   vifname,
00797                         const A&    addr,
00798                         const uint32_t& t
00799                         )
00800 {
00801     PORT_TIMER_SET_HANDLER(deletion_secs, t, 10, 10000, dummy_timer);
00802 }
00803 
00804 template <typename A>
00805 XrlCmdError
00806 XrlRipCommonTarget<A>::ripx_0_1_deletion_delay(
00807                         const string&   ifname,
00808                         const string&   vifname,
00809                         const A&    addr,
00810                         uint32_t&   t
00811                         )
00812 {
00813     PORT_TIMER_GET_HANDLER(deletion_secs, t);
00814 }
00815 
00816 template <typename A>
00817 XrlCmdError
00818 XrlRipCommonTarget<A>::ripx_0_1_set_request_interval(
00819                         const string&   ifname,
00820                         const string&   vifname,
00821                         const A&    addr,
00822                         const uint32_t& t
00823                         )
00824 {
00825     PORT_TIMER_SET_HANDLER(table_request_period_secs, t, 0, 10000,
00826                request_table_timer);
00827 }
00828 
00829 template <typename A>
00830 XrlCmdError
00831 XrlRipCommonTarget<A>::ripx_0_1_request_interval(
00832                         const string&   ifname,
00833                         const string&   vifname,
00834                         const A&    addr,
00835                         uint32_t&   t
00836                         )
00837 {
00838     PORT_TIMER_GET_HANDLER(table_request_period_secs, t);
00839 }
00840 
00841 template <typename A>
00842 XrlCmdError
00843 XrlRipCommonTarget<A>::ripx_0_1_set_update_interval(
00844                         const string&   ifname,
00845                         const string&   vifname,
00846                         const A&    addr,
00847                         const uint32_t& t_secs
00848                         )
00849 {
00850     PORT_TIMER_SET_HANDLER(update_interval, t_secs, 1, 600, dummy_timer);
00851 }
00852 
00853 template <typename A>
00854 XrlCmdError
00855 XrlRipCommonTarget<A>::ripx_0_1_update_interval(const string&   ifname,
00856                         const string&   vifname,
00857                         const A&    addr,
00858                         uint32_t&   t_secs)
00859 {
00860     PORT_TIMER_GET_HANDLER(update_interval, t_secs);
00861 }
00862 
00863 template <typename A>
00864 XrlCmdError
00865 XrlRipCommonTarget<A>::ripx_0_1_set_update_jitter(const string& ifname,
00866                           const string& vifname,
00867                           const A&  addr,
00868                           const uint32_t& t_jitter)
00869 {
00870     PORT_TIMER_SET_HANDLER(update_jitter, t_jitter, 0, 100, dummy_timer);
00871 }
00872 
00873 template <typename A>
00874 XrlCmdError
00875 XrlRipCommonTarget<A>::ripx_0_1_update_jitter(const string& ifname,
00876                           const string& vifname,
00877                           const A&      addr,
00878                           uint32_t&     t_jitter)
00879 {
00880     PORT_TIMER_GET_HANDLER(update_jitter, t_jitter);
00881 }
00882 
00883 template <typename A>
00884 XrlCmdError
00885 XrlRipCommonTarget<A>::ripx_0_1_set_triggered_update_delay(
00886                         const string&   ifname,
00887                         const string&   vifname,
00888                         const A&    addr,
00889                         const uint32_t& t_secs)
00890 {
00891     PORT_TIMER_SET_HANDLER(triggered_update_delay, t_secs, 1, 10000,
00892                dummy_timer);
00893 }
00894 
00895 template <typename A>
00896 XrlCmdError
00897 XrlRipCommonTarget<A>::ripx_0_1_triggered_update_delay(
00898                         const string&   ifname,
00899                         const string&   vifname,
00900                         const A&    addr,
00901                         uint32_t&   t_secs)
00902 {
00903     PORT_TIMER_GET_HANDLER(triggered_update_delay, t_secs);
00904 }
00905 
00906 template <typename A>
00907 XrlCmdError
00908 XrlRipCommonTarget<A>::ripx_0_1_set_triggered_update_jitter(
00909                         const string&   ifname,
00910                         const string&   vifname,
00911                         const A&    addr,
00912                         const uint32_t& t_jitter)
00913 {
00914     PORT_TIMER_SET_HANDLER(triggered_update_jitter, t_jitter, 0, 100,
00915                dummy_timer);
00916 }
00917 
00918 template <typename A>
00919 XrlCmdError
00920 XrlRipCommonTarget<A>::ripx_0_1_triggered_update_jitter(
00921                         const string&   ifname,
00922                         const string&   vifname,
00923                         const A&    addr,
00924                         uint32_t&   t_jitter)
00925 {
00926     PORT_TIMER_GET_HANDLER(triggered_update_jitter, t_jitter);
00927 }
00928 
00929 template <typename A>
00930 XrlCmdError
00931 XrlRipCommonTarget<A>::ripx_0_1_set_interpacket_delay(
00932                         const string&   ifname,
00933                         const string&   vifname,
00934                         const A&    addr,
00935                         const uint32_t& t_msecs
00936                         )
00937 {
00938     PORT_TIMER_SET_HANDLER(interpacket_delay_ms, t_msecs, 10, 10000,
00939                dummy_timer);
00940 }
00941 
00942 template <typename A>
00943 XrlCmdError
00944 XrlRipCommonTarget<A>::ripx_0_1_interpacket_delay(
00945                         const string&   ifname,
00946                         const string&   vifname,
00947                         const A&    addr,
00948                         uint32_t&   t_msecs
00949                         )
00950 {
00951     PORT_TIMER_GET_HANDLER(interpacket_delay_ms, t_msecs);
00952 }
00953 
00954 template <typename A>
00955 XrlCmdError
00956 XrlRipCommonTarget<A>::ripx_0_1_rip_address_status(const string&    ifn,
00957                           const string&     vifn,
00958                           const A&      addr,
00959                           string&       status)
00960 {
00961     pair<Port<A>*, XrlCmdError> pp = find_port(ifn, vifn, addr);
00962     if (pp.first == 0)
00963     return pp.second;
00964 
00965     Port<A>* p = pp.first;
00966     status = p->enabled() ? "enabled" : "disabled";
00967 
00968     if (p->enabled()
00969     && _xpm.underlying_rip_address_up(ifn, vifn, addr) == false) {
00970     if (_xpm.underlying_rip_address_exists(ifn, vifn, addr)) {
00971         status += " [gated by disabled FEA interface/vif/address]";
00972     } else {
00973         status += " [gated by non-existant FEA interface/vif/address]";
00974     }
00975     }
00976 
00977     debug_msg("ripx_0_1_rip_address_status %s/%s/%s -> %s\n",
00978           ifn.c_str(), vifn.c_str(), addr.str().c_str(),
00979           status.c_str());
00980 
00981     return XrlCmdError::OKAY();
00982 }
00983 
00984 template <typename A>
00985 XrlCmdError
00986 XrlRipCommonTarget<A>::ripx_0_1_get_all_addresses(XrlAtomList&  ifnames,
00987                           XrlAtomList&  vifnames,
00988                           XrlAtomList&  addrs)
00989 {
00990     const typename PortManagerBase<A>::PortList & ports = _xpm.const_ports();
00991     typename PortManagerBase<A>::PortList::const_iterator pci;
00992 
00993     for (pci = ports.begin(); pci != ports.end(); ++pci) {
00994     const Port<A>*          port = *pci;
00995     const PortIOBase<A>*    pio  = port->io_handler();
00996     if (pio == 0) {
00997         continue;
00998     }
00999     ifnames.append  ( XrlAtom(pio->ifname())   );
01000     vifnames.append ( XrlAtom(pio->vifname())  );
01001     addrs.append    ( XrlAtom(pio->address())  );
01002     }
01003     return XrlCmdError::OKAY();
01004 }
01005 
01006 
01007 template <typename A>
01008 XrlCmdError
01009 XrlRipCommonTarget<A>::ripx_0_1_get_peers(const string& ifn,
01010                       const string& vifn,
01011                       const A&  addr,
01012                       XrlAtomList&  peers)
01013 {
01014     pair<Port<A>*, XrlCmdError> pp = find_port(ifn, vifn, addr);
01015     if (pp.first == 0)
01016     return pp.second;
01017 
01018     Port<A>* p = pp.first;
01019     typename Port<A>::PeerList::const_iterator pi = p->peers().begin();
01020     while (pi != p->peers().end()) {
01021     const Peer<A>* peer = *pi;
01022     peers.append(XrlAtom(peer->address()));
01023     ++pi;
01024     }
01025     return XrlCmdError::OKAY();
01026 }
01027 
01028 template <typename A>
01029 XrlCmdError
01030 XrlRipCommonTarget<A>::ripx_0_1_get_all_peers(XrlAtomList&  peers,
01031                           XrlAtomList&  ifnames,
01032                           XrlAtomList&  vifnames,
01033                           XrlAtomList&  addrs)
01034 {
01035     const typename PortManagerBase<A>::PortList & ports = _xpm.const_ports();
01036     typename PortManagerBase<A>::PortList::const_iterator pci;
01037 
01038     for (pci = ports.begin(); pci != ports.end(); ++pci) {
01039     const Port<A>* port = *pci;
01040     const PortIOBase<A>* pio = port->io_handler();
01041     if (pio == 0) {
01042         continue;
01043     }
01044 
01045     typename Port<A>::PeerList::const_iterator pi;
01046     for (pi = port->peers().begin(); pi != port->peers().end(); ++pi) {
01047         const Peer<A>* peer = *pi;
01048         peers.append    ( XrlAtom(peer->address()) );
01049         ifnames.append  ( XrlAtom(pio->ifname())   );
01050         vifnames.append ( XrlAtom(pio->vifname())  );
01051         addrs.append    ( XrlAtom(pio->address())  );
01052     }
01053     }
01054     return XrlCmdError::OKAY();
01055 }
01056 
01057 template <typename A>
01058 XrlCmdError
01059 XrlRipCommonTarget<A>::ripx_0_1_get_counters(const string&  ifn,
01060                          const string&  vifn,
01061                          const A&       addr,
01062                          XrlAtomList&   descriptions,
01063                          XrlAtomList&   values)
01064 {
01065     pair<Port<A>*, XrlCmdError> pp = find_port(ifn, vifn, addr);
01066     if (pp.first == 0)
01067     return pp.second;
01068 
01069     const Port<A>* p = pp.first;
01070     descriptions.append(XrlAtom("", string("Requests Sent")));
01071     values.append(XrlAtom(p->counters().table_requests_sent()));
01072 
01073     descriptions.append(XrlAtom("", string("Updates Sent")));
01074     values.append(XrlAtom(p->counters().unsolicited_updates()));
01075 
01076     descriptions.append(XrlAtom("", string("Triggered Updates Sent")));
01077     values.append(XrlAtom(p->counters().triggered_updates()));
01078 
01079     descriptions.append(XrlAtom("", string("Non-RIP Updates Sent")));
01080     values.append(XrlAtom(p->counters().non_rip_updates_sent()));
01081 
01082     descriptions.append(XrlAtom("", string("Total Packets Received")));
01083     values.append(XrlAtom(p->counters().packets_recv()));
01084 
01085     descriptions.append(XrlAtom("", string("Request Packets Received")));
01086     values.append(XrlAtom(p->counters().table_requests_recv()));
01087 
01088     descriptions.append(XrlAtom("", string("Update Packets Received")));
01089     values.append(XrlAtom(p->counters().update_packets_recv()));
01090 
01091     descriptions.append(XrlAtom("", string("Bad Packets Received")));
01092     values.append(XrlAtom(p->counters().bad_packets()));
01093 
01094     if (A::ip_version() == 4) {
01095     descriptions.append(XrlAtom("", string("Authentication Failures")));
01096     values.append(XrlAtom(p->counters().bad_auth_packets()));
01097     }
01098 
01099     descriptions.append(XrlAtom("", string("Bad Routes Received")));
01100     values.append(XrlAtom(p->counters().bad_routes()));
01101 
01102     descriptions.append(XrlAtom("", string("Non-RIP Requests Received")));
01103     values.append(XrlAtom(p->counters().non_rip_requests_recv()));
01104 
01105     return XrlCmdError::OKAY();
01106 }
01107 
01108 template <typename A>
01109 XrlCmdError
01110 XrlRipCommonTarget<A>::ripx_0_1_get_peer_counters(
01111                     const string&   ifn,
01112                     const string&   vifn,
01113                     const A&    addr,
01114                     const A&    peer_addr,
01115                     XrlAtomList&    descriptions,
01116                     XrlAtomList&    values,
01117                     uint32_t&   peer_last_active)
01118 {
01119     pair<Port<A>*, XrlCmdError> pp = find_port(ifn, vifn, addr);
01120     if (pp.first == 0)
01121     return pp.second;
01122 
01123     const Port<A>* port = pp.first;
01124 
01125     typename Port<A>::PeerList::const_iterator pi;
01126     pi = find_if(port->peers().begin(), port->peers().end(),
01127          peer_has_address<A>(peer_addr));
01128 
01129     if (pi == port->peers().end()) {
01130     return XrlCmdError::COMMAND_FAILED(
01131         c_format("Peer %s not found on %s/%s/%s",
01132              peer_addr.str().c_str(), ifn.c_str(), vifn.c_str(),
01133              addr.str().c_str())
01134         );
01135     }
01136 
01137     const Peer<A>* const peer = *pi;
01138 
01139     descriptions.append(  XrlAtom("", string("Total Packets Received")) );
01140     values.append( XrlAtom(peer->counters().packets_recv()) );
01141 
01142     descriptions.append(XrlAtom("", string("Request Packets Received")));
01143     values.append(XrlAtom(peer->counters().table_requests_recv()));
01144 
01145     descriptions.append(XrlAtom("", string("Update Packets Received")));
01146     values.append(XrlAtom(peer->counters().update_packets_recv()));
01147 
01148     descriptions.append(XrlAtom("", string("Bad Packets Received")));
01149     values.append(XrlAtom(peer->counters().bad_packets()));
01150 
01151     if (A::ip_version() == 4) {
01152     descriptions.append(XrlAtom("", string("Authentication Failures")));
01153     values.append(XrlAtom(peer->counters().bad_auth_packets()));
01154     }
01155 
01156     descriptions.append(XrlAtom("", string("Bad Routes Received")));
01157     values.append(XrlAtom(peer->counters().bad_routes()));
01158 
01159     descriptions.append(XrlAtom("", string("Routes Active")));
01160     values.append(XrlAtom(peer->route_count()));
01161 
01162     peer_last_active = peer->last_active().sec();
01163 
01164     return XrlCmdError::OKAY();
01165 }
01166 
01167 template <typename A>
01168 XrlCmdError
01169 XrlRipCommonTarget<A>::trace(bool enable)
01170 {
01171     _rip_system.route_trace().all(enable);
01172     _xpm.packet_trace().all(enable);
01173 
01174     return XrlCmdError::OKAY();
01175 }
01176 
01177 template <typename A>
01178 XrlCmdError
01179 XrlRipCommonTarget<A>::socketx_user_0_1_recv_event(
01180                     const string&       sockid,
01181                     const string&       if_name,
01182                     const string&       vif_name,
01183                     const A&        src_host,
01184                     const uint32_t&     src_port,
01185                     const vector<uint8_t>&  pdata
01186                     )
01187 {
01188     _xpm.deliver_packet(sockid, if_name, vif_name, src_host, src_port, pdata);
01189     return XrlCmdError::OKAY();
01190 }
01191 
01192 template <typename A>
01193 XrlCmdError
01194 XrlRipCommonTarget<A>::socketx_user_0_1_inbound_connect_event(
01195                     const string&   sockid,
01196                     const A&    src_host,
01197                     const uint32_t& src_port,
01198                     const string&   new_sockid,
01199                     bool&       accept
01200                     )
01201 {
01202     debug_msg("socketx_user_0_1_inbound_connect_event %s %s/%u %s\n",
01203           sockid.c_str(), src_host.str().c_str(),
01204           XORP_UINT_CAST(src_port), new_sockid.c_str());
01205 
01206     UNUSED(sockid);
01207     UNUSED(src_host);
01208     UNUSED(src_port);
01209     UNUSED(new_sockid);
01210 
01211     accept = false;
01212     return XrlCmdError::COMMAND_FAILED("Inbound connect not requested.");
01213 }
01214 
01215 template <typename A>
01216 XrlCmdError
01217 XrlRipCommonTarget<A>::socketx_user_0_1_outgoing_connect_event(
01218                     const string&   sockid
01219                     )
01220 {
01221     debug_msg("socketx_user_0_1_outgoing_connect_event %s\n",
01222           sockid.c_str());
01223 
01224     UNUSED(sockid);
01225     return XrlCmdError::COMMAND_FAILED("Outgoing connect not requested.");
01226 }
01227 
01228 template <typename A>
01229 XrlCmdError
01230 XrlRipCommonTarget<A>::socketx_user_0_1_error_event(
01231                     const string&   sockid,
01232                     const string&   reason,
01233                     const bool& fatal
01234                     )
01235 {
01236     debug_msg("socketx_user_0_1_error_event %s %s %s \n",
01237           sockid.c_str(), reason.c_str(),
01238           fatal ? "fatal" : "non-fatal");
01239 
01240     UNUSED(sockid);
01241     UNUSED(reason);
01242     UNUSED(fatal);
01243 
01244     return XrlCmdError::OKAY();
01245 }
01246 
01247 template <typename A>
01248 XrlCmdError
01249 XrlRipCommonTarget<A>::socketx_user_0_1_disconnect_event(
01250                     const string&   sockid
01251                     )
01252 {
01253     debug_msg("socketx_user_0_1_disconnect_event %s\n",
01254           sockid.c_str());
01255 
01256     UNUSED(sockid);
01257 
01258     return XrlCmdError::OKAY();
01259 }
01260 
01261 
01262 template <typename A>
01263 XrlCmdError
01264 XrlRipCommonTarget<A>::policy_backend_0_1_configure(const uint32_t& filter,
01265                             const string& conf)
01266 {
01267     try {
01268     _rip_system.configure_filter(filter, conf);
01269     } catch(const PolicyException& e) {
01270     return XrlCmdError::COMMAND_FAILED("Filter configure failed: " +
01271                        e.str());
01272     }
01273     return XrlCmdError::OKAY();
01274 }
01275 
01276 template <typename A>
01277 XrlCmdError
01278 XrlRipCommonTarget<A>::policy_backend_0_1_reset(const uint32_t& filter)
01279 {
01280     try {
01281     _rip_system.reset_filter(filter);
01282     } catch(const PolicyException& e) {
01283     return XrlCmdError::COMMAND_FAILED("Filter reset failed: " + 
01284                        e.str());
01285     }
01286     return XrlCmdError::OKAY();
01287 }
01288 
01289 template <typename A>
01290 XrlCmdError
01291 XrlRipCommonTarget<A>::policy_backend_0_1_push_routes()
01292 {
01293     _rip_system.push_routes();
01294     return XrlCmdError::OKAY();
01295 }
01296 
01297 template <typename A>
01298 XrlCmdError 
01299 XrlRipCommonTarget<A>::policy_redistx_0_1_add_routex(const IPNet<A>&    net,
01300                              const bool&    unicast,
01301                              const bool&    multicast,
01302                              const A&           nexthop,
01303                              const uint32_t&    metric,
01304                              const XrlAtomList& policytags)
01305 {
01306     string ifname, vifname;
01307 
01308     UNUSED(multicast);
01309 
01310     if (! unicast)
01311     return XrlCmdError::OKAY();
01312 
01313     //
01314     // XXX: The interface and vif name are empty, because the policy
01315     // mechanism doesn't support setting them (yet).
01316     //
01317     _xrm.add_route(net, nexthop, ifname, vifname, metric, 0, policytags);
01318     return XrlCmdError::OKAY();
01319 }
01320 
01321 template <typename A>
01322 XrlCmdError 
01323 XrlRipCommonTarget<A>::policy_redistx_0_1_delete_routex(const IPNet<A>& net,
01324                             const bool& unicast,
01325                             const bool& multicast)
01326 {
01327     UNUSED(multicast);
01328 
01329     if (! unicast)
01330     return XrlCmdError::OKAY();
01331 
01332     _xrm.delete_route(net);
01333     return XrlCmdError::OKAY();
01334 }
01335 #endif // __RIPX_XRL_TARGET_COMMON_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations