xorp

system.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-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/rip/system.hh,v 1.16 2008/10/29 21:59:39 andrewma Exp $
00022 
00023 #ifndef __RIP_SYSTEM_HH__
00024 #define __RIP_SYSTEM_HH__
00025 
00026 
00027 
00028 
00029 #include "trace.hh"
00030 #include "route_db.hh"
00031 #include "port_manager.hh"
00032 
00033 #include "policy/backend/policy_filters.hh"
00034 
00038 template <typename A>
00039 class System :
00040     public NONCOPYABLE
00041 {
00042 public:
00043     typedef RouteDB<A>      RouteDatabase;
00044     typedef PortManagerBase<A>  PortManager;
00045 
00046 public:
00047     System(EventLoop& e) : _e(e), _rtdb(e,_policy_filters), _pm(0) {}
00048     ~System();
00049 
00054     EventLoop& eventloop()          { return _e; }
00055 
00060     const EventLoop& eventloop() const      { return _e; }
00061 
00066     RouteDatabase& route_db()           { return _rtdb; }
00067 
00072     const RouteDatabase& route_db() const   { return _rtdb; }
00073 
00082     bool set_port_manager(PortManager* pm);
00083 
00087     PortManager* port_manager()         { return _pm; }
00088 
00092     const PortManager* port_manager() const { return _pm; }
00093 
00100     void configure_filter(const uint32_t& filter, const string& conf) {
00101     _policy_filters.configure(filter,conf);
00102     }
00103 
00109     void reset_filter(const uint32_t& filter) {
00110     _policy_filters.reset(filter);
00111     }
00112 
00116     void push_routes() {
00117     _rtdb.push_routes();
00118     }
00119 
00123     PolicyFilters& policy_filters() { return _policy_filters; }
00124 
00125     Trace& route_trace() { return _rtdb.trace(); }
00126 
00127 protected:
00128     EventLoop&      _e;
00129 
00130     //
00131     // There should be only one instatiation per process.
00132     // RIP uses separate processes for IPv4 and IPv6 so we are ok.
00133     //
00134     PolicyFilters   _policy_filters;
00135 
00136     RouteDatabase   _rtdb;
00137     PortManager*    _pm;
00138 };
00139 
00140 // ----------------------------------------------------------------------------
00141 // Inline System methods
00142 //
00143 
00144 template <typename A>
00145 bool
00146 System<A>::set_port_manager(PortManager* pm)
00147 {
00148     if (pm != 0 && _pm == 0) {
00149     _pm = pm;
00150     return true;
00151     }
00152     return false;
00153 }
00154 
00155 template <typename A>
00156 System<A>::~System()
00157 {
00158     _rtdb.flush_routes();
00159 }
00160 
00161 #endif // __RIP_SYSTEM_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations