Exemplo n.º 1
0
        public void TestResendsAfterLosingAcks()
        {
            Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp);

            IPEndPoint        serverEndPoint = new IPEndPoint(IPAddress.Loopback, testUdpPort);
            FixedRetryTimeout timeout        = new FixedRetryTimeout(100, 6);

            using (TestServerWrapper server = new TestServerWrapper(serverEndPoint, timeout))
            {
                Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp);

                //
                //
                //
                UdpConnectedClientTransmitter udpTransmitter    = new UdpConnectedClientTransmitter(serverEndPoint);
                ClumsyTransmitter             clumsyTransmitter = new ClumsyTransmitter(udpTransmitter, Console.Out);
                CdpTransmitter transmitter = new CdpTransmitter(clumsyTransmitter);

                Int64 startTicks = Stopwatch.GetTimestamp();
                Console.WriteLine("[Sender {0} millis] Sending...", (Stopwatch.GetTimestamp() - startTicks).StopwatchTicksAsInt64Milliseconds());

                UInt32 offset;
                Byte[] datagram = transmitter.RequestSendBuffer(10, out offset);
                for (Byte i = 0; i < 10; i++)
                {
                    datagram[offset++] = (Byte)('A' + i);
                }
                clumsyTransmitter.DropAllReceivedDatagramsForTheNext(400);
                transmitter.ControllerSendPayloadWithAck(offset, timeout);
                server.TestSucceeded();
            }
        }
Exemplo n.º 2
0
        public void TestMethod1()
        {
            Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp);

            IPEndPoint        serverEndPoint = new IPEndPoint(IPAddress.Loopback, testUdpPort);
            FixedRetryTimeout timeout        = new FixedRetryTimeout(500, 6);

            using (TestServerWrapper server = new TestServerWrapper(serverEndPoint, timeout))
            {
                UdpConnectedClientTransmitter udpTransmitter = new UdpConnectedClientTransmitter(serverEndPoint);
                CdpTransmitter transmitter = new CdpTransmitter(udpTransmitter);


                UInt32 offset;
                Byte[] myMessage;
                Byte[] payloadBuffer;


                //
                // Send and wait for ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be a normal payload with an immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Payload With Ack...");
                transmitter.ControllerSendPayloadWithAck(offset, timeout);

                //
                // Send heartbeat
                //
                Console.WriteLine("[Client] Sending Heartbeat...");
                transmitter.SendHearbeat();

                //
                // Send Random Payload
                //
                myMessage = Encoding.UTF8.GetBytes("This should be a random payload");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Random Payload...");
                transmitter.ControllerSendRandomPayload(offset);

                //
                // Send Payload no ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be the first payload with no immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Payload No Ack...");
                transmitter.ControllerSendPayloadNoAck(offset);

                //
                // Send Payload no ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be the second payload with no immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Payload No Ack...");
                transmitter.ControllerSendPayloadNoAck(offset);

                //
                // Send and wait for ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be a normal payload with an immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Payload With Ack...");
                transmitter.ControllerSendPayloadWithAck(offset, timeout);

                //
                // Send Halt
                //
                Console.WriteLine("[Client] Sending Halt...");
                transmitter.SendHaltNoPayload();

                server.TestSucceeded();
                Console.WriteLine("[Client] Done (Success)");
            }
        }
Exemplo n.º 3
0
        static Int32 Main(string[] args)
        {
            CdpCatOptions optionsParser = new CdpCatOptions();

            if (args.Length <= 0)
            {
                optionsParser.PrintUsage();
                return(-1);
            }

            List <String> nonOptionArgs = optionsParser.Parse(args);

            Cdp.StaticInit(optionsParser.maxPayload.ArgValue);

            ICdpTimeout timeout = new MyCdpTimeout();

            if (optionsParser.listenPort.set)
            {
                IPEndPoint  localEndPoint = new IPEndPoint(IPAddress.Any, optionsParser.listenPort.ArgValue);
                MyCdpServer cdpServer     = new MyCdpServer();
                Socket      udpSocket     = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                Cdp.UdpServerLoop(cdpServer, udpSocket, localEndPoint, new Byte[optionsParser.maxPayload.ArgValue], timeout);
                return(-1);
            }
            else
            {
                if (nonOptionArgs.Count < 2)
                {
                    Console.WriteLine("Missing command line arguments");
                    optionsParser.PrintUsage();
                    return(-1);
                }

                UInt16   port           = UInt16.Parse(nonOptionArgs[1]);
                EndPoint serverEndPoint = new IPEndPoint(EndPoints.ParseIPOrResolveHost(nonOptionArgs[0], DnsPriority.IPv4ThenIPv6), port);

                UdpConnectedClientTransmitter udpTransmitter = new UdpConnectedClientTransmitter(serverEndPoint);
                CdpTransmitter transmitter = new CdpTransmitter(udpTransmitter);


                UInt32 offset;
                Byte[] myMessage;
                Byte[] payloadBuffer;



                transmitter.SendHearbeat();



                myMessage = Encoding.UTF8.GetBytes("This should be a random payload");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                transmitter.ControllerSendRandomPayload(offset + (UInt32)myMessage.Length);



                myMessage = Encoding.UTF8.GetBytes("This should be the first payload with no immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, (UInt32)myMessage.Length);
                transmitter.ControllerSendPayloadNoAck(offset + (UInt32)myMessage.Length);

                myMessage = Encoding.UTF8.GetBytes("This should be the second payload with no immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, (UInt32)myMessage.Length);
                transmitter.ControllerSendPayloadNoAck(offset + (UInt32)myMessage.Length);


                //
                // Send and wait for ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be a normal payload with an immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                transmitter.ControllerSendPayloadWithAck(offset, timeout);



                transmitter.SendHaltNoPayload();


                return(0);
            }
        }