xorp

face_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-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/face_manager.hh,v 1.3 2008/10/02 21:56:34 bms Exp $
00022 
00023 #ifndef __OLSR_FACE_MANAGER_HH__
00024 #define __OLSR_FACE_MANAGER_HH__
00025 
00026 class Olsr;
00027 class Message;
00028 class Face;
00029 class FaceManager;
00030 class LogicalLink;
00031 class Neighbor;
00032 class Neighborhood;
00033 
00038 typedef XorpCallback3<bool,
00039               Message*, const IPv4&, const IPv4&>::RefPtr
00040              MessageReceiveCB;
00041 
00047 class DupeTuple {
00048 public:
00049     DupeTuple(EventLoop& ev, FaceManager* parent, const IPv4& origin,
00050           const uint16_t seqno, const TimeVal& vtime)
00051      : _ev(ev), _parent(parent),
00052        _origin(origin), _seqno(seqno), _is_forwarded(false)
00053     {
00054     update_timer(vtime);
00055     }
00056 
00060     inline IPv4 origin() const { return _origin; }
00061 
00065     inline uint16_t seqno() const { return _seqno; }
00066 
00070     inline bool is_forwarded() const { return _is_forwarded; }
00071 
00077     inline void set_is_forwarded(const bool is_forwarded) {
00078     _is_forwarded = is_forwarded;
00079     }
00080 
00087     inline bool is_seen_by_face(const OlsrTypes::FaceID faceid) const {
00088     return (_iface_list.find(faceid) != _iface_list.end());
00089     }
00090 
00097     inline void set_seen_by_face(const OlsrTypes::FaceID faceid) {
00098     if (_iface_list.find(faceid) == _iface_list.end())
00099         _iface_list.insert(faceid);
00100     }
00101 
00107     void update_timer(const TimeVal& vtime);
00108 
00112     void event_dead();
00113 
00114 private:
00115     EventLoop&      _ev;
00116     FaceManager*    _parent;
00117 
00118     set<OlsrTypes::FaceID>    _iface_list;  // D_iface_list
00119     IPv4        _origin;            // D_addr
00120     uint16_t        _seqno;         // D_seq_num
00121     bool        _is_forwarded;      // D_retransmitted
00122     XorpTimer       _expiry_timer;      // D_time
00123 };
00124 
00129 class FaceManager {
00130   public:
00131     FaceManager(Olsr& olsr, EventLoop& ev);
00132     ~FaceManager();
00133 
00134     MessageDecoder& message_decoder() { return _md; }
00135 
00136     Neighborhood* neighborhood() { return _nh; }
00137     void set_neighborhood(Neighborhood* nh) { _nh = nh; }
00138 
00142     uint32_t get_face_count() const { return _faces.size(); }
00143 
00151     const Face* get_face_by_id(const OlsrTypes::FaceID faceid) const
00152     throw(BadFace);
00153 
00159     void get_face_list(list<OlsrTypes::FaceID>& face_list) const;
00160 
00164     IPv4 get_main_addr() const { return _main_addr; }
00165 
00177     bool set_main_addr(const IPv4& addr);
00178 
00182     TimeVal get_mid_interval() const { return _mid_interval; }
00183 
00190     void set_mid_interval(const TimeVal& interval);
00191 
00195     TimeVal get_mid_hold_time() const { return _mid_interval * 3; }
00196 
00200     TimeVal get_dup_hold_time() const { return _dup_hold_time; }
00201 
00210     void set_dup_hold_time(const TimeVal& dup_hold_time);
00211 
00224     void receive(const string& interface, const string& vif,
00225     const IPv4 & dst, const uint16_t & dport,
00226     const IPv4 & src, const uint16_t & sport,
00227     uint8_t* data, const uint32_t & len);
00228 
00242     bool transmit(const string& interface, const string& vif,
00243     const IPv4 & dst, const uint16_t & dport,
00244     const IPv4 & src, const uint16_t & sport,
00245     uint8_t* data, const uint32_t & len);
00246 
00255     OlsrTypes::FaceID create_face(const string& interface, const string& vif)
00256     throw(BadFace);
00257 
00261     void clear_faces();
00262 
00272     bool activate_face(const string & interface, const string & vif);
00273 
00280     bool delete_face(OlsrTypes::FaceID faceid);
00281 
00298     bool recompute_addresses_face(OlsrTypes::FaceID faceid);
00299 
00307     void vif_status_change(const string& interface, const string& vif,
00308     bool state);
00309 
00318     void address_status_change(const string& interface, const string& vif,
00319     IPv4 addr, bool state);
00320 
00329     OlsrTypes::FaceID get_faceid(const string& interface, const string& vif)
00330     throw(BadFace);
00331 
00340     bool get_interface_vif_by_faceid(OlsrTypes::FaceID faceid,
00341     string & interface, string & vif);
00342 
00351     bool get_interface_cost(OlsrTypes::FaceID faceid, int& cost);
00352 
00361     bool set_face_enabled(OlsrTypes::FaceID faceid, bool enabled);
00362 
00369     bool get_face_enabled(OlsrTypes::FaceID faceid);
00370 
00378     bool set_interface_cost(OlsrTypes::FaceID faceid, const int cost);
00379 
00388     bool set_local_addr(OlsrTypes::FaceID faceid, const IPv4& local_addr);
00389 
00398     bool get_local_addr(OlsrTypes::FaceID faceid, IPv4& local_addr);
00399 
00408     bool set_local_port(OlsrTypes::FaceID faceid, const uint16_t local_port);
00409 
00420     bool get_local_port(OlsrTypes::FaceID faceid, uint16_t& local_port);
00421 
00430     bool set_all_nodes_addr(OlsrTypes::FaceID faceid,
00431                 const IPv4& all_nodes_addr);
00432 
00444     bool get_all_nodes_addr(OlsrTypes::FaceID faceid,
00445                 IPv4& all_nodes_addr);
00446 
00455     bool set_all_nodes_port(OlsrTypes::FaceID faceid,
00456                 const uint16_t all_nodes_port);
00457 
00467     bool get_all_nodes_port(OlsrTypes::FaceID faceid,
00468                 uint16_t& all_nodes_port);
00469 
00476     bool flood_message(Message* message);
00477 
00481     uint16_t get_msg_seqno() { return _next_msg_seqno++; }
00482 
00486     void stop_all_timers();
00487 
00488     void start_hello_timer();
00489     void stop_hello_timer();
00490     void restart_hello_timer();
00491 
00495     void reschedule_hello_timer();
00496 
00500     void reschedule_immediate_hello_timer();
00501 
00505     bool event_send_hello();
00506 
00507     void start_mid_timer();
00508     void stop_mid_timer();
00509     void restart_mid_timer();
00510 
00514     void reschedule_mid_timer();
00515 
00519     void reschedule_immediate_mid_timer();
00520 
00524     bool event_send_mid();
00525 
00531     void set_hello_interval(const TimeVal& interval);
00532 
00536     TimeVal get_hello_interval() { return _hello_interval; }
00537 
00541     TimeVal get_max_jitter() { return _hello_interval / 4; }
00542 
00546     inline uint32_t get_enabled_face_count() const {
00547     return _enabled_face_count;
00548     }
00549 
00565     void add_message_cb(MessageReceiveCB cb);
00566 
00573     bool delete_message_cb(MessageReceiveCB cb);
00574 
00579     bool event_receive_unknown(Message* msg, const IPv4& remote_addr,
00580     const IPv4& local_addr);
00581 
00592     bool forward_message(const IPv4& remote_addr, Message* msg);
00593 
00600     bool is_duplicate_message(const Message* msg) const;
00601 
00610     bool is_forwarded_message(const Message* msg) const;
00611 
00624     DupeTuple* get_dupetuple(const IPv4& origin_addr,
00625                  const uint16_t seqno) const;
00626 
00639     void update_dupetuple(const Message* msg, const bool is_forwarded);
00640 
00644     void event_dupetuple_expired(const IPv4& origin, const uint16_t seqno);
00645 
00649     void clear_dupetuples();
00650 
00655     bool is_local_addr(const IPv4& addr);
00656 
00665     bool get_face_stats(const string& ifname, const string& vifname,
00666             FaceCounters& stats);
00667 
00668   private:
00669     Olsr&       _olsr;
00670     EventLoop&      _eventloop;
00671     MessageDecoder  _md;
00672     Neighborhood*   _nh;
00673 
00674     OlsrTypes::FaceID   _next_faceid;
00675     uint32_t        _enabled_face_count;
00676 
00680     uint16_t        _next_msg_seqno;
00681 
00686     IPv4        _main_addr;
00687 
00691     vector<MessageReceiveCB>        _handlers;
00692 
00696     map<string, OlsrTypes::FaceID>  _faceid_map;
00697 
00701     map<OlsrTypes::FaceID, Face*>   _faces;
00702 
00708     typedef multimap<IPv4, DupeTuple*>  DupeTupleMap;
00709     DupeTupleMap            _duplicate_set;
00710 
00715     TimeVal _hello_interval;
00716     XorpTimer   _hello_timer;
00717 
00722     TimeVal _mid_interval;
00723     XorpTimer   _mid_timer;
00724 
00729     TimeVal _dup_hold_time;
00730 
00735     bool    _is_early_mid_enabled;
00736 };
00737 
00738 #endif // __OLSR_FACE_MANAGER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations