void analyse_topology(char *traceroute);\r
/* implemented in networks.c */\r
\r
+char *parse_datafile_line(char *str);\r
+/* implemented in utils.c */\r
+\r
+time_t get_mtime(const char *path);\r
+/* implemented in utils.c */\r
\r
const char *tr_odd_even(void)\r
{\r
keyword->reserve_min = 8; /* bonus for nominal HTB rate bandwidth (in kbps) */\r
keyword->reserve_max = 0; /* malus for nominal HTB ceil (in kbps) */\r
keyword->default_prio = highest_priority+1;\r
+ keyword->download_aggregation = keyword->upload_aggregation = 0; /* disable by default */\r
keyword->html_color = "000000";\r
keyword->ip_count = 0;\r
keyword->leaf_discipline = "";\r
keyword->allowed_avgmtu = 0;\r
+ keyword->download_aggregation = keyword->upload_aggregation = 1;\r
\r
push(keyword, keywords);\r
if(!defaultkeyword)\r
ioption("htb-default-prio", keyword->default_prio);\r
ioption("htb-rate-bonus", keyword->reserve_min);\r
ioption("htb-ceil-malus", keyword->reserve_max);\r
+ ioption("download-aggregation", keyword->download_aggregation);\r
+ ioption("upload-aggregation", keyword->upload_aggregation);\r
option("leaf-discipline", keyword->leaf_discipline);\r
option("html-color", keyword->html_color);\r
ioption("allowed-avgmtu" ,keyword->allowed_avgmtu);\r
free(restor);\r
}\r
\r
-char *parse_datafile_line(char *str)\r
-{\r
- char *ptr = strchr(str,' ');\r
- if(!ptr)\r
- {\r
- ptr = strchr(str,'\t');\r
- }\r
-\r
- if(ptr)\r
- {\r
- *ptr = 0;\r
- ptr++;\r
- while(*ptr == ' ' || *ptr == '\t')\r
- {\r
- ptr++;\r
- }\r
- return ptr;\r
- } \r
- else \r
- {\r
- return NULL;\r
- }\r
-}\r
+/**/\r
\r
+char *parse_datafile_line(char *str);\r
+time_t get_mtime(const char *path);\r
\r
/*-----------------------------------------------------------------*/\r
/* Are you looking for int main(int argc, char **argv) ? :-)) */\r
{\r
if(start_shaping || stop_shaping || reduce_ceil)\r
{\r
- printf("Reading %s and applying Fair Use Policy rules ... \n", classmap);\r
+ time_t how_much_seconds = time(NULL) - get_mtime(classmap); /* sice start of daily aggregation session */\r
+ printf("Reading %s (%ld seconds old) and applying Fair Use Policy and Aggregation rules... \n", classmap, how_much_seconds);\r
+ \r
parse(classmap)\r
{\r
ptr=strchr(_,' ');\r
ptr++;\r
if_exists(ip,ips,eq(ip->addr,_))\r
{\r
+ int unshape_this_ip = stop_shaping;\r
+ long avg_mbps_down = ip->direct * 8 / how_much_seconds;\r
+ long avg_mbps_up = ip->upload * 8 / how_much_seconds;\r
+ int min_mbps = ip->min>>10;\r
+ int agreg = 1, print_stats = 1;\r
+ \r
+ if(min_mbps < 1)\r
+ {\r
+ min_mbps = 1;\r
+ }\r
+ \r
+ if(ip->keyword->download_aggregation)\r
+ {\r
+ if(min_mbps <= avg_mbps_down)\r
+ {\r
+ unshape_this_ip = 0;\r
+ agreg = (avg_mbps_down+1)/min_mbps;\r
+ ip->max /= agreg;\r
+ printf("Download aggregation 1:%d for %s (min: %lu Mbps avg: %ld Mbps)\n", agreg, ip->name, min_mbps, avg_mbps_down);\r
+ }\r
+ else\r
+ {\r
+ unshape_this_ip = 1;\r
+ }\r
+ }\r
+ else if(ip->keyword->upload_aggregation)\r
+ {\r
+ if(min_mbps <= avg_mbps_up)\r
+ {\r
+ unshape_this_ip = 0;\r
+ agreg = (avg_mbps_up+1)/min_mbps;\r
+ ip->max /= agreg;\r
+ printf("Upload aggregation 1:%d for %s: (min: %lu Mbps avg: %ld Mbps)\n", agreg, ip->name, min_mbps, avg_mbps_up);\r
+ }\r
+ else\r
+ {\r
+ unshape_this_ip = 1;\r
+ }\r
+ }\r
ip->mark=atoi(ptr);\r
- if(ip->max < ip->desired || stop_shaping || reduce_ceil) /* apply or disable FUP limit immediately.... */\r
+ if(ip->max < ip->desired || unshape_this_ip || reduce_ceil) /* apply or disable FUP limit immediately.... */\r
{\r
- if(stop_shaping)\r
+ if(unshape_this_ip)\r
{\r
ip->max = ip->desired;\r
- printf("Removing limit for %-22s %-16s %04d ", ip->name, ip->addr, ip->mark); \r
+ if(stop_shaping) /* all limits removed, but not printed with -s (start_shaping) switch */\r
+ {\r
+ printf("Removing limit for %s (%s) ", ip->name, ip->addr);\r
+ }\r
+ else\r
+ {\r
+ print_stats = 0;\r
+ }\r
}\r
else\r
{\r
- printf("Applying limit for %-22s %-16s %04d ", ip->name, ip->addr, ip->mark);\r
+ printf("Applying limit for %s (%s) ", ip->name, ip->addr);\r
if(reduce_ceil)\r
{\r
ip->max = ip->min + (ip->desired-ip->min)/reduce_ceil;\r
}\r
+ else if(ip->max < ip->min)\r
+ {\r
+ ip->max = ip->min;\r
+ } \r
+ }\r
+ if(print_stats)\r
+ {\r
+ printf("(down: %dk-%dk wants %dk, ", ip->min, ip->max, ip->desired);\r
}\r
- printf("(down: %dk-%dk ", ip->min, ip->max); \r
sprintf(str, "%s class change dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d", \r
tc, lan, ip->group, ip->mark,ip->min,ip->max, burst, ip->prio);\r
safe_run(str);\r
- printf("up: %dk-%dk)\n", (int)((ip->min/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), \r
- (int)((ip->max/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed));\r
+ if(print_stats)\r
+ {\r
+ printf("up: %dk-%dk wants %dk)\n", (int)((ip->min/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), \r
+ (int)((ip->desired/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed),\r
+ (int)((ip->desired/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed));\r
+ }\r
sprintf(str,"%s class change dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d",\r
tc, wan, ip->group, ip->mark,\r
(int)((ip->min/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed),\r