simple_source模块可以在外部设置的属性


有四个局部统计量,分别为产生的bit速率、包速率、包大小,包间隔

状态机为三个非强制对象,在头文件里定义了自中断和转移条件。

/*Include files.                                              */

#include   <oms_dist_support.h>

/*Special  attribute  values.                 */

#define              SSC_INFINITE_TIME                  -1.0

/*Interrupt  code  values.                     */       自定义中断

#define              SSC_START                                   0

#define              SSC_GENERATE                           1

#define              SSC_STOP                                     2

/* Nodeconfiguration constants.   */

#define              SSC_STRM_TO_LOW                          0

/* Macrodefinitions for state          */

/*transitions.                                                */定义转移条件

#define              START                                   (intrpt_code == SSC_START)

#define              DISABLED                            (intrpt_code == SSC_STOP)

#define              STOP                                     (intrpt_code == SSC_STOP)

#define              PACKET_GENERATE                   (intrpt_code == SSC_GENERATE)

/*Function prototypes.                               */

staticvoid                           ss_packet_generate(void);

Init非强制状态的入口程序为

/* Atthis initial state, we read the values of source attributes     */包含源的属性定义

/* andschedule a selt interrupt that will indicate our start time   */表明开始的时间

/* forpacket generation.                                                                                                      */

/* Obtainthe object id of the surrounding module.                                              */

own_id = op_id_self ();获得所属处理器或队列的对象ID

/* Readthe values of the packet generation parameters, i.e. the         */

/*attribute values of the surrounding module.                                  */获取给定对象的某属性

op_ima_obj_attr_get
(own_id,"Packet Interarrival Time", interarrival_str);包间隔

op_ima_obj_attr_get(own_id, "Packet Size",             size_str);   包大小

op_ima_obj_attr_get(own_id, "Packet Format",           format_str);包格式

op_ima_obj_attr_get(own_id, "Start Time",              &start_time);开始时间

op_ima_obj_attr_get(own_id, "Stop Time",               &stop_time);停止时间

/* Loadthe PDFs that will be used in computing the packet                     */

/*interarrival times and packet sizes.                                */从PDF中加载分布

interarrival_dist_ptr= oms_dist_load_from_string (interarrival_str);

pksize_dist_ptr       = oms_dist_load_from_string (size_str);

/* Verifythe existence of the packet format to be used for                      */

/*generated packets.                                                    */

if(strcmp (format_str, "NONE") == 0)  检查是否为无格式的包

{

/* We will generate unformattedpackets. Set the flag.                            */

generate_unformatted = OPC_TRUE;

}

else

{

/* We will generate formatted packets.Turn off the flag.               */

generate_unformatted = OPC_FALSE;

/* Get the list of all available packetformats.*/函数返回一系列包格式的名字

pk_format_names_lptr =prg_tfile_name_list_get (PrgC_Tfile_Type_Packet_Format);

/* Search the list for the requestedpacket format.*/查找所需要的包格式

format_found = OPC_FALSE;

for (i = prg_list_size(pk_format_names_lptr); ((format_found == OPC_FALSE) && (i > 0));i--)

{

/* Access the next formatname and compare with requested    */

/* format name.                                                                                                             */

found_format_str = (char *)prg_list_access (pk_format_names_lptr, i - 1);

if (strcmp (found_format_str,format_str) == 0)

format_found =OPC_TRUE;找到了所需要的包格式

}

if (format_found == OPC_FALSE)

{

/* The requested format doesnot exist. Generate                          */

/* unformatted packets.                                                                                     */

generate_unformatted =OPC_TRUE;

/* Display an appropriatewarning.*/没有找到需要的包格式,输出警告

op_prg_odb_print_major("Warning from simple packet generator model (simple_source):",

"Thespecified packet format", format_str,

"isnot found. Generating unformatted packets instead.", OPC_NIL);

}

/* Destroy the lits and its elementssince we don't need it    */

/* anymore.                                                                                                                              */

prg_list_free(pk_format_names_lptr);释放内存

prg_mem_free  (pk_format_names_lptr);

}

/* Makesure we have valid start and stop times, i.e. stop time is         */

/* notearlier than start time.          */

if((stop_time <= start_time) && (stop_time != SSC_INFINITE_TIME))

{如果结束时间早于开始时间或结束时间不为无穷

/* Stop time is earlier than starttime. Disable the source.   */

start_time = SSC_INFINITE_TIME; 
设置开始时间为无穷并且输出警告

/* Display an appropriate warning.                                                                           */

op_prg_odb_print_major ("Warningfrom simple packet generator model (simple_source):",

"Althoughthe generator is not disabled (start time is set to a finite value),",

"astop time that is not later than the start time is specified.",

"Disablingthe generator.", OPC_NIL);

}

/*Schedule a self interrupt that will indicate our start time for     */

/* packetgeneration activities. If the source is disabled,                         */

/*schedule it at current time with the appropriate code value.             */

if(start_time == SSC_INFINITE_TIME)
如果开始时间是无穷,安排自中断开始时间为仿真时间,否则为实际开始时间

{

op_intrpt_schedule_self (op_sim_time(),
SSC_STOP);

}

else

{

op_intrpt_schedule_self (start_time,
SSC_START);

/* In this case, also schedule theinterrupt when we will stop       */

/* generating packets, unless we areconfigured to run until         */

/* the end of the simulation.   */
  仿真结束时间安排一个自中断

if (stop_time != SSC_INFINITE_TIME)

{

op_intrpt_schedule_self(stop_time,SSC_STOP);

}

next_intarr_time = oms_dist_outcome(interarrival_dist_ptr);通过一个分布生成一个浮点数

/* Make sure that interarrival time isnot negative. In that case it */

/* will be set to 0.    */

if (next_intarr_time <0)

{

next_intarr_time = 0.0;

}

}

/*Register the statistics that will be maintained by this model.   */声明局部统计量

bits_sent_hndl            =op_stat_reg ("Generator.Traffic Sent (bits/sec)",                           OPC_STAT_INDEX_NONE,OPC_STAT_LOCAL);

packets_sent_hndl   = op_stat_reg ("Generator.Traffic Sent(packets/sec)",              OPC_STAT_INDEX_NONE,OPC_STAT_LOCAL);

packet_size_hndl    = op_stat_reg ("Generator.Packet Size(bits)",             OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);

