コード例 #1
0
        private static IEnumerable <LatencyNeighborPair> FindNeighborsInHopPair(ScamperHop currentHop, int currentHopIndex, ScamperHop neighborHop, int neighborHopIndex, decimal maximumLatencyDiff, decimal maxRTT)
        {
            if (currentHop != null && neighborHop != null && currentHop.IPs != null && neighborHop.IPs != null)
            {
                for (var i = 0; i < currentHop.IPs.Count; i++)
                {
                    var currentIPInfo = currentHop.IPs[i];

                    if (currentIPInfo != null && currentIPInfo.IP != null)
                    {
                        for (var j = 0; j < neighborHop.IPs.Count; j++)
                        {
                            var neighborIPInfo = neighborHop.IPs[j];

                            if (neighborIPInfo != null && neighborIPInfo.IP != null && currentIPInfo.IP != neighborIPInfo.IP && currentIPInfo.RTT <= maxRTT && neighborIPInfo.RTT <= maxRTT)
                            {
                                var latencyDiff = Math.Abs(currentIPInfo.RTT - neighborIPInfo.RTT);

                                if (latencyDiff <= maximumLatencyDiff)
                                {
                                    yield return(new LatencyNeighborPair()
                                    {
                                        Neighbor1 = currentIPInfo.IP,
                                        Neighbor2 = neighborIPInfo.IP,
                                        Neighbor1HopIndex = currentHopIndex,
                                        Neighbor2HopIndex = neighborHopIndex,
                                        Neighbor1RTT = currentIPInfo.RTT,
                                        Neighbor2RTT = neighborIPInfo.RTT,
                                        DiffDistanceInHops = neighborHopIndex - currentHopIndex,
                                        LatencyDiff = latencyDiff
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        /*
         # 14. PerHopData -- Response data for the first hop.
         #
         #       If multiple IP addresses respond at the same hop, response data
         #       for each IP address are separated by semicolons:
         #
         #       IP,RTT,nTries                   (for only one responding IP)
         #       IP,RTT,nTries;IP,RTT,nTries;... (for multiple responding IPs)
         #
         #         where
         #
         #       IP -- IP address which sent a TTL expired packet
         #       RTT -- RTT of the TTL expired packet
         #       nTries -- number of tries before response received from hop
         #
         #       This field will have the value 'q' if there was no response at
         #       this hop.
         */
        public static ScamperHop ParseHop(string line, string value)
        {
            // This field will have the value 'q' if there was no response at this hop.
            if (value == "q")
            {
                return(null);
            }

            var rawIPsInfo = value.Split(new char[] { ';' });

            var ipInfosInHop = new List <ScamperHopIPInfo>();

            foreach (var rawIPInfo in rawIPsInfo)
            {
                var infoParts = rawIPInfo.Split(new char[] { ',' });

                if (infoParts.Length != 3)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Number of infoParts in ParseHop was not 3 for rawIPInfo: {0} and line: {1}", rawIPInfo, line));
                }

                var hopIPInfo = new ScamperHopIPInfo()
                {
                    IP    = IPAddress.Parse(infoParts[0]),
                    RTT   = decimal.Parse(infoParts[1]),
                    Tries = int.Parse(infoParts[2])
                };

                ipInfosInHop.Add(hopIPInfo);
            }

            var hop = new ScamperHop()
            {
                IPs = ipInfosInHop
            };

            return(hop);
        }