xorp

io_ip.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2007-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/io_ip.hh,v 1.5 2008/10/02 21:56:48 bms Exp $
00021 
00022 
00023 #ifndef __FEA_IO_IP_HH__
00024 #define __FEA_IO_IP_HH__
00025 
00026 
00027 
00028 #include "fea_data_plane_manager.hh"
00029 
00030 //
00031 // I/O IP raw communication API.
00032 //
00033 
00034 
00035 class EventLoop;
00036 class IfTree;
00037 class IfTreeInterface;
00038 class IfTreeVif;
00039 class IoIpManager;
00040 class IoIpReceiver;
00041 class IPvX;
00042 class XorpFd;
00043 
00044 
00051 class IoIp {
00052 public:
00063     IoIp(FeaDataPlaneManager& fea_data_plane_manager, const IfTree& iftree,
00064      int family, uint8_t ip_protocol);
00065 
00069     virtual ~IoIp();
00070 
00076     IoIpManager& io_ip_manager() { return _io_ip_manager; }
00077 
00083     FeaDataPlaneManager& fea_data_plane_manager() { return _fea_data_plane_manager; }
00084 
00090     virtual bool is_running() const { return _is_running; }
00091 
00097     EventLoop& eventloop() { return (_eventloop); }
00098 
00104     const IfTree& iftree() const { return (_iftree); }
00105 
00111     virtual int family() const { return (_family); }
00112 
00118     virtual uint8_t ip_protocol() const { return (_ip_protocol); }
00119 
00125     IoIpReceiver* io_ip_receiver() { return (_io_ip_receiver); }
00126 
00132     virtual void register_io_ip_receiver(IoIpReceiver* io_ip_receiver);
00133 
00137     virtual void unregister_io_ip_receiver();
00138 
00145     virtual int start(string& error_msg) = 0;
00146 
00153     virtual int stop(string& error_msg) = 0;
00154 
00163     virtual int set_multicast_ttl(int ttl, string& error_msg) = 0;
00164 
00176     virtual int enable_multicast_loopback(bool is_enabled,
00177                       string& error_msg) = 0;
00178 
00189     virtual int set_default_multicast_interface(const string& if_name,
00190                         const string& vif_name,
00191                         string& error_msg) = 0;
00192 
00202     virtual int join_multicast_group(const string& if_name,
00203                      const string& vif_name,
00204                      const IPvX& group,
00205                      string& error_msg) = 0;
00206 
00216     virtual int leave_multicast_group(const string& if_name,
00217                       const string& vif_name,
00218                       const IPvX& group,
00219                       string& error_msg) = 0;
00220 
00247     virtual int send_packet(const string&   if_name,
00248                 const string&   vif_name,
00249                 const IPvX&     src_address,
00250                 const IPvX&     dst_address,
00251                 int32_t     ip_ttl,
00252                 int32_t     ip_tos,
00253                 bool        ip_router_alert,
00254                 bool        ip_internet_control,
00255                 const vector<uint8_t>& ext_headers_type,
00256                 const vector<vector<uint8_t> >& ext_headers_payload,
00257                 const vector<uint8_t>& payload,
00258                 string&     error_msg) = 0;
00259 
00266     virtual XorpFd* mcast_protocol_fd_in() = 0;
00267 
00268 protected:
00291     virtual void recv_packet(const string&  if_name,
00292                  const string&  vif_name,
00293                  const IPvX&    src_address,
00294                  const IPvX&    dst_address,
00295                  int32_t        ip_ttl,
00296                  int32_t        ip_tos,
00297                  bool       ip_router_alert,
00298                  bool       ip_internet_control,
00299                  const vector<uint8_t>& ext_headers_type,
00300                  const vector<vector<uint8_t> >& ext_headers_payload,
00301                  const vector<uint8_t>& payload);
00302 
00311     virtual void recv_system_multicast_upcall(const vector<uint8_t>& payload);
00312 
00313     // Misc other state
00314     bool    _is_running;
00315 
00316 private:
00317     IoIpManager&    _io_ip_manager;     // The I/O IP manager
00318     FeaDataPlaneManager& _fea_data_plane_manager; // The data plane manager
00319     EventLoop&      _eventloop;     // The event loop to use
00320     const IfTree&   _iftree;        // The interface tree to use
00321     int         _family;        // The address family
00322     uint8_t     _ip_protocol;        // The protocol number (IPPROTO_*)
00323     IoIpReceiver*   _io_ip_receiver;    // The registered receiver
00324 };
00325 
00333 class IoIpReceiver {
00334 public:
00338     IoIpReceiver() {}
00339 
00343     virtual ~IoIpReceiver() {}
00344 
00367     virtual void recv_packet(const string&  if_name,
00368                  const string&  vif_name,
00369                  const IPvX&    src_address,
00370                  const IPvX&    dst_address,
00371                  int32_t        ip_ttl,
00372                  int32_t        ip_tos,
00373                  bool       ip_router_alert,
00374                  bool       ip_internet_control,
00375                  const vector<uint8_t>& ext_headers_type,
00376                  const vector<vector<uint8_t> >& ext_headers_payload,
00377                  const vector<uint8_t>& payload) = 0;
00378 
00387     virtual void recv_system_multicast_upcall(const vector<uint8_t>& payload) = 0;
00388 };
00389 
00390 #endif // __FEA_IO_IP_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations