diff options
author | Mike Larson <mike@suva.vyatta.com> | 2008-08-29 10:31:51 -0700 |
---|---|---|
committer | Mike Larson <mike@suva.vyatta.com> | 2008-08-29 10:31:51 -0700 |
commit | 22610d1769c6dabce2b4675085cab369f2d96331 (patch) | |
tree | b71ab147c70404a6f043a5b60f5a8a32ffb00d05 /src/lbdecision.cc | |
parent | bee9cfb28e0578a564628d61862764b3cdb2b377 (diff) | |
download | vyatta-wanloadbalance-22610d1769c6dabce2b4675085cab369f2d96331.tar.gz vyatta-wanloadbalance-22610d1769c6dabce2b4675085cab369f2d96331.zip |
add rule failover support. Failover mode can now be specified on a specific rule. This rule will only direct traffic to a single active interface, on failure of the ping target traffice will be directed out an alternate interface.
note: the one todo item for this feature is to add "stickiness" of an active interface. wlb re-evaluates all rules on an interface state change and this may cause the interface to change for failover mode. supporting this mode requires a less than trivial rewrite of the wlb decision code.:
Diffstat (limited to 'src/lbdecision.cc')
-rw-r--r-- | src/lbdecision.cc | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/lbdecision.cc b/src/lbdecision.cc index 751659d..e6cafac 100644 --- a/src/lbdecision.cc +++ b/src/lbdecision.cc @@ -307,7 +307,7 @@ LBDecision::execute(std::string cmd, std::string &stdout, bool read) char *buf = NULL; size_t len = 0; size_t read_len = 0; - while ((read_len = getline(&buf, &len, f)) != -1) { + while ((read_len = getline(&buf, &len, f)) != (size_t)-1) { stdout += string(buf) + " "; } @@ -334,12 +334,26 @@ LBDecision::get_new_weights(LBData &data, LBRule &rule) if (_debug) { cout << "LBDecision::get_new_weights(): " << iter->first << " is active: " << (data.is_active(iter->first) ? "true" : "false") << endl; } - if (data.is_active(iter->first)) { - weights.insert(pair<int,float>(ct,iter->second)); - group += iter->second; + + if (rule._failover == true) { //add single entry if active + if (weights.empty() == false) { + weights.insert(pair<int,float>(ct,0.)); + } + else { + if (data.is_active(iter->first)) { + weights.insert(pair<int,float>(ct,1.)); + group = 1; + } + } } else { - weights.insert(pair<int,float>(ct,0.)); + if (data.is_active(iter->first)) { + weights.insert(pair<int,float>(ct,iter->second)); + group += iter->second; + } + else { + weights.insert(pair<int,float>(ct,0.)); + } } ++ct; ++iter; @@ -356,7 +370,7 @@ LBDecision::get_new_weights(LBData &data, LBRule &rule) if (w_iter->second > 0.) { //can only be an integer value here w = float(w_iter->second) / float(group); } - group -= w_iter->second; //I THINK THIS NEEDS TO BE ADJUSTED TO THE OVERALL REMAINING VALUES. which is this... + group -= (int)w_iter->second; //I THINK THIS NEEDS TO BE ADJUSTED TO THE OVERALL REMAINING VALUES. which is this... if (w < .01) { weights.erase(w_iter++); continue; |