产生故障与恢复

由于节点或链路不能自主地发生故障或恢复,仿真过程中必须由外部动作来改变节点或链路的状态。通常使用以下四种产生故障与恢复的方法之一:确定性(deterministic)、脚本(scripted)、随机(stochastic) 或 交互(interactive)。确定性方法使某一个节点或链路在仿真中的特定时刻发生故障并恢复。脚本方法比确定性方法更通用,它基于一个文件中明确给出的故障与恢复时刻和位置。随机方法依据给定的时刻与位置分布产生故障与恢复。交互式操作则通过调试器直接设置一次故障或恢复。下面每种方法都各给出一个示例,这些示例可以根据具体的建模需求加以修改。

当某个对象的 condition 属性改变值时,该对象就发生了一次故障或恢复。因此,四种方法各自都提供了一种改变该属性值的机制;它们的区别在于如何选择对象以及如何选择故障或恢复发生的时刻。

除交互式操作之外,每种方法都需要由某个进程来改变节点或链路的 condition 属性。通常,可以由一个*集中式(centralized)进程负责产生故障与恢复,也可以由许多分布式(decentralized)*进程负责。集中式进程通常位于一个专门为此任务预留、并且自身永不发生故障的节点中。而每个分布式进程通常位于不同的节点之内,负责其父节点的故障与恢复。

如果某个节点被禁用,则不会有任何中断投递到该节点内的模块。由于这一事实,节点内的进程无法直接使该节点恢复。进程要被调用,本身必须先收到一个中断才能改变节点的状态,但节点已被禁用,所以它收不到任何中断。因此,如果一个进程负责使其父节点恢复,它可以安排(schedule)一个过程调用中断(procedure call interrupt),该中断会调用一个使节点恢复的过程。虽然过程调用中断是在安排它的进程的上下文中执行该过程,但这个中断并没有投递到节点内的对象,因此仿真内核不会阻止该过程的调用。下一小节中的图示包含一段示例代码片段,它展示的进程正是用这种技术使其父节点先故障再恢复。

确定性进程示例

本节给出的确定性进程示例基于这样一个概念:某个特定的节点或链路在已知的仿真时刻发生故障并恢复。该进程有两个属性用来指定故障与恢复时刻:“fail time” 和 “recover time”。可选地,该进程还可以有另一个属性用来指定要修改的对象,例如使用节点或链路的名称。不过,本例中的进程只是使其父节点先故障再恢复,做法是把父节点的 condition 属性先设为 “disabled”,再设为 “enabled”。由于该进程只负责其父节点,因此它可以看作分布式故障/恢复进程的一个例子。当系统只需要简单的故障/恢复建模时,推荐使用确定性进程方法。通常只安排一次故障/恢复循环,而不是一连串循环。下面的图示给出了一个确定性故障/恢复进程的示例代码片段。

图 193:安排父节点故障与恢复的示例

/* Obtain the module’s and parent node’s object IDs. */
module_id = op_id_self ();
node_id = op_topo_parent (module_id);
/* Obtain the failure and recovery simulation times. */
op_ima_obj_attr_get (module_id, "fail time", &fail_time);
op_ima_obj_attr_get (module_id, "recover time", &recover_time);
/* Schedule the node’s failure and recovery via "call" interrupts. */
op_intrpt_schedule_call (fail_time, FAIL_CODE, fail_recov_proc, OPC_NIL);
op_intrpt_schedule_call (recover_time, RECOV_CODE, fail_recov_proc, OPC_NIL);

图 194:使父节点启用与禁用的示例 Function Block Procedure

fail_recov_proc (state_ptr, code)
	char*  state_ptr;
	int    code;
	{
	Objid nd_objid;

	/** This procedure causes the parent node of the module that this **/
	/** interrupt was scheduled in to either fail or recover,         **/
	/** depending on the code.                                        **/
	FIN (fail_recov_proc (state_ptr, code))

	/* Obtain the parent node’s object ID. */
	nd_objid = op_topo_parent (op_intrpt_source ());

	/* Depending on the code, either enable or disable the node. */
	if (code == RECOV_CODE)
		op_ima_obj_attr_set (nd_objid, "condition", OPC_BOOLINT_ENABLED);
	else
		op_ima_obj_attr_set (nd_objid, "condition", OPC_BOOLINT_DISABLED);

	FOUT

脚本文件进程示例

脚本文件是一个文本文件,其中给出故障与恢复的时刻以及受影响的对象。相关进程依据该脚本文件,在整个系统范围内产生节点和链路的故障与恢复。由于它是整个系统中唯一产生故障与恢复的进程,因此可以看作集中式故障/恢复进程的一个例子。当仿真中在特定时刻发生大量或复杂的故障与恢复序列时,脚本文件进程方法很有用。

在本例中,脚本文件为每一次故障或恢复事件给出一个行。每一行包含三个值:事件要发生的时刻、对象的用户 ID,以及事件类型(故障或恢复)。这里使用对象的用户 ID 而不是对象 ID,因为节点和链路的 “user id” 属性值属于网络模型的一部分,因而在仿真开始之前就是已知的。对象 ID 由仿真内核在运行时分配,只能在仿真过程中才能获知。图 195 展示了一个脚本文件的例子。

脚本文件可以来自多种来源。如果网络模型对应一个已存在的网络,脚本文件可以基于节点与链路故障和恢复的实际记录。另一种做法是创建一个表示某种特定系统行为的脚本文件,例如一系列节点相继故障。脚本文件也可用于测试“最坏情况”场景,例如一组相互依赖的节点和链路同时发生故障。

相关进程读取脚本文件,并建立一张节点与链路故障和恢复时刻的列表。列表建立完成后,进程为第一个故障或恢复事件的时刻安排一个自身中断(self interrupt)。当该自身中断发生时,进程通过调用内核过程 op_ima_obj_attr_set() 把指定对象的 condition 属性设为正确的值,并为下一个故障或恢复事件安排另一个自身中断。下面的图示包含一个基于脚本的故障/恢复进程的示例代码片段。

图 195:脚本文件示例

#	Example script file for node/link failures/recoveries
#	Times are expected in order
#
#	time   user_id   event
	10.00    12      failure
	12.30    12      recovery
	14.40    3       failure
	14.40    4       failure
	14.45    5       failure
	14.55    4       recovery
	100.00   3       recovery

图 196:使对象故障或恢复的 Proto-C 示例

/* This process just received a self intrpt that signals a failure */
/* or recovery action. Obtain the top instruction from the list.    */
inst_ptr = (Script_Inst*) op_prg_list_remove (event_list_ptr, OPC_LISTPOS_HEAD);

/* Convert user ID to object ID. */
object_id = user_id_to_object_id_convert (inst_ptr->user_id);

/* Set the object’s “condition” attribute to the specified value. */

if (inst_ptr->type == FAIL_CODE)
	op_ima_obj_attr_set (object_id, “condition”, OPC_BOOLINT_DISABLED);
else op_ima_obj_attr_set (object_id, “condition”, OPC_BOOLINT_ENABLED);

/* Deallocate instruction. */
op_prg_mem_free (inst_ptr);

/* Transition to next state, where next interrupt is scheduled. */

图 197:安排故障/恢复自身中断的 Proto-C 示例

/* Obtain the next instruction from the list. */
inst_ptr = (Script_Inst*) op_prg_list_access (event_list_ptr, OPC_LISTPOS_HEAD);

/* Schedule a self interrupt for the time. */
op_intrpt_schedule_self (inst_ptr->time, 0);

图 198:读取脚本文件的 Proto-C 示例

/* Obtain name of script file from the process’ attribute. */
op_ima_obj_attr_get (op_id_self (), "script name", script_name);

/* Create and init list to hold failure/recovery instructions. */
event_list_ptr = op_prg_list_create ();

/* Load the file contents into a list. */
line_list_ptr = op_prg_gdf_read (script_name);

/* Loop through the lines of the list and parse each line. */
list_size = op_prg_list_size (line_list_ptr);
for (i = 0; i < list_size; i++)
	{
	/* Obtain the i_th line in the file. */
	string = op_prg_list_access (line_list_ptr, i);

	/* Decompose the line in to fields. */
	field_list_ptr = op_prg_str_decompose (string, " ,/\t");

	/* If the line does not have three fields or starts with '#' */
	/* then skip it and try the next.                            */
	if (op_prg_list_size (field_list_ptr) != 3)
		goto dealloc;
	field0 = op_prg_list_access (field_list_ptr, 0);
	if (field0 [0] == '#')
		goto dealloc;

/* Allocate a structure to hold the event instruction. */
	inst_ptr = (Script_Inst*) op_prg_mem_alloc (sizeof (Script_Inst));

	/* Fill in the instruction. */
	inst_ptr->time = atof (field0);
	inst_ptr->user_id = atoi (op_prg_list_access (field_list_ptr, 1);
	field2 = op_prg_list_access (field_list_ptr, 2);
	if (strcmp ("failure", field2) == 0)
		inst_ptr->type = FAIL_CODE;
	else inst_ptr->type = RECOVER_CODE;

	/* Place the instruction on the end of the list. */
	op_prg_list_insert (event_list_ptr, inst_ptr, OPC_LISTPOS_TAIL);

	/* Deallocate the elements in the list and then the list itself. */
	dealloc:
	op_prg_list_free (field_list_ptr);
	op_prg_mem_free (field_list_ptr);
	}

/* Deallocate the elements in the list and then the list itself. */
op_prg_list_free (line_list_ptr);
op_prg_mem_free (line_list_ptr);

随机进程示例

随机故障/恢复进程依据分布产生节点和链路的故障与恢复,使节点和链路的状态随机变化。示例进程有四个属性决定故障与恢复事件的频繁程度。“node fail mean” 和 “link fail mean” 属性分别给出节点和链路的平均故障时刻;类似地,“node recover mean” 和 “link recover mean” 属性给出平均恢复时刻。进程随机选择一个特定节点或链路使其故障,然后为该节点或链路安排一次恢复。故障与恢复时刻常用指数分布来建模,但对某些特定系统而言,其他分布可能更准确。

当随机产生的故障与恢复对系统来说是合适的模型时,推荐使用随机进程。当故障与恢复数量很大时,随机进程通常比脚本文件进程更实用。随机进程还有一个额外的好处:它动态地产生故障与恢复,能够适应不同规模的网络和不同的仿真时长;而且它无需用户新的输入,就能自动让网络经历典型的场景。

示例进程并行地为节点和链路产生故障。开始时,进程取得平均故障与恢复的属性值,并根据平均值计算出两个故障时刻,然后为一次节点故障安排一个自身中断,再为一次链路安排另一个自身中断。当故障的自身中断发生时,进程随机选择一个节点或链路,并通过内核过程 op_ima_obj_attr_set() 把其 condition 属性设为 “disabled” 使其故障。随后,进程根据指定的平均恢复时刻为该节点或链路计算一个恢复时刻,为恢复安排一个自身中断,并把该节点或链路的对象 ID 作为中断的 code。包含对象 ID 是为了让进程能够识别该启用哪个对象。当这个中断发生时,该对象的 condition 属性被重新设为 “enabled”。在安排恢复中断的同时,进程也安排下一次故障的自身中断。下面的图示包含一个随机故障/恢复示例进程的代码片段。

图 199:使对象故障或恢复的 Proto-C 示例

/* This process just received an interrupt.  Determine what is to  */
/* happen.  Node and link failures use the codes; recovery intrpts */
/* contain the object ID of the object to recover.                 */
code = op_intrpt_code ();
if (code == NODE_FAIL_CODE))
	{
	/* Obtain random node object ID and determine if already disabled. */
	object_index = (int) op_dist_uniform (num_nodes);
	object_id = op_topo_object (OPC_OBJMTYPE_NODE, object_index);
	op_ima_obj_attr_get (object_id, “condition”, &current_condition)
	if (current_condition != disabled)
		{
		/* Cause the node to fail. */
		op_ima_obj_attr_set (object_id, “condition”, OPC_BOOLINT_DISABLED);

		/* Schedule recovery interrupt; first generate recovery time. */
		intrpt_time = op_sim_time () + op_dist_outcome (node_recov_dist_ptr);
		op_intrpt_schedule_self (intrpt_time, object_id);
		}

	/* Schedule the next fail interrupt; first generate failure time. */
	intrpt_time = op_sim_time () + op_dist_outcome (node_fail_dist_ptr);
	op_intrpt_schedule_self (intrpt_time, NODE_FAIL_CODE);
}
else if (code == LINK_FAIL_CODE)
	{
	/* Obtain random link object ID and determine if already disabled. */
	object_index = (int) op_dist_uniform (num_links);
	object_id = op_topo_object (OPC_OBJMTYPE_LINK, object_index);
	op_ima_obj_attr_get (object_id, “condition”, &current_condition)
	if (current_condition != disabled)
		{
		/* Cause the link to fail. */
		op_ima_obj_attr_set (object_id, “condition”, OPC_BOOLINT_DISABLED);

/* Schedule recovery interrupt; first generate recovery time. */
		intrpt = op_sim_time () + op_dist_outcome (link_recov_dist_ptr);
		op_intrpt_schedule_self (intrpt_time, object_id);
		}

	/* Schedule the next fail interrupt; first generate failure time. */
	intrpt_time = op_sim_time () + op_dist_outcome (link_fail_dist_ptr);
	op_intrpt_schedule_self (intrpt_time, LINK_FAIL_CODE);
	}
else
	{
	/* This is a recovery; the code is the object ID of the object */
	/* that is recovering.  Set the “condition” attribute.         */
	op_ima_obj_attr_set (code, “condition”, OPC_BOOLINT_ENABLED);
	}

交互式操作

当仿真在 OPNET 仿真调试器下运行时,可以直接用调试器命令 attrset 设置对象的属性。通过这一机制,可以把节点或链路的 condition 属性设为 “enabled” 或 “disabled”。如果该值发生变化,就会产生恢复或故障中断,其效果与某个进程通过调用内核过程 op_ima_obj_attr_set() 改变属性值完全相同。交互式操作对于“实时”测试系统对故障与恢复的反应很有用。

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · 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