xorp

io.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
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/ospf/io.hh,v 1.31 2008/11/14 12:44:19 bms Exp $
00022 
00023 #ifndef __OSPF_IO_HH__
00024 #define __OSPF_IO_HH__
00025 
00031 template <typename A>
00032 class IO : public ServiceBase {
00033  public:
00034     IO() : _ip_router_alert(false)
00035     {}
00036 
00037     virtual ~IO() {}
00038 
00042     uint16_t get_ip_protocol_number() const {
00043     return OspfTypes::IP_PROTOCOL_NUMBER;
00044     }
00045 
00049     virtual bool send(const string& interface, const string& vif,
00050               A dst, A src,
00051               int ttl, uint8_t* data, uint32_t len) = 0;
00052 
00056     bool set_ip_router_alert(bool alert) {
00057     _ip_router_alert = alert;
00058 
00059     return true;
00060     }
00061 
00065     bool get_ip_router_alert() const { return _ip_router_alert; }
00066 
00067     typedef typename XorpCallback6<void, const string&, const string&,
00068                    A, A,
00069                    uint8_t*,
00070                    uint32_t>::RefPtr ReceiveCallback;
00074     void register_receive(ReceiveCallback cb) { _receive_cb = cb; }
00075 
00079     virtual bool enable_interface_vif(const string& interface,
00080                       const string& vif) = 0;
00081 
00085     virtual bool disable_interface_vif(const string& interface,
00086                        const string& vif) = 0;
00087 
00093     virtual bool is_interface_enabled(const string& interface) const = 0;
00094 
00100     virtual bool is_vif_enabled(const string& interface,
00101                 const string& vif) const = 0;
00102 
00108     virtual bool is_address_enabled(const string& interface, const string& vif,
00109                     const A& address) const = 0;
00110 
00111     typedef typename XorpCallback2<void, const string&,
00112                    bool>::RefPtr InterfaceStatusCb;
00113     typedef typename XorpCallback3<void, const string&, const string&,
00114                    bool>::RefPtr VifStatusCb;
00115     typedef typename XorpCallback4<void, const string&, const string&, A,
00116                    bool>::RefPtr AddressStatusCb;
00117 
00126     void register_interface_status(InterfaceStatusCb cb) {
00127     _interface_status_cb = cb;
00128     }
00129 
00138     void register_vif_status(VifStatusCb cb) {
00139     _vif_status_cb = cb;
00140     }
00141 
00151     void register_address_status(AddressStatusCb cb) {
00152     _address_status_cb = cb;
00153     }
00154 
00164     virtual bool get_addresses(const string& interface,
00165                    const string& vif,
00166                    list<A>& addresses) const = 0;
00167 
00177     virtual bool get_link_local_address(const string& interface,
00178                     const string& vif,
00179                     A& address) = 0;
00180 
00184     virtual bool get_interface_id(const string& interface,
00185                   uint32_t& interface_id) = 0;
00189     virtual uint32_t get_prefix_length(const string& interface,
00190                        const string& vif,
00191                        A address) = 0;
00192 
00196     virtual uint32_t get_mtu(const string& interface) = 0;
00197 
00201     virtual bool join_multicast_group(const string& interface,
00202                       const string& vif, A mcast) = 0;
00203     
00204 
00208     virtual bool leave_multicast_group(const string& interface,
00209                        const string& vif, A mcast) = 0;
00210 
00222     virtual bool add_route(IPNet<A> net,
00223                A nexthop,
00224                uint32_t nexthop_id,
00225                uint32_t metric,
00226                bool equal,
00227                bool discard, const PolicyTags& policytags) = 0;
00228 
00240     virtual bool replace_route(IPNet<A> net,
00241                    A nexthop,
00242                    uint32_t nexthop_id,
00243                    uint32_t metric,
00244                    bool equal,
00245                    bool discard, const PolicyTags& policytags) = 0;
00246 
00250     virtual bool delete_route(IPNet<A> net) = 0;
00251 
00256     void set_interface_mapping(uint32_t interface_id, const string& interface,
00257                    const string& vif) {
00258     interface_vif iv;
00259     iv._interface_name = interface;
00260     iv._vif_name = vif;
00261 
00262     _interface_vif[interface_id] = iv;
00263     }
00264 
00268     bool get_interface_vif_by_interface_id(uint32_t interface_id,
00269                        string& interface, string& vif) {
00270     if (0 == _interface_vif.count(interface_id))
00271         return false;
00272 
00273     interface_vif iv = _interface_vif[interface_id];
00274 
00275     interface = iv._interface_name;
00276     vif = iv._vif_name;
00277 
00278     return true;
00279     }
00280 
00281  protected:
00282     ReceiveCallback _receive_cb;
00283     InterfaceStatusCb   _interface_status_cb;
00284     VifStatusCb     _vif_status_cb;
00285     AddressStatusCb _address_status_cb;
00286     bool _ip_router_alert;
00287 
00288     struct interface_vif {
00289     string _interface_name;
00290     string _vif_name;
00291     };
00292 
00293     map<uint32_t, interface_vif> _interface_vif;
00294 };
00295 #endif // __OSPF_IO_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations