Previous Chapter | Table of Contents | Next Chapter

Chapter 2 - The Simple ATM Example

Defining a Simple Protocol

In ProtoCollum, each part of a system is represented by a Processing Entity (or "PE"). Each Processing Entity has some number of Rules that are used to describe its behavior and interactions with other Processing Entities. A Rule consists of a set of Guard events that are used to decide when the Rule is to be activated and a set of Action events that are evaluated when the Rule is activated.

Each PE is allowed to maintain an internal state separate from that of all other PEs. All communication between PEs is carried by Messages. The Guard events of a Rule of a PE can accept Messages from other PEs and examine the internal state of their own PE. The Action events of that Rule can examine and change the internal state of their own PE, receive information from the Guard events of their Rule, and can send Messages to other PEs.

A more complete and detailed explanation of the Message Passing Model used by ProtoCollum can be found in the first and second chapters of the ProtoCollum User Guide, available here. We concentrate in this Quick Start Guide on just enough of the basics to get a new user up and running with ProtoCollum.

The Simple ATM Example

We begin with a high-level representation of the operation of an ATM. In general, the Customer can perform the following actions:

Each one of these actions corresponds to sending a message from the Customer to the ATM. In response to the actions of the Customer, the ATM in general can perform the following actions:

As can be seen, there are not very many distinct actions, though obviously some actions are appropriate in certain circumstances and inappropriate in others (e.g., if there's already a bank card inserted, it doesn't make much sense to try to insert another one, the ATM can't ejct or retain a bank card if one is not currently inserted). Designing a protocol specification for these operations codifies exactly which actions are appropriate under which circumstances and what happens when those actions are taken. The response of the system to both appropriate and inappropriate actions is relevant in deciding the robustness of the system.

In our simple ATM example, we will start with two PEs, one representing the Customer and one representing the ATM. As we refine the model, additional PEs will be added as necessary. Each one of the Customer or ATM actions mentioned above is represented by a message passed either from the Customer PE to the ATM PE or vice-versa.

Our first version will be very simple, allowing only the insertion of the bank card and then a press of the Cancel button to retrieve it. Though not exciting in itself, this will allow us to go through many of the GUI operations that will be necessary as we progress to more and more complex protocol specifications.

Enough introduction, let's get started with ProtoCollum.

Capturing the Simple Protocol

As mentioned above, ProtoCollum systems consist of Processing Entities, Rules, and Messages. In the following sections, we show at an introductory level how to create, connect, and adjust the properties of each of these types of objects.

Creating the Processing Entities

Invoke ProtoCollum. You should be looking at an empty sheet as shown in Figure 1.

Empty ProtoCollum Edit Sheet
Figure 1. Empty ProtoCollum Edit Sheet

Click on the "PE Mode" button on the toolbar and then click in two spots in the sheet to get two empty PEs. Your window should now look like Figure 2. Resize the window as necessary to keep everything visible.

Two Processing Entities
Figure 2. Two Processing Entities

Click on the "Select Mode" button on the toolbar to get back into Select Mode and then right-click on the pe_0 PE (the one on the left). This will open the PE Properties dialog box, as shown in Figure 3.

Processing Entity Properties Dialog Box
Figure 3. Processing Entity Properties Dialog Box

Using this dialog box, you can change the label of pe_0 to something a bit more mnemonic, such as Customer. Once you've made the change in the Label field of the dialog box, the "Apply" button will change to red to remind you that you have made changes that have not yet been saved. See Figure 4.

Processing Entity Name Change
Figure 4. Processing Entity Name Change

If you click the "Apply" button to record the change to the label, the name displayed on the Edit Sheet for pe_0 will change to Customer and the Properties Dialog Box will stay open. If you clicked the "OK" button, the change will be recorded and the dialog box will close. Click "OK".

Now right-click on the Processing Entity pe_1 and change its label to ATM. Click "OK" to record this change and close the dialog box. Your window should now look like Figure 5.

Two Renamed Processing Entities
Figure 5. Two Renamed Processing Entities

Now that we have done a bit of work, we should save our efforts using the File>Save (or File>Save As) command. This will bring up a standard file selection dialog box. Navigate to the directory you want to save your work in, enter the filename ATM_1, and click "OK". We will update the filename as we further refine the model.

After you have saved your work, take a look at the command results window (shown in Figure 6). This window shows the output of Tcl/Tk commands as they are executed. This is also the window where user-written Tcl/Tk code can display messages. This capability will become more important as the model's complexity increases.

Command Results Window
Figure 6. Command Results Window

Figure 6 shows only the bottom portion of the full ProtoCollum window to focus attention on the Command Results window. The small box in the upper right of the window can be used to change the proportion of the overall ProtoCollum window that is devoted to either the main drawing sheet or the command results.

Adding The First Message and Associated Rules

Now that we have the PEs on the sheet, we can add our first message, representing the Customer inserting their bank card into the ATM. This is a Customer action, so the message source is the PE Customer and its destination is the PE ATM.

We will use the Fast Message Mode to create this message since this mode allows you to add a source rule, a message, and a destination rule all in a single operation.

Click on the "Fast Message Mode" button on the toolbar. The mouse pointer will change to the message cursor . Move the cursor over the stem beneath the Customer PE (the source of the message) and it will change to to indicate that you can click there. Left click and a Rule will appear (as in Figure 7).

Now move the cursor over to the stem beneath the ATM PE (the destination of the message). You will see a dashed line moving with the mouse cursor (as in Figure 8), which has returned to its original form . The line represents the message that will be created. Once over the PE ATM stem, the cursor changes back to to indicate you can click there. Left click and a Rule will appear (as in Figure 9).

Adding the Source Rule in Fast Message Mode
Figure 7. Adding the Source Rule in Fast Message Mode
Adding the Message in Fast Message Mode
Figure 8. Adding the Message in Fast Message Mode
Adding the Destination Rule in Fast Message Mode
Figure 9. Adding the Destination Rule in Fast Message Mode

Click on the "Select Mode" button on the toolbar to get back into Select Mode and then right-click on the Rule rule_0 (the one on PE Customer). Similar to right-clicking a PE, this will open the Rule Properties dialog box, as shown in Figure 10.

Rule Properties Dialog Box
Figure 10. Rule Properties Dialog Box

Change the Label of the rule to something more mnemonic, such as insertCard. Click "OK" to record the change and close the box. In a similar fashion, change the label of rule_1 to acceptCard. Finally, right-click on the Message msg_0 to see its Message Properties dialog box, as shown in Figure 11. Change the message's label to insertedCard and click "OK".

Message Properties Dialog Box
Figure 11. Message Properties Dialog Box

Your window should now look like Figure 12.

First Message Added
Figure 12. First Message Added

The Structure of Rules

Let's take a closer look at the structure of the two rules that we have just added. The Fast Message Mode took care of the details above, but it's instructive to have a quick review of what exactly happened and what it means. (More complete information on the nature of Rules can be found in the ProtoCollum User Guide.)

A rule has a Guard section and an Action section. When all of the events in the Guard section are satisfied, the events specified in the Action section are evaluated. The events in the Guard section can receive messages from other Processing Entities and examine the state of their own PE. The events in the Action section can send events to other PEs and examine and set their own PE's state.

The Guard and Action sections of the rules insertCard and acceptCard are shown in Figure 13. Rule insertCard has only a single event in its Action section, as indicated by the event box between the Mid and End marker ovals .

Two Rules
Figure 13. Two Rules

Similarly, the Rule acceptCard has only a single event in its Guard section, as indicated by the event box between the Upper and Mid marker ovals . For easy visual distinction, the Guard section (between the Upper and Mid marker ovals) has an orange stem while the Action section (between the Mid and Lower marker ovals) has a green stem.

In Figure 13, we see that the Message cardInserted is sent from the Action section of Rule insertCard and is received by the Guard section of Rule acceptCard. Rule insertCard has no events that need to be satisfied in its Guard section, so its Action section will be evaluated any time the Rule is activated. Rule acceptCard has only one event in its Guard section (the one that accepts the Message cardInserted), so its Action section (empty at present) will be evaluated whenever that Message is received.

Adding the Second Messange and Associated Rules

The first message and rules takes care of inserting the bank card. Let's now add a second message and pair of rules to support the Cancel operation.

Once again, click on the "Fast Message Mode" button on the toolbar. With the message cursor , click on the stem of the Customer PE (the source of the message) below the insertCard rule. A new rule will be added. Move over to the stem of the ATM PE (the destination of the message) and click below the acceptCard rule. The new message and associated rules have been added.

Using the Rule Properties dialog (right-click on the rule), change the name of the new rule under the Customer PE to pressCancel. Click "OK" to record the change. Similarly, change the name of the new rule under the ATM PE to cancelOperation. (Don't forget to click "OK" to record the change.)

Finally, use the Message Properties dialog (right-click on the message) to change the name of the new message to keypressCancel. Click "OK" to record the change. Your sheet should now look like Figure 14.

Second Message Added
Figure 14. Second Message Added

Save your work using the File>Save (or File>Save As...) menu item.

Renaming the Edit Sheet

Now that we have created our first Processing Entities and added some Rules and Messages, we can move on to exercising the protocol. Before we get to that, though, let's engage in a bit of housekeeping: renaming this sheet from sheet_0 to ATM Protocol. This will make it easier to keep the sheets straight as we add more.

Right-click on the sheet name tab at the lower left of the sheet. It looks like . The Sheet Tab Menu will pop up, as shown in Figure 15. Select the Rename... menu item to get the Edit Sheet Label dialog box, as shown in Figure 16. Change the name to ATM Protocol and click "OK".

Sheet Tab Menu
Figure 15. Sheet Tab Menu
Edit Sheet Label Dialog Box
Figure 16. Edit Sheet Label Dialog Box

Save your work using the File>Save (or File>Save As...) menu item before we move on to the next section.

Where to Go Next

???

Previous Chapter | Table of Contents | Next Chapter

Copyright © 2003-2005 by Bellum Software™
last updated on 10 August 2005