[Olsr-dev] [PATCH RFC v1 1/4] smart gateway: add SmartGatewaySpeedFile{, Period} parameters

Ferry Huberts (spam-protected)
Thu May 10 17:56:41 CEST 2012


From: Ferry Huberts <(spam-protected)>

To prepare for makeing the smart gateway uplink and downlink
settings dynamic.

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 README-Olsr-Extensions              |    7 +++++++
 files/olsrd.conf.default.full       |   14 ++++++++++++++
 files/olsrd.conf.default.lq         |   14 ++++++++++++++
 files/olsrd.conf.default.lq-fisheye |   14 ++++++++++++++
 src/cfgparser/cfgfile_gen.c         |   20 ++++++++++++++++++++
 src/cfgparser/olsrd_conf.c          |   15 +++++++++++++++
 src/cfgparser/oparse.y              |   20 ++++++++++++++++++++
 src/cfgparser/oscan.lex             |   10 ++++++++++
 src/olsr_cfg.h                      |    6 ++++++
 9 files changed, 120 insertions(+), 0 deletions(-)

diff --git a/README-Olsr-Extensions b/README-Olsr-Extensions
index a6e9d13..7d82947 100644
--- a/README-Olsr-Extensions
+++ b/README-Olsr-Extensions
@@ -282,6 +282,13 @@ All other parameters will be ignored if SmartGateway is set to "no"
    local IPv6 address to use the IPv6 gateway without any kind of address
    translation. The maximum prefix length is 64 bits,
    the default is ::/0 (no prefix).
+5- SmartGatewaySpeedFile specifies the file to watch for (dynamic) values
+   for SmartGatewaySpeed. The default is to have this setting not specified.
+6- SmartGatewaySpeedFilePeriod is the period in milliseconds on which to
+   read in the SmartGatewaySpeedFile (if it changed) and activate its new
+   setting for SmartGatewaySpeed. This setting is only relevant if
+   SmartGatewaySpeedFile has been configured. The default setting
+   is 10000 milliseconds.
 
 
     5.4) Architecture & Notes
diff --git a/files/olsrd.conf.default.full b/files/olsrd.conf.default.full
index 8088a43..1446ea9 100644
--- a/files/olsrd.conf.default.full
+++ b/files/olsrd.conf.default.full
@@ -193,6 +193,20 @@
 
 # SmartGatewayPrefix 0::/0
 
+# Specifies the file to watch for (dynamic) values for SmartGatewaySpeed.
+# If not specified then no watching is performed.
+# (default is unspecified)
+
+# SmartGatewaySpeedFile ""
+
+# Specifies the period in milliseconds on which to read the
+# SmartGatewaySpeedFile (if it changed) and activate its new setting for
+# SmartGatewaySpeed. This setting is only relevant if SmartGatewaySpeedFile
+# has been configured.
+# (default is 10000 milliseconds)
+
+# SmartGatewaySpeedFilePeriod 10000
+
 # Set to yes will make OLSRd to set the file 
 # /proc/sys/net/ipv4/ip_forward to 1 during startup. It will be
 # restored to the original value during shutdown
diff --git a/files/olsrd.conf.default.lq b/files/olsrd.conf.default.lq
index 8859eb1..c70b1e7 100644
--- a/files/olsrd.conf.default.lq
+++ b/files/olsrd.conf.default.lq
@@ -130,6 +130,20 @@
 
 # SmartGatewayPrefix 0::/0
 
+# Specifies the file to watch for (dynamic) values for SmartGatewaySpeed.
+# If not specified then no watching is performed.
+# (default is unspecified)
+
+# SmartGatewaySpeedFile ""
+
+# Specifies the period in milliseconds on which to read the
+# SmartGatewaySpeedFile (if it changed) and activate its new setting for
+# SmartGatewaySpeed. This setting is only relevant if SmartGatewaySpeedFile
+# has been configured.
+# (default is 10000 milliseconds)
+
+# SmartGatewaySpeedFilePeriod 10000
+
 ##############################
 ### OLSR protocol settings ###
 ##############################
diff --git a/files/olsrd.conf.default.lq-fisheye b/files/olsrd.conf.default.lq-fisheye
index bfbd4f5..0fc40f8 100644
--- a/files/olsrd.conf.default.lq-fisheye
+++ b/files/olsrd.conf.default.lq-fisheye
@@ -130,6 +130,20 @@
 
 # SmartGatewayPrefix 0::/0
 
+# Specifies the file to watch for (dynamic) values for SmartGatewaySpeed.
+# If not specified then no watching is performed.
+# (default is unspecified)
+
+# SmartGatewaySpeedFile ""
+
+# Specifies the period in milliseconds on which to read the
+# SmartGatewaySpeedFile (if it changed) and activate its new setting for
+# SmartGatewaySpeed. This setting is only relevant if SmartGatewaySpeedFile
+# has been configured.
+# (default is 10000 milliseconds)
+
+# SmartGatewaySpeedFilePeriod 10000
+
 ##############################
 ### OLSR protocol settings ###
 ##############################
