xorp

bgp_varrw.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-2009 XORP, Inc.
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/bgp/bgp_varrw.hh,v 1.26 2008/11/08 06:14:36 mjh Exp $
00022 
00023 #ifndef __BGP_BGP_VARRW_HH__
00024 #define __BGP_BGP_VARRW_HH__
00025 
00026 #include "policy/backend/single_varrw.hh"
00027 #include "policy/common/element_factory.hh"
00028 #include "internal_message.hh"
00029 
00030 template <class A>
00031 class BGPVarRWCallbacks;
00032 
00041 template <class A>
00042 class BGPVarRW :
00043     public SingleVarRW
00044 {
00045 public:
00046     enum {
00047     VAR_NETWORK4 = VAR_PROTOCOL,
00048         VAR_NEXTHOP4,
00049         VAR_NETWORK6,
00050         VAR_NEXTHOP6,
00051         VAR_ASPATH,
00052         VAR_ORIGIN,         // 15
00053         VAR_NEIGHBOR,
00054         VAR_LOCALPREF,
00055         VAR_COMMUNITY,
00056         VAR_MED,
00057         VAR_MED_REMOVE,         // 20
00058         VAR_AGGREGATE_PREFIX_LEN,
00059         VAR_AGGREGATE_BRIEF_MODE,
00060         VAR_WAS_AGGREGATED,
00061 
00062     VAR_BGPMAX // must be last
00063     };
00064 
00065     typedef Element* (BGPVarRW::*ReadCallback)();
00066     typedef void (BGPVarRW::*WriteCallback)(const Element& e);
00067 
00075     BGPVarRW(const string& name);
00076     virtual ~BGPVarRW();
00077 
00078     void set_peer(const A& peer);
00079     void set_self(const A& self);
00080 
00087     void attach_route(InternalMessage<A>& rtmsg, bool no_modify);
00088     void detach_route(InternalMessage<A>& rtmsg);
00089 
00096     InternalMessage<A>* filtered_message();
00097     
00098     // SingleVarRW interface
00099     Element* single_read(const Id& id);
00100 
00101     void single_write(const Id& id, const Element& e);
00102     void end_write();
00103 
00110     bool modified();
00111 
00117     virtual string more_tracelog();
00118 
00124     virtual Element* read_neighbor();
00125 
00131     Element* read_neighbor_base_cb()    { return read_neighbor(); }
00132 
00133     Element* read_policytags();
00134     Element* read_filter_im();
00135     Element* read_filter_sm();
00136     Element* read_filter_ex();
00137 
00138     Element* read_network4();
00139     Element* read_network6();
00140 
00141     Element* read_nexthop4();
00142     Element* read_nexthop6();
00143     Element* read_aspath();
00144     Element* read_origin();
00145 
00146     Element* read_localpref();
00147     Element* read_community();
00148     Element* read_med();
00149     Element* read_med_remove();
00150 
00151     Element* read_aggregate_prefix_len();
00152     Element* read_aggregate_brief_mode();
00153     Element* read_was_aggregated();
00154 
00155     Element* read_tag();
00156 
00157     void write_filter_im(const Element& e);
00158     void write_filter_sm(const Element& e);
00159     void write_filter_ex(const Element& e);
00160     void write_policytags(const Element& e);
00161 
00162     void write_nexthop4(const Element& e);
00163     void write_nexthop6(const Element& e);
00164     void write_aspath(const Element& e);
00165     void write_origin(const Element& e);
00166 
00167     void write_aggregate_prefix_len(const Element& e);
00168     void write_aggregate_brief_mode(const Element& e);
00169     void write_was_aggregated(const Element& e);
00170 
00171     void write_localpref(const Element& e);
00172     void write_community(const Element& e);
00173     void write_med(const Element& e);
00174     void write_med_remove(const Element& e);
00175 
00176     void write_tag(const Element& e);
00177 
00178 protected:
00179     ElementFactory      _ef;
00180     string          _name;
00181 
00182 private:
00183     void cleanup();
00184     void write_nexthop(const Element& e);
00185 
00186     InternalMessage<A>*         _rtmsg;
00187     bool            _got_fmsg;
00188     PolicyTags*         _ptags;
00189     bool            _wrote_ptags;
00190     FPAListRef                  _palist;
00191     bool            _no_modify;
00192     bool            _modified;
00193     RefPf           _pfilter[3];
00194     bool            _wrote_pfilter[3];
00195     bool            _route_modify;
00196     A               _self;
00197     A               _peer;
00198 
00199     // Aggregation -> we cannot write those directly into the subnet
00200     // route so must provide local volatile copies to be operated on
00201     uint32_t            _aggr_prefix_len;
00202     bool            _aggr_brief_mode;
00203 
00204     // not impl
00205     BGPVarRW(const BGPVarRW&);
00206     BGPVarRW& operator=(const BGPVarRW&);
00207 
00208     static BGPVarRWCallbacks<A> _callbacks;
00209 };
00210 
00211 template <class A>
00212 class BGPVarRWCallbacks {
00213 public:
00214     // XXX don't know how to refer to BGPVarRW<A>::ReadCallback in gcc 2.95
00215     typedef Element* (BGPVarRW<A>::*RCB)();
00216     typedef void (BGPVarRW<A>::*WCB)(const Element&);
00217 
00218     void init_rw(const VarRW::Id&, RCB, WCB);
00219 
00220     BGPVarRWCallbacks();
00221 
00222     RCB _read_map[BGPVarRW<A>::VAR_BGPMAX];
00223     WCB _write_map[BGPVarRW<A>::VAR_BGPMAX];
00224 };
00225 
00226 #endif // __BGP_BGP_VARRW_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations