xorp

pim_rp.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
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/pim/pim_rp.hh,v 1.14 2008/10/02 21:57:55 bms Exp $
00021 
00022 
00023 #ifndef __PIM_PIM_RP_HH__
00024 #define __PIM_PIM_RP_HH__
00025 
00026 
00027 //
00028 // PIM RP information definitions
00029 //
00030 
00031 
00032 
00033 
00034 #include "libxorp/ipvx.hh"
00035 #include "libxorp/ipvxnet.hh"
00036 #include "libxorp/timer.hh"
00037 #include "libproto/proto_unit.hh"
00038 
00039 
00040 //
00041 // Constants definitions
00042 //
00043 
00044 
00045 //
00046 // Structures/classes, typedefs and macros
00047 //
00048 
00049 class PimNode;
00050 class PimRp;
00051 class RpTable;
00052 class PimMre;
00053 
00054 // The PIM RP class
00055 class PimRp {
00056 public:
00057     enum rp_learned_method_t {
00058     RP_LEARNED_METHOD_AUTORP,
00059     RP_LEARNED_METHOD_BOOTSTRAP,
00060     RP_LEARNED_METHOD_STATIC,
00061     RP_LEARNED_METHOD_UNKNOWN
00062     };
00063     
00064     PimRp(RpTable& rp_table, const IPvX& rp_addr, uint8_t rp_priority,
00065       const IPvXNet& group_prefix, uint8_t hash_mask_len,
00066       rp_learned_method_t rp_learned_method);
00067     PimRp(RpTable& rp_table, const PimRp& pim_rp);
00068     ~PimRp();
00069     
00070     RpTable&    rp_table()      { return (_rp_table);       }
00071     
00072     const IPvX& rp_addr()   const   { return (_rp_addr);        }
00073     uint8_t rp_priority()   const   { return (_rp_priority);    }
00074     void    set_rp_priority(uint8_t v) { _rp_priority = v;      }
00075     const IPvXNet& group_prefix() const { return (_group_prefix);   }
00076     uint8_t hash_mask_len() const   { return (_hash_mask_len);  }
00077     void    set_hash_mask_len(uint8_t v) { _hash_mask_len = v;  }
00078     rp_learned_method_t rp_learned_method() const { return (_rp_learned_method); }
00079     static const string rp_learned_method_str(rp_learned_method_t rp_learned_method);
00080     const string rp_learned_method_str() const;
00081     bool    is_updated()    const   { return (_is_updated);     }
00082     void    set_is_updated(bool v)  { _is_updated = v;      }
00083     
00084     list<PimMre *>& pim_mre_wc_list()   { return (_pim_mre_wc_list);    }
00085     list<PimMre *>& pim_mre_sg_list()   { return (_pim_mre_sg_list);    }
00086     list<PimMre *>& pim_mre_sg_rpt_list() { return (_pim_mre_sg_rpt_list); }
00087     list<PimMfc *>& pim_mfc_list()  { return (_pim_mfc_list);   }
00088     list<PimMre *>& processing_pim_mre_wc_list() {
00089     return (_processing_pim_mre_wc_list);
00090     }
00091     list<PimMre *>& processing_pim_mre_sg_list() {
00092     return (_processing_pim_mre_sg_list);
00093     }
00094     list<PimMre *>& processing_pim_mre_sg_rpt_list() {
00095     return (_processing_pim_mre_sg_rpt_list);
00096     }
00097     list<PimMfc *>& processing_pim_mfc_list() {
00098     return (_processing_pim_mfc_list);
00099     }
00100     void    init_processing_pim_mre_wc();
00101     void    init_processing_pim_mre_sg();
00102     void    init_processing_pim_mre_sg_rpt();
00103     void    init_processing_pim_mfc();
00104     
00105     bool    i_am_rp() const { return (_i_am_rp); }
00106     
00107     
00108 private:
00109     RpTable&    _rp_table;      // The RP table I belong to
00110     IPvX    _rp_addr;       // The RP address
00111     uint8_t _rp_priority;       // The RP priority
00112     IPvXNet _group_prefix;      // The group address prefix
00113     uint8_t _hash_mask_len;     // The RP hash mask length
00114     rp_learned_method_t _rp_learned_method; // How learned about this RP
00115     bool    _is_updated;        // True if just created or updated
00116     list<PimMre *> _pim_mre_wc_list;    // List of all related (*,G) entries
00117                     // for this RP.
00118     list<PimMre *> _pim_mre_sg_list;    // List of all related (S,G) entries
00119                     // for this RP that have no (*,G) entry
00120     list<PimMre *> _pim_mre_sg_rpt_list;// List of all related (S,G,rpt)
00121                     // entries for this RP that have no
00122                     // (*,G) entry
00123     list<PimMfc *> _pim_mfc_list;   // List of all related MFC entries
00124                     // for this RP.
00125                     // NOTE: those MFC entries _may_ have
00126                     // existing (*,G) entry.
00127     list<PimMre *> _processing_pim_mre_wc_list; // List of all related
00128                     // (*,G) entries for this RP that are
00129                     // awaiting to be processed.
00130     list<PimMre *> _processing_pim_mre_sg_list; // List of all related
00131                     // (S,G) entries for this RP that
00132                     // have no (*,G) entry and that are
00133                     // awaiting to be processed.
00134     list<PimMre *> _processing_pim_mre_sg_rpt_list; // List of all related
00135                     // (S,G,rpt) entries for this RP that
00136                     // have no (*,G) entry and that are
00137                     // awaiting to be processed.
00138     list<PimMfc *> _processing_pim_mfc_list; // List of all related
00139                     // MFC entries for this RP that are
00140                     // awaiting to be processed.
00141                     // NOTE: those MFC entries _may_ have
00142                     // existing (*,G) entry.
00143     
00144     bool    _i_am_rp;       // True if this RP is me
00145 };
00146 
00147 // The RP table class
00148 class RpTable : public ProtoUnit {
00149 public:
00150     RpTable(PimNode& pim_node);
00151     ~RpTable();
00152 
00153     void    clear();    
00154     int     start();
00155     int     stop();
00156     PimNode&    pim_node()  { return (_pim_node);           }
00157     PimRp   *rp_find(const IPvX& group_addr);
00158     PimRp   *add_rp(const IPvX& rp_addr,
00159             uint8_t rp_priority,
00160             const IPvXNet& group_prefix,
00161             uint8_t hash_mask_len,
00162             PimRp::rp_learned_method_t rp_learned_method);
00163     int     delete_rp(const IPvX& rp_addr,
00164               const IPvXNet& group_prefix,
00165               PimRp::rp_learned_method_t rp_learned_method);
00166     int     delete_all_group_prefixes_rp(const IPvX& rp_addr,
00167                          PimRp::rp_learned_method_t rp_learned_method);
00168     int     delete_all_rps(PimRp::rp_learned_method_t rp_learned_method);
00169     bool    apply_rp_changes();
00170     
00171     void    add_pim_mre(PimMre *pim_mre);
00172     void    add_pim_mfc(PimMfc *pim_mfc);
00173     void    delete_pim_mre(PimMre *pim_mre);
00174     void    delete_pim_mfc(PimMfc *pim_mfc);
00175     
00176     list<PimRp *>& rp_list() { return (_rp_list); }
00177     list<PimRp *>& processing_rp_list() { return (_processing_rp_list); }
00178     
00179     void    init_processing_pim_mre_wc(const IPvX& rp_addr);
00180     void    init_processing_pim_mre_sg(const IPvX& rp_addr);
00181     void    init_processing_pim_mre_sg_rpt(const IPvX& rp_addr);
00182     void    init_processing_pim_mfc(const IPvX& rp_addr);
00183     PimRp   *find_processing_pim_mre_wc(const IPvX& rp_addr);
00184     PimRp   *find_processing_pim_mre_sg(const IPvX& rp_addr);
00185     PimRp   *find_processing_pim_mre_sg_rpt(const IPvX& rp_addr);
00186     PimRp   *find_processing_pim_mfc(const IPvX& rp_addr);
00187     PimRp   *find_processing_rp_by_addr(const IPvX& rp_addr);
00188     bool    has_rp_addr(const IPvX& rp_addr);
00189     
00190 private:
00191     PimRp   *compare_rp(const IPvX& group_addr, PimRp *rp1,
00192                 PimRp *rp2) const;
00193     uint32_t    derived_addr(const IPvX& addr) const;
00194     
00195     PimNode&    _pim_node;      // The associated PIM node
00196     
00197     list<PimRp *> _rp_list;     // The list of RPs
00198     list<PimRp *> _processing_rp_list;  // The list of obsolete RPs to process:
00199     // XXX: the PimRp entry with address of IPvX::ZERO(family()) contains
00200     // the list of PimMre and PimMfc entries that have no RP.
00201 };
00202 
00203 //
00204 // Global variables
00205 //
00206 
00207 
00208 //
00209 // Global functions prototypes
00210 //
00211 
00212 #endif // __PIM_PIM_RP_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations