diff options
author | Michael Larson <slioch@eng-140.vyatta.com> | 2008-02-04 16:45:08 -0800 |
---|---|---|
committer | Michael Larson <slioch@eng-140.vyatta.com> | 2008-02-04 16:45:08 -0800 |
commit | 6fc0de67999f8d8fee10ea7e95ac5601bcb5ff36 (patch) | |
tree | 866acd3d869af8af46b4352ddb7714e7fbbbe1f6 /src | |
parent | e357cbea7769efed1fe897dd800507bc55a15231 (diff) | |
download | vyatta-wanloadbalance-6fc0de67999f8d8fee10ea7e95ac5601bcb5ff36.tar.gz vyatta-wanloadbalance-6fc0de67999f8d8fee10ea7e95ac5601bcb5ff36.zip |
whole raft of cli related changes. Fixed bugs in display output--added error checking on some configuration combinations. added
additional error checking in the code.
Diffstat (limited to 'src')
-rw-r--r-- | src/lbdata.cc | 6 | ||||
-rw-r--r-- | src/lbdata.hh | 5 | ||||
-rw-r--r-- | src/lbdatafactory.cc | 8 | ||||
-rw-r--r-- | src/lbdecision.cc | 8 | ||||
-rw-r--r-- | src/lboutput.cc | 43 |
5 files changed, 46 insertions, 24 deletions
diff --git a/src/lbdata.cc b/src/lbdata.cc index 14a04c0..57050d2 100644 --- a/src/lbdata.cc +++ b/src/lbdata.cc @@ -67,6 +67,7 @@ LBHealth::put(int rtt) LBHealthHistory::LBHealthHistory(int buffer_size) : _last_success(0), _last_failure(0), + _failure_count(0), _index(0) { _resp_data.resize(10); @@ -90,8 +91,10 @@ LBHealthHistory::push(int rtt) if (rtt == -1) { _last_failure = tv.tv_sec; + ++_failure_count; } else { + _failure_count = 0; _last_success = tv.tv_sec; } @@ -115,9 +118,10 @@ LBHealthHistory::push(int rtt) ++ct; } else { - return ct; + break; } } + return ct; } diff --git a/src/lbdata.hh b/src/lbdata.hh index 012d377..d05bf2d 100644 --- a/src/lbdata.hh +++ b/src/lbdata.hh @@ -75,6 +75,8 @@ public: unsigned long _last_success; unsigned long _last_failure; + unsigned long _failure_count; + static int _buffer_size; vector<int> _resp_data; int _index; @@ -102,6 +104,9 @@ class LBHealth { unsigned long last_failure() const {return _hresults._last_failure;} + unsigned long + failure_count() const {return _failure_ct;} + int _success_ct; int _failure_ct; string _ping_target; diff --git a/src/lbdatafactory.cc b/src/lbdatafactory.cc index ed96d72..d422c95 100644 --- a/src/lbdatafactory.cc +++ b/src/lbdatafactory.cc @@ -291,10 +291,10 @@ LBDataFactory::process_rule_source(const string &key, const string &value) _rule_iter->second._s_net = value; } else if (key == "port-name") { - _rule_iter->second._s_port_num = value; + _rule_iter->second._s_port_name = value; } else if (key == "port-number") { - _rule_iter->second._s_port_name = value; + _rule_iter->second._s_port_num = value; } } @@ -315,10 +315,10 @@ LBDataFactory::process_rule_destination(const string &key, const string &value) _rule_iter->second._d_net = value; } else if (key == "port-name") { - _rule_iter->second._d_port_num = value; + _rule_iter->second._d_port_name = value; } else if (key == "port-number") { - _rule_iter->second._d_port_name = value; + _rule_iter->second._d_port_num = value; } } diff --git a/src/lbdecision.cc b/src/lbdecision.cc index 0d256fb..23353ba 100644 --- a/src/lbdecision.cc +++ b/src/lbdecision.cc @@ -190,6 +190,7 @@ LBDecision::run(LBData &lb_data) sprintf(fbuf,"%f",w_iter->second); sprintf(dbuf,"%d",w_iter->first); execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -m state --state NEW -m statistic --mode random --probability " + fbuf + " -j ISP_" + dbuf); + ++w_iter; } //last one is special case, the catch all rule @@ -318,6 +319,13 @@ LBDecision::get_application_cmd(LBRule &rule) else if (rule._s_port_num.empty() == false) { filter += "--source-port " + rule._s_port_num + " "; } + + if (rule._d_port_name.empty() == false) { + filter += "--destination-port " + rule._d_port_name + " "; + } + else if (rule._d_port_num.empty() == false) { + filter += "--destination-port " + rule._d_port_num + " "; + } } return filter; diff --git a/src/lboutput.cc b/src/lboutput.cc index 3ab2bdf..d682dc2 100644 --- a/src/lboutput.cc +++ b/src/lboutput.cc @@ -89,42 +89,43 @@ LBOutput::write(const LBData &lbdata) unsigned long days,hours,mins,secs; days = diff_t / (60*60*24); - diff_t -= days * (60*60*24); if (days > 0) { + diff_t -= days * (60*60*24); sprintf(btmp,"%ld",days); time_buf += string(btmp) + "d"; } hours = diff_t / (60*60); - diff_t -= hours * (60*60); if (hours > 0) { + diff_t -= hours * (60*60); sprintf(btmp,"%ld",hours); time_buf += string(btmp) + "h"; } mins = diff_t / (60); - diff_t -= mins * (60); if (mins > 0) { + diff_t -= mins * (60); sprintf(btmp,"%ld",mins); time_buf += string(btmp) + "m"; } secs = diff_t; - if (secs > 0) { - sprintf(btmp,"%ld",secs); - time_buf += string(btmp) + "s"; - } + sprintf(btmp,"%ld",secs); + time_buf += string(btmp) + "s"; - if (time_buf.empty() == true) { - line += string("0s") + string("\t\t"); + if (iter->second.last_success() == 0) { + line += string("n/a") + string("\t\t"); } else { line += time_buf + string("\t"); + if (time_buf.size() < 6) { + line += string("\t"); + } } time_buf = ""; - if (iter->second.last_success() > 0) { + if (iter->second.last_failure() > 0) { diff_t = cur_t.tv_sec - iter->second.last_failure(); } else { @@ -132,39 +133,43 @@ LBOutput::write(const LBData &lbdata) } days = diff_t / (60*60*24); - diff_t -= days * (60*60*24); if (days > 0) { + diff_t -= days * (60*60*24); sprintf(btmp,"%ld",days); time_buf += string(btmp) + "d"; } hours = diff_t / (60*60); - diff_t -= hours * (60*60); if (hours > 0) { + diff_t -= hours * (60*60); sprintf(btmp,"%ld",hours); time_buf += string(btmp) + "h"; } mins = diff_t / (60); - diff_t -= mins * (60); if (mins > 0) { + diff_t -= mins * (60); sprintf(btmp,"%ld",mins); time_buf += string(btmp) + "m"; } secs = diff_t; - if (secs > 0) { - sprintf(btmp,"%ld",secs); - time_buf += string(btmp) + "s"; - } + sprintf(btmp,"%ld",secs); + time_buf += string(btmp) + "s"; - if (time_buf.empty() == true) { - line += string("0s") + string("\t\t"); + if (iter->second.last_failure() == 0) { + line += string("n/a") + string("\t\t"); } else { line += time_buf + string("\t"); + if (time_buf.size() < 6) { + line += string("\t"); + } } + //now failure count + sprintf(btmp, "%ld", iter->second._hresults._failure_count); + line += string(btmp); line += "\n"; |