CyberT_Effect_Proc_Ptr
摘要
回调:当需要执行某个网络效应时被调用。
语法
<effect_proc_name> (cmd_iface_ptr, effect_args_vptr, model_data_vptr)
| 参数 | 类型 | 说明 |
|---|---|---|
cmd_iface_ptr |
CyberT_Cmd_Iface* |
cyber-effects manager 与各客户端之间的接口。用于在 cyber_effects_mgr(以及各个子 instruction_mgr)与客户端模块之间传递信息。 |
effect_args_vptr |
void* |
指向包含该效应参数值的数据结构的指针(必须转换为合适的类型)。 |
model_data_vptr |
void * |
客户端模块希望在执行效应回调时传入的数据(必须转换为合适的类型)。 |
返回类型
void
无返回值
头文件
cyber_effects.h
示例
来自 ip_rte_central_cpu 的 function block:
void
cyber_effect_change_service_rate_to_cmd_proc (CyberT_Cmd_Iface* cmd_iface_ptr, void* effect_args_vptr, void* model_data_vptr)
{
CyberT_IP_Change_Rate_Args* effect_args_ptr;
double* one_over_service_rate_ptr;
double change_rate, percentage;
/** Callback that represents the effect of changing the **/
/** IP forwarding rate. **/
FIN (cyber_effect_change_service_rate_to_cmd_proc (effect_args_vptr, model_data_vptr));
/* Obtain the arguments sent for this Cyber Effect. */
effect_args_ptr = (CyberT_IP_Change_Rate_Args*) effect_args_vptr;
/* Obtain the data provided by the local process (ip_rte_central_cpu). */
/* In this case it is a reference to the variable holding the current */
/* fowarding date (stored as one over the service rate). */
one_over_service_rate_ptr =(double*) model_data_vptr;
/* When decreasing the rate, the percentage of the change must be less than */
/* 100% (allowing 100% decrease would block completely the forwarding in */
/* this node. That could translate in increase memory in the simulation. */
if (!effect_args_ptr->is_increase && effect_args_ptr->percentage >=1.0)
percentage = 0.99;
else
/* Otherwise use the percentage change requested. */
percentage = effect_args_ptr->percentage;
/* Compute the change rate. */
change_rate = percentage * (1 / (*one_over_service_rate_ptr));
/* Now compute the new once over service rate value. */
if (effect_args_ptr->is_increase)
{
*one_over_service_rate_ptr = 1.0 / (change_rate + (1 / (*one_over_service_rate_ptr)));
}
else
{
*one_over_service_rate_ptr = 1.0 / ((1.0 / (*one_over_service_rate_ptr)) - change_rate);
}
FOUT;
}
详细说明
该回调原型规定了客户端模块中表示某个网络效应的函数应如何定义。表示效应取消操作的函数也使用这一原型。
回调函数通过改变调用它的进程模型的行为来实现某个效应,通常的做法是改变某个参数值。参数 effect_args_vptr 和 model_data_vptr 对这一过程至关重要。两者都必须转换为本地结构,回调才能获取做出所需改动时用到的信息。
- effect_args_vptr 提供对该效应所用参数的访问
- model_data_vptr 提供对客户端模块中各类变量的访问,这些变量或是计算所需,或是会被修改以产生期望的效应。这些变量存储模型参数值,通常是状态变量。
此类回调通过 cyber_effects_cmd_register() 注册。