[Click] [PATCH] Roofnet (3/3)
roberto.riggio at create-net.org
roberto.riggio at create-net.org
Mon Aug 11 06:13:45 EDT 2008
Refactoring of the sr2(*)metric elements. SR2LinkMetric now contains the common code
Signed-off-by: Roberto Riggio <roberto.riggio at create-net.org>
--
diff --git a/roofnet/sr2/sr2ettmetric.cc b/roofnet/sr2/sr2ettmetric.cc
index 5ec7689..ca1f33b 100644
--- a/roofnet/sr2/sr2ettmetric.cc
+++ b/roofnet/sr2/sr2ettmetric.cc
@@ -11,7 +11,8 @@
* holders in advertising related to the Software without their permission.
* The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
* notice is a summary of the Click LICENSE file; the license in that file is
- * legally binding. */
+ * legally binding.
+ */
#include <click/config.h>
#include <click/confparse.hh>
@@ -22,12 +23,8 @@
#include <elements/wifi/linktable.hh>
CLICK_DECLS
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
SR2ETTMetric::SR2ETTMetric()
- : SR2LinkMetric(),
- _link_table(0)
+ : SR2LinkMetric()
{
}
@@ -35,43 +32,6 @@ SR2ETTMetric::~SR2ETTMetric()
{
}
-void *
-SR2ETTMetric::cast(const char *n)
-{
- if (strcmp(n, "SR2ETTMetric") == 0)
- return (SR2ETTMetric *) this;
- else if (strcmp(n, "LinkMetric") == 0)
- return (SR2LinkMetric *) this;
- else
- return 0;
-}
-
-int
-SR2ETTMetric::configure(Vector<String> &conf, ErrorHandler *errh)
-{
- int res = cp_va_kparse(conf, this, errh,
- "LT", 0, cpElement, &_link_table,
- cpEnd);
- if (res < 0)
- return res;
- if (_link_table == 0) {
- click_chatter("%{element}: no LTelement specified",
- this);
- }
- if (_link_table && _link_table->cast("LinkTable") == 0) {
- return errh->error("LinkTable element is not a LinkTable");
- }
- return 0;
-}
-
-
-int
-SR2ETTMetric::get_tx_rate(EtherAddress)
-{
-
- return 2;
-}
-
void
SR2ETTMetric::update_link(IPAddress from, IPAddress to,
Vector<SR2RateSize> rs,
@@ -88,7 +48,7 @@ SR2ETTMetric::update_link(IPAddress from, IPAddress to,
}
- int one_ack_fwd = 0;
+ int one_ack_fwd = 0;
int one_ack_rev = 0;
int six_ack_fwd = 0;
int six_ack_rev = 0;
@@ -165,7 +125,6 @@ SR2ETTMetric::update_link(IPAddress from, IPAddress to,
}
}
}
-
/* update linktable */
if (fwd_metric &&
@@ -188,8 +147,7 @@ SR2ETTMetric::update_link(IPAddress from, IPAddress to,
}
}
-
-ELEMENT_PROVIDES(GridGenericMetric)
-ELEMENT_REQUIRES(bitrate)
EXPORT_ELEMENT(SR2ETTMetric)
+ELEMENT_REQUIRES(bitrate)
+ELEMENT_REQUIRES(SR2LinkMetric)
CLICK_ENDDECLS
diff --git a/roofnet/sr2/sr2ettmetric.hh b/roofnet/sr2/sr2ettmetric.hh
index d54b322..2d50e8d 100644
--- a/roofnet/sr2/sr2ettmetric.hh
+++ b/roofnet/sr2/sr2ettmetric.hh
@@ -20,8 +20,6 @@ CLICK_DECLS
*
*/
-
-
inline unsigned sr2_ett_metric(int ack_prob, int data_prob, int data_rate)
{
@@ -38,34 +36,20 @@ inline unsigned sr2_ett_metric(int ack_prob, int data_prob, int data_rate)
}
-class ETTStat;
-
class SR2ETTMetric : public SR2LinkMetric {
public:
-
SR2ETTMetric();
~SR2ETTMetric();
const char *class_name() const { return "SR2ETTMetric"; }
const char *processing() const { return AGNOSTIC; }
- int configure(Vector<String> &, ErrorHandler *);
-
- void *cast(const char *);
-
- static String read_stats(Element *xf, void *);
-
void update_link(IPAddress from, IPAddress to,
Vector<SR2RateSize> rs,
Vector<int> fwd, Vector<int> rev,
uint32_t seq);
- int get_tx_rate(EtherAddress);
-
-private:
- class LinkTable *_link_table;
-
};
CLICK_ENDDECLS
diff --git a/roofnet/sr2/sr2linkmetric.hh b/roofnet/sr2/sr2linkmetric.hh
index 3b1d1d3..e927bb1 100644
--- a/roofnet/sr2/sr2linkmetric.hh
+++ b/roofnet/sr2/sr2linkmetric.hh
@@ -2,15 +2,19 @@
#define SR2LINKMETRIC_HH
#include <click/element.hh>
#include <click/ipaddress.hh>
+#include "sr2ettstat.hh"
CLICK_DECLS
class SR2LinkMetric : public Element {
public:
- SR2LinkMetric() { }
-
- virtual ~SR2LinkMetric() { }
+ SR2LinkMetric();
+ virtual ~SR2LinkMetric();
+ int configure(Vector<String> &, ErrorHandler *);
+
+protected:
+ class LinkTable *_link_table;
};
diff --git a/roofnet/sr2/sr2txcountmetric.cc b/roofnet/sr2/sr2txcountmetric.cc
index e021031..ccedbc4 100644
--- a/roofnet/sr2/sr2txcountmetric.cc
+++ b/roofnet/sr2/sr2txcountmetric.cc
@@ -22,12 +22,8 @@
#include <elements/wifi/linktable.hh>
CLICK_DECLS
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
SR2TXCountMetric::SR2TXCountMetric()
- : SR2LinkMetric(),
- _link_table(0)
+ : SR2LinkMetric()
{
}
@@ -35,37 +31,6 @@ SR2TXCountMetric::~SR2TXCountMetric()
{
}
-void *
-SR2TXCountMetric::cast(const char *n)
-{
- if (strcmp(n, "SR2TXCountMetric") == 0)
- return (SR2TXCountMetric *) this;
- else if (strcmp(n, "SR2LinkMetric") == 0)
- return (SR2LinkMetric *) this;
- else
- return 0;
-}
-
-int
-SR2TXCountMetric::configure(Vector<String> &conf, ErrorHandler *errh)
-{
- int res = cp_va_kparse(conf, this, errh,
- "LT", 0, cpElement, &_link_table,
- cpEnd);
- if (res < 0)
- return res;
- if (_link_table == 0) {
- click_chatter("%{element}: no LTelement specified",
- this);
- }
- if (_link_table && _link_table->cast("LinkTable") == 0) {
- return errh->error("LinkTable element is not a LinkTable");
- }
- return 0;
-}
-
-
-
void
SR2TXCountMetric::update_link(IPAddress from, IPAddress to,
Vector<SR2RateSize>,
@@ -99,7 +64,7 @@ SR2TXCountMetric::update_link(IPAddress from, IPAddress to,
}
}
-
EXPORT_ELEMENT(SR2TXCountMetric)
ELEMENT_REQUIRES(bitrate)
+ELEMENT_REQUIRES(SR2LinkMetric)
CLICK_ENDDECLS
diff --git a/roofnet/sr2/sr2txcountmetric.hh b/roofnet/sr2/sr2txcountmetric.hh
index 12cf039..55e8f8f 100644
--- a/roofnet/sr2/sr2txcountmetric.hh
+++ b/roofnet/sr2/sr2txcountmetric.hh
@@ -11,56 +11,29 @@ CLICK_DECLS
/*
* =c
- * SR2TXCountMetric(LinkStat, LinkStat)
+ * SR2ETTMetric
* =s Wifi
- * The Estimated Transmission Count metric (ETX).
- * =a ETTMetric
+ * Estimated Transmission Count metric (ETX).
+ *
+ * =io
+ * None
+ *
*/
-
-
-inline unsigned sr2_txcount_metric(int ack_prob, int data_prob, int data_rate)
-{
-
- if (!ack_prob || ! data_prob) {
- return 0;
- }
- int retries = 100 * 100 * 100 / (ack_prob * data_prob) - 100;
- unsigned low_usecs = calc_usecs_wifi_packet(1500, data_rate, retries/100);
- unsigned high_usecs = calc_usecs_wifi_packet(1500, data_rate, (retries/100) + 1);
-
- unsigned diff = retries % 100;
- unsigned average = (diff * high_usecs + (100 - diff) * low_usecs) / 100;
- return average;
-
-}
-
-class ETTStat;
-
class SR2TXCountMetric : public SR2LinkMetric {
public:
-
SR2TXCountMetric();
~SR2TXCountMetric();
const char *class_name() const { return "SR2TXCountMetric"; }
const char *processing() const { return AGNOSTIC; }
- int configure(Vector<String> &, ErrorHandler *);
-
- void *cast(const char *);
-
- static String read_stats(Element *xf, void *);
-
void update_link(IPAddress from, IPAddress to,
Vector<SR2RateSize> rs,
Vector<int> fwd, Vector<int> rev,
uint32_t seq);
-private:
- class LinkTable *_link_table;
-
};
CLICK_ENDDECLS
More information about the click
mailing list