48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include <cstdio>
|
|
#include <vector>
|
|
#include "VpnPeer.hpp"
|
|
|
|
template<int len>
|
|
std::string bitset_to_string(
|
|
const std::bitset<len>& bs,
|
|
char c_f, char c_t, size_t mark_pos, char cm_f, char cm_t)
|
|
{
|
|
std::string out;
|
|
for(size_t pos=0; pos < len; ++pos) {
|
|
if(pos == mark_pos)
|
|
out += bs[pos] ? cm_t : cm_f;
|
|
else
|
|
out += bs[pos] ? c_t : c_f;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
void dump(PacketLossLogger& pllog, int received) {
|
|
printf("%03d, %.03lf ## %s ## %s\n",
|
|
received,
|
|
pllog.get_loss_rate(),
|
|
bitset_to_string<PACKET_LOSS_HISTSIZE>(
|
|
pllog.get_loss_hist(), '_', 'X',
|
|
pllog.get_cur_seqno() % PACKET_LOSS_HISTSIZE,
|
|
'|', '#').c_str(),
|
|
bitset_to_string<PACKET_LOST_AFTER>(
|
|
pllog.get_received_ahead(), '_', 'X',
|
|
pllog.get_cur_seqno() % PACKET_LOST_AFTER,
|
|
'|', '#').c_str());
|
|
}
|
|
|
|
int main(void) {
|
|
PacketLossLogger pllog;
|
|
std::vector<int> sequence({
|
|
1, 2, 3, 5, 6, 4, 8, 7, 8, 9,
|
|
12, 13, 14, 15, 16, 17, 18, 19, 20, 10, 21
|
|
});
|
|
|
|
dump(pllog, 0);
|
|
for(auto val=sequence.begin(); val != sequence.end(); ++val) {
|
|
pllog.log_packet(*val);
|
|
dump(pllog, *val);
|
|
}
|
|
|
|
return 0;
|
|
}
|