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 if(register_mi_mod(exports.name, mi_cmds)!=0)
00114 {
00115 LM_ERR("failed to register MI commands\n");
00116 return -1;
00117 }
00118
00119
00120 timer_lock=lock_alloc();
00121 if (timer_lock==0) {
00122 LM_ERR(" alloc locks failed!\n");
00123 goto error1;
00124 }
00125
00126 if (lock_init(timer_lock)==0){
00127 LM_ERR(" init lock failed\n");
00128 goto error1;
00129 }
00130
00131
00132 if ( init_ip_tree(max_reqs)!=0 ) {
00133 LM_ERR(" ip_tree creation failed!\n");
00134 goto error2;
00135 }
00136
00137
00138 timer = (struct list_link*)shm_malloc(sizeof(struct list_link));
00139 if (timer==0) {
00140 LM_ERR(" cannot alloc shm mem for timer!\n");
00141 goto error3;
00142 }
00143 timer->next = timer->prev = timer;
00144
00145
00146 register_timer( clean_routine , 0, 1 );
00147 register_timer( swap_routine , 0, time_unit );
00148
00149 return 0;
00150 error3:
00151 destroy_ip_tree();
00152 error2:
00153 lock_destroy(timer_lock);
00154 error1:
00155 if (timer_lock) lock_dealloc(timer_lock);
00156 timer_lock = 0;
00157 return -1;
00158 }
00159
00160
00161
00162 static int pike_exit(void)
00163 {
00164
00165 if (timer_lock) {
00166 lock_destroy(timer_lock);
00167 lock_dealloc(timer_lock);
00168 }
00169
00170
00171 if (timer) {
00172 shm_free(timer);
00173 timer = 0;
00174 }
00175
00176
00177 destroy_ip_tree();
00178
00179 return 0;
00180 }
00181
00182