This P2P Network example models a reconfigurable P2P network. Peers are created, deleted or linked to other peers according to some specifications. We model these specifications by means of behavioral rules.
The metamodel of this system is shown here:
The network is composed of nodes. A node can be a peer or a registry. A registry may have peers registrered. Peers are linked to other peers. In a well-formed P2P network all peers should be registered.
We associate peer and registry classes with a picture. This graphical concrete syntax will be used for the definition of the behavioral rules.
We have designed five rules and two helpers to model the behavior of the system, including the rule that initializes the system.
The InitialRule creates the initial model. It contains a registry and eight peers. Seven peers are registered and one is not. Some peers are linked between each other. The NAC pattern forbids the triggering of the rule if was already thrown before.
The New rule models the creation of a peer in the network. It creates a new peer, registers it, and links it with an existing peer. The NAC pattern forbids the triggering of the rule if it is already been executed for the existing peer. This rule spends one time unit on its execution and is triggered every ten time units. So, every eleven time units, a new peer is created.
The Kill rule models the deletion of a peer. A peer is deleted if, as specified in the NAC pattern of the rule, it is not connected with any other peer. A peer spends one time unit on being deleted.
The Random rule models the addition of a link between two peers. This link is created unless there is already one link between both peers or the number of additional connections of one or both peers is greater than two. This rule uses the execRandom helper to check if the rule can be triggered. The NAC pattern forbids the firing of the rule if it is already being executed for these peers. The rule has a periodicity of five time units and spends one time unit on its execution.
The Smart rule models the addition of a link between two peers. This link is created if there is no two-hop between both peers and they are not directly connected either. This rule uses the execSmart helper to check if the rule can be triggered. The NAC pattern forbids the firing of the rule if it is already being executed for these peers. The rule has a periodicity of five time units and spends one time unit on its execution.
We can configure eMotions launcher to run the simulation as shown in the next figure. Please note that we do not need to specify an initial model of the system since we have a rule that creates it.
The P2P.zip file contains the project with all files required to try this example: the metamodel definition, the graphical concrete syntax for the metamodel and its corresponding behavioral specifications. To import this project, right click on the navigation view Import...-> General -> Existing Projects into Workspace -> Select archive file and then select the PS.zip.
The paper on which this P2P network is based can be found here .
A simplifyed version can be found here .