xorp

neighbor.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8 sw=4:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
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/contrib/olsr/neighbor.hh,v 1.4 2008/10/02 21:56:35 bms Exp $
00022 
00023 #ifndef __OLSR_NEIGHBOR_HH__
00024 #define __OLSR_NEIGHBOR_HH__
00025 
00026 class Neighborhood;
00027 
00035 struct IsLinkSymmetricPred {
00036     Neighborhood* _nh;
00037 
00038     IsLinkSymmetricPred(Neighborhood* nh) : _nh(nh) {}
00039 
00043     bool operator()(OlsrTypes::LogicalLinkID linkid);
00044 };
00045 
00053 struct IsTwoHopLinkStrictPred {
00054     Neighborhood* _nh;
00055 
00056     IsTwoHopLinkStrictPred(Neighborhood* nh) : _nh(nh) {}
00057 
00062     bool operator()(OlsrTypes::TwoHopLinkID tlid);
00063 };
00064 
00068 class Neighbor {
00069   public:
00070     Neighbor(EventLoop& ev,
00071          Neighborhood* parent,
00072          const OlsrTypes::NeighborID nid,
00073          const IPv4& main_addr,
00074          const OlsrTypes::LogicalLinkID linkid);
00075 
00076     inline OlsrTypes::NeighborID id() const { return _id; }
00077 
00078     inline const IPv4 main_addr() const { return _main_addr; }
00079 
00080     string toStringBrief();
00081 
00082     OlsrTypes::NeighborType neighbor_type() const;
00083 
00089     inline uint8_t willingness() const { return _willingness; }
00090 
00099     void set_willingness(OlsrTypes::WillType value); 
00100 
00107     bool is_mpr_selector() const;
00108 
00116     void set_is_mpr_selector(bool value, const TimeVal& expiry_time);
00117 
00124     inline bool is_mpr() const { return _is_mpr; }
00125 
00126     inline void set_is_mpr(bool value) { _is_mpr = value; }
00127 
00131     inline bool is_persistent_cand_mpr() const {
00132     return _willingness == OlsrTypes::WILL_ALWAYS;
00133     }
00134 
00147     bool is_cand_mpr();
00148 
00149     inline bool is_sym() const { return _is_sym; }
00150     inline void set_is_sym(bool value) { _is_sym = value; }
00151 
00152     inline const set<OlsrTypes::LogicalLinkID>& links() const {
00153     return _links;
00154     }
00155 
00156     inline const set<OlsrTypes::TwoHopLinkID>& twohop_links() const {
00157     return _twohop_links;
00158     }
00159 
00166     void update_link(const OlsrTypes::LogicalLinkID linkid);
00167 
00177     bool delete_link(const OlsrTypes::LogicalLinkID linkid);
00178 
00185     void add_twohop_link(const OlsrTypes::TwoHopLinkID tlid);
00186 
00195     bool delete_twohop_link(const OlsrTypes::TwoHopLinkID tlid);
00196 
00203     size_t delete_all_twohop_links();
00204 
00208     void event_mpr_selector_expired();
00209 
00216     inline uint32_t degree() const { return _degree; }
00217 
00224     inline uint32_t reachability() const { return _reachability; }
00225 
00235     inline void set_reachability(uint32_t value) { _reachability = value; }
00236 
00242     inline bool is_advertised() const { return _is_advertised; }
00243 
00249     inline void set_is_advertised(bool value) { _is_advertised = value; }
00250 
00251   protected:
00264     void recount_degree();
00265 
00276     bool update_cand_mpr(bool was_cand_mpr);
00277 
00278   private:
00279     EventLoop&          _eventloop;
00280     Neighborhood*       _parent;
00281 
00282     OlsrTypes::NeighborID   _id;
00283 
00287     IPv4            _main_addr;
00288 
00296     bool            _is_mpr;
00297 
00301     bool            _is_sym;
00302 
00306     OlsrTypes::WillType     _willingness;
00307 
00311     uint32_t            _degree;
00312 
00316     uint32_t            _reachability;
00317 
00321     bool            _is_advertised;
00322 
00327     XorpTimer           _mpr_selector_timer;
00328 
00332     set<OlsrTypes::LogicalLinkID>   _links;
00333 
00337     set<OlsrTypes::TwoHopLinkID>    _twohop_links;
00338 };
00339 
00340 #endif // __OLSR_NEIGHBOR_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations