Hybrid modelling of the RED algorithm in the Julia language

This work is devoted to studying the possibilities of hybrid modeling of communication network algorithms in the Julia programming language. A simulation of the system, which consists of an incoming stream processed according to the Transmission Control Protocol (TCP) and a router processing traffic according to the Random Early Detection (RED) algorithm, is carried out. This model contains both continuous and discrete elements, for example, a discrete probability function of random packet dropping in the case of queue congestion.


Introduction
The hybrid approach can be used to simulate systems containing elements with both continuous and discrete functioning [1,2]. Let us consider a model of the interaction between the process of data transmission via the Transmission Control Protocol (TCP) and the process of regulating the flow state when congestion occurs using the Random Early Detection (RED) algorithm [3]. The system contains continuous control objects and a discrete control device. In addition, it is also necessary to consider the transitions between TCP states.
In this paper, it is planned to describe a TCP traffic control system with the RED active queue management algorithm and demonstrate a hybrid approach to modeling communication network algorithms in the Julia scientific computing language.

Description of the RED module model
Active queue management algorithms, in particular the RED, are used to control and prevent congestion in router queues [4]. Traffic state control algorithms can be implemented as a control module in network equipment. The advantage of the RED algorithm is its efficiency and relatively simple implementation on network equipment.
The model for transmitting TCP-like traffic with dynamic flow rate, which is regulated by an RED, consists of two elements. The first element is the TCP source that generates the packets, the second element is the receiver, which is the router's queue, where the incoming packets are processed in accordance with the RED control algorithm and a notification is sent to the source about the packets delivery. The source and the receiver interact through an intermediate := ( ) is the router queue length,̂:=̂( ) is exponentially weighted moving average of the queue length. A mathematical model of the interaction of an incoming TCP stream and a router that processes traffic using a RED-type control algorithm is the autonomous system of three differential equations [5,6,7].
Equation (1) describes the dynamic change in the average TCP window size. The ( max − ( )) Heaviside function limits the growth of the TCP window. The first term in the (2) equation reflects the increase in the queue length when packets arrive which corresponds to the average packet arrival rate, the second term is set to reduce the number of packets in the queue. The (3) equation reflects the change of the exponentially weighted moving average of the queue length function, which is introduced for some smoothing outliers of the queue length.
The RED algorithm is controlled by the (︁̂( ) )︁ -piecewise probabilistic packet drop function which can be written as a system of nonlinear equations.
This function depends on the threshold values of the queue size min and , , as well as the max parameter that sets the part of packets that will be discarded if̂( ) reaches the maximum value.
3. Hybrid implementation of the RED module Julia is a high-level, high-performance programming language designed for scientific computing [8,9,10]. Let's implement a simulation of the RED algorithm in Julia. The DifferentialEquations library is used to effectively solve differential equations of different types [11]. To install and then connect this library, use the following commands in the Julia REPL: using Pkg Pkg.add("DifferentialEquations" ) using DifferentialEquations Let us set the vector of system parameters p = (T, N, C, wq, q_min,q_max, R, p_max, w_max). The variable pr, which is the probability of dropping packets, is set as a global variable.  In the original system of differential equations there are delayed arguments, therefore we define the history function h(p, t), which depends on the parameters vector p and time t. Next, we define the delay of the ( − ( )) variable in (1) equation.

h(p, t) = zeros(1) tau = T lags = [tau]
Let's set the RED function, in which continuous parameters , ( ),̂( ) are calculated, and some restrictions are set for these parameters.
function qAdd(q,w,T,C,N,R) q1 = N * w / T -C q2 = q + q1 if q2 > R return R -q else if q2 > 0 return q1 else return -q end end To implement a discrete reset function into a continuous system, we use one of the tools of the DifferentialEquations package called callbacks. Two functions are defined to work with this tool. The condition function is needed to check if some event has occurred. The affect function is executed if the event occurs. Next, we define the action function, which is the controller. The control_loop! function at each step calculates the new value of the packet drop probability function depending on the current values of the , ( ),̂( ) parameters in accordance with the formula (4). As soon as thĕ( ) value exceeds some predetermined threshold value, the router finds out that the system has started overloading and reports this to the source.

Modeling Results
As a result of the simulation, we obtain a graph demonstrating the behaviour of the TCP Reno window size and the average queue length, i.e. reflecting the dynamics of a queue in a router (or gateway) with a queue management module using the RED algorithm (Fig. 1). As we can see, in the system there are some auto-oscillations of the main parameters under presented initial values.

Conclusion
The application of a hybrid approach to modeling nonlinear systems with control has been demonstrated. The simulated system was an active traffic control model using an algorithm like RED. It has been demonstrated that the Julia programming language contains tools for implementing the continuous-discrete paradigm. The DifferentialEquations package has been used, which allows to solve differential equations systems of various types, including differential equations with delay, the continuous probabilistic function has been implemented using the callback option, the delayed continuous argument to a continuous function has been implemented using the history function. The capabilities of the Julia programming languages in modeling of hybrid systems containing both continuous and discrete aspects of behavior has been studied. The numerical simulation of the transmitting data process via TCP and the process of regulating the flow state using the RED algorithm in the event of congestion has been performed, graphs demonstrating changes in the main parameters of the system have been obtained.