00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QOLYESTER_DAEMON_SET_DUPLICATE_HH
00020 # define QOLYESTER_DAEMON_SET_DUPLICATE_HH 1
00021
00022 # include <sys/types.h>
00023 # include <set>
00024 # include "utl/timeval.hh"
00025 # include "sch/scheduler.hh"
00026 # include "utl/set.hh"
00027 # include "cst/constants.hh"
00028 # include "net/ipaddress.hh"
00029
00030 namespace olsr {
00031
00032 namespace sch {
00033
00034 class StatePrinter;
00035
00036 }
00037
00038 namespace set {
00039
00040 class DuplicateEntry {
00041 typedef DuplicateEntry This;
00042 typedef std::set<address_t> ifaces_t;
00043
00044 inline DuplicateEntry();
00045 public:
00046 inline DuplicateEntry(const address_t& a, u_int16_t s,
00047 const address_t& i, bool r);
00048
00049 virtual ~DuplicateEntry() {}
00050
00051 bool is_valid() const { return !time_.is_past(); }
00052 const timeval_t& time() const { return time_; }
00053 void set_time(const timeval_t& t =
00054 timeval_t::in(cst::dup_hold_time)) {
00055 time_ = t;
00056 }
00057
00058 bool retransmitted() const { return retransmitted_; }
00059 void set_retransmitted() { retransmitted_ = true; }
00060
00061 ifaces_t& ifaces() { return ifaces_; }
00062 const ifaces_t& ifaces() const { return ifaces_; }
00063
00064 inline bool in_ifaces(const address_t& a) const;
00065 inline void add_iface(const address_t& a);
00066 inline bool operator<(const This& rhs) const;
00067
00068 static inline This make_key(const address_t& a, u_int16_t s);
00069 private:
00070 const address_t addr_;
00071 const u_int16_t seqnum_;
00072 bool retransmitted_;
00073 ifaces_t ifaces_;
00074 timeval_t time_;
00075
00076 static This dummy_for_find_;
00077
00078 friend class sch::StatePrinter;
00079 };
00080
00081 class DuplicateSet {
00082 typedef DuplicateSet This;
00083 typedef sch::Updatable<DuplicateEntry> elem_t;
00084 typedef std::set<elem_t> dset_t;
00085 typedef sch::upd::SetEraser<This, dset_t::iterator> eraser_t;
00086 typedef sch::UpdateEvent<eraser_t> updater_t;
00087
00088 typedef utl::Subset<dset_t,
00089 utl::NoAction<This, dset_t::iterator>,
00090 utl::DefaultPredicate<This, dset_t::iterator>,
00091 This> val_dset_t;
00092 public:
00093 typedef val_dset_t dupset_t;
00094
00095 dupset_t& dupset() { return dupset_; }
00096
00097 inline DuplicateSet();
00098
00099 inline void insert(const DuplicateEntry& x);
00100 inline void erase(const dset_t::iterator& pos);
00101 private:
00102 dset_t dset_;
00103 dupset_t dupset_;
00104
00105 friend class sch::StatePrinter;
00106 };
00107
00108 }
00109
00110 typedef set::DuplicateSet dupset_t;
00111 extern dupset_t dup_set;
00112
00113 }
00114
00115 # include "duplicate.hxx"
00116
00117 #endif // ! QOLYESTER_DAEMON_SET_DUPLICATE_HH