How can I edit some process model code in my own IDE (editor) outside of Modeler, without waiting for a heavyweight editor to load every time I click the Function Block button?

Categories:
Solution Number:
S20801
Last Modified:
2013-08-20
Issue

How can I edit some process model code in my own IDE (editor) outside of Modeler, without waiting for a heavyweight editor to load every time I click the Function Block button?

Solution

If you would like to edit some code within Modeler, but edit other code outside of OPNET, and do not want to switch your editor_prog preference every time you edit a block, you may prefer to move some of your code to External Files, which can be edited outside of OPNET, but compiled by OPNET along with your model files.[1,2]The rest of this document will guide you through the process of creating and using an External File.Preview: You will create external code (.ex.c and .h, or .ex.cpp and .hpp), compile that code into an object file (ex.o), and registered that external file with Modeler. Your process model code will call functions provided by your external code. You will edit your external file in the editor of your choice, and whenever you recompile your process model, the external code will be automatically recompiled.Details follow.* Create files in a model directory (e.g.; <HOME>/op_models). You will add code to these files later.* Create new files using one of the following extensions, as appropriate: .ex.cExternal Source (C Code) .ex.cppExternal Source (C++ Code) .hHeader File (C/C++, .h) .hppHeader File (C++, .hpp)It is important to use the extension .ex.c or .ex.cpp on the code files, files with the extensions .c or .cpp without the ex. will not be visible to Modeler. Header files do not need the .ex subextension. [3]For example, if you want to write code to support the wlan_mac process model, you could create the files 'wlan_mac_support.ex.c' and 'wlam_mac_support.h'.* Open your new external files in your preferred code editor.* Launch Modeler, and open your process model in the Process Model EditorExample: wlan_mac* Open the process model's Function Block (or any code block in the model), and move a block of code out of the process model, into your external files. As appropriate, wrap the moved code in a function in the external file, and replace the moved code with a function call in the process model. Use op_ima_obj_svar_get (objid, svar_name) to access state variables of the process model. See Discrete Event Simulation API Reference Manual ->Internal Model Acess to learn how to manipulate process model data.* All external functions called by process model code must be declared in an external header file, so add declarations to the .h or .hpp file as appropriate.* Compile your external code by running 'op_mko' in a command shell window (outside of OPNET). add the -verbose_mk flag for helpful compiler feedback. Example: op_mko -verbose_mk -type ex -m wlan_mac_support(For information, Help -> Product Documentation -> General -> External Interfaces -> op_mko)* Back in Modeler, notify Modeler that a new file has been created. Refresh Modeler's model list. File -> Model Files -> Refresh Model Directories. * In the process model editor, declare the compiled external file. File -> Declare External Files... -> tick your external file. Example: wlan_mac_supportReview: You have created external code (.ex.c and .h, or .ex.cpp and .hpp), compiled that code into an object file (ex.o), and registered that external file with Modeler. Now, you may edit your external file in the editor of your choice, and use 'op_mko' to recompile your changes. Warning: when you recompile your process model, the external code will NOT be automatically recompiled. You must run op_mko or op_mksim or op_runsim to recompile your external code. (op_mksim will build an entire simulation repository, and op_runsim will build and execute the entire simulaiton.)References:[1] http://opnet.com/support/FAQ_HOME[2] For information about external files, see FAQ 9[3] For important notes regarding c++ code in models, see FAQ 522[4] Other FAQs cover external code files: 380 (general), 47 (Unix), 381 (Windows)

Environment

Compiling/Linking

Attachments
NOTICE: Riverbed® product names have changed. Please refer to the Product List for a complete list of product names.
Can't find an answer? Create a case