Add controls for MTU size of virtual socket server
This will allow us to write tests for what happens when large datagrams are discarded. Bug: webrtc:12495 Change-Id: I5c8e9fe55917967ea4604e1b3abe3c590c330ffa Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211044 Reviewed-by: Taylor <deadbeef@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33425}
This commit is contained in:
parent
bccfd26322
commit
3d792e990a
@ -900,7 +900,22 @@ int VirtualSocketServer::SendUdp(VirtualSocket* socket,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (data_size > largest_seen_udp_payload_) {
|
||||
if (data_size > 1000) {
|
||||
RTC_LOG(LS_VERBOSE) << "Largest UDP seen is " << data_size;
|
||||
}
|
||||
largest_seen_udp_payload_ = data_size;
|
||||
}
|
||||
|
||||
// See if we want to drop this packet.
|
||||
if (data_size > max_udp_payload_) {
|
||||
RTC_LOG(LS_VERBOSE) << "Dropping too large UDP payload of size "
|
||||
<< data_size << ", UDP payload limit is "
|
||||
<< max_udp_payload_;
|
||||
// Return as if send was successful; packet disappears.
|
||||
return data_size;
|
||||
}
|
||||
|
||||
if (Random() < drop_prob_) {
|
||||
RTC_LOG(LS_VERBOSE) << "Dropping packet: bad luck";
|
||||
return static_cast<int>(data_size);
|
||||
|
||||
@ -94,6 +94,16 @@ class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> {
|
||||
drop_prob_ = drop_prob;
|
||||
}
|
||||
|
||||
// Controls the maximum UDP payload for the networks simulated
|
||||
// by this server. Any UDP payload sent that is larger than this will
|
||||
// be dropped.
|
||||
size_t max_udp_payload() { return max_udp_payload_; }
|
||||
void set_max_udp_payload(size_t payload_size) {
|
||||
max_udp_payload_ = payload_size;
|
||||
}
|
||||
|
||||
size_t largest_seen_udp_payload() { return largest_seen_udp_payload_; }
|
||||
|
||||
// If |blocked| is true, subsequent attempts to send will result in -1 being
|
||||
// returned, with the socket error set to EWOULDBLOCK.
|
||||
//
|
||||
@ -308,6 +318,13 @@ class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> {
|
||||
std::unique_ptr<Function> delay_dist_;
|
||||
|
||||
double drop_prob_;
|
||||
// The largest UDP payload permitted on this virtual socket server.
|
||||
// The default is the max size of IPv4 fragmented UDP packet payload:
|
||||
// 65535 bytes - 8 bytes UDP header - 20 bytes IP header.
|
||||
size_t max_udp_payload_ = 65507;
|
||||
// The largest UDP payload seen so far.
|
||||
size_t largest_seen_udp_payload_ = 0;
|
||||
|
||||
bool sending_blocked_ = false;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user