// $Id$ #include "ace/INET_Addr.h" #include "ace/SOCK_SEQPACK_Association.h" #include "ace/SOCK_SEQPACK_Connector.h" #include "ace/Log_Msg.h" #include "ace/CDR_Stream.h" #include "ace/High_Res_Timer.h" // FUZZ: disable check_for_streams_include #include "ace/streams.h" #include "ace/os_include/arpa/os_inet.h" // make sure that the code compiles cleanly even if SCTP is not // available. If SCTP is not installed, program will exit early in // main() with an error message #ifdef ACE_HAS_SCTP extern "C" { #include }; #else #ifndef IPPROTO_SCTP #define IPPROTO_SCTP 132 #endif // !IPPROTO_SCTP #define SCTP_NODELAY 1 #endif // ACE_HAS_SCTP // class that manages setting of options #include "Options_Manager.h" // histogram code #include "hist.h" // global constants ACE_CDR::UShort const primerIterations = 100; // ace/High_Res_Timer.h describes the need for the following. ACE_UINT32 const microsec_clock_scale_factor = ACE_High_Res_Timer::global_scale_factor(); // forward declations of functions. Bodies follow main() to improve // file readability. HIST runTest(ACE_SOCK_SEQPACK_Association &); int main(int argc, char **argv){ // Initialize the options manager Options_Manager optsMgr(argc, argv, "client-opts"); // show usage is requested if (optsMgr._usage) { optsMgr._show_usage(cerr, "client-opts"); return 1; } #ifndef ACE_HAS_SCTP ACE_ERROR_RETURN((LM_ERROR, "SCTP was NOT installed/accessible when this binary was compiled.\n"), 1); #endif // check that valid options were specified if (optsMgr._error) { cerr << "ERROR: " << optsMgr._error_message << endl; return 1; } // Create the address that we want the client to connect to ACE_INET_Addr serverAddr(Options_Manager::server_port, Options_Manager::server_host); // Create the address that we want the client to connect FROM ACE_Multihomed_INET_Addr clientAddr; clientAddr.set(optsMgr.client_port, optsMgr.client_connect_addr, 1, optsMgr.secondary_connect_addrs, optsMgr.num_secondary_connect_addrs); // object that manages the connection to the server ACE_SOCK_SEQPACK_Connector connector; // object that manages the data xfer between the client and server ACE_SOCK_SEQPACK_Association dataStream; // connect to the server if (connector.connect (dataStream, serverAddr, 0,clientAddr, 0, 0, 0, optsMgr.test_transport_protocol) == -1) /*, // ALL DEFAULT ARGUMENTS Options_Manager::test_transport_protocol) == -1) */ ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "connection failed"), 1); // run the test HIST testResultsHistogram = NULL; // connection is closed by runTest* functions testResultsHistogram = runTest(dataStream); // report out the test statistics IF NO EXECPTIONS have been thrown // all histograms created are placed onto a linked list that report() // can access. So the histogram created in one of the *_test() functions // will be reported out by the report() call if (testResultsHistogram) report(); return 0; } // create a histogram to store test results HIST createHistogram(ACE_CDR::ULong messageSize){ // The histogram created below lives beyond the scope of this // function. So the memory allocated here cannot be cleaned up when // this function goes out of scope. Unfortunately the histogram // implementation does not clean it up either. So it is a small // memory leak. char * histName = (char *) malloc(200); sprintf(histName, "%s Unmarshalled Msg Synchronous Latency Test\n\t\t\t\t\t(Message Size %u, Message Type octet)", "ACE", messageSize); // actually create the histogram HIST createdHist = histogram(histName, Options_Manager::histogram_bin_count, Options_Manager::histogram_min_bin, Options_Manager::histogram_max_bin); // set the maximum number of outliers to maintain in the histogram set_outer(Options_Manager::histogram_num_outliers, createdHist); return (createdHist); } // send the test header (only contains number of iterations) int sendHeader(ACE_SOCK_SEQPACK_Association & stream) { // create an ACE CDR output stream and place the header information // into it ACE_OutputCDR hdrCDR; hdrCDR << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER); hdrCDR << ACE_CDR::ULong(Options_Manager::test_iterations+primerIterations); if (!hdrCDR.good_bit()) return (0); // send the header to the server (HEADER is 8 BYTES LONG) size_t bt; if (stream.send_n(hdrCDR.begin(), 0, &bt) == -1) return 0; return 1; } // conduct the UnMarshalled Octet performance test using separate // send_n calls with Nagle's algorithm disabled HIST runUnmarshalledOctetTest(ACE_CDR::Octet *buf, size_t seqLen, ACE_SOCK_SEQPACK_Association & stream){ ACE_CDR::ULong const testIterations = Options_Manager::test_iterations; size_t bt; ACE_CDR::ULong cnt = 0; // variables for the timing measurements ACE_hrtime_t startTime, endTime; ACE_CDR::Double messageLatency_usec = 0.0; ACE_CDR::ULong msgLen = seqLen*ACE_CDR::OCTET_SIZE; // explicity configure Nagling. Default is // Options_Manager::test_enable_nagle=0 so default configurations is // NO NAGLING ACE_CDR::Long nagle; if (Options_Manager::test_enable_nagle) nagle=0; else nagle=1; if (-1 == stream.set_option(IPPROTO_SCTP, SCTP_NODELAY, &nagle, sizeof nagle)) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "set_option"), 0); // prime the client and server before starting the test for(cnt=0;cnt