public TCPClientPacketService()
        {
            SendPackets.Add(typeof(S0001Authenticate), 0x0001);
            SendPackets.Add(typeof(S0003Chat), 0x0003);
            SendPackets.Add(typeof(S0005TimeRequest), 0x0005);

            RecvPackets.Add(0x0006, typeof(R0006TimeResponse));
        }
Exemple #2
0
        public TCPServerPacketService()
        {
            SendPackets.Add(typeof(S0006TimeResponse), 0x0006);

            RecvPackets.Add(0x0001, typeof(R0001Authenticate));
            RecvPackets.Add(0x0003, typeof(R0003Chat));
            RecvPackets.Add(0x0005, typeof(R0005TimeRequest));
        }
Exemple #3
0
        /// <summary>
        /// Attempts to match each echo packet with the oldest, available send packet
        /// </summary>
        public override void MatchPackets()
        {
            // Console.WriteLine("this is in first match");
            // Initialize the Send Packet Queue
            var sendQ = new Queue <Tuple <CougarPacket, int> >();

            // Match every Echo Packet to the First, Available Send Packet
            for (int ndx = 0; ndx < ConnectionPackets.Count; ++ndx)
            {
                // Gather the current packet
                var current = ConnectionPackets[ndx];

                // determine TCP type
                switch (current.Type)
                {
                // Add the packet to the Queue if it's a Send
                case TCPType.SEND:
                    // add the packet and the send packet number to the queue
                    sendQ.Enqueue(Tuple.Create <CougarPacket, int>(current, SendIndex++));
                    // add the packet to a list for external use
                    SendPackets.Add(current);
                    break;

                // Match the packet to the first packet in the Queue if it's an Echo
                case TCPType.ECHO:
                    // add the packet to a list of echo packets for external use
                    EchoPackets.Add(current);
                    EchoIndex++;
                    // if there is a send packet to match
                    if (sendQ.Count > 0)
                    {
                        // take the first send packet out of the queue
                        var sendTuple = sendQ.Dequeue();
                        var send      = sendTuple.Item1;

                        // parse the send and echos packets' timestamps
                        DateTime.TryParse(current.TimeStamp, out DateTime echoT);
                        DateTime.TryParse(send.TimeStamp, out DateTime sendT);

                        // calculate the round trip time
                        // RTT = echoT - sendT
                        var rtt = CalculateRoundTripTime(echoT, sendT);
                        RoundTripTimes.Add(rtt);

                        // Format a string declaring the Send and Echo Match
                        PairedMatches.Add(NumberOfMatches++, String.Format("(S#{0}, Packet#{1}), (E#{2}, Packet#{3}), RTT = {4}", sendTuple.Item2, send.PacketNumber, EchoIndex, current.PacketNumber, rtt));
                    }

                    break;
                }
            }
        }
        public override void MatchPackets()
        {
            //Console.WriteLine("this is greedy");
            //  bool correctMatch = true;
            var  sendQ       = new Queue <Tuple <CougarPacket, int> >();
            bool firstPacket = true;

            //for every packet
            for (int ndx = 0; ndx < ConnectionPackets.Count; ++ndx)
            {
                var current = ConnectionPackets[ndx];

                //determine the type
                switch (current.Type)
                {
                // if it is a send packet
                case TCPType.SEND:
                    DateTime lastTime = new DateTime();
                    SendIndex++;
                    SendPackets.Add(current);
                    // if this will be the first packet in the queue
                    if (firstPacket)
                    {
                        // "initialize" the value for last packet's time to this packet's
                        DateTime.TryParse(current.TimeStamp, out lastTime);
                        // clear flag for the next run
                        firstPacket = false;
                    }

                    // parse the current packet's time stamp
                    DateTime.TryParse(current.TimeStamp, out DateTime currentTime);

                    // calculate time elapsed between send packets
                    double tg = currentTime.Subtract(lastTime).TotalSeconds;


                    // reset queue and flags if beyond threshold amount
                    if (tg > Threshold)
                    {
                        sendQ.Clear();
                        firstPacket = true;
                    }

                    // add the packet to the queue if within threshold
                    else
                    {
                        sendQ.Enqueue(Tuple.Create <CougarPacket, int>(current, SendIndex));
                    }
                    break;

                // if it is an echo packet
                case TCPType.ECHO:
                    EchoIndex++;
                    if (sendQ.Count > 0)
                    {
                        // gather the first send packet from the queue
                        var sendTuple = sendQ.Dequeue();
                        var send      = sendTuple.Item1;

                        EchoPackets.Add(current);

                        // determine whether they match, or not
                        if ((current.SeqNum >= send.AckNum) && (current.AckNum > send.SeqNum))    // && correctMatch)
                        {
                            // if they match, calculate the Round Trip Time

                            // RTT = TimeOfEcho - TimeOfSend
                            DateTime.TryParse(current.TimeStamp, out DateTime echoT);
                            DateTime.TryParse(send.TimeStamp, out DateTime sendT);

                            var rtt = CalculateRoundTripTime(echoT, sendT);
                            RoundTripTimes.Add(rtt);

                            // Format a string declaring the Send and Echo Match
                            PairedMatches.Add(NumberOfMatches++, String.Format("(S#{0}, Packet#{1}), (E#{2}, Packet#{3}), RTT = {4}", sendTuple.Item2, send.PacketNumber, EchoIndex, current.PacketNumber, rtt));
                        }
                    }
                    //  else
                    //   correctMatch = false;
                    break;
                }
            }
        }