* Parse and return back the stats report * * \param [in] sock Socket to read the stats message from * \param [out] stats Reference to stats report data * * \return true if error, false if no error */
| 718 | * \return true if error, false if no error |
| 719 | */ |
| 720 | bool parseBMP::handleStatsReport(int sock, MsgBusInterface::obj_stats_report &stats) { |
| 721 | unsigned long stats_cnt = 0; // Number of counter stat objects to follow |
| 722 | unsigned char b[8]; |
| 723 | |
| 724 | if ((Recv(sock, b, 4, MSG_WAITALL)) != 4) |
| 725 | throw "ERROR: Cannot proceed since we cannot read the stats mon counter"; |
| 726 | |
| 727 | bmp_len -= 4; |
| 728 | |
| 729 | // Reverse the bytes and update int |
| 730 | bgp::SWAP_BYTES(b, 4); |
| 731 | memcpy((void*) &stats_cnt, (void*) b, 4); |
| 732 | |
| 733 | SELF_DEBUG("sock = %d : STATS REPORT Count: %u (%d %d %d %d)", |
| 734 | sock, stats_cnt, b[0], b[1], b[2], b[3]); |
| 735 | |
| 736 | // Vars used per counter object |
| 737 | unsigned short stat_type = 0; |
| 738 | unsigned short stat_len = 0; |
| 739 | |
| 740 | // Loop through each stats object |
| 741 | for (unsigned long i = 0; i < stats_cnt; i++) { |
| 742 | |
| 743 | if ((Recv(sock, &stat_type, 2, MSG_WAITALL)) != 2) |
| 744 | throw "ERROR: Cannot proceed since we cannot read the stats type."; |
| 745 | if ((Recv(sock, &stat_len, 2, MSG_WAITALL)) != 2) |
| 746 | throw "ERROR: Cannot proceed since we cannot read the stats len."; |
| 747 | |
| 748 | bmp_len -= 4; |
| 749 | |
| 750 | // convert integer from network to host bytes |
| 751 | bgp::SWAP_BYTES(&stat_type); |
| 752 | bgp::SWAP_BYTES(&stat_len); |
| 753 | |
| 754 | SELF_DEBUG("sock=%d STATS: %lu : TYPE = %u LEN = %u", sock, |
| 755 | i, stat_type, stat_len); |
| 756 | |
| 757 | // check if this is a 32 bit number (default) |
| 758 | if (stat_len == 4 or stat_len == 8) { |
| 759 | |
| 760 | // Read the stats counter - 32/64 bits |
| 761 | if ((Recv(sock, b, stat_len, MSG_WAITALL)) == stat_len) { |
| 762 | bmp_len -= stat_len; |
| 763 | |
| 764 | // convert the bytes from network to host order |
| 765 | bgp::SWAP_BYTES(b, stat_len); |
| 766 | |
| 767 | // Update the table structure based on the stats counter type |
| 768 | switch (stat_type) { |
| 769 | case STATS_PREFIX_REJ: |
| 770 | memcpy((void*) &stats.prefixes_rej, (void*) b, stat_len); |
| 771 | break; |
| 772 | case STATS_DUP_PREFIX: |
| 773 | memcpy((void*) &stats.known_dup_prefixes, (void*) b, stat_len); |
| 774 | break; |
| 775 | case STATS_DUP_WITHDRAW: |
| 776 | memcpy((void*) &stats.known_dup_withdraws, (void*) b, stat_len); |
| 777 | break; |
no test coverage detected