xorp

vrrp_target.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2008-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 // $XORP: xorp/vrrp/vrrp_target.hh,v 1.11 2008/12/18 11:34:51 abittau Exp $
00022 
00023 #ifndef __VRRP_VRRP_TARGET_HH__
00024 #define __VRRP_VRRP_TARGET_HH__
00025 
00026 #include "libxipc/xrl_router.hh"
00027 #include "libfeaclient/ifmgr_xrl_mirror.hh"
00028 #include "xrl/targets/vrrp_base.hh"
00029 #include "xrl/interfaces/fea_rawlink_xif.hh"
00030 #include "xrl/interfaces/fea_rawpkt4_xif.hh"
00031 #include "xrl/interfaces/fea_ifmgr_xif.hh"
00032 #include "vrrp.hh"
00033 #include "vrrp_vif.hh"
00034 
00041 class VrrpTarget : public XrlVrrpTargetBase, public IfMgrHintObserver {
00042 public:
00043     static const string vrrp_target_name;
00044     static const string fea_target_name;
00045 
00049     VrrpTarget(XrlRouter& rtr);
00050     ~VrrpTarget();
00051 
00057     bool       running() const;
00058 
00062     void       tree_complete();
00063 
00067     void       updates_made();
00068 
00079     void       send(const string& ifname, const string& vifname,
00080             const Mac& src, const Mac& dst, uint32_t ether,
00081                 const PAYLOAD& payload);
00082 
00089     void       join_mcast(const string& ifname, const string& vifname);
00090 
00097     void       leave_mcast(const string& ifname, const string& vifname);
00098 
00105     void       start_arps(const string& ifname, const string& vifname);
00106 
00113     void       stop_arps(const string& ifname, const string& vifname);
00114 
00121     void add_mac(const string& ifname, const Mac& mac);
00122 
00129     void delete_mac(const string& ifname, const Mac& mac);
00130 
00131     void add_ip(const string& ifname, const IPv4& ip, uint32_t prefix);
00132     void delete_ip(const string& ifname, const IPv4& ip);
00133 
00134 
00138     EventLoop& eventloop();
00139 
00140 protected:
00141     XrlCmdError common_0_1_get_target_name(
00142         // Output values,
00143         string& name);
00144 
00145     XrlCmdError common_0_1_get_version(
00146         // Output values,
00147         string& version);
00148 
00149     XrlCmdError common_0_1_get_status(
00150         // Output values,
00151         uint32_t&       status,
00152         string& reason);
00153 
00154     XrlCmdError common_0_1_shutdown();
00155     XrlCmdError common_0_1_startup();
00156 
00157     XrlCmdError vrrp_0_1_add_vrid(
00158         // Input values,
00159         const string&   ifname,
00160         const string&   vifname,
00161         const uint32_t& vrid);
00162 
00163     XrlCmdError vrrp_0_1_delete_vrid(
00164         // Input values,
00165         const string&   ifname,
00166         const string&   vifname,
00167         const uint32_t& vrid);
00168 
00169     XrlCmdError vrrp_0_1_set_priority(
00170         // Input values,
00171         const string&   ifname,
00172         const string&   vifname,
00173     const uint32_t& vrid,
00174         const uint32_t& priority);
00175 
00176     XrlCmdError vrrp_0_1_set_interval(
00177         // Input values,
00178         const string&   ifname,
00179         const string&   vifname,
00180     const uint32_t& vrid,
00181         const uint32_t& interval);
00182 
00183     XrlCmdError vrrp_0_1_set_preempt(
00184         // Input values,
00185         const string&   ifname,
00186         const string&   vifname,
00187     const uint32_t& vrid,
00188         const bool&     preempt);
00189 
00190     XrlCmdError vrrp_0_1_set_disable(
00191         // Input values,
00192         const string&   ifname,
00193         const string&   vifname,
00194     const uint32_t& vrid,
00195         const bool&     disable);
00196 
00197     XrlCmdError vrrp_0_1_add_ip(
00198         // Input values,
00199         const string&   ifname,
00200         const string&   vifname,
00201         const uint32_t& vrid,
00202         const IPv4&     ip);
00203 
00204     XrlCmdError vrrp_0_1_set_prefix (
00205         // Input values,
00206         const string&   ifname,
00207         const string&   vifname,
00208         const uint32_t& vrid,
00209         const IPv4&     ip,
00210     const uint32_t& prefix_len);
00211 
00212     XrlCmdError vrrp_0_1_delete_ip(
00213         // Input values,
00214         const string&   ifname,
00215         const string&   vifname,
00216         const uint32_t& vrid,
00217         const IPv4&     ip);
00218 
00219     XrlCmdError vrrp_0_1_get_vrid_info(
00220         // Input values,
00221         const string&   ifname,
00222         const string&   vifname,
00223         const uint32_t& vrid,
00224         // Output values,
00225         string& state,
00226         IPv4&   master);
00227 
00228     XrlCmdError vrrp_0_1_get_vrids(
00229         // Input values,
00230         const string&   ifname,
00231         const string&   vifname,
00232         // Output values,
00233         XrlAtomList&    vrids);
00234 
00235     XrlCmdError vrrp_0_1_get_ifs(
00236         // Output values,
00237         XrlAtomList&    ifs);
00238 
00239     XrlCmdError vrrp_0_1_get_vifs(
00240         // Input values,
00241         const string&   ifname,
00242         // Output values,
00243         XrlAtomList&    vifs);
00244 
00245     XrlCmdError raw_packet4_client_0_1_recv(
00246         // Input values,
00247         const string&   if_name,
00248         const string&   vif_name,
00249         const IPv4&     src_address,
00250         const IPv4&     dst_address,
00251         const uint32_t& ip_protocol,
00252         const int32_t&  ip_ttl,
00253         const int32_t&  ip_tos,
00254         const bool&     ip_router_alert,
00255         const bool&     ip_internet_control,
00256         const vector<uint8_t>&  payload);
00257 
00258     XrlCmdError raw_link_client_0_1_recv(
00259         // Input values,
00260         const string&   if_name,
00261         const string&   vif_name,
00262         const Mac&      src_address,
00263         const Mac&      dst_address,
00264         const uint32_t& ether_type,
00265         const vector<uint8_t>&  payload);
00266 
00267 private:
00268     typedef map<string, VrrpVif*>   VIFS; // vifname -> VrrpVif
00269     typedef map<string, VIFS*>      IFS;  // ifname -> VIFS
00270 
00274     void    shutdown();
00275 
00279     void    start();
00280 
00284     void    check_interfaces();
00285 
00291     void    check_vif(VrrpVif& vif);
00292     
00300     void    add_vrid(const string& ifn, const string& vifn, uint32_t id);
00301 
00309     void    delete_vrid(const string& ifn, const string& vifn, uint32_t id);
00310 
00320     Vrrp&   find_vrid(const string& ifn, const string& vifn, uint32_t id);
00321 
00330     Vrrp*   find_vrid_ptr(const string& ifn, const string& vifn,
00331                   uint32_t id);
00332 
00343     VrrpVif*    find_vif(const string& ifn, const string& vifn,
00344              bool add = false);
00345 
00351     void    xrl_cb(const XrlError& xrl_error);
00352 
00353     XrlRouter&          _rtr;
00354     bool            _running;
00355     IFS             _ifs;
00356     IfMgrXrlMirror      _ifmgr;
00357     bool            _ifmgr_setup;
00358     XrlRawLinkV0p1Client    _rawlink;
00359     XrlRawPacket4V0p1Client _rawipv4;
00360     XrlIfmgrV0p1Client      _fea;
00361     int             _xrls_pending;
00362 };
00363 
00364 #endif // __VRRP_VRRP_TARGET_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations