xorp

redist_policy.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 
00021 #ifndef __RIB_REDIST_POLICY_HH__
00022 #define __RIB_REDIST_POLICY_HH__
00023 
00024 
00025 
00032 template <typename A>
00033 class RedistPolicy {
00034 public:
00043     virtual bool accept(const IPRouteEntry<A>& ipr) const = 0;
00044 
00045     virtual ~RedistPolicy() {};
00046 };
00047 
00051 template <typename A>
00052 class RedistUnaryOp :
00053     public NONCOPYABLE
00054 {
00055 public:
00061     RedistUnaryOp(const RedistPolicy<A>* policy) : _p1(policy) {}
00062     ~RedistUnaryOp() { delete _p1; }
00063 
00064 private:
00065     // The following are not implemented
00066     RedistUnaryOp();
00067 
00068 protected:
00069     const RedistPolicy<A>* _p1;
00070 };
00071 
00075 template <typename A>
00076 class RedistBinaryOp :
00077     public NONCOPYABLE,
00078     public RedistPolicy<A>
00079 {
00080 public:
00089     RedistBinaryOp(RedistPolicy<A>* one, RedistPolicy<A>* two)
00090     : _p1(one), _p2(two) {}
00091     ~RedistBinaryOp() { delete _p1; delete _p2; }
00092 
00093 private:
00094     // The following are not implemented
00095     RedistBinaryOp();
00096 
00097 protected:
00098     const RedistPolicy<A>* _p1;
00099     const RedistPolicy<A>* _p2;
00100 };
00101 
00102 
00106 template <typename A>
00107 class RedistLogicalNot : public RedistUnaryOp<A> {
00108 public:
00109     RedistLogicalNot(const RedistPolicy<A>* p) : RedistUnaryOp<A>(p) {}
00110     bool accept() const { return ! this->_p1->accept(); }
00111 };
00112 
00116 template <typename A>
00117 class RedistLogicalAnd : public RedistBinaryOp<A> {
00118 public:
00119     RedistLogicalAnd(const RedistPolicy<A>* p1, const RedistPolicy<A>* p2)
00120     : RedistBinaryOp<A>(p1, p2)
00121     {}
00122     bool accept(const IPRouteEntry<A>& ipr)
00123     {
00124     return this->_p1->accept(ipr) && this->_p2->accept(ipr);
00125     }
00126 };
00127 
00131 template <typename A>
00132 class RedistLogicalOr : public RedistBinaryOp<A> {
00133 public:
00134     RedistLogicalOr(const RedistPolicy<A>* one, const RedistPolicy<A>* two)
00135     : RedistBinaryOp<A>(one, two)
00136     {}
00137     bool accept(const IPRouteEntry<A>& ipr)
00138     {
00139     return this->_p1->accept(ipr) || this->_p2->accept(ipr);
00140     }
00141 };
00142 
00143 
00149 template <typename A>
00150 class IsOfProtocol : public RedistPolicy<A>
00151 {
00152 public:
00153     IsOfProtocol(const Protocol& p) : _protocol(p) {}
00154     bool accept(const IPRouteEntry<A>& ipr) const {
00155     return ipr.protocol() == _protocol;
00156     }
00157 private:
00158     Protocol _protocol;
00159 };
00160 
00166 template <typename A>
00167 class IsIGP : public RedistPolicy<A>
00168 {
00169 public:
00170     IsIGP() {}
00171     bool accept(const IPRouteEntry<A>& ipr) const {
00172     return ipr.protocol_type() == IGP;
00173     }
00174 };
00175 
00181 template <typename A>
00182 class IsEGP : public RedistPolicy<A>
00183 {
00184 public:
00185     IsEGP() {}
00186     bool accept(const IPRouteEntry<A>& ipr) const {
00187     return ipr.protocol_type() == EGP;
00188     }
00189 };
00190 
00191 #endif // __RIB_REDIST_POLICY_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations