OPNETWorker99培训在OPNET中使用CC语言编程_第1页
OPNETWorker99培训在OPNET中使用CC语言编程_第2页
OPNETWorker99培训在OPNET中使用CC语言编程_第3页
OPNETWorker99培训在OPNET中使用CC语言编程_第4页
OPNETWorker99培训在OPNET中使用CC语言编程_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、copyright 1999 mil 3, inc.programming in c+ in opnet 1programming in c+ in opnetjerome pluncopyright 1999 mil 3, inc.programming in c+ in opnet 2agenda file type suffixes review of building process models in c building process models with c+ basic simulation use of variables based on object classes

2、exceptions and debugging writing c+ pipeline stages using external c+ files generating c+ ema program c+ limitationscopyright 1999 mil 3, inc.programming in c+ in opnet 3opnet file type suffixesprocess modelpipeline stageexternal codeemamodel.pr.mc.pr.c.ps.c.ex.c.em.cc+.pr.cpp.ps.cpp.ex.cpp.em.cppob

3、ject*.pr.o.ps.o.ex.o.em.o* environment attribute arch_suffix set to false copyright 1999 mil 3, inc.programming in c+ in opnet 4compiling c-based process models use op_mko program (invoked by in process editor) example: op_mko -m sink -type pr generate intermediary c file and resulting object file s

4、pecific c compiler invoked based on comp_prog additional compiler options specified with comp_flagsop_mkohost c compiler.pr.m.pr.c.pr.ocopyright 1999 mil 3, inc.programming in c+ in opnet 5compiling c+ process models use op_mko program example: op_mko -m hla_rti_gateway -type pr generate intermediar

5、y c+ file and resulting object file specific c+ compiler invoked based on comp_prog_cpp additional compiler options specified with comp_flags_cppop_mkohost c+ compiler.pr.m.pr.cpp.pr.ocopyright 1999 mil 3, inc.programming in c+ in opnet 6c or c+ compilationc/c+ distinction based on tokenopc_compile_

6、cpp in header block of process model:copyright 1999 mil 3, inc.programming in c+ in opnet 7c+ compilation environment variables solaris with suns cc compiler: comp_prog_cpp : comp_unix_cpp unix with g+: comp_prog_cpp : comp_g+ windows nt with visual c+: comp_prog_cpp : comp_msvc comp_flags_cpp : /gx

7、copyright 1999 mil 3, inc.programming in c+ in opnet 8linking simulations dynamic simulation op_runsim program bind_shobj_prog : linking script bind_shobj_flags : additional linking flags bind_shobj_libs : additional linking libraries in static simulation op_mksim program bind_static_prog : linking

8、script bind_static_flags : additional linking flags bind_static_libs : additional linking librariescopyright 1999 mil 3, inc.programming in c+ in opnet 9linking simulations with c+ process models require appropriate c+ support libraries solaris with sun cc: dynamic simulation:- bind_shobj_prog : bin

9、d_so_cc static simulation:- bind_static_prog : bind_cccopyright 1999 mil 3, inc.programming in c+ in opnet 10linking simulations with c+ process models (cont.) windows nt with visual c+: dynamic simulation:- bind_shobj_prog : bind_cppso_msvc static simulation:- bind_static_prog : bind_cpp_msvc for m

10、ore complete details, refer to external interfaces manual program descriptions chapter development environment attributes sectioncopyright 1999 mil 3, inc.programming in c+ in opnet 11c+ code in process models c+ code allowed in state enter and exit executives state variables temporary variables hea

11、der block function block diagnostic block termination blockcopyright 1999 mil 3, inc.programming in c+ in opnet 12lab 1 : goals create process model containing c+ code compile process model build network simulation with process model run simulationcopyright 1999 mil 3, inc.programming in c+ in opnet

12、 13lab 1 : create process model in a new process editor create one state enter the following in the enter executive of the statecout “process id = “ op_id_self () endl; enter the following two lines in the header blockopc_compile_cpp#include save the process model as show_id compile process model (

13、) copyright 1999 mil 3, inc.programming in c+ in opnet 14labs 1 : create node model in a new node editor add one processor ( ) set the process model to show_id enable the begsim intrpt attribute save the node model as show_idcopyright 1999 mil 3, inc.programming in c+ in opnet 15lab 1 : run network

14、simulation open the cpp_programming project make sure the lab1_show_id scenario is visible it contains 3 show_id nodes open that project and run the simulation ( ) then click on a command prompt window should appear with the output of the simulationcopyright 1999 mil 3, inc.programming in c+ in opne

15、t 16lab 1 : simulation output the end of the output should contain something like|-| initializing results |-|-| progress: time (0 sec.), events (0) | speed: average (0 events/sec.), current (0 events/sec.) | time: elapsed (0 sec.) |-|process id = 4process id = 5process id = 6|-| simulation completed

16、 - collating results. | simulated: time (1 sec.), events (3) | time: elapsed (1sec.) |-|copyright 1999 mil 3, inc.programming in c+ in opnet 17state variables created when the corresponding process is created initialization phase for root processes during simulation for dynamically created processes

17、 constructors can call kps (result is well-defined) root processes never destroyed dynamically created processes potentially destroyed corresponding state variable(s) destroyed termination block executed before variables destructors destructors can call kpscopyright 1999 mil 3, inc.programming in c+

18、 in opnet 18temporary variables created when invoking process model diagnostic block termination block destroyed when exiting process model diagnostic block termination block constructor and destructor can call kpsinvocation startinvocation endcopyright 1999 mil 3, inc.programming in c+ in opnet 19g

19、lobal variables any variable declared in header or function blocks created when process model is loaded by the operating system before simulation created before simulation packages are initialized statically allocated variables: constructors must not use kpscopyright 1999 mil 3, inc.programming in c

20、+ in opnet 20global variables: example of error example of dangerous use of kps in constructorsclass init_error public: init_error () mem_handle = op_prg_pmo_define (data, 100, 10); private: pmohandle mem_handle;init_error will_cause_error;init_error * will_not_cause_error;copyright 1999 mil 3, inc.

21、programming in c+ in opnet 21global variables: example of error (cont.) the previous header block results in with error from constructorcopyright 1999 mil 3, inc.programming in c+ in opnet 22variable creation/destructioncreateddestroyedvariableobject code loaded in memoryprogram terminatedglobalproc

22、ess instance createdprocess instance destroyedstateprocess invocation startedprocess invocation endedtemporarycopyright 1999 mil 3, inc.programming in c+ in opnet 23lab 2 - goals review creation and destruction of variables provided: process model show_vars class show_status (defined in header block

23、)- prints a message when instance created- prints a message when instance destroyed show_status instances as- global variable in header block (header_var)- global variable in function block (function_var)- state variable (state_var)- temporary variable (tmp_var)copyright 1999 mil 3, inc.programming

24、in c+ in opnet 24lab 2 - simulation states with printout statements in enter and exit executives begin simulation interrupt enabled for process model self-interrupt scheduled in enter executive of init in the cpp_programming project, switch to scenario lab2_show_vars and run it can you guess how man

25、y constructions and destructions will occur?copyright 1999 mil 3, inc.programming in c+ in opnet 25lab 2: answers 5 variable creations: header, function, state, temp twice 4 variable destructions: header, function, temp twicecopyright 1999 mil 3, inc.programming in c+ in opnet 26lab 2: result of exe

26、cution object code loading by operating system|-| loading scenario model library|-* variable header_var created * variable function_var created *begin simulation interrupt* variable tmp_var created *enter executive of unforced state init* variable tmp_var destroyed *creation of process state|-| crea

27、ting node contents.|-* variable state_var created *copyright 1999 mil 3, inc.programming in c+ in opnet 27lab 2: result of execution (cont.) self-interrupt* variable tmp_var created *exit executive of unforced state initenter executive of forced state middleexit executive of forced state middleenter

28、 executive of unforced state last* variable tmp_var destroyed *| simulation completed - collating results. | simulated: time (1 sec.), events (1). | time: elapsed (1 sec.)|-press to continue.* variable function_var destroyed * variable header_var destroyed *termination of simulationprocess state nev

29、er destroyedcopyright 1999 mil 3, inc.programming in c+ in opnet 28c+ exceptions kps do not throw any exceptions exceptions unhandled by process model abort the simulation example: process model bad_exception enter executive of init state isthrow this exception is not caught; running a simulation wi

30、th this process model generates * time: . * program: op_runsim (version 6.0.l pl5) * error: unhandled c+ exception in process model (bad_exception)copyright 1999 mil 3, inc.programming in c+ in opnet 29unhandled c+ exception m3_vuerr output * time: . * program: op_runsim (version 6.0.l pl5) * packag

31、e: * function: bad_exception () init enter execs * error: unhandled c+ exception in process model (bad_exception) * function call stack: (builds down) - call block count line# function- 0) 1 118 main (argc, argv) 1) 1 469 sim_main (prog_name, argc, argv, dynamic_sim, def_net_name,num_procs, proc_set

32、_ptr, num_pk_meths, pk_set_ptr, num_pk_fd_meths, pk_fd_set_ptr) 2) 1 884 sim_ev_loop () 3) 1 476 sim_obj_qps_intrpt (simev_ptr) 4) 1 27 bad_exception () init enter execs 5) 1 346 vos_error_print (level, package, error0, error1, error2)-copyright 1999 mil 3, inc.programming in c+ in opnet 30source-le

33、vel debugging most powerful tool for debugging c/c+ code requires knowledge of code layout type structures variable names function names useful to understand c+ code generationcopyright 1999 mil 3, inc.programming in c+ in opnet 31source-level debugging: code generation example: process model tcp_co

34、nn process data stored as c+ class tcp_conn_state state variables data members of tcp_conn_state- tcp_connection connection;- double duration; useful methods of tcp_conn_state- state-transition: tcp_conn ()- diagnostic block: tcp_conn_diag ()- termination block: tcp_conn_state ()copyright 1999 mil 3

35、, inc.programming in c+ in opnet 32source-level debugging: data access in code, op_sv_ptr represents the current statestate variablesopnet internalscopyright 1999 mil 3, inc.programming in c+ in opnet 33writing c+ pipeline stage simulation kernel expects specific prototype for each stage interface f

36、unction named as base name of file c linkage of interface function example: transmission delay for point-to-point pipeline file tx_delay.ps.cpp - interface function tx_delay c linkage with extern “c” around prototype / prototypeextern “c” void tx_delay (packet * pkptr);void tx_delay (packet * pkptr)

37、 . other functions in pipeline stage dont need c linkagecopyright 1999 mil 3, inc.programming in c+ in opnet 34compiling pipeline stages, external files, ema use op_mko program for pipeline stages and external files pipeline stage: op_mko -m dra_error -type ps external file: op_mko -m link_delay -ty

38、pe ex use m3_mkema program for emam3_mkema -m rnode .c file compiled using comp_prog and comp_flags .cpp file compiled using comp_prog_cpp and comp_flags_cpp .o object file generated copyright 1999 mil 3, inc.programming in c+ in opnet 35conflicting file extensions exactly one file with extension .c

39、 or .cpp must be found compilation fails if both extensions found op_mko -m dra_error -type ps will report if dra_error.ps.c and dra_error.ps.cpp are found similar errors for external files and ema * error: pipeline stage model compilation failed both c and c+ source code files foundcopyright 1999 mil 3, inc.programming in c+ in opnet 36linking c/c+ ema programs m3_mkema program links .e

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论