xorp

port.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8: 
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/rip/port.hh,v 1.33 2008/10/02 21:58:16 bms Exp $
00022 
00023 #ifndef __RIP_PORT_HH__
00024 #define __RIP_PORT_HH__
00025 
00026 
00027 
00028 
00029 #include "libxorp/eventloop.hh"
00030 
00031 #include "constants.hh"
00032 #include "port_vars.hh"
00033 #include "port_io.hh"
00034 
00035 //
00036 // Forward declarations
00037 //
00038 class AuthHandlerBase;
00039 
00040 template <typename A>
00041 class OutputTable;
00042 
00043 template <typename A>
00044 class OutputUpdates;
00045 
00046 template <typename A>
00047 class PacketRouteEntry;
00048 
00049 template <typename A>
00050 class PacketQueue;
00051 
00052 template <typename A>
00053 class Peer;
00054 
00055 template <typename A>
00056 class PortManagerBase;
00057 
00058 template <typename A>
00059 class RouteEntry;
00060 
00061 
00068 template <typename A>
00069 class PortAFSpecState
00070 {};
00071 
00078 template <>
00079 class PortAFSpecState<IPv4>
00080 {
00081 private:
00082     AuthHandlerBase* _ah;
00083 
00084 public:
00090     PortAFSpecState();
00091 
00097     ~PortAFSpecState();
00098 
00105     AuthHandlerBase* set_auth_handler(AuthHandlerBase* ah);
00106 
00110     const AuthHandlerBase* auth_handler() const;
00111 
00115     AuthHandlerBase* auth_handler();
00116 };
00117 
00118 
00122 template <>
00123 class PortAFSpecState<IPv6>
00124 {
00125 protected:
00126     uint32_t _mepp; // Max route entries per packet
00127 
00128 public:
00129     PortAFSpecState() : _mepp(50) {}
00130 
00135     uint32_t max_entries_per_packet() const { return _mepp; }
00136 
00141     void set_max_entries_per_packet(uint32_t n) { _mepp = n; }
00142 };
00143 
00144 
00155 template <typename A>
00156 class Port
00157     : public PortIOUserBase<A>
00158 {
00159 public:
00160     typedef A           Addr;
00161     typedef list<Peer<A>*>  PeerList;
00162 
00163 public:
00164     Port(PortManagerBase<A>& manager);
00165 
00166     ~Port();
00167 
00168     PortManagerBase<A>& port_manager()      { return _pm; }
00169 
00175     void set_enabled(bool en);
00176 
00180     bool enabled() const            { return _en; }
00181 
00185     PortTimerConstants& constants()     { return _constants; }
00186 
00190     const PortTimerConstants& constants() const { return _constants; }
00191 
00196     PortAFSpecState<A>& af_state()      { return _af_state; }
00197 
00202     const PortAFSpecState<A>& af_state() const  { return _af_state; }
00203 
00207     uint32_t cost() const           { return _cost; }
00208 
00212     void set_cost(uint32_t cost)        { _cost = cost; }
00213 
00217     const RipHorizon& horizon() const       { return _horizon; }
00218 
00223     void set_horizon(const RipHorizon& h)   { _horizon = h; }
00224 
00230     bool advertise() const          { return _advertise; }
00231 
00236     void set_advertise(bool en)         { _advertise = en; }
00237 
00242     bool advertise_default_route() const    { return _adv_def_rt; }
00243 
00249     void set_advertise_default_route(bool en);
00250 
00255     bool accept_default_route() const       { return _acc_def_rt; }
00256 
00261     void set_accept_default_route(bool en);
00262 
00267     bool passive() const            { return _passive; }
00268 
00273     void set_passive(bool passive);
00274 
00279     bool accept_non_rip_requests() const    { return _acc_non_rip_reqs; }
00280 
00285     void set_accept_non_rip_requests(bool en);
00286 
00290     const PeerList& peers() const       { return _peers; }
00291 
00298     PeerList& peers()               { return _peers; }
00299 
00303     const PortCounters& counters() const    { return _counters; }
00304 
00308     PortCounters& counters()            { return _counters; }
00309 
00315     const Peer<A>* peer(const Addr& addr) const;
00316 
00320     void set_max_packet_buffer_bytes(uint32_t max_bytes);
00321 
00325     uint32_t set_max_packet_buffer_bytes() const;
00326 
00330     uint32_t packet_buffer_bytes() const;
00331 
00335     void reschedule_dummy_timer() {}
00336 
00341     void reschedule_request_table_timer();
00342 
00343 protected:
00348     void start_request_table_timer();
00349 
00353     void stop_request_table_timer();
00354 
00359     bool request_table();
00360 
00365     bool request_table_timeout();
00366 
00371     void start_peer_gc_timer();
00372 
00377     bool peer_gc_timeout();
00378 
00384     void kill_peer_routes();
00385 
00386 protected:
00391     Peer<A>* peer(const Addr& addr);
00392 
00397     Peer<A>* create_peer(const Addr& addr);
00398 
00402     void record_packet(Peer<A>* p);
00403 
00407     void record_response_packet(Peer<A>* p);
00408 
00412     void record_request_packet(Peer<A>* p);
00413 
00419     void record_bad_packet(const string&    why,
00420                const Addr&      addr,
00421                uint16_t         port,
00422                Peer<A>*         p);
00423 
00427     void record_bad_auth_packet(const string&   why,
00428                 const Addr& addr,
00429                 uint16_t    port,
00430                 Peer<A>*    p);
00431 
00437     void record_bad_route(const string& why,
00438               const Addr&   src,
00439               uint16_t  port,
00440               Peer<A>*  p);
00441 
00445     void parse_request(const Addr&      src_addr,
00446                uint16_t         rc_port,
00447                const uint8_t*       entries_ptr,
00448                uint32_t         n_entries);
00449 
00453     void parse_response(const Addr&     src_addr,
00454             uint16_t        src_port,
00455             const uint8_t*      entries_ptr,
00456             uint32_t        n_entries);
00457 
00462     void block_queries();
00463 
00468     bool queries_blocked() const;
00469 
00473     void unsolicited_response_timeout();
00474 
00478     void triggered_update_timeout();
00479 
00486     bool output_allowed() const;
00487 
00492     void start_stop_output_processing();
00493 
00499     void start_output_processing();
00500 
00506     void stop_output_processing();
00507 
00508 public:
00513     void push_packets();
00514 
00521     pair<A,uint16_t> route_policy(const RouteEntry<A>& re) const;
00522 
00529     void port_io_send_completion(bool success);
00530 
00540     void port_io_receive(const Addr&    src_addr,
00541              uint16_t   src_port,
00542              const uint8_t* rip_packet,
00543              const size_t   rip_packet_bytes);
00544 
00551     void port_io_enabled_change(bool en);
00552 
00553 protected:
00554     PortManagerBase<A>& _pm;
00555     PortAFSpecState<A>  _af_state;      // Address family specific data
00556 
00557     PeerList        _peers;         // Peers on Port
00558 
00559     XorpTimer       _rt_timer;      // Request table timer
00560     XorpTimer       _gc_timer;      // Peer garbage collection
00561     XorpTimer       _ur_timer;      // Unsolicited response timer
00562     XorpTimer       _tu_timer;      // Triggered update timer
00563     XorpTimer       _query_blocked_timer;   // Rate limiting on queries
00564 
00565     bool        _en;            // enabled state
00566     uint32_t        _cost;          // Cost metric of port
00567     RipHorizon      _horizon;       // Port Horizon type
00568     bool        _advertise;     // Advertise IO port
00569     bool        _adv_def_rt;        // Advertise default route
00570     bool        _acc_def_rt;        // Accept default route
00571     bool        _passive;       // Passive (recv only port)
00572     bool        _acc_non_rip_reqs;  // Accept non-RIP requests
00573 
00574     PacketQueue<A>* _packet_queue;      // Outbound packet queue
00575     PortTimerConstants  _constants;     // Port related timer constants
00576     PortCounters    _counters;      // Packet counters
00577 
00578     OutputTable<A>* _ur_out;        // Unsolicited update output
00579     OutputUpdates<A>*   _tu_out;        // Triggered update output
00580     OutputTable<A>* _su_out;        // Solicited update output
00581 };
00582 
00583 #endif // __RIP_PORT_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations