void connection::do_byte_calculation(packet p) { assert(this->check_packet(p)); this->byte_total += p.data_size(); if (this->src_to_dst(p)) { this->byte_src_to_dst_num += p.data_size(); return; } if (this->dst_to_src(p)) { this->byte_dst_to_src_num += p.data_size(); return; } assert(false); }
void connection::do_rtt_calculation(packet p) { assert(this->check_packet(p)); if (this->src_to_dst(p)) { if (p.syn() && !p.ack()) { this->seq_num = p.seq_number(); auto it = dst_packets.find(p.seq_number()); if (it != dst_packets.end()) { dst_packets.erase(it); this->rtts.push_back(p.ts() - it->second.ts()); } this->nxt_ack = p.seq_number() + 1; src_packets[this->nxt_ack] = p; } if (p.ack() && !p.syn()) { this->seq_num = p.seq_number(); auto it = dst_packets.find(p.seq_number()); if (it != dst_packets.end()) { dst_packets.erase(it); this->rtts.push_back(p.ts() - it->second.ts()); } this->nxt_ack = p.seq_number() + p.data_size(); src_packets[this->nxt_ack] = p; } if (p.fin()) { this->fin_set = true; this->rtt_t0 = p.ts(); } } if (this->dst_to_src(p)) { if (p.ack() && p.fin()) { if (this->fin_set) { this->rtts.push_back(p.ts() - this->rtt_t0); } } if (p.syn() && p.ack()) { auto it = src_packets.find(p.ack_number()); if (it != src_packets.end()) { src_packets.erase(it); this->rtts.push_back(p.ts() - it->second.ts()); } dst_packets[p.ack_number()] = p; } if (p.ack() && !p.syn()) { auto it = src_packets.find(p.ack_number()); if (it != src_packets.end()) { src_packets.erase(it); this->rtts.push_back(p.ts() - it->second.ts()); } dst_packets[p.ack_number()] = p; } } }