📄 trafbuild.ex.c
字号:
/* trafbuild.ex.c: */
/* Traffic Builder package */
/****************************************/
/* Copyright (c) 1987 - 2000 */
/* by OPNET Technologies, Inc. */
/* (A Delaware Corporation) */
/* 3400 International Drive, N.W. */
/* Washington, D.C., U.S.A. */
/* All Rights Reserved. */
/****************************************/
/* Define symbolic constant for export. */
#define TRAFBUILDC_EXPORT DLLEXPORT
/* ---- (SECTION_INC) Include Directives ---- */
#include "opnet.h"
#include "trafbuild.h"
#include <string.h>
#include <stdio.h>
/* ---- (SECTION_GD) Global Data ---- */
Log_Handle trafbuild_log_handle;
/* ---- (SECTION_ECP) Externally Callable Procedures ---- */
char * trafbuild_hierarchical_name_get (Objid obj);
TRAFBUILDC_EXPORT extern List*
trafbuild_specs_parse (double *start_time_ptr, double *end_time_ptr)
{
Objid conv_objid;
double sim_duration;
List *specs_list_ptr;
int specs_count;
int i, x, y;
TrafbuildT_Specs_Info *specs_info_ptr;
Objid specs_objid;
Objid temp_objid, node;
char temp_str [128];
Boolean valid_spec;
char *modelNames[32767], *src[1000], *dest[1000];
/** This procedure is responsible for parsing the conversation **/
/** specification information. **/
FIN (trafbuild_specs_parse (start_time_ptr, end_time_ptr));
/* Initialize the notification log. */
trafbuild_notif_log_init ();
/* Obtain the conversation information object ID. */
op_ima_obj_attr_get (op_id_self (), "Traffic Information", &conv_objid);
/* Obtain the simulation duration. */
sim_duration = 3600.0;
if (op_ima_sim_attr_exists ("duration") == OPC_TRUE)
op_ima_sim_attr_get (OPC_IMA_DOUBLE, "duration", &sim_duration);
/* Initialize the start and end time parameters. */
*start_time_ptr = OPC_DBL_INFINITY;
*end_time_ptr = 0.0;
/* Create the specification list. */
specs_list_ptr = op_prg_list_create ();
/* Obtain a specification count. */
specs_count = op_topo_child_count (conv_objid, OPC_OBJTYPE_GENERIC);
/*cache all model names for speedier reading*/
for (x = 0; x < op_topo_object_count (OPC_OBJMTYPE_NODE); x++)
{
modelNames[x] = (char *)malloc (255);
node = op_topo_object (OPC_OBJMTYPE_NODE, x);
op_ima_obj_attr_get (node, "model", modelNames[x]);
}
/*cache rule dest and src model types*/
for (i = 0; i < specs_count; i++)
{
/* Access the ith specification information. */
specs_objid = op_topo_child (conv_objid, OPC_OBJTYPE_GENERIC, i);
/* Read in the source information. */
src[i] = (char *)malloc (255);
dest[i] = (char *)malloc (255);
op_ima_obj_attr_get (specs_objid, "Source Name", src[i]);
op_ima_obj_attr_get (specs_objid, "Destination Name", dest[i]);
}
/*search node by node for rule matches*/
for (x = 0; x < op_topo_object_count (OPC_OBJMTYPE_NODE); x++)
{
for (i = 0; i < specs_count; i++)
{
if (!strcmp (modelNames[x], src[i]))
{
/* source match. Loop through all nodes and find dest matches*/
for (y = 0; y < op_topo_object_count (OPC_OBJMTYPE_NODE); y++)
{
if ((!strcmp (modelNames[y], dest[i])) && x != y)
{
/*match. Add to list*/
/* Place the specification information on the list. */
/* Access the ith specification information. */
valid_spec = OPC_TRUE;
specs_objid = op_topo_child (conv_objid, OPC_OBJTYPE_GENERIC, i);
/* Allocate memory to hold the specification information. */
specs_info_ptr = (TrafbuildT_Specs_Info*) op_prg_mem_alloc (sizeof (TrafbuildT_Specs_Info));
strcpy (specs_info_ptr->src_name, trafbuild_hierarchical_name_get(op_topo_object (OPC_OBJMTYPE_NODE, x)));
strcpy (specs_info_ptr->dst_name, trafbuild_hierarchical_name_get(op_topo_object (OPC_OBJMTYPE_NODE, y)));
/* Read in the traffic volume information. */
op_ima_obj_attr_get (specs_objid, "Traffic Volume", temp_str);
specs_info_ptr->bps_dist_handle = oms_dist_load_from_string (temp_str);
/* Read in the packet size information. */
op_ima_obj_attr_get (specs_objid, "Packet Size", temp_str);
specs_info_ptr->pksize_dist_handle = oms_dist_load_from_string (temp_str);
/* Read in the interval information. */
op_ima_obj_attr_get (specs_objid, "Interval", temp_str);
specs_info_ptr->int_dist_handle = oms_dist_load_from_string (temp_str);
/* Read in the duration information. */
op_ima_obj_attr_get (specs_objid, "Duration Information", &temp_objid);
temp_objid = op_topo_child (temp_objid, OPC_OBJTYPE_GENERIC, 0);
op_ima_obj_attr_get (temp_objid, "Start Time", &specs_info_ptr->start_time);
op_ima_obj_attr_get (temp_objid, "End Time", &specs_info_ptr->end_time);
if (specs_info_ptr->end_time == -1.0)
specs_info_ptr->end_time = sim_duration;
if (specs_info_ptr->start_time >= specs_info_ptr->end_time)
{
/* Write a simulation log message. */
trafbuild_invalid_start_end_times_log_write (specs_info_ptr, i);
/* Set a flag to ignore this entry. */
valid_spec = OPC_FALSE;
}
if (valid_spec == OPC_TRUE)
{
/* Insert the specs information in the list. */
op_prg_list_insert (specs_list_ptr, specs_info_ptr, OPC_LISTPOS_TAIL);
/* Set the start time and end time parameters. */
if (specs_info_ptr->start_time < *start_time_ptr)
*start_time_ptr = specs_info_ptr->start_time;
if ((specs_info_ptr->end_time > *end_time_ptr) && (specs_info_ptr->end_time <= sim_duration))
*end_time_ptr = specs_info_ptr->end_time;
}
else
{
/* Free up the unnecessary memory. */
op_prg_mem_free (specs_info_ptr);
}
}
}
}
}
}
/* Set the final start and end times. */
if (*start_time_ptr == OPC_DBL_INFINITY)
*start_time_ptr = 0.0;
if (*end_time_ptr == 0.0)
*end_time_ptr = sim_duration;
FRET (specs_list_ptr);
}
TRAFBUILDC_EXPORT extern void
trafbuild_specs_write (List *specs_list_ptr, double time_origin, double time_end)
{
FILE *fp;
int conv_count;
int i;
TrafbuildT_Specs_Info *specs_info_ptr;
double interval;
double start_sec, end_sec;
double packets_sec, bits_sec;
double pksize;
/** This procedure is responsible for writing out the **/
/** conversation specification information to the traffic file. **/
FIN (trafbuild_file_write (fp, start_time, end_time));
/* Open the traffic file for writing. */
fp = trafbuild_file_open ();
/* Print header information. */
fprintf (fp, "time_origin: %f\n", time_origin);
fprintf (fp, "time_end: %f\n", time_end);
fprintf (fp, "traffic:\n");
fprintf (fp, "source,destination,start_sec,end_sec,bits_sec,packets_sec\n");
/* Print out conversation information. */
conv_count = op_prg_list_size (specs_list_ptr);
for (i = 0; i < conv_count; i++)
{
/* Access the ith conversation. */
specs_info_ptr = (TrafbuildT_Specs_Info*) op_prg_list_access (specs_list_ptr, i);
/* Compute the interval. */
interval = oms_dist_outcome (specs_info_ptr->int_dist_handle);
/* Write conversation information. */
for (start_sec = specs_info_ptr->start_time; start_sec < specs_info_ptr->end_time; start_sec += interval)
{
/* Determine the traffic volume information. */
bits_sec = oms_dist_outcome (specs_info_ptr->bps_dist_handle);
/* Determine the packet size information. */
pksize = oms_dist_outcome (specs_info_ptr->pksize_dist_handle);
/* Compute the packets per second information. */
packets_sec = bits_sec / pksize;
/* Determine the end seconds. */
end_sec = start_sec + interval;
if (end_sec > specs_info_ptr->end_time)
end_sec = specs_info_ptr->end_time;
/* Write out information. */
fprintf (fp, "%s,%s,%f,%f,%f,%f\n", specs_info_ptr->src_name, specs_info_ptr->dst_name,
start_sec, end_sec, bits_sec, packets_sec);
}
}
/* Close the traffic file. */
trafbuild_file_close (fp);
FOUT;
}
/* ---- (SECTION_ICP) Internally Callable Procedures ---- */
static FILE*
trafbuild_file_open (void)
{
char file_name [256];
char model_name [128];
Boolean dir_name_obtained;
char new_file_name [128];
char dir_name [256];
char *dir_file_name;
FILE *file_ptr;
/** This procedure is responsible for opening the traffic file **/
/** for writing. It will obtain the file name from the **/
/** attribute. In the event the filename is left as default, **/
/** the filaname used will be that of the project-scenario. **/
FIN (trafbuild_file_open ());
/* Obtain the file name. */
op_ima_obj_attr_get (op_id_self (), "Traffic Filename", file_name);
/* Check if the filename is set as default. */
if (strcmp (file_name, "default") == 0)
{
/* Obtain the model name for which the packet capture needs */
/* to be performed. */
op_ima_sim_attr_get (OPC_IMA_STRING, "net_name", model_name);
/* Create the file name to contain IP address information. */
sprintf (new_file_name, model_name);
strcat (new_file_name, "-traffic.tr2");
/* Obtain the primary model directory so that a file could */
/* be opened there. */
dir_name_obtained = oms_tan_primary_model_dir_name_get (dir_name);
if (dir_name_obtained == OPC_TRUE)
{
/* Append the file to be opened to the directory where */
/* it should be created. */
strcat (dir_name, "/");
strcat (dir_name, new_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 (new_file_name) + 1);
strcpy (dir_file_name, new_file_name);
}
}
else
{
/* A specific file name has been provided. Obtain the */
/* primary model directory so that a file could be */
/* opened there. */
dir_name_obtained = oms_tan_primary_model_dir_name_get (dir_name);
if (dir_name_obtained == OPC_TRUE)
{
/* Append the file to be opened to the directory where */
/* it should be created. */
strcat (dir_name, "/");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -