xorp

trie.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/harness/trie.hh,v 1.19 2008/10/02 21:56:27 bms Exp $
00021 
00022 #ifndef __BGP_HARNESS_TRIE_HH__
00023 #define __BGP_HARNESS_TRIE_HH__
00024 
00025 #include <stdio.h>
00026 #include "libxorp/timeval.hh"
00027 #include "libxorp/callback.hh"
00028 #include "bgp/packet.hh"
00029 #include "trie_payload.hh"
00030 #include "real_trie.hh"
00031 class BGPPeerData;
00032 
00046 class Trie {
00047 public:
00048     Trie() : _first(0), _last(0), _update_cnt(0), _changes(0), 
00049          _warning(true) {
00050     }
00051 
00052     const UpdatePacket *lookup(const string& net) const;
00053     const UpdatePacket *lookup(const IPv4Net& net) const;
00054     const UpdatePacket *lookup(const IPv6Net& net) const;
00055     void process_update_packet(const TimeVal& tv, const uint8_t *buf,
00056                    size_t len, const BGPPeerData *peerdata);
00057 
00058     typedef RealTrie<IPv4>::TreeWalker TreeWalker_ipv4;
00059     typedef RealTrie<IPv6>::TreeWalker TreeWalker_ipv6;
00060 
00061     void tree_walk_table(const TreeWalker_ipv4& tw) const;
00062     void tree_walk_table(const TreeWalker_ipv6& tw) const;
00063 
00064     typedef XorpCallback2<void, const UpdatePacket*,
00065               const TimeVal&>::RefPtr ReplayWalker;
00066     
00073     void replay_walk(const ReplayWalker uw, const BGPPeerData *peerdata) const;
00074 
00075     uint32_t update_count() {
00076     return _update_cnt;
00077     }
00078 
00079     uint32_t changes() {
00080     return _changes;
00081     }
00082 
00083     void set_warning(bool warning) {
00084     _warning = warning;
00085     }
00086 
00087 private:
00088     template <class A> void add(IPNet<A> net, TriePayload&);
00089     template <class A> void del(IPNet<A> net, TriePayload&);
00090 
00091     template <class A> void get_heads(RealTrie<A>*&, RealTrie<A>*&);
00092 
00093     RealTrie<IPv4> _head_ipv4;
00094     RealTrie<IPv4> _head_ipv4_del;
00095     RealTrie<IPv6> _head_ipv6;
00096     RealTrie<IPv6> _head_ipv6_del;
00097 
00098     TrieData *_first;
00099     TrieData *_last;
00100 
00101     uint32_t _update_cnt;   // Number of update packets seen
00102     uint32_t _changes;      // Number of trie entry changes.
00103 
00104     bool _warning;      // Print warning messages;
00105 };
00106 
00107 #endif // __BGP_HARNESS_TRIE_HH__
00108 
 All Classes Namespaces Functions Variables Typedefs Enumerations