xorp

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-2011 XORP, Inc and Others
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/io.hh,v 1.3 2008/10/02 21:56:34 bms Exp $
00022 
00023 #ifndef __OLSR_IO_HH__
00024 #define __OLSR_IO_HH__
00025 
00033 class IO : public ServiceBase {
00034   public:
00035     IO() {}
00036     virtual ~IO() {}
00037 
00049     virtual bool enable_address(const string& interface, const string& vif,
00050     const IPv4& address, const uint16_t& port,
00051     const IPv4& all_nodes_address) = 0;
00052 
00062     virtual bool disable_address(const string& interface, const string& vif,
00063     const IPv4& address, const uint16_t& port) = 0;
00064 
00071     virtual bool is_interface_enabled(const string& interface) const = 0;
00072 
00080     virtual bool is_vif_enabled(const string& interface,
00081     const string& vif) const = 0;
00082 
00090     virtual bool is_vif_broadcast_capable(const string& interface,
00091     const string& vif) = 0;
00092 
00100     virtual bool is_vif_multicast_capable(const string& interface,
00101     const string& vif) = 0;
00102 
00110     virtual bool is_vif_loopback(const string& interface,
00111     const string& vif) = 0;
00112 
00121     virtual bool is_address_enabled(const string& interface,
00122     const string& vif, const IPv4& address) const = 0;
00123 
00127     typedef  XorpCallback2<void, const string&,
00128                    bool>::RefPtr InterfaceStatusCb;
00129 
00133     typedef  XorpCallback3<void, const string&, const string&,
00134                    bool>::RefPtr VifStatusCb;
00135 
00139     typedef  XorpCallback4<void, const string&, const string&, IPv4,
00140                    bool>::RefPtr AddressStatusCb;
00141 
00145     typedef XorpCallback8<void, const string&, const string&,
00146                    IPv4, uint16_t, IPv4, uint16_t,
00147                    uint8_t*,
00148                    uint32_t>::RefPtr ReceiveCallback;
00149 
00158     virtual bool get_addresses(const string& interface, const string& vif,
00159     list<IPv4>& addresses) const = 0;
00160 
00170     virtual bool get_broadcast_address(const string& interface,
00171                        const string& vif,
00172                        const IPv4& address,
00173                        IPv4& bcast_address) const = 0;
00174 
00182     virtual bool get_interface_id(const string& interface,
00183     uint32_t& interface_id) = 0;
00184 
00191     virtual uint32_t get_mtu(const string& interface) = 0;
00192 
00201     inline void register_interface_status(InterfaceStatusCb cb) {
00202     _interface_status_cb = cb;
00203     };
00204 
00213     inline void register_vif_status(VifStatusCb cb) {
00214     _vif_status_cb = cb;
00215     };
00216 
00226     inline void register_address_status(AddressStatusCb cb) {
00227     _address_status_cb = cb;
00228     };
00229 
00235     inline void register_receive(ReceiveCallback cb) { _receive_cb = cb; };
00236 
00237   protected:
00238     ReceiveCallback _receive_cb;
00239     InterfaceStatusCb   _interface_status_cb;
00240     VifStatusCb     _vif_status_cb;
00241     AddressStatusCb _address_status_cb;
00242 
00243   public:
00244     struct interface_vif {
00245         string _interface_name;
00246         string _vif_name;
00247     };
00248 
00263     virtual bool send(const string& interface, const string& vif,
00264     const IPv4& src, const uint16_t& sport,
00265     const IPv4& dst, const uint16_t& dport,
00266     uint8_t* data, const uint32_t& len) = 0;
00267 
00278     virtual bool add_route(IPv4Net net, IPv4 nexthop, uint32_t faceid,
00279                uint32_t metric,
00280                const PolicyTags& policytags) = 0;
00281 
00292     virtual bool replace_route(IPv4Net net, IPv4 nexthop, uint32_t faceid,
00293                    uint32_t metric,
00294                    const PolicyTags& policytags) = 0;
00295 
00302     virtual bool delete_route(IPv4Net net) = 0;
00303 
00312     inline void set_interface_mapping(uint32_t interface_id,
00313     const string& interface, const string& vif) {
00314     interface_vif iv;
00315 
00316     iv._interface_name = interface;
00317     iv._vif_name = vif;
00318 
00319     _interface_vif[interface_id] = iv;
00320     };
00321 
00330     inline bool get_interface_vif_by_interface_id(uint32_t interface_id,
00331     string& interface, string& vif) {
00332     if (_interface_vif.find(interface_id) == _interface_vif.end())
00333         return false;
00334 
00335     interface_vif iv = _interface_vif[interface_id];
00336     interface = iv._interface_name;
00337     vif = iv._vif_name;
00338     return true;
00339     };
00340 
00341   protected:
00342     map<uint32_t, interface_vif> _interface_vif;
00343 };
00344 
00345 #endif // __OLSR_IO_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations