00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _RL_HT_H_
00028 #define _RL_HT_H_
00029
00030 #include "../../str.h"
00031
00032 typedef struct _pl_pipe
00033 {
00034 unsigned int cellid;
00035 str name;
00036
00037
00038 int algo;
00039 int limit;
00040
00041
00042 int counter;
00043 int last_counter;
00044 int load;
00045
00046 struct _pl_pipe *prev;
00047 struct _pl_pipe *next;
00048 } pl_pipe_t;
00049
00050 typedef struct _rlp_slot
00051 {
00052 unsigned int ssize;
00053 pl_pipe_t *first;
00054 gen_lock_t lock;
00055 } rlp_slot_t;
00056
00057 typedef struct _rlp_htable
00058 {
00059 unsigned int htsize;
00060 rlp_slot_t *slots;
00061 } rlp_htable_t;
00062
00063 int pl_init_htable(unsigned int hsize);
00064 int pl_destroy_htable(void);
00065 void pl_pipe_release(str *pipeid);
00066 pl_pipe_t* pl_pipe_get(str *pipeid, int mode);
00067 int pl_pipe_add(str *pipeid, str *algorithm, int limit);
00068 int pl_print_pipes(void);
00069 int pl_pipe_check_feedback_setpoints(int *cfgsp);
00070 void pl_pipe_timer_update(int interval, int netload);
00071
00072 void rpl_pipe_lock(int slot);
00073 void rpl_pipe_release(int slot);
00074
00075
00076
00077
00078
00079
00080 enum {
00081 PIPE_ALGO_NOP = 0,
00082 PIPE_ALGO_RED,
00083 PIPE_ALGO_TAILDROP,
00084 PIPE_ALGO_FEEDBACK,
00085 PIPE_ALGO_NETWORK
00086 };
00087
00088 typedef struct str_map {
00089 str str;
00090 int id;
00091 } str_map_t;
00092
00093 extern str_map_t algo_names[];
00094
00095 static inline int str_cmp(const str * a , const str * b)
00096 {
00097 return ! (a->len == b->len && ! strncmp(a->s, b->s, a->len));
00098 }
00099
00100 static inline int str_i_cmp(const str * a, const str * b)
00101 {
00102 return ! (a->len == b->len && ! strncasecmp(a->s, b->s, a->len));
00103 }
00104
00109 static inline int str_map_str(const str_map_t * map, const str * key, int * ret)
00110 {
00111 for (; map->str.s; map++)
00112 if (! str_cmp(&map->str, key)) {
00113 *ret = map->id;
00114 return 0;
00115 }
00116 LM_DBG("str_map_str() failed map=%p key=%.*s\n", map, key->len, key->s);
00117 return -1;
00118 }
00119
00124 static inline int str_map_int(const str_map_t * map, int key, str * ret)
00125 {
00126 for (; map->str.s; map++)
00127 if (map->id == key) {
00128 *ret = map->str;
00129 return 0;
00130 }
00131 LM_DBG("str_map_str() failed map=%p key=%d\n", map, key);
00132 return -1;
00133 }
00134
00139 static inline int str_cpy(str * dest, str * src)
00140 {
00141 dest->len = src->len;
00142 dest->s = shm_malloc(src->len);
00143 if (! dest->s) {
00144 LM_ERR("oom: '%.*s'\n", src->len, src->s);
00145 return -1;
00146 }
00147 memcpy(dest->s, src->s, src->len);
00148 return 0;
00149 }
00150
00151
00152 #endif