xorp

filter_manager.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/policy/filter_manager.hh,v 1.10 2008/10/02 21:57:58 bms Exp $
00022 
00023 #ifndef __POLICY_FILTER_MANAGER_HH__
00024 #define __POLICY_FILTER_MANAGER_HH__
00025 
00026 #include "policy/common/policy_exception.hh"
00027 #include "policy/common/filter.hh"
00028 #include "xrl/interfaces/policy_backend_xif.hh"
00029 #include "xrl/interfaces/rib_xif.hh"
00030 #include "libxorp/eventloop.hh"
00031 #include "code.hh"
00032 #include "set_map.hh"
00033 #include "process_watch.hh"
00034 #include "filter_manager_base.hh"
00035 #include "pw_notifier.hh"
00036 #include "protocol_map.hh"
00037 
00038 
00048 class FilterManager : public FilterManagerBase, public PWNotifier {
00049 public:
00050     // XXX: pull this out ?
00051     typedef map<string,Code*> CodeMap;
00052     typedef map<string,string> ConfQueue;
00053     typedef set<uint32_t> TagSet;
00054     typedef map<string,TagSet*> TagMap;
00055 
00059     class FMException : public PolicyException {
00060     public:
00061         FMException(const char* file, size_t line, const string& init_why = "")
00062             : PolicyException("FMException", file, line, init_why) {}  
00063     };
00064 
00079     FilterManager(const CodeMap& imp, const CodeMap& sm, 
00080           const CodeMap& exp, const SetMap& sets, 
00081           const TagMap& tagmap, XrlStdRouter& rtr, 
00082           ProcessWatch& pw,
00083           ProtocolMap& pmap);
00084 
00091     void update_filter(const Code::Target& t);
00092 
00098     void policy_backend_cb(const XrlError& e);
00099 
00103      void push_routes_now();
00104 
00108     void flush_updates_now();
00109 
00118     void flush_updates(uint32_t msec);
00119 
00120     // PWNotifier interface:
00126     void birth(const string& protocol);
00127 
00133     void death(const string& protocol);
00134 
00135 private:
00141     void update_import_filter(const string& protocol);
00142     
00148     void update_sourcematch_filter(const string& protocol);
00149     
00155     void update_export_filter(const string& protocol);
00156 
00162     void update_tagmap(const string& protocol);
00163 
00168     void flush_export_queue();
00169 
00177     void flush_queue(ConfQueue& queue, filter::Filter f);
00178 
00179     void delete_queue_protocol(ConfQueue& queue, const string& protocol);
00180 
00181     void update_queue(const string& protocol, const CodeMap& cm, 
00182               ConfQueue& queue);
00183 
00184     const CodeMap& _import;
00185     const CodeMap& _sourcematch;
00186     const CodeMap& _export;
00187     const SetMap& _sets;
00188     const TagMap& _tagmap;
00189 
00190     ConfQueue _import_queue;
00191     ConfQueue _sourcematch_queue;
00192     ConfQueue _export_queue;
00193     set<string> _push_queue;
00194 
00195     EventLoop& _eventloop;
00196 
00197     // we should have a timer per protocol.
00198     XorpTimer _flush_timer;
00199     XorpTimer _push_timer;
00200     unsigned _push_timeout;
00201     
00202     ProcessWatch& _process_watch;
00203 
00204     XrlPolicyBackendV0p1Client _policy_backend;
00205     XrlRibV0p1Client _rib;
00206 
00207     string _rib_name;
00208     ProtocolMap& _pmap;
00209 };
00210 
00211 #endif // __POLICY_FILTER_MANAGER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations