# CPS-to-Deployment Transformation

## Specification

The specification of the CPS-to-Deployment M2M transformation describes what is expected from any implementation variant.

### Input

- Cyber Physical System instance model that satisfies the validation rules defined on the Live Validation page.

### Output

- Deployment instance model

- Traceability instance model between the CPS and Deployment instance models

### Rules

1. Host mapping: All host instances in the CPS are transformed into deployment hosts.

   - The IP address of the host instance is copied to the deployment model.

   - Traceability: A trace is created between each host instance and related deployment host (`1-to-1`).

2. Application mapping: All application instances allocated to a host instances in the CPS are transformed into deployment applications.

   - The identifier of the application instance is copied to the deployment model.

   - Traceability: A trace is created between each application instance and related deployment application (`1-to-1`).

3. State machine mapping: All deployment applications will contain a deployment behavior transformed from the state machine of their application type.

   - The identifier of the state machine is copied to the description of the deployment behavior.

   - Traceability: A trace is created for each state machine and it refers to all deployment behaviors mapped from that state machine (`1-to-n`).

4. State mapping: Each state of state machines are transformed as behavior states into all deployment behaviors for the given state machine.

   - The identifier of the state is copied to the description of the behavior state.

   - Traceability: A trace is created for each state and it refers to all behavior states mapped from that state (`1-to-n`).

5. Transition mapping: Each transition of state machines are transformed as behavior transitions into all deployment behaviors for the given state machine.

   - The identifier of the transition is copied to the description of the behavior transition.

   - The behavior transition is added to the outgoing transitions of the behavior state mapped from the state containing the transition to the given deployment behavior.

   - The to reference of the behavior transition is set to the behavior state mapped from the target state of the transition to the given deployment behavior.

   - Traceability: A trace is created for each transition and it refers to all behavior transition mapped from that transition (`1-to-n`).

6. Action mapping: The actions of transitions are transformed into trigger references between behavior transitions.

   - A behavior transition `SBT` related to a CPS transition `STr` with action `sendSignal(appTypeId,signalId)` will trigger all behavior transitions `WBT` related to CPS transitions `WTr` with action `waitForSignal(signalId)`, if:

   - The identifier of the application type that contains the state machine of `WTr` is `appTypeId`.

   - The application instance related to the deployment application containing `SBT` is allocated to host instance `H1`.

   - The application instance related to the deployment application containing `WBT` is allocated to host instance `H2`.

   - `H1` can communicate with `H2` transitively:

7. `H1` and `H2` may be the same

8. `H2` is included in the set of values of `communicatesWith` in `H1`

## Testing

We provide unit tests that are defined based on this specification and can test the correctness of any transformation variant.