Example #1
0
        public static void miniDestinationToBlob(MiniDestination d, string containerName, string blobName)
        {
            //set up streamwriter for the blob.
            StreamWriter output = new StreamWriter(BlobLibrary.getBlobWriteStream(containerName, blobName));

            miniDestinationToStream(d, output);
            output.Close();
        }
Example #2
0
        private static void miniDestinationToStream(MiniDestination d, StreamWriter output)
        {
            output.WriteLine("#destination " + d.destination);

            /*** output
             * i j as1 as2 as3
             * for each non-null element [i,j] in buckettable
             * ***/
            //this will barf if bucket table is null.
            output.WriteLine("#buckettable " + d.BucketTable.GetLength(0) + " " + d.BucketTable[0].GetLength(0));
            for (int i = 0; i < d.BucketTable.GetLength(0); i++)
            {
                for (int j = 0; j < d.BucketTable[0].GetLength(0); j++)
                {
                    if (d.BucketTable[i][j] != null)
                    {
                        output.Write(i + " " + j + " ");
                        for (int k = 0; k < d.BucketTable[i][j].Count; k++)
                        {
                            output.Write(d.BucketTable[i][j][k] + " ");
                        }
                        output.Write("\n");
                    }
                }
            }

            /** output i as1 as2 as3
             * for each non-null list in the best[i] array. **/
            output.WriteLine("#best " + d.Best.Length);
            for (int i = 0; i < d.Best.Length; i++)
            {
                if (d.Best[i] != null)
                {
                    output.Write(i + " ");
                    for (int j = 0; j < d.Best[i].Count; j++)
                    {
                        output.Write(d.Best[i][j] + " ");
                    }
                    output.Write("\n");
                }
            }

            /*** output 1 line with all the values of bestrelation separated by ' ' since
             * it is a simple object **/
            output.WriteLine("#bestrelation " + d.BestRelation.Length);
            for (int i = 0; i < d.BestRelation.Length; i++)
            {
                output.Write(d.BestRelation[i] + " ");
            }
            output.Write("\n");

            output.WriteLine("#L " + d.L.Length);
            for (int i = 0; i < d.L.Length; i++)
            {
                output.Write(d.L[i] + " ");
            }
            output.Write("\n");
        }
Example #3
0
        public static MiniDestination miniDestinationFromText(string filename)
        {
            StreamReader    input    = new StreamReader(filename);
            MiniDestination toreturn = miniDestinationFromStream(input);

            input.Close();

            return(toreturn);
        }
Example #4
0
        public static MiniDestination miniDestinationFromBlob(string containerName, string blobName)
        {
            StreamReader    input    = new StreamReader(BlobLibrary.getBlobReadStream(containerName, blobName));
            MiniDestination toreturn = miniDestinationFromStream(input);

            input.Close();

            return(toreturn);
        }
Example #5
0
        private static double getAverageBestSize(MiniDestination d)
        {
            double avg    = 0;
            double points = 0;

            for (int i = 0; i < d.Best.Length; i++)
            {
                if (d.Best[i] != null)
                {
                    avg += d.Best[i].Count;
                    points++;
                }
            }
            return(avg / points);
        }
Example #6
0
        private static double getAverageBestSize(MiniDestination d, List <UInt32> careAbout)
        {
            double avg    = 0;
            double points = 0;

            for (int i = 0; i < d.Best.Length; i++)
            {
                if (careAbout.Contains((UInt32)i))
                {
                    if (d.Best[i] != null)
                    {
                        avg += d.Best[i].Count;
                        points++;
                    }
                }
            }
            return(avg / points);
        }
Example #7
0
        private static bool initDestination(ref NetworkGraph g, ref Destination d, string dest)
        {
            UInt32 destNum;

            if (!UInt32.TryParse(dest, out destNum))
            {
                /*
                 * Console.WriteLine("Invalid ASN!");
                 */
                return(false);
            }
            if (g.GetNode(destNum) == null)
            {
                /*
                 * Console.WriteLine("WARNING: Could not retrieve destination " + d + " from the graph.");
                 */
                return(false);
            }

            /*
             * Console.WriteLine("Initializing variables and running RTA");
             */
            MiniDestination miniDest = SimulatorLibrary.initMiniDestination(g, destNum, false);

            d = new Destination(miniDest);
            bool[] tempS = new bool[Constants._numASNs];
            for (int i = 0; i < tempS.Length; i++)
            {
                tempS[i] = false;
            }
            d.UpdatePaths(tempS);

            /*
             * Console.WriteLine("Done initializing. Current active destination is: " + destNum);
             */
            return(true);
        }
Example #8
0
        private static MiniDestination miniDestinationFromStream(StreamReader input)
        {
            MiniDestination toreturn = new MiniDestination();
            //some constants to make this a little nicer.
            int       currentlyReading = -1;
            const int buckettable      = 0;
            const int best             = 1;
            const int bestrelation     = 2;
            const int l = 3;

            while (!input.EndOfStream)
            {
                string   line   = input.ReadLine().ToLower();
                string[] pieces = line.Split(space, StringSplitOptions.RemoveEmptyEntries);
                if (line[0] == '#')
                {
                    if (line.IndexOf("buckettable") >= 0)
                    {
                        currentlyReading = buckettable;
                        int numRows = int.Parse(pieces[1]);
                        int numCols = int.Parse(pieces[2]);
                        toreturn.BucketTable = new List <UInt32> [numRows][];
                        for (int i = 0; i < toreturn.BucketTable.Length; i++)
                        {
                            toreturn.BucketTable[i] = new List <UInt32> [numCols];
                        }
                    }
                    else if (line.IndexOf("bestrelation") >= 0)
                    {
                        currentlyReading = bestrelation;
                        int numRows = int.Parse(pieces[1]);
                        toreturn.BestRelation = new byte[numRows];
                    }
                    else if (line.IndexOf("destination") >= 0)
                    {
                        UInt32 destNum = UInt32.Parse(pieces[1]);
                        toreturn.destination = destNum;
                    }
                    else if (line.IndexOf("best") >= 0)
                    {
                        currentlyReading = best;
                        int numRows = int.Parse(pieces[1]);
                        toreturn.Best = new List <UInt32> [numRows];
                    }
                    else if (line.IndexOf("l") >= 0)
                    {
                        currentlyReading = l;
                        int numRows = int.Parse(pieces[1]);
                        toreturn.L = new byte[numRows];
                    }
                }
                else
                {
                    int row, col;
                    switch (currentlyReading)
                    {
                    case buckettable:
                        row = int.Parse(pieces[0]);
                        col = int.Parse(pieces[1]);
                        toreturn.BucketTable[row][col] = new List <UInt32>();
                        for (int i = 2; i < pieces.Length; i++)
                        {
                            toreturn.BucketTable[row][col].Add(UInt32.Parse(pieces[i]));
                        }
                        break;

                    case best:
                        row = int.Parse(pieces[0]);
                        toreturn.Best[row] = new List <UInt32>();
                        for (int i = 1; i < pieces.Length; i++)
                        {
                            toreturn.Best[row].Add(UInt32.Parse(pieces[i]));
                        }
                        break;

                    case bestrelation:
                        for (int i = 0; i < pieces.Length; i++)
                        {
                            toreturn.BestRelation[i] = byte.Parse(pieces[i]);
                        }
                        break;

                    case l:
                        for (int i = 0; i < pieces.Length; i++)
                        {
                            toreturn.L[i] = byte.Parse(pieces[i]);
                        }
                        break;
                    }
                }
            }

            return(toreturn);
        }