• Ingen resultater fundet

Design of the Web-Based Approach

Web-Based Interfaces for Simulation of Coloured Petri Net Models

6.3 Design of the Web-Based Approach

Figure 6.3: HTML form as interface to the CPN model.

6.3 Design of the Web-Based Approach

The general description of the approach for creating web-based interfaces for simulating CPN models introduced in Sect. 6.1 will be considered further in this section. Section 6.4 will focus on how to implement the design in the Design/CPN tool.

Several different options exist for executing and controlling a program via a web browser. In this paper we describe an approach for controlling sim-ulations using so-called Forms and Common Gateway Interface scripts (CGI scripts) [35], which are both well-known Internet techniques.

Figure 6.5 illustrates the setup for using CGI scripts, while the message sequence chart in Fig. 6.6 illustrates what happens when a CGI script is ac-tivated by submitting a form from a web browser. Assume that a hypertext document (backup form.html) is located on Computer B which is a web server (HTTP server B). The document could, e.g. be an HTML document producing a form like the one in Fig. 6.3. The application user using the web browser at Computer A downloads the HTML document. The application user then fills out and submits the form. When the application user submits the form, a link (URL) to a file on Computer C that holds the CGI script (backup.cgi) will be followed. (The CGI script may also be placed on the same computer as the HTML form.) This link is a ”normal” HTTP link, but the file on the web server on Computer B is stored in such a way that the web server on Computer C can tell that the file contains a CGI script that is to be executed, rather than a doc-ument that is to be sent to the client as usual. The web server then executes the CGI script which can read the input that the user typed into the form. Based on the input the CGI script dynamically generates an HTML document. The HTML document is sent to the client while it is being generated as a stream.

The web browser on the client computer displays the document while receiving

Figure 6.4: An HTML document containing the results of simulating the CPN model.

the stream of HTML code from the web server, as it would display any other HTML document. The HTML document being received could, e.g. be like the one in Fig. 6.4.

Forms are very useful for specifying textual input via a web browser. Fur-thermore, they provide a simple mechanism for submitting the contents of the form to a CGI script. The HTML code for specifying a form is also very sim-ple. Figure 6.7 shows the HTML code used to display the HTML document in Fig. 6.3. The URL www.daimi.au.dk/cgi-sim/cpn.cgiin line 3identifies the CGI script to be activated when the user submits the form. The button for submitting the form is created using line 15 in Fig. 6.7. Lines 9 – 14 specify that five fields for input should be created. The input fields are named uniquely in the form using names (bandwidth,servers,clients,disk, andprice). These names are used by the CGI script to access the values of the fields when the form is submitted.

Note that only a few lines of HTML code are necessary to create a form,

6.3. Design of the Web-Based Approach 49

backup_form.html HTTP Server

Computer B

Internet

HTTP Server

Web Browser Computer A

backup.cgi Computer C URL

Figure 6.5: A web browser and two web servers.

HTTP Server B Web Browser A

Fill form Submit form

HTTP Server C

Start CGI script

End CGI script get_URL(backup_form.html)

backup_form.html

get_URL(CGI script)

HTML result HTML result

Figure 6.6: A web browser requests a CGI script to be executed.

thus most people who can read CPN models and do some basic programming should be able to learn to write such HTML code without too much difficulty.

The program or CGI script that reads the information submitted in the form and that processes the information is more complex. Specialised scripts are required to handle the incoming form information. CGI scripts may be written in scripting languages like Perl [109] or in programming languages like C and Standard ML (SML) [83]. In general, a CGI script can be considered as an executable program that can be executed on a web server by request from a web browser.

To be able to simulate CPN models using CGI scripts in a controllable manner there are some requirements of the Petri net tool. First of all, the Petri net tool should be able to start a simulation of a specific CPN model without requiring a user to interact with the tool-specific GUI. For example, it should not be necessary to use dialog boxes in the Petri net tool to start a simulation – it should be possible to automate everything in a script. The tool should allow users to write user-defined functions, e.g. for retrieving input, saving files, and printing to standard output. The reason for these requirements is that because a CGI script is invoked via a form, the CGI script must be able to control everything related to reading input from the form, setting the initial state, starting the simulation, and producing results.

To make the CGI script as user-configurable as possible with respect to controlling a simulation, the CGI script must be able to control the simulation

<HTML><BODY> 1

<FORM method=GET

action="http://www.daimi.au.dk/cgi-sim/cpn.cgi"> 3

<CENTER>

<H1>Backup Unlimited Inc.</H1> 5

<H3>Input your data and requirements for a backup system</H3>

<H3>- and we will provide you with what you need for your system.</H3> 7

</CENTER>

Network bandwidth: <INPUT size=15 type=text name=bandwidth value=5>Mbps<BR> 9 Number of servers: <INPUT size=15 type=text name=servers value=1><BR>

Number of workstations: <INPUT size=15 type=text name=clients value=10><BR>11 Disk capacity: <INPUT size=15 type=text name=disk value=10>GB<BR>

Is price more important than performance: 13

<INPUT size=15 type=checkbox name=price><BR><BR>

<INPUT type=submit value=" Submit Requirements "> 15

</FORM></BODY>

</HTML> 17

Figure 6.7: HTML code for creating a form.

tool in the following way: when the CGI script is executed from a web browser, it should automatically execute a sequence of commands. In the following we will refer to this sequence of commands as a batch script [57]. A batch script can be considered as a simulation control script with the purpose of specifying exactly what the CGI script is intended to do – including when to start a simulation. In this context, a CGI script will be defined as an executable CPN simulator together with a batch script which defines what happens when the CGI script is executed.

To give the user the largest possible freedom for defining CGI scripts the batch script needs to be able to be specified by the user. In the context of CGI scripts the batch script typically has a certain structure which is likely to include the following actions:

i. Retrieve parameters from the form (see Fig. 6.7 for example of HTML code for a form).

ii. While there are more simulations to run do the following:

(a) Calculate markings to be used to initialise the state of the CPN model.

(b) Initialise the state of the simulator.

(c) Run simulation – and collect data.

(d) Save results and/or send HTML code to the client web browser.

iii. Quit the CGI script.

First of all, the batch script needs to retrieve the parameters that are sent to the CGI script from the form. After having extracted the data from the input fields in the form, the batch script needs to specify how to run the simulation(s).

6.3. Design of the Web-Based Approach 51

<HTML><BODY> 1

<FORM method=GET action="http://www.daimi.au.dk/cgi-sim/place_order.cgi">

<CENTER> 3

<H1>Backup Unlimited Inc.</H1>

</CENTER> 5

We have now simulated a model of your system using your specified

requirements. We propose that you buy the following backup devices: 7 Backup device B1 or Backup device B2. You can decide which best

suits your needs from the graphs below: 9

<BR>

<CENTER> 11

<IMG SRC="http://www.daimi.au.dk/result.graph.png">

</CENTER> 13

I order the following item: <input size=15 type=text name=no value=B1><BR>

<INPUT type=submit value=" Place Order "><br><br> 15

</FORM></BODY>

</HTML> 17

Figure 6.8: HTML code for creating the form in Fig. 6.4.

The batch script often starts by calculating the markings for the initial state.

The calculation is likely to use input parameters from the form or results from previous simulations. Now the state of the simulator is ready for starting the simulation.

While the simulation runs, data is often collected and saved in files for later processing. Therefore, the model often needs to be instrumented to collect the needed data. When a simulation has finished, the results collected during simulations may be sent directly to the web browser (by printing HTML code to standard output). In addition, results from the simulation may be saved to files for later post-processing. Finally, the batch script may decide that more simulations are to be performed. Then the batch script may continue by restarting the script, otherwise the CGI script terminates.

Simulation tools that support converting a simulator into a CGI script may also include some auxiliary and level facilities. Examples of such high-level facilities are facilities for creating graphs to be saved in files, and facilities for printing HTML code for referring to graphs in the HTML document being generated by the CGI script. This makes it possible for the web browser to download the image containing the graph while displaying the HTML docu-ment. Such an imageresult.graph.pngwas included in the HTML document in Fig. 6.4 in Sect. 6.2 using HTML code like line 12 in Fig. 6.8.

If the simulation tool does not contain the needed post-processing facilities itself, it may possibly use external programs for post-processing of the data.

There are only two requirements of the post-processing tool to allow using it from the CGI script. The first one is that the tool should support being executed from the command line using a script containing all the needed commands to create the graph. Secondly, the tool should be able to save the output to files.

Gnuplot [32] is an example of a tool that can be used for generating plots and graphs, and it supports command line scripts, too.

Given a CPN tool that fulfills the above mentioned requirements by allowing

to create batch scripts and then be remotely controlled, it is possible to create CGI scripts that fulfil many needs for simulation of CPN models from web browsers. In total the CPN expert needs to create two different files: an HTML form (like Fig. 6.7) to be used for specifying input to the CGI script, and the batch script for retrieving input from the form, running the simulation, and for producing results to be displayed at the web browser.

In the approach described in this paper, all input from the application user should be ready before submitting the form. In this situation it is not possible to control the simulation after it is started – the simulation will be non-interactive but results can be shown gradually as they are generated. In Sect. 6.6 we discuss future work which addresses how to obtain interactive simulations within the approach.