5 (opnet XY路由实现)添加信息头

  1. 创建一个包格式,并且包格式命名为head
    2在这里插入图片描述
    在状态中添加 address_dist = op_dist_load (“uniform_int”,0,3);

然后在process的进程里,写一下变量,deistribution*是一个指针类型
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
一个包建立完成,又因为创建的包是16byte的,因此要将包分成两个flit,这部分写的我看不懂

在这里插入图片描述

Objid parent_subnet;
Objid source;
Objid traf_gen_comp_attr_objid, traf_conf_objid;
Objid source_traf_gen_comp_attr_objid,source_traf_conf_objid;
Objid source_pkt_gen_comp_attr_objid,source_pkt_gen_args_objid;

parent_subnet = op_topo_parent(op_id_self ());

op_ima_obj_attr_get (parent_subnet, "coordinate" , &traf_gen_comp_attr_objid);

traf_conf_objid = op_topo_child (traf_gen_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);

op_ima_obj_attr_get_int32(traf_conf_objid, "iX", &iX);
op_ima_obj_attr_get_int32(traf_conf_objid, "iY", &iY);

	
printf("(%d,%d)\n",iX,iY);

flit_buf_handle = op_sar_buf_create (OPC_SAR_BUF_TYPE_REASSEMBLY, OPC_SAR_BUF_OPT_DEFAULT);

address_dist = op_dist_load ("uniform_int",0,3);

segmentation_buf_handle = op_sar_buf_create (OPC_SAR_BUF_TYPE_SEGMENT, OPC_SAR_BUF_OPT_PK_BNDRY);

source = op_id_from_name(parent_subnet,OPC_OBJMTYPE_MODULE,"source");
op_ima_obj_attr_get (source, "Traffic Generation Parameters", &source_traf_gen_comp_attr_objid);
source_traf_conf_objid = op_topo_child (source_traf_gen_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);


op_ima_obj_attr_get (source_traf_conf_objid, "Packet Generation Arguments", &source_pkt_gen_comp_attr_objid);
source_pkt_gen_args_objid = op_topo_child (source_pkt_gen_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);

/* Check if packet segmentation is modeled.	*/
op_ima_obj_attr_get (source_pkt_gen_args_objid, "Segmentation Size", &segmentation_size);
segmentation_size*=8;

printf("segmention_size %d\n",segmentation_size);

在这里插入图片描述
在这里插入图片描述

static void
xmt(void)
{
Packet *dataflit, *src_pkptr,* head,* headlflit;
int startbit,pksize,comp_pk_count=0,pk_index;
int message,destX,destY;
int headlsize;
List* bitrange_list_ptr;
Sar_Bitrange * bitrange_ptr;
FIN(xmt());

dataflit = op_pk_get (SRC_IN_STRM);
bitrange_list_ptr = op_sar_seg_bitrange_list_get (dataflit);
bitrange_ptr = (Sar_Bitrange *) op_prg_list_access (bitrange_list_ptr, OPC_LISTPOS_HEAD);

op_sar_bitrange_info_get (bitrange_ptr, OPC_SAR_BITRANGE_PROPERTY_STARTBIT, &startbit);
op_sar_bitrange_info_get (bitrange_ptr, OPC_SAR_BITRANGE_PROPERTY_PKSIZE, &pksize);

printf("startbit %d,pksize %d\n",startbit,pksize);


op_sar_rsmbuf_seg_insert (flit_buf_handle, dataflit);

comp_pk_count = op_sar_rsmbuf_pk_count (flit_buf_handle);

for (pk_index = 0; pk_index < comp_pk_count;pk_index++)
	{
	src_pkptr = op_sar_rsmbuf_pk_remove(flit_buf_handle);
	op_pk_fd_get_int32 (src_pkptr, 0, &message);
	printf("message %d\n",message);
	//op_subq_pk_insert (0,src_pkptr, OPC_QPOS_TAIL);
	}
if(startbit==0)
	{

    destX = (int)op_dist_outcome (address_dist);
    destY = (int)op_dist_outcome (address_dist);

    head = op_pk_create_fmt ("head1");//´´½¨head°ü
	
    op_pk_nfd_set_int32 (head,"destX",destX);
    op_pk_nfd_set_int32 (head,"destY",destY);

    headlsize = 16;
    /* Loop through to remove segments of the original application packet and   */
    /* send them out to the lower layer.                                        */
   if (segmentation_size > 0  && headlsize > segmentation_size)
     {
    /* Insert the packet into the segmentation buffer and pull out segments */
    /* of size specified by the attribute segment size.                     */

       op_sar_segbuf_pk_insert (segmentation_buf_handle, head, -1);
	  
       while (headlsize > 0)
	     {
		 /* Remove segments of size equal to the segment size and send them to   */
		 /* transport layer. If the number of available bits in the buffer is    */
		 /* is lesser than the segment size a packet will be created only with   */
		 /* remaining bits.                                                      */
		 headlflit = op_sar_srcbuf_seg_remove (segmentation_buf_handle, segmentation_size);
		  
		 /* Update the pk_size remaining to reflect the reduced size.    */
		 headlsize -= segmentation_size;
          
		 /* Send the packet to the lower layer.	*/
		 op_pk_send (headlflit, XMT_OUT_STRM);
	     }
      }
   }

FOUT;
}

在这里插入图片描述
在这里插入图片描述
这次有一点小问题但是搞了很久希望不要和我有同样的问题,结果如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值