[Olsr-dev] [PATCH v3 1/1] smart gateway: add threshold configuration parameter

Ferry Huberts (spam-protected)
Tue Dec 13 09:44:01 CET 2011


Henning,

can we push this? comments?


On 12/12/2011 02:13 PM, Ferry Huberts wrote:
> From: Ferry Huberts <(spam-protected)>
> 
> We can now keep choosing a better gateway by setting the
> configuration setting "SmartGatewayThreshold" to a value
> larger than zero.
> 
> The costs for a new smart gateway must be less than the
> costs of the current smart gateway multiplied by
> SmartGatewayThreshold in order for it to be chosen as
> the new smart gateway.
> 
> This new configuration parameter has a similar function
> and meaning as the NAT threshold configuration parameter.
> 
> Signed-off-by: Ferry Huberts <(spam-protected)>
> ---
>  README-Olsr-Extensions              |    1 +
>  files/olsrd.conf.default.full       |    7 +++++++
>  files/olsrd.conf.default.lq         |    7 +++++++
>  files/olsrd.conf.default.lq-fisheye |    7 +++++++
>  src/cfgparser/cfgfile_gen.c         |   10 ++++++++++
>  src/cfgparser/olsrd_conf.c          |    8 ++++++++
>  src/cfgparser/oparse.y              |   10 ++++++++++
>  src/cfgparser/oscan.lex             |    5 +++++
>  src/gateway_default_handler.c       |   16 +++++++++++-----
>  src/olsr_cfg.h                      |    2 ++
>  10 files changed, 68 insertions(+), 5 deletions(-)
> 
> diff --git a/README-Olsr-Extensions b/README-Olsr-Extensions
> index f7b9e33..6000f2a 100644
> --- a/README-Olsr-Extensions
> +++ b/README-Olsr-Extensions
> @@ -268,6 +268,7 @@ set up the type of the uplink:
>     translation. The maximum prefix length is 64 bits,
>     the default is ::/0 (no prefix).
>  
> +SmartGatewayThreshold <threshold>
>  SmartGatewayUplink <none/ipv4/ipv6/both>
>  SmartGatewayUplinkNAT <yes/no>
>  SmartGatewaySpeed <uplink> <downlink>
> diff --git a/files/olsrd.conf.default.full b/files/olsrd.conf.default.full
> index 83e614b..cd06900 100644
> --- a/files/olsrd.conf.default.full
> +++ b/files/olsrd.conf.default.full
> @@ -149,6 +149,13 @@
>  
>  # SmartGatewayAllowNAT yes
>  
> +# When another gateway than the current one has a cost of less than the cost
> +# of the current gateway multiplied by SmartGatewayThreshold then the smart
> +# gateway is switched to the other gateway. The unit is percentage.
> +# (defaults to 0)
> +
> +# SmartGatewayThreshold 0
> +
>  # Defines what kind of Uplink this node will publish as a
>  # smartgateway. The existence of the uplink is detected by
>  # a route to 0.0.0.0/0, ::ffff:0:0/96 and/or 2000::/3.
> diff --git a/files/olsrd.conf.default.lq b/files/olsrd.conf.default.lq
> index 466f001..a986eed 100644
> --- a/files/olsrd.conf.default.lq
> +++ b/files/olsrd.conf.default.lq
> @@ -86,6 +86,13 @@
>  
>  # SmartGatewayAllowNAT yes
>  
> +# When another gateway than the current one has a cost of less than the cost
> +# of the current gateway multiplied by SmartGatewayThreshold then the smart
> +# gateway is switched to the other gateway. The unit is percentage.
> +# (defaults to 0)
> +
> +# SmartGatewayThreshold 0
> +
>  # Defines what kind of Uplink this node will publish as a
>  # smartgateway. The existence of the uplink is detected by
>  # a route to 0.0.0.0/0, ::ffff:0:0/96 and/or 2000::/3.
> diff --git a/files/olsrd.conf.default.lq-fisheye b/files/olsrd.conf.default.lq-fisheye
> index ce5d8e5..c277ef6 100644
> --- a/files/olsrd.conf.default.lq-fisheye
> +++ b/files/olsrd.conf.default.lq-fisheye
> @@ -86,6 +86,13 @@
>  
>  # SmartGatewayAllowNAT yes
>  
> +# When another gateway than the current one has a cost of less than the cost
> +# of the current gateway multiplied by SmartGatewayThreshold then the smart
> +# gateway is switched to the other gateway. The unit is percentage.
> +# (defaults to 0)
> +
> +# SmartGatewayThreshold 0
> +
>  # Defines what kind of Uplink this node will publish as a
>  # smartgateway. The existence of the uplink is detected by
>  # a route to 0.0.0.0/0, ::ffff:0:0/96 and/or 2000::/3.
> diff --git a/src/cfgparser/cfgfile_gen.c b/src/cfgparser/cfgfile_gen.c
> index fc4ba12..6cfc3b4 100644
> --- a/src/cfgparser/cfgfile_gen.c
> +++ b/src/cfgparser/cfgfile_gen.c
> @@ -446,6 +446,16 @@ void olsrd_write_cnf_autobuf(struct autobuf *out, struct olsrd_config *cnf) {
>        cnf->smart_gw_allow_nat ? "yes" : "no");
>    abuf_puts(out,
>      "\n"
> +    "# When another gateway than the current one has a cost of less than the cost\n"
> +    "# of the current gateway multiplied by SmartGatewayThreshold then the smart\n"
> +    "# gateway is switched to the other gateway. The unit is percentage.\n"
> +    "# (defaults to 0)\n"
> +    "\n");
> +  abuf_appendf(out, "%sSmartGatewayThreshold  %d\n",
> +      cnf->smart_gw_thresh == DEF_GW_THRESH ? "# " : "",
> +      cnf->smart_gw_thresh);
> +  abuf_puts(out,
> +    "\n"
>      "# Defines what kind of Uplink this node will publish as a\n"
>      "# smartgateway. The existence of the uplink is detected by\n"
>      "# a route to 0.0.0.0/0, ::ffff:0:0/96 and/or 2000::/3.\n"
> diff --git a/src/cfgparser/olsrd_conf.c b/src/cfgparser/olsrd_conf.c
> index 95690e7..4c8734f 100644
> --- a/src/cfgparser/olsrd_conf.c
> +++ b/src/cfgparser/olsrd_conf.c
> @@ -549,6 +549,11 @@ olsrd_sanity_check_cnf(struct olsrd_config *cnf)
>  	  fprintf(stderr, "Warning, you are using the min_tc_vtime hack. We hope you know what you are doing... contact olsr.org otherwise.\n");
>    }
>  
> +  if (((cnf->smart_gw_thresh < 10) || (cnf->smart_gw_thresh > 100)) && (cnf->smart_gw_thresh != 0)) {
> +    fprintf(stderr, "Smart gateway threshold %d is not allowed\n", cnf->smart_gw_thresh);
> +    return -1;
> +  }
> +
>    if (cnf->smart_gw_type >= GW_UPLINK_CNT) {
>      fprintf(stderr, "Error, illegal gateway uplink type: %d\n", cnf->smart_gw_type);
>      return -1;
> @@ -758,6 +763,7 @@ set_default_cnf(struct olsrd_config *cnf)
>  
>    cnf->smart_gw_active = DEF_SMART_GW;
>    cnf->smart_gw_allow_nat = DEF_GW_ALLOW_NAT;
> +  cnf->smart_gw_thresh = DEF_GW_THRESH;
>    cnf->smart_gw_type = DEF_GW_TYPE;
>    cnf->smart_gw_uplink = DEF_UPLINK_SPEED;
>    cnf->smart_gw_uplink_nat = DEF_GW_UPLINK_NAT;
> @@ -875,6 +881,8 @@ olsrd_print_cnf(struct olsrd_config *cnf)
>  
>    printf("SmGw. Allow NAT  : %s\n", cnf->smart_gw_allow_nat ? "yes" : "no");
>  
> +  printf("SmGw. threshold  : %d%%\n", cnf->smart_gw_thresh);
> +
>    printf("Smart Gw. Uplink : %s\n", GW_UPLINK_TXT[cnf->smart_gw_type]);
>  
>    printf("SmGw. Uplink NAT : %s\n", cnf->smart_gw_uplink_nat ? "yes" : "no");
> diff --git a/src/cfgparser/oparse.y b/src/cfgparser/oparse.y
> index 24c9a41..80667c4 100644
> --- a/src/cfgparser/oparse.y
> +++ b/src/cfgparser/oparse.y
> @@ -216,6 +216,7 @@ static int add_ipv6_addr(YYSTYPE ipaddr_arg, YYSTYPE prefixlen_arg)
>  %token TOK_USE_NIIT
>  %token TOK_SMART_GW
>  %token TOK_SMART_GW_ALLOW_NAT
> +%token TOK_SMART_GW_THRESH
>  %token TOK_SMART_GW_UPLINK
>  %token TOK_SMART_GW_UPLINK_NAT
>  %token TOK_SMART_GW_SPEED
> @@ -295,6 +296,7 @@ stmt:       idebug
>            | suse_niit
>            | bsmart_gw
>            | bsmart_gw_allow_nat
> +          | asmart_gw_thresh
>            | ssmart_gw_uplink
>            | bsmart_gw_uplink_nat
>            | ismart_gw_speed
> @@ -1286,6 +1288,14 @@ bsmart_gw_allow_nat: TOK_SMART_GW_ALLOW_NAT TOK_BOOLEAN
>  }
>  ;
>  
> +asmart_gw_thresh: TOK_SMART_GW_THRESH TOK_INTEGER
> +{
> +  PARSER_DEBUG_PRINTF("Smart gateway threshold: %d\n", $2->integer);
> +  olsr_cnf->smart_gw_thresh = $2->integer;
> +  free($2);
> +}
> +;
> +
>  ssmart_gw_uplink: TOK_SMART_GW_UPLINK TOK_STRING
>  {
>  	PARSER_DEBUG_PRINTF("Smart gateway uplink: %s\n", $2->string);
> diff --git a/src/cfgparser/oscan.lex b/src/cfgparser/oscan.lex
> index 25a4ecb..ab1469b 100644
> --- a/src/cfgparser/oscan.lex
> +++ b/src/cfgparser/oscan.lex
> @@ -471,6 +471,11 @@ IPV6ADDR {IPV6PAT1}|{IPV6PAT2}|{IPV6PAT3}|{IPV6PAT4}|{IPV6PAT5}|{IPV6PAT6}|{IPV6
>      return TOK_SMART_GW_ALLOW_NAT;
>  }
>  
> +"SmartGatewayThreshold" {
> +    yylval = NULL;
> +    return TOK_SMART_GW_THRESH;
> +}
> +
>  "SmartGatewayUplink" {
>      yylval = NULL;
>      return TOK_SMART_GW_UPLINK;
> diff --git a/src/gateway_default_handler.c b/src/gateway_default_handler.c
> index a18dba8..c569a6e 100644
> --- a/src/gateway_default_handler.c
> +++ b/src/gateway_default_handler.c
> @@ -43,6 +43,7 @@ static void gw_default_choose_gateway(void) {
>    olsr_linkcost cost_ipv4, cost_ipv6;
>    struct gateway_entry *gw;
>    bool dual;
> +  olsr_linkcost path_cost_times_threshold;
>  
>    cost_ipv4 = ROUTE_COST_BROKEN;
>    cost_ipv6 = ROUTE_COST_BROKEN;
> @@ -56,13 +57,18 @@ static void gw_default_choose_gateway(void) {
>        continue;
>      }
>  
> -    if (!gw_def_finished_ipv4 && gw->ipv4 && gw->ipv4nat == olsr_cnf->smart_gw_allow_nat && tc->path_cost < cost_ipv4) {
> +    if (olsr_cnf->smart_gw_thresh == 0) {
> +      path_cost_times_threshold = tc->path_cost;
> +    } else {
> +      path_cost_times_threshold = ((long long)tc->path_cost * (long long)olsr_cnf->smart_gw_thresh + 50LL) / 100LL;
> +    }
> +    if (!gw_def_finished_ipv4 && gw->ipv4 && gw->ipv4nat == olsr_cnf->smart_gw_allow_nat && path_cost_times_threshold < cost_ipv4) {
>        inet_ipv4 = gw;
> -      cost_ipv4 = tc->path_cost;
> +      cost_ipv4 = path_cost_times_threshold;
>      }
> -    if (!gw_def_finished_ipv6 && gw->ipv6 && tc->path_cost < cost_ipv6) {
> +    if (!gw_def_finished_ipv6 && gw->ipv6 && path_cost_times_threshold < cost_ipv6) {
>        inet_ipv6 = gw;
> -      cost_ipv6 = tc->path_cost;
> +      cost_ipv6 = path_cost_times_threshold;
>      }
>    } OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
>  
> @@ -78,7 +84,7 @@ static void gw_default_choose_gateway(void) {
>    }
>  
>    /* finished ? */
> -  if (gw_def_finished_ipv4 && gw_def_finished_ipv6) {
> +  if ((olsr_cnf->smart_gw_thresh == 0) && gw_def_finished_ipv4 && gw_def_finished_ipv6) {
>      olsr_stop_timer(gw_def_timer);
>      gw_def_timer = NULL;
>    }
> diff --git a/src/olsr_cfg.h b/src/olsr_cfg.h
> index b944706..3e55003 100644
> --- a/src/olsr_cfg.h
> +++ b/src/olsr_cfg.h
> @@ -79,6 +79,7 @@
>  #define DEF_USE_NIIT         true
>  #define DEF_SMART_GW         false
>  #define DEF_GW_ALLOW_NAT     true
> +#define DEF_GW_THRESH        0
>  #define DEF_GW_TYPE          GW_UPLINK_IPV46
>  #define DEF_GW_UPLINK_NAT    true
>  #define DEF_UPLINK_SPEED     128
> @@ -255,6 +256,7 @@ struct olsrd_config {
>    bool use_niit;
>  
>    bool smart_gw_active, smart_gw_allow_nat, smart_gw_uplink_nat;
> +  uint8_t smart_gw_thresh;
>    enum smart_gw_uplinktype smart_gw_type;
>    uint32_t smart_gw_uplink, smart_gw_downlink;
>    struct olsr_ip_prefix smart_gw_prefix;


-- 
Ferry Huberts




More information about the Olsr-dev mailing list