00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QOLYESTER_DAEMON_SET_TOPOLOGY_HXX
00020 # define QOLYESTER_DAEMON_SET_TOPOLOGY_HXX 1
00021
00022 # include "gra/graph.hh"
00023 # include "set/neighbors.hh"
00024
00025 # include "topology.hh"
00026
00027 namespace olsr {
00028
00029 extern sched_t scheduler;
00030 extern pathnet_t path_net;
00031 extern cproxy_t cproxy;
00032
00033 namespace set {
00034
00035 TopologyEntry::TopologyEntry() :
00036 daddr_(),
00037 laddr_(),
00038 seqnum_(0),
00039 time_(0, 0)
00040 {}
00041
00042 TopologyEntry::TopologyEntry(const address_t& d, const address_t& l,
00043 u_int16_t sn, const timeval_t& v) :
00044 daddr_(d),
00045 laddr_(l),
00046 seqnum_(sn),
00047 time_(timeval_t::in(v))
00048 {}
00049
00050 bool
00051 TopologyEntry::is_valid() const { return !time_.is_past(); }
00052
00053 void
00054 TopologyEntry::set_time(const timeval_t& t) { time_ = t; }
00055
00056 bool
00057 TopologyEntry::operator<(const This& rhs) const {
00058 return laddr_ < rhs.laddr_;
00059 }
00060
00061 const TopologyEntry&
00062 TopologyEntry::make_key(const address_t& l) {
00063 const_cast<address_t&>(dummy_for_find_.laddr_) = l;
00064 return dummy_for_find_;
00065 }
00066
00067 TopologySet::TopologySet()
00068 : tset_(),
00069 toposet_(*this, tset_)
00070 {}
00071
00072 void
00073 TopologySet::insert(const TopologyEntry& x) {
00074 tset_t::iterator pos = tset_.insert(x);
00075
00076 sch::TimedEvent* e = new updater_t(x.time(), eraser_t(*this, pos));
00077 const_cast<elem_t&>(*pos).set_updater(e);
00078 scheduler.insert(e);
00079
00080 path_net.insert_node(gra::AdjNode(x.last_addr()));
00081 path_net.insert_node(gra::AdjNode(x.dest_addr()));
00082 path_net.insert_arc(gra::AdjInfo(x.last_addr(), x.dest_addr(), topo));
00083 routes_recomp.set_mark();
00084 }
00085
00086 void
00087 TopologySet::erase(const tset_t::iterator& pos) {
00088 path_net.remove_arc(gra::AdjInfo::make_key(pos->last_addr(),
00089 pos->dest_addr(),
00090 topo));
00091 if (cproxy.sym_neighborset().find(Neighbor::make_key(pos->last_addr())) ==
00092 cproxy.sym_neighborset().end())
00093 path_net.remove_node_if_alone(gra::AdjNode::make_key(pos->last_addr()));
00094 if (cproxy.sym_neighborset().find(Neighbor::make_key(pos->dest_addr())) ==
00095 cproxy.sym_neighborset().end())
00096 path_net.remove_node_if_alone(gra::AdjNode::make_key(pos->dest_addr()));
00097
00098
00099 sch::TimedEvent* e = pos->updater();
00100 tset_.erase(pos);
00101 scheduler.destroy(e);
00102 routes_recomp.set_mark();
00103 }
00104
00105 }
00106
00107 }
00108
00109 #endif // ! QOLYESTER_DAEMON_SET_TOPOLOGY_HXX