Ejemplo n.º 1
0
        private void analysePathfile(ref NetworkGraph graph, string command)
        {
            string[] cpieces = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (cpieces.Length < 2)
            {
                Console.WriteLine("error: usage analysepathfile <filename>");
                return;
            }

            TextWriter tw = new StreamWriter("result_bucket.txt");
            TextWriter twViolation = new StreamWriter("violation_bucket.txt");
            TextWriter twMissing = new StreamWriter("missing_bucket.txt");
            TextWriter twRandom = new StreamWriter("random_file.txt");
            //for (int i = 0; i < allPaths.Count; i++)
            //{
            //    tw.WriteLine(pathString(allPaths[i]));
            //}
            //tw.Close();

            using (var reader = new StreamReader(cpieces[1]))
            {
                PathChecker pathChecker = new PathChecker();
                Destination newD2 = new Destination();
                initDestination(ref graph, ref newD2, "destination " + "1");

                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    string[] lpieces = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (lpieces.Length == 2)
                    {
                        int dstNum;
                        string path = lpieces[1];

                        if (!int.TryParse(lpieces[0], out dstNum))
                        {
                            Console.WriteLine("invalid destination. " + lpieces[0]);
                            continue;
                        }
                        if (dstNum > Constants._numASNs)
                        {
                            continue;
                        }

                        if (dstNum != newD2.destination)
                        {
                            try
                            {
                                initDestination(ref graph, ref newD2, "destination " + dstNum);
                            }
                            catch (Exception x)
                            {
                                Console.Out.WriteLine("Exception computing dest: " + dstNum);
                                continue;
                            }
                        }
                        try
                        {
                            string result = pathChecker.pathAnalysis(path, ref newD2, ref twMissing, ref twRandom, ref twViolation);
                            tw.WriteLine(result); tw.Flush();
                        }
                        catch (Exception y)
                        {
                            Console.Out.WriteLine("Exception analysing path: " + path);
                            continue;
                        }
                    }
                }
            }
            tw.Close();
            twMissing.Close();
            twRandom.Close();
        }
Ejemplo n.º 2
0
        private bool analysePath(ref NetworkGraph graph, string command)
        {
            string[] cpieces = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (cpieces.Length < 3)
            {
                Console.WriteLine("error: usage analysepath <dstnum> <path>");
                return false;
            }

            int dstNum;
            string path = cpieces[2];

            if (!int.TryParse(cpieces[1], out dstNum))
            {
                Console.WriteLine("invalid destination.");
                return false;
            }

            PathChecker pathChecker = new PathChecker();

            if (dstNum > Constants._numASNs)
            {
                return false;
            }

            Destination newD2 = new Destination();
            if (initDestination(ref graph, ref newD2, "destination " + dstNum))
            {
                Console.WriteLine("HN: initialized " + newD2.destination);

                pathChecker.pathAnalysis(path, ref newD2);
                return true;
            }
            return false;
        }