interarrivals_hndl  = op_stat_reg ("Generator.PacketInterarrival Time (secs)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);

init出口程序

/*Determine the code of the interrupt, which is used in evaluating      */

/* statetransition conditions.         */

intrpt_code= op_intrpt_code ();

init转到generate状态时的执行的函数代码

staticvoid

ss_packet_generate(void)

{

Packet*                                pkptr;

double                                  pksize;

/** This function creates a packetbased on the packet generation**/

/** specifications of the source modeland sends it to the lower layer.**/

FIN (ss_packet_generate ());

/* Generate a packet size outcome.                                             */

pksize = (double) ceil(oms_dist_outcome (pksize_dist_ptr));

ceil返回大于或等于指定表达式的最小整数

/* Create a packet of specified formatand size.*/

if (generate_unformatted == OPC_TRUE)

{

/* We produce unformattedpackets. Create one. */

pkptr = op_pk_create(pksize);

}

else

{

/* Create a packet with the specifiedformat.*/

pkptr = op_pk_create_fmt(format_str);创建一个预定义结构的包,返回包格式

op_pk_total_size_set (pkptr,pksize);  设置包的大小

}

/* Update the packet generationstatistics.   */

op_stat_write (packets_sent_hndl, 1.0);

op_stat_write (packets_sent_hndl, 0.0);

op_stat_write (bits_sent_hndl, (double)pksize);

op_stat_write (bits_sent_hndl, 0.0);

op_stat_write (packet_size_hndl,(double) pksize);

op_stat_write (interarrivals_hndl,next_intarr_time);

/* Send the packet via the stream tothe lower layer.    */

op_pk_send (pkptr, SSC_STRM_TO_LOW);将包发送到输出包流中

FOUT;

}

generate状态的入口代码

/* At theenter execs of the "generate" state we schedule the              */

/*arrival of the next packet.                                                                                       */

next_intarr_time= oms_dist_outcome (interarrival_dist_ptr);

/* Makesure that interarrival time is not negative. In that case it */

/* will beset to 0. */  确定包生成的间隔时间是有效的

if(next_intarr_time <0)

{

next_intarr_time = 0;

}

next_pk_evh= op_intrpt_schedule_self (op_sim_time () + next_intarr_time, SSC_GENERATE);

generate的出口代码

/*Determine the code of the interrupt, which is used in evaluating      */

/* statetransition conditions.                                                                                             */

intrpt_code= op_intrpt_code ();

stop状态的入口代码

/* Whenwe enter into the "stop" state, it is the time for us to     */

/* stopgenerating traffic. We simply cancel the generation of the        */

/* nextpacket and go into a silent mode by not scheduling anything    */

/* else.                                                                                                                                       */

if(op_ev_valid (next_pk_evh) == OPC_TRUE)

{

op_ev_cancel (next_pk_evh); 
撤销事件

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

opnet的simple_source模块学习 分类: opnet 2014-05-18 09:50 170人阅读 评论(0) 收藏的更多相关文章

  1. C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏

    using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...

  2. 网站通用登录模块代码 分类: ASP.NET 2014-12-06 10:49 615人阅读 评论(0) 收藏

    1.HTML部分:     <form id="form1" runat="server">     <script src=".. ...

  3. iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏

    youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...

  4. Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  5. Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏

    效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  6. JqueryEasyUI 解决IE下加载时页面错乱的问题 分类: JavaScript JqueryEasyUI 2014-09-20 09:50 545人阅读 评论(1) 收藏

    问题描述: 一直觉得jqueryeasyui在IE下的渲染效果不大好,尤其刚进入页面时的加载,页面会出现布局错乱,虽然是一闪而过,但是给用户的体验不好: 可以通过在页面onload时,增加一个遮罩层, ...

  7. PIGS 分类: POJ 图论 2015-08-10 09:15 3人阅读 评论(0) 收藏

    PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18209 Accepted: 8277 Description Mir ...

  8. Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏

    Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36398 Accepted: 15554 Descripti ...

  9. 多校3- RGCDQ 分类: 比赛 HDU 2015-07-31 10:50 2人阅读 评论(0) 收藏

    RGCDQ Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practic ...

随机推荐

  1. grid编辑后时间格式不对问题

    在column中应该定义xtype和format格式: xtype: 'datecolumn', format:'Y-m-d'   之后正常

  2. Linux命令 查看及修改文件属性

    chmod [功能说明] 改变文件的访问权限  #Linux中访问权限分为:文件属主(文件的创建者)文件组属主(创建者所处的组)和其他(其他用户) [语法格式] Chmod[参数]mode[文件名或目 ...

  3. swiper.js 碰到的坑

    1. swiper隐藏之后,再显示,滑动不流畅,且无限滑动会失败: 解决方法: 添加一下两个属性 observer: true,//修改swiper自己或子元素时,自动初始化swiper observ ...

  4. 摘记:Web应用系统测试内容

    表示层: 内容测试,包括整体审美.字体.色彩.拼写.内容准确性和默认值 Web站点结构,包括无效的链接或图形 用户环境,包括Web浏览器版本和操作系统配置(每一个浏览器都有不同的脚本引擎或虚拟机在客户 ...

  5. java web数据库(SQL 2008+IDEA 14)环境配置

    废话少说,在之前已经配置过IDEA+Tomcat的环境之后,现在需要进行数据库配置: 1.首先,SQL SERVER2008数据库的安装 (1)将下载的sqlserver 2008数据库进行解压,点击 ...

  6. 《HelloGitHub》第 15 期

    公告 这段时间没怎么写文章,跑去写 https://hellogithub.com 这个网站了,现在已经顺利上线,功能后面会持续迭代. 最后,这个 https://hellogithub.com 网站 ...

  7. maven下载jar包失败后无法再次重新下载

    maven下载jar包失败后无法再次重新下载:删除maven 资源库中的 *.lastUpdated文件

  8. Python开发简单爬虫(一)

    一 .简单爬虫架构: 爬虫调度端:启动爬虫,停止爬虫,监视爬虫运行情况 URL管理器:对将要爬取的和已经爬取过的URL进行管理:可取出带爬取的URL,将其传送给“网页下载器” 网页下载器:将URL指定 ...

  9. Eclipse 快捷键和模板设置

    快捷键设置 菜单  Window --> Preferences---General---Keys Content Assist:  代码提示快捷键 模板设置 新建一个模板 在Insert Va ...

  10. 水题 第三站 HDU Largest prime factor

    先写一遍思路,跟素数表很类似吧. 1)从小到大遍历数据范围内的所有数.把包含质因子的数的位置都设成跟质因子的位置相同. 2)同一个数的位置可能被多次复写.但是由于是从小到大遍历,这就保证了最后一次写入 ...