xorp

mld6igmp_vif.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/mld6igmp/mld6igmp_vif.hh,v 1.51 2008/10/02 21:57:44 bms Exp $
00021 
00022 #ifndef __MLD6IGMP_MLD6IGMP_VIF_HH__
00023 #define __MLD6IGMP_MLD6IGMP_VIF_HH__
00024 
00025 
00026 //
00027 // IGMP and MLD virtual interface definition.
00028 //
00029 
00030 
00031 
00032 
00033 #include "libxorp/config_param.hh"
00034 #include "libxorp/timer.hh"
00035 #include "libxorp/vif.hh"
00036 #include "libproto/proto_unit.hh"
00037 #include "mrt/buffer.h"
00038 #include "mrt/multicast_defs.h"
00039 #include "igmp_proto.h"
00040 #include "mld6_proto.h"
00041 #include "mld6igmp_node.hh"
00042 #include "mld6igmp_group_record.hh"
00043 
00044 
00045 //
00046 // Constants definitions
00047 //
00048 
00049 //
00050 // Structures/classes, typedefs and macros
00051 //
00052 
00056 class Mld6igmpVif : public ProtoUnit, public Vif {
00057 public:
00064     Mld6igmpVif(Mld6igmpNode& mld6igmp_node, const Vif& vif);
00065     
00069     virtual ~Mld6igmpVif();
00070 
00081     int     set_proto_version(int proto_version);
00082     
00089     int     start(string& error_msg);
00090     
00093     void notifyUpdated();
00094 
00101     int     stop(string& error_msg);
00102 
00108     void    enable();
00109     
00116     void    disable();
00117 
00134     int     mld6igmp_recv(const IPvX& src, const IPvX& dst,
00135                   int ip_ttl, int ip_tos, bool ip_router_alert,
00136                   bool ip_internet_control,
00137                   buffer_t *buffer, string& error_msg);
00138     
00148     string  flags_string() const;
00149     
00155     Mld6igmpNode& mld6igmp_node() const { return (_mld6igmp_node); }
00156 
00162     const IPvX& primary_addr() const    { return (_primary_addr); }
00163 
00169     void    set_primary_addr(const IPvX& v) { _primary_addr = v; }
00170 
00180     int     update_primary_address(string& error_msg);
00181     
00187     const IPvX& querier_addr()  const       { return (_querier_addr); }
00188     
00194     void    set_querier_addr(const IPvX& v) { _querier_addr = v;    }
00195 
00203     Mld6igmpGroupSet& group_records() { return (_group_records); }
00204 
00212     const Mld6igmpGroupSet& group_records() const { return (_group_records); }
00213 
00221     bool    proto_is_ssm() const;
00222     
00230     const XorpTimer& const_other_querier_timer() const { return (_other_querier_timer); }
00231 
00237     ConfigParam<bool>& ip_router_alert_option_check() { return (_ip_router_alert_option_check); }
00238     
00244     ConfigParam<TimeVal>& configured_query_interval() { return (_configured_query_interval); }
00245 
00254     const TimeVal& effective_query_interval() const { return (_effective_query_interval); }
00255 
00264     void    set_effective_query_interval(const TimeVal& v);
00265 
00271     ConfigParam<TimeVal>& query_last_member_interval() { return (_query_last_member_interval); }
00272 
00278     ConfigParam<TimeVal>& query_response_interval() { return (_query_response_interval); }
00279 
00285     ConfigParam<uint32_t>& configured_robust_count() { return (_configured_robust_count); }
00286 
00295     uint32_t    effective_robustness_variable() const { return (_effective_robustness_variable); }
00296 
00305     void    set_effective_robustness_variable(uint32_t v);
00306 
00318     uint32_t    last_member_query_count() const { return (_last_member_query_count); }
00319 
00328     const TimeVal& group_membership_interval() const { return (_group_membership_interval); }
00329 
00338     const TimeVal& last_member_query_time() const { return (_last_member_query_time); }
00339 
00348     const TimeVal& older_version_host_present_interval() const { return (_older_version_host_present_interval); }
00349 
00350     //
00351     // Add/delete routing protocols that need to be notified for membership
00352     // changes.
00353     //
00354 
00368     int     add_protocol(xorp_module_id module_id,
00369                  const string& module_instance_name);
00370     
00384     int     delete_protocol(xorp_module_id module_id,
00385                 const string& module_instance_name, string& error_msg);
00386 
00398     int     join_prune_notify_routing(const IPvX& source,
00399                       const IPvX& group,
00400                       action_jp_t action_jp) const;
00401     //
00402     // Functions for sending protocol messages
00403     //
00404 
00420     int     mld6igmp_send(const IPvX& src, const IPvX& dst,
00421                   uint8_t message_type, uint16_t max_resp_code,
00422                   const IPvX& group_address, buffer_t *buffer,
00423                   string& error_msg);
00424 
00433     int mld6igmp_group_query_send(const IPvX& group_address,
00434                   string& error_msg);
00435 
00445     int     mld6igmp_group_source_query_send(const IPvX& group_address,
00446                          const set<IPvX>& sources,
00447                          string& error_msg);
00448 
00463     int     mld6igmp_query_send(const IPvX& src, const IPvX& dst,
00464                     const TimeVal& max_resp_time,
00465                     const IPvX& group_address,
00466                     const set<IPvX>& sources,
00467                     bool s_flag,
00468                     string& error_msg);
00469 
00476     bool    is_igmpv1_mode() const;
00477 
00484     bool    is_igmpv2_mode() const;
00485 
00492     bool    is_igmpv3_mode() const;
00493 
00500     bool    is_mldv1_mode() const;
00501 
00508     bool    is_mldv2_mode() const;
00509 
00519     bool    is_igmpv1_mode(const Mld6igmpGroupRecord* group_record) const;
00520 
00530     bool    is_igmpv2_mode(const Mld6igmpGroupRecord* group_record) const;
00531 
00541     bool    is_igmpv3_mode(const Mld6igmpGroupRecord* group_record) const;
00542 
00552     bool    is_mldv1_mode(const Mld6igmpGroupRecord* group_record) const;
00553 
00563     bool    is_mldv2_mode(const Mld6igmpGroupRecord* group_record) const;
00564 
00565 private:
00566     //
00567     // Private functions
00568     //
00569 
00576     const char  *proto_message_type2ascii(uint8_t message_type) const;
00577 
00583     buffer_t    *buffer_send_prepare();
00584 
00596     uint16_t    calculate_ipv6_pseudo_header_checksum(const IPvX& src,
00597                               const IPvX& dst,
00598                               size_t len,
00599                               uint8_t protocol);
00600 
00606     bool    i_am_querier() const;
00607 
00613     void    set_i_am_querier(bool v);
00614 
00615     //
00616     // Callbacks for configuration and non-configurable parameters
00617     //
00618     void    set_configured_query_interval_cb(TimeVal v);
00619     void    set_query_last_member_interval_cb(TimeVal v);
00620     void    set_query_response_interval_cb(TimeVal v);
00621     void    set_configured_robust_count_cb(uint32_t v);
00622     void    recalculate_effective_query_interval();
00623     void    recalculate_effective_robustness_variable();
00624     void    recalculate_last_member_query_count();
00625     void    recalculate_group_membership_interval();
00626     void    recalculate_last_member_query_time();
00627     void    recalculate_older_version_host_present_interval();
00628     void    restore_effective_variables();
00629 
00630     //
00631     // Private state
00632     //
00633     Mld6igmpNode& _mld6igmp_node;   // The MLD6IGMP node I belong to
00634     buffer_t    *_buffer_send;      // Buffer for sending messages
00635     enum {
00636     MLD6IGMP_VIF_QUERIER    = 1 << 0 // I am the querier
00637     };
00638     uint32_t    _proto_flags;       // Various flags (MLD6IGMP_VIF_*)
00639     IPvX    _primary_addr;      // The primary address on this vif
00640     IPvX    _querier_addr;      // IP address of the current querier
00641     XorpTimer   _other_querier_timer;   // To timeout the (other) 'querier'
00642     XorpTimer   _query_timer;       // Timer to send queries
00643     uint8_t _startup_query_count;   // Number of queries to send quickly
00644                     // during startup
00645     Mld6igmpGroupSet _group_records;    // The group records
00646 
00647     //
00648     // Misc configuration parameters
00649     //
00650     ConfigParam<bool> _ip_router_alert_option_check; // The IP Router Alert option check flag
00651     ConfigParam<TimeVal> _configured_query_interval;    // The configured Query Interval
00652     TimeVal _effective_query_interval;  // The effective Query Interval
00653     ConfigParam<TimeVal> _query_last_member_interval;   // The Last Member Query Interval
00654     ConfigParam<TimeVal> _query_response_interval;  // The Query Response Interval
00655     ConfigParam<uint32_t> _configured_robust_count; // The configured Robustness Variable count
00656     uint32_t    _effective_robustness_variable; // The effective Robustness Variable
00657 
00658     //
00659     // Other parameters that are not directly configurable
00660     //
00661     uint32_t    _last_member_query_count;   // The Last Member Query Count
00662     TimeVal _group_membership_interval; // The Group Membership Interval
00663     TimeVal _last_member_query_time;    // The Last Member Query Time
00664     TimeVal _older_version_host_present_interval;   // The Older Version Host Present Interval
00665 
00666     //
00667     // Misc. other state
00668     //
00669     // Registered protocols to notify for membership change.
00670     vector<pair<xorp_module_id, string> > _notify_routing_protocols;
00671     bool _dummy_flag;           // Dummy flag
00672     
00673     //
00674     // Not-so handy private functions that should go somewhere else
00675     //
00676     // MLD/IGMP control messages recv functions
00677     int     mld6igmp_membership_query_recv(const IPvX& src,
00678                            const IPvX& dst,
00679                            uint8_t message_type,
00680                            uint16_t max_resp_code,
00681                            const IPvX& group_address,
00682                            buffer_t *buffer);
00683     int     mld6igmp_ssm_membership_query_recv(const IPvX& src,
00684                            const IPvX& dst,
00685                            uint8_t message_type,
00686                            uint16_t max_resp_code,
00687                            const IPvX& group_address,
00688                            buffer_t *buffer);
00689     int     mld6igmp_membership_report_recv(const IPvX& src,
00690                         const IPvX& dst,
00691                         uint8_t message_type,
00692                         uint16_t max_resp_code,
00693                         const IPvX& group_address,
00694                         buffer_t *buffer);
00695     int     mld6igmp_leave_group_recv(const IPvX& src,
00696                       const IPvX& dst,
00697                       uint8_t message_type,
00698                       uint16_t max_resp_code,
00699                       const IPvX& group_address,
00700                       buffer_t *buffer);
00701     int     mld6igmp_ssm_membership_report_recv(const IPvX& src,
00702                             const IPvX& dst,
00703                             uint8_t message_type,
00704                             buffer_t *buffer);
00705     int     mld6igmp_query_version_consistency_check(const IPvX& src,
00706                              const IPvX& dst,
00707                              uint8_t message_type,
00708                              int message_version);
00709 
00710     // MLD/IGMP control messages process functions
00711     int     mld6igmp_process(const IPvX& src,
00712                  const IPvX& dst,
00713                  int ip_ttl,
00714                  int ip_tos,
00715                  bool ip_router_alert,
00716                  bool ip_internet_control,
00717                  buffer_t *buffer,
00718                  string& error_msg);
00719 
00720     // MLD/IGMP uniform interface for protocol-related constants
00721     size_t  mld6igmp_constant_minlen() const;
00722     uint32_t    mld6igmp_constant_timer_scale() const;
00723     uint8_t mld6igmp_constant_membership_query() const;
00724 
00725     void    other_querier_timer_timeout();
00726     void    query_timer_timeout();
00727 
00728     void    decode_exp_time_code8(uint8_t code, TimeVal& timeval,
00729                       uint32_t timer_scale);
00730     void    decode_exp_time_code16(uint16_t code, TimeVal& timeval,
00731                        uint32_t timer_scale);
00732     void    encode_exp_time_code8(const TimeVal& timeval,
00733                       uint8_t& code,
00734                       uint32_t timer_scale);
00735     void    encode_exp_time_code16(const TimeVal& timeval,
00736                        uint16_t& code,
00737                        uint32_t timer_scale);
00738 
00739     bool wants_to_be_started; // as soon as we can, ie if the interface appears.
00740 };
00741 
00742 //
00743 // Global variables
00744 //
00745 
00746 //
00747 // Global functions prototypes
00748 //
00749 
00750 #endif // __MLD6IGMP_MLD6IGMP_VIF_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations