xorp

code.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/code.hh,v 1.13 2008/10/02 21:57:57 bms Exp $
00022 
00023 #ifndef __POLICY_CODE_HH__
00024 #define __POLICY_CODE_HH__
00025 
00026 
00027 
00028 
00029 
00030 #include "policy/common/filter.hh"
00031 
00032 typedef map<string, string>    SUBR; // XXX string* would be better...
00033 
00040 class Code {
00041 public:
00048     class Target {
00049     public:
00053     Target() {}
00054 
00061     Target(const string& p, filter::Filter f) : _protocol(p), _filter(f) {}
00062 
00069     bool operator<(const Target& rhs) const;
00070 
00071     bool operator==(const Target& rhs) const;
00072     bool operator!=(const Target& rhs) const;
00073 
00079     const string protocol() const { return _protocol; }
00080 
00086     void set_protocol(const string& protocol) { _protocol = protocol; }
00087 
00093     filter::Filter filter() const { return _filter; }
00094 
00100     void set_filter(const filter::Filter& filter) { _filter = filter; }
00101 
00105     string str() const;
00106 
00107     private:
00108     string      _protocol;
00109     filter::Filter  _filter;
00110     };
00111 
00112     typedef set<Target> TargetSet;
00113 
00114     // if it is export filter code, these are the tags used by the code.
00115     typedef set<uint32_t> TagSet;
00116 
00122     const Code::Target& target() const { return _target; }
00123 
00129     void set_target(const Code::Target target) { _target = target; }
00130 
00136     void set_target_protocol(const string& protocol);
00137 
00143     void set_target_filter(const filter::Filter& filter);
00144 
00150     const string& code() const { return _code; }
00151 
00157     void set_code(const string& code) { _code = code; }
00158 
00164     void add_code(const string& code) { _code += code; }
00165 
00171     const set<string> referenced_set_names() const {
00172     return _referenced_set_names;
00173     }
00174 
00180     void set_referenced_set_names(const set<string>& set_names) {
00181     _referenced_set_names = set_names;
00182     }
00183 
00189     void add_referenced_set_name(const string& set_name) {
00190     _referenced_set_names.insert(set_name);
00191     }
00192 
00196     void clear_referenced_set_names() { _referenced_set_names.clear(); }
00197 
00198     /*
00199      * Get the set of source protocols.
00200      *
00201      * @return a reference to the set of source protocols.
00202      */
00203     const set<string>& source_protocols() const { return _source_protocols; }
00204 
00210     void add_source_protocol(const string& protocol) {
00211     _source_protocols.insert(protocol);
00212     }
00213 
00219     const Code::TagSet& all_tags() const { return _all_tags; }
00220 
00227     const Code::TagSet& redist_tags() const { return _redist_tags; }
00228 
00236     void add_tag(uint32_t tag, bool is_redist_tag) {
00237     _all_tags.insert(tag);
00238     if (is_redist_tag)
00239         _redist_tags.insert(tag);
00240     }
00241 
00242     void add_subr(const string& policy, const string& code);
00243 
00244     const SUBR& subr() const;
00245 
00249     string str();
00250 
00258     Code& operator +=(const Code& rhs);
00259 
00260 private:
00261     Target  _target;
00262     string  _code;
00263     set<string> _referenced_set_names;
00264 
00265     // if it is an export filter code, these are source protocols which will
00266     // send routes to the target
00267     set<string> _source_protocols;
00268 
00269     TagSet  _all_tags;
00270     TagSet  _redist_tags;   // The tags used for route redistribution
00271     SUBR    _subr;
00272 };
00273 
00274 #endif // __POLICY_CODE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations