xorp

policy_list.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/policy_list.hh,v 1.10 2008/10/02 21:57:59 bms Exp $
00022 
00023 #ifndef __POLICY_POLICY_LIST_HH__
00024 #define __POLICY_POLICY_LIST_HH__
00025 
00026 
00027 
00028 #include "code_list.hh"
00029 #include "set_map.hh"
00030 #include "var_map.hh"
00031 #include "policy_map.hh"
00032 #include "visitor_semantic.hh"
00033 
00045 class PolicyList :
00046     public NONCOPYABLE
00047 {
00048 public:
00049     typedef set<uint32_t> TagSet;
00050     typedef map<string,TagSet*> TagMap;
00051 
00052     enum PolicyType {
00053     IMPORT,
00054     EXPORT
00055     };
00056 
00064     PolicyList(const string& p, PolicyType pt, 
00065            PolicyMap& pmap,
00066            SetMap& smap, VarMap& vmap, string mod);
00067 
00068     ~PolicyList();
00069 
00075     void push_back(const string& policyname);
00076 
00086     void compile_policy(PolicyStatement& ps,
00087             Code::TargetSet& mod, 
00088             uint32_t& tagstart,
00089             map<string, set<uint32_t> >& ptags);
00090 
00099     void compile(Code::TargetSet& mod, uint32_t& tagstart, map<string, set<uint32_t> >& ptags);
00100    
00104     string str();
00105 
00114     void link_code(Code& ret);
00115 
00121     void get_targets(Code::TargetSet& targets);
00122 
00130     void get_redist_tags(const string& protocol, Code::TagSet& ts);
00131 
00132 private:
00133     typedef pair<string,CodeList*>  PolicyCode;
00134     typedef list<PolicyCode>        PolicyCodeList;
00135     typedef set<string>         POLICIES;
00136 
00145     void semantic_check(PolicyStatement& ps, VisitorSemantic::PolicyType type);
00146 
00154     void compile_import(PolicyCodeList::iterator& iter, PolicyStatement& ps,
00155             Code::TargetSet& modified_targets);
00156 
00165     void compile_export(PolicyCodeList::iterator& iter, PolicyStatement& ps,
00166             Code::TargetSet& modified_targets, uint32_t& tagstart,
00167             map<string, set<uint32_t> > & ptags);
00168 
00169     Term* create_mod(Term::BLOCKS block);
00170     void  add_policy_expression(const string& exp);
00171 
00172     string      _protocol;
00173     PolicyType      _type;
00174     PolicyCodeList  _policies;
00175     PolicyMap&      _pmap;
00176     SetMap&     _smap;
00177     VarMap&     _varmap;
00178     string      _mod;
00179     Term*       _mod_term;
00180     Term*       _mod_term_import;
00181     Term*       _mod_term_export;
00182     static uint32_t _pe;
00183     POLICIES        _pe_policies;
00184 };
00185 
00186 #endif // __POLICY_POLICY_LIST_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations