op_subq_pk_access()

摘要

获取存储在指定子队列中、位于指定子队列位置的数据包的指针。

语法

op_subq_pk_access (subq_index, pos_index)
参数 类型 说明
subq_index int 目标子队列的数字索引 [子队列流索引从 0 开始,依次递增 1。子队列的数量没有上限,但如果连续使用它们,可以实现内存的节约使用。除了显式的子队列索引,还可以指定抽象子队列选择索引。抽象子队列选择索引通过某个子队列独有的属性来指定该子队列。可接受的抽象子队列选择索引列于表 85“Subqueue Selection Index Symbolic Constants“ 第 26 页。]
pos_index int 要访问的数据包在子队列内所处的数字位置索引 [位置索引从队列头部处的 0 开始,依次递增 1 直到尾部。除了显式的位置索引,还可以指定抽象子队列位置索引(参见表 84“Subqueue Position Index Symbolic Constants“ 第 25 页);可接受的取值为 OPC_QPOS_HEAD、OPC_QPOS_TAIL 和 OPC_QPOS_PRIO。]

返回类型

Packet*

指向在指定子队列中访问到的数据包的指针。若指定的位置索引大于指定子队列中尾部数据包的索引,将返回符号常量 OPC_NIL 所代表的特殊值。

示例

/* determine if queue is empty; if not, then process its contents */
if (op_q_empty () == OPC_FALSE)
	{
	/* determine the number of subqueues */
	op_ima_obj_attr_get (op_id_self (), "subqueue", &subq_objid);
	num_subqs = op_topo_child_count (subq_objid, OPC_OBJTYPE_SUBQ);

	/* loop through each subqueue */
	for (q_index = 0; q_index < num_subqs; q_index++)
		{
		/* determine the number of packets in subqueue */
		num_pkts = op_subq_stat (q_index, OPC_QSTAT_PKSIZE);
		/* loop through each packet in subqueue */
		for (j = 0; j < num_pkts; j++)
			{
			/* schedule self interrupt based on packet’s insert time */
			pkptr = op_subq_pk_access (q_index, j);
			op_intrpt_schedule_self (op_q_insert_time (pkptr) + 0.05, PROC_COMP);
			}
		}
	}

详情

本 KP 只能在与队列模块上运行的进程的上下文中调用(或由队列进程直接或间接调用的函数中调用);从处理器上运行的进程或管道级调用它们将导致错误。

如果为参数 pos_index 指定的值不是受支持的符号常量 OPC_QPOS_PRIO、OPC_QPOS_HEAD 或 OPC_QPOS_TAIL 之一,且该值小于零,则本 KP 将访问子队列头部的数据包。类似地,如果 <pos_index> 大于或等于子队列中数据包的数量,本 KP 将访问子队列尾部的数据包。

用途

提供一种获取子队列中所包含数据包的指针的机制。通常用于扫描子队列的内容,以寻找某个特定数据包(或某类数据包)。扫描可以先通过以 OPC_QSTAT_PKSIZE 为参数调用 KP op_subq_stat() 确定子队列中数据包的数量来实现。随后可以设置一个循环,通过调用 op_subq_pk_access() 获取子队列中每个数据包的指针。一旦获得数据包的指针,就可以利用它的任何属性来实现复杂的排队算法,包括:大小(总大小、批量数据大小或字段大小)、创建时间、打戳时间、入队时间、等待时间、字段内容、优先级等。

错误

  • 程序中止:KP 需要队列上下文。
  • 可恢复错误:子队列选择标志(<flag>)无法识别。

参考

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com