Exemple #1
0
        public static void computeUtility(string[] commandPieces, resultObject Result)
        {
            //usage computeutility AS d iteration
            if (commandPieces.Length < 4)
            {
                Console.WriteLine("computeutility [ASN] [dest] [iteration]");
                return;
            }

            UInt32 ASN, dest;
            Int32 iter;
            if (!UInt32.TryParse(commandPieces[1], out ASN) || !UInt32.TryParse(commandPieces[2], out dest) || !Int32.TryParse(commandPieces[3], out iter))
            {
                Console.WriteLine("bad params");
                return;
            }
            if (iter > Result.state.Count)
            {
                Console.WriteLine("iteration too large.");
                return;
            }
            bool[] iterState = Result.state[iter];
            foreach (var stub in Result.g.getStubs())
                iterState[stub] = true;//turn on the stubs as in the sim
            SimulatorLibrary.setUtilityComputation(UtilityComputationType.outgoing);
            GlobalState initial = SimulatorLibrary.initGlobalState(Result.g, Result.earlyAdopters, Result.weightedNodes, short.Parse(Result.k));
            Destination d = new Destination(SimulatorLibrary.initMiniDestination(Result.g, dest, false));
            d.UpdatePaths(iterState);
            d.ComputeU(initial.W);
            Console.WriteLine("Utility for " + ASN + " in iteration: " + iter + " is " + d.U[ASN]);
            Worker w = new Worker();
               int afterFlip= w.ComputeUtility(d.BucketTable, d.Best, d.ChosenParent, d.SecP, iterState, ASN, d.L[ASN], d.BestRelation[ASN], initial.W);
            Console.WriteLine("Utility for " + ASN + " in iteration: " + iter + " if they flip is " +afterFlip);
        }
        public static void trafficThroughSecureProviders(resultObject results)
        {
            //get what the simulation state would look like.
            GlobalState GS = SimulatorLibrary.initGlobalState(results.g, results.earlyAdopters, results.weightedNodes, short.Parse(results.k));

            /** First, get a list of multihomed stubs as destinations **/
            var stubs=results.g.getStubs();
            List<UInt32> multihomedStubs = new List<UInt32>();
            foreach(UInt32 stubNum in stubs)
            {
                AsNode stub = results.g.GetNode(stubNum);
                //if this stub is multihomed, init a destination. add it to the list.
                if (stub.GetNeighborsByType(RelationshipType.CustomerOf).ToArray().Length > 1)
                    multihomedStubs.Add(stubNum);

            }

            Console.WriteLine(multihomedStubs.Count + " stubs out of " + stubs.Count + " are multihomed.");

            StreamWriter output = new StreamWriter("trafficThroughSecureProvider.txt");

            /** Second, go through each iteration... **/
            int iteration=0;
            foreach (bool[] S in results.state)
            {
                DateTime IterationStart = DateTime.Now;
                Int32 numDone = 0;
                foreach (UInt32 multihomedStubNum in multihomedStubs)
                {
                    /** for this multhomed stub, see how much traffic
                     * goes through secure providers **/
                    AsNode multihomedStub = results.g.GetNode(multihomedStubNum);
                    Destination multihomedStubDest = new Destination(SimulatorLibrary.initMiniDestination(results.g, multihomedStubNum, false));

                    //computer the paths and utilities.
                    multihomedStubDest.UpdatePaths(S);
                    multihomedStubDest.ComputeU(GS.W);

                    //get the providers.
                    var Providers = multihomedStub.GetNeighborsByType(RelationshipType.CustomerOf);

                    //count traffic through secure providers (and number of secure providers).
                    Int64 TotalU = 0;
                    Int64 SecureProviderU = 0;
                    Int32 TotalProviders = Providers.Count();
                    Int32 SecureProviders = 0;
                    foreach (var Provider in Providers)
                    {
                        if (S[Provider.NodeNum])
                        {
                            SecureProviderU += multihomedStubDest.U[Provider.NodeNum];
                            SecureProviders++;
                        }
                        TotalU += multihomedStubDest.U[Provider.NodeNum];
                    }

                    /*write out summary of how much traffic went through secure providers. */
               output.WriteLine(iteration + " :: " + multihomedStubNum + " " + SecureProviders + " " + TotalProviders + " " + SecureProviderU + " " + TotalU);
                    numDone++;
                    if ((numDone % 100) == 0)
                        Console.WriteLine("Done " + numDone + " at " + DateTime.Now);
                }
                //some benchmarking.
                Console.WriteLine(DateTime.Now + " done iteration " + iteration + " it started at " + IterationStart);

                iteration++;
            }

            output.Close();
        }
        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));
        }
Exemple #4
0
        private void runCompareU(List<UInt32> nonstubs,Destination d,ref Worker w,bool onlybenefit,ref GlobalState globalState)
        {
            if (d.BucketTable == null)
            {
                Console.WriteLine("null bucket table!");
                return;
            }
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Reset();
            stopwatch.Start();
            d.UpdatePaths(globalState.S);
            d.ComputeU(globalState.W);//just in case.
            stopwatch.Stop();

            foreach (UInt32 ASN in nonstubs)
            {
                if (d.Best[ASN] != null)//nonstub has a path to d
                {
                    int notASN = w.ComputeUtility(d.BucketTable, d.Best, d.ChosenParent, d.SecP, globalState.S, ASN, d.L[ASN], d.BestRelation[ASN], globalState.W);
                    if (!onlybenefit || d.U[ASN] < notASN)
                        Console.WriteLine(ASN + " :: " + d.U[ASN] + " : " + notASN);
                }
            }
            Console.WriteLine("update paths and compute u took: " + stopwatch.ElapsedMilliseconds + " ms");
        }
Exemple #5
0
        private bool initDestination(ref NetworkGraph g, ref Destination d,string command)
        {
            string resp;
            if (command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length < 2)
            {
                Console.WriteLine("Please enter a destination ASN: ");
                resp = Console.ReadLine();

            }
            else
                resp = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1];

            UInt32 destNum;
            if (!UInt32.TryParse(resp, out destNum))
            {
                Console.WriteLine("invalid ASN! ");
                return false;
            }
            if (g.GetNode(destNum) == null)
            {
                Console.WriteLine("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);//init paths with S = all false
             Console.WriteLine("done initializing. Current active destination is: " + destNum);
            List<UInt32> temp = new List<UInt32>();
            temp.Add(d.destination);
            d.BestNew[d.destination] = temp;
            //Console.Write("Dest BestNew["+ d.destination + "] = " + d.BestNew[d.destination][0]);
            return true;
        }
        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]));
                }
            }
        }
        /// <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");
        }