Beispiel #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));
        }
Beispiel #2
0
        public static void traverseDoD(NetworkGraph g)
        {
            //starting at 721 print out providers to DoD people.

            AsNode         DoDMain       = g.GetNode(721);
            List <UInt32>  DoDProviders  = new List <UInt32>();
            List <UInt32>  DoDPeers      = new List <UInt32>();
            List <UInt32>  DoDASNs       = new List <UInt32>();
            Queue <UInt32> ASesToProcess = new Queue <UInt32>();

            DoDASNs.Add(721);
            ASesToProcess.Enqueue(721);


            while (ASesToProcess.Count > 0)
            {
                AsNode curr = g.GetNode(ASesToProcess.Dequeue());
                Console.WriteLine("Processing: " + curr.NodeNum);
                foreach (var provider in curr.GetNeighborsByType(RelationshipType.CustomerOf))
                {
                    if (!DoDASNs.Contains(provider.NodeNum) && !DoDProviders.Contains(provider.NodeNum))
                    {
                        DoDProviders.Add(provider.NodeNum);
                        Console.WriteLine(curr.NodeNum + " has non-DoD provider: " + provider.NodeNum);
                        Console.ReadLine();
                    }
                }
                foreach (var customer in curr.GetNeighborsByType(RelationshipType.ProviderTo))
                {
                    if (!DoDASNs.Contains(customer.NodeNum) && !ASesToProcess.Contains(customer.NodeNum))
                    {
                        ASesToProcess.Enqueue(customer.NodeNum);
                        DoDASNs.Add(customer.NodeNum);
                    }
                }
                foreach (var peer in curr.GetNeighborsByType(RelationshipType.PeerOf))
                {
                    if (!DoDASNs.Contains(peer.NodeNum))
                    {
                        DoDPeers.Add(peer.NodeNum);
                    }
                }
            }

            Console.WriteLine("DoDProviders: ");
            foreach (var provider in DoDProviders)
            {
                if (!DoDASNs.Contains(provider))
                {
                    Console.Write(provider + ", ");
                }
            }
            Console.WriteLine();
            Console.WriteLine("DoDPeers: ");
            foreach (var peer in DoDPeers)
            {
                Console.Write(peer + ", ");
            }
            Console.WriteLine();
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public static void neverOn(string[] commandPieces)
        {
            string[]      ResultDirs = Directory.GetDirectories(ResultsExplorer.defaultResultsDirectory);
            List <UInt32> neverOn    = new List <UInt32>();
            StreamWriter  output     = new StreamWriter(Console.OpenStandardOutput());

            if (commandPieces.Length > 1)
            {
                output.Close();
                output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[1]);
            }
            bool includestubs = false;

            if (commandPieces.Length > 2 && commandPieces[2].IndexOf("stubs") >= 0)
            {
                includestubs = true;
            }
            NetworkGraph g = new NetworkGraph();

            foreach (var reDir in ResultDirs)
            {
                if (File.Exists(reDir + "\\params.txt"))
                {
                    resultObject curr = ResultsExplorer.readParamsFile(reDir + "\\params.txt");
                    double       u    = -1;
                    int          f    = -1;
                    int          k    = -1;
                    double.TryParse(curr.u, out u);
                    int.TryParse(curr.f, out f);
                    int.TryParse(curr.k, out k);
                    if (u == 0 && f == 0 && k == 9)//for simplicity vanilla graph + k=9
                    {
                        if (File.Exists(reDir + "\\" + curr.precursor + ".S200000.csv"))
                        {
                            curr.state = ResultsExplorer.readStateFromFile(reDir + "\\" + curr.precursor + ".S200000.csv");
                        }
                        if (neverOn.Count == 0)//init the set of nodes that are never on if needed.
                        {
                            if (File.Exists(ResultsExplorer.defaultGraphDirectory + curr.graphFile))
                            {
                                InputFileReader ifr = new InputFileReader(ResultsExplorer.defaultGraphDirectory + curr.graphFile, g);
                                ifr.ProcessFile();
                            }
                            var nonstubs = g.getNonStubs();
                            foreach (var n in g.GetAllNodes())
                            {
                                if (includestubs || nonstubs.Contains(n.NodeNum))
                                {
                                    neverOn.Add(n.NodeNum);
                                }
                            }
                        }

                        //go through and remove anyone we saw as on from the set of nodes that are never on.
                        bool[] lastState = curr.state[curr.state.Count - 1];
                        for (int i = 0; i < lastState.Length; i++)
                        {
                            if (lastState[i])
                            {
                                if (neverOn.Contains((UInt32)i))
                                {
                                    neverOn.Remove((UInt32)i);
                                }
                            }
                        }
                    }
                }
            }
            foreach (var no in neverOn)
            {
                output.WriteLine(no);
            }
            output.Close();

            double avgDegreeOfNeverOn = 0;

            foreach (var no in neverOn)
            {
                double deg = g.GetNode(no).GetAllNeighbors().Count();
                avgDegreeOfNeverOn += deg;
            }

            avgDegreeOfNeverOn /= neverOn.Count;

            Console.WriteLine(neverOn.Count + " nodes never turn on. their average degree is " + avgDegreeOfNeverOn);
            /** See who has competition **/
            List <UInt32> haveCompetition = new List <UInt32>();

            foreach (var no in neverOn)
            {
                var alwaysOffNode = g.GetNode(no);
                var customers     = alwaysOffNode.GetNeighborsByType(RelationshipType.ProviderTo);
                foreach (var c in customers)
                {
                    var providers = c.GetNeighborsByType(RelationshipType.CustomerOf);
                    if (providers.Count() > 1 && !haveCompetition.Contains(no))//this customer of the never on guy has more than 1 provider. this never on guy had competition.
                    {
                        haveCompetition.Add(no);
                    }
                }
            }
            //convert from list of nodes with competition to nodes without competition.
            List <UInt32> nocompetition = new List <uint>();

            foreach (var no in neverOn)
            {
                if (!haveCompetition.Contains(no))
                {
                    nocompetition.Add(no);
                }
            }
            Console.WriteLine(nocompetition.Count + " of these guys had no competition for their customers.");

            /** See who is next to ASes with no competition **/
            List <UInt32> nexttonocompetition = new List <UInt32>();

            foreach (var no in neverOn)
            {
                if (!nocompetition.Contains(no))
                {
                    //this guy had competition. see if he is connected to someone without competition.
                    var alwaysOffNode = g.GetNode(no);
                    foreach (var neighbor in alwaysOffNode.GetAllNeighbors())
                    {
                        if (nocompetition.Contains(neighbor.NodeNum) && !nexttonocompetition.Contains(no))
                        {
                            nexttonocompetition.Add(no);
                        }
                    }
                }
            }
            Console.WriteLine(nexttonocompetition.Count + " of the remaining " + haveCompetition.Count + " ASes are next to one with no competition.");
            output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + "neveron-withcomp.txt");
            List <UInt32> withCompetitionNotNextToNoCompetition = new List <UInt32>();

            foreach (var asn in haveCompetition)
            {
                if (!nexttonocompetition.Contains(asn))
                {
                    output.WriteLine(asn);
                    withCompetitionNotNextToNoCompetition.Add(asn);
                }
            }
            output.Close();

            /** See which of the remaining ASes are a part of the "jump level" topology **/
            List <UInt32> inJumpLevel = new List <uint>();

            foreach (var asn in withCompetitionNotNextToNoCompetition)
            {
                var           alwaysOffNode = g.GetNode(asn);
                var           providers     = alwaysOffNode.GetNeighborsByType(RelationshipType.CustomerOf);
                List <UInt32> providerASNs  = new List <uint>();
                foreach (var p in providers)
                {
                    providerASNs.Add(p.NodeNum);
                }
                foreach (var c in alwaysOffNode.GetNeighborsByType(RelationshipType.ProviderTo))
                {
                    var customersProviders = c.GetNeighborsByType(RelationshipType.CustomerOf);
                    foreach (var cP in customersProviders)
                    {
                        if (providerASNs.Contains(cP.NodeNum) && !inJumpLevel.Contains(asn))
                        {
                            inJumpLevel.Add(asn);
                        }
                    }
                }
            }
            output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + "neveron-nojumplevel.txt");
            foreach (var asn in withCompetitionNotNextToNoCompetition)
            {
                if (!inJumpLevel.Contains(asn))
                {
                    output.WriteLine(asn);
                }
            }
            output.Close();
            /** to be continued***/
            Console.WriteLine(inJumpLevel.Count + " of the remaining " + withCompetitionNotNextToNoCompetition.Count + " ASes are in jump level topologies");
        }
        private static List <UInt32> stubsThroughMeIncrease(List <UInt32> sourceNodes, UInt32 ASN, List <bool[]> state, NetworkGraph g, StreamWriter output)
        {
            var stubs = g.getStubs();

            var ASNode = g.GetNode(ASN);

            //this node flipped,figure out which iteration.
            int flippedIter = -1;

            for (int i = 0; flippedIter < 0 && i < state.Count; i++)
            {
                if (state[i][ASN])
                {
                    flippedIter = i;
                }
            }

            if (flippedIter == 0)
            {
                Console.WriteLine("ASN: " + ASN + " was on to begin with.");
                return(new List <UInt32>());
            }

            //one variable per source node counting how many stubs of mine
            //route through me from this source now.
            List <UInt32> newCustomerPathsPerSourceNode = new List <UInt32>();

            for (int i = 0; i < sourceNodes.Count; i++)
            {
                newCustomerPathsPerSourceNode.Add(0);
            }


            foreach (var customer in ASNode.GetNeighborsByType(RelationshipType.ProviderTo))
            {
                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(g, customer.NodeNum, false));
                //paths before the AS flipped (from early adopters to this stub.)
                d.UpdatePaths(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, state[flippedIter - 1]));
                    }
                    else
                    {//dummy vals. this source is the destination.
                        pathsBefore.Add(new UInt32[0]);
                        pathsBeforeStrings.Add("");
                    }
                }
                //paths after AS flipped.
                d.UpdatePaths(state[flippedIter]);
                foreach (var bigASN in sourceNodes)
                {
                    if (bigASN != d.destination)
                    {
                        pathsAfter.Add(d.GetPathList(bigASN));
                        pathsAfterStrings.Add(d.GetPath(bigASN, 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)
                            {
                                //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 (ResultsExplorer.fullySecure(pathsAfter[i], ASNode.NodeNum, state[flippedIter - 1], stubs) && !pathsBefore[i].Contains(ASNode.NodeNum))
                                {
                                    /** Console.WriteLine("---");
                                     * Console.WriteLine("Path from: " + bigASN + " to " + customer.NodeNum + " changed from: ");
                                     * Console.WriteLine(pathsBeforeStrings[i]);
                                     * Console.WriteLine("to: ");
                                     * Console.WriteLine(pathsAfterStrings[i]);
                                     * Console.WriteLine("---");
                                     **///don't be verbose.

                                    newCustomerPathsPerSourceNode[i]++;
                                }
                            }
                        }
                    }
                }
                //put progress meter here
            }

            return(newCustomerPathsPerSourceNode);
        }