Run clang format on pseudotcp/test

Bug: webrtc:5273
Change-Id: Ib2e5b749951c805417fd50022172c604a4fe241b
Reviewed-on: https://webrtc-review.googlesource.com/27122
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21128}
This commit is contained in:
Steve Anton 2017-11-29 10:19:58 -08:00 committed by Commit Bot
parent 02384b8e3f
commit cc65bd018d
2 changed files with 105 additions and 120 deletions

View File

@ -29,9 +29,9 @@
#include "rtc_base/timeutils.h" #include "rtc_base/timeutils.h"
// The following logging is for detailed (packet-level) analysis only. // The following logging is for detailed (packet-level) analysis only.
#define _DBG_NONE 0 #define _DBG_NONE 0
#define _DBG_NORMAL 1 #define _DBG_NORMAL 1
#define _DBG_VERBOSE 2 #define _DBG_VERBOSE 2
#define _DEBUGMSG _DBG_NONE #define _DEBUGMSG _DBG_NONE
namespace cricket { namespace cricket {
@ -125,8 +125,10 @@ const uint8_t TCP_OPT_NOOP = 1; // No-op.
const uint8_t TCP_OPT_MSS = 2; // Maximum segment size. const uint8_t TCP_OPT_MSS = 2; // Maximum segment size.
const uint8_t TCP_OPT_WND_SCALE = 3; // Window scale factor. const uint8_t TCP_OPT_WND_SCALE = 3; // Window scale factor.
const long DEFAULT_TIMEOUT = 4000; // If there are no pending clocks, wake up every 4 seconds const long DEFAULT_TIMEOUT =
const long CLOSED_TIMEOUT = 60 * 1000; // If the connection is closed, once per minute 4000; // If there are no pending clocks, wake up every 4 seconds
const long CLOSED_TIMEOUT =
60 * 1000; // If the connection is closed, once per minute
#if PSEUDO_KEEPALIVE #if PSEUDO_KEEPALIVE
// !?! Rethink these times // !?! Rethink these times
@ -134,7 +136,7 @@ const uint32_t IDLE_PING =
20 * 20 *
1000; // 20 seconds (note: WinXP SP2 firewall udp timeout is 90 seconds) 1000; // 20 seconds (note: WinXP SP2 firewall udp timeout is 90 seconds)
const uint32_t IDLE_TIMEOUT = 90 * 1000; // 90 seconds; const uint32_t IDLE_TIMEOUT = 90 * 1000; // 90 seconds;
#endif // PSEUDO_KEEPALIVE #endif // PSEUDO_KEEPALIVE
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Helper Functions // Helper Functions
@ -256,8 +258,7 @@ PseudoTcp::PseudoTcp(IPseudoTcpNotify* notify, uint32_t conv)
m_support_wnd_scale = true; m_support_wnd_scale = true;
} }
PseudoTcp::~PseudoTcp() { PseudoTcp::~PseudoTcp() {}
}
int PseudoTcp::Connect() { int PseudoTcp::Connect() {
if (m_state != TCP_LISTEN) { if (m_state != TCP_LISTEN) {
@ -285,19 +286,19 @@ void PseudoTcp::NotifyClock(uint32_t now) {
if (m_state == TCP_CLOSED) if (m_state == TCP_CLOSED)
return; return;
// Check if it's time to retransmit a segment // Check if it's time to retransmit a segment
if (m_rto_base && (rtc::TimeDiff32(m_rto_base + m_rx_rto, now) <= 0)) { if (m_rto_base && (rtc::TimeDiff32(m_rto_base + m_rx_rto, now) <= 0)) {
if (m_slist.empty()) { if (m_slist.empty()) {
RTC_NOTREACHED(); RTC_NOTREACHED();
} else { } else {
// Note: (m_slist.front().xmit == 0)) { // Note: (m_slist.front().xmit == 0)) {
// retransmit segments // retransmit segments
#if _DEBUGMSG >= _DBG_NORMAL #if _DEBUGMSG >= _DBG_NORMAL
RTC_LOG(LS_INFO) << "timeout retransmit (rto: " << m_rx_rto RTC_LOG(LS_INFO) << "timeout retransmit (rto: " << m_rx_rto
<< ") (rto_base: " << m_rto_base << ") (now: " << now << ") (rto_base: " << m_rto_base << ") (now: " << now
<< ") (dup_acks: " << static_cast<unsigned>(m_dup_acks) << ") (dup_acks: " << static_cast<unsigned>(m_dup_acks)
<< ")"; << ")";
#endif // _DEBUGMSG #endif // _DEBUGMSG
if (!transmit(m_slist.begin(), now)) { if (!transmit(m_slist.begin(), now)) {
closedown(ECONNABORTED); closedown(ECONNABORTED);
return; return;
@ -350,7 +351,7 @@ void PseudoTcp::NotifyClock(uint32_t now) {
now) <= 0)) { now) <= 0)) {
packet(m_snd_nxt, 0, 0, 0); packet(m_snd_nxt, 0, 0, 0);
} }
#endif // PSEUDO_KEEPALIVE #endif // PSEUDO_KEEPALIVE
} }
bool PseudoTcp::NotifyPacket(const char* buffer, size_t len) { bool PseudoTcp::NotifyPacket(const char* buffer, size_t len) {
@ -533,8 +534,8 @@ IPseudoTcpNotify::WriteResult PseudoTcp::packet(uint32_t seq,
if (len) { if (len) {
size_t bytes_read = 0; size_t bytes_read = 0;
rtc::StreamResult result = m_sbuf.ReadOffset( rtc::StreamResult result =
buffer.get() + HEADER_SIZE, len, offset, &bytes_read); m_sbuf.ReadOffset(buffer.get() + HEADER_SIZE, len, offset, &bytes_read);
RTC_DCHECK(result == rtc::SR_SUCCESS); RTC_DCHECK(result == rtc::SR_SUCCESS);
RTC_DCHECK(static_cast<uint32_t>(bytes_read) == len); RTC_DCHECK(static_cast<uint32_t>(bytes_read) == len);
} }
@ -547,13 +548,14 @@ IPseudoTcpNotify::WriteResult PseudoTcp::packet(uint32_t seq,
<< "><TS=" << (now % 10000) << "><TS=" << (now % 10000)
<< "><TSR=" << (m_ts_recent % 10000) << "><LEN=" << len << "><TSR=" << (m_ts_recent % 10000) << "><LEN=" << len
<< ">"; << ">";
#endif // _DEBUGMSG #endif // _DEBUGMSG
IPseudoTcpNotify::WriteResult wres = m_notify->TcpWritePacket( IPseudoTcpNotify::WriteResult wres = m_notify->TcpWritePacket(
this, reinterpret_cast<char *>(buffer.get()), len + HEADER_SIZE); this, reinterpret_cast<char*>(buffer.get()), len + HEADER_SIZE);
// Note: When len is 0, this is an ACK packet. We don't read the return value for those, // Note: When len is 0, this is an ACK packet. We don't read the return value
// and thus we won't retry. So go ahead and treat the packet as a success (basically simulate // for those, and thus we won't retry. So go ahead and treat the packet as a
// as if it were dropped), which will prevent our timers from being messed up. // success (basically simulate as if it were dropped), which will prevent our
// timers from being messed up.
if ((wres != IPseudoTcpNotify::WR_SUCCESS) && (0 != len)) if ((wres != IPseudoTcpNotify::WR_SUCCESS) && (0 != len))
return wres; return wres;
@ -581,7 +583,7 @@ bool PseudoTcp::parse(const uint8_t* buffer, uint32_t size) {
seg.tsval = bytes_to_long(buffer + 16); seg.tsval = bytes_to_long(buffer + 16);
seg.tsecr = bytes_to_long(buffer + 20); seg.tsecr = bytes_to_long(buffer + 20);
seg.data = reinterpret_cast<const char *>(buffer) + HEADER_SIZE; seg.data = reinterpret_cast<const char*>(buffer) + HEADER_SIZE;
seg.len = size - HEADER_SIZE; seg.len = size - HEADER_SIZE;
#if _DEBUGMSG >= _DBG_VERBOSE #if _DEBUGMSG >= _DBG_VERBOSE
@ -592,7 +594,7 @@ bool PseudoTcp::parse(const uint8_t* buffer, uint32_t size) {
<< "><TS=" << (seg.tsval % 10000) << "><TS=" << (seg.tsval % 10000)
<< "><TSR=" << (seg.tsecr % 10000) << "><LEN=" << seg.len << "><TSR=" << (seg.tsecr % 10000) << "><LEN=" << seg.len
<< ">"; << ">";
#endif // _DEBUGMSG #endif // _DEBUGMSG
return process(seg); return process(seg);
} }
@ -603,9 +605,9 @@ bool PseudoTcp::clock_check(uint32_t now, long& nTimeout) {
size_t snd_buffered = 0; size_t snd_buffered = 0;
m_sbuf.GetBuffered(&snd_buffered); m_sbuf.GetBuffered(&snd_buffered);
if ((m_shutdown == SD_GRACEFUL) if ((m_shutdown == SD_GRACEFUL) &&
&& ((m_state != TCP_ESTABLISHED) ((m_state != TCP_ESTABLISHED) ||
|| ((snd_buffered == 0) && (m_t_ack == 0)))) { ((snd_buffered == 0) && (m_t_ack == 0)))) {
return false; return false;
} }
@ -636,14 +638,15 @@ bool PseudoTcp::clock_check(uint32_t now, long& nTimeout) {
m_lasttraffic + (m_bOutgoing ? IDLE_PING * 3 / 2 : IDLE_PING), m_lasttraffic + (m_bOutgoing ? IDLE_PING * 3 / 2 : IDLE_PING),
now)); now));
} }
#endif // PSEUDO_KEEPALIVE #endif // PSEUDO_KEEPALIVE
return true; return true;
} }
bool PseudoTcp::process(Segment& seg) { bool PseudoTcp::process(Segment& seg) {
// If this is the wrong conversation, send a reset!?! (with the correct conversation?) // If this is the wrong conversation, send a reset!?! (with the correct
// conversation?)
if (seg.conv != m_conv) { if (seg.conv != m_conv) {
//if ((seg.flags & FLAG_RST) == 0) { // if ((seg.flags & FLAG_RST) == 0) {
// packet(tcb, seg.ack, 0, FLAG_RST, 0, 0); // packet(tcb, seg.ack, 0, FLAG_RST, 0, 0);
//} //}
RTC_LOG_F(LS_ERROR) << "wrong conversation"; RTC_LOG_F(LS_ERROR) << "wrong conversation";
@ -681,7 +684,7 @@ bool PseudoTcp::process(Segment& seg) {
if (m_state == TCP_LISTEN) { if (m_state == TCP_LISTEN) {
m_state = TCP_SYN_RECEIVED; m_state = TCP_SYN_RECEIVED;
RTC_LOG(LS_INFO) << "State: TCP_SYN_RECEIVED"; RTC_LOG(LS_INFO) << "State: TCP_SYN_RECEIVED";
//m_notify->associate(addr); // m_notify->associate(addr);
queueConnectMessage(); queueConnectMessage();
} else if (m_state == TCP_SYN_SENT) { } else if (m_state == TCP_SYN_SENT) {
m_state = TCP_ESTABLISHED; m_state = TCP_ESTABLISHED;
@ -690,7 +693,7 @@ bool PseudoTcp::process(Segment& seg) {
if (m_notify) { if (m_notify) {
m_notify->OnTcpOpen(this); m_notify->OnTcpOpen(this);
} }
//notify(evOpen); // notify(evOpen);
} }
} else { } else {
RTC_LOG_F(LS_WARNING) << "Unknown control code: " << seg.data[0]; RTC_LOG_F(LS_WARNING) << "Unknown control code: " << seg.data[0];
@ -725,7 +728,7 @@ bool PseudoTcp::process(Segment& seg) {
#if _DEBUGMSG >= _DBG_VERBOSE #if _DEBUGMSG >= _DBG_VERBOSE
RTC_LOG(LS_INFO) << "rtt: " << rtt << " srtt: " << m_rx_srtt RTC_LOG(LS_INFO) << "rtt: " << rtt << " srtt: " << m_rx_srtt
<< " rto: " << m_rx_rto; << " rto: " << m_rx_rto;
#endif // _DEBUGMSG #endif // _DEBUGMSG
} else { } else {
RTC_NOTREACHED(); RTC_NOTREACHED();
} }
@ -755,17 +758,17 @@ bool PseudoTcp::process(Segment& seg) {
} }
if (m_dup_acks >= 3) { if (m_dup_acks >= 3) {
if (m_snd_una >= m_recover) { // NewReno if (m_snd_una >= m_recover) { // NewReno
uint32_t nInFlight = m_snd_nxt - m_snd_una; uint32_t nInFlight = m_snd_nxt - m_snd_una;
m_cwnd = std::min(m_ssthresh, nInFlight + m_mss); // (Fast Retransmit) m_cwnd = std::min(m_ssthresh, nInFlight + m_mss); // (Fast Retransmit)
#if _DEBUGMSG >= _DBG_NORMAL #if _DEBUGMSG >= _DBG_NORMAL
RTC_LOG(LS_INFO) << "exit recovery"; RTC_LOG(LS_INFO) << "exit recovery";
#endif // _DEBUGMSG #endif // _DEBUGMSG
m_dup_acks = 0; m_dup_acks = 0;
} else { } else {
#if _DEBUGMSG >= _DBG_NORMAL #if _DEBUGMSG >= _DBG_NORMAL
RTC_LOG(LS_INFO) << "recovery retransmit"; RTC_LOG(LS_INFO) << "recovery retransmit";
#endif // _DEBUGMSG #endif // _DEBUGMSG
if (!transmit(m_slist.begin(), now)) { if (!transmit(m_slist.begin(), now)) {
closedown(ECONNABORTED); closedown(ECONNABORTED);
return false; return false;
@ -782,7 +785,8 @@ bool PseudoTcp::process(Segment& seg) {
} }
} }
} else if (seg.ack == m_snd_una) { } else if (seg.ack == m_snd_una) {
// !?! Note, tcp says don't do this... but otherwise how does a closed window become open? // !?! Note, tcp says don't do this... but otherwise how does a closed
// window become open?
m_snd_wnd = static_cast<uint32_t>(seg.wnd) << m_swnd_scale; m_snd_wnd = static_cast<uint32_t>(seg.wnd) << m_swnd_scale;
// Check duplicate acks // Check duplicate acks
@ -790,11 +794,11 @@ bool PseudoTcp::process(Segment& seg) {
// it's a dup ack, but with a data payload, so don't modify m_dup_acks // it's a dup ack, but with a data payload, so don't modify m_dup_acks
} else if (m_snd_una != m_snd_nxt) { } else if (m_snd_una != m_snd_nxt) {
m_dup_acks += 1; m_dup_acks += 1;
if (m_dup_acks == 3) { // (Fast Retransmit) if (m_dup_acks == 3) { // (Fast Retransmit)
#if _DEBUGMSG >= _DBG_NORMAL #if _DEBUGMSG >= _DBG_NORMAL
RTC_LOG(LS_INFO) << "enter recovery"; RTC_LOG(LS_INFO) << "enter recovery";
RTC_LOG(LS_INFO) << "recovery retransmit"; RTC_LOG(LS_INFO) << "recovery retransmit";
#endif // _DEBUGMSG #endif // _DEBUGMSG
if (!transmit(m_slist.begin(), now)) { if (!transmit(m_slist.begin(), now)) {
closedown(ECONNABORTED); closedown(ECONNABORTED);
return false; return false;
@ -821,7 +825,7 @@ bool PseudoTcp::process(Segment& seg) {
if (m_notify) { if (m_notify) {
m_notify->OnTcpOpen(this); m_notify->OnTcpOpen(this);
} }
//notify(evOpen); // notify(evOpen);
} }
// If we make room in the send queue, notify the user // If we make room in the send queue, notify the user
@ -836,18 +840,19 @@ bool PseudoTcp::process(Segment& seg) {
if (m_notify) { if (m_notify) {
m_notify->OnTcpWriteable(this); m_notify->OnTcpWriteable(this);
} }
//notify(evWrite); // notify(evWrite);
} }
// Conditions were acks must be sent: // Conditions were acks must be sent:
// 1) Segment is too old (they missed an ACK) (immediately) // 1) Segment is too old (they missed an ACK) (immediately)
// 2) Segment is too new (we missed a segment) (immediately) // 2) Segment is too new (we missed a segment) (immediately)
// 3) Segment has data (so we need to ACK!) (delayed) // 3) Segment has data (so we need to ACK!) (delayed)
// ... so the only time we don't need to ACK, is an empty segment that points to rcv_nxt! // ... so the only time we don't need to ACK, is an empty segment that points
// to rcv_nxt!
SendFlags sflags = sfNone; SendFlags sflags = sfNone;
if (seg.seq != m_rcv_nxt) { if (seg.seq != m_rcv_nxt) {
sflags = sfImmediateAck; // (Fast Recovery) sflags = sfImmediateAck; // (Fast Recovery)
} else if (seg.len != 0) { } else if (seg.len != 0) {
if (m_ack_delay == 0) { if (m_ack_delay == 0) {
sflags = sfImmediateAck; sflags = sfImmediateAck;
@ -863,7 +868,7 @@ bool PseudoTcp::process(Segment& seg) {
RTC_LOG_F(LS_INFO) << "too old"; RTC_LOG_F(LS_INFO) << "too old";
} }
} }
#endif // _DEBUGMSG #endif // _DEBUGMSG
// Adjust the incoming segment to fit our receive buffer // Adjust the incoming segment to fit our receive buffer
if (seg.seq < m_rcv_nxt) { if (seg.seq < m_rcv_nxt) {
@ -920,13 +925,13 @@ bool PseudoTcp::process(Segment& seg) {
RList::iterator it = m_rlist.begin(); RList::iterator it = m_rlist.begin();
while ((it != m_rlist.end()) && (it->seq <= m_rcv_nxt)) { while ((it != m_rlist.end()) && (it->seq <= m_rcv_nxt)) {
if (it->seq + it->len > m_rcv_nxt) { if (it->seq + it->len > m_rcv_nxt) {
sflags = sfImmediateAck; // (Fast Recovery) sflags = sfImmediateAck; // (Fast Recovery)
uint32_t nAdjust = (it->seq + it->len) - m_rcv_nxt; uint32_t nAdjust = (it->seq + it->len) - m_rcv_nxt;
#if _DEBUGMSG >= _DBG_NORMAL #if _DEBUGMSG >= _DBG_NORMAL
RTC_LOG(LS_INFO) RTC_LOG(LS_INFO)
<< "Recovered " << nAdjust << " bytes (" << m_rcv_nxt << " -> " << "Recovered " << nAdjust << " bytes (" << m_rcv_nxt << " -> "
<< m_rcv_nxt + nAdjust << ")"; << m_rcv_nxt + nAdjust << ")";
#endif // _DEBUGMSG #endif // _DEBUGMSG
m_rbuf.ConsumeWriteBuffer(nAdjust); m_rbuf.ConsumeWriteBuffer(nAdjust);
m_rcv_nxt += nAdjust; m_rcv_nxt += nAdjust;
m_rcv_wnd -= nAdjust; m_rcv_wnd -= nAdjust;
@ -937,7 +942,7 @@ bool PseudoTcp::process(Segment& seg) {
#if _DEBUGMSG >= _DBG_NORMAL #if _DEBUGMSG >= _DBG_NORMAL
RTC_LOG(LS_INFO) << "Saving " << seg.len << " bytes (" << seg.seq RTC_LOG(LS_INFO) << "Saving " << seg.len << " bytes (" << seg.seq
<< " -> " << seg.seq + seg.len << ")"; << " -> " << seg.seq + seg.len << ")";
#endif // _DEBUGMSG #endif // _DEBUGMSG
RSegment rseg; RSegment rseg;
rseg.seq = seg.seq; rseg.seq = seg.seq;
rseg.len = seg.len; rseg.len = seg.len;
@ -958,7 +963,7 @@ bool PseudoTcp::process(Segment& seg) {
if (m_notify) { if (m_notify) {
m_notify->OnTcpReadable(this); m_notify->OnTcpReadable(this);
} }
//notify(evRead); // notify(evRead);
} }
return true; return true;
@ -975,10 +980,8 @@ bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {
while (true) { while (true) {
uint32_t seq = seg->seq; uint32_t seq = seg->seq;
uint8_t flags = (seg->bCtrl ? FLAG_CTL : 0); uint8_t flags = (seg->bCtrl ? FLAG_CTL : 0);
IPseudoTcpNotify::WriteResult wres = packet(seq, IPseudoTcpNotify::WriteResult wres =
flags, packet(seq, flags, seg->seq - m_snd_una, nTransmit);
seg->seq - m_snd_una,
nTransmit);
if (wres == IPseudoTcpNotify::WR_SUCCESS) if (wres == IPseudoTcpNotify::WR_SUCCESS)
break; break;
@ -995,10 +998,11 @@ bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {
RTC_LOG_F(LS_VERBOSE) << "MTU too small"; RTC_LOG_F(LS_VERBOSE) << "MTU too small";
return false; return false;
} }
// !?! We need to break up all outstanding and pending packets and then retransmit!?! // !?! We need to break up all outstanding and pending packets and then
// retransmit!?!
m_mss = PACKET_MAXIMUMS[++m_msslevel] - PACKET_OVERHEAD; m_mss = PACKET_MAXIMUMS[++m_msslevel] - PACKET_OVERHEAD;
m_cwnd = 2 * m_mss; // I added this... haven't researched actual formula m_cwnd = 2 * m_mss; // I added this... haven't researched actual formula
if (m_mss < nTransmit) { if (m_mss < nTransmit) {
nTransmit = m_mss; nTransmit = m_mss;
break; break;
@ -1006,14 +1010,14 @@ bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {
} }
#if _DEBUGMSG >= _DBG_NORMAL #if _DEBUGMSG >= _DBG_NORMAL
RTC_LOG(LS_INFO) << "Adjusting mss to " << m_mss << " bytes"; RTC_LOG(LS_INFO) << "Adjusting mss to " << m_mss << " bytes";
#endif // _DEBUGMSG #endif // _DEBUGMSG
} }
if (nTransmit < seg->len) { if (nTransmit < seg->len) {
RTC_LOG_F(LS_VERBOSE) << "mss reduced to " << m_mss; RTC_LOG_F(LS_VERBOSE) << "mss reduced to " << m_mss;
SSegment subseg(seg->seq + nTransmit, seg->len - nTransmit, seg->bCtrl); SSegment subseg(seg->seq + nTransmit, seg->len - nTransmit, seg->bCtrl);
//subseg.tstamp = seg->tstamp; // subseg.tstamp = seg->tstamp;
subseg.xmit = seg->xmit; subseg.xmit = seg->xmit;
seg->len = nTransmit; seg->len = nTransmit;
@ -1025,7 +1029,7 @@ bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {
m_snd_nxt += seg->len; m_snd_nxt += seg->len;
} }
seg->xmit += 1; seg->xmit += 1;
//seg->tstamp = now; // seg->tstamp = now;
if (m_rto_base == 0) { if (m_rto_base == 0) {
m_rto_base = now; m_rto_base = now;
} }
@ -1042,11 +1046,11 @@ void PseudoTcp::attemptSend(SendFlags sflags) {
#if _DEBUGMSG #if _DEBUGMSG
bool bFirst = true; bool bFirst = true;
#endif // _DEBUGMSG #endif // _DEBUGMSG
while (true) { while (true) {
uint32_t cwnd = m_cwnd; uint32_t cwnd = m_cwnd;
if ((m_dup_acks == 1) || (m_dup_acks == 2)) { // Limited Transmit if ((m_dup_acks == 1) || (m_dup_acks == 2)) { // Limited Transmit
cwnd += m_dup_acks * m_mss; cwnd += m_dup_acks * m_mss;
} }
uint32_t nWindow = std::min(m_snd_wnd, cwnd); uint32_t nWindow = std::min(m_snd_wnd, cwnd);
@ -1080,7 +1084,7 @@ void PseudoTcp::attemptSend(SendFlags sflags) {
<< " nEmpty: " << available_space << " nEmpty: " << available_space
<< " ssthresh: " << m_ssthresh << "]"; << " ssthresh: " << m_ssthresh << "]";
} }
#endif // _DEBUGMSG #endif // _DEBUGMSG
if (nAvailable == 0) { if (nAvailable == 0) {
if (sflags == sfNone) if (sflags == sfNone)
@ -1099,7 +1103,7 @@ void PseudoTcp::attemptSend(SendFlags sflags) {
// If there is data already in-flight, and we haven't a full segment of // If there is data already in-flight, and we haven't a full segment of
// data ready to send then hold off until we get more to send, or the // data ready to send then hold off until we get more to send, or the
// in-flight data is acknowledged. // in-flight data is acknowledged.
if (m_use_nagling && (m_snd_nxt > m_snd_una) && (nAvailable < m_mss)) { if (m_use_nagling && (m_snd_nxt > m_snd_una) && (nAvailable < m_mss)) {
return; return;
} }
@ -1134,11 +1138,10 @@ void PseudoTcp::closedown(uint32_t err) {
if (m_notify) { if (m_notify) {
m_notify->OnTcpClosed(this, err); m_notify->OnTcpClosed(this, err);
} }
//notify(evClose, err); // notify(evClose, err);
} }
void void PseudoTcp::adjustMTU() {
PseudoTcp::adjustMTU() {
// Determine our current mss level, so that we can adjust appropriately later // Determine our current mss level, so that we can adjust appropriately later
for (m_msslevel = 0; PACKET_MAXIMUMS[m_msslevel + 1] > 0; ++m_msslevel) { for (m_msslevel = 0; PACKET_MAXIMUMS[m_msslevel + 1] > 0; ++m_msslevel) {
if (static_cast<uint16_t>(PACKET_MAXIMUMS[m_msslevel]) <= m_mtu_advise) { if (static_cast<uint16_t>(PACKET_MAXIMUMS[m_msslevel]) <= m_mtu_advise) {
@ -1146,29 +1149,26 @@ PseudoTcp::adjustMTU() {
} }
} }
m_mss = m_mtu_advise - PACKET_OVERHEAD; m_mss = m_mtu_advise - PACKET_OVERHEAD;
// !?! Should we reset m_largest here? // !?! Should we reset m_largest here?
#if _DEBUGMSG >= _DBG_NORMAL #if _DEBUGMSG >= _DBG_NORMAL
RTC_LOG(LS_INFO) << "Adjusting mss to " << m_mss << " bytes"; RTC_LOG(LS_INFO) << "Adjusting mss to " << m_mss << " bytes";
#endif // _DEBUGMSG #endif // _DEBUGMSG
// Enforce minimums on ssthresh and cwnd // Enforce minimums on ssthresh and cwnd
m_ssthresh = std::max(m_ssthresh, 2 * m_mss); m_ssthresh = std::max(m_ssthresh, 2 * m_mss);
m_cwnd = std::max(m_cwnd, m_mss); m_cwnd = std::max(m_cwnd, m_mss);
} }
bool bool PseudoTcp::isReceiveBufferFull() const {
PseudoTcp::isReceiveBufferFull() const {
size_t available_space = 0; size_t available_space = 0;
m_rbuf.GetWriteRemaining(&available_space); m_rbuf.GetWriteRemaining(&available_space);
return !available_space; return !available_space;
} }
void void PseudoTcp::disableWindowScale() {
PseudoTcp::disableWindowScale() {
m_support_wnd_scale = false; m_support_wnd_scale = false;
} }
void void PseudoTcp::queueConnectMessage() {
PseudoTcp::queueConnectMessage() {
rtc::ByteBufferWriter buf(rtc::ByteBuffer::ORDER_NETWORK); rtc::ByteBufferWriter buf(rtc::ByteBuffer::ORDER_NETWORK);
buf.WriteUInt8(CTL_CONNECT); buf.WriteUInt8(CTL_CONNECT);

View File

@ -30,18 +30,14 @@ class PseudoTcpForTest : public cricket::PseudoTcp {
PseudoTcpForTest(cricket::IPseudoTcpNotify* notify, uint32_t conv) PseudoTcpForTest(cricket::IPseudoTcpNotify* notify, uint32_t conv)
: PseudoTcp(notify, conv) {} : PseudoTcp(notify, conv) {}
bool isReceiveBufferFull() const { bool isReceiveBufferFull() const { return PseudoTcp::isReceiveBufferFull(); }
return PseudoTcp::isReceiveBufferFull();
}
void disableWindowScale() { void disableWindowScale() { PseudoTcp::disableWindowScale(); }
PseudoTcp::disableWindowScale();
}
}; };
class PseudoTcpTestBase : public testing::Test, class PseudoTcpTestBase : public testing::Test,
public rtc::MessageHandler, public rtc::MessageHandler,
public cricket::IPseudoTcpNotify { public cricket::IPseudoTcpNotify {
public: public:
PseudoTcpTestBase() PseudoTcpTestBase()
: local_(this, 1), : local_(this, 1),
@ -67,12 +63,8 @@ class PseudoTcpTestBase : public testing::Test,
remote_.NotifyMTU(mtu); remote_.NotifyMTU(mtu);
remote_mtu_ = mtu; remote_mtu_ = mtu;
} }
void SetDelay(int delay) { void SetDelay(int delay) { delay_ = delay; }
delay_ = delay; void SetLoss(int percent) { loss_ = percent; }
}
void SetLoss(int percent) {
loss_ = percent;
}
void SetOptNagling(bool enable_nagles) { void SetOptNagling(bool enable_nagles) {
local_.SetOption(PseudoTcp::OPT_NODELAY, !enable_nagles); local_.SetOption(PseudoTcp::OPT_NODELAY, !enable_nagles);
remote_.SetOption(PseudoTcp::OPT_NODELAY, !enable_nagles); remote_.SetOption(PseudoTcp::OPT_NODELAY, !enable_nagles);
@ -91,12 +83,8 @@ class PseudoTcpTestBase : public testing::Test,
void SetLocalOptRcvBuf(int size) { void SetLocalOptRcvBuf(int size) {
local_.SetOption(PseudoTcp::OPT_RCVBUF, size); local_.SetOption(PseudoTcp::OPT_RCVBUF, size);
} }
void DisableRemoteWindowScale() { void DisableRemoteWindowScale() { remote_.disableWindowScale(); }
remote_.disableWindowScale(); void DisableLocalWindowScale() { local_.disableWindowScale(); }
}
void DisableLocalWindowScale() {
local_.disableWindowScale();
}
protected: protected:
int Connect() { int Connect() {
@ -111,8 +99,14 @@ class PseudoTcpTestBase : public testing::Test,
UpdateLocalClock(); UpdateLocalClock();
} }
enum { MSG_LPACKET, MSG_RPACKET, MSG_LCLOCK, MSG_RCLOCK, MSG_IOCOMPLETE, enum {
MSG_WRITE}; MSG_LPACKET,
MSG_RPACKET,
MSG_LCLOCK,
MSG_RCLOCK,
MSG_IOCOMPLETE,
MSG_WRITE
};
virtual void OnTcpOpen(PseudoTcp* tcp) { virtual void OnTcpOpen(PseudoTcp* tcp) {
// Consider ourselves connected when the local side gets OnTcpOpen. // Consider ourselves connected when the local side gets OnTcpOpen.
// OnTcpWriteable isn't fired at open, so we trigger it now. // OnTcpWriteable isn't fired at open, so we trigger it now.
@ -137,7 +131,8 @@ class PseudoTcpTestBase : public testing::Test,
} }
} }
virtual WriteResult TcpWritePacket(PseudoTcp* tcp, virtual WriteResult TcpWritePacket(PseudoTcp* tcp,
const char* buffer, size_t len) { const char* buffer,
size_t len) {
// Randomly drop the desired percentage of packets. // Randomly drop the desired percentage of packets.
// Also drop packets that are larger than the configured MTU. // Also drop packets that are larger than the configured MTU.
if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) { if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) {
@ -167,15 +162,13 @@ class PseudoTcpTestBase : public testing::Test,
virtual void OnMessage(rtc::Message* message) { virtual void OnMessage(rtc::Message* message) {
switch (message->message_id) { switch (message->message_id) {
case MSG_LPACKET: { case MSG_LPACKET: {
const std::string& s( const std::string& s(rtc::UseMessageData<std::string>(message->pdata));
rtc::UseMessageData<std::string>(message->pdata));
local_.NotifyPacket(s.c_str(), s.size()); local_.NotifyPacket(s.c_str(), s.size());
UpdateLocalClock(); UpdateLocalClock();
break; break;
} }
case MSG_RPACKET: { case MSG_RPACKET: {
const std::string& s( const std::string& s(rtc::UseMessageData<std::string>(message->pdata));
rtc::UseMessageData<std::string>(message->pdata));
remote_.NotifyPacket(s.c_str(), s.size()); remote_.NotifyPacket(s.c_str(), s.size());
UpdateRemoteClock(); UpdateRemoteClock();
break; break;
@ -232,11 +225,11 @@ class PseudoTcpTest : public PseudoTcpTestBase {
recv_stream_.GetSize(&received); recv_stream_.GetSize(&received);
// Ensure we closed down OK and we got the right data. // Ensure we closed down OK and we got the right data.
// TODO: Ensure the errors are cleared properly. // TODO: Ensure the errors are cleared properly.
//EXPECT_EQ(0, local_.GetError()); // EXPECT_EQ(0, local_.GetError());
//EXPECT_EQ(0, remote_.GetError()); // EXPECT_EQ(0, remote_.GetError());
EXPECT_EQ(static_cast<size_t>(size), received); EXPECT_EQ(static_cast<size_t>(size), received);
EXPECT_EQ(0, memcmp(send_stream_.GetBuffer(), EXPECT_EQ(0,
recv_stream_.GetBuffer(), size)); memcmp(send_stream_.GetBuffer(), recv_stream_.GetBuffer(), size));
RTC_LOG(LS_INFO) << "Transferred " << received << " bytes in " << elapsed RTC_LOG(LS_INFO) << "Transferred " << received << " bytes in " << elapsed
<< " ms (" << size * 8 / elapsed << " Kbps)"; << " ms (" << size * 8 / elapsed << " Kbps)";
} }
@ -314,18 +307,14 @@ class PseudoTcpTest : public PseudoTcpTestBase {
rtc::MemoryStream recv_stream_; rtc::MemoryStream recv_stream_;
}; };
class PseudoTcpTestPingPong : public PseudoTcpTestBase { class PseudoTcpTestPingPong : public PseudoTcpTestBase {
public: public:
PseudoTcpTestPingPong() PseudoTcpTestPingPong()
: iterations_remaining_(0), : iterations_remaining_(0),
sender_(NULL), sender_(NULL),
receiver_(NULL), receiver_(NULL),
bytes_per_send_(0) { bytes_per_send_(0) {}
} void SetBytesPerSend(int bytes) { bytes_per_send_ = bytes; }
void SetBytesPerSend(int bytes) {
bytes_per_send_ = bytes;
}
void TestPingPong(int size, int iterations) { void TestPingPong(int size, int iterations) {
uint32_t start, elapsed; uint32_t start, elapsed;
iterations_remaining_ = iterations; iterations_remaining_ = iterations;
@ -411,8 +400,7 @@ class PseudoTcpTestPingPong : public PseudoTcpTestBase {
do { do {
send_stream_.GetPosition(&position); send_stream_.GetPosition(&position);
tosend = bytes_per_send_ ? bytes_per_send_ : sizeof(block); tosend = bytes_per_send_ ? bytes_per_send_ : sizeof(block);
if (send_stream_.Read(block, tosend, &tosend, NULL) != if (send_stream_.Read(block, tosend, &tosend, NULL) != rtc::SR_EOS) {
rtc::SR_EOS) {
sent = sender_->Send(block, tosend); sent = sender_->Send(block, tosend);
UpdateLocalClock(); UpdateLocalClock();
if (sent != -1) { if (sent != -1) {
@ -500,11 +488,9 @@ class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase {
private: private:
// IPseudoTcpNotify interface // IPseudoTcpNotify interface
virtual void OnTcpReadable(PseudoTcp* tcp) { virtual void OnTcpReadable(PseudoTcp* tcp) {}
}
virtual void OnTcpWriteable(PseudoTcp* tcp) { virtual void OnTcpWriteable(PseudoTcp* tcp) {}
}
void ReadUntilIOPending() { void ReadUntilIOPending() {
char block[kBlockSize]; char block[kBlockSize];
@ -555,8 +541,7 @@ class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase {
} while (sent > 0); } while (sent > 0);
// At this point, we've filled up the available space in the send queue. // At this point, we've filled up the available space in the send queue.
int message_queue_size = int message_queue_size = static_cast<int>(rtc::Thread::Current()->size());
static_cast<int>(rtc::Thread::Current()->size());
// The message queue will always have at least 2 messages, an RCLOCK and // The message queue will always have at least 2 messages, an RCLOCK and
// an LCLOCK, since they are added back on the delay queue at the same time // an LCLOCK, since they are added back on the delay queue at the same time
// they are pulled off and therefore are never really removed. // they are pulled off and therefore are never really removed.
@ -774,7 +759,7 @@ TEST_F(PseudoTcpTestPingPong, TestPingPongShortSegments) {
SetLocalMtu(1500); SetLocalMtu(1500);
SetRemoteMtu(1500); SetRemoteMtu(1500);
SetOptAckDelay(5000); SetOptAckDelay(5000);
SetBytesPerSend(50); // i.e. two Send calls per payload SetBytesPerSend(50); // i.e. two Send calls per payload
TestPingPong(100, 5); TestPingPong(100, 5);
} }
@ -784,7 +769,7 @@ TEST_F(PseudoTcpTestPingPong, TestPingPongShortSegmentsWithNaglingOff) {
SetLocalMtu(1500); SetLocalMtu(1500);
SetRemoteMtu(1500); SetRemoteMtu(1500);
SetOptNagling(false); SetOptNagling(false);
SetBytesPerSend(50); // i.e. two Send calls per payload SetBytesPerSend(50); // i.e. two Send calls per payload
TestPingPong(100, 5); TestPingPong(100, 5);
} }
@ -793,7 +778,7 @@ TEST_F(PseudoTcpTestPingPong, TestPingPongShortSegmentsWithNaglingOff) {
TEST_F(PseudoTcpTestPingPong, TestPingPongShortSegmentsWithAckDelayOff) { TEST_F(PseudoTcpTestPingPong, TestPingPongShortSegmentsWithAckDelayOff) {
SetLocalMtu(1500); SetLocalMtu(1500);
SetRemoteMtu(1500); SetRemoteMtu(1500);
SetBytesPerSend(50); // i.e. two Send calls per payload SetBytesPerSend(50); // i.e. two Send calls per payload
SetOptAckDelay(0); SetOptAckDelay(0);
TestPingPong(100, 5); TestPingPong(100, 5);
} }