Exemplo n.º 1
0
        private void getpath(string[] pieces)
        {
            if (pieces.Length < 3)
               return;

               uint as1, as2;
               if (!uint.TryParse(pieces[1], out as1) || !uint.TryParse(pieces[2], out as2))
               {
               return;
               }

               if (g.GetNode(as1) == null || g.GetNode(as2) == null)
               return;

               Destination as2_dst = new Destination(SimulatorLibrary.initMiniDestinationSP(g, as2, false));
               bool[] dummyS = new bool[Constants._numASNs];
               as2_dst.UpdatePaths(dummyS);
               Console.WriteLine("shortest path:");
               Console.WriteLine(as2_dst.GetPath(as1,g));
               Console.WriteLine("regular path:");
               as2_dst = new Destination(SimulatorLibrary.initMiniDestination(g, as2, false));
               as2_dst.UpdatePaths(dummyS);
               Console.WriteLine(as2_dst.GetPath(as1));
        }
Exemplo n.º 2
0
        public string pathAnalysis(string path, ref Destination dest, ref TextWriter Missing, ref TextWriter randomFile, ref TextWriter ViolationType)
        {
            int pathExists;
            int pathViolate = 0;
            int GR = 0;
            int bestrln = 0;
            int bestrlnHop = 0;
            int shortest = 0;
            int shortestHop = 0;
            int shortestLen = 0;
            int bucket;
            List<UInt32> relPath = new List<UInt32>();

            //Check if path exists from best new and make a relPath
            string[] asPath = path.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            UInt32 AS;
            UInt32.TryParse(asPath[0], out AS);

            if (dest.BestNew[AS] != null)
            {
                pathExists = 1;
                UInt32 first = (UInt32)((AS << 3) + Destination._NOREL);
                relPath.Add(first);

                for (int i = 0; i < (asPath.Length - 1); i++)
                {
                    int asNum, asTo;
                    int.TryParse(asPath[i], out asNum);
                    int.TryParse(asPath[i + 1], out asTo);

                    if (dest.BestNew[asNum] != null)
                    {
                        UInt32 encoded0 = (UInt32)((asTo << 3) + Destination._PROVIDERCOLUMN);
                        UInt32 encoded1 = (UInt32)((asTo << 3) + Destination._CUSTOMERCOLUMN);
                        UInt32 encoded2 = (UInt32)((asTo << 3) + Destination._PEERCOLUMN);
                        UInt32 encoded3 = (UInt32)((asTo << 3) + Destination._NOREL);

                        if (dest.BestNew[asNum].Exists(element => element == encoded0))
                        {
                            relPath.Add(encoded0);
                        }
                        else if (dest.BestNew[asNum].Exists(element => element == encoded1))
                        {
                            relPath.Add(encoded1);
                        }
                        else if (dest.BestNew[asNum].Exists(element => element == encoded2))
                        {
                            relPath.Add(encoded2);
                        }
                        else if (dest.BestNew[asNum].Exists(element => element == encoded3))
                        {
                            relPath.Add(encoded3);
                        }
                        else
                        {
                            pathExists = 0;
                            break;
                        }

                        // Now do perform a sanity check
                        int size = relPath.Count;
                        int rel, prevRel;
                        UInt32 temp;
                        dest.unjoin(relPath[size-1], out temp, out rel);
                        dest.unjoin(relPath[size-2], out temp, out prevRel);

                        if ((rel == Destination._PEERCOLUMN && prevRel == Destination._CUSTOMERCOLUMN) || (prevRel == Destination._PEERCOLUMN && rel == Destination._PROVIDERCOLUMN) || (prevRel == Destination._PEERCOLUMN && rel == Destination._PEERCOLUMN) || (prevRel == Destination._CUSTOMERCOLUMN && (rel == Destination._PEERCOLUMN || rel == Destination._PROVIDERCOLUMN)))
                        {
                            pathViolate = 1;
                            pathExists = 0;
                            ViolationType.WriteLine(pathString(relPath));
                            ViolationType.Flush();
                            break;
                        }
                    }
                    else
                    {
                        pathExists = 0;
                        break;
                    }
                }
            }
            else
            {
                pathExists = 0;
            }

            //Check hop count for missing link
            /*
            if(pathExists == 0)
            {
                int hopsfromend = 0, hopsfromstart = 0;
                string tempPath = "";

                for (int i = 1; i < asPath.Length; i++)
                {
                    tempPath = "";
                    for (int j = asPath.Length - i; j < asPath.Length; j++)
                    {
                        if (j == (asPath.Length - 1))
                        { tempPath = tempPath + asPath[j]; }
                        else { tempPath = tempPath + asPath[j] + ","; }
                    }

                    //Check if path exists
                    if(!pathAvailable(tempPath, dest.BestNew))
                    {
                        hopsfromend = i;
                        hopsfromstart = asPath.Length - i;
                        break;
                    }
                    else
                    {
                        hopsfromend = i;
                        hopsfromstart = asPath.Length - i;
                    }
                }

                Missing.WriteLine(hopsfromstart + " " + hopsfromend);
                Missing.Flush();
            }
            */

            //GR path and compare
            string GR_string = dest.GetPathCommaSep(AS);
            if (pathAvailable_GR(path, ref dest.Best) && (pathExists == 1))
            {
                GR = 1;
            }

            //if not GR check for best rel
            if ((GR == 0) && (pathExists == 1))
            {
                bestrln = 1;
                for (int j = 0; j < (relPath.Count - 1); j++)
                {
                    UInt32 fromAS, tempAS;
                    int rel, temprel, bestRelation;
                    dest.unjoin(relPath[j], out fromAS, out temprel);
                    dest.unjoin(relPath[j+1], out tempAS, out rel);

                    bestRelation = bestrel(fromAS, ref dest);

                    if (bestRelation == -1) { throw new Exception(); }

                    if (rel > bestRelation)
                    {
                        bestrln = 0;
                        break;
                    }

                }
            }

            //checking for bestRl for first hop
            if (1 == 1) {
                bestrlnHop = 1;
                UInt32 fromAS, tempAS;
                int rel, temprel, bestRelation;
                dest.unjoin (relPath [0], out fromAS, out temprel);
                dest.unjoin (relPath [1], out tempAS, out rel);

                bestRelation = bestrel (fromAS, ref dest);

                if (bestRelation == -1) {
                    throw new Exception ();
                }

                if (rel > bestRelation) {
                    bestrlnHop = 0;
                }
            }

            //Check for shortest
            if ((GR == 0) && (bestrln == 0) && (pathExists == 1)) {
                shortest = 1;
                shortestLen = asPath.Length -1; // to correct for the next comment
                for (int i = 1; i < asPath.Length-1; i++) { //i=1 essentially means checking for path length 2, therefore the -1
                    List<List<UInt32>> allPaths = new List<List<UInt32>> ();
                    List<UInt32> pathNew = new List<UInt32> ();
                    UInt32 first = (UInt32)((AS << 3) + Destination._NOREL);
                    pathNew.Add (first);
                    //Console.Out.WriteLine("Checking length: " + i);
                    if (dest.pathoflength (AS, dest.destination, ref allPaths, pathNew, i)) {
                        shortest = 0;
                        shortestLen = i;
                        if (shortestLen == 1) {
                            shortest = 1;
                        }
                        //Console.Out.WriteLine ("Path length: " + asPath.Length);
                        //Console.Out.WriteLine(i + " shortest: " + shortest+ " B KA: " + allPaths.Count + " " + dest.pathString(allPaths[0]));
                        break;
                    }
                }
            } else { // Added to compute shortest lenght path for all buckets and for per hop shortest
                shortestLen = asPath.Length-1;
                for (int i = 1; i < asPath.Length; i++) {
                    List<List<UInt32>> allPaths = new List<List<UInt32>> ();
                    List<UInt32> pathNew = new List<UInt32> ();
                    UInt32 first = (UInt32)((AS << 3) + Destination._NOREL);
                    pathNew.Add (first);
                    //Console.Out.WriteLine ("Checking : " + i);
                    if (dest.pathoflength (AS, dest.destination, ref allPaths, pathNew, i)) {
                        shortestLen = i;
                        break;
                    }
                }
            }

            shortestLen = shortestLen + 1; //shortestLen is now the number of AS in shortest path

            if (shortestLen == asPath.Length) {
                shortestHop = 1;
            }

            //space seperated: path bucket
            //bucket -1 -> Export Violation
            //bucket  0 -> Missing Link
            //bucket  1 -> GR
            //bucket  2 -> Best Relation
            //bucket  3 -> Shortest
            //bucket  4 -> None but doesnt violate export

            if (pathExists == 1)
            {
                if (GR == 1)
                {
                    bucket = 1;
                }
                else if (bestrln == 1)
                {
                    bucket = 2;
                }
                else if (shortest == 1)
                {
                    bucket = 3;
                }
                else
                {
                    bucket = 4;
                    //Console.WriteLine("Difference: " + (asPath.Length - shortestLen) + "\n Length: " + asPath.Length + "\nShortest: " + shortestLen);
                    //ShortestDiff.WriteLine((asPath.Length - shortestLen));
                    //ShortestDiff.Flush();
                }
            }
            else
            {
                if (pathViolate == 1)
                {
                    bucket = -1;
                }
                else
                {
                    bucket = 0;
                }
            }
            //Console.Out.WriteLine(path + " " + bucket);
            // Format: Original Path | Bucket | GR Path | Shortest Length | lastHop info : BestRln+Shortest
            randomFile.WriteLine(dest.pathString(relPath) + "|" + bucket + "|" + dest.GetPath(AS) + "|" + shortestLen + "|" + bestrlnHop + "" + shortestHop);
            randomFile.Flush();
            //Console.WriteLine("Path: " + dest.pathString(relPath) + "\n" + GR_string + "    Exitsts: " + pathExists + "    GR: " + GR + "    BestReln: "+ bestrln + "     Shortest: " + shortest + "    Violate: " + pathViolate + "\n");
            return path + " " + bucket;
        }
