xorp

mfea_dataflow.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/fea/mfea_dataflow.hh,v 1.10 2008/10/02 21:56:49 bms Exp $
00021 
00022 
00023 #ifndef __FEA_MFEA_DATAFLOW_HH__
00024 #define __FEA_MFEA_DATAFLOW_HH__
00025 
00026 
00027 //
00028 // MFEA (Multicast Forwarding Engine Abstraction) dataflow definition.
00029 //
00030 
00031 
00032 
00033 
00034 #include "libxorp/timer.hh"
00035 #include "libproto/proto_unit.hh"
00036 #include "mrt/mrt.hh"
00037 #include "mfea_mrouter.hh"
00038 
00039 
00040 //
00041 // Constants definitions
00042 //
00043 
00044 
00045 //
00046 // Structures/classes, typedefs and macros
00047 //
00048 
00049 class MfeaDfe;
00050 class MfeaDfeLookup;
00051 class MfeaNode;
00052 
00056 class MfeaDft : public Mrt<MfeaDfeLookup> {
00057 public:
00063     MfeaDft(MfeaNode& mfea_node);
00064     
00068     virtual ~MfeaDft();
00069     
00076     MfeaNode&   mfea_node() const { return (_mfea_node); }
00077     
00084     int     family() const;
00085     
00108     int     add_entry(const IPvX& source, const IPvX& group,
00109               const TimeVal& threshold_interval,
00110               uint32_t threshold_packets,
00111               uint32_t threshold_bytes,
00112               bool is_threshold_in_packets,
00113               bool is_threshold_in_bytes,
00114               bool is_geq_upcall,
00115               bool is_leq_upcall,
00116               string& error_msg);
00117     
00140     int     delete_entry(const IPvX& source, const IPvX& group,
00141                  const TimeVal& threshold_interval,
00142                  uint32_t threshold_packets,
00143                  uint32_t threshold_bytes,
00144                  bool is_threshold_in_packets,
00145                  bool is_threshold_in_bytes,
00146                  bool is_geq_upcall,
00147                  bool is_leq_upcall,
00148                  string& error_msg);
00149     
00157     int     delete_entry(const IPvX& source, const IPvX& group);
00158     
00159 private:
00166     int     delete_entry(MfeaDfe *mfea_dfe);
00167     
00168     MfeaNode&   _mfea_node; // The Mfea node
00169 };
00170 
00174 class MfeaDfeLookup : public Mre<MfeaDfeLookup> {
00175 public:
00184     MfeaDfeLookup(MfeaDft& mfea_dft, const IPvX& source, const IPvX& group);
00185     
00189     ~MfeaDfeLookup();
00190     
00197     MfeaDft& mfea_dft() const { return (_mfea_dft); }
00198     
00205     int     family() const;
00206     
00227     MfeaDfe *find(const TimeVal& threshold_interval,
00228               uint32_t threshold_packets,
00229               uint32_t threshold_bytes,
00230               bool is_threshold_in_packets,
00231               bool is_threshold_in_bytes,
00232               bool is_geq_upcall,
00233               bool is_leq_upcall);
00234     
00240     void    insert(MfeaDfe *mfea_dfe);
00241 
00247     void    remove(MfeaDfe *mfea_dfe);
00248     
00255     bool    is_empty() const { return (_mfea_dfe_list.empty()); }
00256     
00262     list<MfeaDfe *>&    mfea_dfe_list() { return (_mfea_dfe_list); }
00263     
00264 private:
00265     MfeaDft&        _mfea_dft;  // The Mfea dataflow table (yuck!)
00266     list<MfeaDfe *> _mfea_dfe_list; // The list of dataflow monitor entries
00267 };
00268 
00276 class MfeaDfe {
00277 public:
00298     MfeaDfe(MfeaDfeLookup& mfea_dfe_lookup,
00299         const TimeVal& threshold_interval,
00300         uint32_t threshold_packets,
00301         uint32_t threshold_bytes,
00302         bool is_threshold_in_packets,
00303         bool is_threshold_in_bytes,
00304         bool is_geq_upcall,
00305         bool is_leq_upcall);
00306     
00310     ~MfeaDfe();
00311     
00318     MfeaDfeLookup& mfea_dfe_lookup() const { return (_mfea_dfe_lookup); }
00319     
00327     MfeaDft& mfea_dft() const;
00328     
00334     EventLoop& eventloop() const;
00335     
00342     int     family() const;
00343     
00349     const IPvX& source_addr() const { return (_mfea_dfe_lookup.source_addr());}
00350     
00356     const IPvX& group_addr() const { return (_mfea_dfe_lookup.group_addr()); }
00357     
00371     bool is_valid() const;
00372     
00391     bool is_same(const TimeVal& threshold_interval_test,
00392          uint32_t threshold_packets_test,
00393          uint32_t threshold_bytes_test,
00394          bool is_threshold_in_packets_test,
00395          bool is_threshold_in_bytes_test,
00396          bool is_geq_upcall_test,
00397          bool is_leq_upcall_test) const;
00398     
00405     void init_sg_count();
00406     
00420     bool test_sg_count();
00421     
00425     void start_measurement();
00426     
00430     void dataflow_signal_send();
00431     
00437     const TimeVal& threshold_interval() const { return (_threshold_interval); }
00438     
00444     uint32_t threshold_packets() const { return (_threshold_packets); }
00445     
00451     uint32_t threshold_bytes() const { return (_threshold_bytes); }
00452     
00458     bool is_threshold_in_packets() const { return (_is_threshold_in_packets); }
00459     
00465     bool is_threshold_in_bytes() const { return (_is_threshold_in_bytes); }
00466     
00472     bool is_geq_upcall() const { return (_is_geq_upcall); }
00473     
00479     bool is_leq_upcall() const { return (_is_leq_upcall); }
00480 
00486     const TimeVal& start_time() const;
00487     
00494     uint32_t measured_packets() const;
00495     
00502     uint32_t measured_bytes() const;
00503     
00504     
00505 private:
00506     // Private methods
00507     void measurement_timer_timeout();
00508     
00509     // Private state
00510     MfeaDfeLookup& _mfea_dfe_lookup;  // The Mfea dataflow lookup entry (yuck!)
00511     TimeVal _threshold_interval;    // The threshold interval
00512     uint32_t    _threshold_packets; // The threshold value (in packets)
00513     uint32_t    _threshold_bytes;   // The threshold value (in bytes)
00514     bool    _is_threshold_in_packets; // If true, _threshold_packets is
00515                       // valid
00516     bool    _is_threshold_in_bytes; // If true, _threshold_bytes is valid
00517     bool    _is_geq_upcall;     // If true, the operation is ">=".
00518     bool    _is_leq_upcall;     // If true, the operation is "<=".
00519     
00520 #define MFEA_DATAFLOW_TEST_FREQUENCY    4
00521     SgCount _last_sg_count;     // Last measurement result
00522     SgCount _measured_sg_count; // Measured result
00523     SgCount _delta_sg_count[MFEA_DATAFLOW_TEST_FREQUENCY]; // Delta measurement result
00524     size_t  _delta_sg_count_index; // Index into next '_delta_sg_count'
00525     bool    _is_bootstrap_completed;
00526     
00527     TimeVal _measurement_interval;  // Interval between two measurements
00528     XorpTimer   _measurement_timer; // Timer to perform measurements
00529     
00530     // Time when current measurement window has started
00531     // XXX: used for debug purpose only
00532     TimeVal _start_time[MFEA_DATAFLOW_TEST_FREQUENCY];
00533 };
00534 
00535 
00536 //
00537 // Global variables
00538 //
00539 
00540 
00541 //
00542 // Global functions prototypes
00543 //
00544 
00545 #endif // __FEA_MFEA_DATAFLOW_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations