From: fendo Date: Tue, 26 Feb 2013 10:50:44 +0000 (+0100) Subject: Add cli show group and update rate calculation X-Git-Tag: 2.2.1-2sames3.8~7 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/b15e1bf64eb16c1d9bc53f464380fe012f25faaa?ds=inline;hp=df35f4d66fd01268fe4456994368b76a541acec4 Add cli show group and update rate calculation --- diff --git a/cli.c b/cli.c index 65afb43..c39eac0 100644 --- a/cli.c +++ b/cli.c @@ -78,6 +78,7 @@ static char *debug_levels[] = { #endif static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int argc); +static int cmd_show_group(struct cli_def *cli, char *command, char **argv, int argc); static int cmd_show_tunnels(struct cli_def *cli, char *command, char **argv, int argc); static int cmd_show_users(struct cli_def *cli, char *command, char **argv, int argc); static int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int argc); @@ -161,6 +162,7 @@ void init_cli() cli_register_command(cli, c, "remotelns-conf", cmd_show_rmtlnsconf, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Show a list of remote LNS configuration"); #endif cli_register_command(cli, c, "session", cmd_show_session, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of sessions or details for a single session"); + cli_register_command(cli, c, "group", cmd_show_group, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of groups or details for a single group"); cli_register_command(cli, c, "tbf", cmd_show_tbf, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "List all token bucket filters in use"); cli_register_command(cli, c, "throttle", cmd_show_throttle, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "List all throttled sessions and associated TBFs"); cli_register_command(cli, c, "tunnels", cmd_show_tunnels, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of tunnels or details for a single tunnel"); @@ -3107,7 +3109,7 @@ static int cmd_show_access_list(struct cli_def *cli, char *command, char **argv, } if (i) - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "%s IP access list %s", ip_filters[f].extended ? "Extended" : "Standard", @@ -3145,6 +3147,77 @@ static int cmd_reload(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } +static int cmd_show_group(struct cli_def *cli, char *command, char **argv, int argc) +{ + int i; + groupidt g; + + if (CLI_HELP_REQUESTED) + return cli_arg_help(cli, 1, + "<1-%d>", MAXGROUPE-1, "Show specific group by id", + NULL); + + time(&time_now); + if (argc > 0) + { + // Show individual group + for (i = 0; i < argc; i++) + { + sessionidt s; + + g = atoi(argv[i]); + if (g <= 0 || g >= MAXGROUPE) + { + cli_print(cli, "Invalid group id \"%s\"", argv[i]); + continue; + } + + cli_print(cli, "\r\nGroup %d:", g); + cli_print(cli, "\tNb Session:\t\t%d", grpsession[g].nbsession); + cli_print(cli, "\tNb Routes:\t\t%d", grpsession[g].nbroutesgrp); + cli_print(cli, "\ttime_changed:\t\t%d\n", grpsession[g].time_changed); + + for (i = 0; i < grpsession[g].nbsession; i++) + { + if ((s = grpsession[g].sesslist[i].sid)) + { + cli_print(cli, "\tSession:\t%d\tTx Rate:%d Kbps\t\t\tweight:\t%d", + s, + grpsession[g].sesslist[i].tx_rate/(1024/8), + grpsession[g].sesslist[i].weight); + } + } + + for (i = 0; i < grpsession[g].nbroutesgrp; i++) + { + if (grpsession[g].route[i].ip != 0) + { + cli_print(cli, "\tRoute:\t%s/%d", fmtaddr(htonl(grpsession[g].route[i].ip), 0), grpsession[g].route[i].prefixlen); + } + } + } + return CLI_OK; + } + + // Show Summary + cli_print(cli, "%5s %7s %9s %12s", + "GID", + "Nb Sess", + "Nb Routes", + "Time changed"); + + for (g = gnextgrpid; g != 0; g = grpsession[g].prev) + { + cli_print(cli, "%5d %7d %9d %12d", + g, + grpsession[g].nbsession, + grpsession[g].nbroutesgrp, + grpsession[g].time_changed); + } + + return CLI_OK; +} + #ifdef LAC static int cmd_setforward(struct cli_def *cli, char *command, char **argv, int argc) diff --git a/grpsess.c b/grpsess.c index a26c489..bfc7d8d 100644 --- a/grpsess.c +++ b/grpsess.c @@ -22,7 +22,7 @@ union grp_iphash { union grp_iphash *idx; } grp_ip_hash[256]; // Mapping from IP address to group structures. -static groupidt gnextgrpid = 0; +groupidt gnextgrpid = 0; // Find gruop by IP, < 1 for not found // @@ -483,7 +483,7 @@ static void grp_uncache_ipsession(groupidt g, sessionidt s) // return the next session can be used on the group sessionidt grp_getnextsession(groupidt g, in_addr_t ip) { - sessionidt s = 0, s2 = 0, s3 = 0, smax = 0; + sessionidt s = 0, s2 = 0, s3 = 0; int i; uint32_t ltime_changed = 0, mintxrate = 0xFFFFFFFF, maxtxrate = 0; uint32_t txrate; @@ -491,43 +491,25 @@ sessionidt grp_getnextsession(groupidt g, in_addr_t ip) if (g >= MAXGROUPE) return 0; - if (grpsession[g].time_changed < config->grp_txrate_average_time) - { - if ((s = sessionbyip(ip))) - { - if ( (session[s].ppp.phase > Establish) && - (time_now - session[s].last_packet <= (config->echo_timeout + 1)) ) - { - return s; - } - s = 0; - } - } - else + if (grpsession[g].time_changed >= config->grp_txrate_average_time) { // recalculation txrate ltime_changed = grpsession[g].time_changed; grpsession[g].time_changed = 0; - s = 0; for (i = 0; i < grpsession[g].nbsession; i++) { if ((s2 = grpsession[g].sesslist[i].sid)) { - s3 = s2; - grpsession[g].sesslist[i].tx_rate = session[s2].coutgrp_delta/ltime_changed; session[s2].coutgrp_delta = 0; - //LOG(3, s2, session[s2].tunnel, "TX Rate: %d session weight: %d\n", - // grpsession[g].sesslist[i].tx_rate, grpsession[g].sesslist[i].weight); - txrate = grpsession[g].sesslist[i].tx_rate/grpsession[g].sesslist[i].weight; if (txrate < mintxrate) { if ( session[s2].ppp.phase > Establish && (time_now - session[s2].last_packet <= (config->echo_timeout + 1)) ) { - s = s2; + grpsession[g].smin = s2; mintxrate = txrate; } } @@ -537,16 +519,29 @@ sessionidt grp_getnextsession(groupidt g, in_addr_t ip) if ( session[s2].ppp.phase > Establish && (time_now - session[s2].last_packet <= (config->echo_timeout + 1)) ) { - smax = s2; + grpsession[g].smax = s2; maxtxrate = txrate; } } } } + } - if (smax && (maxtxrate != mintxrate)) + if ((s = sessionbyip(ip))) + { + if (s == grpsession[g].smax) + { + s = grpsession[g].smin; + grpsession[g].smax = 0; + } + else if ( (session[s].ppp.phase > Establish) && + (time_now - session[s].last_packet <= (config->echo_timeout + 1)) ) { - grp_uncache_ipsession(g, smax); + return s; + } + else + { + s = 0; } } @@ -564,7 +559,6 @@ sessionidt grp_getnextsession(groupidt g, in_addr_t ip) (time_now - session[s2].last_packet <= (config->echo_timeout + 1))) { s = s2; - //LOG(3, s, session[s].tunnel, "New random session\n"); } else { diff --git a/l2tpns.h b/l2tpns.h index fd7e0ba..2274e0a 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -351,6 +351,8 @@ typedef struct { uint32_t time_changed; groupidt prev; + sessionidt smax; + sessionidt smin; groupsessionidt sesslist[MAXSESSINGRP]; routet route[MAXROUTEINGRP]; // static routes uint8_t nbroutesgrp; @@ -1032,6 +1034,7 @@ extern sessiont *session; extern sessionlocalt *sess_local; extern ippoolt *ip_address_pool; extern groupsesst *grpsession; +groupidt gnextgrpid; #define sessionfree (session[0].next)