xorp

mfea_mrouter.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 
00021 #ifndef __FEA_MFEA_MROUTER_HH__
00022 #define __FEA_MFEA_MROUTER_HH__
00023 
00024 
00025 //
00026 // Multicast routing kernel-access specific definitions.
00027 //
00028 
00029 #ifdef HAVE_SYS_UIO_H
00030 #include <sys/uio.h>
00031 #endif
00032 
00033 #include "libxorp/eventloop.hh"
00034 #include "libproto/proto_unit.hh"
00035 
00036 
00037 //
00038 // Constants definitions
00039 //
00040 
00041 
00042 //
00043 // Structures/classes, typedefs and macros
00044 //
00045 
00046 class IPvX;
00047 class MfeaNode;
00048 class SgCount;
00049 class TimeVal;
00050 class VifCount;
00051 class FibConfig;
00052 
00053 
00060 class MfeaMrouter : public ProtoUnit {
00061 public:
00067     MfeaMrouter(MfeaNode& mfea_node, const FibConfig& fibconfig);
00068     
00072     virtual ~MfeaMrouter();
00073 
00079     int     start();
00080     
00086     int     stop();
00087 
00088 #ifdef USE_MULT_MCAST_TABLES
00089 
00093     int getTableId() const;
00094 #endif
00095 
00102     bool have_multicast_routing4() const;
00103     
00110     bool have_multicast_routing6() const;
00111 
00121     int multicast_forwarding_enabled4(bool& ret_value,
00122                       string& error_msg) const;
00123 
00133     int multicast_forwarding_enabled6(bool& ret_value,
00134                       string& error_msg) const;
00135 
00145     int set_multicast_forwarding_enabled4(bool v, string& error_msg);
00146 
00156     int set_multicast_forwarding_enabled6(bool v, string& error_msg);
00157     
00163     int     kernel_mrouter_ip_protocol() const;
00164     
00172     XorpFd  mrouter_socket() const { return (_mrouter_socket); }
00173     
00179     int     start_mrt();
00180     
00186     int     stop_mrt();
00187     
00194     int     start_pim(string& error_msg);
00195     
00202     int     stop_pim(string& error_msg);
00203     
00210     int add_multicast_vif(uint32_t vif_index);
00211     
00218     int delete_multicast_vif(uint32_t vif_index);
00219     
00237     int     add_mfc(const IPvX& source, const IPvX& group,
00238             uint32_t iif_vif_index, uint8_t *oifs_ttl,
00239             uint8_t *oifs_flags,
00240             const IPvX& rp_addr);
00241     
00249     int     delete_mfc(const IPvX& source, const IPvX& group);
00250     
00273     int     add_bw_upcall(const IPvX& source, const IPvX& group,
00274                   const TimeVal& threshold_interval,
00275                   uint32_t threshold_packets,
00276                   uint32_t threshold_bytes,
00277                   bool is_threshold_in_packets,
00278                   bool is_threshold_in_bytes,
00279                   bool is_geq_upcall,
00280                   bool is_leq_upcall,
00281                   string& error_msg);
00282     
00305     int     delete_bw_upcall(const IPvX& source, const IPvX& group,
00306                  const TimeVal& threshold_interval,
00307                  uint32_t threshold_packets,
00308                  uint32_t threshold_bytes,
00309                  bool is_threshold_in_packets,
00310                  bool is_threshold_in_bytes,
00311                  bool is_geq_upcall,
00312                  bool is_leq_upcall,
00313                  string& error_msg);
00314     
00324     int     delete_all_bw_upcall(const IPvX& source, const IPvX& group,
00325                      string& error_msg);
00326     
00339     int     get_sg_count(const IPvX& source, const IPvX& group,
00340                  SgCount& sg_count);
00341     
00354     int     get_vif_count(uint32_t vif_index, VifCount& vif_count);
00355     
00363     bool    mrt_api_mrt_mfc_flags_disable_wrongvif() const {
00364     return (_mrt_api_mrt_mfc_flags_disable_wrongvif);
00365     }
00366     
00377     bool    mrt_api_mrt_mfc_flags_border_vif() const {
00378     return (_mrt_api_mrt_mfc_flags_border_vif);
00379     }
00380     
00391     bool    mrt_api_mrt_mfc_rp() const {
00392     return (_mrt_api_mrt_mfc_rp);
00393     }
00394     
00401     bool    mrt_api_mrt_mfc_bw_upcall() const {
00402     return (_mrt_api_mrt_mfc_bw_upcall);
00403     }
00404     
00414     int     kernel_call_process(const uint8_t *databuf, size_t datalen);
00415     
00416 private:
00417     // Private functions
00418     MfeaNode&   mfea_node() const   { return (_mfea_node);  }
00419     
00420     // Private state
00421     MfeaNode&     _mfea_node;   // The MFEA node I belong to
00422     XorpFd    _mrouter_socket; // The socket for multicast routing access
00423 
00424     //
00425     // Flags about various support by the advanced kernel multicast API:
00426     //  - support for disabling WRONGVIF signals per vif
00427     //  - support for the border bit flag (per MFC per vif)
00428     //  - support for kernel-level PIM Register encapsulation
00429     //  - support for bandwidth-related upcalls from the kernel
00430     //
00431     bool    _mrt_api_mrt_mfc_flags_disable_wrongvif;
00432     bool    _mrt_api_mrt_mfc_flags_border_vif;
00433     bool    _mrt_api_mrt_mfc_rp;
00434     bool    _mrt_api_mrt_mfc_bw_upcall;
00435 
00436     //
00437     // Original state from the underlying system before the MFEA was started
00438     //
00439     bool    _multicast_forwarding_enabled;
00440     const FibConfig& _fibconfig;
00441 };
00442 
00448 class SgCount {
00449 public:
00453     SgCount() : _pktcnt(0), _bytecnt(0), _wrong_if(0) {}
00454     
00461     SgCount& operator=(const SgCount& sg_count) {
00462     _pktcnt = sg_count.pktcnt();
00463     _bytecnt = sg_count.bytecnt();
00464     _wrong_if = sg_count.wrong_if();
00465     return (*this);
00466     }
00467     
00474     SgCount& operator+=(const SgCount& sg_count) {
00475     _pktcnt += sg_count.pktcnt();
00476     _bytecnt += sg_count.bytecnt();
00477     _wrong_if += sg_count.wrong_if();
00478     return (*this);
00479     }
00480     
00488     SgCount& operator-=(const SgCount& sg_count) {
00489     _pktcnt -= sg_count.pktcnt();
00490     _bytecnt -= sg_count.bytecnt();
00491     _wrong_if -= sg_count.wrong_if();
00492     return (*this);
00493     }
00494     
00500     size_t  pktcnt()    const   { return (_pktcnt); }
00501     
00507     size_t  bytecnt()   const   { return (_bytecnt);    }
00508     
00514     size_t  wrong_if()  const   { return (_wrong_if);   }
00515     
00521     void    set_pktcnt(size_t v)    { _pktcnt = v;      }
00522     
00528     void    set_bytecnt(size_t v)   { _bytecnt = v;     }
00529     
00535     void    set_wrong_if(size_t v)  { _wrong_if = v;    }
00536     
00540     void    reset() { _pktcnt = 0; _bytecnt = 0; _wrong_if = 0; }
00541     
00547     bool    is_valid() const { return (! ((_pktcnt == (size_t)~0)
00548                           && (_bytecnt == (size_t)~0)
00549                           && (_wrong_if == (size_t)~0))); }
00550     
00551 private:
00552     size_t  _pktcnt;    // Number of multicast data packets received
00553     size_t  _bytecnt;   // Number of multicast data bytes received
00554     size_t  _wrong_if;  // Number of multicast data packets received
00555                 // on wrong iif
00556 };
00557 
00558 //
00559 // A class that contains information about a vif in the kernel.
00560 //
00561 
00568 class VifCount {
00569 public:
00573     VifCount() : _icount(0), _ocount(0), _ibytes(0), _obytes(0) {}
00574     
00581     VifCount& operator=(const VifCount& vif_count) {
00582     _icount = vif_count.icount();
00583     _ocount = vif_count.ocount();
00584     _ibytes = vif_count.ibytes();
00585     _obytes = vif_count.obytes();
00586     return (*this);
00587     }
00588     
00594     size_t  icount()    const   { return (_icount); }
00595     
00601     size_t  ocount()    const   { return (_ocount); }
00602     
00608     size_t  ibytes()    const   { return (_ibytes); }
00609     
00615     size_t  obytes()    const   { return (_obytes); }
00616     
00622     void    set_icount(size_t v)    { _icount = v;      }
00623 
00629     void    set_ocount(size_t v)    { _ocount = v;      }
00630 
00636     void    set_ibytes(size_t v)    { _ibytes = v;      }
00637     
00643     void    set_obytes(size_t v)    { _obytes = v;      }
00644     
00650     bool    is_valid() const { return (! ((_icount == (size_t)~0)
00651                           && (_ocount == (size_t)~0)
00652                           && (_ibytes == (size_t)~0)
00653                           && (_obytes == (size_t)~0))); }
00654     
00655 private:
00656     size_t  _icount;    // Number of input multicast data packets
00657     size_t  _ocount;    // Number of output multicast data packets
00658     size_t  _ibytes;    // Number of input multicast data bytes
00659     size_t  _obytes;    // Number of output multicast data bytes
00660 };
00661 
00662 //
00663 // Global variables
00664 //
00665 
00666 
00667 //
00668 // Global functions prototypes
00669 //
00670 
00671 #endif // __FEA_MFEA_MROUTER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations