Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Protecting Referenced Models

About Protected Models

A protected model is a referenced model from which all block and line information have been eliminated. Protecting a model does not use encryption technology. A protected model can be distributed without revealing the intellectual property that it embodies. When simulated, a protected model gives the same results that its source model does when referenced in Accelerator mode.

You can use a protected model much as you could any other referenced model. Simulink tools work with protected models to the extent possible given that the model's contents are obscured. For example, the Model Explorer and the Model Dependency Viewer show the hierarchy under an ordinary referenced model, but not under a protected model. Signals in a protected model cannot be logged, because the log could reveal information about the protected model's contents.

When a referenced model requires object definitions or tunable parameters that are defined in the MATLAB base workspace, the protected version of the model may need some or all of those same definitions when it executes as part of a third-party model. Simulink provides techniques for identifying and obtaining the needed data, and then packaging it with the protected model for delivery.

Protecting a model requires a Real-Time Workshop license, which makes code generation capabilities available for use internally when creating the protected version of the model. A third party that receives the model does not need a Real-Time Workshop license to use the model, and cannot use Real-Time Workshop to generate code for the model or any model that references it.

The Model Protection Facility

The Model Protection facility is a set of Simulink commands, tools, and techniques that you can use to protect a referenced model, identify definitions that it needs, and package the model and any definitions for delivery to a third party. The receiver can then unpackage and use the protected model and any definitions. To see a demo of the Model Protection facility, access MATLAB Online Help and choose:

Demos > Simulink > Modeling Features > Model Reference > Model Reference Protected Models

The Model Protection facility is not an integrated unit like a viewer or editor, and has only a command-line interface. To begin using the facility, you execute a protect command in the MATLAB base workspace. See the Simulink.ReferencedModel.protect reference page for complete information about the protect command. The syntax of the command is:

[harnessHandle, neededVars] = Simulink.ModelReference.protect (model, 'Param', Val, ...)

You can use the protect command and its arguments to:

For simplicity, Protecting a Referenced Model shows you how to use each of these capabilities separately when protecting a model. In practice, you can use any or all of the capabilities at the same time, and specify optional argument pairs in any order.

After you have created or obtained all the components that you intend to provide to the receiver, you can package them for delivery as described in Packaging a Protected Model. The receiver of the model will need instructions for unpacking the component(s) and using them in a model. The necessary instructions appear in Using a Protected Model.

Model Protection Requirements

Protecting a model requires meeting all requirements listed in Simulink Model Referencing Requirements, as well as the following:

Model protection is also subject to certain limitations, as described in Model Protection Limitations.

Protecting a Referenced Model

If you need nothing but the protected model itself, with no harness model or list of names, all you need to do is specify the source model to the protect command.

Simulink.ModelReference.protect(model)

The model is the name or handle of the model to be protected, or the full path to the model to be protected. If the model block uses variants, only the active variant is protected. See Using Model Reference Variants.

The protect command creates a protected version of the model and stores it by default in the current working directory. You can change this default as described in Specifying an Output Directory. The protected model has the same name as the source model, with the suffix .mdlp. In the MATLAB Directory Browser, a small image of a lock appears in the upper left corner of a protected model's icon.

Never change the name of a protected model. If you rename a protected model, or change its suffix, the model will be unusable until its original name and suffix are restored. You also cannot change a protected model internally in any way: any internal change will destroy the usability of the file.

Specifying an Output Directory

To specify a directory other than the current working directory to contain the protected model, use the optional Path argument:

Simulink.ModelReference.protect(model, 'Path', pathname)

where pathname is a fully qualified pathname of an accessible writeable directory. The command stores the protected model in the indicated directory.

Creating a Harness Model

When the protect command protects a model, it can also create a harness model. This model contains a Model block that is preconfigured to work with the protected model. This Model block:

To create a harness model when protecting a model, specify the optional Harness argument as true. The protect command returns the handle of the harness model in the first output argument:

[harnessHandle] = Simulink.ModelReference.protect(model, 'Harness', true)

The harness model opens as a new untitled model that contains only the described Model block. This block, and any other Model block that references a protected model, shows a small image of a lock in its upper left corner. You can:

See Packaging a Protected Model for more about how to use a harness model and the Model block that it contains.

Obtaining Object and Variable Names

When a referenced model requires any object or tunable parameter that is defined in the MATLAB base workspace, executing the protected version of the model will require that same entity if it is:

When you protect a model, you must obtain the definitions of all necessary base workspace entities and ship them along with the model. The necessary steps for obtaining the definitions are:

See Packaging a Protected Model for information about how to ship the base workspace definitions.

Obtaining Candidate Names.   When the protect command executes, it always generates a cell array that includes the names of all base workspace entities that the protected model might need. You can obtain this array by accepting the second return value when you execute the command:

[~, neededVars] = Simulink.ModelReference.protect(model)

The tilde (~) operator discards the first argument, or you could accept it if you create a harness model at the same time. The returned cell array neededVars is guaranteed to include the name of every needed base workspace entity.

Pruning Unnecessary Names.   The cell array neededVars may also include the names of base workspace entities that the protected model does not need. For example, neededVars could contain names of workspace objects that define signals that do not connect to any root I/O port within the protected model. The protected version of the model does not need the corresponding definitions, because they do not specify anything about its interface to other model entities.

Leaving unnecessary names in neededVars risks disclosing intellectual property, adds unnecessary definitions to the receiver's model, and increases the likelihood of a name conflict with that model. Because a protected model cannot be changed, resolving such a conflict would require the receiver's model to change.

To remove unnecessary names, edit the cell array neededVars and delete any names that do not correspond to definitions that serve the protected model in one of the capacities listed under Obtaining Object and Variable Names. If you are not sure which names are extra, you can remove any doubtful cases and later test to see whether any missing definitions result.

Saving Workspace Definitions.   The cell array derived in the previous steps contains only the names of base workspace entities. The protected model needs the definitions themselves, in a separate file that can be shipped along with the model. To create this file, execute:

save(myFile.mat, neededVars{:})

where myFile is any file (or path) name, and neededVars is the (possibly pruned) second return value of the protect command. The {:} operator converts the cell array neededVars into a list of comma-separated names, which become arguments to save. When the command executes, it evaluates each name, thus obtaining the corresponding definition from the base workspace, and stores all the definitions in myFile.mat. The receiver of the protected model can then restore the base workspace definitions by loading myFile.mat.

Packaging a Protected Model

A protected model consists of the model itself, optionally a harness model, and any needed definitions saved in a MAT file, as described in Saving Workspace Definitions. The Model Protection facility does not require packaging these files in any specific way. For example, they could be:

All that matters is that the receiver has the information necessary to access any packing format used and retrieve the original file(s). One way to ensure this result is to use the Simulink Manifest Tools, as described in Model Dependencies.

Testing a Protected Model

To test a protected model, you enact the same sequence that the receiver will enact, as described in Using a Protected Model. Since you are also the supplier, both the original and the protected model may exist on the MATLAB path. If a Model block's Model name field names the model without providing a suffix, the unprotected (.mdl) version will take precedence over the protected (.mdlp) model, regardless of their relative positions on the MATLAB path. Explicitly specify the .mdlp suffix in the Model block's Model name field if needed to override this default when testing a protected model.

If you want to ensure that the protected model gives the same results as the source model, you can create a parent model that contains two Model blocks. One Model block references the source model, in Accelerator mode, and the other references the protected model. You can then log the outputs of the blocks and compare the logged data to see that the two versions of the block behave identically. See Logging Signals for more information.

Using a Protected Model

Using a protected model does not require a Real-Time Workshop license. Using a protected model requires that the model:

A typical workflow for meeting these requirements is:

  1. If necessary, unpack the files according to any accompanying directions.

  2. If a MAT-file containing workspace definitions is provided, load the MAT-file.

  3. If a harness model is provided, copy the Model block into a Normal-mode model.

  4. Connect signals to the Model block that match its input and output port requirements.

  5. Provide any needed model argument values. See Assigning Model Argument Values.

You should now be able to simulate the model that references the protected model, which will produce the same outputs that it did when used in Accelerator mode in the source model. Many variations on these instructions are possible, such as:

To facilitate locating protected models:

When you change a Model block to reference a protected model, the block's Simulation mode becomes Accelerator and cannot be changed.

Model Protection Limitations

Protected models are subject to all limitations listed in Limitations on All Model Referencing and Limitations on Accelerator Mode Referenced Models. The following limitations also apply to protected models.

Protected models must also meet certain requirements, as described in Model Protection Requirements.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS