Docsity

Verifying Network Protocols: A Logical Approach, Study notes of Network Technologies and TCP/IP

Toggle sidebar
bg1
COMPUTER SYSTEMS LABORATORY
STANFORD ELECTRONICS LABORATORIES
DEPARTMENT OF ELECTRICAL ENGINEERING
STANFORD UNIVERSITY
-
STANFORD, CA 94305
VERIFYING
NETWORK
PROTOCOLS
USING
TEMPORAL
LOGIC
Brent T. Hailpern
Susan S. Owicki
TECHNICAL
REPORT
NO.
192
June 1980
This work was supported
by
the Joint Services Electronics Project
under contract N-00014-75-C-0601. Brent Hailpern was supported by
fellowships from the National Science Foundation
and the Fannie and John Hertz Foundation
pf3
pf4
pf5
pf8
pf9
pfa
pff
pf12
pf13
pf14
pf16
pf17
pf18

Partial preview of the text

Download Verifying Network Protocols: A Logical Approach and more Study notes Network Technologies and TCP/IP in PDF only on Docsity!

COMPUTER SYSTEMS LABORATORY

STANFORD ELECTRONICS LABORATORIES

DEPARTMENT OF ELECTRICAL ENGINEERING STANFORD UNIVERSITY - STANFORD, CA 94305

VERIFYING NETWORK PROTOCOLS

USING TEMPORAL LOGIC

Brent T. Hailpern

Susan S. Owicki

TECHNICAL REPORT NO. 192

June 1980

This work was supported by the Joint Services Electronics Project under contract N-00014-75-C-0601. Brent Hailpern was supported by fellowships from the National Science Foundation and the Fannie and John Hertz Foundation

Introduction

Programs that implement computer communication protocols can exhibit ex- tremely complicated behavior, since they must cope with asynchronous comput- ing agents and the possibility of failures in the agents and in the communica- tion medium. (^) A survey of the literature in the area of protocol verification may be found in Sunshine [l7]. Most previous approaches to verifying network protocols have been based upon reachability arguments for finite-state models of the protocols. However, only protocols of limited complexity can be verified using finite-state models, because of the combinatorial explosion of the state space as the complexity of the protocol increases. Finite-state models also have difficulty in expressing properties related to correct data transfer. In contrast, the approach described here models a protocol as a parallel program, and correctness proofs follow the Floyd/Hoare style of program verification. Logical assertions attached to the program abstract from the representation of the state and allow reasoning about classes of states. This avoids the combinatorial explosion, and the length of the proof need not grow unmanageably as the protocol size increases. In this approach, the network/protocol system is modeled by a set of inter- acting modules that represent logical units of the system, such as the communica-

  • tion medium, transmitter, and receiver. There are two kinds of modules to be considered: processes and monitors. A process is an active program component, and a monitor is a data abstraction with synchronization [2, 71. We exploit the modularity of the system model in the construction of proofs. At the lowest level, the properties of processes and monitors are verified by examination of their code. In constructing the system proof we use these verified properties and can ignore the internal structure of the module implementations. For example, buffers are an abstract data type that may be implemented in many ways. Any implementation meeting the requirements of the data type may be used in the protocol without affecting the correctness proof of the rest of the system. Two kinds of properties, safety and liveness, are important for parallel sys- tems. Safety properties have the form *bad things will not happenā€. They are analogous to partial correctness and are expressed by invariant assertions which must be satisfied by the system state at all times. Safety properties are often expressed in terms of auxiliary variables that record the history of the interac- tions of the modules. Since auxiliary variables are not implemented, they can record histories of unbounded length and are an important element in our proofs. Safety proofs are constructed as follows. One first verifies the invariants of the lowest level modules directly from the code. One then shows that in conjunction these invariants imply the invariants of larger components; ultimately arriving at a proof of the invariant of the whole system.

retransmission. The first time the receiver gets a message with a given sequence number, it records the message in the output stream. It also sends the transmitter an acknowledgment for every message, it receives.

Temporal Logic

Temporal logic provides operators for reasoning about program computations. A computation is a sequence of states that could arise during program execution. Informally, the first state in a computation represents the present, and subsequent states represent the future. Computations are not restricted to starting at the beginning of the program, so a *futureā€ state in one computation may be the Upresentā€ state in another. The version of temporal logic we will use was developed by Pnueli [4, 13, 14, 151, and is further described by Lamport [9]. Its two basic operators are o (henceforth) and o (eventually). The formula UP (henceforth P) means aP is true for all states in the computation.ā€ The formula OP (eventually P) is interpreted as ā€œthere is some state in the computation in which P is true.ā€ The modalities o and o are duals, that is,

. -^ OPE^ WO-JP,

When we say that a temporal formula is true for a program, we mean that it is true for all computations of that program. Temporal operators can be used to express both safety and liveness properties. For example, program termination, ,a liveness property, can be expressed by the formula atP 3 OufterP,

where ot P and after P are assertions that are true of states in which control is (respectively) at the beginning or end of the program. An example of a safety property is an inductive assertion, that is, an assertion that will remain true if it ever becomes true. The following formula states that I is an inductive assertion

Combinations of the two modalities are also useful. For example, the formula DO P (infinitely often P) implies that there are an infinite number of future states for which P is true. (To understand this interpretation, note that OP implies that P will be true in some future state. The formula OOP states that this will always be true. In particular, if P ever becomes false, it is guaranteed to become true again at some later time, and this means that it must be true an infinite number

of times.) The oo operator is especially useful for stating recurring properties of a program, for example,

ao(the buj jet is not jdf)

The dual of infinitely often (00) is 00, pronounced eventually henceforth. The formula OOP states that there is some point after which P remains true forever. An example of the use of this modality concerns program deadlock. Deadlock occurs when each process in a system is waiting for some other process to release a resource. One could state that deadlock is inevitable by the formula

OO(all pr ocesses are waiting).

Biatories

Our proof uses history variables to record the sequence of messages that are the input and output of the modules of the system. History variables have frequently been used in reasoning about communication systems [5,8, 11, 121. The -names of the history variables are indicated in the network diagram in Figure 2. As already mentioned, X is the input history of the transmitter (and the entire system), and Y is the output of the receiver (and the system). The input and output histories of the message medium are a and 8, respectively, while the input and output histories of the acknowledgment medium are 7 and 6. We denote the ith element of X by di, since it is the tl^ th datum. A message consisting of the pair i and di, that is [i, di], will be abbreviated Mi. This is the form of messages in Q and p. An acknowledgment for message i, the pair [i, ā€˜(a&ā€œ] is denoted by Ai: messages in 7 and 6 have this form. We now introduce some notation for describing histories. Let A and B be

arbitrary history sequences. The length of A is denoted by IAI. If A has elements

U, U, v, z then we can write, A=< uvyz >.

If I4 =^ IZ then we may also write

We denote concatenation of sequences by juxtaposition, that is,

A=< uu >< yz >=< uvyz >

liveness properties are specified by temporal logic assertions called commitments. Commitments describe conditions that the process causes to become true. Finally, the services provided by the medium (sending and receiving a message, checking for the presence of messages) must be precisely defined. Since the communication medium we are considering is an unreliable one, it has a very weak invariant: nothing comes out that was not put I’D. More precisely,

where m is any message. This safety assertion describes a medium which may lose, duplicate, and re-order messages: the only assumption is that it does not create spurious ones. The invariants above would be satisfied by a medium that never delivered any messages, and in that case no output would ever appear. The medium has two independent commitments that guarantee that some messages ultimately get through. The first is an assertion that if an unbounded number of messages are sent, then messages are infinitely often available to be received.

44 1^00 mtdhi8t8ikf

u(7) 3 0 0 mrt.EzistsM

( m t r 2 )

(mrt2)

The second commitment asserts that if the same message is .sent over and over again, it will eventually be delivered (provided that the receiving process keeps accepting messages). This is expressed by the formulas

(uc(u, m) A u(p)) 3 Om E p

(u47, m) A u(6)) 3 On2^ E^6

These are about the weakest assumptions we can make and still be able to show that the protocol is able to deliver messages. To precisely specify the services of the medium we give pre, post and Iive assertions about each operation. Pre and post give safety (partial correctness) conditions for the operations. If the pre-condition holds when the operation is invoked, and if it terminates, then at termination the post-condition must hold. The variables in these assertion must be private to the process that invokes the operation, in the sense that no other process can modify their values. This avoids the complexity that can arise when dealing with variables that are shared between

several processes. (A general discussion of private variables is given by Owicki [ll].) The live assertion describes the effects that the operation causes when it is invoked. This may be a conditional commitment (as shown for receive below) and it may involve variables that can be modified by other processes. The medium we are assuming provides three services: send a message, receive a message, and check to see whether any messages are waiting to be received. The specifications of these services are given below for the medium mtr; the specifications for mrt are essentially the same.

send(m)

  • pre: a = A post: a =A live: at mtr.send 3 Oa^ jter^ mtr.send

receive(var m)

pre: p = B

  • post: p =B live: (at mtr .r eceive A Omtr.hi8t8M) 1 O(a jter mtveceive)

existsM

pre: true post: true 1 live: at^ mtr.ezi8t8hf^ >^ Oafter^ mtr.ezistsM

Note that a send operation always terminates, and receive terminates if a message is available. The pre and post conditions of mtr.ExistsM are both Yrueā€, which gives no safety information about the operation. In fact, we will only use mtr.existsM in reasoning about the liveness property that a receive terminates. The timer is another black box, and we could define its properties in a similar way. However, since we will not be doing detailed proofs, it suffices to state that if the timer is set and never canceled then eventually a timeout notification will be received.

\

. The second invariant states that if acknowledgment^ i^ is in the output history d (^) 7, message i is in the input history /3, and the associated datum di is in Y. This is obvious from the flow of control in the receiver. An acknowledgment is only sent after the corresponding message has been received and its datum appended to Y.

Safety: System.

The system safety specifications are also given by an invariant assertion:

Y (^) - 4x. w

This assertion states that the output values are some initial sequence of the input values. It does not imply that any output values are ever produced; that requirement is given in the liveness specifications to be discussed later. The system safety specifications are not verified by examining the program code. Instead, we show that the invariant of the system is implied by the invariants of its components. This approach lessens the level of detail which must be dealt with at each step. It has the further advantage that the system proof remains valid if any component is replaced by a different implementation that meets the same specifications. Let us now proceed by assuming the invariants for the transmitter, the receiver, and the communications medium, and showing that the system invariant must follow. As a first step, we note that the hypothesis of the receiver assertion Rl REP 3 3i(m=MJ

follows immediately from the safety properties of the transmitter and receiver. Since the transmitter only puts legitimate messages into the medium (Tl), and any message that comes out of the medium must have been put in by the transmitter (mtrl), the receiver can only obtain legitimate messages. Now let n = max{i:Mi E @}.

Since the hypothesis of Rl is satisfied, we know that the conclusion of RI holds, namely Y -(< di >;=I l

But by mtrl, M,EP 3 M&a

and by Tl,

Thus we can conclude

which implies the system safety assertion Sl.

Liveness: Transmitter and Receiver

Liveness specifications of processes, like those of monitors, are given by com- mitments. Verifying that a process satisfies its liveness specifications requires reasoning based on assumptions about the liveness properties of program state- ments. Our assumption is that processes execute fairly, that is, each process makes progress unless it is blocked. More precisely, let 8 be an unblockable action in the program, at 8 be the assertion that 6 is ready to be executed, and after 8 the assertion that control has finished 8. Our basic liveness assumption can be expressed in temporal logic by

at8 3 Oajter 8.

In the protocol system we are discussing, a process can only become blocked while trying to execute a receive operation on a communication medium which has nothing available to be received. The liveness specification for the receive operation (of mtr) states that receive will terminate if a message is available, that

(at mtrreceive A mtr.EzistsM) 3 Oa jter^ mtweceive

Starting from these assumptions about program actions, one can derive rules for proving liveness properties of larger program statements. For example, con- sider a program statement of the form loops end loop

where S is a statement that does not contain any loops or actions that could be blocked, For such a statement, one can prove

atS 3 q OatS,

that is, control will infinitely often be at the beginning of S, (This is exactly the form of the loop in the transmitter program.) On the other hand, consider the receiver program. Here again we have a loop, but its body S’^ contains the

the absence of blocking, and the fact that the transmitter will accept an acknowl- edgment each time around its loop if one is available. The third commitment is a promise to start sending the next data item as soon as the current one has been acknowledged. Vi(Ai E 6 3 1x1 2 i) 3

Q j(Aj E 6 3 (L(c(QI, Mj+l) V O(Aj+l E 6)))

WI

The hypothesis of this commitment is an assertion that the rest of the system must satisfy: an acknowledgment for message i is not received before the trans- mitter has started to work on message i. Under that assumption, once the trans- mitter receives acknowledgment j, it starts to send message j + 1, and it will send that message an unbounded number of times unless it eventually receives acknowledgment j + 1. Next we consider the liveness specifications of the receiver. Again we have three commitments, and they are quite similar to the commitments of the trans- mitter. First, the receiver will cause /9 and 7 to grow unboundedly as long as it is able to receive messages from mtr. q omtr.Ezists M (^3) 47) (R3)

. - oomtr.EzistsM^1 u(P)^ VW The receiver code satisfies these assertions because the repeated availability of messages implies that the receiver can not be blocked at its receive operation. Therefore it repeatedly executes its loop body, and each time it increases the length of /3 and 7. Note that the transmitter commitment T3, which corresponds to R3, did not require an assumption about the rest of the system in order to guarantee that the size of Q keeps growing. This difference between T3 and R comes from the fact that the transmitter uses a timeout mechanism and the receiver does not. The receiver’s third commitment is to acknowledge each message it receives. (Vi(MieP 3 IYI 2 i-l)~u(P)) 3 (R5)

W Mj E P 3 (o(lY) 2 i) A (47~Ai) V OMj+l E /VI This is analogous to transmitter commitment T5, Assuming that message i does not arrive until the receiver has processed i - 1, and that ,8 grows unboundedly, the receiver will acknowledge each message it receives until the next one arrives, and will add dk to the output sequence Y. (It is necessary to assume uv) because the receiver can block if messages do not arrive; such an assumption is unnecessary for the transmitter, since it can never block.)

Liveneas: no starvation

Our first step in establishing system liveness is a proof that all of the medium history variables grow unboundedly.

44 (T3) u(a) 3 q O(mtr.EzistsM) (mtr2) q O(mtr.EzistsM) 3 u(7) (^) WI q o(mtr.Exists M) > u(p) (^) VW u(7) > oo(mrt.ExistsM) (mrt2) q o(mrt.ExistsM) 3 u(6) (^) (W

In combination, these assertions imply that all of the history sequences grow without bound, that is,

and that input is infinitely often available for mrt.receive and mtr.receive.

Liveness: System

The system liveness property we ultimately want to prove is that each message is eventually output. Since the safety property tells us that any output produced is an initial segment of the input sequence, all we need to establish is that the output stream gets arbitrarily long, that is,

u(Y) (s2)

We prove this by induction on the length of Y. The induction step is to show that if Y contains k messages at some point, then it will eventually contain k + 1 messages:

o(lYI = k 3 olYl > k)

The first step in the proof is to establish the hypotheses of assertions T5 and R5, which state that messages and acknowledgments do not arrive before the recipient is ready to handle them. This is actually a safety property of the system (it often turns out that liveness proofs require additional safety properties). It can be proved easily from the safety specifications of the modules.

Conclusion

In addition to the protocol presented here, we have proved the correctness of three additional protocols using this approach: Stenning’s full data transfer pro- tocol 1161, the alternating bit protocol (as stated by Bochmann [l]), and Brinch Hansen’s multiprocessor network [3]. We have found that program verification techniques can be used to prove the safety and liveness of network protocols that handle an unreliable medium. By insisting on modular decomposition and restricting the view of implementation details, we are able to manage the complexity of program proofs. Temporal logic is an important tool, which allows us to state liveness properties in a clear, consistent manner.

References

[l] Gregor V. Bochmann and Jan Gecsei. A unified method for the specification and verification of protocols. Proceedings of FLP Congress 77, pages 229-

  1. North Holland Publishing Company, 1977.

.’ - [2] Per Brinch Hansen. Operating System Principles. Prentice-Hall, Englewood Cliffs, New Jersey, 1973.

[3] Per Brinch Hansen. Network: A multiprocessor program. H!XE nsnssctions on Software Engineering, SE-4 (3):194-199, May 1978.

. [4] Dov Gabbay, Amir Pnueli, Sharon Shelah, Yonatan Stavi. On the temporal analysis of fairness. Seventh Annual ACM Symposium on Principles of Programming Languages, (Las Vegas) pages 163-173, Association for Com- puting Machinery, 28 January 1980.

[5] Donald I. Good and Richard M. Cohen. Principles of proving concurrent programs in Gypsy. Sixth Annual ACM Symposium on Principles of Pro- gramming Languages, (San Antonio) pages 42-52, Association for Compu- ting Machinery, 29 January 1979.

[6] Brent T. Hailpern. Verifying Concurrent Processes Using Temporal Logic. In preparation, PhD Thesis, Stanford University, 1980.

[7] C. A. R. Hoare. Monitors: An operating system structuring concept. Com- munications of the ACM, 17(10):549-557, October 1974.

[8] John H. Howard. Proving monitors. Communications of the ACM, 19(5):273- 279, May 1976.

[9] Leslie Lamport. ā€˜Sometimen is sometimes *not never? On the temporal logic

of programs. Seventh Annual ACM Symposium on Principles of Program-

ming Languages, (Las Vegas) pages 174-185, Association for Computing Machinery, 28 January 1980.

[lo] Leslie Lamport and Susan S. Owicki. Proving liveness properties of concur- rent programs. In preparation, 1980.

[ll] Susan S. Owicki. Specifications and proofs for abstract data types in concur- rent programs. In F.L. Bauer and M. Broy, editors, Program Construction, pages 174-197. Springer-Verlag, 1979. [lZ] Susan S. Owicki. Specification and verification of a network mail system. In F.L. Bauer and M. Broy, editors, Program Construction, pages 198-234. Springer-Verlag, 1979.

[13] Amir Pnueli. The temporal logic of programs. The 18th Annual Symposium on Foundations of Computer Science, (Providence, Rhode Island) pages 46-57, Institute of Electrical and Electronic Engineers, 31 October 1977.

[14] Amir Pnueli. A temporal semantics for concurrent programs. Unpublished, University of Pennsylvania, November 1977.

. - [15] Amir Pnueli. The temporal semantics of concurrent programs. The Interna- tional Symposium on the Semantics of Concurrent Computation, (Evian) July 1979.

[lS] Norman V. Stenning. A data transfer protocol. Computer Networks, 1(2):99- 110, September 1976.

[17] Carl A. Sunshine. Formal techniques for protocol specification and verification, Computer, 12 (9):20-27, IEEE Computer Society, September 1979.

.