xorp

xrl_io.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8 sw=4:
00003 
00004 // Copyright (c) 2001-2009 XORP, Inc.
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License, Version 2, June
00008 // 1991 as published by the Free Software Foundation. Redistribution
00009 // and/or modification of this program under the terms of any other
00010 // version of the GNU General Public License is not permitted.
00011 // 
00012 // This program is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00015 // see the GNU General Public License, Version 2, a copy of which can be
00016 // found in the XORP LICENSE.gpl file.
00017 // 
00018 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00019 // http://xorp.net
00020 
00021 // $XORP: xorp/contrib/olsr/xrl_io.hh,v 1.3 2008/10/02 21:56:36 bms Exp $
00022 
00023 #ifndef __OLSR_XRL_IO_HH__
00024 #define __OLSR_XRL_IO_HH__
00025 
00026 #include "libxipc/xrl_router.hh"
00027 
00028 #include "libfeaclient/ifmgr_xrl_mirror.hh"
00029 #include "policy/backend/policytags.hh"
00030 
00031 #include "io.hh"
00032 #include "xrl_queue.hh"
00033 
00034 class EventLoop;
00035 class XrlPort;
00036 
00037 typedef list<XrlPort*>          XrlPortList;
00038 typedef map<ServiceBase*, XrlPort*> XrlDeadPortMap;
00039 
00043 class XrlIO : public IO,
00044           public IfMgrHintObserver,
00045           public ServiceChangeObserverBase {
00046  public:
00047 
00056     XrlIO(EventLoop& eventloop, XrlRouter& xrl_router,
00057       const string& feaname, const string& ribname);
00058 
00062     ~XrlIO();
00063 
00069     int startup();
00070 
00076     int shutdown();
00077 
00083     void component_up(string name);
00084 
00090     void component_down(string name);
00091 
00102     void receive(const string& sockid,
00103     const string& interface, const string& vif,
00104     const IPv4& src, const uint16_t& sport,
00105     const vector<uint8_t>& payload);
00106 
00121     bool send(const string& interface, const string& vif,
00122     const IPv4& src, const uint16_t& sport,
00123     const IPv4& dst, const uint16_t& dport,
00124     uint8_t* data, const uint32_t& len);
00125 
00135     bool enable_interface_vif(const string& interface, const string& vif);
00136 
00146     bool disable_interface_vif(const string& interface, const string& vif);
00147 
00159     bool enable_address(const string& interface, const string& vif,
00160     const IPv4& address, const uint16_t& port,
00161     const IPv4& all_nodes_address);
00162 
00172     bool disable_address(const string& interface, const string& vif,
00173     const IPv4& address, const uint16_t& port);
00174 
00181     bool is_interface_enabled(const string& interface) const;
00182 
00190     bool is_vif_enabled(const string& interface, const string& vif) const;
00191 
00199     bool is_vif_broadcast_capable(const string& interface,
00200     const string& vif);
00201 
00209     bool is_vif_multicast_capable(const string& interface,
00210     const string& vif);
00211 
00215     bool is_vif_loopback(const string& interface, const string& vif);
00216 
00225     bool is_address_enabled(const string& interface, const string& vif,
00226                 const IPv4& address) const;
00227 
00237     bool get_addresses(const string& interface, const string& vif,
00238                list<IPv4>& addresses) const;
00239 
00249     bool get_broadcast_address(const string& interface,
00250     const string& vif, IPv4& address) const;
00251 
00261     bool get_broadcast_address(const string& interface,
00262                    const string& vif,
00263                    const IPv4& address,
00264                    IPv4& bcast_address) const;
00265 
00273     bool get_interface_id(const string& interface, uint32_t& interface_id);
00274 
00283     uint32_t get_prefix_length(const string& interface, const string& vif,
00284                     IPv4 address);
00285 
00292     uint32_t get_mtu(const string& interface);
00293 
00297     void register_rib();
00298 
00302     void unregister_rib();
00303 
00312     void rib_command_done(const XrlError& error, bool up,
00313               const char *comment);
00314 
00326     bool add_route(IPv4Net net,
00327            IPv4 nexthop,
00328            uint32_t nexthop_id,
00329            uint32_t metric,
00330            const PolicyTags& policytags);
00331 
00343     bool replace_route(IPv4Net net,
00344                IPv4 nexthop,
00345                uint32_t nexthop_id,
00346                uint32_t metric,
00347                const PolicyTags& policytags);
00348 
00356     bool delete_route(IPv4Net net);
00357 
00358 private:
00366     void status_change(ServiceBase* service,
00367                ServiceStatus    old_status,
00368                ServiceStatus    new_status);
00369 
00373     const ServiceBase* ifmgr_mirror_service_base() const {
00374     return dynamic_cast<const ServiceBase*>(&_ifmgr);
00375     }
00376 
00380     const IfMgrIfTree& ifmgr_iftree() const { return _ifmgr.iftree(); }
00381 
00386     void tree_complete();
00387 
00392     void updates_made();
00393 
00400     void send_cb(const XrlError& xrl_error);
00401 
00407     XrlPort* find_port(const string&    ifname,
00408                const string&    vifname,
00409                const IPv4&  addr);
00415     const XrlPort* find_port(const string&  ifname,
00416                  const string&  vifname,
00417                  const IPv4&    addr) const;
00418 
00422     inline XrlPortList& ports() { return _ports; }
00423 
00427     inline const XrlPortList& ports() const { return _ports; }
00428 
00432     void try_start_next_port();
00433 
00434 private:
00435     EventLoop&      _eventloop;
00436     XrlRouter&      _xrl_router;
00437     string      _feaname;
00438     string      _ribname;
00439     uint32_t        _component_count;
00440 
00444     IfMgrXrlMirror  _ifmgr;
00445 
00449     IfMgrIfTree     _iftree;
00450 
00454     XrlQueue        _rib_queue;
00455 
00459     XrlPortList     _ports;
00460 
00464     XrlDeadPortMap  _dead_ports;
00465 };
00466 
00467 #endif // __OLSR_XRL_IO_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations