xorp

xrl_port.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/xrl_port.hh,v 1.3 2008/10/02 21:56:37 bms Exp $
00022 
00023 #ifndef __OLSR_XRL_PORT_HH__
00024 #define __OLSR_XRL_PORT_HH__
00025 
00026 
00027 #include "libxorp/ipv4.hh"
00028 #include "libxorp/safe_callback_obj.hh"
00029 #include "libxorp/service.hh"
00030 
00031 class XrlError;
00032 class XrlRouter;
00033 
00041 class XrlPort : public ServiceBase,
00042         public CallbackSafeObject {
00043 public:
00058     XrlPort(IO* io,
00059         EventLoop& eventloop,
00060         XrlRouter& xrl_router,
00061         const string& ssname,
00062         const string& ifname,
00063         const string& vifname,
00064         const IPv4& local_addr,
00065         const uint16_t local_port,
00066         const IPv4& all_nodes_addr);
00067 
00068     ~XrlPort();
00069 
00080     int startup();
00081 
00091     int shutdown();
00092 
00104     bool send_to(const IPv4& dst_addr,
00105              const uint16_t dst_port,
00106              const vector<uint8_t>& payload);
00107 
00111     inline string socket_server() const { return _ss; }
00112 
00116     inline string ifname() const { return _ifname; }
00117 
00121     inline string vifname() const { return _vifname; }
00122 
00126     inline IPv4 local_address() const { return _local_addr; }
00127 
00131     inline uint16_t local_port() const { return _local_port; }
00132 
00137     inline string sockid() const { return _sockid; }
00138 
00142     inline IPv4 all_nodes_address() const { return _all_nodes_addr; }
00143 
00144 private:
00145     bool startup_socket();
00146 
00147     //
00148     // Socket open operations.
00149     //
00150     bool request_udp_open_bind_broadcast();
00151     void udp_open_bind_broadcast_cb(const XrlError& e, const string* psid);
00152 
00153     bool request_tos();
00154     void tos_cb(const XrlError& xrl_error);
00155 
00156     void socket_setup_complete();
00157 
00158     //
00159     // BSD hack.
00160     //
00161     bool request_reuseport();
00162     void reuseport_cb(const XrlError& e);
00163 
00164     bool request_onesbcast(const bool enabled);
00165     void onesbcast_cb(const XrlError& e);
00166 
00167     //
00168     // Socket close operations.
00169     //
00170 
00171     bool request_close();
00172     void close_cb(const XrlError& xrl_error);
00173 
00174     //
00175     // Socket send operations.
00176     //
00177 
00178     void send_cb(const XrlError& xrl_error);
00179 
00180 private:
00181     IO*         _io;
00182     EventLoop&      _eventloop;
00183     XrlRouter&      _xrl_router;
00184 
00185     string      _ss;
00186     string      _ifname;
00187     string      _vifname;
00188     IPv4        _local_addr;
00189     uint16_t        _local_port;
00190     IPv4        _all_nodes_addr;
00191 
00192     /* If true, system is initializing and cannot send normal packets with send_to */
00193     bool        _pending;
00194 
00195     string      _sockid;
00196 
00197     bool        _is_undirected_broadcast;
00198 };
00199 
00200 #endif // __OLSR_XRL_PORT_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations