• No results found

Simulation Software

4.3.1

Introduction

In order to analyse the models and protocols considered in this thesis, simulation software has been developed. Although all Turing-complete programming languages

are equally expressive in terms of the algorithms they can compute and therefore the problems they can analyse, some have features that make them more suitable for deployment than others. For example, scripting languages such as Tcl are suitable for development of operating system scripts and other tasks which are not performance-critical, while compiled languages such as C or C++ are generally applied to performance critical tasks.

This section considers the languages used to construct the software used for simulations, their advantages and limitations, and motivates the decisions made.

4.3.2

Objective Caml

Objective Caml (OCaml) [92] is a functional, object-oriented programming language which generates fast native code. It has been applied to programming language research, system administration and network programming. It is compatible with Windows and Unix platforms, and can be linked to external libraries to provide a graphical user interface.

The flexibility provided by OCaml is capable of modelling general system behaviour in any problem domain, and encapsulating complexity via its object system. This makes it a very appropriate fit for complex simulations with a number of active components. For example, individual protocol layers can be modelled as individual objects, encapsulating all their internal state to make development easier and allow the isolation of individual bugs. Or alternatively, simulation conceptual functions such as routing or energy analysis can be easily separated into distinct modules. This produces elegant and well-structured applications that are easily extensible.

The type system provided by OCaml provides for strong static typing, and type inference, which serves to eliminate a large proportion of errors by checking that data items only undergo meaningful operations. This elimination of a number of logic errors allows the later phases of testing to proceed more quickly, as many bugs have been exposed before compilation succeeds.

A further advantage of OCaml is that the native code generator allows the production of extremely fast code, with a typical benchmark speed between C and C++. In comparison to MATLAB, this allows faster development, by permitting iterations

to test and generate new results. It also increases the size of result sets that can be generated, and allows larger topology sizes to be used. Furthermore, many tasks can be parallelised via the use of distinct processes and inter-process communication, allowing simulations to proceed in parallel on systems with multiple processors. The external library interfaces available for OCaml allow the use of a graphical user interface through the Simple DirectMedia Layer (SDL), which provides an intuitive tool for system testing and analysis and validation of expected protocol behaviour in complex scenarios. This high-performance GUI provides for accessible inspection behaviour of protocols, and permits faster development than merely examining result outputs or event log files. For example, the emergent behaviour of the original dynamic disturbance protocol described in Section 5.4.2, page 121, which led to the development of the dual routing strategy was motivated by examining the behaviour of the protocols using the graphical interface.

There are several disadvantages to OCaml. Firstly, the standard library supplied lacks many convenient data structures, or useful operations upon them. This requires the programmer to reinvent many standard library operations. Secondly, due to the sophistication of the type system, errors can sometimes be cryptic and be caused by errors at a different location than that reported by the compiler. Although a top-level and debugger are provided which allow interaction with a running system, it is difficult to reliably debug a complex application which uses external libraries such as the GUI. Furthermore, parallelism is difficult, and increasing performance on multi-core processors requires the code to be divided into independent processes or to use inter-process communication, which sometimes makes development unnatural.

4.3.3

MATLAB

MATLAB is a programming language intended for fast vector and matrix processing for scientific programming. A wide range of toolboxes for specific tasks exist, and its extensive use in scientific computing ensures that a wide range of third-party code components and software modules are available. The primary advantage to MATLAB is that vector processing is a better fit for applications involving integrated numerical calculations that fit naturally into vectors or matrices, and as a result MATLAB is widely used in signal processing applications.

MATLAB offers an extensive set of libraries and toolboxes to allow code reuse rather than independent development. Its plotting tools allow the user to rapidly experiment with the best and most intuitive way of presenting the results for system testing and documentation. As a result, all topology diagrams produced as graphs in the thesis are generated from MATLAB, even if they are saved from OCaml code originally.

Another compelling advantage of MATLAB is its support for interactive modelling of a scenario, via the interactive command prompt environment, which speeds development and testing in prototyping situations. For example, topologies can be generated, plotted, connectivity tested and routing performed, allowing rapid development through continuous adjustment and debugging of the protocols during development. For example, prototypes of the simulator used in Chapters 5 and 6 were developed in MATLAB.

There are several disadvantages to developing simulation applications with MAT- LAB. The first is the performance which is notably poorer than OCaml. Attempts to compile the code using a MATLAB compiler did not succeed under the system configuration available, and interactive rendering made it preferable to run the code as normal under the standard environment. The data types available are less rich than OCaml, which makes it less suitable for tasks that do not naturally fit a vector paradigm. Also, MATLAB provides parallelism through its parfor (parallel for loop) constructs; however these are not entirely transparent as language features, and restrict the ways in which code within the parallel loops can operate.

4.3.4

Software Simulations For Thesis Results

The simulations in Chapters 4, 5 and 6 are implemented in OCaml, although results are exported to MATLAB for the production of result graphs. MATLAB is also used to provide additional validation in Section 5.6.4, page 127 and Section 6.4.4, page 151.

The reasons for building the earlier code components in OCaml are that these applications were developed as part of a flexible and extensible architecture, which was envisioned to fit generic multihop routing applications. As distributed beamforming concept was added, MATLAB proved a more natural fit which was

easier to work with and debug interactively, especially in the presence of supernodes which may have statistical performance variations. Therefore, the simulator for Section 7, page 158 was implemented in MATLAB. The reduced performance of MATLAB relative to OCaml was compensated for with additional hardware, specifically a multi-core processor which permitted faster execution of the simulations in parallel.