xorp

vrrp.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.hh,v 1.10 2008/12/18 11:34:51 abittau Exp $
00022 
00023 #ifndef __VRRP_VRRP_HH__
00024 #define __VRRP_VRRP_HH__
00025 
00026 
00027 
00028 
00029 #include "libxorp/ipv4.hh"
00030 #include "libxorp/timer.hh"
00031 #include "libxorp/mac.hh"
00032 #include "libxorp/eventloop.hh"
00033 #include "vrrp_packet.hh"
00034 #include "vrrp_vif.hh"
00035 
00036 //#include "arpd.hh"
00037 
00038 #define MAX_VRRP_SIZE (20 + VRRP_MAX_PACKET_SIZE)
00039 
00046 class Vrrp {
00047 public:
00048     static const Mac mcast_mac;
00049 
00055     Vrrp(VrrpVif& vif, EventLoop& e, uint32_t vrid);
00056     ~Vrrp();
00057 
00063     void        set_priority(uint32_t priority);
00064 
00070     void        set_interval(uint32_t interval);
00071 
00078     void        set_preempt(bool preempt);
00079 
00085     void        set_disable(bool disable);
00086 
00092     void        add_ip(const IPv4& ip);
00093 
00094     void set_prefix(const IPv4& ip, uint32_t prefix);
00095 
00101     void        delete_ip(const IPv4& ip);
00102 
00108     bool        running() const;
00109 
00115     uint32_t        priority() const;
00116 
00120     void        start();
00121 
00125     void        stop();
00126 
00131     //void      check_ownership();
00132 
00139     void        recv(const IPv4& from, const VrrpHeader& vh);
00140 
00146     //ARPd&     arpd();
00147 
00154     void        get_info(string& state, IPv4& master) const;
00155 
00156 private:
00157     enum State {
00158     INITIALIZE = 0,
00159     MASTER,
00160     BACKUP
00161     };
00162 
00163     enum {
00164     PRIORITY_LEAVE  = 0,
00165     PRIORITY_OWN    = 255
00166     };
00167 
00168     typedef set<IPv4>   IPS;
00169 
00175     void setup_intervals();
00176 
00182     void setup_timers(bool skew = false);
00183 
00187     void cancel_timers();
00188 
00192     void send_arps();
00193 
00199     void send_arp(const IPv4& ip);
00200 
00206     void send_advertisement(uint32_t priority);
00207 
00213     void send_advertisement();
00214 
00218     void become_master();
00219 
00223     void become_backup();
00224 
00231     bool master_down_expiry();
00232 
00238     bool adver_expiry();
00239 
00246     void recv_adver_master(const IPv4& from, uint32_t priority);
00247 
00253     void recv_adver_backup(uint32_t priority);
00254 
00260     void prepare_advertisement(uint32_t priority);
00261 
00268     void recv_advertisement(const IPv4& from, uint32_t priority);
00269 
00276     bool check_ips(const VrrpHeader& vh);
00277 
00278     IPv4        _last_adv;
00279     VrrpVif&  _vif;
00280     uint32_t        _vrid;
00281     uint32_t        _priority;
00282     uint32_t        _interval;
00283     double      _skew_time;
00284     double      _master_down_interval;
00285     bool        _preempt;
00286     set<IPv4>       _ips;
00287     map<uint32_t, uint32_t> _prefixes; // map IP addr to prefix value.
00288     State       _state;
00289     XorpTimer       _master_down_timer;
00290     XorpTimer       _adver_timer;
00291     //bool      _own;
00292     bool        _disable;
00293     VrrpPacket      _adv_packet;
00294     Mac         _source_mac;
00295     //ARPd      _arpd; // XXX use OS proxy arp mechanism?
00296 };
00297 
00298 #endif // __VRRP_VRRP_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations