xorp

route_table_nhlookup.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2009 XORP, Inc.
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 // $XORP: xorp/bgp/route_table_nhlookup.hh,v 1.20 2008/11/08 06:14:39 mjh Exp $
00021 
00022 #ifndef __BGP_ROUTE_TABLE_NHLOOKUP_HH__
00023 #define __BGP_ROUTE_TABLE_NHLOOKUP_HH__
00024 
00025 #include "route_table_base.hh"
00026 #include "libxorp/ref_trie.hh"
00027 #include "next_hop_resolver.hh"
00028 
00029 template<class A>
00030 class MessageQueueEntry {
00031 public:
00032     MessageQueueEntry(InternalMessage<A>* add_msg,
00033               InternalMessage<A>* delete_msg);
00034     MessageQueueEntry(const MessageQueueEntry& original);
00035     ~MessageQueueEntry();
00036     typedef enum op {
00037     ADD = 1,
00038     REPLACE = 2
00039     } Op;
00040     Op type() const {
00041     if (_add_msg!=NULL && _delete_msg==NULL) return ADD;
00042     if (_add_msg!=NULL && _delete_msg!=NULL) return REPLACE;
00043     abort();
00044     }
00045     InternalMessage<A>* add_msg() const {return _add_msg;}
00046     const SubnetRoute<A>* added_route() const {return _add_msg->route();}
00047     FPAListRef& added_attributes() const {return _add_msg->attributes();}
00048 
00049     InternalMessage<A>* delete_msg() const {return _delete_msg;}
00050     const SubnetRoute<A>* deleted_route() const {return _delete_msg->route();}
00051     FPAListRef& deleted_attributes() const {return _delete_msg->attributes();}
00052     const IPNet<A>& net() const {return _add_msg->route()->net();}
00053     string str() const;
00054 private:
00055     void copy_in(InternalMessage<A>* add_msg,
00056          InternalMessage<A>* delete_msg);
00057 
00058     InternalMessage<A>* _add_msg;
00059     InternalMessage<A>* _delete_msg;
00060 
00061     //These references are to ensure that the SubnetRoutes from the
00062     //add and delete messages don't get deleted before we're done with
00063     //them.
00064     SubnetRouteConstRef<A> _added_route_ref;
00065     SubnetRouteConstRef<A> _deleted_route_ref;
00066 };
00067 
00068 template<class A>
00069 class NhLookupTable : public BGPRouteTable<A>  {
00070 public:
00071     NhLookupTable(string tablename,
00072           Safi safi,
00073           NextHopResolver<A> *nexthop_resolver,
00074           BGPRouteTable<A> *parent);
00075     int add_route(InternalMessage<A> &rtmsg,
00076           BGPRouteTable<A> *caller);
00077     int replace_route(InternalMessage<A> &old_rtmsg,
00078               InternalMessage<A> &new_rtmsg,
00079               BGPRouteTable<A> *caller);
00080     int delete_route(InternalMessage<A> &rtmsg, 
00081              BGPRouteTable<A> *caller);
00082     int push(BGPRouteTable<A> *caller);
00083     const SubnetRoute<A> *lookup_route(const IPNet<A> &net,
00084                        uint32_t& genid,
00085                        FPAListRef& pa_list) const;
00086     void route_used(const SubnetRoute<A>* route, bool in_use);
00087     
00088     virtual void RIB_lookup_done(const A& nexthop, 
00089              const set <IPNet<A> >& nets,
00090              bool lookup_succeeded);
00091 
00092     RouteTableType type() const {return NHLOOKUP_TABLE;}
00093     string str() const;
00094 private:
00095     //access the message queue by subnet or an address on the subnet
00096     RefTrie<A, MessageQueueEntry<A> > _queue_by_net;
00097     //access the message queue by nexthop
00098     multimap <A, MessageQueueEntry<A>*> _queue_by_nexthop;
00099 
00100     NextHopResolver<A>* _next_hop_resolver;
00101 
00105     void add_to_queue(const A& nexthop, const IPNet<A>& net,
00106               InternalMessage<A>* new_msg,
00107               InternalMessage<A>* old_msg);
00108 
00116     MessageQueueEntry<A> *
00117     lookup_in_queue(const A& nexthop, const IPNet<A>& net) const;
00118 
00122     void remove_from_queue(const A& nexthop, const IPNet<A>& net);
00123 };
00124 
00125 #endif // __BGP_ROUTE_TABLE_NHLOOKUP_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations