diff options
| author | slioch <slioch@eng-140.vyatta.com> | 2009-07-28 14:35:37 -0700 |
|---|---|---|
| committer | slioch <slioch@eng-140.vyatta.com> | 2009-07-28 14:35:37 -0700 |
| commit | dfbf4cac22b97eab470ecd251384bf471bfed3e6 (patch) | |
| tree | 5453baa75826ec854b8bc712852fced80106d93a /src/lbtest_ttl.cc | |
| parent | fe6f0901ab0970bcc937328e6093f5b0f118230d (diff) | |
| download | vyatta-wanloadbalance-dfbf4cac22b97eab470ecd251384bf471bfed3e6.tar.gz vyatta-wanloadbalance-dfbf4cac22b97eab470ecd251384bf471bfed3e6.zip | |
reworked tests to fix bug in handling of received packets. modified show cmd output.
Diffstat (limited to 'src/lbtest_ttl.cc')
| -rw-r--r-- | src/lbtest_ttl.cc | 191 |
1 files changed, 21 insertions, 170 deletions
diff --git a/src/lbtest_ttl.cc b/src/lbtest_ttl.cc index 47d1f4d..551db07 100644 --- a/src/lbtest_ttl.cc +++ b/src/lbtest_ttl.cc @@ -30,8 +30,6 @@ #include "lbdata.hh" #include "lbtest_ttl.hh" -TTLEngine LBTestTTL::_engine; - using namespace std; /** @@ -39,30 +37,25 @@ using namespace std; * **/ void -TTLEngine::init() +LBTestTTL::init() { - if (_initialized == false) { - _results.erase(_results.begin(),_results.end()); - } if (_debug) { - cout << "TTLEngine::init(): initializing test system" << endl; + cout << "LBTestTTL::init(): initializing test system" << endl; } - _initialized = true; - _received = false; } /** * * **/ -int -TTLEngine::process(LBHealth &health,LBTestTTL *data) +void +LBTestTTL::send(LBHealth &health) { if (_debug) { - cout << "TTLEngine::process()" << endl; + cout << "LBTestTTL::process()" << endl; } //iterate over packets and send - string target = data->_target; + string target = _target; if (target.empty()) { if (health._nexthop == "dhcp") { target = health._dhcp_nexthop; @@ -74,130 +67,42 @@ TTLEngine::process(LBHealth &health,LBTestTTL *data) //don't have target yet... if (target.empty()) { - return -1; + return; } if (_debug) { - cout << "TTLEngine::process(): sending ttl test for: " << health._interface << " for " << target << endl; + cout << "LBTestTTL::process(): sending ttl test for: " << health._interface << " for " << target << endl; } _packet_id = get_new_packet_id(); - send(data->_send_raw_sock, health._interface,target,_packet_id,health._address,data->get_ttl(),data->get_port()); + send(_send_raw_sock, health._interface,target,_packet_id,health._address,get_ttl(),get_port()); _results.insert(pair<int,PktData>(_packet_id,PktData(health._interface,-1))); - return 0; -} - -/** - * - * - **/ -int -TTLEngine::recv(LBHealth &health,LBTestTTL *data) -{ - _initialized = false; - if (_received == false) { - //use gettimeofday to calculate time to millisecond - //then iterate over recv socket and receive and record - //use sysinfo to make sure we don't get stuck in a loop with timechange - struct timeval send_time; - gettimeofday(&send_time,NULL); - struct sysinfo si; - sysinfo(&si); - //for now hardcode to 5 second overall timeout - unsigned long timeout = si.uptime + 5; //seconds - unsigned long cur_time = si.uptime; - - int pending_result_ct = _results.size(); - while (cur_time < timeout && pending_result_ct != 0) { - int id = receive(data->_recv_icmp_sock); - if (_debug) { - cout << "TTLEngine::recv(): " << id << endl; - } - //update current time for comparison - struct sysinfo si; - sysinfo(&si); - cur_time = si.uptime; - timeval recv_time; - gettimeofday(&recv_time,NULL); - map<int,PktData>::iterator r_iter = _results.find(id); - if (r_iter != _results.end()) { - //calculate time in milliseconds - int secs = 0; - int msecs = recv_time.tv_usec - send_time.tv_usec; - if (msecs < 0) { - secs = recv_time.tv_sec - send_time.tv_sec - 1; - } - else { - secs = recv_time.tv_sec - send_time.tv_sec; - } - //time in milliseconds below - r_iter->second._rtt = abs(msecs) / 1000 + 1000 * secs; - --pending_result_ct; - } - else { - return -1; - } - } - if (_debug) { - cout << "TTLEngine::recv(): finished heath test" << endl; - } - _received = true; - } - //now let's just look the packet up since we are through with the receive option - map<int,PktData>::iterator r_iter = _results.begin(); - data->_state = LBTest::K_FAILURE; - while (r_iter != _results.end()) { - if (r_iter->second._iface == health._interface) { - if (r_iter->second._rtt < data->_resp_time) { - data->_state = LBTest::K_SUCCESS; - if (_debug) { - cout << "TTLEngine::recv(): success for " << r_iter->second._iface << " : " << r_iter->second._rtt << endl; - } - int rtt = r_iter->second._rtt; - _results.erase(r_iter); - return rtt; - } - else { - if (_debug) { - cout << "TTLEngine::recv(): failure for " << r_iter->second._iface << " : " << r_iter->second._rtt << endl; - } - _results.erase(r_iter); - return -1; - } - } - ++r_iter; - } - - if (_debug) { - cout << "EngineTTL::recv(): failure for " << health._interface << " : unable to find interface" << endl; - } - return -1; + return; } - /** * * **/ void -TTLEngine::send(int send_sock, const string &iface, const string &target_addr, unsigned short packet_id, string saddress, int ttl, unsigned short port) +LBTestTTL::send(int send_sock, const string &iface, const string &target_addr, unsigned short packet_id, string saddress, int ttl, unsigned short port) { if (_debug) { - cout << "TTLEngine::send(): packet_id: " << packet_id << ", ttl: " << ttl << ", port: " << port << endl; + cout << "LBTestTTL::send(): packet_id: " << packet_id << ", ttl: " << ttl << ", port: " << port << endl; } if (saddress.empty()) { if (_debug) { - cout << "TTLEngine::send() source address is empty" << endl; + cout << "LBTestTTL::send() source address is empty" << endl; } return; } if (_debug) { - cout << "TTLEngine::send() source address is: " << saddress << endl; + cout << "LBTestTTL::send() source address is: " << saddress << endl; } int err; @@ -214,7 +119,7 @@ TTLEngine::send(int send_sock, const string &iface, const string &target_addr, u struct hostent *h = gethostbyname(target_addr.c_str()); if (h == NULL) { if (_debug) { - cerr << "TTLEngine::send() Error in resolving hostname" << endl; + cerr << "LBTestTTL::send() Error in resolving hostname" << endl; } syslog(LOG_ERR, "wan_lb: error in resolving configured hostname: %s", target_addr.c_str()); return; @@ -222,8 +127,9 @@ TTLEngine::send(int send_sock, const string &iface, const string &target_addr, u // bind a socket to a device name (might not work on all systems): if (setsockopt(send_sock, SOL_SOCKET, SO_BINDTODEVICE, iface.c_str(), iface.size()) != 0) { + cout << "send sock: " << send_sock << endl; if (_debug) { - cerr << "TTLEngine::send() failure to bind to interface: " << iface << endl; + cerr << "LBTestTTL::send() failure to bind to interface: " << iface << endl; } syslog(LOG_ERR, "wan_lb: failure to bind to interface: %s", iface.c_str()); return; //will allow the test to time out then @@ -267,7 +173,7 @@ TTLEngine::send(int send_sock, const string &iface, const string &target_addr, u taddr.sin_port = packet_id; err = sendto(send_sock, buffer, sizeof(iphdr)+sizeof(udphdr)+data_length, 0, (struct sockaddr*)&taddr, sizeof(taddr)); if (_debug) { - cout << "TTLEngine::send(): send " << err << " bytes" << endl; + cout << "LBTestTTL::send(): send " << err << " bytes" << endl; } if (_debug) { if(err < 0) { @@ -299,61 +205,6 @@ TTLEngine::send(int send_sock, const string &iface, const string &target_addr, u } } -/** - * - * - **/ -int -TTLEngine::receive(int recv_sock) -{ - timeval wait_time; - int icmp_pktsize = 40; - char resp_buf[icmp_pktsize]; - icmphdr *icmp_hdr; - fd_set readfs; - - FD_ZERO(&readfs); - FD_SET(recv_sock, &readfs); - - wait_time.tv_usec = 0; - wait_time.tv_sec = 3; //3 second timeout - - if (_debug) { - cout << "TTLEngine::receive(): start" << endl; - } - - //NEW-OLD STUFF HERE - - if (select(recv_sock+1, &readfs, NULL, NULL, &wait_time) != 0) { - int bytes_recv = ::recv(recv_sock, &resp_buf, 56, MSG_PEEK); - if (bytes_recv != -1) { - if (_debug) { - cout << "TTLEngine::receive() received: " << bytes_recv << endl; - } - icmp_hdr = (struct icmphdr *)(resp_buf + sizeof(iphdr)); - if (icmp_hdr->type == ICMP_TIME_EXCEEDED) { - //process packet data - int ret = ::recv(recv_sock, &resp_buf, icmp_pktsize, 0); - if (ret != -1) { - char* data; - int id = 0; - data = (char*)(&resp_buf) + 49; - memcpy(&id, data, sizeof(unsigned short)); - if (_debug) { - cout << "TTLEngine::receive(): " << id << endl; - } - return id; - } - } - } - else { - cerr << "TTLEngine::receive(): error from recvfrom" << endl; - } - } - return -1; -} - - /** @@ -362,7 +213,7 @@ TTLEngine::receive(int recv_sock) * **/ unsigned short -TTLEngine::in_checksum(unsigned short *addr, int len) +LBTestTTL::in_checksum(unsigned short *addr, int len) { int sum = 0; unsigned short answer = 0; @@ -392,7 +243,7 @@ TTLEngine::in_checksum(unsigned short *addr, int len) * **/ unsigned short -TTLEngine::udp_checksum(unsigned char proto, char *packet, int length, unsigned long source_address, unsigned long dest_address) +LBTestTTL::udp_checksum(unsigned char proto, char *packet, int length, unsigned long source_address, unsigned long dest_address) { struct PseudoHdr { @@ -433,7 +284,7 @@ TTLEngine::udp_checksum(unsigned char proto, char *packet, int length, unsigned * **/ unsigned short -TTLEngine::get_new_packet_id() +LBTestTTL::get_new_packet_id() { if (_packet_id >= _max_port_id) _packet_id = _min_port_id; |
