Modelica-based TCP simulation

For the study and verification of our mathematical model of telecommunication systems a discrete simulation model and a continuous analytical model were developed. However, for various reasons, these implementations are not entirely satisfactory. It is necessary to develop a more adequate simulation model, possibly using a different modeling paradigm. In order to modeling of the TCP source it is proposed to use a hybrid (continuous-discrete) approach. For computer implementation of the model the physical modeling language Modelica is used. The hybrid approach allows us to take into account the transitions between different states in the continuous model of the TCP protocol. The considered approach allowed to obtain a simple simulation model of TCP source. This model has great potential for expansion. It is possible to implement different types of TCP.


Introduction
While complex systems modeling there is the problem of choosing a model approach.When using a discrete-continuous dichotomy, we always have some inappropriate elements. These elements of the model do not well correspond to the selected approach. During simulation of TCP protocol the serious problems arised. As it turned out adequate TCP models are simply missing. Not even a common method for its modeling (see [1][2][3]) exists.
For modeling we used the continuous (fluid) model for TCP (see [4,5]). However, this approach allowed us to model the TCP protocol only partially. In addition, we received differential inclusions instead of differential equations.
For further development of our model, it was decided to use a hybrid approach (see [6][7][8][9][10]). This article discusses a general approach to a hybrid modeling of TCP. The implementation is demonstrated on the basis of Modelica language (see [11,12]).
The structure of the article is as follows. The section 2 describes the hybrid paradigm of mathematical modeling. Also the general information about the language of physical modeling named Modelica is given in the same section. Modelica implements continuous and hybrid paradigms. The congestion control mechanism in the TCP Reno protocol are presented in the 2. The hybrid approach to modeling The hybrid (see [6][7][8][9][10]) system has both continuous and discrete aspects of behavior. The hybrid behavior may be due to different reasons.
• Hybrid behavior is due to the joint operation of the continuous and discrete objects. For example, the automatic control system with continuous control object and discrete control device. • Hybrid behavior is caused by changes in the structure of the system. A system with variable number of components may be considered as an example. • Hybrid behavior may be caused by instant qualitative changes in a continuous object. In this case, qualitative changes during the simulation of continuous systems are presented as discrete events. Asesult, the hybridism is not an inherent characteristic of the system, but the modeling technique.
Hybrid systems may be considered as discrete-continuous or continuous-discrete systems.
• The waiting time for the next input and the duration of the output action can be taken into account in discrete systems. • The coexistence of instant and long-term processes in a continuous-time model.
We will add discrete elements to the initially developed continuous dynamic model. Modelica language (see [11,12]) is developed by a nonprofit organization Modelica, which also develops a free library for this language. Modelica is positioned as an object-oriented physical modeling language. The equations are a special entity in the language. The number of equations and variables in the program must be the same.
Modelica supports continuous and hybrid (continuous-discrete) paradigms. However, the discrete elements are also present in the language.

TCP congestion control mechanism
The TCP protocol uses a sliding window mechanism to avoid a congestion. The implementation of this mechanism depends on the particular type of TCP protocol.
In TCP Reno protocol the congestion control mechanism consists of the following phases: slow start, congestion avoidance, fast recovery, and timeout. Dynamics of changes in congestion window size (CWND) depends on the specific phase (see Fig. 1).
If the total network arrival rate exceeds the maximum network rate, there is a network overload. If the overload condition lasts long enough for the buffer overflows, the data loss occurs in the network. Lost segments are retransmitted by TCP and promote continued growth of congestion. The transport protocol control algorithm should prevent the occurrence of congestion and facilitate the end of the network overload conditions in the case of its occurrence.
TCP uses a greedy algorithm for the use of bandwidth. At first it attempts to use all the available bandwidth. To do this, it increases the window exponentially (multiplicative increase). In the case of packet loss, the TCP first reduces the window size. Then TCP increases the window size linearly. TCP determines the occurrence of an overload condition expecting that the cause of packet loss is the network congestion. The congestion avoidance algorithm is described in RFC 5681 [17]. Each time the source receives a delivery notification (Acknowledge, ACK), in slow start phase congestion window is increased. The source increases the congestion window size depending on the number of confirmed segments (Segment Size, SS): cwnd = cwnd + 1 for each transmitted ACK. Initial congestion window size (Maximum Segment Size, MSS) can take a value of 1, 2 or 10 segments. The receiver sends an ACK for each packet, but in reality it can be assumed that confirmation come together at the end of the double turnaround time (Round-Trip Time, RTT). Thus, the congestion window is doubled after the round-trip time.
When TCP Reno window size takes the certain value the protocol mechanism enters the congestion avoidance phase. In this phase, the congestion window is increased by the amount of 1/cwnd for each acknowledgment ACK, which is equivalent to increasing of the window by one packet for the double-turn.
Protocol TCP Reno monitors two options of packet loss: • Triple Duplicate ACK (TD). Let n-th package is not delivered, and subsequent packets (n + 1, n + 2, etc.) are delivered. For each packet delivered in violation of prioritization(for n + 1, n + 2, and so on), the recipient sends ACK message for the last undelivered (nth) package. With receiving three such packets the source resends the n-th package. In addition, the window size is decreased by 2 times cwnd → cwnd/2. • Timeout (TO). While sending a package the timeout timer is started. After receiving the confirmation the timer is restarted. Wherein the window size is set to the initial value of the congestion window. The first lost package is resent. The protocol passes into a slow start phase.
The TCP protocol uses multiple timers. The main one is Retransmission timer. It restarts each time when a segment is sended. If an acknowledgment does't received before the timer triggering, then the segment is retransmitted.
The retransmission timer doesn't change in the slow start phase and in the congestion avoidance phase. It linearly decreases over time in the fast recovery phase and in the timeout phase.
Thus we can write the equations for the window evolution in TCP protocol in Modelica language (Listing 1).

Modeling of discrete state transitions
Let's describe the TCP state transitions. Note that since we have already described the internal states of each phase as the equations in Modelica, we can't use the equations to describe the state transitions. Otherwise, the resulting system will be an overdetermined. For such cases, Modelica language provides the algorithm statement.
The slow start is the initial state. We use the ssth variable for transition from a slow start phase to a congestion avoidance phase. when a new connection is opened, this variable is initialized to the maximum possible size of the window. The slow start phase continues until the value of the cwnd reaches the ssth, then a transition occurs to the congestion avoidance phase.
When packet loss occurs the TCP goes either into a fast recovery phase, or into a timeout phase. We model this transition empirically, depending on the window threshold (timeout_th) [18].
Similarly, the TCP protocol can either go from the congestion avoidance phase into a fast recovery phase, or into a timeout phase.
After retransmission time the TCP protocol goes from a fast recover phase into a congestion avoidance phase, and from a timeout phase into a slow start phase.
Based on the description of the state transitions we can construct the UML-diagram (Fig. 2). The resulting chart can be converted to a Modelica program. We give a fragment of the listing (Listing 2). Here we demonstrate only the state transition algorithm for TCP. As can be seen, it is made by almost verbatim copying of UML-diagrams (it is theoretically possible to carry out the code generation based on the corresponding chart).

The transition to the continuous model
Because we want to construct the hybrid continuous-discrete model, we need pass to the continuous-time model in order to describe the operation of each TCP phase. The transition between the phases will be described by discrete states.
Using the results of section 3, the behavior of our model may be formalized. A congestion window change is described by an elementary event, which corresponds to a single acknowledgment or confirmation of all. Let us assume that the elementary event is the arrival of all acknowledgments that occurs during the round-trip time (RTT). In the slow start phase a congestion window size increases with each occurrence of confirmation (ACK): We now rewrite (1) relative to the round-trip time T : Assuming that ∆t = T , we obtain dW dt = W T , Thus, the window grows exponentially, as it should be in a slow start phase in accordance with the TCP description.
Similarly, we examine congestion avoidance phase. For each occurrence of an ACK the window size is increased: .
We rewrite this for a round-trip time: W (t n + ∆t) = W (t n ) + 1 W (t n ) W (t n ); W (t n + ∆t) − W (t n ) ∆t = 1 ∆t .
Assuming that ∆t = T , we have dW dt = 1 T , The result is a linear increase of the window, as described in the specification of the TCP. Using these equations, we can write the equations for the TCP protocol in Modelica language (Listing 3).

Conclusions
We investigated the TCP protocol as part of a larger system. Some mathematical models (both analytical and simulation) of this mechanism using different paradigms and techniques were presented. On closer inspection, the presented modeling techniques have shown their shortcomings.
The considered in the article hybrid (continuous-discrete) approach seems to be the most appropriate for network protocol modeling.