diff --git a/src/cfgparser/cfgfile_gen.c b/src/cfgparser/cfgfile_gen.c
index dd58dc5..ea9914e 100644
--- a/src/cfgparser/cfgfile_gen.c
+++ b/src/cfgparser/cfgfile_gen.c
@@ -511,6 +511,26 @@ void olsrd_write_cnf_autobuf(struct autobuf *out, struct olsrd_config *cnf) {
       olsr_ip_prefix_to_string(&cnf->smart_gw_prefix));
   abuf_puts(out,
     "\n"
+    "# Specifies the file to watch for (dynamic) values for SmartGatewaySpeed.\n"
+    "# If not specified then no watching is performed.\n"
+    "# (default is unspecified)\n"
+    "\n");
+  abuf_appendf(out, "%sSmartGatewaySpeedFile \"%s\"\n",
+      !cnf->smart_gw_speed_file ? "# " : "",
+      !cnf->smart_gw_speed_file ? "" : cnf->smart_gw_speed_file);
+  abuf_puts(out,
+    "\n"
+    "# Specifies the period in milliseconds on which to read the\n"
+    "# SmartGatewaySpeedFile (if it changed) and activate its new setting for\n"
+    "# SmartGatewaySpeed. This setting is only relevant if SmartGatewaySpeedFile\n"
+    "# has been configured.\n"
+    "# (default is 10000 milliseconds)\n"
+    "\n");
+  abuf_appendf(out, "%sSmartGatewaySpeedFilePeriod %d\n",
+      cnf->smart_gw_speed_file_period == DEF_GW_FILE_PERIOD ? "# " : "",
+      cnf->smart_gw_speed_file_period);
+  abuf_puts(out,
+    "\n"
     "##############################\n"
     "### OLSR protocol settings ###\n"
     "##############################\n"
diff --git a/src/cfgparser/olsrd_conf.c b/src/cfgparser/olsrd_conf.c
index ad90094..17cc913 100644
--- a/src/cfgparser/olsrd_conf.c
+++ b/src/cfgparser/olsrd_conf.c
@@ -579,6 +579,15 @@ olsrd_sanity_check_cnf(struct olsrd_config *cnf)
         cnf->smart_gw_uplink, MIN_SMARTGW_SPEED, MAX_SMARTGW_SPEED);
     return -1;
   }
+  if (cnf->smart_gw_speed_file && (strlen(cnf->smart_gw_speed_file) == 0)) {
+	  cnf->smart_gw_speed_file = NULL;
+  }
+  if (cnf->smart_gw_speed_file_period < MIN_SMARTGW_SPEED_FILE_PERIOD ||
+      cnf->smart_gw_speed_file_period > MAX_SMARTGW_SPEED_FILE_PERIOD) {
+    fprintf(stderr, "Error, bad gateway speed file interval: %d seconds (should be %d-%d)\n",
+            cnf->smart_gw_speed_file_period, MIN_SMARTGW_SPEED_FILE_PERIOD, MAX_SMARTGW_SPEED_FILE_PERIOD);
+    return -1;
+  }
 
   if (cnf->interface_defaults == NULL) {
     /* get a default configuration if the user did not specify one */
@@ -781,6 +790,8 @@ set_default_cnf(struct olsrd_config *cnf)
   cnf->smart_gw_uplink = DEF_UPLINK_SPEED;
   cnf->smart_gw_uplink_nat = DEF_GW_UPLINK_NAT;
   cnf->smart_gw_downlink = DEF_DOWNLINK_SPEED;
+  cnf->smart_gw_speed_file = NULL;
+  cnf->smart_gw_speed_file_period = DEF_GW_FILE_PERIOD;
 
   cnf->use_src_ip_routes = DEF_USE_SRCIP_ROUTES;
   cnf->set_ip_forward = true;
@@ -908,6 +919,10 @@ olsrd_print_cnf(struct olsrd_config *cnf)
   printf("Smart Gw. speed  : %d kbit/s up, %d kbit/s down\n",
       cnf->smart_gw_uplink, cnf->smart_gw_downlink);
 
+  printf("Smart Gw spd file: %s\n", !cnf->smart_gw_speed_file ? "" : cnf->smart_gw_speed_file);
+
+  printf("Smart Gw spd intv: %d\n", cnf->smart_gw_speed_file_period);
+
   if (olsr_cnf->smart_gw_prefix.prefix_len == 0) {
     printf("# Smart Gw. prefix : ::/0\n");
   }
diff --git a/src/cfgparser/oparse.y b/src/cfgparser/oparse.y
index d260e58..0822bcb 100644
--- a/src/cfgparser/oparse.y
+++ b/src/cfgparser/oparse.y
@@ -222,6 +222,8 @@ static int add_ipv6_addr(YYSTYPE ipaddr_arg, YYSTYPE prefixlen_arg)
 %token TOK_SMART_GW_UPLINK
 %token TOK_SMART_GW_UPLINK_NAT
 %token TOK_SMART_GW_SPEED
+%token TOK_SMART_GW_SPEED_FILE
+%token TOK_SMART_GW_SPEED_FILE_PERIOD
 %token TOK_SMART_GW_PREFIX
 %token TOK_SRC_IP_ROUTES
 %token TOK_MAIN_IP
@@ -305,6 +307,8 @@ stmt:       idebug
           | ssmart_gw_uplink
           | bsmart_gw_uplink_nat
           | ismart_gw_speed
+          | ssmart_gw_speed_file
+          | ismart_gw_speed_file_period
           | ismart_gw_prefix
           | bsrc_ip_routes
           | amain_ip
@@ -1351,6 +1355,22 @@ ismart_gw_speed: TOK_SMART_GW_SPEED TOK_INTEGER TOK_INTEGER
 }
 ;
 
