Page MenuHomec4science

cc.hh
No OneTemporary

File Metadata

Created
Mon, Jul 7, 23:19
#ifndef CLICK_CC_HH
#define CLICK_CC_HH
#include <click/element.hh>
#include <click/notifier.hh>
#include <click/confparse.hh>
#include <click/timer.hh>
#include <click/error.hh>
#include <click/etheraddress.hh>
#include <click/hashtable.hh>
#include <click/args.hh>
#include <click/string.hh>
#include <click/vector.hh>
#include <click/glue.hh> //for randomness source
#include <click/integers.hh>
#include <clicknet/tcp.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <stdint.h>
//#include <math.h> /* log */
#include "util.hh"
#include "routingpaths.hh"
#include "mfleakybucket-standalone.hh"
//For debug_output:
#ifdef CLICK_USERLEVEL
# include <stdarg.h>
#endif
//#define SCALING_FACTOR 16777216u //16777216 = 2^24
#define SCALING_FACTOR 1048576u //=2^20
CLICK_DECLS
class MFLeakyBucketSA;
/*
* class Cc:
* Click element in charge of rate-limiting the source over each route
*/
class Cc : public Element {
public:
Cc();
~Cc();
//This is to return _notifier
void *cast(const char *);
const char *class_name() const { return "Cc"; }
const char *port_count() const { return "2/1"; }
//push input 0 : packets from host
//push input 1 : control packets from network
//push output 0 : shaped traffic to leaky bucket
const char *processing() const { return "hh/h"; }
int configure(Vector<String> &, ErrorHandler *);
int initialize(ErrorHandler *);
void push(int, Packet*);
String getFirstRate();
String getAllRates();
void set_nr_routes(int n) {_nr_routes = n;}
void set_wifi_route(bool b) {_send_wifi_route = b;}
void set_plc_route(bool b) {_send_plc_route = b;}
#ifdef CLICK_USERLEVEL
void set_alpha_rate(double a) {_alpha_rate = a;}
void set_beta(double b) {_beta = b;}
void set_delta(double d) {_delta = d;}
double get_alpha_rate() {return _alpha_rate;}
double get_beta() {return _beta;}
#else
void set_alpha_rate(uint32_t a) {_alpha_rate = a;}
#endif
uint32_t get_rate(FormatedRoute route) {return _rateTable[route]._rate;}
void reset_rates();
void reset_flow(IPAddress);
void set_debug(bool b) {_debug=b;}
void set_saturate(bool b) {_saturate_routes=b;}
void set_burst_size(int a) { _burst_size = a;}
static int reset_flow_handler(const String &, Element *, void *,ErrorHandler *);
static int nr_routes_handler(const String &, Element *, void *, ErrorHandler *);
static int alpha_rate_handler(const String &, Element *, void *, ErrorHandler *);
static int beta_handler(const String &, Element *, void *, ErrorHandler *);
static int reset_rates_handler(const String &, Element *, void *, ErrorHandler *);
static int bool_handler(const String &, Element *, void *,ErrorHandler *);
static int wifi_plc_route_handler(const String &, Element *, void *,ErrorHandler *);
static int burst_size_handler(const String &, Element *, void *,ErrorHandler *);
static int delta_handler(const String &, Element *, void *, ErrorHandler *);
uint16_t getCurrentSeqNum(IPAddress const& addr);
uint16_t getCurrentSeqNum(IPAddress const& addr, bool);
void add_handlers();
private:
//////////// functions /////////////////////
uint32_t initMultiplexedRoute(Vector<Route> const& routes);
void updateAllRates();
Timestamp _now;
bool _send_wifi_route;
bool _send_plc_route;
int _max_num_hop_routes;
bool _delete_route_no_traffic;
FormatedRoute _force_packet; // force a packet (with seq 0) to get price
// send packets in bursts
int _burst_size;
int _count_packets;
FormatedRoute _route_to_send;
Timestamp _first_packet;
bool _saturate_routes;
#ifdef CLICK_USERLEVEL
double _alpha_rate;
double _alpha_rate_aggressive;
double _alpha_momentum;
double _beta; //step size for prop. fairness
double _alpha_div;
uint32_t dtMultipathUpdateController(FormatedRoute const& route, float received_price);
double derUtilityFunction(double x);
double invDerUtilityFunction(double x);
double _scaling; //scaling for gradient steps
double _delta;
#else
uint32_t _alpha_rate; //expressed in 1/1000
uint32_t _alpha_momentum; //expressed in 1/1000
uint32_t _alpha_rate_aggressive;
//scaling stuff:
uint32_t _alpha_s, _s_minus_alpha_s, _alpha_momentum_s, _s_minus_alpha_momentum_s;
uint32_t dtMultipathUpdateController(FormatedRoute const& route, uint32_t received_price);
uint64_t derUtilityFunction(uint32_t x, uint32_t scaling_factor);
int _delta;
#endif
uint32_t _init_nr_aggressive_slots; //number of initial slots during which we use a larger step size
uint32_t _nr_aggressive_slots;
void run_timer(Timer *timer);
int _drops;
ActiveNotifier _notifier;
bool _debug;
bool _experiment;
uint8_t _nr_routes;
String _routingPaths_name;
String _lb_int1_name;
String _lb_int2_name;
RoutingPaths* _routingPaths_element;
MFLeakyBucketSA* _mfl_int1;
MFLeakyBucketSA* _mfl_int2;
Timestamp _time;
Timer _update_timer; //checks dead routes
Timer _rates_timer; //update rates from rcvd prices
Timer _active_timer;
Timer _packet_timer;
uint32_t _update_period_ms; //period with which the _update_timer fires
uint32_t _rates_period_ms; //period with which the _rates_timer fires
HashTable<FormatedRoute,Timestamp> _removed_routes;
HashTable<FormatedRoute,rateTuple_entry> _rateTable;
HashTable<FormatedRoute,uint32_t> _packets_sent_table;
Timestamp _ts_packets_sent;
// keep stats to update alpha if needed
HashTable<FormatedRoute,bool> _is_rate_increasing;
HashTable<FormatedRoute, Vector<uint32_t> > _max_rates;
HashTable<FormatedRoute, Vector<uint32_t> > _min_rates;
Timestamp _last_alpha_update;
// to stop flows
HashTable<FlowTuple, int> _stop_flow_table;
#ifdef CLICK_USERLEVEL
HashTable<FormatedRoute,float> _priceTable;
#else
HashTable<FormatedRoute,uint32_t> _priceTable;
#endif
HashTable<IPAddress,uint16_t> _seqNumTable;
HashTable<IPAddress, Vector<FormatedRoute> > _dst2routes; //to know the set of routes for a given destination
//Handlers
static String rate_callback(Element *e, void *thunk);
static String rates_callback(Element *e, void *thunk);
};
CLICK_ENDDECLS
#endif

Event Timeline