|
xorp
|
00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*- 00002 00003 // Copyright (c) 2001-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/rip/xrl_port_manager.hh,v 1.22 2008/10/30 00:30:54 pavlin Exp $ 00021 00022 #ifndef __RIP_XRL_PORT_MANAGER_HH__ 00023 #define __RIP_XRL_PORT_MANAGER_HH__ 00024 00025 00026 00027 #include "libxorp/service.hh" 00028 #include "libfeaclient/ifmgr_xrl_mirror.hh" 00029 #include "port_manager.hh" 00030 00031 #include "port.hh" 00032 #include "trace.hh" 00033 00034 class XrlRouter; 00035 00047 template <typename A> 00048 class XrlPortManager : 00049 public NONCOPYABLE, 00050 public PortManagerBase<A>, 00051 public IfMgrHintObserver, 00052 public ServiceBase, 00053 public ServiceChangeObserverBase 00054 { 00055 public: 00056 XrlPortManager(System<A>& system, 00057 XrlRouter& xr, 00058 IfMgrXrlMirror& ifm) 00059 : PortManagerBase<A>(system, ifm.iftree()), 00060 ServiceBase("RIP Port Manager"), 00061 _xr(xr), _ifm(ifm) 00062 { 00063 _ifm.attach_hint_observer(this); 00064 } 00065 00066 ~XrlPortManager(); 00067 00073 int startup(); 00074 00080 int shutdown(); 00081 00095 bool add_rip_address(const string& ifname, 00096 const string& vifname, 00097 const A& addr); 00098 00109 bool remove_rip_address(const string& ifname, 00110 const string& vifname, 00111 const A& addr); 00112 00129 bool deliver_packet(const string& sockid, 00130 const string& ifname, 00131 const string& vifname, 00132 const A& src_addr, 00133 uint16_t src_port, 00134 const vector<uint8_t>& pdata); 00135 00141 Port<A>* find_port(const string& ifname, 00142 const string& vifname, 00143 const A& addr); 00149 const Port<A>* find_port(const string& ifname, 00150 const string& vifname, 00151 const A& addr) const; 00152 00160 bool underlying_rip_address_up(const string& ifname, 00161 const string& vifname, 00162 const A& addr) const; 00163 00171 bool underlying_rip_address_exists(const string& ifname, 00172 const string& vifname, 00173 const A& addr) const; 00174 00175 Trace& packet_trace() { return _trace; } 00176 protected: 00177 // 00178 // IfMgrHintObserver methods 00179 // 00180 void tree_complete(); 00181 void updates_made(); 00182 00183 // 00184 // ServiceChangeObserverBase methods 00185 // - used for observing status changes of XrlPortIO objects instantiated 00186 // by XrlPortManager instance. 00187 // 00188 void status_change(ServiceBase* service, 00189 ServiceStatus old_status, 00190 ServiceStatus new_status); 00191 00192 // 00193 // Attempt to start next io handler. Walk list of ports, check 00194 // none are in state SERVICE_STARTING and call start on first found to be 00195 // in state SERVICE_READY. 00196 // 00197 // We start 1 at a time to avoid races trying to create 00198 // sockets with the fea. 00199 // 00200 void try_start_next_io_handler(); 00201 00202 protected: 00203 XrlRouter& _xr; // XrlRouter 00204 IfMgrXrlMirror& _ifm; // Interface Mirror 00205 map<ServiceBase*, Port<A>*> _dead_ports; // Ports awaiting io shutdown 00206 00207 private: 00208 Trace _trace; 00209 }; 00210 00211 #endif // __RIP_XRL_PORT_MANAGER_HH__