初学opnet 如理解有误,欢迎指正
INIT 出口代码 出口代码有点长,不要被吓到了
/* Obtain the address assigned to this node. */
if (op_ima_obj_attr_get (mac_attr_objid, "Address", &my_32bit_address) //op_ima_obj_attr_get(objid,attr_name,value_ptr) 从指定的对象objid中获取属性attr_name放到value_ptr中 value_ptr是void*型 返回值为compcode
== OPC_COMPCODE_FAILURE)
{
eth_mac_error ("Unable to read station address attribute.", OPC_NIL, OPC_NIL);
}
/* Perform auto-addressing for the MAC address dynamically addresses·, if auto-assigned, the address resolution function also detects duplicate */
/* static assignments. By default each address is */
/* considered as being a valid destination unless it is */
/* explicitly set. */
oms_aa_address_resolve (oms_aa_handle, mac_attr_objid, &my_32bit_address);//
Creates a new, unique address (if theaddress is auto-assigned), or verifies that theaddress is unique (if the address is explicitly assigned). 所以有检测重复分配的功能
/* Initialize and export the frame-waiting variable used */ 初始化并导出帧等待变量
/* by deference process in computing deference intervals. */
frame_waiting = 0.0;
op_stat_write (frame_handle, frame_waiting);
/* Obtain the node's object id. */
own_node_objid = op_topo_parent (my_objid); 获得节点id
/* Obtain the process's process handle. */
own_prohandle = op_pro_self (); //获得进程句柄
/* Obtain the name of the process. */
op_ima_obj_attr_get (my_objid, "process model", proc_model_name);
/* Register this Ethernet MAC process in the model-wide registry. */
own_process_record_handle = (OmsT_Pr_Handle) oms_pr_process_register (own_node_objid, my_objid, 获得记录进程注册信息的句柄
own_prohandle, proc_model_name);
/* Register the protocol attribute and mac type info of this */
/* process into the model-wide registry. */
oms_pr_attr_set (own_process_record_handle, "protocol", OMSC_PR_STRING, "mac", OPC_NIL); 在句柄中注册协议信息 name type value ...OPNIL
oms_pr_attr_set (own_process_record_handle, "mac_type", OMSC_PR_STRING, "eth", OPC_NIL); /*两句可以合并为一句 oms_pr_attr_set (own_process_record_handle, "protocol", OMSC_PR_STRING, "mac", "mac_type", OMSC_PR_STRING, "eth",OPC_NIL);*/
/* Determine object identifier of transmitter connecting */
/* the MAC layer to the bus. This Objid is needed to abort */