xorp

external.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/external.hh,v 1.3 2008/10/02 21:56:34 bms Exp $
00022 
00023 #ifndef __OLSR_EXTERNAL_HH__
00024 #define __OLSR_EXTERNAL_HH__
00025 
00026 class ExternalRoute;
00027 class ExternalRoutes;
00028 class RouteManager;
00029 
00036 struct ExternalRouteOrderPred {
00037     ExternalRoutes& _ers;
00038 
00039     inline ExternalRouteOrderPred(ExternalRoutes& ers) : _ers(ers) {}
00040 
00059     bool operator()(const OlsrTypes::ExternalID lhid,
00060             const OlsrTypes::ExternalID rhid);
00061 };
00062 
00067 class ExternalRoutes {
00068   public:
00069     ExternalRoutes(Olsr& olsr, EventLoop& eventloop,
00070            FaceManager& fm, Neighborhood& nh);
00071     ~ExternalRoutes();
00072 
00073     //
00074     // Accessors/mutators.
00075     //
00076     FaceManager& face_manager() { return _fm; }
00077 
00078     inline RouteManager* route_manager() { return _rm; }
00079 
00080     inline void set_route_manager(RouteManager* rm) { _rm = rm; }
00081 
00082     //
00083     // HNA protocol variables.
00084     //
00085 
00086     inline TimeVal get_hna_interval() const { return _hna_interval; }
00087 
00097     void set_hna_interval(const TimeVal& hna_interval);
00098 
00099     inline TimeVal get_hna_hold_time() const {
00100     return 3 * get_hna_interval();
00101     }
00102 
00103 
00104     //
00105     // HNA routes in.
00106     //
00107 
00125     OlsrTypes::ExternalID update_hna_route_in(const IPv4Net& dest,
00126                           const IPv4& lasthop,
00127                           const uint16_t distance,
00128                           const TimeVal& expiry_time,
00129                           bool& is_created)
00130     throw(BadExternalRoute);
00131 
00144     OlsrTypes::ExternalID add_hna_route_in(const IPv4Net& dest,
00145                        const IPv4& lasthop,
00146                        const uint16_t distance,
00147                        const TimeVal& expiry_time)
00148     throw(BadExternalRoute);
00149 
00156     bool delete_hna_route_in(OlsrTypes::ExternalID erid);
00157 
00161     void clear_hna_routes_in();
00162 
00172     const ExternalRoute* get_hna_route_in(const IPv4Net& dest,
00173                       const IPv4& lasthop)
00174     throw(BadExternalRoute);
00175 
00186     OlsrTypes::ExternalID get_hna_route_in_id(const IPv4Net& dest,
00187                           const IPv4& lasthop)
00188     throw(BadExternalRoute);
00189 
00197     const ExternalRoute* get_hna_route_in_by_id(
00198     const OlsrTypes::ExternalID erid)
00199     throw(BadExternalRoute);
00200 
00212     size_t hna_origin_count() const;
00213 
00221     size_t hna_dest_count() const;
00222 
00226     inline size_t hna_entry_count() const {
00227     return _routes_in.size();
00228     }
00229 
00235     void get_hna_route_in_list(list<OlsrTypes::ExternalID>& hnalist);
00236 
00237     //
00238     // HNA routes out.
00239     //
00240 
00248     bool originate_hna_route_out(const IPv4Net& dest)
00249     throw(BadExternalRoute);
00250 
00258     void withdraw_hna_route_out(const IPv4Net& dest)
00259     throw(BadExternalRoute);
00260 
00264     void clear_hna_routes_out();
00265 
00274     OlsrTypes::ExternalID get_hna_route_out_id(const IPv4Net& dest)
00275     throw(BadExternalRoute);
00276 
00277     //
00278     // RouteManager interaction.
00279     //
00280 
00291     void push_external_routes();
00292 
00293     //
00294     // HNA transmission timer.
00295     //
00296 
00297     void start_hna_send_timer();
00298     void stop_hna_send_timer();
00299     void restart_hna_send_timer();
00300 
00304     void reschedule_hna_send_timer();
00305 
00309     void reschedule_immediate_hna_send_timer();
00310 
00311     //
00312     // Event handlers.
00313     //
00314 
00324     bool event_send_hna();
00325 
00336     bool event_receive_hna(Message* msg,
00337                const IPv4& remote_addr,
00338                const IPv4& local_addr);
00339 
00345     void event_hna_route_in_expired(const OlsrTypes::ExternalID erid);
00346 
00347 private:
00348     Olsr&       _olsr;
00349     EventLoop&      _eventloop;
00350     FaceManager&    _fm;
00351     Neighborhood&   _nh;
00352     RouteManager*   _rm;
00353 
00354     ExternalRouteOrderPred  _routes_in_order_pred;
00355 
00356     bool        _is_early_hna_enabled;
00357 
00358     OlsrTypes::ExternalID   _next_erid;
00359 
00364     TimeVal     _hna_interval;
00365     XorpTimer       _hna_send_timer;
00366 
00371     typedef multimap<IPv4Net, OlsrTypes::ExternalID>    ExternalDestInMap;
00372     ExternalDestInMap   _routes_in_by_dest;
00373 
00377     typedef map<OlsrTypes::ExternalID, ExternalRoute*>  ExternalRouteMap;
00378     ExternalRouteMap    _routes_in;
00379 
00383     typedef map<IPv4Net, OlsrTypes::ExternalID> ExternalDestOutMap;
00384     ExternalDestOutMap  _routes_out_by_dest;
00385 
00389     ExternalRouteMap    _routes_out;
00390 };
00391 
00396 class ExternalRoute {
00397 public:
00401     explicit ExternalRoute(ExternalRoutes& parent,
00402                EventLoop& ev,
00403                const OlsrTypes::ExternalID erid,
00404                const IPv4Net& dest,
00405                const IPv4& lasthop,
00406                const uint16_t distance,
00407                const TimeVal& expiry_time)
00408      : _parent(parent),
00409        _eventloop(ev),
00410        _id(erid),
00411        _is_self_originated(false),
00412        _dest(dest),
00413        _lasthop(lasthop),
00414        _distance(distance)
00415     {
00416     update_timer(expiry_time);
00417     }
00418 
00422     explicit ExternalRoute(ExternalRoutes& parent,
00423                EventLoop& ev,
00424                const OlsrTypes::ExternalID erid,
00425                const IPv4Net& dest)
00426      : _parent(parent),
00427        _eventloop(ev),
00428        _id(erid),
00429        _is_self_originated(true),
00430        _dest(dest),
00431        _distance(0)
00432     {
00433     }
00434 
00435     virtual ~ExternalRoute() {}
00436 
00440     inline OlsrTypes::ExternalID id() const { return _id; }
00441 
00445     inline bool is_self_originated() const { return _is_self_originated; }
00446 
00450     inline IPv4Net dest() const { return _dest; }
00451 
00456     inline IPv4 lasthop() const { return _lasthop; }
00457 
00461     inline uint16_t distance() const { return _distance; }
00462 
00466     inline void set_distance(const uint16_t distance) {
00467     _distance = distance;
00468     }
00469 
00473     inline TimeVal time_remaining() const {
00474     TimeVal tv;
00475     _expiry_timer.time_remaining(tv);
00476     return tv;
00477     }
00478 
00484     void update_timer(const TimeVal& expiry_time);
00485 
00490     void event_expired();
00491 
00492 private:
00493     ExternalRoutes&     _parent;
00494     EventLoop&          _eventloop;
00495     OlsrTypes::ExternalID   _id;
00496 
00501     bool            _is_self_originated;
00502 
00506     IPv4Net         _dest;
00507 
00511     IPv4            _lasthop;
00512 
00516     XorpTimer           _expiry_timer;
00517 
00522     uint16_t            _distance;
00523 };
00524 
00525 #endif // __OLSR_EXTERNAL_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations