Beispiel #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();
        }
Beispiel #3
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");
        }