xorp

peer.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/rip/peer.hh,v 1.15 2008/10/02 21:58:16 bms Exp $
00021 
00022 #ifndef __RIP_PEER_HH__
00023 #define __RIP_PEER_HH__
00024 
00025 #include "libxorp/timeval.hh"
00026 #include "route_entry.hh"
00027 
00031 struct PeerCounters {
00032 public:
00033     PeerCounters() : _packets_recv(0), _updates_recv(0), _requests_recv(0),
00034              _bad_routes(0), _bad_packets(0), _bad_auth_packets(0)
00035     {}
00036 
00040     uint32_t packets_recv() const       { return _packets_recv; }
00041 
00045     void incr_packets_recv()            { _packets_recv++; }
00046 
00050     uint32_t update_packets_recv() const    { return _updates_recv; }
00051 
00055     void incr_update_packets_recv()     { _updates_recv++; }
00056 
00060     uint32_t table_requests_recv() const    { return _requests_recv; }
00061 
00065     void incr_table_requests_recv()     { _requests_recv++; }
00066 
00071     uint32_t bad_routes() const         { return _bad_routes; }
00072 
00076     void incr_bad_routes()          { _bad_routes++; }
00077 
00081     uint32_t bad_packets() const        { return _bad_packets; }
00082 
00086     void incr_bad_packets()         { _bad_packets++; }
00087 
00091     uint32_t bad_auth_packets() const       { return _bad_auth_packets; }
00092 
00096     void incr_bad_auth_packets()        { _bad_auth_packets++; }
00097 
00098 protected:
00099     uint32_t _packets_recv;
00100     uint32_t _updates_recv;
00101     uint32_t _requests_recv;
00102     uint32_t _bad_routes;
00103     uint32_t _bad_packets;
00104     uint32_t _bad_auth_packets;
00105 };
00106 
00107 // Forward declaration of Peer class
00108 template <typename A> class Peer;
00109 
00116 template <typename A>
00117 class PeerRoutes : public RouteEntryOrigin<A> {
00118 public:
00119     PeerRoutes(Peer<A>& peer) : RouteEntryOrigin<A>(false), _peer(peer) {}
00120 
00121 private:
00122     uint32_t expiry_secs() const;
00123     uint32_t deletion_secs() const;
00124 
00125     Peer<A>&    _peer;      // The corresponding peer
00126 };
00127 
00128 
00129 // Forward declaration of Port class
00130 template <typename A>
00131 class Port;
00132 
00145 template <typename A>
00146 class Peer : public RouteEntryOrigin<A>
00147 {
00148 public:
00149     typedef A           Addr;
00150     typedef Port<A>     RipPort;
00151     typedef RouteEntry<A>   Route;
00152 
00153 public:
00154     Peer(RipPort& p, const Addr& addr);
00155     ~Peer();
00156 
00160     const Addr& address() const         { return _addr; }
00161 
00165     PeerCounters& counters()            { return _counters; }
00166 
00170     const PeerCounters& counters() const    { return _counters; }
00171 
00175     RipPort& port()             { return _port; }
00176 
00180     const RipPort& port() const         { return _port; }
00181 
00185     void set_last_active(const TimeVal& t)  { _last_active = t; }
00186 
00190     const TimeVal& last_active() const      { return _last_active; }
00191 
00203     bool update_route(const IPNet<A>&   net,
00204               const A&      nexthop,
00205               uint32_t      cost,
00206               uint32_t      tag,
00207               const PolicyTags& policytags);
00208 
00214     void push_routes();
00215 
00216     uint32_t expiry_secs() const;
00217 
00218     uint32_t deletion_secs() const;
00219 
00220 protected:
00221     void set_expiry_timer(Route* route);
00222     void expire_route(Route* route);
00223 
00224     RipPort&        _port;
00225     Addr        _addr;
00226     PeerCounters    _counters;
00227     TimeVal     _last_active;
00228     PeerRoutes<A>   _peer_routes;
00229 };
00230 
00231 
00236 template <typename A>
00237 struct peer_has_address {
00238     peer_has_address(const A& addr) : _a(addr) {}
00239 
00240     bool operator() (const Peer<A>& p) const { return p.address() == _a; }
00241 
00242     bool operator() (const Peer<A>* p) const { return p->address() == _a; }
00243 
00244 private:
00245     A _a;
00246 };
00247 
00248 #endif // __RIP_PEER_HH__
00249 
 All Classes Namespaces Functions Variables Typedefs Enumerations