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/contrib/mld6igmp_lite/mld6igmp_vif.hh,v 1.3 2008/10/02 21:56:32 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     
00097     int     stop(string& error_msg);
00098 
00104     void    enable();
00105     
00112     void    disable();
00113 
00130     int     mld6igmp_recv(const IPvX& src, const IPvX& dst,
00131                   int ip_ttl, int ip_tos, bool ip_router_alert,
00132                   bool ip_internet_control,
00133                   buffer_t *buffer, string& error_msg);
00134     
00144     string  flags_string() const;
00145     
00151     Mld6igmpNode& mld6igmp_node() const { return (_mld6igmp_node); }
00152 
00158     const IPvX& primary_addr() const    { return (_primary_addr); }
00159 
00165     void    set_primary_addr(const IPvX& v) { _primary_addr = v; }
00166 
00176     int     update_primary_address(string& error_msg);
00177     
00183     const IPvX& querier_addr()  const       { return (_querier_addr); }
00184     
00190     void    set_querier_addr(const IPvX& v) { _querier_addr = v;    }
00191 
00199     Mld6igmpGroupSet& group_records() { return (_group_records); }
00200 
00208     const Mld6igmpGroupSet& group_records() const { return (_group_records); }
00209 
00217     bool    proto_is_ssm() const;
00218     
00226     const XorpTimer& const_other_querier_timer() const { return (_other_querier_timer); }
00227 
00233     ConfigParam<bool>& ip_router_alert_option_check() { return (_ip_router_alert_option_check); }
00234     
00240     ConfigParam<TimeVal>& configured_query_interval() { return (_configured_query_interval); }
00241 
00250     const TimeVal& effective_query_interval() const { return (_effective_query_interval); }
00251 
00260     void    set_effective_query_interval(const TimeVal& v);
00261 
00267     ConfigParam<TimeVal>& query_last_member_interval() { return (_query_last_member_interval); }
00268 
00274     ConfigParam<TimeVal>& query_response_interval() { return (_query_response_interval); }
00275 
00281     ConfigParam<uint32_t>& configured_robust_count() { return (_configured_robust_count); }
00282 
00291     uint32_t    effective_robustness_variable() const { return (_effective_robustness_variable); }
00292 
00301     void    set_effective_robustness_variable(uint32_t v);
00302 
00314     uint32_t    last_member_query_count() const { return (_last_member_query_count); }
00315 
00324     const TimeVal& group_membership_interval() const { return (_group_membership_interval); }
00325 
00334     const TimeVal& last_member_query_time() const { return (_last_member_query_time); }
00335 
00344     const TimeVal& older_version_host_present_interval() const { return (_older_version_host_present_interval); }
00345 
00346     //
00347     // Add/delete routing protocols that need to be notified for membership
00348     // changes.
00349     //
00350 
00364     int     add_protocol(xorp_module_id module_id,
00365                  const string& module_instance_name);
00366     
00380     int     delete_protocol(xorp_module_id module_id,
00381                 const string& module_instance_name);
00382 
00394     int     join_prune_notify_routing(const IPvX& source,
00395                       const IPvX& group,
00396                       action_jp_t action_jp) const;
00397     //
00398     // Functions for sending protocol messages
00399     //
00400 
00416     int     mld6igmp_send(const IPvX& src, const IPvX& dst,
00417                   uint8_t message_type, uint16_t max_resp_code,
00418                   const IPvX& group_address, buffer_t *buffer,
00419                   string& error_msg);
00420 
00429     int mld6igmp_group_query_send(const IPvX& group_address,
00430                   string& error_msg);
00431 
00441     int     mld6igmp_group_source_query_send(const IPvX& group_address,
00442                          const set<IPvX>& sources,
00443                          string& error_msg);
00444 
00459     int     mld6igmp_query_send(const IPvX& src, const IPvX& dst,
00460                     const TimeVal& max_resp_time,
00461                     const IPvX& group_address,
00462                     const set<IPvX>& sources,
00463                     bool s_flag,
00464                     string& error_msg);
00465 
00472     bool    is_igmpv1_mode() const;
00473 
00480     bool    is_igmpv2_mode() const;
00481 
00488     bool    is_igmpv3_mode() const;
00489 
00496     bool    is_mldv1_mode() const;
00497 
00504     bool    is_mldv2_mode() const;
00505 
00515     bool    is_igmpv1_mode(const Mld6igmpGroupRecord* group_record) const;
00516 
00526     bool    is_igmpv2_mode(const Mld6igmpGroupRecord* group_record) const;
00527 
00537     bool    is_igmpv3_mode(const Mld6igmpGroupRecord* group_record) const;
00538 
00548     bool    is_mldv1_mode(const Mld6igmpGroupRecord* group_record) const;
00549 
00559     bool    is_mldv2_mode(const Mld6igmpGroupRecord* group_record) const;
00560 
00561 private:
00562     //
00563     // Private functions
00564     //
00565 
00572     const char  *proto_message_type2ascii(uint8_t message_type) const;
00573 
00579     buffer_t    *buffer_send_prepare();
00580 
00592     uint16_t    calculate_ipv6_pseudo_header_checksum(const IPvX& src,
00593                               const IPvX& dst,
00594                               size_t len,
00595                               uint8_t protocol);
00596 
00602     bool    i_am_querier() const;
00603 
00609     void    set_i_am_querier(bool v);
00610 
00611     //
00612     // Callbacks for configuration and non-configurable parameters
00613     //
00614     void    set_configured_query_interval_cb(TimeVal v);
00615     void    set_query_last_member_interval_cb(TimeVal v);
00616     void    set_query_response_interval_cb(TimeVal v);
00617     void    set_configured_robust_count_cb(uint32_t v);
00618     void    recalculate_effective_query_interval();
00619     void    recalculate_effective_robustness_variable();
00620     void    recalculate_last_member_query_count();
00621     void    recalculate_group_membership_interval();
00622     void    recalculate_last_member_query_time();
00623     void    recalculate_older_version_host_present_interval();
00624     void    restore_effective_variables();
00625 
00626     //
00627     // Private state
00628     //
00629     Mld6igmpNode& _mld6igmp_node;   // The MLD6IGMP node I belong to
00630     buffer_t    *_buffer_send;      // Buffer for sending messages
00631     enum {
00632     MLD6IGMP_VIF_QUERIER    = 1 << 0 // I am the querier
00633     };
00634     uint32_t    _proto_flags;       // Various flags (MLD6IGMP_VIF_*)
00635     IPvX    _primary_addr;      // The primary address on this vif
00636     IPvX    _querier_addr;      // IP address of the current querier
00637     XorpTimer   _other_querier_timer;   // To timeout the (other) 'querier'
00638     XorpTimer   _query_timer;       // Timer to send queries
00639     uint8_t _startup_query_count;   // Number of queries to send quickly
00640                     // during startup
00641     Mld6igmpGroupSet _group_records;    // The group records
00642 
00643     //
00644     // Misc configuration parameters
00645     //
00646     ConfigParam<bool> _ip_router_alert_option_check; // The IP Router Alert option check flag
00647     ConfigParam<TimeVal> _configured_query_interval;    // The configured Query Interval
00648     TimeVal _effective_query_interval;  // The effective Query Interval
00649     ConfigParam<TimeVal> _query_last_member_interval;   // The Last Member Query Interval
00650     ConfigParam<TimeVal> _query_response_interval;  // The Query Response Interval
00651     ConfigParam<uint32_t> _configured_robust_count; // The configured Robustness Variable count
00652     uint32_t    _effective_robustness_variable; // The effective Robustness Variable
00653 
00654     //
00655     // Other parameters that are not directly configurable
00656     //
00657     uint32_t    _last_member_query_count;   // The Last Member Query Count
00658     TimeVal _group_membership_interval; // The Group Membership Interval
00659     TimeVal _last_member_query_time;    // The Last Member Query Time
00660     TimeVal _older_version_host_present_interval;   // The Older Version Host Present Interval
00661 
00662     //
00663     // Misc. other state
00664     //
00665     // Registered protocols to notify for membership change.
00666     vector<pair<xorp_module_id, string> > _notify_routing_protocols;
00667     bool _dummy_flag;           // Dummy flag
00668     
00669     //
00670     // Not-so handy private functions that should go somewhere else
00671     //
00672     // MLD/IGMP control messages recv functions
00673     int     mld6igmp_membership_query_recv(const IPvX& src,
00674                            const IPvX& dst,
00675                            uint8_t message_type,
00676                            uint16_t max_resp_code,
00677                            const IPvX& group_address,
00678                            buffer_t *buffer);
00679     int     mld6igmp_ssm_membership_query_recv(const IPvX& src,
00680                            const IPvX& dst,
00681                            uint8_t message_type,
00682                            uint16_t max_resp_code,
00683                            const IPvX& group_address,
00684                            buffer_t *buffer);
00685     int     mld6igmp_membership_report_recv(const IPvX& src,
00686                         const IPvX& dst,
00687                         uint8_t message_type,
00688                         uint16_t max_resp_code,
00689                         const IPvX& group_address,
00690                         buffer_t *buffer);
00691     int     mld6igmp_leave_group_recv(const IPvX& src,
00692                       const IPvX& dst,
00693                       uint8_t message_type,
00694                       uint16_t max_resp_code,
00695                       const IPvX& group_address,
00696                       buffer_t *buffer);
00697     int     mld6igmp_ssm_membership_report_recv(const IPvX& src,
00698                             const IPvX& dst,
00699                             uint8_t message_type,
00700                             buffer_t *buffer);
00701     int     mld6igmp_query_version_consistency_check(const IPvX& src,
00702                              const IPvX& dst,
00703                              uint8_t message_type,
00704                              int message_version);
00705 
00706     // MLD/IGMP control messages process functions
00707     int     mld6igmp_process(const IPvX& src,
00708                  const IPvX& dst,
00709                  int ip_ttl,
00710                  int ip_tos,
00711                  bool ip_router_alert,
00712                  bool ip_internet_control,
00713                  buffer_t *buffer,
00714                  string& error_msg);
00715 
00716     // MLD/IGMP uniform interface for protocol-related constants
00717     size_t  mld6igmp_constant_minlen() const;
00718     uint32_t    mld6igmp_constant_timer_scale() const;
00719     uint8_t mld6igmp_constant_membership_query() const;
00720 
00721     void    other_querier_timer_timeout();
00722     void    query_timer_timeout();
00723 
00724     void    decode_exp_time_code8(uint8_t code, TimeVal& timeval,
00725                       uint32_t timer_scale);
00726     void    decode_exp_time_code16(uint16_t code, TimeVal& timeval,
00727                        uint32_t timer_scale);
00728     void    encode_exp_time_code8(const TimeVal& timeval,
00729                       uint8_t& code,
00730                       uint32_t timer_scale);
00731     void    encode_exp_time_code16(const TimeVal& timeval,
00732                        uint16_t& code,
00733                        uint32_t timer_scale);
00734 };
00735 
00736 //
00737 // Global variables
00738 //
00739 
00740 //
00741 // Global functions prototypes
00742 //
00743 
00744 #endif // __MLD6IGMP_MLD6IGMP_VIF_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations