Hi Samuel,
The attached simple BWCounter element works out bit rate over 5 second
intervals. It is not accumulative, so each interval rate is only calculated
for that interval. I'm sure there are much more advanced and accurate
methods to use but for my purposes this was sufficient.
You might also want to have a look at <clickdir>/include/gaprate.hh
Cheers
Beyers
On 6/15/07, Samuel <[EMAIL PROTECTED]> wrote:
Hi,
I was interested in measuring the bit rate and not only the packet
rate with the Counter element. I was thinking about programming it,
but wanted to ask first in case it has been done, or it is not
achievable. I imagine I am not the first one to think about it and
perhaps someone has some views on how to get it or even some code. Has
anyone any patches to do it? Is it perhaps doable with another element
which I missed? Any useful ideas on program to do it, perhaps?
Thanks in advance,
Samu
_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click
#ifndef CLICK_BWCOUNTER_HH
#define CLICK_BWCOUNTER_HH
#include <click/element.hh>
CLICK_DECLS
class BWCounter : public Element {
public:
BWCounter();
~BWCounter();
const char *class_name() const { return "BWCounter"; }
const char *port_count() const { return "1/1"; }
const char *processing() const { return PUSH; }
void add_handlers();
static String bw_handler(Element*, void*);
void push(int, Packet *);
uint32_t _bw;
uint32_t _rate;
uint32_t _last_update;
};
CLICK_ENDDECLS
#endif
#include <click/config.h>
#include "bwcounter.hh"
#include <click/error.hh>
#include <click/confparse.hh>
#include <click/straccum.hh>
CLICK_DECLS
BWCounter::BWCounter() : _bw(0), _rate(0), _last_update(0)
{
}
BWCounter::~BWCounter()
{
}
void BWCounter::push(int, Packet *p)
{
_rate += p->length();
if ((_last_update + 5*CLICK_HZ) < click_jiffies()) {
_last_update = click_jiffies();
_bw = (_rate * 8)/5;
_rate = 0;
}
output(0).push(p);
}
String BWCounter::bw_handler(Element* e, void *thunk)
{
BWCounter *r = static_cast<BWCounter*>(e);
StringAccum sa;
sa << (uint32_t)(r->_bw/1000000) << " mbps";
return sa.take_string();
}
void BWCounter::add_handlers()
{
add_read_handler("bw", bw_handler, (void *)0);
}
CLICK_ENDDECLS
EXPORT_ELEMENT(BWCounter)
_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click