xorp

route_manager.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/route_manager.hh,v 1.3 2008/10/02 21:56:35 bms Exp $
00022 
00023 #ifndef __OLSR_ROUTE_MANAGER_HH__
00024 #define __OLSR_ROUTE_MANAGER_HH__
00025 
00026 class Olsr;
00027 class FaceManager;
00028 class Neighborhood;
00029 class TopologyManager;
00030 class ExternalRoutes;
00031 
00047 class RouteEntry {
00048   public:
00049     RouteEntry()
00050      : _destination_type(OlsrTypes::VT_UNKNOWN),
00051        _direct(false),
00052        _nexthop(IPv4::ZERO()),
00053        _faceid(OlsrTypes::UNUSED_FACE_ID),
00054        _cost(0),
00055        _originator(IPv4::ZERO()),
00056        _main_address(IPv4::ZERO()),
00057        _filtered(false)
00058     {}
00059 
00060     /*
00061      * @return An integer which identifies the part of OLSR from which we
00062      * have learned this route: neighborhood, TC, HNA, MID.
00063      */
00064     inline OlsrTypes::VertexType destination_type() const {
00065     return _destination_type;
00066     }
00067 
00074     inline void set_destination_type(const OlsrTypes::VertexType vt) {
00075     _destination_type = vt;
00076     }
00077 
00086     inline bool direct() const { return _direct; }
00087 
00093     inline void set_direct(bool is_direct) { _direct = is_direct; }
00094 
00098     inline IPv4 nexthop() const { return _nexthop; }
00099 
00105     inline void set_nexthop(const IPv4& nexthop) { _nexthop = nexthop; }
00106 
00110     inline OlsrTypes::FaceID faceid() { return _faceid; }
00111 
00117     inline void set_faceid(const OlsrTypes::FaceID faceid) {
00118     _faceid = faceid;
00119     }
00120 
00124     inline uint32_t cost() const { return _cost; }
00125 
00131     inline void set_cost(const uint32_t cost) { _cost = cost; }
00132 
00136     inline IPv4 originator() const { return _originator; }
00137 
00143     inline void set_originator(const IPv4& originator) {
00144     _originator = originator;
00145     }
00146 
00151     inline IPv4 main_address() const { return _main_address; }
00152 
00161     inline void set_main_address(const IPv4& main_addr) {
00162     _main_address = main_addr;
00163     }
00164 
00168     inline bool filtered() const { return _filtered; }
00169 
00174     inline void set_filtered(const bool was_filtered) {
00175     _filtered = was_filtered;
00176     }
00177 
00181     string str();
00182 
00183   private:
00184     OlsrTypes::VertexType   _destination_type; // MID, TC, HNA. neighbor, etc.
00185     bool        _direct;    // destination is directly connected
00186 
00187     IPv4        _nexthop;
00188     OlsrTypes::FaceID   _faceid;    // face used to reach nexthop
00189 
00190     uint32_t        _cost;      // OLSR link cost.
00191 
00192     IPv4        _originator;    // advertising router
00193     IPv4        _main_address;  // If this is an N1, N2, TC or MID
00194                     // route, this is the main address
00195                     // of the destination; similar to
00196                     // OSPF router ID.
00197 
00198     bool        _filtered;  // true if policy filtered this route.
00199 };
00200 
00218 class RouteManager {
00219   public:
00220     RouteManager(Olsr& olsr, EventLoop& eventloop,
00221          FaceManager* fm, Neighborhood* nh,
00222          TopologyManager* tm, ExternalRoutes* er);
00223     ~RouteManager();
00224 
00228     void schedule_route_update();
00229 
00233     void schedule_external_route_update();
00234 
00247     bool add_onehop_link(const LogicalLink* l, const Neighbor* n);
00248 
00265     bool add_twohop_link(const Neighbor* n, const TwoHopLink* l2,
00266              const TwoHopNeighbor* n2);
00267 
00281     bool add_tc_link(const TopologyEntry* tc);
00282 
00297     bool add_hna_route(const IPv4Net& dest,
00298                const IPv4& lasthop,
00299                const uint16_t distance);
00300 
00305     void push_routes();
00306 
00307   protected:
00315     void recompute_all_routes();
00316 
00317     inline Vertex make_origin_vertex() {
00318     Vertex v;
00319     v.set_is_origin(true);
00320     v.set_main_addr(_fm->get_main_addr());
00321     return v;
00322     }
00323 
00324     //
00325     // Route table transactions.
00326     //
00327 
00334     void begin();
00335 
00342     void end();
00343 
00344     //
00345     // Route table manipulation.
00346     //
00347 
00356     bool add_entry(const IPv4Net& net, const RouteEntry& rt);
00357 
00366     bool delete_entry(const IPv4Net& net, const RouteEntry& rt);
00367 
00377     bool replace_entry(const IPv4Net& net, const RouteEntry& rt,
00378                const RouteEntry& previous_rt);
00379 
00380     //
00381     // RIB interaction.
00382     //
00383 
00393     bool add_route(IPv4Net net, IPv4 nexthop,
00394            uint32_t metric, RouteEntry& rt);
00395 
00404     bool delete_route(const IPv4Net& net, const RouteEntry& rt);
00405 
00416     bool replace_route(IPv4Net net, IPv4 nexthop,
00417                uint32_t metric,
00418                RouteEntry& rt,
00419                RouteEntry& previous_rt);
00420 
00421     //
00422     // Policy interaction.
00423     //
00424 
00438     bool do_filtering(IPv4Net& net, IPv4& nexthop,
00439               uint32_t& metric, RouteEntry& rt,
00440               PolicyTags& policytags);
00441 
00442   private:
00443     Olsr&       _olsr;
00444     EventLoop&      _eventloop;
00445     FaceManager*    _fm;
00446     Neighborhood*   _nh;
00447     TopologyManager*    _tm;
00448     ExternalRoutes* _er;
00449 
00450     Spt<Vertex>     _spt;
00451     Vertex      _origin;
00452 
00453     bool        _in_transaction;
00454 
00455     XorpTask        _route_update_task;
00456 
00457     Trie<IPv4, RouteEntry>*     _current;
00458     Trie<IPv4, RouteEntry>*     _previous;
00459 };
00460 
00461 #endif // __OLSR_ROUTE_MANAGER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations