📄 noncopytcptestee.c
字号:
/*
* ============================================================
* (c) Copyright 2007 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
* ============================================================
* Automated Revision Information
* Changed: $Date: 2007-10-15 15:13:14 -0700 (Mon, 15 Oct 2007) $
* Revision: $Revision: 4244 $
*/
/*
* ======== nonCopyTestee.c ========
*
* Non-Copy TCP Testee benchmark application
*/
#include <stdio.h>
#include <netmain.h>
#include <_stack.h>
#include <std.h>
#include <mem.h>
#include <gbl.h>
#include <sys.h>
#include <tsk.h>
#ifdef _64P_
#include <bcache.h>
#else // EVM DM642
#include <csl.h>
#include <csl_cache.h>
#endif
#include <thrload.h>
#include "nonCopyTCP.h"
//---------------------------------------------------------------------------
// Title String
//
char *VerStr = "\nNon-Copy TCP Testee Benchmark\n";
// Our NETCTRL callback functions
static void NetworkOpen();
static void NetworkClose();
static void NetworkIPAddr( IPN IPAddr, uint IfIdx, uint fAdd );
// Fun reporting function
static void ServiceReport( uint Item, uint Status, uint Report, HANDLE hCfgEntry );
// Define the servers functions
static int dtask_tcp_transmit_srv( SOCKET s, UINT32 unused );
static int dtask_tcp_receive_srv( SOCKET s, UINT32 unused );
//---------------------------------------------------------------------------
// External references
//
extern TSK_Obj TSK_idle;
//---------------------------------------------------------------------------
// Configuration
//
char *HostName = "tidsp";
char *LocalIPMask = "255.255.254.0"; // Not used when using DHCP
char *GatewayIP = "0.0.0.0"; // Not used when using DHCP
char *DomainName = "benchmark.net"; // Not used when using DHCP
char *DNSServer = "0.0.0.0"; // Used when set to anything but zero
/* Static IP address */
char *LocalIPAddr = TESTEE_IPADDR_STRING;
Bool flag = FALSE;
Int loop = BENCH_FRAMES/2;
THRLOAD_tskEnvHandle idleEnv;
UINT8 DHCP_OPTIONS[] = { DHCPOPT_SERVER_IDENTIFIER, DHCPOPT_ROUTER };
//---------------------------------------------------------------------
// Main Entry Point
//---------------------------------------------------------------------
int main()
{
Bool rc;
#ifdef _64P_
/* Setup cache for C64P devices */
BCACHE_setSize (&bcacheSize);
#else // EVM DM642
/* Setup cache using CSL */
CACHE_setL2Mode(l2CacheSize);
#endif
/* Initialize the THRLOAD module */
THRLOAD_init();
/* Allocate THRLOAD task environment handle for the idle task. */
idleEnv = MEM_calloc(0, sizeof(THRLOAD_tskEnvObj), 0);
/*
* Add the idle task which is executed whenever no other threads wants to
* to THRLOAD so that we can measure relative time spent doing "nothing".
*/
rc = THRLOAD_add(&TSK_idle, idleEnv);
if (rc == FALSE) {
SYS_abort("Failed to register idle task");
}
}
//
// Main Thread
//
int StackTest()
{
int rc;
HANDLE hCfg;
//
// THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!!
//
rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
if( rc )
{
printf("NC_SystemOpen Failed (%d)\n",rc);
for(;;);
}
// Print out our banner
printf(VerStr);
//
// Create and build the system configuration from scratch.
//
// Create a new configuration
hCfg = CfgNew();
if( !hCfg )
{
printf("Unable to create configuration\n");
goto main_exit;
}
// We better validate the length of the supplied names
if( strlen( DomainName ) >= CFG_DOMAIN_MAX ||
strlen( HostName ) >= CFG_HOSTNAME_MAX )
{
printf("Names too long\n");
goto main_exit;
}
// Add our global hostname to hCfg (to be claimed in all connected domains)
CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
strlen(HostName), (UINT8 *)HostName, 0 );
// If the IP address is specified, manually configure IP and Gateway
if( inet_addr(LocalIPAddr) )
{
CI_IPNET NA;
CI_ROUTE RT;
IPN IPTmp;
// Setup manual IP address
bzero( &NA, sizeof(NA) );
NA.IPAddr = inet_addr(LocalIPAddr);
NA.IPMask = inet_addr(LocalIPMask);
strcpy( NA.Domain, DomainName );
NA.NetType = 0;
// Add the address to interface 1
CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0,
sizeof(CI_IPNET), (UINT8 *)&NA, 0 );
// Add the default gateway. Since it is the default, the
// destination address and mask are both zero (we go ahead
// and show the assignment for clarity).
bzero( &RT, sizeof(RT) );
RT.IPDestAddr = 0;
RT.IPDestMask = 0;
RT.IPGateAddr = inet_addr(GatewayIP);
// Add the route
CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0,
sizeof(CI_ROUTE), (UINT8 *)&RT, 0 );
// Manually add the DNS server when specified
IPTmp = inet_addr(DNSServer);
if( IPTmp )
CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 );
}
// Else we specify DHCP
else
{
CI_SERVICE_DHCPC dhcpc;
// Specify DHCP Service on IF-1
bzero( &dhcpc, sizeof(dhcpc) );
dhcpc.cisargs.Mode = CIS_FLG_IFIDXVALID;
dhcpc.cisargs.IfIdx = 1;
dhcpc.cisargs.pCbSrv = &ServiceReport;
dhcpc.param.pOptions = DHCP_OPTIONS;
dhcpc.param.len = 2;
CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0,
sizeof(dhcpc), (UINT8 *)&dhcpc, 0 );
}
//
// Configure IPStack/OS Options
//
// We don't want to see debug messages less than WARNINGS
rc = DBG_WARN;
CfgAddEntry( hCfg, CFGTAG_OS, CFGITEM_OS_DBGPRINTLEVEL,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
//
// This code sets up the TCP and UDP buffer sizes
// (Note 8192 is actually the default. This code is here to
// illustrate how the buffer and limit sizes are configured.)
//
// TCP Transmit buffer size
rc = 8192;
CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
// TCP Receive buffer size (copy mode)
rc = 8192;
CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXBUF,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
// TCP Receive limit (non-copy mode)
rc = 8192;
CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXLIMIT,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
// UDP Receive limit
rc = 8192;
CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
//
// Boot the system using this configuration
//
// We keep booting until the function returns 0. This allows
// us to have a "reboot" command.
//
do
{
rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );
} while( rc > 0 );
// Delete Configuration
CfgFree( hCfg );
// Close the OS
main_exit:
NC_SystemClose();
return(0);
}
//
// System Task Code [ Server Daemon Servers ]
//
static HANDLE hTransmit=0,hReceive=0;
//
// NetworkOpen
//
// This function is called after the configuration has booted
//
static void NetworkOpen()
{
// Create our local servers
hTransmit = DaemonNew( SOCK_STREAM, 0, 1000, dtask_tcp_transmit_srv,
OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
hReceive = DaemonNew( SOCK_STREAMNC, 0, 1001, dtask_tcp_receive_srv,
OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
}
//
// NetworkClose
//
// This function is called when the network is shutting down,
// or when it no longer has any IP addresses assigned to it.
//
static void NetworkClose()
{
DaemonFree( hTransmit );
DaemonFree( hReceive );
}
//
// NetworkIPAddr
//
// This function is called whenever an IP address binding is
// added or removed from the system.
//
static void NetworkIPAddr( IPN IPAddr, uint IfIdx, uint fAdd )
{
// static uint fAddGroups = 0;
IPN IPTmp;
if( fAdd )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -