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
00028
00029
00030
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <stdlib.h>
00038 #include <unistd.h>
00039 #include <fcntl.h>
00040
00041 #include "../../sr_module.h"
00042 #include "../../error.h"
00043 #include "../../dprint.h"
00044 #include "../../ut.h"
00045 #include "../../mem/shm_mem.h"
00046 #include "../../timer.h"
00047 #include "../../locking.h"
00048 #include "ip_tree.h"
00049 #include "timer.h"
00050 #include "pike_mi.h"
00051 #include "pike_funcs.h"
00052
00053 MODULE_VERSION
00054
00055
00056
00057 static int pike_init(void);
00058 static int pike_exit(void);
00059
00060
00061
00062
00063 static int time_unit = 2;
00064 static int max_reqs = 30;
00065 int timeout = 120;
00066 int pike_log_level = L_WARN;
00067
00068
00069 gen_lock_t* timer_lock=0;
00070 struct list_link* timer = 0;
00071
00072
00073 static cmd_export_t cmds[]={
00074 {"pike_check_req", (cmd_function)pike_check_req, 0, 0, 0, REQUEST_ROUTE},
00075 {0,0,0,0,0,0}
00076 };
00077
00078 static param_export_t params[]={
00079 {"sampling_time_unit", INT_PARAM, &time_unit},
00080 {"reqs_density_per_unit", INT_PARAM, &max_reqs},
00081 {"remove_latency", INT_PARAM, &timeout},
00082 {"pike_log_level", INT_PARAM, &pike_log_level},
00083 {0,0,0}
00084 };
00085
00086
00087 static mi_export_t mi_cmds [] = {
00088 {MI_PIKE_LIST, mi_pike_list, MI_NO_INPUT_FLAG, 0, 0 },
00089 {0,0,0,0,0}
00090 };
00091
00092
00093 struct module_exports exports= {
00094 "pike",
00095 DEFAULT_DLFLAGS,
00096 cmds,
00097 params,
00098 0,
00099 mi_cmds,
00100 0,
00101 0,
00102 pike_init,
00103 0,
00104 (destroy_function) pike_exit,
00105 0
00106 };
00107
00108
00109
00110
00111 static int pike_init(void)
00112 {
00113
00114 timer_lock=lock_alloc();
00115 if (timer_lock==0) {
00116 LM_ERR(" alloc locks failed!\n");
00117 goto error1;
00118 }
00119
00120 if (lock_init(timer_lock)==0){
00121 LM_ERR(" init lock failed\n");
00122 goto error1;
00123 }
00124
00125
00126 if ( init_ip_tree(max_reqs)!=0 ) {
00127 LM_ERR(" ip_tree creation failed!\n");
00128 goto error2;
00129 }
00130
00131
00132 timer = (struct list_link*)shm_malloc(sizeof(struct list_link));
00133 if (timer==0) {
00134 LM_ERR(" cannot alloc shm mem for timer!\n");
00135 goto error3;
00136 }
00137 timer->next = timer->prev = timer;
00138
00139
00140 register_timer( clean_routine , 0, 1 );
00141 register_timer( swap_routine , 0, time_unit );
00142
00143 return 0;
00144 error3:
00145 destroy_ip_tree();
00146 error2:
00147 lock_destroy(timer_lock);
00148 error1:
00149 if (timer_lock) lock_dealloc(timer_lock);
00150 timer_lock = 0;
00151 return -1;
00152 }
00153
00154
00155
00156 static int pike_exit(void)
00157 {
00158
00159 if (timer_lock) {
00160 lock_destroy(timer_lock);
00161 lock_dealloc(timer_lock);
00162 }
00163
00164
00165 if (timer) {
00166 shm_free(timer);
00167 timer = 0;
00168 }
00169
00170
00171 destroy_ip_tree();
00172
00173 return 0;
00174 }
00175
00176