+ssmart_gw_speed_file: TOK_SMART_GW_SPEED_FILE TOK_STRING
+{
+	PARSER_DEBUG_PRINTF("Smart gateway speed file: %s\n", $2->string);
+	olsr_cnf->smart_gw_speed_file = $2->string;
+	free($2);
+}
+;
+
+ismart_gw_speed_file_period: TOK_SMART_GW_SPEED_FILE_PERIOD TOK_INTEGER
+{
+	PARSER_DEBUG_PRINTF("Smart gateway speed file interval: %u\n", $2->integer);
+	olsr_cnf->smart_gw_speed_file_period = $2->integer;
+	free($2);
+}
+;
+
 bsmart_gw_uplink_nat: TOK_SMART_GW_UPLINK_NAT TOK_BOOLEAN
 {
 	PARSER_DEBUG_PRINTF("Smart gateway uplink nat: %s\n", $2->boolean ? "yes" : "no");
diff --git a/src/cfgparser/oscan.lex b/src/cfgparser/oscan.lex
index 7c8200c..c90c801 100644
--- a/src/cfgparser/oscan.lex
+++ b/src/cfgparser/oscan.lex
@@ -501,6 +501,16 @@ IPV6ADDR {IPV6PAT1}|{IPV6PAT2}|{IPV6PAT3}|{IPV6PAT4}|{IPV6PAT5}|{IPV6PAT6}|{IPV6
     return TOK_SMART_GW_SPEED;
 }
 
+"SmartGatewaySpeedFile" {
+    yylval = NULL;
+    return TOK_SMART_GW_SPEED_FILE;
+}
+
+"SmartGatewaySpeedFilePeriod" {
+    yylval = NULL;
+    return TOK_SMART_GW_SPEED_FILE_PERIOD;
+}
+
 "SmartGatewayPrefix" {
     yylval = NULL;
     return TOK_SMART_GW_PREFIX;
diff --git a/src/olsr_cfg.h b/src/olsr_cfg.h
index 349cbc2..7eb2047 100644
--- a/src/olsr_cfg.h
+++ b/src/olsr_cfg.h
@@ -86,6 +86,7 @@
 #define DEF_GW_UPLINK_NAT    true
 #define DEF_UPLINK_SPEED     128
 #define DEF_DOWNLINK_SPEED   1024
+#define DEF_GW_FILE_PERIOD   10000
 #define DEF_USE_SRCIP_ROUTES false
 
 #define DEF_IF_MODE          IF_MODE_MESH
@@ -127,6 +128,9 @@
 #define MIN_SMARTGW_SPEED    1
 #define MAX_SMARTGW_SPEED    320000000
 
+#define MIN_SMARTGW_SPEED_FILE_PERIOD  1000
+#define MAX_SMARTGW_SPEED_FILE_PERIOD  320000000
+
 #ifndef IPV6_ADDR_SITELOCAL
 #define IPV6_ADDR_SITELOCAL    0x0040U
 #endif
@@ -274,6 +278,8 @@ struct olsrd_config {
   uint8_t smart_gw_thresh;
   enum smart_gw_uplinktype smart_gw_type;
   uint32_t smart_gw_uplink, smart_gw_downlink;
+  char * smart_gw_speed_file;
+  uint32_t smart_gw_speed_file_period;
   struct olsr_ip_prefix smart_gw_prefix;
 
   /* Main address of this node */
-- 
1.7.7.6





More information about the Olsr-dev mailing list