[SDP] Moved the test program to be built in the tests directory. (Rev 818)
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 19 Dec 2005 09:02:08 +0000 (09:02 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 19 Dec 2005 09:02:08 +0000 (09:02 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@206 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/sdp/tests/basic/BasicConnect.cpp [new file with mode: 0644]
ulp/sdp/tests/basic/SdpConnect.cpp [new file with mode: 0644]
ulp/sdp/tests/basic/makefile [new file with mode: 0644]
ulp/sdp/tests/basic/sources [new file with mode: 0644]
ulp/sdp/tests/dirs [new file with mode: 0644]

diff --git a/ulp/sdp/tests/basic/BasicConnect.cpp b/ulp/sdp/tests/basic/BasicConnect.cpp
new file mode 100644 (file)
index 0000000..9f5837a
--- /dev/null
@@ -0,0 +1,492 @@
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <Setupapi.h>\r
+#include <tchar.h>\r
+#include <strsafe.h>\r
+#include <assert.h>\r
+#include <strsafe.h>\r
+\r
+\r
+static int result = 0;\r
+\r
+\r
+// Notes:\r
+//\r
+// -- Maximum message size calculation:\r
+//        The maximum lenght of an IP message is 64K-1 (the length field in the IP header is 16 bits wide).\r
+//        The IP length field includes the IP header.\r
+//        Therefore, the maximum length of a UDP message payload is:\r
+//            64K-1-20(IP header)-8(UDP header) = 65507 bytes\r
+\r
+\r
+void printUsage(char *exeName){\r
+       printf("usage of program is:\n");\r
+       printf("%s <\"client\"> <destinationIP> <destinationPort> <numberOfMessages> <constSize>\nif contSize==0, then client will send numberOfMessages messages of 1,2,3,...numberOfMessages bytes\nif contSize!=0 then client will send numberOfMessages messages of contSize bytes\n",exeName);\r
+       printf("\n    or\n\n");\r
+       printf("%s <server> <localPort>\n\t", exeName);\r
+}\r
+\r
+WSABUF* allocateBuffer(int len){\r
+       WSABUF* buffer = new WSABUF[1];\r
+       if (buffer == NULL) {\r
+               printf("Error in allocating memory for buffer\n");\r
+               return NULL;\r
+       }else{\r
+               buffer[0].len = len;\r
+               buffer[0].buf = new char [len];\r
+               if (buffer[0].buf == NULL) {\r
+                       printf("Error in allocating memory for buffer[0].buf\n");\r
+                       delete [] buffer;\r
+                       return NULL;\r
+               }else{\r
+                       buffer[0].buf[0] = 0;\r
+                       return buffer;\r
+               }\r
+       }\r
+}\r
+\r
+void freeBuffer(WSABUF* buffer){\r
+       delete [] buffer[0].buf; \r
+       delete [] buffer;\r
+}\r
+\r
+SOCKET createSocket(){\r
+       WSADATA wsaData;\r
+       int error = WSAStartup( MAKEWORD( 2, 2 ), &wsaData);\r
+       if (error) {\r
+               printf("Error in WSAStartup: winsock error=%d\n", WSAGetLastError());\r
+               return INVALID_SOCKET;\r
+       }\r
+       SOCKET socket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);\r
+       if (socket == INVALID_SOCKET) {\r
+               printf("Error in WSASocket: winsock error=%d\n", WSAGetLastError());\r
+       }\r
+       return socket;  \r
+}\r
+\r
+bool increaseSendBuffSize(SOCKET socket, int requestedBufferSize){\r
+       int realSendBufferSize;\r
+       int error = setsockopt(socket, SOL_SOCKET, SO_SNDBUF,  (char*)&requestedBufferSize, sizeof (int));\r
+       if (error) {\r
+               printf("Error in setsockopt: winsock error=%d\n", WSAGetLastError());\r
+               return FALSE;\r
+       }\r
+       int size = sizeof (int);\r
+       error = getsockopt(socket, SOL_SOCKET, SO_SNDBUF,  (char*)&realSendBufferSize, &size);\r
+       if (error) {\r
+               printf("Error in getsockopt: winsock error=%d\n", WSAGetLastError());\r
+               return FALSE;\r
+       }\r
+       if (realSendBufferSize != requestedBufferSize) {\r
+               printf("Error: realSendBufferSize!=requestedBufferSize:\n \\r
+                       , realSendBufferSize = %d, requestedBufferSize=%d", \r
+                       realSendBufferSize, requestedBufferSize);\r
+               return FALSE;\r
+       }\r
+       return TRUE;\r
+}\r
+\r
+sockaddr addressFromString(char *address, USHORT port)\r
+\r
+{\r
+       SOCKADDR_IN socket_address;\r
+       sockaddr *socket_address_ptr = (sockaddr*)&socket_address;\r
+       memset(&socket_address, 0, sizeof(socket_address));\r
+       socket_address.sin_family = AF_INET;\r
+       socket_address.sin_port = htons(port);\r
+       int b1,b2,b3,b4;\r
+       sscanf(address, "%d.%d.%d.%d",&b1, &b2, &b3, &b4);\r
+       socket_address.sin_addr.S_un.S_un_b.s_b1 = (BYTE)b1;\r
+       socket_address.sin_addr.S_un.S_un_b.s_b2 = (BYTE)b2;\r
+       socket_address.sin_addr.S_un.S_un_b.s_b3 = (BYTE)b3;\r
+       socket_address.sin_addr.S_un.S_un_b.s_b4 = (BYTE)b4;\r
+       return *socket_address_ptr;\r
+}\r
+\r
+void performancePrint(double size, DWORD startTime){\r
+       DWORD mseconds = GetTickCount()-startTime;\r
+       if(mseconds!=0){\r
+               printf("sent and received %f bytes/%d mseconds => %f MBPS\n", \r
+                               size, mseconds, (size/mseconds)/1000.0);        \r
+       }else{\r
+               printf("sent and received %f bytes, in 0 mseconds\n", size);\r
+       }\r
+}\r
+\r
+void clientDebugMessage(bool printEnable, int debugMessageNumber, double size, DWORD time){\r
+       if(!printEnable){\r
+               return;\r
+       }\r
+       switch(debugMessageNumber){\r
+               case 1:\r
+                       printf("sending %f bytes at time %d msec\n", size, time);\r
+                       break;\r
+               case 2:\r
+                       performancePrint(size, time);\r
+                       break;\r
+               case 3:\r
+                       printf("\n\n\nPerformance summary:\n");\r
+                       performancePrint(size, time);\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+}\r
+\r
+//             0: normanl good receive\r
+//             2: error\r
+int myReceive(\r
+       SOCKET socket, \r
+       WSABUF* receiveBufferArray, \r
+       WSAOVERLAPPED* wsaoverlappedPtr,\r
+       DWORD* numOfRecvBytesPtr, \r
+       DWORD* flagsPtr,\r
+       int timeoutTime\r
+       ){\r
+\r
+       int recvStat = WSARecv(\r
+               socket, \r
+               receiveBufferArray, \r
+               1, \r
+               numOfRecvBytesPtr, \r
+               flagsPtr, \r
+               NULL, \r
+               NULL\r
+               );\r
+       if( (recvStat!= 0)  ){ \r
+               printf("erroro\n");\r
+               DWORD dwgle  = WSAGetLastError();\r
+               if (dwgle != WSA_IO_PENDING ) {\r
+                       printf("Error in WSARecv: winsock error=%d\n", WSAGetLastError());\r
+                       return 2;\r
+               }\r
+       } \r
+       return 0;               \r
+}\r
+\r
+\r
+#define SEND\r
+\r
+void client(char *IP, int Port, int numberOfMessages, int constSize)\r
+{\r
+    bool debug = FALSE;\r
+    SOCKET socket = INVALID_SOCKET;\r
+    sockaddr localSockAddr;\r
+    sockaddr destSockAddr;\r
+    WSABUF* sendBufferArray = NULL;\r
+    WSABUF* receiveBufferArray = NULL;\r
+    DWORD firstSendStartTime;\r
+    DWORD startTime;\r
+    DWORD flags = 0;\r
+    DWORD numOfSentBytes;\r
+    DWORD numOfRecvBytes;\r
+    double totalSentBytes = 0;\r
+    DWORD timeoutTime = 3000; //represents mseconds\r
+    DWORD totalWaitTime = 0;\r
+    int ret;\r
+\r
+\r
+    printf("client starting: ip=%s, port=%d, numberOfMessages=%d\n",  IP, Port, numberOfMessages );\r
+\r
+    // open and connect the socket:\r
+    socket = createSocket();\r
+    if(socket==INVALID_SOCKET) {\r
+        result = 1;\r
+        goto cleanup;\r
+    }\r
+\r
+    destSockAddr = addressFromString (IP, (USHORT)Port);\r
+    if(WSAConnect(socket, &destSockAddr, sizeof(destSockAddr), NULL, NULL, NULL, NULL)!=0){\r
+        printf("Error in WSAConnect: winsock error=%d\n", WSAGetLastError());\r
+        result = 1;\r
+        goto cleanup;\r
+    }\r
+\r
+\r
+#ifndef SEND\r
+    // Send the buffer sizes\r
+    char message[40];\r
+    StringCbPrintf(message, sizeof message, "%d,%d,", constSize,numberOfMessages);\r
+    ret = send(socket, message, strlen (message), 0);\r
+    if (ret != strlen (message)) {\r
+        printf("Error in send winsock error=%d\n", WSAGetLastError());\r
+        result = 1;\r
+        goto cleanup;\r
+    }\r
+#endif   \r
+\r
+    // allocate send & receive buffers:\r
+    sendBufferArray = allocateBuffer(constSize);\r
+    if(sendBufferArray==NULL){ \r
+        result = 1;\r
+        goto cleanup;\r
+    }\r
+    receiveBufferArray = allocateBuffer(constSize);\r
+    if(receiveBufferArray==NULL){\r
+        result = 1;\r
+        goto cleanup;\r
+    }\r
+\r
+    firstSendStartTime = GetTickCount();\r
+    // main client loop:\r
+    for(int i = 0;  i < numberOfMessages;  i++) {\r
+        int messageSize = constSize==0 ? i : constSize;\r
+        startTime = GetTickCount();\r
+        clientDebugMessage(debug, 1, (double)messageSize, startTime);\r
+        sendBufferArray[0].len = messageSize;\r
+        if(i==numberOfMessages){\r
+            sendBufferArray[0].buf[0] = 1;\r
+        }\r
+\r
+        if (messageSize > 10 ) {\r
+            // Just put some data in here\r
+            int q;\r
+            for (q= 0; q< 8; q++ ) {\r
+                sendBufferArray[0].buf[q] = (char)q + 'A';\r
+            }\r
+        }\r
+#ifdef SEND\r
+        if(WSASend(socket, sendBufferArray, 1, &numOfSentBytes, 0, NULL, NULL) != 0) {\r
+            printf("Error in WSASend in messageSize=%d: winsock error=%d\n", messageSize, WSAGetLastError());\r
+            result = 1;\r
+            goto cleanup;\r
+        }\r
+        if(numOfSentBytes!=messageSize) {\r
+            printf("numOfSentBytes!=messageSize\n");\r
+            result = 1;\r
+            goto cleanup;\r
+        }\r
+#else\r
+        DWORD Flags = 0;\r
+        if(WSARecv(socket, sendBufferArray, 1, &numOfSentBytes, &Flags, NULL, NULL) != 0) {\r
+            printf("Error in WSARecv in messageSize=%d: winsock error=%d\n", messageSize, WSAGetLastError());\r
+            result = 1;\r
+            goto cleanup;\r
+        }\r
+        assert(numOfSentBytes == messageSize); // Make sure we have a complete buffer\r
+        if (numOfSentBytes > 4) {\r
+            //printf("Recieved %c%c%c%c\n", sendBufferArray->buf[0], sendBufferArray->buf[1], sendBufferArray->buf[2], sendBufferArray->buf[3] );\r
+        }\r
+        //printf("i = %d Recieved %d bytes\n",i, numOfSentBytes);       \r
+\r
+#endif\r
+/*\r
+               int recvStatus = myReceive(\r
+                                                                   socket, \r
+                                                                   receiveBufferArray, \r
+                                                                   NULL, \r
+                                                                   &numOfRecvBytes, \r
+                                                                   &flags, \r
+                                                                   timeoutTime\r
+                                                                   );\r
+               switch(recvStatus){\r
+                       case 0:\r
+                               totalSentBytes+=messageSize;\r
+                               if(numOfRecvBytes!=messageSize){\r
+                                       printf("numOfRecvBytes(%d) != messageSize(%d)\n", numOfRecvBytes, messageSize);\r
+                                       result = 1;\r
+                                       goto cleanup;\r
+                               }\r
+                               clientDebugMessage(debug, 2, messageSize, startTime);\r
+                               break;\r
+                       case 2:\r
+                               result = 1;\r
+                               goto cleanup;\r
+                       default:\r
+                               printf("reached default in switch statement\n");\r
+                               result = 1;\r
+                               goto cleanup;\r
+               }\r
+*/\r
+       }\r
+       \r
+       if(totalSentBytes!=0){\r
+               clientDebugMessage(TRUE, 3, totalSentBytes, firstSendStartTime+totalWaitTime);\r
+       }else{\r
+               printf("no bytes transferred\n");\r
+       }\r
+       \r
+       cleanup:\r
+               if(socket!=INVALID_SOCKET){\r
+                       if(closesocket(socket)!=0){\r
+                               printf("closesocket error: error = %d\n", WSAGetLastError());\r
+                       }\r
+               }\r
+               WSACleanup();\r
+               if(sendBufferArray!=NULL){\r
+                       freeBuffer(sendBufferArray);\r
+               }\r
+               if(receiveBufferArray!=NULL){\r
+                       freeBuffer(receiveBufferArray);\r
+               }\r
+//     printf("sleeping ...\n");\r
+//     Sleep(1000);\r
+}\r
+\r
+void serverDebugMessage(bool printEnable, int messageNumber, double size){\r
+       if(!printEnable){\r
+               return;\r
+       }\r
+       switch(messageNumber){\r
+               case 1:\r
+                       printf("-----------------------------------------------------------\n");\r
+                       printf(" received %f bytes at time %d\n", size, GetTickCount());\r
+                       break;\r
+               case 2:\r
+                       printf("sent back %f bytes at time %d\n", size, GetTickCount());\r
+                       printf("-----------------------------------------------------------\n\n");\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+}\r
+\r
+void Server(int Port)\r
+{\r
+       SOCKET s;\r
+       WSADATA wsaData;\r
+       sockaddr saLocal, saFrom;\r
+       int i;\r
+       DWORD start, end, Flags = 0;\r
+       int NumberOfMessages = 1;\r
+       int MessageSize = 70000;\r
+       WSABUF wsb;\r
+       \r
+\r
+       printf("Starting as Server port=%d, \n", Port  );\r
+\r
+       int err = WSAStartup( MAKEWORD( 2, 2 ), &wsaData);\r
+       if ( err != 0 ) {\r
+               printf("Error opening winsock err=%d", WSAGetLastError());\r
+               goto cleanup;\r
+       }\r
+\r
+       s = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0 );\r
+       if (s == INVALID_SOCKET) {\r
+               printf("Error creating socket winsock err=%d", WSAGetLastError());\r
+               goto cleanup;\r
+       }\r
+\r
+       int RecvBufferSize = 0* 1024, RealRecvBufferSize;\r
+       err = setsockopt(s, SOL_SOCKET, SO_RCVBUF,  (char *)&RecvBufferSize, sizeof (int));\r
+       if ( err != 0 ) {\r
+               printf("Error setsockopt failed err=%d", WSAGetLastError());\r
+               goto cleanup;\r
+       }\r
+       int Size = sizeof (int);\r
+       err = getsockopt(s, SOL_SOCKET, SO_RCVBUF,  (char *)&RealRecvBufferSize, &Size);\r
+       if ( err != 0 ) {\r
+               printf("Error setsockopt failed err=%d", WSAGetLastError());\r
+               goto cleanup;\r
+       }\r
+       if (RealRecvBufferSize != RecvBufferSize) {\r
+               printf("Error: RealSendBufferSize = %d", RealRecvBufferSize);\r
+               goto cleanup;\r
+       }\r
+\r
+\r
+       DWORD dwBytesRecieved;\r
+\r
+       // Bind the socket first\r
+\r
+       SOCKADDR_IN *psa = (SOCKADDR_IN*)&saLocal;\r
+       memset(&saLocal, 0, sizeof(saLocal));\r
+       psa->sin_family = AF_INET;\r
+       psa->sin_port = htons((USHORT)Port);\r
+       \r
+       err = bind(s, &saLocal, sizeof(saLocal));\r
+       if ( err != 0 ) {\r
+               printf("Error bind winsock err=%d", WSAGetLastError());\r
+               goto cleanup;\r
+       }\r
+\r
+       err = listen(s, 10);\r
+       if ( err != 0 ) {\r
+               printf("Error on listen winsock err=%d", WSAGetLastError());\r
+               goto cleanup;\r
+       }\r
+\r
+       while (1) {\r
+               int addrLen = sizeof (saFrom);\r
+               SOCKET s1 = accept(s, &saFrom, &addrLen);\r
+               if (s1 == INVALID_SOCKET)  {\r
+                       printf("Error accept failed err=%d", WSAGetLastError());\r
+                       goto cleanup;\r
+               }\r
+\r
+               \r
+               for (i =0; i < 1; i++) {\r
+                       // Recieve the data\r
+                       printf ("Calling recieve\n");\r
+                       \r
+                       wsb.len = MessageSize;\r
+                       wsb.buf = new char [MessageSize];\r
+                       if (wsb.buf == NULL ) {\r
+                               printf("Error Allocating memory\n");\r
+                               goto cleanup;\r
+                       } \r
+                       \r
+                       err = WSARecv(\r
+                               s1,\r
+                               &wsb,\r
+                               1,\r
+                               &dwBytesRecieved,\r
+                               &Flags,\r
+                               NULL,\r
+                               NULL\r
+                               );\r
+                       if (err == SOCKET_ERROR) {\r
+                               DWORD gle = WSAGetLastError();\r
+                               if (gle != WSA_IO_PENDING) {\r
+                               \r
+                                       printf("Error WSARecv winsock err=%d", gle);\r
+                                       goto cleanup;\r
+                               }\r
+                       }\r
+\r
+                       // send a reply packet\r
+                       \r
+                       StringCbCopy(wsb.buf, wsb.len, "I'm a demo server");\\r
+                       wsb.len = strlen(wsb.buf);\r
+                       err = WSASend(\r
+                               s1,\r
+                               &wsb,\r
+                               1,\r
+                               &dwBytesRecieved,\r
+                               Flags,\r
+                               NULL,\r
+                               NULL\r
+                               );\r
+                       if (err == SOCKET_ERROR) {\r
+                               DWORD gle = WSAGetLastError();\r
+                               if (gle != WSA_IO_PENDING) {\r
+                               \r
+                                       printf("Error WSASend winsock err=%d", gle);\r
+                                       goto cleanup;\r
+                               }\r
+                       }                       \r
+               }\r
+       }       \r
+       cleanup:\r
+       WSACleanup();   \r
+\r
+}\r
+\r
+__cdecl main (int argc, char *argv[]){\r
+       if ((argc == 6) && !_stricmp(argv[1],"client") ) {\r
+               int port = atoi(argv[3]);\r
+               int numberOfMessages = atoi(argv[4]);\r
+               int constSize = atoi(argv[5]);\r
+               client(argv[2], port, numberOfMessages, constSize);\r
+               return result;\r
+       }else if((argc==3 ) && !_stricmp(argv[1],"server") ){\r
+               int port = atoi(argv[2]);\r
+               Server(port);\r
+               return result;\r
+       }else{\r
+               printUsage(argv[0]);\r
+               return 1;               \r
+       }\r
+}\r
diff --git a/ulp/sdp/tests/basic/SdpConnect.cpp b/ulp/sdp/tests/basic/SdpConnect.cpp
new file mode 100644 (file)
index 0000000..c0cdcf6
--- /dev/null
@@ -0,0 +1,550 @@
+
+#ifdef _WIN32
+#include <Winsock2.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#define AF_INET_FAMILY PF_INET
+
+#define sleep(x) Sleep(1000 * (x));
+#define CloseSocket closesocket
+
+#define GetTimeMs() GetTickCount()
+#else
+
+#define AF_INET_FAMILY 27
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <errno.h>
+
+#define _stricmp strcasecmp
+#define WSAGetLastError() errno
+#define CloseSocket close
+
+
+#endif
+// Windows linux 
+
+const int NumberOfThreads = 1;
+
+HANDLE g_ComplitionPort;
+HANDLE *g_pThreads;
+
+#define ASSERT assert
+
+struct sockaddr addressFromString(char *address, int port)
+{
+       unsigned int b1,b2,b3,b4;
+
+       struct sockaddr_in socket_address;
+       struct sockaddr *socket_address_ptr = (struct sockaddr*)&socket_address;
+    
+       memset(&socket_address, 0, sizeof(socket_address));
+       socket_address.sin_family = AF_INET;
+       socket_address.sin_port = htons((u_short)port);
+
+
+       sscanf(address, "%d.%d.%d.%d",&b1, &b2, &b3, &b4);
+       socket_address.sin_addr.s_addr = b4 * 256 * 256 *256 +
+                                        b3 * 256 * 256 + 
+                                        b2 * 256 +
+                                        b1;
+                                        
+       return *socket_address_ptr;
+}
+
+
+struct OverlappedSend {
+    OVERLAPPED Overlapped;
+    SOCKET Socket;
+    void *Buffer; // The data to send
+    int  DataSize;
+    DWORD NumberOfBytesSent;
+    int  RemainingSends;
+    int  SendsInAir;     // Curently sent data
+    CRITICAL_SECTION Lock;
+    HANDLE SendDoneEvent;
+
+};
+
+
+DWORD WINAPI WorkerThreadFunc( LPVOID lpParam )
+{
+    BOOL ret;
+    DWORD NumberOfBytes;
+    ULONG_PTR CompletionKey;
+    OVERLAPPED* lpOverlapped;
+    OverlappedSend *pOverLappedSend;
+    BOOL  ContinueLoop = true;
+    int iRet;
+    
+    while (TRUE) {
+        ret = GetQueuedCompletionStatus(
+                                g_ComplitionPort,
+                                &NumberOfBytes,
+                                &CompletionKey,
+                                &lpOverlapped,
+                                INFINITE);
+        ASSERT(ret != 0);
+        pOverLappedSend = CONTAINING_RECORD(lpOverlapped, OverlappedSend, Overlapped);
+        // Work on the object itself:
+        EnterCriticalSection(&pOverLappedSend->Lock);
+        pOverLappedSend->SendsInAir--;
+        ASSERT(pOverLappedSend->SendsInAir ==0); // Only one thread
+        if (pOverLappedSend->RemainingSends > 0) {
+            // do the next send
+            WSABUF Buffers;
+            Buffers.len = pOverLappedSend->DataSize;
+            Buffers.buf = (char *) pOverLappedSend->Buffer;
+            pOverLappedSend->SendsInAir++;
+            pOverLappedSend->RemainingSends--;
+            
+            iRet = WSASend(
+                pOverLappedSend->Socket,
+                &Buffers,
+                1,
+                &pOverLappedSend->NumberOfBytesSent,
+                0,
+                &pOverLappedSend->Overlapped,
+                NULL
+                );
+            ASSERT((iRet ==0) || (iRet == SOCKET_ERROR && WSAGetLastError() == WSA_IO_PENDING ));
+
+        } else {
+            // Nothing more to send - signal compleation and exit
+            SetEvent(pOverLappedSend->SendDoneEvent);
+            ContinueLoop = false;
+        }
+        LeaveCriticalSection(&pOverLappedSend->Lock);
+        if (!ContinueLoop) {
+            break;
+        }
+
+    }
+    return 0;
+}
+
+void CreateComplitionPort(int newfd)
+{
+    g_pThreads = new HANDLE [NumberOfThreads];
+    ASSERT(g_pThreads != NULL);
+
+    g_ComplitionPort = CreateIoCompletionPort((HANDLE)newfd, NULL, NULL, 2);
+    if(g_ComplitionPort == NULL) {
+        printf("Create complition port failed err=%d", GetLastError());
+        exit(1);
+    }
+
+    // Create the threads that will work on the complitions
+    g_pThreads[0] = CreateThread(NULL, 0 ,WorkerThreadFunc ,NULL, 0,NULL );
+
+
+}
+
+void CloseComplitionPort()
+{
+    //??? Post a complition thread end message
+
+    WaitForMultipleObjects(NumberOfThreads,g_pThreads, TRUE, INFINITE);
+    CloseHandle(g_ComplitionPort);
+
+}
+
+void SendDataOverlapped(int newfd, double NumberOfBuffers, double BufferSize, BOOL SendPacketNumber)
+{
+    // We will start with one operations simultaniously
+    int i ;
+    double d;
+    VOID *buffer = NULL;
+    double elapsed, acc = 0;
+    WSAOVERLAPPED wsa;
+    OverlappedSend *pOverLappedSend = NULL;
+    BOOL ret;
+    memset(&wsa, 0, sizeof wsa);
+
+    buffer = malloc ((size_t)BufferSize);
+    if (buffer == NULL) {
+        printf("Error allocating buffer\n");
+        exit(1);
+    }
+
+    CreateComplitionPort(newfd);
+
+    pOverLappedSend = new OverlappedSend;
+
+    // Set it's fields
+    memset(&pOverLappedSend->Overlapped, 0, sizeof (pOverLappedSend->Overlapped));
+    pOverLappedSend->Socket = newfd;
+    pOverLappedSend->Buffer = buffer;
+    pOverLappedSend->DataSize = (size_t)BufferSize;
+    pOverLappedSend->RemainingSends = (size_t)NumberOfBuffers;
+    pOverLappedSend->SendsInAir = 1; // To force a simulate of the compleation
+    InitializeCriticalSection(&pOverLappedSend->Lock);
+    pOverLappedSend->SendDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+
+    double Start = GetTimeMs();
+    // Post the message that will do the first send
+    ret = PostQueuedCompletionStatus(
+                              g_ComplitionPort,
+                              (DWORD)BufferSize,
+                              NULL,
+                              &pOverLappedSend->Overlapped
+                                );
+    ASSERT(ret != 0);
+
+    // wait for the send 
+    WaitForSingleObject(pOverLappedSend->SendDoneEvent, INFINITE);
+    elapsed = (GetTimeMs() - Start) / 1000;
+    printf("Finishd sending correctly %f mbytes/sec\n", NumberOfBuffers * BufferSize /elapsed/1024/1024 );
+    CloseComplitionPort();
+//Cleanup:
+    free(buffer);
+
+
+}
+
+
+
+void SendData(int newfd, double NumberOfBuffers, double BufferSize, BOOL SendPacketNumber)
+{
+    int i ;
+    double d;
+    CHAR *buffer = NULL;
+    double elapsed, acc = 0;
+
+    buffer = new char [(size_t)BufferSize];
+    if (buffer == NULL) {
+        printf("Error allocating buffer\n");
+        exit(1);
+    }
+
+    printf("Starting to send %lf messages of size %lf\n", NumberOfBuffers, BufferSize );
+
+    i = 0;
+
+    for (i = 0; i < 10; i++) {
+        buffer[i] = 'a' + i;
+    }
+    double Start = GetTimeMs();
+
+    for (d=0; d < NumberOfBuffers; d++) {
+        int j;
+        if (SendPacketNumber) {
+            memset(buffer, (char) d, (size_t)BufferSize);
+        }
+        
+        j = send(newfd, buffer, (size_t)BufferSize, 0 );
+            acc += j;
+        if (j!=BufferSize) {
+            printf("Error send not compleated  sent %lf\n", acc);
+            goto Cleanup;
+        }
+    }
+    elapsed = (GetTimeMs() - Start) / 1000;
+    printf("Finishd sending correctly %f mbytes/sec (%f seconfs)\n", acc/elapsed/1024/1024, elapsed );
+Cleanup:
+    free(buffer);
+}
+
+
+void RecvData(int newfd, double NumberOfBuffers, double BufferSize )
+{
+    int read1 = 1;
+    unsigned char *p;
+    char buffer[380000];
+    double elapsed, acc = 0;
+    int i;
+    double  Start = GetTimeMs();
+
+    while ((read1 != -1) /*&& (acc < (double)BufferSize * NumberOfBuffers)*/) {
+        read1 = recv(newfd, buffer, sizeof buffer, 0);
+        if (read1 == -1 || read1 == 0) {
+               printf("Finsihed reading, total read %lf bytes last read =%d\n", acc, read1 );
+            if (acc != BufferSize * NumberOfBuffers) {
+                printf("Error, expected to read %lf but read %lf\n",
+                    (BufferSize * NumberOfBuffers), acc);
+            }
+            break;
+        }
+        else {
+            acc += read1;
+
+//                      printf("read returned %d \"%c%c%c%c\"\n",read1,
+//                      buffer[0],buffer[1], buffer[2], buffer[3]);
+        }
+    }
+
+    if (acc != ((double)BufferSize * NumberOfBuffers)) {
+        printf("Error, expected to read %lf but read %lf",
+            ((double)BufferSize * NumberOfBuffers), acc);
+    } else {
+        elapsed = (GetTimeMs() - Start) / 1000;
+        printf("Finishd reading correctly %f mbytes/sec (time = %f)\n", acc / elapsed/1024/1024, elapsed);
+    }
+}
+
+void PrintUsage(char *name)
+{
+    printf("The program might be used in client or server mode\n");
+       printf("usage is %s <server> <port number>\n", name);
+    printf("usage is %s <client> <ip> <port number> <option number> <WritePacketNumber> <UseOverlappedSend> <Number of packets> <PacketSize>\n", name);
+    printf("The option will be sent to the remote side\n");
+       printf("Available options are:\n");
+       printf("    1 - just recieve packets forever (the other side will send xxx bytes yyy times)\n");
+       printf("    2 - send xxx bytes yyy times (based on input from network)\n");
+    printf("    WritePacketNumber can be 0 (no) or 1 (yes)\n");
+    printf("    UseOverlappedSend can be 0 (no) or 1 (yes)\n");
+
+}
+
+int Connect(int argc, char *argv[])
+{
+       struct sockaddr server_addr;
+       int port = atoi(argv[3]);
+    int s, ret;
+    int Send = 0;
+    int BufferSize, NumberOfBuffers;
+    int result = 0;
+    BOOL SendPacketNumber;
+    int  UseOverlappedSend = 0;
+
+    if (argv[4][0] == '1') {
+        Send = 1;
+    }else if (argv[4][0] == '2') {
+        Send = 0;
+    } else {
+        printf("Error - don't know if to send or recieve\n");
+        exit(1);
+    }
+
+    if (argv[5][0] == '0') {
+        SendPacketNumber = FALSE;
+    }else if (argv[5][0] == '1') {
+        SendPacketNumber = TRUE;
+    } else {
+        printf("Error - don't know if to send the packet number\n");
+        exit(1);
+    }
+
+    if (argv[6][0] == '0') {
+        UseOverlappedSend = FALSE;
+    }else if (argv[6][0] == '1') {
+        UseOverlappedSend = TRUE;
+    } else {
+        printf("Error - don't know if to send overlapped or not\n");
+        exit(1);
+    }
+    
+
+    NumberOfBuffers = atoi(argv[7]);
+    BufferSize = atoi(argv[8]);
+    
+       printf("Using port %d %s %s %s NumberOfBuffers = %d , BufferSize = %d \n", 
+        port, 
+        Send == 1 ? "sending" : "recieving", 
+        SendPacketNumber ? "Packets Are filed with data" : "Packets are not filled with data",
+        UseOverlappedSend ? "Using overlapped send" : "not using overlapped send", 
+        NumberOfBuffers,
+        BufferSize
+        );
+
+    server_addr = addressFromString(argv[2], port);
+
+       s = socket (AF_INET_FAMILY, SOCK_STREAM, 0);
+    if (s == -1) {
+            printf("Error creating socket\n");
+    }
+
+    ret = connect(s, &server_addr, sizeof(server_addr));
+    if (ret ==0) {
+        printf("connect succeeded\n");
+    } else {
+        printf("connect failed\n");
+            result = 1;
+            goto cleanup;
+    }
+
+    // Send the other side the correct information: 
+    // send(=1), UseOverlapped ,NumberOfBuffers, BufferSize,
+    // or recieve(=0),UseOverlapped ,NumberOfBuffers, BufferSize,
+    if (Send) {
+        char message[60];
+        sprintf(message, "1,%d,%d,%d,0,", UseOverlappedSend,NumberOfBuffers, BufferSize);
+        ret = send(s, message, strlen (message), 0);
+        if (ret != strlen (message)) {
+            printf("Error in send winsock error=%d\n", WSAGetLastError());
+            result = 1;
+            goto cleanup;
+        } 
+    } else {
+        char message[60];
+        sprintf(message, "2,%d,%d,%d,%d,",UseOverlappedSend, NumberOfBuffers, BufferSize, SendPacketNumber);
+        ret = send(s, message, strlen (message), 0);
+        if (ret != strlen (message)) {
+            printf("Error in send winsock error=%d\n", WSAGetLastError());
+            result = 1;
+            goto cleanup;
+        }
+    }
+    if (Send) {
+        if (UseOverlappedSend) {
+            SendDataOverlapped(s, NumberOfBuffers, BufferSize, SendPacketNumber);
+        } else {
+            SendData(s, NumberOfBuffers, BufferSize, SendPacketNumber);
+        }
+    } else {
+        RecvData(s, NumberOfBuffers, BufferSize);
+    }
+cleanup:
+    ret = CloseSocket(s);
+    if (ret == 0) {
+        printf("CloseSocket succeeded\n");
+    } else {
+        printf("CloseSocket failed\n");
+    }
+    
+    
+
+    return result;
+
+
+
+}
+int ReadNumber(int fd)
+{
+    //???
+       char Data[20]; // Don't care about buffer overflows :-)
+       int i = 0, ret;
+//    printf("ReadNumber called\n");
+
+       while (1) {
+               ret = recv(fd,&Data[i],1,0);
+        if (ret != 1) {
+            printf("Error reading data 1\n");
+            exit(1);
+        }
+               if (Data[i] == ',') break;
+               i++;
+               if (i == 20) {
+                       printf("Error reading data 2\n");
+                       exit(1);
+               }       
+       }
+       return atoi(Data);
+}
+
+int Server(int argc, char *argv[])
+{
+
+       u_short port = (u_short)atoi(argv[2]);
+    int option;
+       int s, newfd;
+       int ret;
+       struct sockaddr_in my_addr, client_addr;
+       int addr_len = sizeof(client_addr);
+    int BufferSize, NumberOfBuffers;
+    BOOL SendPacketNumber;
+    int UseOverlappedSend;
+
+       printf("Using port %d\n", port);
+    
+       memset(&my_addr, 0, sizeof(my_addr));
+       my_addr.sin_family = AF_INET;
+       my_addr.sin_port = htons(port);
+       s = socket (AF_INET_FAMILY , SOCK_STREAM, IPPROTO_TCP);
+        if (s == -1) {
+                printf("Error creating socket\n");
+        }
+
+       ret =   bind(s, (struct sockaddr*)&my_addr, sizeof(my_addr));
+       if (ret < 0) {
+               printf("Error in bind\n" );
+       }
+
+       ret = listen(s, 5);
+       for(;;) {
+               struct sockaddr name;
+               int namelen;
+               unsigned char *p;
+               
+               newfd  = accept(s, (struct sockaddr *)&client_addr, &addr_len);
+               namelen = sizeof(name);
+               getpeername(newfd, &name, &namelen);
+               p = (unsigned char *) &client_addr;
+               printf("recieved a client %d from %d.%d.%d.%d:%d\n", newfd, 
+                               p[4], p[5],p[6], p[7], p[2] *256 +  p[3] ) ;
+
+
+       option = ReadNumber(newfd);
+        UseOverlappedSend = ReadNumber(newfd);
+        NumberOfBuffers = ReadNumber(newfd);
+        BufferSize = ReadNumber(newfd);
+        SendPacketNumber = ReadNumber(newfd);
+
+
+        printf("%s ,%s Using overlapped Send,NumberOfBuffers = %d , BufferSize =%d PacketsFilled=%s \n", 
+            option == 2 ? "sending" : "recieving",
+            UseOverlappedSend ? "" : "not",
+            NumberOfBuffers,
+            BufferSize,
+            SendPacketNumber ? "true" : "false"
+            );
+        
+        if (option == 1) RecvData(newfd, NumberOfBuffers, BufferSize);
+        if (option == 2) SendData(newfd, NumberOfBuffers, BufferSize, SendPacketNumber);
+
+        ret = CloseSocket(newfd);
+        if (ret == 0) {
+            printf("CloseSocket succeeded\n");
+        } else {
+            printf("CloseSocket failed\n");
+        }
+        //break;    
+    }
+    return 0;
+}
+
+int __cdecl main(int argc, char *argv[])
+{
+    int error; 
+
+       if (argc < 3) {
+               PrintUsage(argv[0]);
+               return 1;
+       }
+
+#ifdef _WIN32
+    {
+        WSADATA wsaData;
+
+       error = WSAStartup( MAKEWORD( 2, 2 ), &wsaData);
+       if (error) {
+               printf("Error in WSAStartup: winsock error=%d\n", WSAGetLastError());
+                       return 1;
+       }
+    }
+#endif    
+    if (!_stricmp(argv[1],"client")) {
+        Connect(argc, argv);
+        //sleep(2);
+    } else if (!_stricmp(argv[1],"server")) {
+        Server(argc, argv);
+    } else {
+        printf("Unknowion option %s", argv[1]);
+               PrintUsage(argv[0]);
+        
+    }
+       SOCKET s;
+    s = socket (AF_INET_FAMILY, SOCK_STREAM, 0);
+CloseSocket(s);        
+    //printf("calling WSACleanup\n ");
+    int ret = WSACleanup ();
+    //printf("ret = %d", ret);
+    //Sleep(10000);
+    return 0;
+}
+
diff --git a/ulp/sdp/tests/basic/makefile b/ulp/sdp/tests/basic/makefile
new file mode 100644 (file)
index 0000000..9c985f5
--- /dev/null
@@ -0,0 +1,7 @@
+#\r
+# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
+# file to this component.  This file merely indirects to the real make file\r
+# that is shared by all the driver components of the Windows NT DDK\r
+#\r
+\r
+!INCLUDE $(NTMAKEENV)\makefile.def\r
diff --git a/ulp/sdp/tests/basic/sources b/ulp/sdp/tests/basic/sources
new file mode 100644 (file)
index 0000000..a7b034a
--- /dev/null
@@ -0,0 +1,91 @@
+########################################################################\r
+#\r
+#  Copyright(c) Infinicon Systems All rights reserved.\r
+#\r
+########################################################################\r
+\r
+########################################################################\r
+# The first section is nothing but manditory items.\r
+########################################################################\r
+\r
+########################################################################\r
+# The TARGETNAME.  This is name of the item being built (without the\r
+#  extension.\r
+TARGETNAME=SdpConnect\r
+\r
+########################################################################\r
+# The path where all binaries are built.  \r
+#\r
+TARGETPATH=..\..\..\..\bin\user\obj$(BUILD_ALT_DIR)\r
+\r
+########################################################################\r
+# The type of item that is being built.  This is manditory.\r
+# Value         Meaning\r
+# DYNLINK       - A DLL.\r
+# DRIVER        - A kernel device driver.\r
+# EXPORT_DRIVER - A kernel device driver with exports.\r
+# PROGRAM       - A windows executable.\r
+# PROGLIB       - A windows library.\r
+# MINPORT       - A miniport driver.\r
+# GDI_DRIVER    - A video driver.\r
+# LIBRARY       - A library \r
+TARGETTYPE=PROGRAM\r
+UMTYPE=console\r
+USE_CRTDLL=1\r
+\r
+#\r
+########################################################################\r
+# All the source files in this project.  \r
+#\r
+SOURCES=\\r
+       SdpConnect.cpp\r
+\r
+#\r
+########################################################################\r
+# The items below this line are not manditory, but they are certainly\r
+#  helpful!\r
+########################################################################\r
+\r
+########################################################################\r
+# The include directories for project.\r
+INCLUDES=..\sdpdll; f:\Progra~1\Micros~1.net\vc7\PlatformSDK\Include\r
+#RCOPTIONS=/I..\..\win\include\r
+#\r
+\r
+########################################################################\r
+# Set defines particular to the driver. A good Idea to build listings\r
+#USER_C_FLAGS=$(USER_C_FLAGS) -DEXPORT_CL_SYMBOLS\r
+\r
+############################################\r
+# Libraries that I want the driver to link with.\r
+TARGETLIBS=\\r
+       $(SDK_LIB_PATH)\ws2_32.lib  \\r
+       $(SDK_LIB_PATH)\Rpcrt4.lib\r
+#\r
+########################################################################\r
+\r
+\r
+########################################################################\r
+# Set the warning levels to maximum.\r
+MSC_WARNING_LEVEL= /W3\r
+#\r
+\r
+########################################################################\r
+# Set the linker to produce a map file.  A must have in emergency\r
+#  situations.\r
+LINKER_FLAGS=$(LINKER_FLAGS)\r
+#\r
+\r
+########################################################################\r
+#BROWSER_INFO=1\r
+#BROWSERFILE=$(TARGETPATH)\*\$(TARGETNAME).bsc -n\r
+#\r
+\r
+########################################################################\r
+# Things to be built before compile, before link, after build\r
+#NTTARGETFILE0=\r
+#NTTARGETFILE1=\r
+#NTTARGETFILES \r
+########################################################################\r
+\r
+\r
diff --git a/ulp/sdp/tests/dirs b/ulp/sdp/tests/dirs
new file mode 100644 (file)
index 0000000..a064b77
--- /dev/null
@@ -0,0 +1,3 @@
+dirs = \\r
+basic          \\r
+\r