Under Consideration for Publication in Formal Aspects of Computing Modelling Ieee 802.11 Csma/ca Rts/cts with Stochastic Bigraphs with Sharing

Stochastic bigraphical reactive systems (SBRS) [Mil09, KMT08] is a recent formalism for modelling systems that evolve in time and space. However, the underlying spatial model is based on sets of trees and thus cannot represent spatial locations that are shared among several entities in a simple or intuitive way. We adopt an extension of the formalism, SBRS with sharing [SC10], in which the topology is modelled by a directed acyclic graph structure. We give an overview of SBRS with sharing, we extend it with rule priorities, and then use it to develop a model of the 802.11 CSMA/CA RTS/CTS protocol with exponential backoff, for an arbitrary network topology with possibly overlapping signals. The model uses sharing to model overlapping connectedness areas, instantaneous prioritised rules for deterministic computations, and stochastic rules with exponential reaction rates to model constant and uniformly distributed timeouts and constant transmission times. Equivalence classes of model states modulo instantaneous reactions yield states in a CTMC that can be analysed using PRISM [KNP11]. We illustrate the model on a simple example wireless network with three overlapping signals and we present some example quantitative properties.


Introduction
Systems of mobile devices and wireless networks evolve in both time and space. Stochastic bigraphical reactive systems (SBRS) [Mil09,KMT08] is a recent formalism for modelling the temporal and spatial evolution of computation: it should be ideally suited to this domain. However, SBRS assume an underlying model of space that is not overlapping, that is, spaces can be nested and connectivity is defined by a tree structure. A crucial aspect of wireless networks is signal interference: a device may be in the range of more than one signal. In other words, wireless networks are overlapping. Therefore, we adopt SBRS with sharing [SC10], a novel extension of the standard formalism whose spatial model is based on Directed Acyclic Graphs (DAG), thus allowing for a native representation of overlapping space. Additionally, we introduce rule priorities to allow for partial ordering of reaction rules. The result, PSBRS with sharing, allows us to model signal interference and in this paper we use it to model IEEE 802.11 CSMA/CA RTS/CTS, a protocol designed to handle signal interference. To illustrate the protocol, assume stations A, B, C, D where B and C are in the range of A, and B is in the range of D. In CSMA/CA a transaction is defined to be an exchange of packets between two stations that terminates with the transmission of an acknowledgement ACK. A is willing to transmit a packet to B and so transmits a request-to-send RTS, which includes the source, destination, and the duration of the following transaction (i.e. transmission of a clear-to-send CTS followed by a the data packet and the corresponding ACK). B responds (if the medium is free) with a CTS. Upon successful receipt of the CTS, A is allowed to transmit the actual data packet. Station B checks whether the received packet is corrupted by performing a cyclic redundancy check (CRC) and sends back an ACK. Receipt of the acknowledgement indicates that no collision occurred. Note that CTS, ACK and the data packet are sent only if the medium is idle for a short inter-frame space (SIFS) period. If A does not receive the CTS or the ACK packets, then it will retransmit until it gets acknowledged or reaches a given number of transmissions. All other stations receiving either the RTS and/or the CTS, e.g. C and D, set their virtual carrier sense timer (called NAV) with the duration value contained in those packets, and so will not attempt transmission until the NAV reaches 0. Figure 1 illustrates the scenario of A transmitting to B.
The exponential backoff scheme is executed each time the medium is sensed as busy or when a retransmission occurs. The station defers its transmission and the scheme initialises its random backoff timer. This value is obtained by uniformly choosing a value in the interval [0, t], where t min ≤ t ≤ t max is the current contention window (CW) size, and multiplying it for the duration of a slot time denoted by τ . At each timer initialisation, the interval is updated as follows: [0, t ], with t 2t + 1. Upon successful transmission t is reset to t min . The parameters of the protocol specified by the standard are summarised in Table 1. The values used correspond to the times defined for a physical layer (PHY) with a data-rate of 1 Mbps. For example, λ C is the time taken to transmit a CTS packet (with length 14 bytes = 112 bits) at 1 Mbps.

Stochastic BRS with sharing
Bigraphical reactive systems (BRS) is a recent formalism for modelling the temporal and spatial evolution of computation. It was initially introduced by Milner [Mil09] to provide a fully graphical model capable of representing both connectivity and locality. A BRS consists of a set of bigraphs and a set of reaction rules, which defines the dynamic evolution of the system by specifying how the set of bigraphs can be reconfigured. In this section we define informally BRS and its extensions (e.g. sharing, stochastic semantics and rule priorities), with enough detail to support the models adopted in our application.

Constituents of bigraphs and graphical notation
Some example bigraphs are depicted in Table 2 (left column). Dashed rectangles denote regions. Their rôle is to describe parts of the system that are not necessarily adjacent. The ovals and circles are nodes, which can represent physical or logical components within the system. Each node has a type, called control, denoted here by the labels A to D. The set of controls of a bigraphs is called signature. Each node can have zero, one or many ports, indicated by bullets, which represent possible connections. Actual connections are represented as links, depicted by solid (green) lines, which may connect ports and names. In the examples, they are ranged over by x, y, z. They can be thought of as links (or potential links) to other bigraphs. Gray squares are called sites. They encode parts of the model that have been abstracted away. Summarising, nodes represent the spatial placement of agents while links represent their communication capabilities.

Interfaces and sorting
The capabilities of bigraph B to interact with the external environment are recorded in its interface. For example, we write B : 1 → 2, {x, y} to indicate that B has one site, two regions and its names are x and y. We sometimes use to denote 0 and the pair 0, ∅ . Controls and links in a bigraph can be classified by means of sorts. A sorting discipline is a triple ( , K, ) where is a non empty set of sorts, K is a signature and is a formation rule. Sorts are ranged over by a, b, . . .. An example of sorting is given in Tables 3 and 4. A formation rule can be thought of as a set of properties a bigraph has to satisfy. For examples, it can specify that nodes of sort a may only contain b-nodes or that a-nodes may only by linked to b-nodes. Disjunctive sorts are written as ab, meaning that a node can either be of sort a or sort b. The interface of a sorted bigraph is expressed as follow: B : a → b, {z} . The notation indicates that B's site is of sort a, its region is of sort b and its name is z. From now on, all bigraphs are assumed sorted.

Bigraphs with sharing
In [SC10] we have extended standard bigraphs so that a node or a site may be placed in the intersection of other nodes or regions. This implies a locality model based on DAGs instead of forests. An example bigraph with sharing and the DAG encoding its node hierarchy are shown in Fig. 2a, and b, respectively. Our extension yields several advantages. First, its completeness allows the direct representation of any topology with overlapping places. Second, the modelling phase is more natural and immediate, because no additional links, copies of nodes and special controls have to be introduced to encode intersections. Third, the DAG structure of the spatial model appears to have many similarities with the notions from category theory used in the standard definition of bigraphs. In more detail, bigraphs with sharing can be defined in the categorical setting of Milner's s-categories and an axiomatisation of algebraic terms can be defined by a bialgebra over palce graphs. For brevity, in the remainder of this paper, we use the term 'bigraphs' to refer to 'bigraphs with sharing'.

Algebraic definition
The structure of a bigraph can also be formulated in an algebraic form closing resembling traditional process calculi. This is done by combining elementary bigraphs via the operations listed in Table 2. Note that, the algebraic form is equivalent to the graphical notation. Parallel product F G expresses a bigraphical term obtained by juxtaposing bigraphs F and G and merging their common names. Similarly, merge product F | G denotes the juxtaposition of bigraphs F and G which is then placed inside a single region. Nesting operation F .G allows us to place bigraph G inside F . Also in this case, common names are merged. Name closure /x F is used to disallow connections on name x in bigraph F . This means that all F 's links to x are broken and x removed. In example /z A xz y given in Table 2, new name introduction is simply indicated by y. The new name y is not linked to any node. Sharing operation share F by φ in G is a specialised version of nesting in which the regions of bigraph F can be placed inside the sites of bigraph G. The association between F 's regions and G's sites is specified by placing φ. This allows the expression of shared nodes, i.e. nodes situated in the intersection of other nodes. Numbering of regions and sites proceeds from left to right starting from zero. Therefore, placings can be expressed by a vector of sets indicating the sites associated to each region. For instance, placing φ [{0}, {0, 1}] indicates that the first F 's region is placed in the first G's site while the second F 's region is shared between the first and the second G's site. This is depicted in Fig. 2.
The elementary bigraphs most commonly used in our application are identities and 1. An example identity is id 2,ab . It indicates a bigraph with two regions each one containing a site, and two separate links a and b. Bigraph 1 : 0 → 1 consists of one single region.

Bigraphical reactive systems
A Bigraphical Reactive System (BRS) consists of a set of bigraphs representing the state of the system, and a set of reaction rules, defining how the system can reconfigure itself. A reaction rule R is a pair (R, R ), where R and R are bigraphs that can be inserted into the same host bigraph (i.e. they have the same interface). We sometimes indicate a rule as R R R . The evolution of a system S t is derived by checking if R is an occurrence in S t (this is also called bigraph matching) and by substituting it with R to obtain a new system S t+1 . Such a reaction is indicated with S t R S t+1 . We also use * to indicate zero or more applications of a reaction. In a Stochastic BRS (SBRS) [KMT08], rates are associated with reaction rules; the resulting transition system can be translated into a Continuous Time Markov Chain (CTMC) for quantitative analysis. We adopt the following notational conventions: R R α R indicates a stochastic reaction rule with rate α ∈ R + , while transition S t ρ R S t+1 denotes the update of bigraph S t via R with rate ρ. Instantaneous reactions are characterised by rate α ∞. From now on, a reaction is deemed as instantaneous when its rate is omitted in the notation.

Priority BRS and priority SBRS
A Priority BRS (PBRS) is a BRS with rule priorities in the style of [BBKW89], i.e. by introducing a partial ordering on the rules of the reactive system. A reaction rule of lower priority can be applied only if no rule of higher priority is applicable. We write R < R to indicate that reaction rule R has higher priority than reaction rule R. A priority class P is a set of reaction rules with the same priority. By an abuse of notation, we write P < P when, for any two rules R ∈ P and R ∈ P , we have R < R . We also say that class P has lower priority than class P .
Similarly, a Priority SBRS (PSBRS) consists of an SBRS augmented with rule priorities. We require all the rules in a priority class to be instantaneous, if it contains an instantaneous rule.

Bigraphical model of wireless network topology
In this section we define the class of bigraphs used to represent WLANs in our model. Informally, nodes represent the main entities present in the network, namely stations, wireless signals and packets. Their relationships are expressed by links between them and by node sharing. Overlapping signals are modelled by a node representing a station in the intersection of two or more nodes representing the signals. This modelling strategy is explained in greater detail later on. The graphical form of an example bigraph encoding a station is shown in Fig. 3a. Packets to be sent are indicated by triangle-shaped nodes. Another example is given in Fig. 4b where the graphical form for the encoding of three stations with overlapping wireless signals is drawn. Before proceeding with a formal description of the bigraphical model, we observe that the oval shape used for nodes representing signals does not correspond to the actual shape of an area covered by a signal in a real WLAN. This is because the nesting of nodes represents a topological space and not an Euclidean space. Therefore, distances between places and their shapes are not expressible in bigraphs.
Modelling 802.11 CSMA/CA with stochastic bigraphs with sharing The parameters are t ∈ T and 272 μs ≤ l ≤ 18768 μs The fifteen controls listed in Table 3 are used to encode the entities forming a WLAN. These are organised into sorts as follows. Controls describing wireless signals are grouped together into sort s {Q}. They represent the address of a node and a queue of packets respectively: virtual entities introduced only to simplify the modelling process. Specifically, they allow one to distinguish their links from the links of m and s-nodes. The set of sorts is written as {s, m, p, a, q}. The signature is given by K s∈ s. The sorting discipline ensures that only bigraphs with a meaningful structure are constructed. For example, it forces packets to be always located inside a machine and a machine to be always surrounded by its signal. This is formalised in formation rule with conditions i , 1 ≤ i ≤ 10, given in Table 4. We briefly comment on each condition. Condition 1 states that dummy nodes of control Q and A are atomic (i.e. they contain nothing). Conditions 2 -4 specify a hierarchic structure on the placing of the nodes. In particular, s-nodes are the outermost nodes in the model. They contain m-nodes, which in turn contain pa-nodes. Conditions 5 , 6 specify the placing described in the example in Fig. 3a. Condition 7 ensures that an address A is always connected to a unique name and to one ancestor signal node. This allows the discrimination of signals according to the machine, and thus the address they belong to. Conditions 8 , 9 describe the queue-like structure formed by packets which sit within a station as in Fig. 3a. Condition 10 states that an address may be linked to several packets. This models the destination field in each packet. Finally, we refer the sorting used in the model as 802.11 (K, , ).
Our approach to modelling network topologies is explained through an example. Consider for instance the WLAN of three stations shown in Fig. 4a. Assume that both stations A and C are willing to transmit to station B. The bigraphical model needs to record that the system is composed of three stations, each one with its own wireless signal. Then, it also has to satisfy the following requirements: Req1 A and C sense B, Req2 B senses A and C, Req3 A does not sense C and C does not sense A.  an m-node has one a-child 6 a p-node has one q-child 7 an a-node is always linked to one grandparent of sort s and a name 8 in an m-node, one port may be linked to one m-node and the other may be linked to one p-node 9 in a p-node, one port may be linked to an a-node and the other is always linked to one mq-node (see Fig. 3a) 10 an a-node may be linked to many p-nodes This wireless network is modelled by bigraph N 0 : → s, {a A , a B , a C , } given in Fig. 4b. For purposes of aesthetic clarity we adopt a simplified graphical notation in which aq-nodes are encoded by special diamond ports as shown in Fig. 3b. Stations A, B, and C are encoded by the three M-nodes linked to names a A , a B and a C , respectively. Their signals are indicated by nodes S t A , S t B , S t C , respectively, and they are linked to the corresponding name. Observe that each station sits within its own signal node. Req1 is satisfied by station B being in the intersection of the two signals S t A and S t C . Req2 is satisfied because the two m-nodes for stations A and C are contained by node S t B . Finally, Req3 holds because station A is outside S t C and vice versa. An equivalent algebraic form of N 0 is indicate stations A, B and C, respectively, and terms 1 encode A's and C's packets (i.e. the blue triangles in Fig. 4b), respectively. The network topology is specified by placing This simple example shows how our modelling strategy can provide adequate expressive power for the representation of arbitrary network topologies. Moreover, bigraphs with sharing allow us to express succinctly complex network topologies.
Modelling 802.11 CSMA/CA with stochastic bigraphs with sharing  3 R DATA (l) ρ 3 (l) sender has sent a CTS → sender has sent its data packet. Fig. 7  4 R ACK (t, t , l) ρ 4 data packet sent → ACK sent and locks released.
sender (not the most recent) has to back off and receiver has detected a collision → locks are released and the sender is timed out. 6 R BACK2 (t, t , l) ρ 5 most recent sender has to back off and receiver has detected a collision → locks are released and the sender is timed out.  We now list our modelling assumptions: • All signals have equal power. This implies that if a station A is within the range of another station B, then B is within the range of A. • The range of broadcast packets is the same of unicast packets.
• The range of small packets is the same of large packets.
• No packet is lost during transmission, i.e ideal channel conditions. • Static topology.
We remark that these assumptions derive from those made in the specification of the 802.11 protocol [IEE05].

Stochastic reaction rules modelling the protocol
Before presenting the bigraphical reactive system, we introduce some notation and conventions. The stochastic reaction rules in our model have the form R L (π ) R ρ R , where subscript L is a label describing the rule semantics and π is a list of parameters. All the rules respect the sorting 802.11 . We call the interface of the rule the interface of bigraphs R and R . Reaction rates are indicated by ρ(π ). Names used as addresses range over a, a , a A , a B , . . .. Destination addresses are denoted by d, d , . . .. When defining reaction rules, name x is used to denote a link between two m-nodes while name q represents a link between a p-node and a node of control Q.
The 802.11 CSMA/CA RTS/CTS protocol is modelled as a PSBRS in which WLAN's configurations are encoded by 802.11 sorted bigraphs and system updates are expressed by reaction rules. These are described in the remainder of this section. In order to obtain a general model of the protocol, each reaction rule is indexed by parameters such as the values of timers (indicated with t and t ) and packet sizes (denoted by l). In the following a graphical description of each reaction rule is presented. Equivalent algebraic definitions are reported in Appendix A. A summary of the rules is in Table 5 using the following convention: each description takes the form description of bigraph on lhs → description of bigraph on rhs .
The first rule R RTS (t, l) models the initial phase of the CSMA/CA protocol: whenever a sender senses the channel free, it is allowed to initiate a communication. A graphical representation of the reaction is given in Fig. 5. The station willing to transmit is encoded on the left-hand side by a node of control M containing a triangle of control W l . On the right-hand side, a communication is instantiated. This is shown by the RTS l triangle, the M L and the S t L nodes. The reaction rate is defined as follows:  Note that it depends on t, i.e. the contention window size of the sending station. Term τ t 2 is a constant indicating the average time the sender waits idle before its contention window of size t is fully consumed 2 . In algebraic terms, this reaction rule is defined as A a .1)). The interface of the reaction rule is given by: The second rule R CTS (t, t , l) describes the transmission of a CTS packet from the sender to the receiver. Its graphical representation is given in Fig. 6. The reaction can be triggered only when the sender and the receiver sense each other and the receiver is available for a transmission. These two preconditions are encoded in the left-hand side by two nodes of control M L and M D being in the same intersection of signals and by the node of control S t containing the receiver, respectively. Moreover, M D can be identified as the receiver because it is linked to the sender's RTS l triangle. Note also that both the receiver and the sender can be in the range of other stations. On the right-hand side the receiver is locked (nodes of control S t L and M L ) and a link between the two machines is established. The reaction rate is ρ 2 (λ S + λ C ) −1 .
Modelling 802.11 CSMA/CA with stochastic bigraphs with sharing The third rule R DATA (l) models the transmission of a data packet from the receiver to the sender. Its graphical form is depicted in Fig. 7. On the left-hand side, the sender's triangle is of control CTS l , while on the right-hand side it is of control P l . The rule can only be applied when a communication between two stations has already been initiated. This is encoded by the edge connecting the nodes of control M L . Observe that the sender and the receiver can sense two different sets of stations because the M L nodes are placed in two different regions. The reaction rate depends on the size of the data packet to be transmitted: ρ 3 (l) (λ S +l) −1 .
The fourth rule R ACK (t, t , l) specifies the last phase of the protocol: upon successfully transmitting a data packet, the receiver sends back to the sender an ACK control packet and stops transmitting. A graphical representation of the rule is given in Fig. 8. On the left-hand side the two stations are engaged in a communication. This is encoded by the intersecting nodes of control S L and by the link connecting the two M L s. The triangle of the sender is of control P l , meaning that a data packet has been transmitted. On the right-hand side locks on both the stations are released and the sender's backoff timer is reset to t min . This is expressed by the nodes of control M, S t min C and S t C . Moreover, the link between the two machines is removed. Also the triangle is removed. The reaction rate is ρ 4 (λ S + λ A ) −1 .
A pictorial representation of how the previous four stochastic reaction rules: R RTS (t, l), R CTS (t, t , l), R DATA (l), and R ACK (t, t , l), are used to encode the packet exchange between two stations as specified by the protocol is given in Fig. 9. From this figure, it is possible to infer the contribution of the relevant constants to the associated rates (summarised in Table 5). For example, rate ρ 1 (t), the rate for R RTS (t, l) rule, includes the sum of λ D , the constant for DIFS, τ t 2 , the constant denoting the average duration of the sender's contention window of size t and λ R , the constant indicating the transmission time of an RTS packet.   The fifth rule R BACK1 (t, t , l) models collisions when two stations simultaneously try to transmit an RTS packet. It is expressed graphically in Fig. 10. On the left-hand side, triangle of control RTS is placed within a node of control M B . This represents the fact that the sender has to back off. The receiver is in a potential collision state, indicated by control M P . On the right-hand side locks are released and the sender's contention window is increased. This is encoded by the node of control S 2t+1 C , the triangle of control W l and nodes of control M. The modification of parameter t models the exponential back-off procedure. The reaction rate is ρ 5 λ −1 T , i.e the sender's time-out expires before a CTS packet is received.
The sixth rule R BACK2 (t, t , l) is very similar to the previous one. It is applied when the receiver has control M D instead of M P . This happens when all the other conflicting stations have already backed off. A graphical representation of the rule is given in Fig. 11. In both the previous two rules, nodes of control S 2t+1 C are replaced by S E when t ≥ t max . This models the protocol when the maximum number of transmission attempts is reached. Rates associated to each of the previous reaction rules are summarised in Table 5.
The six stochastic reaction rules described so far encode behaviours of stations as specified by the CSMA/CA RTS/CTS protocol. In the remainder of this section, a set of six instantaneous reaction rules is introduced. These rules are used to enforce conditions on the system that assure the rules presented above can only be fired in a meaningful order. More formally, they force some invariants to be satisfied before one of the stochastic rule is triggered. For example, any station receiving more than one RTS has to be marked as M P . This allows the correct choice of whether rule R CTS (t, t , l) or rule R BACK1 (t, t , l) has to be applied. We explain the interplay between stochastic and instantaneous rules in more detail when rule priorities are assigned (at the end of this section).
An overview of the instantaneous rules is the following. The first three rules deal with the detection and marking of stations involved in a communication. Rule R D (t) detects and marks stations that have to defer. This is depicted in Fig. 12. On the left-hand side, an idle station has received an RTS from some other station. This is modelled by a node of control M placed within a node of control S t L . Moreover, links indicating addresses are not joined together i.e. there are two distinct links to names a and a . On the right-hand side, the station is marked by assigning control M D to it.
Modelling 802.11 CSMA/CA with stochastic bigraphs with sharing  Rule R P (t, t ) detects and marks stations that are in a potential conflict state. The graphical representation is given in Fig. 13. In the left-hand side, a station receives an RTS from more than one station. This is shown by the node of control M D placed within the intersection of two nodes of control S t L . Observe that the station can be in the range of other machines. This is modelled by the extra region surrounding M D . On the right-hand side, the station detecting the conflict is marked by assigning control M P to it.
Rule R B (l) detects and marks stations that have to backoff when a conflict occurs. This is drawn in Fig. 14. On the left-hand side, the sender is trying to communicate with a receiver in a conflict state. This is shown by nodes of control M L , RTS l and M P . Note that the triangle and the receiver are linked together on name d. On the right-hand side, the sender is marked by assigning control M B to it.
The last three instantaneous reactions are used to release the locks when a communication is terminated. Rule R UD (t) releases the lock of a deferred station when its NAV reaches 0. This is modelled by the node of control M D enclosed by a node of control S t C on the left-hand side. On the right-hand side, the lock is released by assigning control M to the station. A graphical representation of the reaction rule is given in Fig. 15.   Similar to the previous rule R UP (t) is used to release the lock of a station in a potential conflict state. This is encoded by the node of control M P on the left-hand side. The rule is depicted in Fig. 16.
Finally, rule R UC (t) models the release of the lock at the end of a transmission. The graphical representation is in Fig. 16. On the left-hand side, the station is idle and ready to release the lock. This is encoded by the node of control S t C linked to its child node of control M. On the right-hand side, the final stage of the protocol is performed by substituting S t C with S t . Note that this rule is not in conflict with rules R UD (t) and R UP (t) because it can only be applied to a sender or a receiver.
Reaction rules are organised into six priority classes as follows: All stochastic rules belong to P 0 , i.e. the class with lowest priority. Therefore, any stochastic rule can be applied only when no instantaneous rule can be applied. A brief description of the priority classes is the following.
P 5 is the class with highest priority. Rules assigned to this class mark with control M an idle station in a clear signal (i.e. of control S t C ). Class P 4 has one rule that marks with control M a sender or receiver inside its clear signal, the signal is marked as S t . Since P 4 < P 5 , all idle stations must be marked as M before the clear signal containing them is marked as S t . Similarly, rules in priority classes P 3 , P 2 , P 1 mark a station inside a locked signal (S t L ) as deferred (M D ), in a potential conflict state (M P ) and backing off (M B ), respectively. This is necessary because rules with higher priorities may have marked a station as M even if it is contained in a locked signal. Finally, stochastic rules in P 0 can be applied safely since all the preconditions are enforced by the prior application of the rules with higher priorities.

Discussion
A difficulty with rewriting rules in general, and therefore a problem for us here, is how to deal with situations where we want to rewrite because a condition does not apply. For instance, we want to apply rule R RTS (t, l) only when the sender is not in a locked signal. In our approach, this issue has been solved by introducing priorities on reaction rules as described above. However, there are two modelling choices other than using PSBRSs.
One option is to parameterise the reactions on the topology of the network. For instance, the first rule (RTS packet transmission) can be modified so all the idle signals sensed by the sender are explicitly listed. Since only idle signals are included and no other signals are allowed via shared regions, then the rule can only be applied when the sender is not within a locked signal. An additional parameter n indicating the number of signals in the sender's range is required, i.e R RTS (t, l, n). A major drawback of this approach is that a different rule has to be instantiated for every network topology. Moreover, the specification of the rule becomes cumbersome and difficult to read. An advantage is that less controls are required for the modelling of the protocol's phases and no instantaneous reaction rule is introduced.
The other option involves extending the notion of reaction rule to include what may be called conditional reaction rules, having the form (ϕ, R, R , ρ), where ϕ is a BiLog [CMS05] predicate expressing a condition imposed upon the bigraphical context in which left-hand side R occurs. Also with this option, less controls are required and instantaneous reaction rules can be avoided. A disadvantage is that it is often necessary to specify predicates involving universal quantifiers or expressing the absence of a pattern. These may be difficult to verify especially when the size of the system grows.
Our approach allows the specification of concise rules that can be applied to any network topology. This conciseness is important not only because it allows for a clearer description of the model, as we showed in this section, but also because the size of the left-hand sides of our reaction rules is always constant. Therefore, there is no performance deterioration when a reaction rule is applied to a bigraph with many nodes.
A common issue with instantaneous rules is the generation of intermediate states that may not represent meaningful network configurations. In order to minimise the number of states stored during the execution of a model, we treat instantaneous rules like rewriting within an equivalence class, and only store a canonical form, after applying all possible instantaneous rules. This is possible because in our model instantaneous rules within a priority class are confluent, thus they always yield a unique fixed point. We explain this procedure in Sect. 7.
We note that we have defined exponential rates from time constants, i.e. if we have a constant k waiting (or transmission, or sum of constants) time, then we use as CTMC rate k −1 .
Finally, we remark that although the protocol assumes a static topology, we could easily define rules for station movement in and out of a signal range, i.e. protocol behaviour in a dynamic topology.

Execution of an example network with three stations
In this section we describe two example executions of our model starting from initial state N 0 , the bigraph encoding of an example WLAN with three stations given in Fig. 4. Recall that all the possible evolutions of a system are obtained by successive applications of reaction rules chosen among the ones described above.

M. Calder, M. Sevegnani
The first execution encodes the successful transmission of a packet from station A to station B, with no collisions occurring. It is the result of the application of reaction rules R RTS (t A , l), R D (t B ), R CTS (t A , t B , l), R D (t C ), R DATA (l), R ACK (t A , t B , l), R UD (t C ), R UC (t A ) and R UC (t B ), in that order. The dynamic evolution of the network is represented pictorially in Fig. 18. Observe that in state N 6 (second diagram in the third row), the sender's contention windows size is reset: t A t min . An alternative execution can be obtained by changing the order in which the locks are released, i.e. by applying R UC (t B ) before R UC (t A ). The resulting state is again N 9 . Execution N 0 RTS · · · UC N 9 can further proceed in an analogous way by transmitting the remaining packet from C to B. The symmetrical evolution in which station C sends its packet to B can be obtained from initial state N 0 by applying reaction rules R RTS (t C , k), , R UC (t C ) and R UC (t B ), in that order.
The second execution encodes a transmission in which a collision occurs. It is shown in Fig. 19. The initial state is bigraph N 2 obtained in the trace described above. As can be seen, in this evolution station C sends its RTS before B transmits its CTS. Therefore, stations C and A have to defer and the backoff scheme is executed. This is encoded by the application of rules R BACK1 (t A , t B , l) and R BACK2 (t C , t B , k). Station C can try to retransmit (by applying rule R RTS (t C , k)) only after its timeout has expired. The contention windows of senders A and C are exponentially increased in states N 4 and N 7 , respectively. Therefore, t i 2t i + 1 with i ∈ {A, C}. An alternative execution can be computed by inverting the order of application of rules R B (l) and R B (k). This leads to state N 3 . Another interleaving is obtained when R BACK1 (t C , t B , k) is applied before R BACK2 (t A , t B , l). Also in this case, the final state is still N 8 .
The two evolutions above show how instantaneous rules must be applied before stochastic rules as required by the priority hierarchy of our model. For instance, in the second trace, rules R P (t A , t C ), R B (l) and R B (k) are applied before rule R BACK1 (t A , t B , l).

CTMC analysis
We first explain how to compute the CTMC capturing the semantics of a PSBRS. In particular, we describe our approach to reduce the number of intermediate states generated by the application of instantaneous reaction rules. Whenever a reconfiguration S of a state S (i.e. S ρ S ) is obtained, the unique fixed point S * is computed by iteratively applying to S all the instantaneous rules. Then, state S * is stored in memory in place of S as a reconfiguration of S (i.e. S ρ S * ). A formal representation of the procedure is given by All the priority classes, P i < · · · < P j , contain only instantaneous reaction rules. Note that all the rule applications respect the priority hierarchy and that all the intermediate states S , S , S , . . . obtained during the computation of S * are discarded. Furthermore, by definition of fixed point, no instantaneous rule can be applied to S * . This always forces the first reaction to have rate ρ ∞. This approach can only be used if each priority class whose instantaneous reactions are ignored has a unique fixed point (as is the case in our model).
The procedures described above can be explained by showing how to compute the CTMC starting from bigraph N 0 , the example WLAN of three stations used in the example in the previous section. The parameters of the model are packet transmission times l 8464 μs and k 4368 μs. 3 Contention windows for stations A, B and C are t A , t B , t C 15. In the PSBRS, iterated applications of instantaneous reaction rules belonging to the same priority class always yield a fixed point. Hence, intermediate states generated by P 5 , . . . , P 1 can be ignored. Another property of our model is that any reaction S ρ S can only be obtained by a single application of a stochastic reaction rule R. This may not hold with more complex topologies.
Modelling 802.11 CSMA/CA with stochastic bigraphs with sharing  The resulting CTMC (indicated by M) is given in Fig. 20. Reactions corresponding to actions on station C are indicated with left facing arrows and those on station A by right facing arrows. The diagram is organised into seven diamond sub-parts each one representing a different transmission attempt after a collision. Each diamond is indicated by M i with 1 ≤ i ≤ 7. Note that only the first two diamonds are shown in Fig. 20. The central node of a diamond (indicated with •) is the top vertex of the successive one as for instance state N 8 in M 1 and M 2 . The bottom node of M 1 (indicated with ) is shared between all the seven diamonds. It represents the state in which both packets are successfully transmitted to B. It is shared because the contention windows of stations A and C are reset to t min 15 in every diamond after every transmission of the ACK control packet. The reactions going to the centre of the diamond encode transmission collisions. A side of a diamond is formed from four reactions, encoding the successful transmission of a packet. For instance, side N 0 * N 9 encodes transmission of A's packet before C's packet at the first attempt. Dashed arrows correspond to the encoding of the two executions described in Sect. 6. The CTMC has two deadlock states. One is node • in M 7 representing stations A and C when the maximum number of transmission attempts is reached, i.e. both signals are S E . The other is node described above.
As can be seen in the diagram, the CTMC does not contain the intermediate states generated by the application of instantaneous rules. Take for instance reaction N 0 N 2 in M 1 . By inspecting the execution in Fig. 18, we see that it corresponds to reactions In this case, intermediate bigraph N 1 is not used as a CTMC state. Also note that no instantaneous reaction rule can be applied to N 1 . Analogously, reaction N 2 as shown in Fig. 19. Here, intermediate bigraphs N 0 , N 1 , N 2 and N 2 are discarded. Note that only one between N 2 and N 2 is computed by the rewriting engine, because only one path is needed to compute fix point N 3 . In both the reactions considered, the stochastic rate is the rate of the stochastic reaction rule applied at the beginning of the corresponding sequence. Finally, we note that the CTMCs generated from our model, for any finite topology, will be finite because there are a finite number of transmissions, a finite number of packets, and a finite number of stations.

Analysis of quantitative properties
It is possible to express quantitative properties about the behaviour of our model by combining BiLog and CSL (Continuous Stochastic Logic) [ASSB96]. In more detail, we use BiLog to express predicates that are used as atomic propositions in CSL. In [CS12], it was shown that this kind of predicate can be reduced to one or more instances of bigraph matching. Therefore, the predicates in our analysis are represented as bigraphs. For example, we define pattern P ϕ error S E to encode predicate ϕ error , which is true whenever a station reaches the maximum number of transmission attempts, namely there is a signal node in error state. This predicate can then be used in any CSL formula such as ψ 1 P <0.001 (F ϕ error ), i.e. eventually a station is in error state with probability less than 0.001. Note that the only state satisfying ϕ error is node • in M 7 .
Quantitative properties can be evaluated with standard tools for CTMC model checking. Here we use the probabilistic model checker PRISM [KNP11] on some simple CSL formulae expressing properties on M. In particular, we take advantage of the explicit model import feature in PRISM which allows the importation of a CTMC's rate matrix and its labelling function.
It is also possible to specify properties that evaluate to a numerical value. Let us analyse some examples. Example 7.1 The probability of a station being in an error state is given by formula P ? (F ϕ error ) 6.08 × 10 −7 , which implies that M | ψ 1 . This small value is explained by the fact that only two stations compete for transmission in our example topology. When more overlapping stations are present in the network, iterated collisions are more likely, thus this value increases.
Example 7.2 The probability that a collision occurs is expressed by P ? (F ϕ collision ) 0.36. Predicate ϕ collision is encoded by the matching of pattern P ϕ collision M Bxy M Bzw . It corresponds to state N 3 in M 1 and the states in the same position in M i with 1 < i ≤ 7.
Example 7.3 The probability of station A successfully transmitting its packet in 1 ≤ n ≤ 7 transmission attempts is expressed by P ? (ϕ n A ). The cumulative plot is given in Fig. 21. Predicate ϕ n A corresponds to pattern with t 2 n+3 − 1. Therefore, the labelling function marks the nodes indicated with in M. Observe that the predicate cannot be defined to simply match state because information about the number of transmission attempts is lost after every application of reaction rule ρ 4 ACK when the contention window is reset.

Discussion
Previous studies of the IEEE 802.11 standard have focussed mainly on the quantitative analysis of the basic access mechanism. Two example works that consider the RTS/CTS handshake are [Bia00] and [CG97]. The results reported by those authors are used to evaluate the performance of the protocol, e.g. system throughput and congestion rate, and are obtained by means of simulation. In both cases, the network topology is not encoded directly, but a probability of collision p is assigned to each station. Hence, higher values of p allow one to encode "denser" topologies. Another example of analysis is the analytic approach presented in [AA10], but it is difficult to compare with our analysis, since again the network topology is modelled implicitly by a collision probability.
Modelling 802.11 CSMA/CA with stochastic bigraphs with sharing In general, the model checking approach has some benefits over simulation [Cla08]. Probably, the most relevant advantage in the context of wireless networks modelling is that all possible states are explored. In particular, model checking can explore those states having a reachability probability that is too small to be discoverable by simulation. This is fundamental to obtain precise and trustworthy results especially when analysing safety-critical systems and border-line or unusual system behaviours. Consider for instance Example 7.1 in which the probability to reach an error state is computed, i.e. P ? (F ϕ error ) 6.08 × 10 −7 . In this case, simulation based approaches could erroneously conclude that the system can never be in an an error state (thus giving a wrong answer) because the probability to discover such states is too low to be found in a reasonable number of simulation runs.
The quantitative properties we presented earlier in this section serve mainly to show how SBRS can effectively be analysed and to highlight the expressive power of both bigraphs with sharing and BiLog. Following these examples, more advanced analysis can be carried out by researchers in wireless networking and practitioners in the field of performance evaluation. For instance, network throughput can be studied by varying the parameters of the protocol and the exponential increase of the contention window size can be compared with different backoff schemes. Another interesting investigation is to analyse the effects of the RTS/CTS mechanism on different network topologies (e.g. sparse or dense) to find out when the mechanism improves network throughput and when it introduces overhead.
Our bigraphical model can be extended easily to analyse more realistic systems, i.e. systems in which the assumptions made in the 802.11 protocol are not met. For example, formation rule of sorting 802.11 given in Table 4 allows for the specification of networks in which signals do not have equal power as it is the case in the WLAN encoded by the bigraph in Fig. 22. The diagram shows that receiver B is within the signal range of station C but C is not in the range of B. Therefore, station C cannot receive a CTS packet from B and reaction rule R CTS (t, t , l) can never be applied. In order to model this kind of system, stochastic reaction rule R T (t, l) given in Fig. 23 needs be introduced. It encodes the behaviour of a sender timing out before a CTS packet is received. It can be thought as the opposite of R RTS (t, l) described in Sect. 5 where the size of the contention window is increased in the reactum as in reaction rules R BACK1 (t, t , l) and R BACK2 (t, t , l). Also in this case, node of control M. Calder, M. Sevegnani With the addition of this new reaction rule, the system can evolve to a state in which C's signal has control S E after seven transmission attempts.
Another modification for a more realistic model is to represent a constant transmission time τ with an Erlang distribution of shape k and rate k τ . In a CTMC, this can be achieved by replacing transitions in the form N 1 τ N with N N 1 k τ N 2 k τ · · · N N k+1 . Note that when k 1 we have an exponential distribution. A drawback of this approach is that k − 1 states are added to the CTMC and that an additional priority class needs be added in order to avoid interleaving with the other reaction rules of the model. We observed that in most cases k ≈ 4 is sufficient for an accurate approximation. Finally, the model can be further refined by adding reaction rules encoding the movement of stations in and out of signals. They would encode both the spatial movement of mobile stations and the variation of signal coverage due to frequency interference. These reaction rules would usually be slower than the other stochastic reaction rules.

Conclusions and future work
We have adopted SBRS with sharing to exploit a locality model based on DAGs and we illustrated the extended formalism with a model of the IEEE 802.11 CSMA/CA RTS/CTS protocol. The graphical form of the rules illustrates the spatial aspects of the protocol in a precise and intuitive way. Reaction rules are then organised into priority classes to form a PSBRS allowing the specification of concise rules that can be efficiently applied on any arbitrary network topology. The simple WLAN of three stations with overlapping signals provides an example of a practical application of stochastic bigraphs and one that could not be modelled using the original formalism. The CTMC encoding offers the possibility of quantitative analysis, allowing us to quantify probabilities such as a packet is received, or two stations are in an error state, or how the former depends on the number of retransmissions. Future work includes further extensions to the tools for bigraphs such as support for automatic CTMC generation and translation of BiLog predicates.
Modelling 802.11 CSMA/CA with stochastic bigraphs with sharing We begin with the algebraic description of the six stochastic reaction rules: