亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

OPNET學(xué)習(xí)筆記之simple_source模塊

系統(tǒng) 2122 0

simple_source模塊的功能是按照配置產(chǎn)生包,包括不同的包格式和產(chǎn)生速率,也是比較簡單的進(jìn)程模型。

參考了《 opnet process model:simple_source分析 http://hi.baidu.com/ebinghaus/blog/item/c7cade9228876c83a877a405.html

  該模塊有4個(gè)local statistic,注意有5個(gè)model attribute,分別是Packet Interarrival Time,Packet Size,Packet Format,Start Time,Stop Time,這些是在使用該模塊時(shí)需要配置的,當(dāng)然也可以使用默認(rèn)配置。

狀態(tài)機(jī)也很簡單:

OPNET學(xué)習(xí)筆記之simple_source模塊

在header block中定義了

/* Include files.?????*/
#include?<oms_dist_support.h>   //注意該模塊使用了外部文件《oms_dist_support》和《oms_string_support》

/* Special attribute values.??*/
#define??SSC_INFINITE_TIME??-1.0     //定義無窮大時(shí)間為-1

/* Interrupt code values.???*/   //注意這里的中斷代碼是自定義的,為了在產(chǎn)生自中斷是使用
#define??SSC_START????0
#define??SSC_GENERATE???1
#define??SSC_STOP????2

/* Node configuration constants.?*/
#define??SSC_STRM_TO_LOW???0     //發(fā)送的stream index,默認(rèn)的,該模塊只有一個(gè)stream連接,所以不需要?jiǎng)討B(tài)獲取stream index

/* Macro definitions for state??transitions.*/    //轉(zhuǎn)換條件為中斷代碼是自定義的常量:

#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.????*/
static void???ss_packet_generate (void);   //產(chǎn)生包的函數(shù),在function block中定義

?

一,INIT的入口代碼:

/* At this initial state, we read the values of source attributes?*/
/* and schedule a selt interrupt that will indicate our start time?*/
/* for packet generation.???????????*/

/* Obtain the object id of the surrounding module.?????*/
own_id = op_id_self ();         //首先得到surrounding objid,應(yīng)該是自己的objid,后面根據(jù)objid獲取對象的屬性

/* Read the values of the packet generation parameters, i.e. the?*/
/* attribute values of the surrounding module.??????*/

//用op_ima_obj_attr_get()得到對象的屬性的值,是產(chǎn)生包的參數(shù)。注意interarrival_str和size_str是臨時(shí)變量,還是char數(shù)組類型。
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);

/* Load the PDFs that will be used in computing the packet???*/
/* interarrival times and packet sizes.????????*/

//裝入PDF,用于前兩個(gè)參數(shù),得到包產(chǎn)生和包大小的分布,函數(shù)是oms_dist_load_from_string(),這樣很方便的使用string類型的參數(shù)。
//獲得的是分布函數(shù)的句柄,注意兩個(gè)句柄都是state variable,類型為Omst_dist_handle。

interarrival_dist_ptr = oms_dist_load_from_string (interarrival_str);
pksize_dist_ptr?????? = oms_dist_load_from_string (size_str);

/* Verify the existence of the packet format to be used for???generated packets.?*/
if (strcmp (format_str, "NONE") == 0)   //檢查是否是無格式包
?{
?/* We will generate unformatted packets. 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 packet formats.????*/

//用prg_tfile_name_list_get()得到所有可用的包格式
?pk_format_names_lptr = prg_tfile_name_list_get (PrgC_Tfile_Type_Packet_Format);

?/* Search the list for the requested packet format.????*/
?format_found = OPC_FALSE;
?for (i = prg_list_size (pk_format_names_lptr); ((format_found == OPC_FALSE) && (i > 0)); i--)
??{
??/* Access the next format name 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 does not exist. Generate unformatted packets.?????*/
??generate_unformatted = OPC_TRUE;
?
??/* Display an appropriate warning.???????*/
??op_prg_odb_print_major ("Warning from simple packet generator model (simple_source):",
????????"The specified packet format", format_str,
????????"is not found. Generating unformatted packets instead.", OPC_NIL);
??}

?/* Destroy the lits and its elements since we don't need it??*/
?/* anymore.??????????????*/
?prg_list_free (pk_format_names_lptr);
?prg_mem_free? (pk_format_names_lptr);
?}?
?
/* Make sure we have valid start and stop times, i.e. stop time is??not earlier than start time.?*/
if ((stop_time <= start_time) && (stop_time != SSC_INFINITE_TIME))   //開始/結(jié)束時(shí)間不合法,設(shè)置開始仿真時(shí)間為無窮大
?{
?/* Stop time is earlier than start time. Disable the source.?*/
?start_time = SSC_INFINITE_TIME;

?/* Display an appropriate warning.????????*/
?op_prg_odb_print_major ("Warning from simple packet generator model (simple_source):",
???????"Although the generator is not disabled (start time is set to a finite value),",
???????"a stop time that is not later than the start time is specified.",
???????"Disabling the generator.", OPC_NIL);
?}

/* Schedule a self interrupt that will indicate our start time for?*/
/* packet generation activities. If the source is disabled,???*/
/* schedule it at current time with the appropriate code value.??*/

//產(chǎn)生自中斷,以指示開始產(chǎn)生包的時(shí)間, 如果停止產(chǎn)生包時(shí)刻小于開始產(chǎn)生包的時(shí)刻(這時(shí)開始產(chǎn)生包的時(shí)間是無限大)在當(dāng)前仿真時(shí)刻產(chǎn)生中斷號為SSC_STOP中斷
if (start_time == SSC_INFINITE_TIME)
?{
?op_intrpt_schedule_self (op_sim_time (), SSC_STOP);   //馬上給出自中斷
?}
else
?{
?op_intrpt_schedule_self (start_time, SSC_START);    //自中斷,在開始時(shí)間,中斷號為SSC_START

?/* In this case, also schedule the interrupt when we will stop?*/
?/* generating packets, unless we are configured to run until?*/
?/* the end of the simulation.?????????*/
?if (stop_time != SSC_INFINITE_TIME)
??{
??op_intrpt_schedule_self (stop_time, SSC_STOP);   //當(dāng)結(jié)束時(shí)間不是無限大時(shí),在結(jié)束時(shí)間產(chǎn)生自中斷,中斷號為SSC_STOP
??}
?
?next_intarr_time = oms_dist_outcome (interarrival_dist_ptr);   //通過分布函數(shù)句柄計(jì)算產(chǎn)生下一個(gè)包的時(shí)間間隔,這里是state variable

?/* Make sure that interarrival time is not negative. In that case it will be set to 0.*/
?if (next_intarr_time <0)
??{
??next_intarr_time = 0.0;   //保證間隔時(shí)間不小于0
??}

?}

/* Register the statistics that will be maintained by this model.?*/

//注冊局部統(tǒng)計(jì)量,返回局部統(tǒng)計(jì)量的句柄
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.Packet Interarrival Time (secs)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);

?

二, 由于初始狀態(tài)是非強(qiáng)制狀態(tài),進(jìn)程執(zhí)行完入口代碼后,停留在該狀態(tài)等待中斷觸發(fā)轉(zhuǎn)移狀態(tài),仿真時(shí)刻到10s(屬性start_time設(shè)置的值)時(shí)將產(chǎn)生中斷號為SSC_START中斷,中斷產(chǎn)生后將首先執(zhí)行當(dāng)前狀態(tài)的出口代碼,初始狀態(tài)的出口代碼如下:
intrpt_code = op_intrpt_code ();   //得到當(dāng)前的中斷代碼

這時(shí)條件START滿足, 進(jìn)程將從初始狀態(tài)轉(zhuǎn)換到generate狀態(tài) ,轉(zhuǎn)移時(shí)首先執(zhí)行轉(zhuǎn)移函數(shù)ss_packet_generate (void),在function block中定義的轉(zhuǎn)移函數(shù)如下:

?

static void ss_packet_generate (void)
?{
?Packet*????pkptr;
?double????pksize;

?

?/** This function creates a packet based on the packet generation??**/
?/** specifications of the source model and sends it to the lower layer.?**/
?FIN (ss_packet_generate ());

?

?/* Generate a packet size outcome.?????*/
?pksize = (double) ceil (oms_dist_outcome (pksize_dist_ptr));   //通過分布函數(shù)句柄得到包大小,再通過ceil()函數(shù)向上舍入,得到包大小
?
?/* Create a packet of specified format and size.?*/
?if (generate_unformatted == OPC_TRUE)
??{
??/* We produce unformatted packets. Create one.?*/
??pkptr = op_pk_create (pksize);             //使用op_pk_creat()函數(shù)產(chǎn)生無格式包
??}
?else
??{
??/* Create a packet with the specified format.?*/
??pkptr = op_pk_create_fmt (format_str);       //使用op_pk_creat_fmt()函數(shù)產(chǎn)生有格式包
??op_pk_total_size_set (pkptr, pksize);         //置有格式包的總大小
??}

?

?/* Update the packet generation statistics.???*/   //通過局部統(tǒng)計(jì)量句柄更新統(tǒng)計(jì)量,注意xxx/sec的量都是在更新后馬上清零
?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 to the lower layer.?*/
?op_pk_send (pkptr, SSC_STRM_TO_LOW);     //發(fā)送包到定義好的stream index,默認(rèn)為0

?

?FOUT;
?}?

?

三, ? 執(zhí)行完轉(zhuǎn)移函數(shù)后將跳到generate狀態(tài),并首先執(zhí)行入口代碼,如下:

/* At the enter execs of the "generate" state we schedule the??*/
/* arrival of the next packet.??????????*/
next_intarr_time = oms_dist_outcome (interarrival_dist_ptr);   //通過分布函數(shù)句柄得到下一個(gè)包的產(chǎn)生時(shí)間間隔

?

/* Make sure that interarrival time is not negative. In that case it will be set to 0.*/
if (next_intarr_time <0)
?{
?next_intarr_time = 0;
?}

//在當(dāng)前時(shí)間+間隔時(shí)間后,產(chǎn)生自中斷,中斷號為SSC_GENERATE,注意返回值為Evhandle類型

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

?

四, 執(zhí)行完入口代碼后,進(jìn)程將停留在generate狀態(tài)等待中斷,當(dāng)下一個(gè)中斷發(fā)生,進(jìn)行狀態(tài)轉(zhuǎn)換,首先執(zhí)行g(shù)enerate狀態(tài)的出口代碼:

intrpt_code = op_intrpt_code ();  //得到中斷號

然后判斷轉(zhuǎn)移條件。

如果是STOP,執(zhí)行stop狀態(tài)的入口代碼:

/* When we enter into the "stop" state, it is the time for us to?*/
/* stop generating traffic. We simply cancel the generation of the?*/
/* next packet and go into a silent mode by not scheduling anything?*/
/* else.???????????????*/
if (op_ev_valid (next_pk_evh) == OPC_TRUE)     //如果下一個(gè)事件仍然有效,就取消該事件,使用事件句柄
?{
?op_ev_cancel (next_pk_evh);
?}

OPNET學(xué)習(xí)筆記之simple_source模塊


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久99久久99精品 | 免费国产高清精品一区在线 | 亚洲国产精品久久久天堂 | 久久久久久一级毛片免费无遮挡 | 国产精品99久久99久久久看片 | 亚洲高清视频一区 | 亚洲欧美成人综合久久久 | 婷婷免费视频 | 国产在线拍国产拍拍偷 | 日本aaaaa级毛片 | 日本精品久久久久中文字幕8 | 99热这里都是国产精品 | 国内高清久久久久久久久 | 亚洲精品在线看 | 拔插拔插成人 | 狠狠的色| 色爱区综合激月婷婷激情五月 | 成人日韩 | 欧美亚洲精品小说一区二三区 | 天堂日韩 | 国产精品98视频全部国产 | 中文字幕亚洲在线 | 午夜剧j| 国产成人免费片在线观看 | 欧美成人免费视频a | 精品一区二区三区在线观看 | 四虎影视在线影院4hu | 久久精品国产国产精品四凭 | 99热在线精品观看 | 国产大片中文字幕在线观看 | 黄色在线观看www | 99热久久国产精品这里小说 | 欧美日韩加勒比一区二区三区 | 亚洲视频免费一区 | 五月天婷亚洲天综合网精品偷 | 91在线播 | 美女视频黄a视频免费全过程在线 | 在线不卡日本 | 国产精品分类视频分类一区 | 亚洲国产成人久久笫一页 | 亚洲免费中文字幕 |