[Olsr-dev] [PATCH v1 2/5] sgw: do not write uplink/downlink speed directly

Ferry Huberts (spam-protected)
Fri May 8 10:12:38 CEST 2015


From: Ferry Huberts <(spam-protected)>

So that we can keep a boolean on whether the speed is zero, which
is needed in a later patch.

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 lib/sgwdynspeed/src/speedFile.c |  4 ++--
 src/cfgparser/olsrd_conf.c      |  5 +++--
 src/cfgparser/oparse.y          |  5 +++--
 src/gateway.c                   |  8 ++++----
 src/olsr_cfg.h                  | 23 +++++++++++++++++++++++
 5 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/lib/sgwdynspeed/src/speedFile.c b/lib/sgwdynspeed/src/speedFile.c
index bf3a246..0937da2 100644
--- a/lib/sgwdynspeed/src/speedFile.c
+++ b/lib/sgwdynspeed/src/speedFile.c
@@ -264,10 +264,10 @@ void readSpeedFile(char * fileName) {
 	fp = NULL;
 
 	if (uplinkSet) {
-		olsr_cnf->smart_gw_uplink = uplink;
+	  smartgw_set_uplink(olsr_cnf, uplink);
 	}
 	if (downlinkSet) {
-		olsr_cnf->smart_gw_downlink = downlink;
+	  smartgw_set_downlink(olsr_cnf, downlink);
 	}
 	if (uplinkSet || downlinkSet) {
 	  refresh_smartgw_netmask();
diff --git a/src/cfgparser/olsrd_conf.c b/src/cfgparser/olsrd_conf.c
index 30e2829..6365d48 100644
--- a/src/cfgparser/olsrd_conf.c
+++ b/src/cfgparser/olsrd_conf.c
@@ -46,6 +46,7 @@
 #include "net_olsr.h"
 #include "olsr.h"
 #include "egressTypes.h"
+#include "gateway.h"
 
 #include <assert.h>
 #include <stdio.h>
@@ -999,9 +1000,9 @@ set_default_cnf(struct olsrd_config *cnf, char * configuration_file)
   cnf->smart_gw_weight_etx = DEF_GW_WEIGHT_ETX;
   cnf->smart_gw_divider_etx = DEF_GW_DIVIDER_ETX;
   cnf->smart_gw_type = DEF_GW_TYPE;
-  cnf->smart_gw_uplink = DEF_UPLINK_SPEED;
+  smartgw_set_uplink(cnf, DEF_UPLINK_SPEED);
   cnf->smart_gw_uplink_nat = DEF_GW_UPLINK_NAT;
-  cnf->smart_gw_downlink = DEF_DOWNLINK_SPEED;
+  smartgw_set_downlink(cnf, DEF_DOWNLINK_SPEED);
 
   cnf->use_src_ip_routes = DEF_USE_SRCIP_ROUTES;
   cnf->set_ip_forward = true;
diff --git a/src/cfgparser/oparse.y b/src/cfgparser/oparse.y
index 5301598..aa42842 100644
--- a/src/cfgparser/oparse.y
+++ b/src/cfgparser/oparse.y
@@ -48,6 +48,7 @@
 #include "../link_set.h"
 #include "../olsr.h"
 #include "../egressTypes.h"
+#include "../gateway.h"
 
 #include <stddef.h>
 #include <stdio.h>
@@ -1579,8 +1580,8 @@ ssmart_gw_uplink: TOK_SMART_GW_UPLINK TOK_STRING
 ismart_gw_speed: TOK_SMART_GW_SPEED TOK_INTEGER TOK_INTEGER
 {
 	PARSER_DEBUG_PRINTF("Smart gateway speed: %u uplink/%u downlink kbit/s\n", $2->integer, $3->integer);
-	olsr_cnf->smart_gw_uplink = $2->integer;
-	olsr_cnf->smart_gw_downlink = $3->integer;
+	smartgw_set_uplink(olsr_cnf, $2->integer);
+	smartgw_set_downlink(olsr_cnf, $3->integer);
 	free($2);
 	free($3);
 }
diff --git a/src/gateway.c b/src/gateway.c
index 88092de..0e67876 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -1522,11 +1522,11 @@ static bool determineBestEgressLink(enum sgw_multi_change_phase phase) {
 
   if (changed || MSGW_ROUTE_FORCED(phase)) {
     if (!bestEgressLink || !bestEgressLink->upCurrent) {
-      olsr_cnf->smart_gw_uplink = 0;
-      olsr_cnf->smart_gw_downlink = 0;
+      smartgw_set_uplink(olsr_cnf, 0);
+      smartgw_set_downlink(olsr_cnf, 0);
     } else {
-      olsr_cnf->smart_gw_uplink = bestEgressLink->bwCurrent.egressUk;
-      olsr_cnf->smart_gw_downlink = bestEgressLink->bwCurrent.egressDk;
+      smartgw_set_uplink(olsr_cnf, bestEgressLink->bwCurrent.egressUk);
+      smartgw_set_downlink(olsr_cnf, bestEgressLink->bwCurrent.egressDk);
     }
     refresh_smartgw_netmask();
   }
diff --git a/src/olsr_cfg.h b/src/olsr_cfg.h
index 00cda23..8eb9938 100644
--- a/src/olsr_cfg.h
+++ b/src/olsr_cfg.h
@@ -333,6 +333,7 @@ struct olsrd_config {
   uint32_t smart_gw_divider_etx;
   enum smart_gw_uplinktype smart_gw_type;
   uint32_t smart_gw_uplink, smart_gw_downlink;
+  bool smart_gateway_bandwidth_zero;
   struct olsr_ip_prefix smart_gw_prefix;
 
   /* Main address of this node */
@@ -429,6 +430,28 @@ extern "C" {
   void win32_olsrd_free(void *ptr);
 #endif /* defined _WIN32 */
 
+  /*
+   * Smart-Gateway uplink/downlink accessors
+   */
+
+  static inline void set_smart_gateway_bandwidth_zero(struct olsrd_config *cnf) {
+    cnf->smart_gateway_bandwidth_zero = !cnf->smart_gw_uplink || !cnf->smart_gw_downlink;
+  }
+
+  static inline void smartgw_set_uplink(struct olsrd_config *cnf, uint32_t uplink) {
+    cnf->smart_gw_uplink = uplink;
+    set_smart_gateway_bandwidth_zero(cnf);
+  }
+
+  static inline void smartgw_set_downlink(struct olsrd_config *cnf, uint32_t downlink) {
+    cnf->smart_gw_downlink = downlink;
+    set_smart_gateway_bandwidth_zero(cnf);
+  }
+
+  static inline bool smartgw_is_zero_bandwidth(struct olsrd_config *cnf) {
+    return cnf->smart_gateway_bandwidth_zero;
+  }
+
 #if defined __cplusplus
 }
 #endif /* defined __cplusplus */
-- 
2.1.0





More information about the Olsr-dev mailing list