xorp

twohop.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/twohop.hh,v 1.3 2008/10/02 21:56:36 bms Exp $
00022 
00023 #ifndef __OLSR_TWOHOP_HH__
00024 #define __OLSR_TWOHOP_HH__
00025 
00026 class Neighbor;
00027 class Neighborhood;
00028 
00029 // From now on, N1 is shorthand for "one-hop neighbor", and
00030 // N2 is shorthand for "two-hop neighbor".
00031 
00037 class TwoHopNeighbor {
00038   public:
00039     TwoHopNeighbor(EventLoop& ev,
00040            Neighborhood* parent,
00041            const OlsrTypes::TwoHopNodeID id,
00042            const IPv4& main_addr,
00043            const OlsrTypes::TwoHopLinkID tlid);
00044 
00045     inline OlsrTypes::TwoHopNodeID id() const { return _id; }
00046     inline IPv4 main_addr() const { return _main_addr; }
00047 
00048     string toStringBrief();
00049 
00056     void add_twohop_link(const OlsrTypes::TwoHopLinkID tlid);
00057 
00065     bool delete_twohop_link(const OlsrTypes::TwoHopLinkID tlid);
00066 
00067     size_t delete_all_twohop_links();
00068 
00069     inline const set<OlsrTypes::TwoHopLinkID>& twohop_links() const {
00070     return _twohop_links;
00071     }
00072 
00078     void add_covering_mpr(const OlsrTypes::NeighborID nid);
00079 
00085     void withdraw_covering_mpr(const OlsrTypes::NeighborID nid);
00086 
00090     void reset_covering_mprs();
00091 
00095     inline uint32_t coverage() const { return _coverage; }
00096 
00100     inline bool is_covered() const { return _coverage > 0; }
00101 
00107     inline uint32_t reachability() const { return _reachability; }
00108 
00112     inline void set_reachability(uint32_t value) { _reachability = value; }
00113 
00117     inline bool is_reachable() const { return _reachability > 0; }
00118 
00125     bool is_strict() const { return _is_strict; }
00126 
00132     void set_is_strict(bool is_strict) {
00133     _is_strict = is_strict;
00134     }
00135 
00139     const set<OlsrTypes::TwoHopLinkID>& twohop_links() {
00140     return _twohop_links;
00141     }
00142 
00143   private:
00144     EventLoop&          _ev;
00145     Neighborhood*       _parent;
00146 
00150     OlsrTypes::TwoHopNodeID _id;
00151 
00156     IPv4            _main_addr;
00157 
00161     bool            _is_strict;
00162 
00168     uint32_t            _coverage;
00169 
00173     uint32_t            _reachability;
00174 
00178     set<OlsrTypes::TwoHopLinkID>        _twohop_links;
00179 };
00180 
00194 class TwoHopLink {
00195 public:
00196     TwoHopLink(EventLoop& ev, Neighborhood* parent,
00197            OlsrTypes::TwoHopLinkID tlid,
00198            Neighbor* nexthop, const TimeVal& vtime);
00199 
00204     inline OlsrTypes::TwoHopLinkID id() const { return _id; }
00205 
00210     inline Neighbor* nexthop() const { return _nexthop; }
00211 
00216     inline TwoHopNeighbor* destination() const {
00217     XLOG_ASSERT(0 != _destination);     // Catch programming errors.
00218     return _destination;
00219     }
00220 
00226     inline void set_destination(TwoHopNeighbor* destination) {
00227     // Invariant: set_destination() should only be called once,
00228     // immediately after the TwoHopLink has been created, to
00229     // associate it with a TwoHopNeighbor.
00230     XLOG_ASSERT(0 == _destination);
00231     _destination = destination;
00232     }
00233 
00238     inline OlsrTypes::FaceID face_id() const { return _face_id; }
00239 
00243     inline double near_etx() const { return _near_etx; }
00244 
00248     inline double far_etx() const { return _far_etx; }
00249 
00255     inline void set_face_id(const OlsrTypes::FaceID faceid) {
00256     _face_id = faceid;
00257     }
00258 
00264     inline void set_near_etx(const double& near_etx) {
00265     _near_etx = near_etx;
00266     }
00267 
00273     inline void set_far_etx(const double& far_etx) {
00274     _far_etx = far_etx;
00275     }
00276 
00280     inline TimeVal time_remaining() const {
00281     TimeVal tv;
00282     _expiry_timer.time_remaining(tv);
00283     return tv;
00284     }
00285 
00291     void update_timer(const TimeVal& vtime);
00292 
00297     void event_dead();
00298 
00299 private:
00300     EventLoop&          _ev;
00301     Neighborhood*       _parent;
00302 
00306     OlsrTypes::TwoHopLinkID _id;
00307 
00312     Neighbor*           _nexthop;
00313 
00317     TwoHopNeighbor*     _destination;
00318 
00323     OlsrTypes::FaceID       _face_id;
00324 
00328     XorpTimer           _expiry_timer;
00329 
00333     double          _near_etx;
00334 
00338     double          _far_etx;
00339 };
00340 
00341 #endif // __OLSR_TWOHOP_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations