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:
parent
02384b8e3f
commit
cc65bd018d
@ -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
|
||||||
@ -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) {
|
||||||
@ -290,8 +291,8 @@ void PseudoTcp::NotifyClock(uint32_t now) {
|
|||||||
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
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
@ -550,10 +551,11 @@ IPseudoTcpNotify::WriteResult PseudoTcp::packet(uint32_t seq,
|
|||||||
#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
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,9 +643,10 @@ bool PseudoTcp::clock_check(uint32_t now, long& nTimeout) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
@ -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
|
||||||
@ -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,14 +840,15 @@ 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) {
|
||||||
@ -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,7 +998,8 @@ 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
|
||||||
@ -1013,7 +1017,7 @@ bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@ -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,7 +1149,7 @@ 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
|
||||||
@ -1155,20 +1158,17 @@ PseudoTcp::adjustMTU() {
|
|||||||
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);
|
||||||
|
|||||||
@ -30,13 +30,9 @@ 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,
|
||||||
@ -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.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user