From e71549a2cb01609f781667490f68dc2876c5c024 Mon Sep 17 00:00:00 2001
From: Mic Bowman
Date: Mon, 29 Dec 2014 12:02:36 -0800
Subject: Add debugging code for simulating packet loss in outgoing UDP
packets. The algorithm for dropping packets is a modified two state algorithm
for creating bursts of dropped packets. As configured there is about a 1.5%
drop rate.
Invocation of the packet loss code is commented out by default.
---
.../ClientStack/Linden/UDP/OpenSimUDPBase.cs | 66 ++++++++++++++++++++++
1 file changed, 66 insertions(+)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
index 94300f8..9bee3ad 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
@@ -107,6 +107,62 @@ namespace OpenMetaverse
///
public float AverageReceiveTicksForLastSamplePeriod { get; private set; }
+ #region PacketDropDebugging
+ ///
+ /// For debugging purposes only... random number generator for dropping
+ /// outbound packets.
+ ///
+ private Random m_dropRandomGenerator;
+
+ ///
+ /// For debugging purposes only... parameters for a simplified
+ /// model of packet loss with bursts, overall drop rate should
+ /// be roughly 1 - m_dropLengthProbability / (m_dropProbabiliy + m_dropLengthProbability)
+ /// which is about 1% for parameters 0.0015 and 0.15
+ ///
+ private double m_dropProbability = 0.0030;
+ private double m_dropLengthProbability = 0.15;
+ private bool m_dropState = false;
+
+ ///
+ /// For debugging purposes only... parameters to control the time
+ /// duration over which packet loss bursts can occur, if no packets
+ /// have been sent for m_dropResetTicks milliseconds, then reset the
+ /// state of the packet dropper to its default.
+ ///
+ private int m_dropLastTick = 0;
+ private int m_dropResetTicks = 500;
+
+ ///
+ /// Debugging code used to simulate dropped packets with bursts
+ ///
+ private bool DropOutgoingPacket()
+ {
+ double rnum = m_dropRandomGenerator.NextDouble();
+
+ // if the connection has been idle for awhile (more than m_dropResetTicks) then
+ // reset the state to the default state, don't continue a burst
+ int curtick = Util.EnvironmentTickCount();
+ if (Util.EnvironmentTickCountSubtract(curtick, m_dropLastTick) > m_dropResetTicks)
+ m_dropState = false;
+
+ m_dropLastTick = curtick;
+
+ // if we are dropping packets, then the probability of dropping
+ // this packet is the probability that we stay in the burst
+ if (m_dropState)
+ {
+ m_dropState = (rnum < (1.0 - m_dropLengthProbability)) ? true : false;
+ }
+ else
+ {
+ m_dropState = (rnum < m_dropProbability) ? true : false;
+ }
+
+ return m_dropState;
+ }
+ #endregion PacketDropDebugging
+
///
/// Default constructor
///
@@ -117,6 +173,10 @@ namespace OpenMetaverse
{
m_localBindAddress = bindAddress;
m_udpPort = port;
+
+ // for debugging purposes only, initializes the random number generator
+ // used for simulating packet loss
+ // m_dropRandomGenerator = new Random();
}
///
@@ -395,6 +455,12 @@ namespace OpenMetaverse
{
// if (IsRunningOutbound)
// {
+
+ // This is strictly for debugging purposes to simulate dropped
+ // packets when testing throttles & retransmission code
+ // if (DropOutgoingPacket())
+ // return;
+
try
{
m_udpSocket.BeginSendTo(
--
cgit v1.1