00001 #ifndef D__metric
00002 #define D__metric
00003
00004
00005 #include <awds/NodeId.h>
00006 #include <awds/NodeDescr.h>
00007 #include <awds/Topology.h>
00008
00009 #include <limits>
00010
00011 #include <iostream>
00012
00013 namespace awds {
00014
00015 class Routing;
00016
00022 class Metric {
00023 protected:
00024 Routing *routing;
00025
00026 virtual RTopology::link_quality_t my_get_quality(NodeDescr &ndescr) {
00027 return 10;
00028 }
00029
00030 virtual uint32_t my_calculate( RTopology::link_quality_t forward,
00031 RTopology::link_quality_t backward) {
00032
00033
00034 return 1;
00035 }
00036 public:
00037 Metric(Routing *r):routing(r) {
00038 }
00039
00040 virtual ~Metric() {}
00041
00042
00045 virtual void addNode(const NodeId& nodeId) {}
00046
00049 virtual void delNode(const NodeId& nodeId) {}
00050
00054 virtual void begin_update() {}
00055
00059 virtual void end_update() {}
00060
00064 virtual int update() {
00065 return 8;
00066 }
00067
00071 RTopology::link_quality_t get_quality(NodeDescr &ndescr) {
00072
00073 return std::max( std::min(my_get_quality(ndescr), RTopology::max_quality()),
00074 (RTopology::link_quality_t)1);
00075 }
00076
00080 uint32_t calculate(RTopology::LinkList::iterator &it) {
00081 RTopology::link_quality_t f,b;
00082 uint32_t mw = std::numeric_limits<uint32_t>::max();
00083
00084 if (it->get_qualities(f,b))
00085 mw = my_calculate(f,b);
00086
00087 mw = std::min(mw, std::numeric_limits<uint32_t>::max() / 1024U);
00088
00089 it->set_metric_weight(mw);
00090 return mw;
00091 }
00092
00093 };
00094 }
00095
00096 #endif // D__metric
00097
00098
00099
00100
00101
00102
00103