Any variables that are used within the protocol must be initialised
outside the main protocol, otherwise every time the protocol is
called, the variables would be reset. Static variables are not
suitable, since an independent copy of the variables is needed at each
end of the simulated communication channel. An
routine must be included before the
protocol routine. This
allows any variables to be assigned a starting value. It is obvious
that any variables which are setup in the
and then used in the main
protocol, will have to be declared
globally. Examples of variables which need such initialisation are
the sequence numbers of frames to be sent, the status of the link as
perceived by each end, etc.
The overall structure of the complete protocol is shown in
Figure 1. There must be definitions of both the
initialise and the
protocol functions, in that order,
with any other functions used by
protocol coming later in the
file. The global declared data is also available in these functions.
In order to distinguish the two ends of the communications channel, on output they are labelled as Protocol A and Protocol B, whilst the code knows them as 0 and 1.
Figure 1: Overall Structure of a Protocol