Exemplo n.º 3
0
        private bool all_path_info(ref List<Destination> ds, ref NetworkGraph graph, string command)
        {
            TextWriter tw = new StreamWriter("decoy/all_path_info.txt");
            string[] cpieces = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (cpieces.Length < 2)
            {
                Console.WriteLine("error: usage all_path_info <dstnum>");
                return false;
            }

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

            Destination newD = new Destination();
            if (initDestination (ref graph, ref newD, "destination " + dstNum)) {
                ds.Add (newD);
                Console.WriteLine ("HN: initialized and added " + newD.destination);
            } else {
                Console.WriteLine ("could not find destination");
                return false;
            }

            var lines = File.ReadAllLines("decoy/all_asn.txt");
            foreach (var line in lines)
            {
                UInt32 ASN = Convert.ToUInt32(line);
                tw.WriteLine(ASN + " " + newD.GetPath(ASN));
            }
            return true;
        }
Exemplo n.º 4
0
        private bool getPath(ref List<Destination> ds, ref NetworkGraph graph, string command)
        {
            string[] cpieces = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (cpieces.Length < 3)
            {
                Console.WriteLine("error: usage getpath <as#> <dstnum>");
                return false;
            }

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

            foreach (Destination d in ds)
            {
                if (d.destination == dstNum)
                {
                    //d.Best[0]++;

                    Console.WriteLine("Path from " + ASN + " to " + d.destination + " is " + d.GetPath(ASN));
                    return true;
                }
            }

            //Added by Haseeb *Computes destination so getPath doesnt return false if the destination is not initialised before calling getPath

            Destination newD = new Destination();
            if (initDestination(ref graph, ref newD, "destination " + dstNum))
            {
                ds.Add(newD);
                Console.WriteLine("HN: initialized and added " + newD.destination);

                //newD.Best[0]++;

                Console.WriteLine("HN: Path from " + ASN + " to " + newD.destination + " is " + newD.GetPath(ASN));
                return true;
            }

            Console.WriteLine("could not find destination");
            return false;
        }
Exemplo n.º 5
0
        public void getPath(string[] commandPieces)
        {
            if (commandPieces.Length < 3)
            {
                Console.WriteLine("usage: getpath [Source ASN] [Dest ASN] [iteration? default will be to print all of them.]");
                return;
            }
            UInt32 SASN,DASN;
            if (!UInt32.TryParse(commandPieces[1], out SASN) || !UInt32.TryParse(commandPieces[2], out DASN))
            {
                Console.WriteLine("malformed ASN");
                return;
            }
            int iteration = results.state.Count ;
            if (commandPieces.Length > 3)
            {
                int.TryParse(commandPieces[3], out iteration);
            }

            Destination D = new Destination(SimulatorLibrary.initMiniDestination(results.g, DASN, false));
            if (D.Best[SASN] == null)
            {
                Console.WriteLine(SASN + " has no path to " + DASN);
                return;
            }

            if (iteration < results.state.Count)
            {
                D.UpdatePaths(results.state[iteration]);
                Console.WriteLine(D.GetPath(SASN, results.state[iteration]));
            }
            else
            {
                for (iteration = 0; iteration < results.state.Count; iteration++)
                {
                    D.UpdatePaths(results.state[iteration]);
                    Console.WriteLine(iteration+" : "+D.GetPath(SASN, results.state[iteration]));
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// given an ASN tells which of it's stub neighbors experienced path changed because of their flip.
        /// prints these paths. 
        /// </summary>
        /// <param name="commandPieces"></param>
        public void whosePathChanged(string[] commandPieces)
        {
            if (commandPieces.Length < 2)
            {
                Console.WriteLine("usage: whosePathChanges [ASN] [path from?ASN]");
                return;
            }
            if (commandPieces[1] == "help")
            {
                Console.WriteLine("tells you the paths through this ASN from the source to this ASN's stub neighbors (that were on before this ASN flipped) that changed when this ASN turned on. If you don't give a source ASN it will use the set of early adopters as sources.");
            }
            UInt32 ASN;
            if (!UInt32.TryParse(commandPieces[1], out ASN))
            {
                Console.WriteLine("malformed ASN");
                return;
            }
            AsNode ASNode;
            if ((ASNode = results.g.GetNode(ASN)) == null)
            {
                Console.WriteLine("This node was not in the graph");
                return;
            }
            List<UInt32> sourceNodes=results.earlyAdopters;
            if (commandPieces.Length > 2 && commandPieces[2]!= "neighbors" &&commandPieces[2]!="customers"
                && commandPieces[2] != "tier1" && commandPieces[2] != "big5")
            {
                UInt32 ASN2;
                if (!UInt32.TryParse(commandPieces[2], out ASN2))
                {
                    Console.WriteLine("malformed source ASN");
                    return;
                }
                AsNode ASNode2;
                if ((ASNode2 = results.g.GetNode(ASN2)) == null)
                {
                    Console.WriteLine("The source AS was not in the graph");
                 return;
                }
                sourceNodes=new List<uint>();
                sourceNodes.Add(ASN2);
            }

            if (results.state[results.state.Count - 1][ASN] == false)
            {
                Console.WriteLine("ASN: " + ASN + " never flipped.");
             return;
            }
             //this node flipped,figure out which iteration.
                int flippedIter = -1;
                for (int i = 0; flippedIter < 0 && i < results.state.Count; i++)
                {
                    if (results.state[i][ASN])
                        flippedIter = i;
                }

            if(flippedIter ==0)
            {
                Console.WriteLine("ASN: "+ASN +" was on to begin with.");
                return;
            }
            List<UInt32> stubs = results.g.getStubs();
            var customers = ASNode.GetNeighborsByType(RelationshipType.ProviderTo);
            if (commandPieces.Length > 2)
            {
                if (commandPieces[2] == "neighbors")
                {
                    sourceNodes = new List<uint>();
                    foreach (var neighbor in ASNode.GetAllNeighbors())
                        sourceNodes.Add(neighbor.NodeNum);
                }
                if (commandPieces[2] == "customers")
                {
                    sourceNodes = new List<uint>();
                    foreach (var customer in customers)
                        sourceNodes.Add(customer.NodeNum);
                }
                if (commandPieces[2] == "big5")
                {
                    sourceNodes = new List<uint>();
                    sourceNodes.Add(15169);
                    sourceNodes.Add(8075);
                    sourceNodes.Add(32934);
                    sourceNodes.Add(20940);
                    sourceNodes.Add(22822);
                }
                if (commandPieces[2] == "tier1")
                {
                    sourceNodes = new List<uint>();
                    sourceNodes.Add(1239);
                    sourceNodes.Add(701);
                    sourceNodes.Add(7018);
                    sourceNodes.Add(174);
                    sourceNodes.Add(3356);
                }
            }

            Console.WriteLine("computing paths through " + ASN + " to its neighbors from : ");
            foreach (var sn in sourceNodes)
                Console.Write(sn + ", ");
            Console.WriteLine("\nthat change when "+ASN+" flipped. This may take some time. " + ASN + " has " + ASNode.GetAllNeighbors().Count() + " neighbors.");

            double progressMeter = 0.05;//variable to print out messages of progress.
            int doneNeighbors = 0;//same deal.
            int numPathsChanged = 0;
            int numPathsChangedOnSource = 0;
            List<UInt32> neighborsChangedFor = new List<uint>();
            List<UInt32> neighborsChangedForOnSource = new List<uint>();
            List<UInt32> sourcesChanged = new List<uint>();
            List<UInt32> sourcesChangedOnSource = new List<uint>();

            /** going to iterate over customers of this node that were on before this node flipped (or were stubs), ie. they were
             * a potential motivator for the flip. does this node actually gain their traffic? **/
            foreach (var neighbor in customers)
            {
                /** If this node was on before (ie. they would change their decision to the secure parent now)
                 * and they were a stub (just for ease of understanding for now)**/
                if (results.state[flippedIter - 1][neighbor.NodeNum] || stubs.Contains(neighbor.NodeNum))
                {
                    List<UInt32[]> pathsBefore = new List<uint[]>();
                    List<UInt32[]> pathsAfter = new List<uint[]>();
                    List<string> pathsBeforeStrings = new List<string>();
                    List<string> pathsAfterStrings = new List<string>();

                    Destination d = new Destination(SimulatorLibrary.initMiniDestination(results.g, neighbor.NodeNum, false));

                    //paths before the AS flipped (from early adopters to this stub.)
                    d.UpdatePaths(results.state[flippedIter - 1]);

                    foreach (var bigASN in sourceNodes)
                    {
                        if (bigASN != d.destination)
                        {

                            pathsBefore.Add(d.GetPathList(bigASN));//path from bigASN to the stub.
                            pathsBeforeStrings.Add(d.GetPath(bigASN, results.state[flippedIter - 1]));
                        }
                        else
                        {//dummy vals. this source is the destination.
                            pathsBefore.Add(new UInt32[0]);
                            pathsBeforeStrings.Add("");
                        }
                    }
                    //paths after AS flipped.
                    d.UpdatePaths(results.state[flippedIter]);
                    foreach (var bigASN in sourceNodes)
                    {
                        if (bigASN != d.destination)
                        {
                            pathsAfter.Add(d.GetPathList(bigASN));
                            pathsAfterStrings.Add(d.GetPath(bigASN, results.state[flippedIter]));
                        }
                        else
                        {
                            //dummy vals. this source is the destination.
                            pathsAfter.Add(new UInt32[0]) ;
                            pathsAfterStrings.Add("");
                        }
                    }

                    for (int i = 0; i < sourceNodes.Count; i++)
                    {
                        var bigASN = sourceNodes[i];
                        if (bigASN != d.destination)
                        {
                            var pathBefore = pathsBefore[i];
                            var pathAfter = pathsAfter[i];
                            bool pathChanged = false;
                            for (int j = 0; j < pathBefore.Length; j++)
                            {
                                if (pathBefore[j] != pathAfter[j])
                                    pathChanged = true;
                            }

                            if (pathChanged)
                            {
                                if (pathsBeforeStrings[i].IndexOf(ASN.ToString()) >= 0 || pathsAfterStrings[i].IndexOf(ASN.ToString()) >= 0)
                                {

                                    numPathsChanged++;
                                    if (!neighborsChangedFor.Contains(neighbor.NodeNum))
                                        neighborsChangedFor.Add(neighbor.NodeNum);
                                    if (!sourcesChanged.Contains(bigASN))
                                        sourcesChanged.Add(bigASN);
                                    //the path after must have been fully secure save for the guy who flipped. and the path before cannot contain the guy who flipped.
                                    if (fullySecure(pathsAfter[i],ASNode.NodeNum,results.state[flippedIter-1],stubs) && !pathsBefore[i].Contains(ASNode.NodeNum))
                                    {
                                        Console.WriteLine("---");
                                        Console.WriteLine("Path from: " + bigASN + " to " + neighbor.NodeNum + " changed from: ");
                                        Console.WriteLine(pathsBeforeStrings[i]);
                                        Console.WriteLine("to: ");
                                        Console.WriteLine(pathsAfterStrings[i]);
                                        Console.WriteLine("---");

                                        numPathsChangedOnSource++;
                                        if (!neighborsChangedForOnSource.Contains(neighbor.NodeNum))
                                            neighborsChangedForOnSource.Add(neighbor.NodeNum);
                                        if (!sourcesChangedOnSource.Contains(bigASN))
                                            sourcesChangedOnSource.Add(bigASN);
                                    }
                                }
                            }
                        }
                    }
                    doneNeighbors++;
                    if (doneNeighbors > customers.Count() * (progressMeter))
                    {
                        Console.WriteLine(progressMeter * 100 + "% done.");
                        progressMeter += 0.05;

                    }
                }
            }
            Console.WriteLine(numPathsChanged + " paths changed. to " + neighborsChangedFor.Count + " customers from " + sourcesChanged.Count + " sources");
            Console.WriteLine(numPathsChangedOnSource + " paths changed and had the source on before. these went to " + neighborsChangedForOnSource.Count + " customers from "+sourcesChangedOnSource.Count+ " sources");
        }