README 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. Migrating your INET-based models from OMNeT++ 3.x to 4.x
  2. ========================================================
  3. Overview
  4. ========
  5. The tools in this directory are for migrating simulation models based
  6. on previous INET versions, written for OMNeT++ 3.x. These tools
  7. should be run *after* the corresponding migration scripts in OMNeT++
  8. (omnetpp-4.x/migrate/*).
  9. What has changed in INET for OMNeT++ 4.x?
  10. - most differences are due to OMNeT++ changes: different NED and ini file
  11. syntax, C++ code changes due to simulation library changes (64-bit
  12. simtime, added "get" verbs, methods renamed, etc)
  13. - directory structure. Now everything is under src/ and examples/.
  14. - NED:
  15. - several parameters and gates got renamed (as we standardized on
  16. camelCaseNames instead of under_score_names; also gate names are
  17. now xxxIn/xxxOut versus the old fromXxx/toXxx to from_xxx/to_xxx)
  18. - default values and @units added to many parameters
  19. - "in"+"out" gates of Router/StandardHost got merged to inout gate "pppg",
  20. and corresponding pairs of unidirectional connections got merged
  21. into single bidirectional ones
  22. - likewise, "ethIn"+"ethOut" gates and connections got merged into
  23. "ethg" ones
  24. - wherever "like" occurred in NED files, a module interface got
  25. extracted, and the modules implement that interface; for example,
  26. all mobility models now implement "IMobility" (by convention, names
  27. of module interfaces begin with "I")
  28. - other smaller changes
  29. - msg:
  30. - removed omitGetVerb everywhere - now all getter methods begin with "get"
  31. - C++:
  32. - several methods and some classes got renamed, mostly to let getter
  33. methods begin with the word "get"
  34. Prerequisites:
  35. ==============
  36. - read Migration.pdf from the OMNeT++ 4.0 distro. You ABSOLUTELY want
  37. to do that before doing anything.
  38. - make sure you have a *backup* of the original source files you
  39. want to port. If you have your sources in a version control
  40. system (like Subversion, Mercurial or Git; highly recommended!)
  41. make a branch or at least a different working copy.
  42. - have a good visual diff tool at hand that can also compare whole
  43. directory trees (like meld, winmerge, k3diff, etc).
  44. The migration process
  45. =====================
  46. A generic advice beforehand: don't try to swallow everything at once.
  47. Do the porting with simtime_t = double first, get everything working,
  48. validate if possible -- THEN switch to int64-base simtime.
  49. 1. Project Setup.
  50. If you extended INET, it's likely that your sources are in various
  51. subdirs in the INET directory tree. In OMNeT++ 4.0 it is possible to
  52. do it in a cleaner way, by separating the base INET and you project
  53. into two separate projects. It goes like this:
  54. 1. Start the IDE.
  55. 2. Import the base INET as a project (File|Import... --> General /
  56. Existing projects into workspace)
  57. 3. Create a new OMNeT++ project, and copy your sources into it.
  58. (We recommend you make a "src" and an "examples" or "simulations"
  59. subdirectory.)
  60. 4. Mark you project as dependent on INET (Project Properties --> Project
  61. References --> check INET).
  62. Then your project can use modules from INET, your C++ sources may include
  63. headers from INET etc, all automatically. No manual tweaking needed.
  64. This setup also has the advantage that when a new INET version comes out,
  65. you can just replace your INET dir with the new one; no manual merging
  66. needed.
  67. 2. Switch OMNeT++ to "double" simtime
  68. Add -DUSE_DOUBLE_SIMTIME to CFLAGS (CFLAGS_DEBUG and CFLAGS_RELEASE)
  69. in Makefile.inc or configure.user, whichever you like (in the latter case
  70. don't forget to re-run ./configure), or by temporarily adding
  71. #define USE_DOUBLE_SIMTIME to the top of include/simkerneldefs.h;
  72. then recompile it (make cleanall; make)
  73. 3. Run migration scripts
  74. Much of the migration process is automated by various scripts, located under
  75. omnetpp-4.x/migrate and INET/migrate. They should be run on the command prompt
  76. (not inside IDE).
  77. a. make copy of the current state of your sources
  78. b. run the scripts one by one, first the OMNeT++ ones, then the INET ones.
  79. The scripts convert files in the current directory, so you need to
  80. "cd" to your project's root dir, and invoke the scripts from there,
  81. like:
  82. $ cd ~/workspace/myproj
  83. $ ~/omnetpp-4.0/migrate/migratened
  84. With migratecpp, you also want to save the output into a text file, as
  85. it prints various suggestions about the source.
  86. c. start your visual diff tool (meld etc), and diff the project to the
  87. backup you did in step (a), to review what changes the scripts did.
  88. Most migration scripts work by plain text substitution (basically
  89. global find/replace), and occasionally they replace things they were
  90. not supposed to.
  91. 4. NED files
  92. The migration scripts only do part of the job. You need to do some more manual
  93. changes to get error-free NED files; and you'll probably want to make further
  94. changes, to make use of the new possibilities of NED.
  95. Revise module parameters
  96. Especially simple module parameters. Many that came out as "double" or
  97. "volatile double" after the migration script should actually be "int" or
  98. "volatile int". (In 3.x there was only a "numeric" type, and the migration
  99. script of course doesn't know whether they should be "int" or "double" now.)
  100. Example:
  101. volatile double numHosts; // should be: int numHosts;
  102. You can now provide default values to parameters, so that they can be
  103. simply assigned in omnetpp.ini, with **.apply-default = true.
  104. Also, some parameters need units. Like those that are time should have
  105. @unit(s), packet length etc in bytes should have @unit(byte) or @unit(B),
  106. etc. Units should be added to values and default values too.
  107. Examples:
  108. double timeout;
  109. double startTime;
  110. volatile double sendInterval;
  111. could be changed to:
  112. double timeout @unit(s) = default(120s);
  113. double startTime @unit(s) = default(uniform(1s,2s));
  114. volatile double sendInterval @unit(s) = default(exponential(100ms));
  115. By convention, parameter names begin with lowercase, and use camelCase
  116. instead of under_scores.
  117. Adjust gate names
  118. To be more compliant with the new INET naming convention, you may change
  119. gate names to the style xxxIn/xxxOut, from the former from_xxx/to_xxx or
  120. fromXxxx/toXxxx.
  121. Merge gates of routers/hosts
  122. If you have host or router models, change their gates like this:
  123. inout in[];
  124. output out[];
  125. input ethIn[];
  126. output ethOut[];
  127. to:
  128. inout pppg[];
  129. inout ethg[];
  130. Merge the corresponding connections too, like:
  131. in[i] --> ppp[i].physIn;
  132. out[i] <-- ppp[i].physOut;
  133. needs to be changed to:
  134. pppg[i] <--> ppp[i].phys;
  135. And this:
  136. ethIn[i] --> eth[i].physIn;
  137. ethOut[i] <-- eth[i].physOut;
  138. to
  139. ethg[i] <--> eth[i].phys;
  140. And of course sizeof(ethOut) changes to sizeof(ethg), and sizeof(out)
  141. to sizeof(pppg).
  142. Use bidirectional connections
  143. Merge pairs of uni-directional connections to a single bidirectional one;
  144. for example, this:
  145. r1.out++ --> ethernetline --> r2.in++;
  146. r1.in++ <-- ethernetline <-- r2.out++;
  147. becomes
  148. r1.pppg++ <--> ethernetline <--> r2.pppg++;
  149. You also can use the provided "mergenedconns" migration script to
  150. automate this step. Review the results though.
  151. Fix channel datarates
  152. Channel data rates used to be plain numbers; now it expects a unit
  153. like Kbps or Mbps. Change likes like:
  154. datarate = 512*1000000;
  155. to
  156. datarate = 512Mbps;
  157. Make channels inner types
  158. It was customary to put channel definitions in the same file as your
  159. network. These channes can now become inner types of the network.
  160. That is, a channel like
  161. channel fiberline extends ned.BasicChannel
  162. {
  163. parameters:
  164. delay = 1us;
  165. datarate = 512Mbps;
  166. }
  167. may be moved inside the network:
  168. network MyNetwork
  169. {
  170. parameters: ...
  171. gates: ...
  172. types:
  173. channel fiberline extends ned.BasicChannel {
  174. delay = 1us;
  175. datarate = 512Mbps;
  176. }
  177. submodules: ...
  178. ...
  179. }
  180. Eliminate superfluous network definitions.
  181. After conversion, you're going to see NED code like:
  182. module MyNetwork
  183. {
  184. // submodules, connections etc...
  185. }
  186. network myNetwork extends MyNetwork
  187. {
  188. }
  189. Which can be simplified to:
  190. network MyNetwork
  191. {
  192. }
  193. Remember to change "myNetwork" to "MyNetwork" in the corresponding ini file,
  194. too!
  195. Add/make use of default icons.
  196. Add default icons to your simple modules. Looks like this:
  197. simple MyModule {
  198. parameters:
  199. @display("i=block/table");
  200. ...
  201. }
  202. The modules in INET have default icons now too, so after this you can safely
  203. kill off almost all "i=" stuff can be killed off from submodule display strings
  204. in compound modules and networks.
  205. FlatNetworkConfigurator changes
  206. In the new INET, FlatNetworkConfigurator no longer has the parameters
  207. "moduleTypes" and "nonIPModuleTypes"; so these parameters can be removed
  208. from the NED files. Instead, all module types that represent some physical
  209. device in the network have to be annotated with @node(): hosts, routers,
  210. switches, access points, etc. Example:
  211. module Router
  212. {
  213. parameters:
  214. @node(); <==== note added property!
  215. string routingFile = default("");
  216. //...
  217. }
  218. If you wrote your own Configurator, you'll probably want to revise it as well,
  219. and use topo.extractByProperty("node") instead of extractByModuleType(..).
  220. Existing extractByModuleType(..) calls probably won't work out of the box
  221. anyway, because NED type names need to be referred to with fully qualified
  222. name, that is, "inet.nodes.inet.StandardHost" instead of just "StandardHost".
  223. The same for findModuleType(): they'll only work if you write fully qualified
  224. names.
  225. 5. C++ files
  226. 6. ini files
  227. 7. Validate
  228. Run your simulations and make sure they do what they are supposed to do.
  229. Possibly, compare output or saved log with that from the original (3.x)
  230. version.
  231. 8. Recompile with int64-based simtime_t
  232. Change back OMNeT++ to int64-based simtime_t (basically undo what you did
  233. in (2)); then recompile everything. In your project you'll encounter
  234. lots of "cannot convert simtime_t to double" and "no matching function for
  235. somethingOrOther(foo_t, bar_t, const simtime&)". The solution is usually
  236. one of these:
  237. - change variable or function argument from "double" to "simtime_t"
  238. - add an explicit cast to double (SIMTIME_DBL() macro)
  239. It is sometimes tricky which way to choose, but you'll get the hang of it
  240. after a while.
  241. 9. Validate
  242. Run your simulations again, and make sure they work correctly. You cannot
  243. expect to get the exact same output as from "double" simtime, due to increased
  244. precision of simtime; outputs may even diverge significantly after a while,
  245. as the simulation chooses a differen trajectory; but still try to make sure
  246. things work correctly.
  247. 10. Rejoice
  248. Release a big sigh of relief, and go out to have a beer :)
  249. Send questions, problems, hatemail to:
  250. andras@omnetpp.org