opnet_節(jié)點模型中UDP進程模塊上層模塊與其通信代碼分析
UDP模塊上層進程模塊與UDP交互的注冊流程大體如下所示,具體代碼和分析見后:
1.創(chuàng)建鏈表,通過oms_pr_process_discover通過匹配屬性名稱和屬性值來獲取processregistry process handle。
2.通過移除鏈表,獲取進程記錄句柄。
3.獲取udp模塊對象id
4.確認輸出輸入流
5.創(chuàng)建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:本例中所要查詢的進程注冊表已在該節(jié)點模塊中的UDP進程模塊中注冊和設置 )。
2.再通過oms_pr_process_discover()來獲取匹配的List類型數(shù)據(jù)(PS:本例是獲取節(jié)點ID為node_id的節(jié)點下的protocol為“udp”的進程模型module隊列,其中node_id通過op_topo_parent(op_id_self())獲取,其中op_id_self()函數(shù)獲取當前進程模塊ID,op_topo_parent(op_id_self())獲取當前進程模塊所在節(jié)點模塊ID)
3.通過op_prg_list_remove()或者op_prg_list_access()來獲取OmsT_Pr_Handle類型的數(shù)據(jù)(PS:本代碼中假設本節(jié)點中protocol為"udp"的進程模型只有一個)
4.通過oms_pr_attr_get()函數(shù)process_record_handle獲取當前節(jié)點模塊下udp進程模塊的模型ID。
5.通過oms_tan_neighbot_streams_find()函數(shù)獲取當前進程模型和UDP進程模型的輸入輸出流。
6.通過自定義函數(shù)注冊當前進程模型和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())獲取節(jié)點ID
2.??????通過op_id_from_name()函數(shù)獲取名稱為ip的類型為OPC_OBJMTYPE_MODULE的進程模塊ID
3.??????通過op_ima_obj_attr_get_objid()函數(shù)獲取主機參數(shù)屬性,存儲至ip_host_comp_obid中
4.??????通過op_topo_child()函數(shù)獲取復合屬性對象ip_host_comp_obid中的第一個子對象id。
5.??????通過op_ima_obj_attr_get_objid()函數(shù)獲取其接口信息對象ID。
6.??????通過op_topo_child()函數(shù)獲取接口信息對象inf_info_comp_obid的第一個子對象ID。
7.??????通過op_ima_obj_attr_get_objid()函數(shù)獲取地址信息(char型)。
8. ?????通過ip_addr_create()函數(shù)創(chuàng)建地址(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()函數(shù)創(chuàng)建與UDP進程模塊通信的“udp_command_v3”格式ici。
2.設置ici的端口。
3.安裝該ici
4.遠程強制喚醒進程模塊ID為udp_obid的進程模塊的UDPC_COMMAND_CREATE_PORT中斷。
5.獲取該ici的status屬性值。





