xorp

xrl_mld6igmp_node.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2009 XORP, Inc.
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/xrl_mld6igmp_node.hh,v 1.3 2008/10/02 21:56:33 bms Exp $
00021 
00022 #ifndef __MLD6IGMP_XRL_MLD6IGMP_NODE_HH__
00023 #define __MLD6IGMP_XRL_MLD6IGMP_NODE_HH__
00024 
00025 
00026 //
00027 // MLD6IGMP XRL-aware node definition.
00028 //
00029 
00030 #include "libxipc/xrl_std_router.hh"
00031 
00032 #include "libfeaclient/ifmgr_xrl_mirror.hh"
00033 
00034 #include "xrl/interfaces/finder_event_notifier_xif.hh"
00035 #include "xrl/interfaces/fea_rawpkt4_xif.hh"
00036 #include "xrl/interfaces/fea_rawpkt6_xif.hh"
00037 #include "xrl/interfaces/cli_manager_xif.hh"
00038 #include "xrl/interfaces/mld6igmp_client_xif.hh"
00039 #include "xrl/targets/mld6igmp_base.hh"
00040 
00041 #include "mld6igmp_node.hh"
00042 #include "mld6igmp_node_cli.hh"
00043 
00044 
00045 //
00046 // The top-level class that wraps-up everything together under one roof
00047 //
00048 class XrlMld6igmpNode : public Mld6igmpNode,
00049             public XrlStdRouter,
00050             public XrlMld6igmpTargetBase,
00051             public Mld6igmpNodeCli {
00052 public:
00053     XrlMld6igmpNode(int         family,
00054             xorp_module_id  module_id, 
00055             EventLoop&      eventloop,
00056             const string&   class_name,
00057             const string&   finder_hostname,
00058             uint16_t        finder_port,
00059             const string&   finder_target,
00060             const string&   fea_target,
00061             const string&   mfea_target);
00062     virtual ~XrlMld6igmpNode();
00063 
00069     int startup();
00070 
00076     int shutdown();
00077 
00083     XrlRouter&  xrl_router() { return *this; }
00084 
00090     const XrlRouter& xrl_router() const { return *this; }
00091 
00092     //
00093     // XrlMld6igmpNode front-end interface
00094     //
00095     int enable_cli();
00096     int disable_cli();
00097     int start_cli();
00098     int stop_cli();
00099     int enable_mld6igmp();
00100     int disable_mld6igmp();
00101     int start_mld6igmp();
00102     int stop_mld6igmp();
00103 
00104     // XrlTask relatedMethods that need to be public
00105     void send_register_unregister_interest();
00106     void send_register_unregister_receiver();
00107     void send_join_leave_multicast_group();
00108     void send_protocol_message();
00109 
00110 protected:
00111     //
00112     // XRL target methods
00113     //
00117     XrlCmdError common_0_1_get_target_name(
00118     // Output values, 
00119     string& name);
00120 
00124     XrlCmdError common_0_1_get_version(
00125     // Output values, 
00126     string& version);
00127 
00131     XrlCmdError common_0_1_get_status(// Output values,
00132                       uint32_t& status,
00133                       string&   reason);
00134 
00138     XrlCmdError common_0_1_shutdown();
00139 
00147     XrlCmdError finder_event_observer_0_1_xrl_target_birth(
00148     // Input values,
00149     const string&   target_class,
00150     const string&   target_instance);
00151 
00159     XrlCmdError finder_event_observer_0_1_xrl_target_death(
00160     // Input values,
00161     const string&   target_class,
00162     const string&   target_instance);
00163 
00185     XrlCmdError cli_processor_0_1_process_command(
00186     // Input values, 
00187     const string&   processor_name, 
00188     const string&   cli_term_name, 
00189     const uint32_t& cli_session_id,
00190     const string&   command_name, 
00191     const string&   command_args, 
00192     // Output values, 
00193     string& ret_processor_name, 
00194     string& ret_cli_term_name, 
00195     uint32_t& ret_cli_session_id,
00196     string& ret_command_output);
00197 
00222     XrlCmdError raw_packet4_client_0_1_recv(
00223     // Input values,
00224     const string&   if_name,
00225     const string&   vif_name,
00226     const IPv4& src_address,
00227     const IPv4& dst_address,
00228     const uint32_t& ip_protocol,
00229     const int32_t&  ip_ttl,
00230     const int32_t&  ip_tos,
00231     const bool& ip_router_alert,
00232     const bool& ip_internet_control,
00233     const vector<uint8_t>&  payload);
00234 
00266     XrlCmdError raw_packet6_client_0_1_recv(
00267     // Input values,
00268     const string&   if_name,
00269     const string&   vif_name,
00270     const IPv6& src_address,
00271     const IPv6& dst_address,
00272     const uint32_t& ip_protocol,
00273     const int32_t&  ip_ttl,
00274     const int32_t&  ip_tos,
00275     const bool& ip_router_alert,
00276     const bool& ip_internet_control,
00277     const XrlAtomList&  ext_headers_type,
00278     const XrlAtomList&  ext_headers_payload,
00279     const vector<uint8_t>&  payload);
00280     
00288     XrlCmdError mld6igmp_0_1_enable_vif(
00289     // Input values,
00290     const string&   vif_name,
00291     const bool& enable);
00292 
00293     XrlCmdError mld6igmp_0_1_start_vif(
00294     // Input values, 
00295     const string&   vif_name);
00296 
00297     XrlCmdError mld6igmp_0_1_stop_vif(
00298     // Input values, 
00299     const string&   vif_name);
00300 
00306     XrlCmdError mld6igmp_0_1_enable_all_vifs(
00307     // Input values,
00308     const bool& enable);
00309 
00310     XrlCmdError mld6igmp_0_1_start_all_vifs();
00311 
00312     XrlCmdError mld6igmp_0_1_stop_all_vifs();
00313 
00320     XrlCmdError mld6igmp_0_1_enable_mld6igmp(
00321     // Input values,
00322     const bool& enable);
00323 
00324     XrlCmdError mld6igmp_0_1_start_mld6igmp();
00325 
00326     XrlCmdError mld6igmp_0_1_stop_mld6igmp();
00327 
00334     XrlCmdError mld6igmp_0_1_enable_cli(
00335     // Input values,
00336     const bool& enable);
00337 
00338     XrlCmdError mld6igmp_0_1_start_cli();
00339 
00340     XrlCmdError mld6igmp_0_1_stop_cli();
00341 
00349     XrlCmdError mld6igmp_0_1_get_vif_proto_version(
00350     // Input values, 
00351     const string&   vif_name, 
00352     // Output values, 
00353     uint32_t&   proto_version);
00354 
00362     XrlCmdError mld6igmp_0_1_set_vif_proto_version(
00363     // Input values, 
00364     const string&   vif_name, 
00365     const uint32_t& proto_version);
00366 
00372     XrlCmdError mld6igmp_0_1_reset_vif_proto_version(
00373     // Input values, 
00374     const string&   vif_name);
00375 
00385     XrlCmdError mld6igmp_0_1_get_vif_ip_router_alert_option_check(
00386     // Input values,
00387     const string&   vif_name,
00388     // Output values,
00389     bool&   enabled);
00390 
00400     XrlCmdError mld6igmp_0_1_set_vif_ip_router_alert_option_check(
00401     // Input values,
00402     const string&   vif_name,
00403     const bool& enable);
00404 
00411     XrlCmdError mld6igmp_0_1_reset_vif_ip_router_alert_option_check(
00412     // Input values,
00413     const string&   vif_name);
00414 
00425     XrlCmdError mld6igmp_0_1_get_vif_query_interval(
00426     // Input values,
00427     const string&   vif_name,
00428     // Output values,
00429     uint32_t&   interval_sec,
00430     uint32_t&   interval_usec);
00431 
00442     XrlCmdError mld6igmp_0_1_set_vif_query_interval(
00443     // Input values,
00444     const string&   vif_name,
00445     const uint32_t& interval_sec,
00446     const uint32_t& interval_usec);
00447 
00453     XrlCmdError mld6igmp_0_1_reset_vif_query_interval(
00454     // Input values,
00455     const string&   vif_name);
00456 
00467     XrlCmdError mld6igmp_0_1_get_vif_query_last_member_interval(
00468     // Input values,
00469     const string&   vif_name,
00470     // Output values,
00471     uint32_t&   interval_sec,
00472     uint32_t&   interval_usec);
00473 
00484     XrlCmdError mld6igmp_0_1_set_vif_query_last_member_interval(
00485     // Input values,
00486     const string&   vif_name,
00487     const uint32_t& interval_sec,
00488     const uint32_t& interval_usec);
00489 
00496     XrlCmdError mld6igmp_0_1_reset_vif_query_last_member_interval(
00497     // Input values,
00498     const string&   vif_name);
00499 
00510     XrlCmdError mld6igmp_0_1_get_vif_query_response_interval(
00511     // Input values,
00512     const string&   vif_name,
00513     // Output values,
00514     uint32_t&   interval_sec,
00515     uint32_t&   interval_usec);
00516 
00527     XrlCmdError mld6igmp_0_1_set_vif_query_response_interval(
00528     // Input values,
00529     const string&   vif_name,
00530     const uint32_t& interval_sec,
00531     const uint32_t& interval_usec);
00532 
00538     XrlCmdError mld6igmp_0_1_reset_vif_query_response_interval(
00539     // Input values,
00540     const string&   vif_name);
00541 
00549     XrlCmdError mld6igmp_0_1_get_vif_robust_count(
00550     // Input values,
00551     const string&   vif_name,
00552     // Output values,
00553     uint32_t&   robust_count);
00554 
00562     XrlCmdError mld6igmp_0_1_set_vif_robust_count(
00563     // Input values,
00564     const string&   vif_name,
00565     const uint32_t& robust_count);
00566 
00572     XrlCmdError mld6igmp_0_1_reset_vif_robust_count(
00573     // Input values,
00574     const string&   vif_name);
00575 
00581     XrlCmdError mld6igmp_0_1_log_trace_all(
00582     // Input values,
00583     const bool& enable);
00584 
00602     XrlCmdError mld6igmp_0_1_add_protocol4(
00603     // Input values, 
00604     const string&   xrl_sender_name, 
00605     const string&   protocol_name, 
00606     const uint32_t& protocol_id, 
00607     const string&   vif_name, 
00608     const uint32_t& vif_index);
00609 
00610     XrlCmdError mld6igmp_0_1_add_protocol6(
00611     // Input values, 
00612     const string&   xrl_sender_name, 
00613     const string&   protocol_name, 
00614     const uint32_t& protocol_id, 
00615     const string&   vif_name, 
00616     const uint32_t& vif_index);
00617 
00618     XrlCmdError mld6igmp_0_1_delete_protocol4(
00619     // Input values, 
00620     const string&   xrl_sender_name, 
00621     const string&   protocol_name, 
00622     const uint32_t& protocol_id, 
00623     const string&   vif_name, 
00624     const uint32_t& vif_index);
00625 
00626     XrlCmdError mld6igmp_0_1_delete_protocol6(
00627     // Input values, 
00628     const string&   xrl_sender_name, 
00629     const string&   protocol_name, 
00630     const uint32_t& protocol_id, 
00631     const string&   vif_name, 
00632     const uint32_t& vif_index);
00633     
00634 private:
00635     class XrlTaskBase;
00636 
00637     const ServiceBase* ifmgr_mirror_service_base() const {
00638     return dynamic_cast<const ServiceBase*>(&_ifmgr);
00639     }
00640     const IfMgrIfTree& ifmgr_iftree() const { return _ifmgr.iftree(); }
00641 
00647     virtual void finder_connect_event();
00648 
00654     virtual void finder_disconnect_event();
00655 
00656     //
00657     // Methods to handle the XRL tasks
00658     //
00659     void add_task(XrlTaskBase* xrl_task);
00660     void send_xrl_task();
00661     void pop_xrl_task();
00662     void retry_xrl_task();
00663 
00664     void fea_register_startup();
00665     void mfea_register_startup();
00666     void fea_register_shutdown();
00667     void mfea_register_shutdown();
00668     void finder_send_register_unregister_interest_cb(const XrlError& xrl_error);
00669 
00670     //
00671     // Protocol node methods
00672     //
00673     int register_receiver(const string& if_name, const string& vif_name,
00674               uint8_t ip_protocol,
00675               bool enable_multicast_loopback);
00676     int unregister_receiver(const string& if_name, const string& vif_name,
00677                 uint8_t ip_protocol);
00678     void fea_client_send_register_unregister_receiver_cb(const XrlError& xrl_error);
00679 
00680     int join_multicast_group(const string& if_name, const string& vif_name,
00681                  uint8_t ip_protocol, const IPvX& group_address);
00682     int leave_multicast_group(const string& if_name, const string& vif_name,
00683                   uint8_t ip_protocol, const IPvX& group_address);
00684     void fea_client_send_join_leave_multicast_group_cb(const XrlError& xrl_error);
00685 
00686     int proto_send(const string& if_name,
00687            const string& vif_name,
00688            const IPvX& src_address,
00689            const IPvX& dst_address,
00690            uint8_t ip_protocol,
00691            int32_t ip_ttl,
00692            int32_t ip_tos,
00693            bool ip_router_alert,
00694            bool ip_internet_control,
00695            const uint8_t* sndbuf,
00696            size_t sndlen,
00697            string& error_msg);
00698     void fea_client_send_protocol_message_cb(const XrlError& xrl_error);
00699     
00700     int send_add_membership(const string& dst_module_instance_name,
00701                 xorp_module_id dst_module_id,
00702                 uint32_t vif_index,
00703                 const IPvX& source,
00704                 const IPvX& group);
00705     int send_delete_membership(const string& dst_module_instance_name,
00706                    xorp_module_id dst_module_id,
00707                    uint32_t vif_index,
00708                    const IPvX& source,
00709                    const IPvX& group);
00710     void send_add_delete_membership();
00711     void mld6igmp_client_send_add_delete_membership_cb(const XrlError& xrl_error);
00712     
00713     //
00714     // Protocol node CLI methods
00715     //
00716     int add_cli_command_to_cli_manager(const char *command_name,
00717                        const char *command_help,
00718                        bool is_command_cd,
00719                        const char *command_cd_prompt,
00720                        bool is_command_processor);
00721     void cli_manager_client_send_add_cli_command_cb(const XrlError& xrl_error);
00722     int delete_cli_command_from_cli_manager(const char *command_name);
00723     void cli_manager_client_send_delete_cli_command_cb(const XrlError& xrl_error);
00724 
00725     int family() const { return (Mld6igmpNode::family()); }
00726 
00727 
00731     class XrlTaskBase {
00732     public:
00733     XrlTaskBase(XrlMld6igmpNode& xrl_mld6igmp_node)
00734         : _xrl_mld6igmp_node(xrl_mld6igmp_node) {}
00735     virtual ~XrlTaskBase() {}
00736 
00737     virtual void dispatch() = 0;
00738     virtual const char* operation_name() const = 0;
00739 
00740     protected:
00741     XrlMld6igmpNode&    _xrl_mld6igmp_node;
00742     private:
00743     };
00744 
00749     class RegisterUnregisterInterest : public XrlTaskBase {
00750     public:
00751     RegisterUnregisterInterest(XrlMld6igmpNode& xrl_mld6igmp_node,
00752                    const string&    target_name,
00753                    bool         is_register)
00754         : XrlTaskBase(xrl_mld6igmp_node),
00755           _target_name(target_name),
00756           _is_register(is_register) {}
00757 
00758     void        dispatch() {
00759         _xrl_mld6igmp_node.send_register_unregister_interest();
00760     }
00761     const char* operation_name() const {
00762         return ((_is_register)? "register" : "unregister");
00763     }
00764     const string&   target_name() const { return _target_name; }
00765     bool        is_register() const { return _is_register; }
00766 
00767     private:
00768     string      _target_name;
00769     bool        _is_register;
00770     };
00771 
00776     class RegisterUnregisterReceiver : public XrlTaskBase {
00777     public:
00778     RegisterUnregisterReceiver(XrlMld6igmpNode& xrl_mld6igmp_node,
00779                    const string&    if_name,
00780                    const string&    vif_name,
00781                    uint8_t      ip_protocol,
00782                    bool         enable_multicast_loopback,
00783                    bool         is_register)
00784         : XrlTaskBase(xrl_mld6igmp_node),
00785           _if_name(if_name),
00786           _vif_name(vif_name),
00787           _ip_protocol(ip_protocol),
00788           _enable_multicast_loopback(enable_multicast_loopback),
00789           _is_register(is_register) {}
00790 
00791     void        dispatch() {
00792         _xrl_mld6igmp_node.send_register_unregister_receiver();
00793     }
00794     const char* operation_name() const {
00795         return ((_is_register)? "register" : "unregister");
00796     }
00797     const string&   if_name() const { return _if_name; }
00798     const string&   vif_name() const { return _vif_name; }
00799     uint8_t     ip_protocol() const { return _ip_protocol; }
00800     bool        enable_multicast_loopback() const {
00801         return _enable_multicast_loopback;
00802     }
00803     bool        is_register() const { return _is_register; }
00804 
00805     private:
00806     string      _if_name;
00807     string      _vif_name;
00808     uint8_t     _ip_protocol;
00809     bool        _enable_multicast_loopback;
00810     bool        _is_register;
00811     };
00812 
00816     class JoinLeaveMulticastGroup : public XrlTaskBase {
00817     public:
00818     JoinLeaveMulticastGroup(XrlMld6igmpNode&    xrl_mld6igmp_node,
00819                 const string&       if_name,
00820                 const string&       vif_name,
00821                 uint8_t         ip_protocol,
00822                 const IPvX&     group_address,
00823                 bool            is_join)
00824         : XrlTaskBase(xrl_mld6igmp_node),
00825           _if_name(if_name),
00826           _vif_name(vif_name),
00827           _ip_protocol(ip_protocol),
00828           _group_address(group_address),
00829           _is_join(is_join) {}
00830 
00831     void        dispatch() {
00832         _xrl_mld6igmp_node.send_join_leave_multicast_group();
00833     }
00834     const char* operation_name() const {
00835         return ((_is_join)? "join" : "leave");
00836     }
00837     const string&   if_name() const { return _if_name; }
00838     const string&   vif_name() const { return _vif_name; }
00839     uint8_t     ip_protocol() const { return _ip_protocol; }
00840     const IPvX& group_address() const { return _group_address; }
00841     bool        is_join() const { return _is_join; }
00842 
00843     private:
00844     string      _if_name;
00845     string      _vif_name;
00846     uint8_t     _ip_protocol;
00847     IPvX        _group_address;
00848     bool        _is_join;
00849     };
00850 
00854     class SendProtocolMessage : public XrlTaskBase {
00855     public:
00856     SendProtocolMessage(XrlMld6igmpNode&    xrl_mld6igmp_node,
00857                 const string&   if_name,
00858                 const string&   vif_name,
00859                 const IPvX&     src_address,
00860                 const IPvX&     dst_address,
00861                 uint8_t     ip_protocol,
00862                 int32_t     ip_ttl,
00863                 int32_t     ip_tos,
00864                 bool        ip_router_alert,
00865                 bool        ip_internet_control,
00866                 const uint8_t*  sndbuf,
00867                 size_t      sndlen)
00868         : XrlTaskBase(xrl_mld6igmp_node),
00869           _if_name(if_name),
00870           _vif_name(vif_name),
00871           _src_address(src_address),
00872           _dst_address(dst_address),
00873           _ip_protocol(ip_protocol),
00874           _ip_ttl(ip_ttl),
00875           _ip_tos(ip_tos),
00876           _ip_router_alert(ip_router_alert),
00877           _ip_internet_control(ip_internet_control) {
00878         _payload.resize(sndlen);
00879         for (size_t i = 0; i < sndlen; i++)
00880         _payload[i] = sndbuf[i];
00881     }
00882 
00883     void        dispatch() {
00884         _xrl_mld6igmp_node.send_protocol_message();
00885     }
00886     const char* operation_name() const {
00887         return ("send");
00888     }
00889     const string&   if_name() const { return _if_name; }
00890     const string&   vif_name() const { return _vif_name; }
00891     const IPvX& src_address() const { return _src_address; }
00892     const IPvX& dst_address() const { return _dst_address; }
00893     uint8_t     ip_protocol() const { return _ip_protocol; }
00894     int32_t     ip_ttl() const { return _ip_ttl; }
00895     int32_t     ip_tos() const { return _ip_tos; }
00896     bool        ip_router_alert() const { return _ip_router_alert; }
00897     bool        ip_internet_control() const { return _ip_internet_control; }
00898     const vector<uint8_t>& payload() const { return _payload; }
00899 
00900     private:
00901     string      _if_name;
00902     string      _vif_name;
00903     IPvX        _src_address;
00904     IPvX        _dst_address;
00905     uint8_t     _ip_protocol;
00906     int32_t     _ip_ttl;
00907     int32_t     _ip_tos;
00908     bool        _ip_router_alert;
00909     bool        _ip_internet_control;
00910     vector<uint8_t> _payload;
00911     };
00912 
00916     class SendAddDeleteMembership {
00917     public:
00918     SendAddDeleteMembership(const string& dst_module_instance_name,
00919                 xorp_module_id dst_module_id,
00920                 uint32_t vif_index,
00921                 const IPvX& source,
00922                 const IPvX& group,
00923                 bool is_add)
00924         : _dst_module_instance_name(dst_module_instance_name),
00925           _dst_module_id(dst_module_id),
00926           _vif_index(vif_index),
00927           _source(source),
00928           _group(group),
00929           _is_add(is_add) {}
00930     const char* operation_name() const {
00931         return ((_is_add)? "add membership" : "delete membership");
00932     }
00933     const string& dst_module_instance_name() const { return _dst_module_instance_name; }
00934     xorp_module_id dst_module_id() const { return _dst_module_id; }
00935     uint32_t vif_index() const { return _vif_index; }
00936     const IPvX& source() const { return _source; }
00937     const IPvX& group() const { return _group; }
00938     bool is_add() const { return _is_add; }
00939 
00940     private:
00941     string      _dst_module_instance_name;
00942     xorp_module_id  _dst_module_id;
00943     uint32_t    _vif_index;
00944     IPvX        _source;
00945     IPvX        _group;
00946     bool        _is_add;
00947     };
00948 
00949     EventLoop&          _eventloop;
00950     const string        _finder_target;
00951     const string        _fea_target;
00952     const string        _mfea_target;
00953 
00954     IfMgrXrlMirror      _ifmgr;
00955 
00956     XrlRawPacket4V0p1Client _xrl_fea_client4;
00957     XrlRawPacket6V0p1Client _xrl_fea_client6;
00958     XrlMld6igmpClientV0p1Client _xrl_mld6igmp_client_client;
00959     XrlCliManagerV0p1Client _xrl_cli_manager_client;
00960     XrlFinderEventNotifierV0p1Client    _xrl_finder_client;
00961 
00962     static const TimeVal    RETRY_TIMEVAL;
00963 
00964     bool            _is_finder_alive;
00965 
00966     bool            _is_fea_alive;
00967     bool            _is_fea_registered;
00968 
00969     bool            _is_mfea_alive;
00970     bool            _is_mfea_registered;
00971 
00972     list<XrlTaskBase* >     _xrl_tasks_queue;
00973     XorpTimer           _xrl_tasks_queue_timer;
00974     list<SendAddDeleteMembership> _send_add_delete_membership_queue;
00975     XorpTimer           _send_add_delete_membership_queue_timer;
00976 };
00977 
00978 #endif // __MLD6IGMP_XRL_MLD6IGMP_NODE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations