<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Computer simulation of the stochastic RED algorithm</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Anna Maria Yu. Apreutesey</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Anna V. Korolkova</string-name>
          <email>korolkova-av@rudn.ru</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dmitry S. Kulyabov</string-name>
          <email>kulyabov-ds@rudn.ru</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Early Detection</string-name>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Laboratory of Information Technologies, Joint Institute for Nuclear Research</institution>
          ,
          <addr-line>6 Joliot-Curie St., Dubna, Moscow region</addr-line>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Peoples' Friendship University of Russia (RUDN University)</institution>
          ,
          <addr-line>6 Miklukho-Maklaya St, Moscow, 117198, Russian</addr-line>
        </aff>
      </contrib-group>
      <fpage>45</fpage>
      <lpage>53</lpage>
      <abstract>
        <p>The purpose of this work is to study the capabilities of the Julia language for numerical modeling of stochastic systems. As a stochastic system we consider the model of interaction between the process of data transmission via the Transmission Control Protocol (TCP) and the process of regulating the flow state using the Random Early Detection (RED) algorithm. The mathematical model of this interaction is a system of stochastic diferential equations, where there are both continuous and discrete elements of the model. When simulating such systems, it is important to consider the properties of continuous parameters, such as queue length of a router and the TCP window size, as well as discrete transitions between TCP states and the probabilistic packet drop function. Such hybrid systems can be quite easily implemented in specialized dynamic systems modeling languages, for example in Modelica. However, this software package does not have built-in universal tools for modeling stochastic systems, where it is important to consider the random nature of the behavior. The aim of this work is to find optimal tools for modeling such stochastic systems using the Julia language which in used for scientific calculations. For modeling the RED algorithm, the DiferentialEquations.jl library is used. This tool of the Julia language allows solving various kinds of diferential equations, including stochastic diferential equations and delay diferential equations. As a result of the simulation graphs were obtained that demonstrate the dynamics of changes of the TCP window size and the queue length, depending on the initial model parameters and queue threshold values, the correct selection of which ensures the stable operation of the system.</p>
      </abstract>
      <kwd-group>
        <kwd>Stochastic diferential equations</kwd>
        <kwd>Active Queue Management</kwd>
        <kwd>mathematical modeling</kwd>
        <kwd>Julia</kwd>
        <kwd>Random</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>LGOBE
(D. S. Kulyabov)</p>
    </sec>
    <sec id="sec-2">
      <title>1. Introduction</title>
      <p>
        Active Queue Management techniques have been proposed to both alleviate some congestion
control problems for IP networks as well as provide the quality of service. RED controlled
systems [
        <xref ref-type="bibr" rid="ref1 ref2">1, 2</xref>
        ] are widely used in modern data networks, which allow to study the trafic
transmission system with AQM policy as the RED type algorithm [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. The modeling and
Workshop on information technology and scientific computing in the framework of the XI International Conference
https://yamadharma.github.io/ (D. S. Kulyabov)
      </p>
      <p>
        © 2021 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0).
CEUR
Workshop
Proceedings
analysis of such algorithms are important for understanding systems dynamics which depends
on the initial settings of the routers. The studies of various models of the trafic transmission
process are urgent tasks, since they allow to evaluate the network weaknesses and trafic losses.
The mathematical model for the interaction of an incoming TCP stream and a router that
processes trafic using a RED control algorithm can be represented as a system of stochastic
diferential equations. Such hybrid system [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] combines the work of both continuous and
discrete elements of the system, such as transitions between TCP states and the probabilistic
function of dropping packets. The purpose of this work is to search in the Julia scientific
computing language for universal tools for the numerical modeling of stochastic systems, where
it is necessary to take into account the random nature of the behavior of the main parameters.
      </p>
    </sec>
    <sec id="sec-3">
      <title>2. Stochastic model of the RED algorithm</title>
      <p>Consider the process of transmitting TCP-like trafic controlled by the RED algorithm. A
continuous state vector is ( , , )̂  , where  ∶=  () — average TCP window size (in
packets),  ∶= () — average queue length (in packets),  ∶̂= (̂) — exponentially weighted
moving average of the queue length.</p>
      <p>
        The stochastic model is a system of three Ito stochastic diferential equations [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]:
⎧
⎪d () =
⎪
( 1 −
 ()
 2() ( )̂
2 ()
) d +
      </p>
      <p>1 +
√  ()
 2() ( )̂
2 ()</p>
      <p>d 1 ,
 ()
 ()
⎨d() = (
⎪
⎪
⎩d(̂) =   () (() − (̂) ).</p>
      <p>() − () ) d +</p>
      <p>()
√  ()
 () − ()
d 2 ,
•  () is the Round Trip Time (RTT). It is the time taken for a packet to be sent from a
source to a destination and for the corresponding acknowledgement to be received by
the source, assuming no packet loss; () — speed of processing packets in the queue;
•  () is a number of TCP sessions;
• d 1 is the Wiener process corresponding to a random  () process;
• d 2 is the Wiener process corresponding to a random () process.</p>
      <p>As the the average queue length increases, the packets drop probability also increases. The
classical example of an AQM policy is RED for which  ( )̂ takes the next form:
 ( )̂ =
⎧0,
⎪ (̂) −  min
⎨  max −  min
⎪
⎩1,</p>
      <p>0 ⩽ (̂) &lt;  min,
 max,  min ⩽ (̂) ⩽  max,
(̂) &gt;  max.</p>
      <p>Here  ( )̂ is the package dropping function, (̂) is the queue length weighted average,
 min and  max are thresholds of queue length weighted average,  max is the maximum level of
packages reset.
(1)
(2)</p>
    </sec>
    <sec id="sec-4">
      <title>3. Computer simulation of the RED module</title>
      <p>
        Julia is a high-level language for scientific and engineering calculations [
        <xref ref-type="bibr" rid="ref4 ref6 ref7 ref8">4, 6, 7, 8</xref>
        ]. To model
the described system, the DiferentialEquations.jl [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] library was used, which makes it possible
to solve various types of diferential equations, including stochastic diferential equations of the
next form
d() =  (, () )d +  (, () )d ,
(3)
where () ∈ ℝ is some random process,  ∶=  () ∈ ℝ is the Wiener process.
      </p>
      <p>To install the package we will use the following command in Julia REPL:
using Pkg
Pkg.add("DifferentialEquations")</p>
      <p>We will enable the package using the command:
using DifferentialEquations
T = 0.5
N = 60.0
q_min = 0.25
q_max = 0.50
R = 300.0
p_max = 0.1
w_max = 32.0
p = (T, N, C, wq, q_min, q_max, R, p_max, w_max)</p>
      <p>We set the vector of the initial system parameters p = (T, N, C, wq, q_min, q_max, R,
p_max, w_max).</p>
      <p>After declaring the variables and the vector of the system parameters, in the RED function
we define the deterministic part of the ( 1) system of equations:
function RED(du, u, param, t)
if w &lt; w_max</p>
      <p>
        du[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] = 1.0 / T(q) - ( w / 2 )* w * p(q_avg) / T(q)
end
else
end
du[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] = N * w / T(q) - C(q)
du[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] = wq * C(q) * (q - q_avg)
      </p>
      <p>
        du[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] = - ( w / 2 )* w * p(q_avg) / T(q)
The stochastic part of the (1) system of equations is specified in the REDst function:
function REDst(du,u,param,t)
w, q, q_avg = u
du[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] = sqrt(1.0 / T(q) + ((w / 2) * w * p(q_avg)/ T(q)))
if ((N * w / T(q) - C(q)) &lt; 0)
du[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] = 0.0
du[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] = sqrt(N * w / T(q) - C(q))
Let us define the probabilistic function of dropping packets according to the ( 2) equation:
else
end
du[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] = 0.0
else
end
end
end
function p(q_avg)
global q_min, q_max
if (q_avg &lt; q_min * R)
      </p>
      <p>p = 0.0
elseif (q_avg &gt; q_max * R)
p = 1.0
p = p_max * (q_avg / R - q_min) / (q_max - q_min)</p>
      <p>The DiferentialEquations.jl package allows you to use callbacks to inject custom code into
the solver algorithms to model complex functions with conditions and discontinuities. To work
with callbacks, two functions are defined: the condition function checks if an event has occurred,
the afect function is executed if the event has occurred.</p>
      <p>
        Let us define the condition function and the afecting function, thereby limiting the growth
of the TCP window size to the maximum value:
function condition_w_max(u,t,integrator)
global w_max
u[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] &gt;= w_max
end
function affect_w_max!(integrator)
global w_max
for c in full_cache(integrator)
      </p>
      <p>
        c.u[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] = w_max
end
      </p>
      <p>
        end
We also add callbacks to control the growth of the () variable:
function condition_Rq(u,t,integrator)
global R
u[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] &gt;= R
end
function affect_Rq!(integrator)
global R
for c in full_cache(integrator)
      </p>
      <p>
        c.u[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] = R
end
      </p>
      <p>
        end
function condition_Rq_avg(u,t,integrator)
global R
u[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] &gt;= R
end
end
      </p>
      <p>end
function affect_Rq_avg!(integrator)
global R
for c in full_cache(integrator)</p>
      <p>
        c.u[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] = R
The callback option for the (̂) variable is set in the same way:
      </p>
      <p>In this case, we used several callback functions of the discrete type DiscreteCallback. The
condition function implements event detection at each step of solving dt, and each afecting
function will be executed if the condition function returns true:
save_positions = (true,true)
cb_w_max = DiscreteCallback(condition_w_max, affect_w_max!,</p>
      <p>save_positions = save_positions)
cb_Rq = DiscreteCallback(condition_Rq, affect_Rq!,</p>
      <p>save_positions = save_positions)
cb_Rq_avg = DiscreteCallback(condition_Rq_avg, affect_Rq_avg!,
save_positions = save_positions)</p>
      <p>With the CallbackSet() tool, multiple callbacks can be combined into one group:
Clbsset = CallbackSet(PositiveDomain(), cb_w_max, cb_Rq, cb_Rq_avg)</p>
      <p>Let’s call the SDEProblem solver of the DiferentialEquations.jl package, the arguments of
which are passed the RED function that specifies the deterministic part of the equations and the
REDst function that specifies the stochastic part of the system. Also, in the arguments to the
solver, the vector of the initial states of the system and the simulation time are indicated:</p>
      <p>Let’s call the solve method of the DiferentialEquations.jl library to solve the above system
of equations. The Euler - Maruyama method is used as a numerical method, which has a strong
order (  ,   ) = (1.0, 0.5.)The value   denotes the deterministic accuracy order, the value  
denotes the stochastic part approximation order.
sol = solve(prob_sde_RED, EM(), dt=dt, callback = Clbsset)</p>
      <p>Using the parallel computing capabilities of the Julia language, let us simulate a large number
of trajectories:
ensembleprob = EnsembleProblem(prob_sde_RED)
sim = solve(ensembleprob, EM(), dt=dt, callback = Clbsset, trajectories =
↪ 200)</p>
      <p>Use the EnsembleSummary() method to combine the modeled set of trajectories.
summ = EnsembleSummary(sim, 0:dt:tf)</p>
    </sec>
    <sec id="sec-5">
      <title>4. Simulation results</title>
      <p>As a result of the simulation, graphs of changes in the TCP window size and the average queue
size in a router with a queue control module according to the RED algorithm were obtained
for various initial values of the model. With some initial parameters, the system quickly finds
suitable values of variables and changes within the average values (fig. 1–3). In the case of
modeling only the deterministic part of the (1) system of equations, the model enters a stationary
mode of operation (fig. 2).</p>
      <p>(a)
(b)</p>
      <p>
        Using active queue management algorithms such as RED for trafic control reduces the
chances of global synchronization occurring, but does not completely eliminate it [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]. At some
values of the initial parameters in the settings of the routers, the system has auto-oscillations of
the main parameters (fig. 4–6).
      </p>
    </sec>
    <sec id="sec-6">
      <title>5. Conclusion</title>
      <p>The universal and efective tools of the DiferentialEquations.jl library of the Julia scientific
computing language were demonstrated for the numerical simulation of a nonlinear system
with control, the mathematical model of which is a system of stochastic diferential equations.
The interaction of the process of data transmission via the TCP protocol and the process of the
lfow state regulation by the RED algorithm in the event of overloads was considered. The tools
of the Julia language used in this work are applicable to modeling such stochastic systems with
control, containing elements of both continuous and discrete nature of functioning. As a result
of modeling, graphs were obtained that demonstrate changes in the main parameters of the
system depending on the threshold values of the queue.</p>
    </sec>
    <sec id="sec-7">
      <title>Acknowledgments</title>
      <p>This paper has been supported by the RUDN University Strategic Academic Leadership Program
and by Russian Foundation for Basic Research (RFBR) according to the research project No
1901-00645.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>S.</given-names>
            <surname>Floyd</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Jacobson</surname>
          </string-name>
          ,
          <article-title>Random Early Detection Gateways for Congestion Avoidance</article-title>
          ,
          <source>IEEE/ACM Transactions on Networking</source>
          <volume>1</volume>
          (
          <year>1993</year>
          )
          <fpage>397</fpage>
          -
          <lpage>413</lpage>
          . doi:
          <volume>10</volume>
          .1109/90.251892.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>V.</given-names>
            <surname>Misra</surname>
          </string-name>
          ,
          <string-name>
            <surname>W.-B. Gong</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          <string-name>
            <surname>Towsley</surname>
          </string-name>
          ,
          <article-title>Fluid-Based Analysis of a Network of AQM Routers Supporting TCP Flows with an Application to RED</article-title>
          ,
          <source>ACM SIGCOMM Computer Communication Review</source>
          <volume>30</volume>
          (
          <year>2000</year>
          )
          <fpage>151</fpage>
          -
          <lpage>160</lpage>
          . doi:
          <volume>10</volume>
          .1145/347057.347421.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>A. V.</given-names>
            <surname>Korolkova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T. R.</given-names>
            <surname>Velieva</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P. A.</given-names>
            <surname>Abaev</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L. A.</given-names>
            <surname>Sevastianov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D. S.</given-names>
            <surname>Kulyabov</surname>
          </string-name>
          ,
          <source>Hybrid Simulation Of Active Trafic Management, Proceedings 30th European Conference on Modelling and Simulation</source>
          (
          <year>2016</year>
          )
          <fpage>685</fpage>
          -
          <lpage>691</lpage>
          . doi:
          <volume>10</volume>
          .7148/2016-0685.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>D.</given-names>
            <surname>Färnqvist</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Strandemar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K. H.</given-names>
            <surname>Johansson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. P.</given-names>
            <surname>Hespanha</surname>
          </string-name>
          ,
          <article-title>Hybrid Modeling of Communication Networks Using Modelica</article-title>
          ,
          <source>in: The 2nd International Modelica Conference</source>
          ,
          <year>2002</year>
          , pp.
          <fpage>209</fpage>
          -
          <lpage>213</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>A. V.</given-names>
            <surname>Korolkova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D. S.</given-names>
            <surname>Kulyabov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T. R.</given-names>
            <surname>Velieva</surname>
          </string-name>
          ,
          <string-name>
            <given-names>I. S.</given-names>
            <surname>Zaryadov</surname>
          </string-name>
          ,
          <article-title>Essay on the study of the selfoscillating regime in the control system</article-title>
          , in: M.
          <string-name>
            <surname>Iacono</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          <string-name>
            <surname>Palmieri</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Gribaudo</surname>
          </string-name>
          , M. Ficco (Eds.),
          <source>33 European Conference on Modelling and Simulation, ECMS</source>
          <year>2019</year>
          , volume
          <volume>33</volume>
          of
          <article-title>Communications of the ECMS, European Council for Modelling and Simulation</article-title>
          , Caserta,
          <year>2019</year>
          , pp.
          <fpage>473</fpage>
          -
          <lpage>480</lpage>
          . doi:
          <volume>10</volume>
          .7148/2019-0473.
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>J.</given-names>
            <surname>Bezanson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Karpinski</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V. B.</given-names>
            <surname>Shah</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Edelman</surname>
          </string-name>
          , Julia:
          <string-name>
            <given-names>A Fast</given-names>
            <surname>Dynamic Language for Technical Computing</surname>
          </string-name>
          (
          <year>2012</year>
          )
          <fpage>1</fpage>
          -
          <lpage>27</lpage>
          . arXiv:
          <volume>1209</volume>
          .
          <fpage>5145</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>J.</given-names>
            <surname>Bezanson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Edelman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Karpinski</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V. B.</given-names>
            <surname>Shah</surname>
          </string-name>
          ,
          <article-title>Julia: A fresh approach to numerical computing</article-title>
          ,
          <source>SIAM Review 59</source>
          (
          <year>2017</year>
          )
          <fpage>65</fpage>
          -
          <lpage>98</lpage>
          . doi:
          <volume>10</volume>
          .1137/141000671. arXiv:
          <volume>1411</volume>
          .
          <fpage>1607</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>A.</given-names>
            <surname>Joshi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Lakhanpal</surname>
          </string-name>
          , Learning Julia, Packt Publishing,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>C.</given-names>
            <surname>Rackauckas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Q.</given-names>
            <surname>Nie</surname>
          </string-name>
          , DiferentialEquations.jl
          <article-title>- A Performant and Feature-Rich Ecosystem for Solving Diferential Equations in Julia</article-title>
          ,
          <source>Journal of Open Research Software</source>
          <volume>5</volume>
          (
          <year>2017</year>
          ). doi:
          <volume>10</volume>
          .5334/jors.151.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>D. S.</given-names>
            <surname>Kulyabov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. V.</given-names>
            <surname>Korolkova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T. R.</given-names>
            <surname>Velieva</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E. G.</given-names>
            <surname>Eferina</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L. A.</given-names>
            <surname>Sevastianov</surname>
          </string-name>
          ,
          <article-title>The Methodology of Studying of Active Trafic Management Module Self-oscillation Regime</article-title>
          , in: W. Zamojski,
          <string-name>
            <given-names>J.</given-names>
            <surname>Mazurkiewicz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Sugier</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Walkowiak</surname>
          </string-name>
          , J. Kacprzyk (Eds.),
          <source>DepCoSRELCOMEX 2017. Advances in Intelligent Systems and Computing</source>
          , volume
          <volume>582</volume>
          <source>of Advances in Intelligent Systems and Computing</source>
          , Springer International Publishing, Cham,
          <year>2018</year>
          , pp.
          <fpage>215</fpage>
          -
          <lpage>224</lpage>
          . doi:
          <volume>10</volume>
          .1007/978-3-
          <fpage>319</fpage>
          -59415-6_
          <fpage>21</fpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>