xorp

link.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-2009 XORP, Inc.
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/link.hh,v 1.3 2008/10/02 21:56:34 bms Exp $
00022 
00023 #ifndef __OLSR_LINK_HH__
00024 #define __OLSR_LINK_HH__
00025 
00026 class Neighbor;
00027 class Neighborhood;
00028 
00038 class LogicalLink {
00039   public:
00040     LogicalLink(Neighborhood* tm,
00041      EventLoop& eventloop,
00042      const OlsrTypes::LogicalLinkID id,
00043      const TimeVal& vtime,
00044      const IPv4& remote_addr,
00045      const IPv4& local_addr);
00046 
00050     inline OlsrTypes::LogicalLinkID id() const { return _id; }
00051 
00055     inline OlsrTypes::NeighborID neighbor_id() const { return _neighborid; }
00056 
00062     inline void set_neighbor_id(OlsrTypes::NeighborID neighborid) {
00063     _neighborid = neighborid;
00064     }
00065 
00069     inline Neighbor* destination() const {
00070     XLOG_ASSERT(0 != _destination); // Pilot error if we get here.
00071     return _destination;
00072     }
00073 
00079     inline void set_destination(Neighbor* n) { _destination = n; }
00080 
00084     inline OlsrTypes::FaceID faceid() const { return _faceid; }
00085 
00091     inline void set_faceid(OlsrTypes::FaceID faceid) {
00092     _faceid = faceid;
00093     }
00094 
00098     inline IPv4 local_addr() const { return _local_addr; }
00099 
00103     inline IPv4 remote_addr() const { return _remote_addr; }
00104 
00108     inline double near_etx() const { return _near_etx; }
00109 
00113     inline double far_etx() const { return _far_etx; }
00114 
00124     void update_timers(const TimeVal& vtime,
00125                bool saw_self = false,
00126                const LinkCode lc = LinkCode());
00127 
00134     OlsrTypes::LinkType link_type() const;
00135 
00139     inline bool is_sym() const {
00140     return link_type() == OlsrTypes::SYM_LINK;
00141     }
00142 
00146     inline TimeVal sym_time_remaining() const {
00147     TimeVal tv;
00148     _sym_timer.time_remaining(tv);
00149     return tv;
00150     }
00151 
00155     inline TimeVal asym_time_remaining() const {
00156     TimeVal tv;
00157     _asym_timer.time_remaining(tv);
00158     return tv;
00159     }
00160 
00164     inline TimeVal time_remaining() const {
00165     TimeVal tv;
00166     _dead_timer.time_remaining(tv);
00167     return tv;
00168     }
00169 
00175     inline bool pending() const { return _is_pending; }
00176 
00180     void event_sym_timer();
00181 
00185     void event_asym_timer();
00186 
00190     void event_lost_timer();
00191 
00197     void event_dead_timer();
00198 
00199   private:
00200     Neighborhood*   _nh;
00201     EventLoop&      _eventloop;
00202 
00206     OlsrTypes::LogicalLinkID        _id;
00207 
00211     OlsrTypes::FaceID       _faceid;
00212 
00216     OlsrTypes::NeighborID   _neighborid;
00217 
00221     Neighbor*           _destination;
00222 
00227     IPv4            _remote_addr;
00228 
00233     IPv4            _local_addr;
00234 
00235     //
00236     // Link state timers.
00237     //
00238 
00242     XorpTimer           _sym_timer;
00243 
00247     XorpTimer           _asym_timer;
00248 
00252     XorpTimer           _lost_timer;
00253 
00257     XorpTimer           _dead_timer;
00258 
00259     //
00260     // Link etx fields.
00261     //
00262 
00266     bool            _is_pending;
00267 
00271     double          _near_etx;
00272 
00276     double          _far_etx;
00277 };
00278 
00279 #endif // __OLSR_LINK_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations