|
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/fea/ifconfig_reporter.hh,v 1.9 2008/10/02 21:56:47 bms Exp $ 00021 00022 #ifndef __FEA_IFCONFIG_REPORTER_HH__ 00023 #define __FEA_IFCONFIG_REPORTER_HH__ 00024 00025 00026 // 00027 // Mechanism for reporting network interface related information to 00028 // interested parties. 00029 // 00030 00031 00032 00033 class IfConfigUpdateReplicator; 00034 class IfTree; 00035 class IPv4; 00036 #ifdef HAVE_IPV6 00037 class IPv6; 00038 #endif 00039 00046 class IfConfigUpdateReporterBase { 00047 public: 00048 enum Update { CREATED, DELETED, CHANGED }; 00049 00056 IfConfigUpdateReporterBase(IfConfigUpdateReplicator& update_replicator); 00057 00065 IfConfigUpdateReporterBase(IfConfigUpdateReplicator& update_replicator, 00066 const IfTree& observed_iftree); 00067 00071 virtual ~IfConfigUpdateReporterBase() {} 00072 00078 const IfTree& observed_iftree() const { return (_observed_iftree); } 00079 00083 void add_to_replicator(); 00084 00088 void remove_from_replicator(); 00089 00090 virtual void interface_update(const string& ifname, 00091 const Update& u) = 0; 00092 00093 virtual void vif_update(const string& ifname, 00094 const string& vifname, 00095 const Update& u) = 0; 00096 00097 virtual void vifaddr4_update(const string& ifname, 00098 const string& vifname, 00099 const IPv4& addr, 00100 const Update& u) = 0; 00101 00102 #ifdef HAVE_IPV6 00103 virtual void vifaddr6_update(const string& ifname, 00104 const string& vifname, 00105 const IPv6& addr, 00106 const Update& u) = 0; 00107 #endif 00108 00109 virtual void updates_completed() = 0; 00110 00111 private: 00112 IfConfigUpdateReplicator& _update_replicator; 00113 const IfTree& _observed_iftree; 00114 }; 00115 00119 class IfConfigUpdateReplicator : public IfConfigUpdateReporterBase { 00120 public: 00121 typedef IfConfigUpdateReporterBase::Update Update; 00122 00123 public: 00124 IfConfigUpdateReplicator(const IfTree& observed_iftree) 00125 : IfConfigUpdateReporterBase(*this, observed_iftree) 00126 {} 00127 virtual ~IfConfigUpdateReplicator(); 00128 00134 int add_reporter(IfConfigUpdateReporterBase* rp); 00135 00141 int remove_reporter(IfConfigUpdateReporterBase* rp); 00142 00147 void interface_update(const string& ifname, 00148 const Update& u); 00149 00154 void vif_update(const string& ifname, 00155 const string& vifname, 00156 const Update& u); 00157 00162 void vifaddr4_update(const string& ifname, 00163 const string& vifname, 00164 const IPv4& addr, 00165 const Update& u); 00166 00167 #ifdef HAVE_IPV6 00168 00172 void vifaddr6_update(const string& ifname, 00173 const string& vifname, 00174 const IPv6& addr, 00175 const Update& u); 00176 #endif 00177 00182 void updates_completed(); 00183 00184 protected: 00185 list<IfConfigUpdateReporterBase*> _reporters; 00186 }; 00187 00195 class IfConfigErrorReporterBase { 00196 public: 00197 IfConfigErrorReporterBase() : _error_cnt(0) {} 00198 virtual ~IfConfigErrorReporterBase() {} 00199 00200 virtual void config_error(const string& error_msg) = 0; 00201 00202 virtual void interface_error(const string& ifname, 00203 const string& error_msg) = 0; 00204 00205 virtual void vif_error(const string& ifname, 00206 const string& vifname, 00207 const string& error_msg) = 0; 00208 00209 virtual void vifaddr_error(const string& ifname, 00210 const string& vifname, 00211 const IPv4& addr, 00212 const string& error_msg) = 0; 00213 00214 #ifdef HAVE_IPV6 00215 virtual void vifaddr_error(const string& ifname, 00216 const string& vifname, 00217 const IPv6& addr, 00218 const string& error_msg) = 0; 00219 #endif 00220 00224 const string& first_error() const { return _first_error; } 00225 00229 const string& last_error() const { return _last_error; } 00230 00234 uint32_t error_count() const { return _error_cnt; } 00235 00239 void reset() { 00240 _first_error.erase(); 00241 _last_error.erase(); 00242 _error_cnt = 0; 00243 } 00244 00245 void log_error(const string& s) { 00246 if (0 == _error_cnt) 00247 _first_error = s; 00248 _last_error = s; 00249 _error_cnt++; 00250 } 00251 00252 private: 00253 string _last_error; // last error reported 00254 string _first_error; // first error reported 00255 00256 uint32_t _error_cnt; // number of errors reported 00257 }; 00258 00263 class IfConfigErrorReporter : public IfConfigErrorReporterBase { 00264 public: 00265 IfConfigErrorReporter(); 00266 00267 void config_error(const string& error_msg); 00268 00269 void interface_error(const string& ifname, 00270 const string& error_msg); 00271 00272 void vif_error(const string& ifname, 00273 const string& vifname, 00274 const string& error_msg); 00275 00276 void vifaddr_error(const string& ifname, 00277 const string& vifname, 00278 const IPv4& addr, 00279 const string& error_msg); 00280 00281 #ifdef HAVE_IPV6 00282 void vifaddr_error(const string& ifname, 00283 const string& vifname, 00284 const IPv6& addr, 00285 const string& error_msg); 00286 #endif 00287 00288 private: 00289 }; 00290 00291 #endif // __FEA_IFCONFIG_REPORTER_HH__