Sunteți pe pagina 1din 23

/* Process model C form file: p_wpan_packet_source_process.pr.c */ /* Portions of this file copyright 1986-2008 by OPNET Technologies, Inc.

*/

/* This variable carries the header into the object file */ const char p_wpan_packet_source_process_pr_c [] = "MIL_3_Tfile_Hdr_ 145A 30A mod eler 7 4F4F7EA8 4F4F7EA8 1 preeti-81ebc3d2 preeti 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 1bcc 1

"; #include <string.h>

/* OPNET system definitions */ #include <opnet.h>

/* Header Block */ /* Include files // Distribution Modeling sub-package #include <oms_dist_support.h> #include "headers\wpan_math.h" #include "headers\wpan_params.h" #include "headers\wpan_struct.h" /* Node configuration constants /* Special attribute values #define SC_INFINITE_TIME /* Interrupt code values #define SC_START #define SC_STOP #define SC_GENERATE_ACK #define SC_GENERATE_UNACK */ */ -1.0 */ 0 1 2 3 */ */

/* Input and output streams #define STRM_FROM_UNACK_TO_MAC 0 #define STRM_FROM_ACK_TO_MAC 1

/* State machine conditions */ #define START ((op_intrpt_type () == OPC_INTRP T_SELF) && (op_intrpt_code () == SC_START)) #define DISABLED ((op_intrpt_type () == OPC_INTRP T_SELF) && (op_intrpt_code () == SC_STOP)) #define STOP ((op_intrpt_type () == OPC_INTRP T_SELF) && (op_intrpt_code () == SC_STOP)) #define ACK_MSDU_GENERATE ((op_intrpt_type () == OPC_INTRPT_SELF) && (op_intrpt_code () == SC_GENERATE_ACK)) #define UNACK_MSDU_GENERATE ((op_intrpt_type () == OPC_INTRPT_SELF)

&& (op_intrpt_code () == SC_GENERATE_UNACK)) /* Function static void static void static void static void prototypes. */ wpan_source_init (void); wpan_print_parameters (void); wpan_ack_traffic_generate (void); wpan_unack_traffic_generate (void);

/* Global variables. */ extern int app_sent_msdu_nbr; // Number of MSDU generated by the Application Lay er extern double app_sent_msdu_bits; // MSDUs sent by the Application Layer [kbits]

/* End of Header Block */ #if !defined (VOSD_NO_FIN) #undef BIN #undef BOUT #define BIN FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_b lock_origin; #define BOUT BIN #define BINIT FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_block_origin = __ LINE__; #else #define BINIT #endif /* #if !defined (VOSD_NO_FIN) */

/* State variable definitions */ typedef struct { /* Internal state tracking for FSM */ FSM_SYS_STATE /* State Variables */ double ack_start_time ; /* Time when this source will start its ack-MSDU generat ion activities. */ double ack_stop_time ; /* Time when this source will stop its ack-MSDU generati on activities. */ OmsT_Dist_Handle ack_msdu_interarrival_dist_ptr ; /* PDF used to determine the interarrival times of the g enerated ack-MSDUs. */ OmsT_Dist_Handle ack_msdu_size_dist_ptr ; /* PDF used to determine the sizes of generated ack-MSDU s. */ char ack_msdu_interarrival_dist_str[1 28] ; /* PDF used to determine the interarrival times of the g enerated ack-MSDUs. */ char ack_msdu_size_dist_str[128] ; /* PDF used to determine the sizes of generated ack-MSDU s. */ double unack_start_time ; /* Time when this source will start its unack-MSDU gener ation activities. */ double unack_stop_time

; /* tion activities. */ OmsT_Dist_Handle ; /* ated unack-MSDUs. */ OmsT_Dist_Handle ; /* DUs. */ char [128] ; /* ated unack-MSDUs. */ char ; /* DUs. */ int ; /* char ; /* Objid ; /* Boolean ; /* Stathandle ; /* tic. */ Stathandle ; /* stic. */ Stathandle ; /* Stathandle ; /* statistic. */ Stathandle ; /* tic. */ Stathandle ; /* DUs. */ Stathandle ; Stathandle ; /* tic. */ Stathandle ; /* stic. */ Stathandle ; /* Stathandle l ; /* statistic. */ Stathandle ; /* tic. */ Stathandle ; /* DUs. */ Stathandle ;

Time when this source will stop its unack-MSDU genera unack_msdu_interarrival_dist_ptr PDF used to determine the interarrival times of gener unack_msdu_size_dist_ptr PDF used to determine the sizes of generated unack-MS unack_msdu_interarrival_dist_str PDF used to determine the interarrival times of gener unack_msdu_size_dist_str[128] PDF used to determine the sizes of generated unack-MS dest_mac_address Destination MAC address for data transmission */ node_name[30] Name of the node */ parent_id Object ID of the parent object (node) */ enable_log Is the logging to the file enabled? */ ack_bits_sent_hndl Statistic handle for "Traffic Sent (bits/sec)" statis ack_msdus_sent_hndl Statistic handle for "Traffic Sent (MSDUs/sec)" stati ack_msdu_size_hndl Statistic handle for "MSDU Size (bits)" statistic. */ ack_msdu_interarrival_time_hndl Statistic handle for "MSDUt Interaarival Time (secs)" ack_bits_sent_hndlG Statistic handle for "Traffic Sent (bits/sec)" statis ack_msdus_hndl Statistic handle for the total number of generated MS ack_msdus_hndlG unack_bits_sent_hndl Statistic handle for "Traffic Sent (bits/sec)" statis unack_msdus_sent_hndl Statistic handle for "Traffic Sent (MSDUs/sec)" stati unack_msdu_size_hndl Statistic handle for "MSDU Size (bits)" statistic. */ unack_msdu_interarrival_time_hnd Statistic handle for "MSDU Interaarival Time (secs)" unack_bits_sent_hndlG Statistic handle for "Traffic Sent (bits/sec)" statis unack_msdus_hndl Statistic handle for the total number of generated MS unack_msdus_hndlG

Evhandle ; U. */ Evhandle ; SDU. */

ack_next_msdu_evh /* Event handle for the arrival of next acknowledged MSD unack_next_msdu_evh /* Event handle for the arrival of next unacknowledged M

} p_wpan_packet_source_process_state; #define ack_start_time #define ack_stop_time #define ack_msdu_interarrival_dist_ptr _dist_ptr #define ack_msdu_size_dist_ptr r #define ack_msdu_interarrival_dist_str _dist_str #define ack_msdu_size_dist_str r #define unack_start_time #define unack_stop_time #define unack_msdu_interarrival_dist_ptr terarrival_dist_ptr #define unack_msdu_size_dist_ptr ptr #define unack_msdu_interarrival_dist_str terarrival_dist_str #define unack_msdu_size_dist_str str #define dest_mac_address #define node_name #define parent_id #define enable_log #define ack_bits_sent_hndl #define ack_msdus_sent_hndl #define ack_msdu_size_hndl #define ack_msdu_interarrival_time_hndl _time_hndl #define ack_bits_sent_hndlG #define ack_msdus_hndl #define ack_msdus_hndlG #define unack_bits_sent_hndl #define unack_msdus_sent_hndl #define unack_msdu_size_hndl #define unack_msdu_interarrival_time_hndl terarrival_time_hndl #define unack_bits_sent_hndlG #define unack_msdus_hndl #define unack_msdus_hndlG #define ack_next_msdu_evh #define unack_next_msdu_evh op_sv_ptr->ack_start_time op_sv_ptr->ack_stop_time op_sv_ptr->ack_msdu_interarrival op_sv_ptr->ack_msdu_size_dist_pt op_sv_ptr->ack_msdu_interarrival op_sv_ptr->ack_msdu_size_dist_st op_sv_ptr->unack_start_time op_sv_ptr->unack_stop_time op_sv_ptr->unack_msdu_in op_sv_ptr->unack_msdu_size_dist_ op_sv_ptr->unack_msdu_in op_sv_ptr->unack_msdu_size_dist_ op_sv_ptr->dest_mac_address op_sv_ptr->node_name op_sv_ptr->parent_id op_sv_ptr->enable_log op_sv_ptr->ack_bits_sent_hndl op_sv_ptr->ack_msdus_sent_hndl op_sv_ptr->ack_msdu_size_hndl op_sv_ptr->ack_msdu_interarrival op_sv_ptr->ack_bits_sent_hndlG op_sv_ptr->ack_msdus_hndl op_sv_ptr->ack_msdus_hndlG op_sv_ptr->unack_bits_sent_hndl op_sv_ptr->unack_msdus_sent_hndl op_sv_ptr->unack_msdu_size_hndl op_sv_ptr->unack_msdu_in op_sv_ptr->unack_bits_sent_hndlG op_sv_ptr->unack_msdus_hndl op_sv_ptr->unack_msdus_hndlG op_sv_ptr->ack_next_msdu_evh op_sv_ptr->unack_next_msdu_evh

/* These macro definitions will define a local variable called */ /* "op_sv_ptr" in each function containing a FIN statement. */ /* This variable points to the state variable data structure, */ /* and can be used from a C debugger to display their values. */ #undef FIN_PREAMBLE_DEC #undef FIN_PREAMBLE_CODE #define FIN_PREAMBLE_DEC p_wpan_packet_source_process_state *op_sv_ptr; #define FIN_PREAMBLE_CODE \ op_sv_ptr = ((p_wpan_packet_source_process_state *)(OP_SIM_CONTE

XT_PTR->_op_mod_state_ptr)); /* Function Block */ #if !defined (VOSD_NO_FIN) enum { _op_block_origin = __LINE__ + 2}; #endif /******************************************************************************* ** IEEE 802.15.4/ZigBee OPNET Simulation Model ******************************************************************************** ** Author: Petr Jurcik <petr@isep.ipp.pt> <jurcikp@control.felk.cvut.cz> Author: Anis Koubaa <aska@isep.ipp.pt> Organization: IPP-HURRAY Research Group CISTER/ISEP Polytechnic Institute of Porto, Portugal Organization: Department of Control Engineering Faculty of Electrical Engineering Czech Technical University in Prague, Czech Republic Copyright (c) 2007 - 2009 This file is part of IEEE 802.15.4/ZigBee OPNET Simulation Model for OPNET Model er. IEEE 802.15.4/ZigBee OPNET Simulation Model can be used, copied and modified under the next licenses: - GPL - GNU General Public License Code can be modified and re-distributed under any combination of the above liste d licenses. If a contributor does not agree with some of the licenses, he/she ca n delete appropriate line. If you delete all lines, you are not allowed to distr ibute source code and/or binaries utilizing code. ******************************************************************************** ** GNU General Public License IEEE 802.15.4/ZigBee OPNET Simulation Model is free software; you can redistribu te it and/or modify it under the terms of the GNU General Public License as publ ished by the Free Software Foundation; either version 2 of the License, or (at your option) any later versi on. IEEE 802.15.4/ZigBee OPNET Simulation Model is distributed in the hope that it w ill be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of ME RCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public L icense for more details. You should have received a copy of the GNU General Public License along with IEE E 802.15.4/ZigBee OPNET Simulation Model; if not, write to the Free Software Fou ndation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

******************************************************************************** */ /******************************************************************************* ** * The Traffic source can produce unacknowledged and acknowledged MSDUs * (MAC Service Dat Units = MAC Frame Payload) for CAP period. ******************************************************************************** **/ /*------------------------------------------------------------------------------* Function: wpan_source_init * * Description: - initialize the process * - read the values of source attributes * - schedule a self interrupt that will indicate start time * for MSDU generation * * No parameters *-------------------------------------------------------------------------------*/ static void wpan_source_init() { Objid own_id; /* Object ID of the surrounding processor or queue */ Objid traffic_source_comp_id; Objid traffic_source_id; char device_mode[20]; /* mode of the device: PAN Coordinator or End De vice */ /* Stack tracing enrty point */ FIN(wpan_source_init); /* obtain self object ID of the surrounding processor or queue */ own_id = op_id_self (); /* obtain object ID of the parent object (node) */ parent_id = op_topo_parent (own_id); /* get the value to check if this node is PAN coordinator or not */ op_ima_obj_attr_get (parent_id, "Device Mode", device_mode); /* get the name of the node */ op_ima_obj_attr_get (parent_id, "name", node_name); /* get destination MAC address */ op_ima_obj_attr_get (own_id, "Destination MAC Address", &dest_mac_addres s); op_ima_obj_attr_get (parent_id, "Enable Logging", &enable_log); op_ima_obj_attr_get (own_id, "Acknowledged Traffic Parameters", &traffic _source_id); traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_G ENERIC, 0); /* Read the values of the ack-MSDU generation parameters, i.e. the attri

bute values of the surrounding module. */ op_ima_obj_attr_get (traffic_source_comp_id, ck_msdu_interarrival_dist_str); op_ima_obj_attr_get (traffic_source_comp_id, ck_msdu_size_dist_str); op_ima_obj_attr_get (traffic_source_comp_id, ack_start_time); op_ima_obj_attr_get (traffic_source_comp_id, ack_stop_time);

"MSDU Interarrival Time", a "MSDU Size", "Start Time", "Stop Time", a & &

op_ima_obj_attr_get (own_id, "Unacknowledged Traffic Parameters", &traff ic_source_id); traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_G ENERIC, 0); /* Read the values of the unack-MSDU generation parameters, i.e. the att ribute values of the surrounding module. */ op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interarrival Time", u nack_msdu_interarrival_dist_str); op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size", u nack_msdu_size_dist_str); op_ima_obj_attr_get (traffic_source_comp_id, "Start Time", & unack_start_time); op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time", & unack_stop_time); /* if your are PAN Coordinator do not send packets itself */ if ((strcmp(device_mode, "PAN Coordinator")==0) && (dest_mac_address==PA N_COORDINATOR_ADDRESS)) { ack_start_time = SC_INFINITE_TIME; unack_start_time = SC_INFINITE_TIME; } /* if the destination MAC address is broadcast do not send acknowledged packets */ if ((dest_mac_address == BROADCAST_ADDRESS)&&(ack_start_time != SC_INFIN ITE_TIME)) { ack_start_time = SC_INFINITE_TIME; if (enable_log) { printf (" [Node %s] The acknowledged data cannot be gene rated, since the Destination MAC Adddress is set to BROADCAST. \n", node_name); } } /* Load the PDFs that will be used in computing the MSDU Interarrival Ti mes and MSDU Sizes. */ ack_msdu_interarrival_dist_ptr = oms_dist_load_from_string (ack_msdu_int erarrival_dist_str); ack_msdu_size_dist_ptr = oms_dist_load_from_string (ack_msdu_size_ dist_str); /* Load the PDFs that will be used in computing the MSDUt Interarrival T imes and MSDU Sizes. */ unack_msdu_interarrival_dist_ptr = oms_dist_load_from_string (unack_msdu _interarrival_dist_str); unack_msdu_size_dist_ptr = oms_dist_load_from_string (unack_msdu_s ize_dist_str);

/* Make sure we have valid start and stop times, i.e. stop time is not e arlier than start time. */ if ((ack_stop_time <= ack_start_time) && (ack_stop_time != SC_INFINITE_T IME)) { /* Stop time is earlier than start time. Disable the source. */ ack_start_time = SC_INFINITE_TIME; /* Display an appropriate warning. */ op_prg_odb_print_major ("Warning from a Traffic source model:", "Although the ac knowledged generator is not disabled (start time is set to a finite value) a sto p time that is not later than the start time is specified.", "Disabling the a cknowledged generator.", OPC_NIL); } /* Make sure we have valid start and stop times, i.e. stop time is not e arlier than start time. */ if ((unack_stop_time <= unack_start_time) && (unack_stop_time != SC_INFI NITE_TIME)) { /* Stop time is earlier than start time. Disable the source. */ unack_start_time = SC_INFINITE_TIME; /* Display an appropriate warning. */ op_prg_odb_print_major ("Warning from a Traffic source model:", "Although the un acknowledged generator is not disabled (start time is set to a finite value) a s top time that is not later than the start time is specified.", "Disabling the u nacknowledged generator.", OPC_NIL); } /* Schedule a self interrupt that will indicate transition to next state */ if ((ack_start_time == SC_INFINITE_TIME) && (unack_start_time == SC_INFI NITE_TIME)) { op_intrpt_schedule_self (op_sim_time (), SC_STOP); //DISABL ED } else { op_intrpt_schedule_self (op_sim_time (), SC_START); //START . /* In this case, also schedule the interrupt for starting of the MSDU generation */ if (ack_start_time != SC_INFINITE_TIME) op_intrpt_schedule_self (ack_start_time, SC_GENERATE_ACK ); //ACK_MSDU_GENERATE if (unack_start_time != SC_INFINITE_TIME) op_intrpt_schedule_self (unack_start_time, SC_GENERATE_U NACK); //UNACK_MSDU_GENERATE /* In this case, also schedule the interrupt when we will stop generating */ /* MSDUs, unless we are configured to run until the end of the s imulation. */ if ((ack_stop_time != SC_INFINITE_TIME) && (unack_stop_time != S

C_INFINITE_TIME)) k_stop_time), SC_STOP); } }

{ op_intrpt_schedule_self (max_double (ack_stop_time, unac

wpan_print_parameters (); /* Stack tracing exit point */ FOUT; } /*------------------------------------------------------------------------------* Function: wpan_print_parameters * * Description: print the setting Traffic source parameters * * No parameters *-------------------------------------------------------------------------------*/ static void wpan_print_parameters() { /* Stack tracing enrty point */ FIN(wpan_print_parameters); if (enable_log) { printf ("|----- [MSDU GENERATION - NODE \"%s\"] -------------------------------------|\n", node_name); printf (" Acknowledged Traffic parameters:\n"); printf ("\t MSDU Interarival PDF : %s\n", ack_msdu_interarrival_ dist_str); printf ("\t MSDU Size PDF : %s\n", ack_msdu_size_dist_str ); if (ack_start_time == -1) { printf ("\t Start time : Infinity \n"); } else { printf ("\t Start time : %f\n", ack_start_time ); } if (ack_stop_time == -1) { printf ("\t Stop time : Infinity \n"); } else { printf ("\t Stop time : %f\n", ack_stop_time) ; } printf (" Unacknowledged Traffic parameters:\n"); printf ("\t MSDU Interarival PDF : %s\n", unack_msdu_interarriva l_dist_str); printf ("\t MSDU Size PDF : %s\n", unack_msdu_size_dist_s tr); if (unack_start_time == -1) { printf ("\t Start time : Infinity \n"); } else {

printf ("\t Start time me); } if (unack_stop_time == -1) { printf ("\t Stop time } else { printf ("\t Stop time e);

: %f\n", unack_start_ti

: Infinity \n"); : %f\n", unack_stop_tim

} if (dest_mac_address == -1) { printf (" Destination MAC Address : PAN_coordinator \n") ; } else if (dest_mac_address == 0xFFFF) { printf (" Destination MAC Address : Broadcast - %d (%#X) \n", dest_mac_address, dest_mac_address); } else { printf (" Destination MAC Address : %d (%#X)\n", dest_ma c_address, dest_mac_address); } printf ("|----------------------------------------------------------------------------|\n\n"); } /* Stack tracing exit point */ FOUT; } /*------------------------------------------------------------------------------* Function: wpan_ack_traffic_generate * * Description: creates a MSDU requiring acknowledge based on the MSDU generatio n * specifications of the source model and sends it to the lower layer. * * No parameters *-------------------------------------------------------------------------------*/ static void wpan_ack_traffic_generate() { Packet* msdu_ptr; int msdu_size; /* size in bits */ double next_intarr_time; /* interarrival time of next MSDU */ double abs_next_intarr_time; /* absolute interarrival time of next MSDU */ /* Stack tracing enrty point */ FIN (wpan_ack_traffic_generate); /* Generate a MSDU size outcome. */ msdu_size = (int) ceil (oms_dist_outcome (ack_msdu_size_dist_ptr)); /* 0 <= packet_size <= aMaxMACFrameSize_Bits (=(aMaxPHYPacketSize_Bits-M AC_HEADER_SIZE)) */

if (msdu_size > aMaxMACFrameSize_Bits) msdu_size = aMaxMACFrameSize_Bits; /* The size of generated MSDU is bigger than the maximum - the size is set to the maximum. */ if (msdu_size < 0) msdu_size = 0; /* We produce unformatted packets. Create one. */ msdu_ptr = op_pk_create (msdu_size); /* schedule next MSDU generation */ next_intarr_time = oms_dist_outcome (ack_msdu_interarrival_dist_ptr); /* Make sure that interarrival time is not negative. In that case it wil l be set to 0. */ if (next_intarr_time <0) next_intarr_time = 0.0; abs_next_intarr_time = op_sim_time () + next_intarr_time; /* Update the op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write packet generation statistics. */ (ack_msdus_sent_hndl, 1.0); (ack_msdus_sent_hndl, 0.0); (ack_bits_sent_hndl, (double) msdu_size); (ack_bits_sent_hndl, 0.0); (ack_bits_sent_hndlG, (double) msdu_size); (ack_bits_sent_hndlG, 0.0); (ack_msdu_size_hndl, (double) msdu_size); (ack_msdu_interarrival_time_hndl, next_intarr_time); (ack_msdus_hndl, 1.0); (ack_msdus_hndlG, 1.0);

app_sent_msdu_bits = app_sent_msdu_bits + (msdu_size/1000.0); app_sent_msdu_nbr = app_sent_msdu_nbr + 1; /* send the MSDU via the stream to the lower layer. op_pk_send (msdu_ptr, STRM_FROM_ACK_TO_MAC); */

if (enable_log) { printf (" [Node %s] t= %f -> Acknowledged MSDU (size = %d bits) was generated and sent to MAC layer.\n", node_name, op_sim_time(), msdu_size); } if ((abs_next_intarr_time <= ack_stop_time) || (ack_stop_time == SC_INFI NITE_TIME)) { ack_next_msdu_evh = op_intrpt_schedule_self (abs_next_intarr_tim e, SC_GENERATE_ACK); if (enable_log) { printf ("\t Next Acknowledged MSDU will be generated at %f\n\n", abs_next_intarr_time); } } /* Stack tracing exit point */ FOUT; } /*------------------------------------------------------------------------------

-* Function: wpan_unack_traffic_generate * * Description: creates a MSDU based on the MSDU generation * specifications of the source model and sends it to the lower layer. * * No parameters *-------------------------------------------------------------------------------*/ static void wpan_unack_traffic_generate() { Packet* msdu_ptr; int msdu_size; /* size in bits */ double next_intarr_time; /* interarrival time of next MSDU */ double abs_next_intarr_time; /* absolute interarrival time of next MSDU */ /* Stack tracing enrty point */ FIN (wpan_unack_traffic_generate); /* Generate a MSDU size outcome. */ msdu_size = (int) ceil (oms_dist_outcome (unack_msdu_size_dist_ptr)); /* 0 <= packet_size <= aMaxMACFrameSize_Bits (=(aMaxPHYPacketSize_Bits-M AC_HEADER_SIZE))*/ if (msdu_size > aMaxMACFrameSize_Bits) msdu_size = aMaxMACFrameSize_Bits; /* The size of generated MSDU is bigger than the maximum - the size is set to the maximum. */ if (msdu_size < 0) msdu_size = 0; /* We produce unformatted packets. Create one. */ msdu_ptr = op_pk_create (msdu_size); /* schedule next MSDU generation */ next_intarr_time = oms_dist_outcome (unack_msdu_interarrival_dist_ptr); /* Make sure that interarrival time is not negative. In that case it wil l be set to 0. */ if (next_intarr_time <0) next_intarr_time = 0.0; abs_next_intarr_time = op_sim_time () + next_intarr_time; /* Update the op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write op_stat_write packet generation statistics. */ (unack_msdus_sent_hndl, 1.0); (unack_msdus_sent_hndl, 0.0); (unack_bits_sent_hndl, (double) msdu_size); (unack_bits_sent_hndl, 0.0); (unack_bits_sent_hndlG, (double) msdu_size); (unack_bits_sent_hndlG, 0.0); (unack_msdu_size_hndl, (double) msdu_size); (unack_msdu_interarrival_time_hndl, next_intarr_time); (unack_msdus_hndl, 1.0); (unack_msdus_hndlG, 1.0);

app_sent_msdu_bits = app_sent_msdu_bits + (msdu_size/1000.0); app_sent_msdu_nbr = app_sent_msdu_nbr + 1; /* Send the MSDU via the stream to the lower layer. op_pk_send (msdu_ptr, STRM_FROM_UNACK_TO_MAC); */

if (enable_log) { printf (" [Node %s] t= %f -> Unacknowledged MSDU (size = %d bits ) was generated and sent to MAC layer.\n", node_name, op_sim_time(), msdu_size); } if ((abs_next_intarr_time <= unack_stop_time) || (unack_stop_time == SC_ INFINITE_TIME)) { unack_next_msdu_evh = op_intrpt_schedule_self (abs_next_intarr_t ime, SC_GENERATE_UNACK); if (enable_log) { printf ("\t Next Unacknowledged MSDU will be generated a t %f\n\n", abs_next_intarr_time); } } /* Stack tracing exit point */ FOUT; } /* End of Function Block */ /* Undefine optional tracing in FIN/FOUT/FRET */ /* The FSM has its own tracing code and the other */ /* functions should not have any tracing. #undef FIN_TRACING #define FIN_TRACING #undef FOUTRET_TRACING #define FOUTRET_TRACING #if defined (__cplusplus) extern "C" { #endif void p_wpan_packet_source_process (OP_SIM_CONTEXT_ARG_OPT); VosT_Obtype _op_p_wpan_packet_source_process_init (int * init_block_ptr) ; void _op_p_wpan_packet_source_process_diag (OP_SIM_CONTEXT_ARG_OPT); void _op_p_wpan_packet_source_process_terminate (OP_SIM_CONTEXT_ARG_OPT) ; VosT_Address _op_p_wpan_packet_source_process_alloc (VosT_Obtype, int); void _op_p_wpan_packet_source_process_svar (void *, const char *, void * *); #if defined (__cplusplus) } /* end of 'extern "C"' */ #endif

*/

/* Process model interrupt handling procedure */ void p_wpan_packet_source_process (OP_SIM_CONTEXT_ARG_OPT) { #if !defined (VOSD_NO_FIN) int _op_block_origin = 0; #endif FIN_MT (p_wpan_packet_source_process ()); { FSM_ENTER ("p_wpan_packet_source_process") FSM_BLOCK_SWITCH { /*--------------------------------------------------------*/ /** state (init) enter executives **/ FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "p_wpan_packe t_source_process [init enter execs]") FSM_PROFILE_SECTION_IN ("p_wpan_packet_source_pr ocess [init enter execs]", state0_enter_exec) { /* Initialization */ wpan_source_init (); /* Register the statistics that will be maintain ed by this model. */ ack_bits_sent_hndl = op_sta t_reg ("Traffic Source.Generated Acknowledged Traffic (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); ack_msdus_sent_hndl = op_stat_reg (" Traffic Source.Generated Acknowledged Traffic (MSDUs/sec)", OPC_STAT _INDEX_NONE, OPC_STAT_LOCAL); ack_msdu_size_hndl = op_sta t_reg ("Traffic Source.Size of the Acknowledged MSDU (bits)", OPC_STAT _INDEX_NONE, OPC_STAT_LOCAL); ack_msdu_interarrival_time_hndl = op_stat_reg (" Traffic Source.Acknowledged MSDU Interarrival Time (secs)", OPC_STAT_INDEX_N ONE, OPC_STAT_LOCAL); ack_msdus_hndl = op_stat_reg ("Traffic Source.Number of Generated Acknowledged MSDUs", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); unack_bits_sent_hndl = op_stat_reg ("Traffic Source.Generated Unacknowledged Traffic (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); unack_msdus_sent_hndl = op_stat_reg ("Traffic Source.Generated Unacknowledged Traffic (MSDUs/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); unack_msdu_size_hndl = op_stat_reg ("Traffic Source.Size of the Unacknowledged MSDU (bits)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); unack_msdu_interarrival_time_hndl = op_sta t_reg ("Traffic Source.Unacknowledged MSDU Interarrival Time (secs)", OPC_STAT _INDEX_NONE, OPC_STAT_LOCAL); unack_msdus_hndl

= op_stat_reg ("Traffic Source.Number of Generated Unacknowledged MSDUs", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); ack_bits_sent_hndlG = op_stat_reg ("Traffic Source.Generated Acknowledged Traffic (bits/sec)", OPC_STAT_INDEX_ NONE, OPC_STAT_GLOBAL); ack_msdus_hndlG = op_stat_reg (" Traffic Source.Number of Generated Acknowledged MSDUs", OPC_STA T_INDEX_NONE, OPC_STAT_GLOBAL); unack_bits_sent_hndlG = op_stat_reg ("Traffic Source.Generated Unacknowledged Traffic (bits/sec)", OPC_STAT_INDEX_N ONE, OPC_STAT_GLOBAL); unack_msdus_hndlG = op_stat_reg (" Traffic Source.Number of Generated Unacknowledged MSDUs", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL); } FSM_PROFILE_SECTION_OUT (state0_enter_exec) /** state (init) exit executives **/ FSM_STATE_EXIT_FORCED (0, "init", "p_wpan_packet_source_ process [init exit execs]") /** state (init) transition processing **/ FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", " ", "init", "idle", "tr_0", "p_wpan_packet_source_process [init -> idle : default / ]") /*--------------------------------------------------------*/

/** state (idle) enter executives **/ FSM_STATE_ENTER_UNFORCED (1, "idle", state1_enter_exec, "p_wpan_packet_source_process [idle enter execs]") /** blocking after enter executives of unforced state. * */ FSM_EXIT (3,"p_wpan_packet_source_process") /** state (idle) exit executives **/ FSM_STATE_EXIT_UNFORCED (1, "idle", "p_wpan_packet_sourc e_process [idle exit execs]") /** state (idle) transition processing **/ FSM_PROFILE_SECTION_IN ("p_wpan_packet_source_process [i dle trans conditions]", state1_trans_conds) FSM_INIT_COND (START) FSM_TEST_COND (DISABLED) FSM_DFLT_COND FSM_TEST_LOGIC ("idle") FSM_PROFILE_SECTION_OUT (state1_trans_conds) FSM_TRANSIT_SWITCH { FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "S TART", "", "idle", "generate", "tr_1", "p_wpan_packet_source_process [idle -> ge

nerate : START / ]") FSM_CASE_TRANSIT (1, 5, state5_enter_exec, ;, "D ISABLED", "", "idle", "stop", "tr_8", "p_wpan_packet_source_process [idle -> sto p : DISABLED / ]") FSM_CASE_TRANSIT (2, 1, state1_enter_exec, ;, "d efault", "", "idle", "idle", "tr_9", "p_wpan_packet_source_process [idle -> idle : default / ]") } /*--------------------------------------------------------*/

/** state (generate) enter executives **/ FSM_STATE_ENTER_UNFORCED (2, "generate", state2_enter_ex ec, "p_wpan_packet_source_process [generate enter execs]") /** blocking after enter executives of unforced state. * */ FSM_EXIT (5,"p_wpan_packet_source_process") /** state (generate) exit executives **/ FSM_STATE_EXIT_UNFORCED (2, "generate", "p_wpan_packet_s ource_process [generate exit execs]") /** state (generate) transition processing **/ FSM_PROFILE_SECTION_IN ("p_wpan_packet_source_process [g enerate trans conditions]", state2_trans_conds) FSM_INIT_COND (ACK_MSDU_GENERATE) FSM_TEST_COND ((1)) FSM_TEST_COND (STOP) FSM_TEST_LOGIC ("generate") FSM_PROFILE_SECTION_OUT (state2_trans_conds) FSM_TRANSIT_SWITCH { FSM_CASE_TRANSIT (0, 3, state3_enter_exec, ;, "A CK_MSDU_GENERATE", "", "generate", "ACK", "tr_4", "p_wpan_packet_source_process [generate -> ACK : ACK_MSDU_GENERATE / ]") FSM_CASE_TRANSIT (1, 4, state4_enter_exec, ;, "" , "", "generate", "UNACK", "tr_5", "p_wpan_packet_source_process [generate -> UN ACK : / ]") FSM_CASE_TRANSIT (2, 5, state5_enter_exec, ;, "S TOP", "", "generate", "stop", "tr_7", "p_wpan_packet_source_process [generate -> stop : STOP / ]") } /*--------------------------------------------------------*/

/** state (ACK) enter executives **/ FSM_STATE_ENTER_FORCED (3, "ACK", state3_enter_exec, "p_ wpan_packet_source_process [ACK enter execs]") FSM_PROFILE_SECTION_IN ("p_wpan_packet_source_pr ocess [ACK enter execs]", state3_enter_exec) { /* Generate and send an acknowledged MSDU (MAC F

rame Payload) */ wpan_ack_traffic_generate (); } FSM_PROFILE_SECTION_OUT (state3_enter_exec) /** state (ACK) exit executives **/ FSM_STATE_EXIT_FORCED (3, "ACK", "p_wpan_packet_source_p rocess [ACK exit execs]") /** state (ACK) transition processing **/ FSM_TRANSIT_FORCE (2, state2_enter_exec, ;, "default", " ", "ACK", "generate", "tr_2", "p_wpan_packet_source_process [ACK -> generate : d efault / ]") /*--------------------------------------------------------*/

/** state (UNACK) enter executives **/ FSM_STATE_ENTER_FORCED (4, "UNACK", state4_enter_exec, " p_wpan_packet_source_process [UNACK enter execs]") FSM_PROFILE_SECTION_IN ("p_wpan_packet_source_pr ocess [UNACK enter execs]", state4_enter_exec) { /* Generate and send an unacknowledged MSDU (MAC Frame Payload) */ wpan_unack_traffic_generate (); } FSM_PROFILE_SECTION_OUT (state4_enter_exec) /** state (UNACK) exit executives **/ FSM_STATE_EXIT_FORCED (4, "UNACK", "p_wpan_packet_source _process [UNACK exit execs]") /** state (UNACK) transition processing **/ FSM_TRANSIT_ONLY ((UNACK_MSDU_GENERATE), 2, state2_enter _exec, ;, UNACK, "UNACK_MSDU_GENERATE", "", "UNACK", "generate", "tr_6", "p_wpan _packet_source_process [UNACK -> generate : UNACK_MSDU_GENERATE / ]") /*--------------------------------------------------------*/

/** state (stop) enter executives **/ FSM_STATE_ENTER_UNFORCED (5, "stop", state5_enter_exec, "p_wpan_packet_source_process [stop enter execs]") FSM_PROFILE_SECTION_IN ("p_wpan_packet_source_pr ocess [stop enter execs]", state5_enter_exec) { /* When we enter into the "stop" state, it is th e time for us to */ /* stop generating traffic. We simply cancel the generation of the */ /* next MSDU (MAC frame payload) and go into a s ilent mode by not /* scheduling anything else. */

if (op_ev_valid (ack_next_msdu_evh) == OPC_TRUE) op_ev_cancel (ack_next_msdu_evh); if (op_ev_valid (unack_next_msdu_evh) == OPC_TRU E) op_ev_cancel (unack_next_msdu_evh); } FSM_PROFILE_SECTION_OUT (state5_enter_exec) /** blocking after enter executives of unforced state. * */ FSM_EXIT (11,"p_wpan_packet_source_process") /** state (stop) exit executives **/ FSM_STATE_EXIT_UNFORCED (5, "stop", "p_wpan_packet_sourc e_process [stop exit execs]") /** state (stop) transition processing **/ FSM_TRANSIT_MISSING ("stop") /*--------------------------------------------------------*/

} FSM_EXIT (0,"p_wpan_packet_source_process") } }

void _op_p_wpan_packet_source_process_diag (OP_SIM_CONTEXT_ARG_OPT) { /* No Diagnostic Block */ }

void _op_p_wpan_packet_source_process_terminate (OP_SIM_CONTEXT_ARG_OPT) { FIN_MT (_op_p_wpan_packet_source_process_terminate ()) /* No Termination Block */ Vos_Poolmem_Dealloc (op_sv_ptr); FOUT }

/* Undefine shortcuts to state variables to avoid */ /* syntax error in direct access to fields of */ /* local variable prs_ptr in _op_p_wpan_packet_source_process_svar function. */ #undef ack_start_time #undef ack_stop_time #undef ack_msdu_interarrival_dist_ptr #undef ack_msdu_size_dist_ptr #undef ack_msdu_interarrival_dist_str #undef ack_msdu_size_dist_str #undef unack_start_time #undef unack_stop_time #undef unack_msdu_interarrival_dist_ptr #undef unack_msdu_size_dist_ptr #undef unack_msdu_interarrival_dist_str #undef unack_msdu_size_dist_str #undef dest_mac_address #undef node_name #undef parent_id #undef enable_log #undef ack_bits_sent_hndl #undef ack_msdus_sent_hndl #undef ack_msdu_size_hndl #undef ack_msdu_interarrival_time_hndl #undef ack_bits_sent_hndlG #undef ack_msdus_hndl #undef ack_msdus_hndlG #undef unack_bits_sent_hndl #undef unack_msdus_sent_hndl #undef unack_msdu_size_hndl #undef unack_msdu_interarrival_time_hndl #undef unack_bits_sent_hndlG #undef unack_msdus_hndl #undef unack_msdus_hndlG #undef ack_next_msdu_evh #undef unack_next_msdu_evh #undef FIN_PREAMBLE_DEC #undef FIN_PREAMBLE_CODE #define FIN_PREAMBLE_DEC #define FIN_PREAMBLE_CODE VosT_Obtype _op_p_wpan_packet_source_process_init (int * init_block_ptr) { VosT_Obtype obtype = OPC_NIL; FIN_MT (_op_p_wpan_packet_source_process_init (init_block_ptr)) obtype = Vos_Define_Object_Prstate ("proc state vars (p_wpan_packet_sour ce_process)", sizeof (p_wpan_packet_source_process_state)); *init_block_ptr = 0; FRET (obtype) } VosT_Address _op_p_wpan_packet_source_process_alloc (VosT_Obtype obtype, int init_block) { #if !defined (VOSD_NO_FIN)

int _op_block_origin = 0; #endif p_wpan_packet_source_process_state * ptr; FIN_MT (_op_p_wpan_packet_source_process_alloc (obtype)) ptr = (p_wpan_packet_source_process_state *)Vos_Alloc_Object (obtype); if (ptr != OPC_NIL) { ptr->_op_current_block = init_block; #if defined (OPD_ALLOW_ODB) ptr->_op_current_state = "p_wpan_packet_source_process [init ent er execs]"; #endif } FRET ((VosT_Address)ptr) }

void _op_p_wpan_packet_source_process_svar (void * gen_ptr, const char * var_name, vo id ** var_p_ptr) { p_wpan_packet_source_process_state *prs_ptr; FIN_MT (_op_p_wpan_packet_source_process_svar (gen_ptr, var_name, var_p_ ptr)) if (var_name == OPC_NIL) { *var_p_ptr = (void *)OPC_NIL; FOUT } prs_ptr = (p_wpan_packet_source_process_state *)gen_ptr; if (strcmp ("ack_start_time" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_start_time); FOUT } if (strcmp ("ack_stop_time" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_stop_time); FOUT } if (strcmp ("ack_msdu_interarrival_dist_ptr" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_msdu_interarrival_dist_ptr) ; FOUT } if (strcmp ("ack_msdu_size_dist_ptr" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_msdu_size_dist_ptr); FOUT } if (strcmp ("ack_msdu_interarrival_dist_str" , var_name) == 0) { *var_p_ptr = (void *) (prs_ptr->ack_msdu_interarrival_dist_str); FOUT

} if (strcmp ("ack_msdu_size_dist_str" , var_name) == 0) { *var_p_ptr = (void *) (prs_ptr->ack_msdu_size_dist_str); FOUT } if (strcmp ("unack_start_time" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_start_time); FOUT } if (strcmp ("unack_stop_time" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_stop_time); FOUT } if (strcmp ("unack_msdu_interarrival_dist_ptr" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_msdu_interarrival_dist_pt r); FOUT } if (strcmp ("unack_msdu_size_dist_ptr" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_msdu_size_dist_ptr); FOUT } if (strcmp ("unack_msdu_interarrival_dist_str" , var_name) == 0) { *var_p_ptr = (void *) (prs_ptr->unack_msdu_interarrival_dist_str ); if FOUT } (strcmp ("unack_msdu_size_dist_str" , var_name) == 0) { *var_p_ptr = (void *) (prs_ptr->unack_msdu_size_dist_str); FOUT } (strcmp ("dest_mac_address" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->dest_mac_address); FOUT } (strcmp ("node_name" , var_name) == 0) { *var_p_ptr = (void *) (prs_ptr->node_name); FOUT } (strcmp ("parent_id" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->parent_id); FOUT } (strcmp ("enable_log" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->enable_log); FOUT } (strcmp ("ack_bits_sent_hndl" , var_name) == 0) {

if

if

if

if

if

*var_p_ptr = (void *) (&prs_ptr->ack_bits_sent_hndl); FOUT } if (strcmp ("ack_msdus_sent_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_msdus_sent_hndl); FOUT } if (strcmp ("ack_msdu_size_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_msdu_size_hndl); FOUT } if (strcmp ("ack_msdu_interarrival_time_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_msdu_interarrival_time_hndl ); if FOUT } (strcmp ("ack_bits_sent_hndlG" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_bits_sent_hndlG); FOUT } (strcmp ("ack_msdus_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_msdus_hndl); FOUT } (strcmp ("ack_msdus_hndlG" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_msdus_hndlG); FOUT } (strcmp ("unack_bits_sent_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_bits_sent_hndl); FOUT } (strcmp ("unack_msdus_sent_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_msdus_sent_hndl); FOUT } (strcmp ("unack_msdu_size_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_msdu_size_hndl); FOUT } (strcmp ("unack_msdu_interarrival_time_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_msdu_interarrival_time_hn

if

if

if

if

if

if dl);

FOUT } if (strcmp ("unack_bits_sent_hndlG" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_bits_sent_hndlG); FOUT }

if (strcmp ("unack_msdus_hndl" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_msdus_hndl); FOUT } if (strcmp ("unack_msdus_hndlG" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_msdus_hndlG); FOUT } if (strcmp ("ack_next_msdu_evh" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ack_next_msdu_evh); FOUT } if (strcmp ("unack_next_msdu_evh" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->unack_next_msdu_evh); FOUT } *var_p_ptr = (void *)OPC_NIL; FOUT }

S-ar putea să vă placă și