⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpip_bench.c

📁 ST for linux SDK采用的tcp/ip协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************/
/*                                                                            */
/* File name   : TCPIP_BENCH.C                                                */
/*                                                                            */
/* Description : TCPIP Bench Debug                                            */
/*                                                                            */
/* COPYRIGHT (C) ST-Microelectronics 2005                                     */
/*                                                                            */
/* Date               Modification                 Name                       */
/* ----               ------------                 ----                       */
/* 02/03/05           Created                      M.CHAPPELLIER              */
/*                                                                            */
/******************************************************************************/
/* This TCPIP bench tool is reading packets and sending packets to a server   */
/* The server is managed by a java application running on the server side     */
/* You will find the .jar server code in stdebug/tcpip/tcpip_bench_server.jar */
/* This is a part of the OS+ example which is there... Integration of the     */
/* bench in STSDK as an advantage in a sense that it could be used also for   */
/* linux.                                                                     */
/* We absolutely recommand you to perform this test using a direct connection */
/* between the platform and the server, please avoid switch or hubs           */
/* It's because typically switchs have the capability to request to slow down */
/* read/write transfers to avoid overflows in its internal buffers            */
/* This control which is called the "Spanning tree", look for it on google    */
 
/* Includes */
/* -------- */
#include "stapp_main.h"
#include "stdebug_main.h"                 
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
#if defined(TCPIP_STACK_NEXGEN)
#include <ngsocket.h>
#endif
#endif

/* Local definitions */
/* ----------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
#define BUFFER_SIZE        0x10000
#define MINIMUM_PORT       1
#define MAXIMUM_PORT       65535
#define MINIMUM_DATASIZE   1
#define MAXIMUM_DATASIZE   0xFFFFFFFF
#define MINIMUM_PACKETSIZE 64
#define MAXIMUM_PACKETSIZE 64536
#define MINIMUM_ITERATIONS 1
#endif

/* Keep track of the best transfer rates */
/* ------------------------------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
typedef struct bps_statistics_s 
{
 double bsf; /* Best measure      */
 double wsf; /* Worst measure     */
 double cum; /* Cumul of measures */
 double avg; /* Average measure   */
 U32    iterations;
} bps_statistics_t;
#endif

/* Local variables */
/* --------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
static char             server_ip[40];
static U32              server_port;
static U32              data_size;
static U32              packet_size;
static U32              iterations;
static bps_statistics_t read_statistics,send_statistics;
#endif

/* Local prototypes */
/* ---------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
static int  TCPIPi_Read_Str_Token   (U32 sock_desc,char *token,U32 size);
static int  TCPIPi_Read_Exp_Token   (U32 sock_desc,char *expected);
static int  TCPIPi_Send_Str_Token   (U32 sock_desc,char *token);
static int  TCPIPi_Send_Int_Token   (U32 sock_desc,U32   value);
static int  TCPIPi_Read_Data        (U32 sock_desc,U32   data_size,U32 packet_size);
static int  TCPIPi_Send_Data        (U32 sock_desc,U32   data_size,U32 packet_size);
static void TCPIPi_Update_Statistics(U32 start_time,double data_size,bps_statistics_t *stats,char *direction);
#endif

/* ========================================================================
   Name:        TT_TCPIP_Bench
   Description: Perform a benchmark of the tcpip interface
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
BOOL TT_TCPIP_Bench(parse_t *pars_p,char *result)
{
 S32    ID;
 U32    sock_desc,i,timeout;
 struct sockaddr_in sock_addr;

 /* Get the bench parameters */
 /* ======================== */
 
 /* Get Ethernet Identifier */
 /* ----------------------- */
 if (cget_integer(pars_p,0,&ID)==TRUE)
  {
   tag_current_line(pars_p,"Invalid ethernet ID, should be [0,1,..]");
   return(TRUE);
  }
 if (ID>=TCPIP_MAX_NUMBER)
  {
   print("--> Invalid ethernet ID, should be [0,1,..] !\n");
   return(TRUE);
  }

 /* Get the server ip address */
 /* ------------------------- */
 if (cget_string(pars_p,"192.168.0.100",server_ip,sizeof(server_ip))==TRUE)
  {
   tag_current_line(pars_p,"Invalid server ip address, should be [\"192.168.0.100\"]");
   return(TRUE);
  }
  
 /* Get the server port */
 /* ------------------- */
 if (cget_integer(pars_p,1234,(S32 *)&server_port)==TRUE)
  {
   tag_current_line(pars_p,"Invalid server port, should be [1,65535]");
   return(TRUE);
  }
 if ((server_port<MINIMUM_PORT)||(server_port>MAXIMUM_PORT))
  {
   print("--> Invalid server port, should be [1,65535] !\n");
   return(TRUE);
  }

 /* Get the data size */
 /* ----------------- */
 if (cget_integer(pars_p,40*1024*1024,(S32 *)&data_size)==TRUE)
  {
   tag_current_line(pars_p,"Invalid data size, should be [1,..]");
   return(TRUE);
  }
 if ((data_size<MINIMUM_DATASIZE)||(data_size>MAXIMUM_DATASIZE))
  {
   print("--> Invalid data size, should be [1,..] !\n");
   return(TRUE);
  }

 /* Get the packet size */
 /* ------------------- */
 if (cget_integer(pars_p,(7*188)+42,(S32 *)&packet_size)==TRUE)
  {
   tag_current_line(pars_p,"Invalid packet size, should be [64,64536]");
   return(TRUE);
  }
 if ((packet_size<MINIMUM_PACKETSIZE)||(packet_size>MAXIMUM_PACKETSIZE))
  {
   print("--> Invalid packet size, should be [64,64536] !\n");
   return(TRUE);
  }

 /* Get the nb of iterations */
 /* ------------------------ */
 if (cget_integer(pars_p,10,(S32 *)&iterations)==TRUE)
  {
   tag_current_line(pars_p,"Invalid nb of iterations, should be [1,..]");
   return(TRUE);
  }
 if (iterations<MINIMUM_ITERATIONS)
  {
   print("--> Invalid nb of iterations, should be [1,..] !\n");
   return(TRUE);
  }

 /* Connect to the TCP bandwidth server */
 /* =================================== */
 print("You need first to run the java application server in order to perfom this ip bench.   \n");
 print("The java application is available in $STSDKROOT/stdebug/tcpip/tcpip_bench_server.jar  \n");
 print("When the java is started, just click on the TCP Bandwith tab and click on the start   \n");
 print("button (the one which is on the right position) in the server area.                   \n");
 print("Please note that the bench performed is using the tcp/ip stack, so this is worst case \n");
 print("as we bypass the stack when video decode.                                             \n");
 print("We absolutely recommand you to connect directly the board on the server to have       \n");
 print("consistent results. Please do not use switchs or hub in between the board and the java\n");
 print("server. In fact ethernet switches have the capability to request to slow down the     \n");
 print("read/writes transfers to avoid to overflow its internal circular buffers....          \n");
 print("This mechanism is called the \"Spanning tree\", look for it on Google...              \n\n");
 print("Server      = %s:%d\n",server_ip,server_port);
 print("Data size   = %d\n",data_size);
 print("Packet size = %d\n",packet_size);
 print("Iterations  = %d\n\n",iterations);

 /* Create the socket descriptor */
 /* ---------------------------- */
 if ((sock_desc=socket(AF_INET,SOCK_STREAM,0))==-1)
  {
   print("--> Failed to create socket,errno=%d !\n",errno);
   return(TRUE);
  }

 /* Setup the socket address structure */
 /* ---------------------------------- */
 memset(&sock_addr,0,sizeof(sock_addr));
 sock_addr.sin_family = AF_INET;
#if !defined(ST_OSLINUX)
 sock_addr.sin_len    = sizeof(sock_addr);
#endif
 sock_addr.sin_port   = htons(server_port);

 /* Set the socket address to connect to */
 /* ------------------------------------ */
#if !defined(ST_OSLINUX)
 if (inet_aton(server_ip,&sock_addr.sin_addr.s_addr)==0)
#else
 if (inet_aton(server_ip,&sock_addr.sin_addr)==0)
#endif
  {
   print("--> Invalid server address, errno=%d !\n",errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }
 print("Connecting to server %s on port %d...\n",server_ip,server_port);

 /* Connect to the TCP bandwidth server */
 /* ----------------------------------- */
 timeout=0;
 while((connect(sock_desc,(struct sockaddr *)&sock_addr,sizeof(sock_addr))==-1)&&(timeout<10))
  {
   timeout++;
   print("--> Connection failed, try again in one second %d/10 !\n",timeout);
   Task_Delay(ST_GetClocksPerSecond());
  }
 if (timeout==10)
  {
   print("--> Unable to connect to the server !\n");
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Handshake with the TCP bandwidth server */
 /* ======================================= */
 print("Handshaking with TCP bandwidth server...\n");

 /* Send 'ready' token to the socket */
 /* -------------------------------- */
 if (TCPIPi_Send_Str_Token(sock_desc,"ready")==-1)
  {
   print("--> Failed to send 'ready' token, errno=%d !\n",errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Read 'ready' token back from the socket */
 /* --------------------------------------- */
 if (TCPIPi_Read_Exp_Token(sock_desc,"ready")==-1)
  {
   print("--> Failed to read 'ready' token,errno=%d !\n",errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Send 'parameters' token to the socket */
 /* ------------------------------------- */
 if (TCPIPi_Send_Str_Token(sock_desc,"parameters")==-1)
  {
   print("--> Failed to send 'parameters' token, errno=%d !\n",errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Read 'data size' token back from the socket */
 /* ------------------------------------------- */
 if (TCPIPi_Read_Exp_Token(sock_desc,"data size")==-1)
  {
   print("--> Failed to read 'data size' token, errno=%d !\n",errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Send the data size to the socket */
 /* -------------------------------- */
 if (TCPIPi_Send_Int_Token(sock_desc,data_size)==-1)
  {
   print("--> Failed to send data size, errno=%d !\n", errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Read 'packet size' token back from the socket */
 /* --------------------------------------------- */
 if (TCPIPi_Read_Exp_Token(sock_desc,"packet size")==-1)
  {
   print("--> Failed to read 'packet size' token, errno=%d !\n",errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Send the packet size to the socket */
 /* ---------------------------------- */
 if (TCPIPi_Send_Int_Token(sock_desc,packet_size)==-1)
  {
   print("--> Failed to send packet size, errno=%d !\n",errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Read 'iterations' token back from the socket */
 /* -------------------------------------------- */
 if (TCPIPi_Read_Exp_Token(sock_desc,"iterations")==-1)
  {
   print("--> Failed to read 'iterations' token, errno=%d !\n",errno);
#if defined(ST_OSLINUX)
   close(sock_desc);
#else
   closesocket(sock_desc);
#endif
   return(TRUE);
  }

 /* Send the iterations to the socket */
 /* --------------------------------- */
 if (TCPIPi_Send_Int_Token(sock_desc,iterations)==-1)
  {
   print("--> Failed to send iterations, errno=%d !\n",errno);
   return(TRUE);
  }

 /* Read 'ok' token back from the socket */
 /* ------------------------------------ */
 if (TCPIPi_Read_Exp_Token(sock_desc,"ok")==-1)
  {
   print("--> Failed to read 'ok' token, errno=%d !\n",errno);
   return(TRUE);
  }
 print("Connected to server...\n\n");

 /* Clear the statistics */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -