xorp

iv_exec.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/backend/iv_exec.hh,v 1.19 2008/10/02 21:58:04 bms Exp $
00022 
00023 #ifndef __POLICY_BACKEND_IV_EXEC_HH__
00024 #define __POLICY_BACKEND_IV_EXEC_HH__
00025 
00026 #include "libxorp/xorp.h"
00027 
00028 #include "policy/common/dispatcher.hh"
00029 #include "policy/common/varrw.hh"
00030 #include "policy/common/policy_exception.hh"
00031 #ifndef XORP_DISABLE_PROFILE
00032 #include "policy_profiler.hh"
00033 #endif
00034 
00035 #include "instruction.hh"
00036 #include "set_manager.hh"
00037 #include "term_instr.hh"
00038 #include "policy_instr.hh"
00039 #include "policy_backend_parser.hh"
00040 
00047 class IvExec :
00048     public NONCOPYABLE,
00049     public InstrVisitor
00050 {
00051 public:
00057     enum FlowAction {
00058     ACCEPT,
00059     REJ,
00060     DEFAULT
00061     };
00062 
00068     class RuntimeError : public PolicyException {
00069     public:
00070     RuntimeError(const char* file, size_t line, const string& init_why = "")
00071         : PolicyException("RuntimeError", file, line, init_why) {}  
00072     };
00073 
00074     IvExec();
00075     ~IvExec();
00076    
00077     void set_policies(vector<PolicyInstr*>* policies);
00078     void set_set_manager(SetManager* sman);
00079    
00083     FlowAction run(VarRW* varrw);
00084 
00090     FlowAction runPolicy(PolicyInstr& pi);
00091 
00097     FlowAction runTerm(TermInstr& ti);
00098 
00102     void visit(Push& p);
00103 
00107     void visit(PushSet& ps);
00108     
00112     void visit(OnFalseExit& x);
00113 
00117     void visit(Load& l);
00118 
00122     void visit(Store& s);
00123 
00127     void visit(Accept& a);
00128     
00132     void visit(Reject& r);
00133 
00137     void visit(NaryInstr& nary);
00138 
00139     void visit(Next& next);
00140     void visit(Subr& sub);
00141 
00146     static string fa2str(const FlowAction& fa);
00147 
00148 #ifndef XORP_DISABLE_PROFILE
00149     void    set_profiler(PolicyProfiler*);
00150 #endif
00151     string  tracelog();
00152     void    set_subr(SUBR* subr);
00153 
00154 private:
00158     void clear_trash();
00159 
00160     PolicyInstr**   _policies;
00161     unsigned        _policy_count;
00162     const Element** _stack_bottom;
00163     const Element** _stack;
00164     const Element** _stackend;
00165     const Element** _stackptr;
00166     SetManager*     _sman;
00167     VarRW*      _varrw;
00168     bool        _finished;
00169     Dispatcher      _disp;
00170     FlowAction      _fa;
00171     Element**       _trash;
00172     unsigned        _trashc;
00173     unsigned        _trashs;
00174     ostringstream   _os;
00175 #ifndef XORP_DISABLE_PROFILE
00176     PolicyProfiler* _profiler;
00177 #endif
00178     bool        _do_trace;
00179     bool        _did_trace;
00180     Next::Flow      _ctr_flow;
00181     SUBR*       _subr;
00182 };
00183 
00184 #endif // __POLICY_BACKEND_IV_EXEC_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations