opnet_节点模型中UDP进程模块上层模块与其通信代码分析
扫描二维码
随时随地手机看文章
UDP模块上层进程模块与UDP交互的注册流程大体如下所示,具体代码和分析见后:
1.创建链表,通过oms_pr_process_discover通过匹配属性名称和属性值来获取processregistry process handle。
2.通过移除链表,获取进程记录句柄。
3.获取udp模块对象id
4.确认输出输入流
5.创建udp的ici控制流
void assemble_init() { /* Variable for discover the udp module */ List proc_record_handle_list; OmsT_Pr_Handle process_record_handle; FIN(assemble_init()); my_port = UDP_PORT; my_ipaddr = own_ipaddr_get(); /* Find udp module */ op_prg_list_init (&proc_record_handle_list); oms_pr_process_discover (OPC_OBJID_INVALID, &proc_record_handle_list, "node objid", OMSC_PR_OBJID, node_id, "protocol", OMSC_PR_STRING, "udp", OPC_NIL); if (op_prg_list_size (&proc_record_handle_list) != 1) { /* Generate a simulation log message first and end simulation. */ op_sim_end ("Error: either zero or several udp processes connected to application layer.", "", "", ""); } /* Assume there is only one udp module in the node */ /* Get the process record handle for the udp process model */ process_record_handle = (OmsT_Pr_Handle) op_prg_list_remove (&proc_record_handle_list, OPC_LISTPOS_HEAD); /* Obtain the module object id of the udp */ oms_pr_attr_get (process_record_handle, "module objid", OMSC_PR_OBJID, &udp_obid); /* Determine the input and output stream indices */ oms_tan_neighbor_streams_find (my_id, udp_obid, &input_strm, &output_strm); /* Create ICI for udp to get status value */ assemble_create_udp_rcv_port(my_port); FOUT; }
代码分析:
1.进程注册表可以通过oms_pr_process_register()来注册,可以通过oms_pr_attr_set()来设置属性名称、属性类型、属性值(PS:本例中所要查询的进程注册表已在该节点模块中的UDP进程模块中注册和设置 )。
2.再通过oms_pr_process_discover()来获取匹配的List类型数据(PS:本例是获取节点ID为node_id的节点下的protocol为“udp”的进程模型module队列,其中node_id通过op_topo_parent(op_id_self())获取,其中op_id_self()函数获取当前进程模块ID,op_topo_parent(op_id_self())获取当前进程模块所在节点模块ID)
3.通过op_prg_list_remove()或者op_prg_list_access()来获取OmsT_Pr_Handle类型的数据(PS:本代码中假设本节点中protocol为"udp"的进程模型只有一个)
4.通过oms_pr_attr_get()函数process_record_handle获取当前节点模块下udp进程模块的模型ID。
5.通过oms_tan_neighbot_streams_find()函数获取当前进程模型和UDP进程模型的输入输出流。
6.通过自定义函数注册当前进程模型和UDP进程模型的交互ICI接口。
IpT_Address own_ipaddr_get(void) { IpT_Address ipaddr; char ip_addr_str[32]; Objid my_node_id, ip_module, temp_obid, ip_host_comp_obid, inf_info_comp_obid; FIN(own_ipaddr_get()); /* Get node's ID */ my_node_id = op_topo_parent(op_id_self()); /* Get ID of IP module */ ip_module = op_id_from_name(my_node_id, OPC_OBJMTYPE_MODULE, "ip"); /* Get ID of ip host parameters's attribute */ op_ima_obj_attr_get_objid( ip_module, "ip host parameters", &ip_host_comp_obid ); /* Get ID of compond attribute */ temp_obid = op_topo_child( ip_host_comp_obid, OPC_OBJTYPE_GENERIC, 0 ); /* Get ID of Interface Information below compond attribute */ op_ima_obj_attr_get_objid( temp_obid, "Interface Information", &inf_info_comp_obid ); /* Get ID of compond attribute */ temp_obid = op_topo_child(inf_info_comp_obid, OPC_OBJTYPE_GENERIC, 0); /* Get string of Address attribute */ op_ima_obj_attr_get_str( temp_obid, "Address", sizeof(ip_addr_str), ip_addr_str ); ipaddr = ip_address_create(ip_addr_str); FRET (ipaddr); }
代码分析:
1. 通过op_topo_parent(op_id_self())获取节点ID
2. 通过op_id_from_name()函数获取名称为ip的类型为OPC_OBJMTYPE_MODULE的进程模块ID
3. 通过op_ima_obj_attr_get_objid()函数获取主机参数属性,存储至ip_host_comp_obid中
4. 通过op_topo_child()函数获取复合属性对象ip_host_comp_obid中的第一个子对象id。
5. 通过op_ima_obj_attr_get_objid()函数获取其接口信息对象ID。
6. 通过op_topo_child()函数获取接口信息对象inf_info_comp_obid的第一个子对象ID。
7. 通过op_ima_obj_attr_get_objid()函数获取地址信息(char型)。
8. 通过ip_addr_create()函数创建地址(IpT_Address结构类型)
int assemble_create_udp_rcv_port(int port_num) { int ind; FIN(assemble_create_udp_rcv_port(port_num)); if (op_prg_odb_ltrace_active ("udp")) op_prg_odb_print_major ("Issuing CREATE_PORT command...", OPC_NIL); /* Issue the CREATE_PORT command. */ command_ici_ptr = op_ici_create ("udp_command_v3"); /* Set UDP local port */ op_ici_attr_set (command_ici_ptr, "local_port", port_num); op_ici_install (command_ici_ptr); op_intrpt_force_remote (UDPC_COMMAND_CREATE_PORT, udp_obid); /* Get the status indication from the ici */ op_ici_attr_get_int32 (command_ici_ptr, "status", &ind); FRET(ind); }
代码分析:
1.通过op_ici_create()函数创建与UDP进程模块通信的“udp_command_v3”格式ici。
2.设置ici的端口。
3.安装该ici
4.远程强制唤醒进程模块ID为udp_obid的进程模块的UDPC_COMMAND_CREATE_PORT中断。
5.获取该ici的status属性值。