xorp

face.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/face.hh,v 1.3 2008/10/02 21:56:34 bms Exp $
00022 
00023 #ifndef __OLSR_FACE_HH__
00024 #define __OLSR_FACE_HH__
00025 
00026 class FaceManager;
00027 class Packet;
00028 class Link;
00029 class Message;
00030 class MessageDecoder;
00031 class Neighborhood;
00032 class Olsr;
00033 class XorpTimer;
00034 
00038 class FaceCounters {
00039 public:
00040     FaceCounters()
00041      : _bad_packets(0),
00042        _bad_messages(0),
00043        _duplicates(0),
00044        _messages_from_self(0),
00045        _unknown_messages(0),
00046        _forwarded(0)
00047     {}
00048 
00049     inline size_t bad_packets() const { return _bad_packets; }
00050     inline void incr_bad_packets() { _bad_packets++; }
00051 
00052     inline size_t bad_messages() const { return _bad_messages; }
00053     inline void incr_bad_messages() { _bad_messages++; }
00054 
00055     inline size_t messages_from_self() const { return _messages_from_self; }
00056     inline void incr_messages_from_self() { _messages_from_self++; }
00057 
00058     inline size_t unknown_messages() const { return _unknown_messages; }
00059     inline void incr_unknown_messages() { _unknown_messages++; }
00060 
00061     inline size_t duplicates() const { return _duplicates; }
00062     inline void incr_duplicates() { _duplicates++; }
00063 
00064     inline size_t forwarded() const { return _forwarded; }
00065     inline void incr_forwarded() { _forwarded++; }
00066 
00067 private:
00071     uint32_t        _bad_packets;
00072 
00076     uint32_t        _bad_messages;
00077 
00082     uint32_t        _duplicates;
00083 
00088     uint32_t        _messages_from_self;
00089 
00093     uint32_t        _unknown_messages;
00094 
00099     uint32_t        _forwarded;
00100 };
00101 
00127 class Face {
00128   public:
00129     Face(Olsr& olsr, FaceManager& fm, Neighborhood* nh,
00130      MessageDecoder& md,
00131      const string& interface, const string& vif,
00132      OlsrTypes::FaceID id);
00133 
00137     inline OlsrTypes::FaceID id() const { return _id; }
00138 
00142     string interface() const { return _interface; }
00143 
00147     string vif() const { return _vif; }
00148 
00152     FaceCounters& counters() {
00153     return _counters;
00154     }
00155 
00159     const FaceCounters& counters() const {
00160     return _counters;
00161     }
00162 
00166     inline uint32_t mtu() const { return _mtu; }
00167 
00171     inline void set_mtu(const uint32_t mtu) { _mtu = mtu; }
00172 
00177     inline uint32_t get_pkt_seqno() { return _next_pkt_seqno++; }
00178 
00182     inline bool enabled() const {
00183       return _enabled;
00184     }
00185 
00189     inline IPv4 all_nodes_addr() const {
00190       return _all_nodes_addr;
00191     }
00192 
00196     inline uint16_t all_nodes_port() const {
00197       return _all_nodes_port;
00198     }
00199 
00203     inline IPv4 local_addr() const {
00204       return _local_addr;
00205     }
00206 
00210     inline uint16_t local_port() const {
00211       return _local_port;
00212     }
00213 
00218     inline int cost() const {
00219       return _cost;
00220     }
00221 
00228     void set_enabled(bool value);
00229 
00235     inline void set_all_nodes_addr(const IPv4& all_nodes_addr) {
00236     _all_nodes_addr = all_nodes_addr;
00237     }
00238 
00244     inline void set_all_nodes_port(const uint16_t all_nodes_port) {
00245     _all_nodes_port = all_nodes_port;
00246     }
00247 
00253     inline void set_local_addr(const IPv4& local_addr) {
00254     _local_addr = local_addr;
00255     }
00256 
00262     inline void set_local_port(const uint16_t local_port) {
00263     _local_port = local_port;
00264     }
00265 
00271     inline void set_cost(int cost) {
00272     _cost = cost;
00273     }
00274 
00282     bool transmit(uint8_t* data, const uint32_t& len);
00283 
00292     void originate_hello();
00293 
00294   private:
00295     Olsr&       _olsr;
00296     FaceManager&    _fm;
00297     Neighborhood*   _nh;
00298     MessageDecoder& _md;
00299 
00303     FaceCounters    _counters;
00304 
00308     OlsrTypes::FaceID   _id;
00309 
00313     bool        _enabled;
00314 
00318     string      _interface;
00319 
00323     string      _vif;
00324 
00328     uint32_t        _mtu;
00329 
00334     IPv4        _local_addr;
00335 
00340     uint16_t        _local_port;
00341 
00346     IPv4        _all_nodes_addr;
00347 
00352     uint16_t        _all_nodes_port;
00353 
00357     int         _cost;
00358 
00362     uint32_t        _next_pkt_seqno;
00363 };
00364 
00365 #endif // __OLSR_FACE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations