private void SendThread(object obj)
        {
            CancellationToken token = (CancellationToken)obj;

            IntPtr socket = IntPtr.Zero;

            try
            {
                testLogger.LogComment("TCP Sends from {0}:{1} to {2}:{3}", localAddress, localPort, remoteAddress, remotePort);
                socket = sockets.CreateTcpSocket(localAddress, localPort, ipv6Mode);
                sockets.Connect(socket, remoteAddress, remotePort, ipv6Mode);
                testLogger.LogComment("Connected to TCP Server at {0}:{1}", remoteAddress, remotePort);

                Byte[] sendData;
                while (!token.IsCancellationRequested)
                {
                    sendData = NetworkInterfaceDataPathTests.GeneratePayload(1000);
                    testLogger.LogTrace("TcpSender[{0}]  Sending Data", this.identifier);
                    sockets.Send(socket, sendData);
                    UnitsTransfered += sendData.Length;
                    Wlan.Sleep(NetworkInterfaceDataPathTests.RandomWaitTime());
                    DateTime nextLogTime = DateTime.Now;
                    if (DateTime.Now > nextLogTime)
                    {
                        testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sending TCP Data to {0}:{1}.  Bytes Sent {2}", remoteAddress, remotePort, UnitsTransfered));
                        nextLogTime = DateTime.Now.Add(logInterval);
                    }
                    testLogger.LogTrace("TcpSender[{0}]  Total Bytes Sent: {1}", this.identifier, UnitsTransfered);
                }

                testLogger.LogComment("TCP Send Completed from {0}:{1} to {2}:{3} Bytes Count = {4}",
                                      localAddress, localPort, remoteAddress, remotePort, UnitsTransfered);
            }
            catch (Exception error)
            {
                testLogger.LogError(string.Format(CultureInfo.InvariantCulture, "Error when sending TCP Data from {0}:{1} to {2}:{3} : {4}", localAddress, localPort, remoteAddress, remotePort, error.ToString()));
                throw;
            }
            finally
            {
                if (socket != IntPtr.Zero)
                {
                    testLogger.LogTrace("TcpSender[{0}] Closing Send Socket", this.identifier);
                    sockets.CloseSocket(socket);
                }
            }
        }
Exemplo n.º 2
0
        private void SendThread(object obj)
        {
            CancellationToken token = (CancellationToken)obj;

            IntPtr socket = IntPtr.Zero;

            try
            {
                testLogger.LogComment("Broadcast Sends from {0}:{1} to {2}:{3}", localAddress, localPort, remoteAddress, remotePort);
                socket = sockets.CreateBroadcastSocket(localAddress, localPort);
                UnitsTransfered++;
                Byte[] sendData;
                while (!token.IsCancellationRequested)
                {
                    sendData = NetworkInterfaceDataPathTests.GeneratePayload(100);
                    testLogger.LogTrace("BroadcastSender[{0}]  Sending Packet", this.identifier);
                    sockets.SendTo(socket, sendData, remoteAddress, remotePort, false);
                    Wlan.Sleep(NetworkInterfaceDataPathTests.RandomWaitTime());
                    UnitsTransfered++;
                    DateTime nextLogTime = DateTime.Now;
                    if (DateTime.Now > nextLogTime)
                    {
                        testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sending Broadcast Data to {0}:{1}.  Packets Sent {2}", remoteAddress, remotePort, UnitsTransfered));
                        nextLogTime = DateTime.Now.Add(logInterval);
                    }

                    testLogger.LogTrace("BroadcastSender[{0}] Packets Sent: {1}", this.identifier, UnitsTransfered);
                }

                testLogger.LogComment("Broadcast Send Completed from {0}:{1} to {2}:{3}. Packet Count = {4}",
                                      localAddress, localPort, remoteAddress, remotePort, UnitsTransfered);
            }
            catch (Exception error)
            {
                testLogger.LogError(error.ToString());
                throw;
            }
            finally
            {
                if (socket != IntPtr.Zero)
                {
                    testLogger.LogTrace("BroadcastSender[{0}] Closing Send Socket", this.identifier);
                    sockets.CloseSocket(socket);
                }
            }
        }
Exemplo n.º 3
0
        private void SendThread(object obj)
        {
            CancellationToken token = (CancellationToken)obj;

            IntPtr socket = IntPtr.Zero;

            try
            {
                testLogger.LogComment("Multicast Sends from {0}:{1} to {2}:{3}", localAddress, localPort, remoteAddress, remotePort);
                if (ipv6Mode)
                {
                    if (testMode == TestMode.Wlan)
                    {
                        using (Wlan wlanApi = new Wlan())
                        {
                            var wlanInterfaceList = wlanApi.EnumWlanInterfaces();
                            if (wlanInterfaceList.Count < 1)
                            {
                                throw new TestConfigException("No WLAN Interfaces were discovered.  Ensure that WLAN interfaces are enabled, discoverable, and operational.");
                            }
                            var wlanInterface = wlanInterfaceList[0];

                            UInt32 wlanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(wlanInterface.Id);
                            socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort, wlanInterfaceIndex);
                        }
                    }
                    else
                    {
                        UInt32 lanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(localInterfaceGuid);
                        socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort, lanInterfaceIndex);
                    }
                }
                else
                {
                    socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort);
                }

                Byte[] sendData;
                while (!token.IsCancellationRequested)
                {
                    sendData = NetworkInterfaceDataPathTests.GeneratePayload(100);
                    testLogger.LogTrace("MulticastSender[{0}]   Sending Packet", this.identifier);
                    sockets.SendTo(socket, sendData, remoteAddress, remotePort, ipv6Mode);
                    UnitsTransfered++;
                    Wlan.Sleep(NetworkInterfaceDataPathTests.RandomWaitTime());
                    DateTime nextLogTime = DateTime.Now;
                    if (DateTime.Now > nextLogTime)
                    {
                        testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sending Multicast Data to {0}:{1}.  Packets Sent {2}", remoteAddress, remotePort, UnitsTransfered));
                        nextLogTime = DateTime.Now.Add(logInterval);
                    }

                    testLogger.LogTrace("MulticastSender[{0}]   Packets Sent {1}", this.identifier, UnitsTransfered);
                }

                testLogger.LogComment("Multicast Send Completed from {0}:{1} to {2}:{3}. Packet Count = {4}",
                                      localAddress, localPort, remoteAddress, remotePort, UnitsTransfered);
            }
            catch (Exception error)
            {
                testLogger.LogError(error.ToString());
                throw;
            }
            finally
            {
                if (socket != IntPtr.Zero)
                {
                    testLogger.LogTrace("MulticastSender[{0}] Closing Send Socket", this.identifier);
                    sockets.CloseSocket(socket);
                }
            }
        }