|
| 1 | +// Concord |
| 2 | +// |
| 3 | +// Copyright (c) 2022 VMware, Inc. All Rights Reserved. |
| 4 | +// |
| 5 | +// This product is licensed to you under the Apache 2.0 license (the "License"). You may not use this product except in |
| 6 | +// compliance with the Apache 2.0 License. |
| 7 | +// |
| 8 | +// This product may include a number of subcomponents with separate copyright notices and license terms. Your use of |
| 9 | +// these subcomponents is subject to the terms and conditions of the sub-component's license, as noted in the LICENSE |
| 10 | +// file. |
| 11 | + |
| 12 | +include "network.s.dfy" |
| 13 | +include "cluster_config.s.dfy" |
| 14 | +include "messages.dfy" |
| 15 | + |
| 16 | +module Client { |
| 17 | + import opened Library |
| 18 | + import opened HostIdentifiers |
| 19 | + import opened Messages |
| 20 | + import Network |
| 21 | + import ClusterConfig |
| 22 | + |
| 23 | + // Define your Client protocol state machine here. |
| 24 | + datatype Constants = Constants(myId:HostId, clusterConfig:ClusterConfig.Constants) { |
| 25 | + // host constants coupled to DistributedSystem Constants: |
| 26 | + // DistributedSystem tells us our id so we can recognize inbound messages. |
| 27 | + predicate WF() { |
| 28 | + && clusterConfig.WF() |
| 29 | + && clusterConfig.N() <= myId < NumHosts() |
| 30 | + } |
| 31 | + |
| 32 | + predicate Configure(id:HostId, clusterConf:ClusterConfig.Constants) { |
| 33 | + && myId == id |
| 34 | + && clusterConfig == clusterConf |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + // Placeholder for possible client state |
| 39 | + datatype Variables = Variables( |
| 40 | + lastRequestTimestamp:nat, |
| 41 | + lastReplyTimestamp:nat |
| 42 | + ) { |
| 43 | + |
| 44 | + predicate WF(c:Constants) |
| 45 | + { |
| 46 | + && c.WF() |
| 47 | + && lastRequestTimestamp >= lastReplyTimestamp |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + function PendingRequests(c:Constants, v:Variables) : nat |
| 52 | + requires v.WF(c) |
| 53 | + { |
| 54 | + v.lastRequestTimestamp - v.lastReplyTimestamp |
| 55 | + } |
| 56 | + |
| 57 | + // Predicate that describes what is needed and how we mutate the state v into v' when SendPrePrepare |
| 58 | + // Action is taken. We use the "binding" variable msgOps through which we send/recv messages. |
| 59 | + predicate SendClientOperation(c:Constants, v:Variables, v':Variables, msgOps:Network.MessageOps<Message>) |
| 60 | + { |
| 61 | + && v.WF(c) |
| 62 | + && msgOps.IsSend() |
| 63 | + && PendingRequests(c,v) == 0 |
| 64 | + && var msg := msgOps.send.value; |
| 65 | + && msg.payload.ClientRequest? |
| 66 | + && msg.sender == c.myId |
| 67 | + && msg.payload.clientOp.sender == c.myId |
| 68 | + && msg.payload.clientOp.timestamp == v.lastRequestTimestamp + 1 |
| 69 | + && v' == v.(lastRequestTimestamp := v.lastRequestTimestamp + 1) |
| 70 | + } |
| 71 | + |
| 72 | + predicate Init(c:Constants, v:Variables) { |
| 73 | + && v.WF(c) |
| 74 | + && v.lastRequestTimestamp == 0 |
| 75 | + && v.lastReplyTimestamp == 0 |
| 76 | + } |
| 77 | + |
| 78 | + // Jay Normal Form - syntactic sugar, useful for selecting the next step |
| 79 | + datatype Step = |
| 80 | + | SendClientOperationStep() |
| 81 | + |
| 82 | + predicate NextStep(c:Constants, v:Variables, v':Variables, msgOps:Network.MessageOps<Message>, step: Step) { |
| 83 | + match step |
| 84 | + case SendClientOperationStep() => SendClientOperation(c, v, v', msgOps) |
| 85 | + } |
| 86 | + |
| 87 | + predicate Next(c:Constants, v:Variables, v':Variables, msgOps:Network.MessageOps<Message>) { |
| 88 | + exists step :: NextStep(c, v, v', msgOps, step) |
| 89 | + } |
| 90 | +} |
0 commit comments