Ejemplo n.º 1
0
        private static void Kernel_UdpIpSend(UdpIpTraceData packet)
        {
            if (packet.size == 56)
            {
                uint  ipv4  = BitConverter.ToUInt32(packet.daddr.MapToIPv4().GetAddressBytes(), 0);
                ulong netId = (ulong)packet.dport << 32 | ipv4;

                lock (lockObj)
                {
                    if (pings.ContainsKey(netId))
                    {
                        if (pings[netId].tFirstSend == -1)
                        {
                            pings[netId].tFirstSend = packet.TimeStampRelativeMSec;
                        }

                        pings[netId].stunSentCnt++;
                        // For the first 10 seconds of connection, some STUN packets may be dropped entirely, which messes with the ping
                        // filter. Assuming late packets were dropped at the beginning helps.
                        if (pings[netId].tStunSent == -1 || packet.TimeStampRelativeMSec - pings[netId].tFirstSend < 10000)
                        {
                            pings[netId].tStunSent = packet.TimeStampRelativeMSec;
                        }
                        else
                        {
                            pings[netId].stunLateCnt++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void LogEvent(UdpIpTraceData data)
        {
            LogRow text = new LogRow();

            _netWriter.WriteHeader(data, text);
            text.Add(data.saddr.ToString());
            text.Add(data.sport.ToString());
            text.Add(data.daddr.ToString());
            text.Add(data.dport.ToString());
            _netWriter.WriteRow(text);
        }
 private static void Kernel_UdpIpRecv(UdpIpTraceData packet)
 {
     if (pings.ContainsKey(packet.saddr) && packet.size == 68)
     {
         if (pings[packet.saddr].tPacketSent != -1)
         {
             pings[packet.saddr].tLastRecv   = packet.TimeStampRelativeMSec;
             pings[packet.saddr].ping        = packet.TimeStampRelativeMSec - pings[packet.saddr].tPacketSent;
             pings[packet.saddr].tPacketSent = -1;
         }
     }
 }
Ejemplo n.º 4
0
        private static void Kernel_UdpIpRecv(UdpIpTraceData packet)
        {
            if (packet.size == 68)
            {
                uint  ipv4  = BitConverter.ToUInt32(packet.saddr.MapToIPv4().GetAddressBytes(), 0);
                ulong netId = (ulong)packet.sport << 32 | ipv4;

                lock (lockObj)
                {
                    if (pings.ContainsKey(netId))
                    {
                        if (pings[netId].tStunSent != -1)
                        {
                            PingInfo pi = pings[netId];

                            pi.tLastStunRecv = packet.TimeStampRelativeMSec;
                            pi.ping          = packet.TimeStampRelativeMSec - pi.tStunSent;

                            pi.pingSamples[pi.cnt++ % N_SAMPLES] = pi.ping;
                            if (pi.cnt >= N_SAMPLES)
                            {   // After N_SAMPLES measurements, compute average ping and jitter
                                pi.avgPing = 0;
                                for (int i = 0; i < N_SAMPLES; i++)
                                {
                                    pi.avgPing += pi.pingSamples[i];
                                }
                                pi.avgPing /= N_SAMPLES;

                                pi.jitter = 0;
                                for (int i = 0; i < N_SAMPLES; i++)
                                {
                                    pi.jitter += Math.Pow(pi.pingSamples[i] - pi.avgPing, 2);
                                }
                                pi.jitter = Math.Sqrt(pi.jitter / N_SAMPLES);
                            }

                            pings[netId].tStunSent = -1;
                        }
                    }
                }
            }
        }
        private static void Kernel_UdpIpSend(UdpIpTraceData packet)
        {
            if (packet.size == 56)
            {
                if (!pings.ContainsKey(packet.daddr))
                {
                    pings[packet.daddr] = new PingInfo(packet.TimeStampRelativeMSec);
                }

                pings[packet.daddr].tPacketSent = packet.TimeStampRelativeMSec;

                foreach (IPAddress ip in pings.Keys)
                {
                    if (pings[ip].tLastRecv - packet.TimeStampRelativeMSec > 10000)
                    {
                        pings.Remove(ip);
                    }
                }
            }
        }