📄 trafbuild.ex.c
字号:
strcat (dir_name, file_name);
/* Create the file name to be created along with the */
/* directory path. */
dir_file_name = (char *) op_prg_mem_alloc (strlen (dir_name) + 1);
strcpy (dir_file_name, dir_name);
}
else
{
/* Unable to find primary model directory name. Create */
/* the file name to be created in the directory from */
/* where OPNET was started. */
dir_file_name = (char *)op_prg_mem_alloc (strlen (file_name) + 1);
strcpy (dir_file_name, file_name);
}
}
/* Create the file to contain IP interface informaiton and set */
/* a flag to restrict multiple file opens. */
file_ptr = fopen (dir_file_name, "w");
/* Return the file pointer. */
FRET (file_ptr);
}
static void
trafbuild_file_close (FILE *fp)
{
/** This procedure is responsible for closing the traffic file. **/
FIN (trafbuild_file_close (fp));
/* Close the traffic file. */
fclose (fp);
FOUT;
}
static void
trafbuild_notif_log_init (void)
{
int trafbuild_log_limit = 64;
static Boolean trafbuild_log_initialized = OPC_FALSE;
/** Initializes handles used for simulation notification **/
/** logging. Creates a log handle for each distinct tuple **/
/** (i.e., <Category, Class, Subclass>) -- these handles **/
/** are later used by the ATM models to log messages. **/
FIN (trafbuild_notif_log_init ());
/* Create log handles if not already created. */
if (trafbuild_log_initialized == OPC_FALSE)
{
/* Set flag to prevent re-initialization. */
trafbuild_log_initialized = OPC_TRUE;
/* If specified, obtain the values set for the maximum */
/* number of log entries on a per "category" basis. */
if (op_ima_sim_attr_exists (TRAFBUILDC_LOG_LIMIT))
op_ima_sim_attr_get (OPC_IMA_INTEGER, TRAFBUILDC_LOG_LIMIT, &trafbuild_log_limit);
/* Configuration related notification handles. */
trafbuild_log_handle = op_prg_log_handle_create (OpC_Log_Category_Configuration,
"Traffic Builder", "Configuration", trafbuild_log_limit);
}
FOUT;
}
static void
trafbuild_invalid_source_name_log_write (TrafbuildT_Specs_Info *specs_info_ptr, int index)
{
char *name_ptr;
/** This function writes a log indicating that the source **/
/** name has been specified incorrectly. **/
FIN (trafbuild_invalid_source_name_log_write (specs_info_ptr, index));
/* Determine the source/destination names. */
if (strcmp (specs_info_ptr->src_name, "default") == 0)
name_ptr = (char*) op_prg_mem_copy_create ("Unspecified", strlen ("Unspecified") + 1);
else
name_ptr = (char*) op_prg_mem_copy_create (specs_info_ptr->src_name, strlen (specs_info_ptr->src_name) + 1);
/* Write the notification log. */
op_prg_log_entry_write (trafbuild_log_handle,
"ERROR(S):\n"
" The following Traffic Builder specification is\n"
" invalid due to an invalid source name:\n"
" \n"
" Entry Number: %d\n"
" Source Name: %s\n"
"\n"
"REASON(S):\n"
" The source name was left as 'Unspecified'\n"
"\n"
"SUGGESTION(S):\n"
" Ensure that a source name is specified as\n"
" something other than 'Unspecified'.\n"
"\n"
"NOTE(S)\n"
" This Traffic Builder entry is BEING IGNORED.\n"
"\n",
index,
name_ptr);
/* Free memory. */
op_prg_mem_free (name_ptr);
FOUT;
}
static void
trafbuild_invalid_dest_name_log_write (TrafbuildT_Specs_Info *specs_info_ptr, int index)
{
char *name_ptr;
/** This function writes a log indicating that the source **/
/** name has been specified incorrectly. **/
FIN (trafbuild_invalid_dest_name_log_write (specs_info_ptr, index));
/* Determine the source/destination names. */
if (strcmp (specs_info_ptr->dst_name, "default") == 0)
name_ptr = (char*) op_prg_mem_copy_create ("Unspecified", strlen ("Unspecified") + 1);
else
name_ptr = (char*) op_prg_mem_copy_create (specs_info_ptr->dst_name, strlen (specs_info_ptr->dst_name) + 1);
/* Write the notification log. */
op_prg_log_entry_write (trafbuild_log_handle,
"ERROR(S):\n"
" The following Traffic Builder specification is\n"
" invalid due to an invalid destination name:\n"
" \n"
" Entry Number: %d\n"
" Destination Name: %s\n"
"\n"
"REASON(S):\n"
" The destination name was left as 'Unspecified'\n"
"\n"
"SUGGESTION(S):\n"
" Ensure that a destination name is specified as\n"
" something other than 'Unspecified'.\n"
"\n"
"NOTE(S)\n"
" This Traffic Builder entry is BEING IGNORED.\n"
"\n",
index,
name_ptr);
/* Free memory. */
op_prg_mem_free (name_ptr);
FOUT;
}
static void
trafbuild_invalid_start_end_times_log_write (TrafbuildT_Specs_Info *specs_info_ptr, int index)
{
char *src_name_ptr;
char *dst_name_ptr;
/** This function writes a log indicating that the source **/
/** name has been specified incorrectly. **/
FIN (trafbuild_invalid_dest_name_log_write (specs_info_ptr, index));
/* Determine the source/destination names. */
if (strcmp (specs_info_ptr->src_name, "default") == 0)
src_name_ptr = (char*) op_prg_mem_copy_create ("Unspecified", strlen ("Unspecified") + 1);
else
src_name_ptr = (char*) op_prg_mem_copy_create (specs_info_ptr->src_name, strlen (specs_info_ptr->src_name) + 1);
if (strcmp (specs_info_ptr->dst_name, "default") == 0)
dst_name_ptr = (char*) op_prg_mem_copy_create ("Unspecified", strlen ("Unspecified") + 1);
else
dst_name_ptr = (char*) op_prg_mem_copy_create (specs_info_ptr->dst_name, strlen (specs_info_ptr->dst_name) + 1);
/* Write the notification log. */
op_prg_log_entry_write (trafbuild_log_handle,
"ERROR(S):\n"
" The following Traffic Builder specification is\n"
" invalid due to an invalid start and end times:\n"
" \n"
" Entry Number: %d\n"
" Source Name: %s\n"
" Destination Name: %s\n"
" Start Time: %f\n"
" End Time: %f\n"
"\n"
"REASON(S):\n"
" The end time is less than or equal to the start\n"
" time.\n"
"\n"
"SUGGESTION(S):\n"
" Ensure that the end time is greater than the\n"
" start time.\n"
"\n"
"NOTE(S)\n"
" This Traffic Builder entry is BEING IGNORED.\n"
"\n",
index,
src_name_ptr,
dst_name_ptr,
specs_info_ptr->start_time,
specs_info_ptr->end_time);
/* Free memory. */
op_prg_mem_free (src_name_ptr);
op_prg_mem_free (dst_name_ptr);
FOUT;
}
/**************** Internal functions ****************/
char *
trafbuild_hierarchical_name_get (Objid obj)
{
Objid cur_obj;
char* result_str;
char* name_str;
Prg_List* parent_lptr;
int full_name_len = 0;
int list_size;
int i;
char object_name [255];
/** PURPOSE: Returns the hierarchical name of the object in a newly **/
/** allocated block. This name does not include the top subnet. **/
/** **/
/** REQUIRES: The object is a valid object. **/
/** **/
/** EFFECTS: Caller takes ownership of RESULT. **/
/** In the event of an error, RESULT == PRGC_NIL. **/
/** In the event the top subnet is passed in, RESULT == empty string **/
FIN (trafbuild_hierarchical_name_get (obj));
/* The current object at the beginning will be the object handle passed in. */
cur_obj = obj;
/* Create the list that will store all of the parts of the hierarchical name */
/* This list will then be traveresed to create the whole name. By doing this */
/* the length of the resulting name can be determined and the proper amount of */
/* memory can be dynamically allocated. */
parent_lptr = prg_list_create ();
if (parent_lptr == PRGC_NIL)
{
FRET (PRGC_NIL);
}
/* Go through the parent of each object and insert the name of each at the end */
/* of the list. When PRGC_NIl is returned the top has been reached and the */
/* list can be used to form the full name. */
while (cur_obj != OPC_OBJID_NULL)
{
/* Retrieve the name of the current subnet */
op_ima_obj_attr_get (cur_obj, "name", object_name);
/* Allocate memory for object name. */
name_str = (char*) prg_mem_alloc (sizeof (char) * (strlen (object_name) + 1));
strcpy (name_str, object_name);
/* Insert the new element at the head of the list of names. */
prg_list_insert (parent_lptr, name_str, PRGC_LISTPOS_HEAD);
/* Add the size of the current name to the full name length plus one for */
/* period between names. This will be used later to allocated the proper */
/* amount of space for the hierarchical name. */
full_name_len += ( strlen (name_str) + 1);
/* Get the parent of this object so that the next part of the name can be */
/* retrieved. */
cur_obj = op_topo_parent (cur_obj);
}
/* The top subnet should not be part of the name therefore we need to remove */
/* it from the list of names before forming the final name. */
prg_list_remove (parent_lptr, PRGC_LISTPOS_HEAD);
/* Recalculate the name length as top is not part of the name. */
full_name_len -= 4;
/* If the full_name_len is equal to zero, the top subnet was passed in. */
/* one space for an empty string. */
if (full_name_len == 0)
full_name_len++;
/* Allocate space for the hierarchical name based on the length of all parts of */
/* the name including the period between the parts. */
result_str = (char *) prg_mem_alloc (full_name_len);
/* Print an error message and return an error if no space could be allocated. */
/* for the name. */
if (result_str == PRGC_NIL)
{
FRET (PRGC_NIL);
}
/* Initialize the string to be empty. */
*result_str = '\0';
/* Go through the list from the beginning adding each elemnt of the list to the */
/* full hierarchical name. At the end of this loop the name is complete. */
list_size = prg_list_size (parent_lptr);
/* Build the string based on the list of parent names. */
for (i = 0; i < list_size; i++)
{
name_str = prg_list_remove (parent_lptr, OPC_LISTPOS_HEAD);
/* Prepend the dot only when this is not the first part of the name. */
if (i != 0)
strcat (result_str, ".");
strcat (result_str, name_str);
/* Free element in list. */
prg_mem_free (name_str);
}
/* The parent_list is no longer used, therefore free up all the memory in use */
/* by the list. */
prg_list_free (parent_lptr);
FRET (result_str);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -