1 /*
2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10 #include "api/test/network_emulation/network_emulation_interfaces.h"
11
12 #include "rtc_base/net_helper.h"
13
14 namespace webrtc {
15
EmulatedIpPacket(const rtc::SocketAddress & from,const rtc::SocketAddress & to,rtc::CopyOnWriteBuffer data,Timestamp arrival_time,uint16_t application_overhead)16 EmulatedIpPacket::EmulatedIpPacket(const rtc::SocketAddress& from,
17 const rtc::SocketAddress& to,
18 rtc::CopyOnWriteBuffer data,
19 Timestamp arrival_time,
20 uint16_t application_overhead)
21 : from(from),
22 to(to),
23 data(data),
24 headers_size(to.ipaddr().overhead() + application_overhead +
25 cricket::kUdpHeaderSize),
26 arrival_time(arrival_time) {
27 RTC_DCHECK(to.family() == AF_INET || to.family() == AF_INET6);
28 }
29
AverageSendRate() const30 DataRate EmulatedNetworkOutgoingStats::AverageSendRate() const {
31 RTC_DCHECK_GE(packets_sent, 2);
32 RTC_DCHECK(first_packet_sent_time.IsFinite());
33 RTC_DCHECK(last_packet_sent_time.IsFinite());
34 return (bytes_sent - first_sent_packet_size) /
35 (last_packet_sent_time - first_packet_sent_time);
36 }
37
AverageReceiveRate() const38 DataRate EmulatedNetworkIncomingStats::AverageReceiveRate() const {
39 RTC_DCHECK_GE(packets_received, 2);
40 RTC_DCHECK(first_packet_received_time.IsFinite());
41 RTC_DCHECK(last_packet_received_time.IsFinite());
42 return (bytes_received - first_received_packet_size) /
43 (last_packet_received_time - first_packet_received_time);
44 }
45
46 } // namespace webrtc
47