예제 #1
0
        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();
        }
예제 #2
0
 private List<long[]> readUTable(resultObject Params, string ufile)
 {
     if (!File.Exists(Params.directory + Params.precursor + "." + ufile))
     {
         Console.WriteLine("error could not find utilities file: " + Params.directory + "." + Params.precursor + "." + ufile);
         return null;
     }
     List<long[]> UTable = new List<long[]>();
     StreamReader input = new StreamReader(Params.directory  + Params.precursor + "." + ufile);
     while (!input.EndOfStream)
         UTable.Add(lineToUtilities(input.ReadLine()));
     input.Close();
     return UTable;
 }
예제 #3
0
        public static resultObject readParamsFile(string paramsFile)
        {
            StreamReader input = new StreamReader(paramsFile);
            resultObject toreturn = new resultObject();

            while (!input.EndOfStream)
            {
                string line = input.ReadLine();
                string[] pieces = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                if (line.IndexOf("setutility") >= 0)
                {
                    //line pertaining to setting the utility computation
                    if (pieces.Length > 1)
                        toreturn.utility = pieces[1];
                }
                else if (line.IndexOf("Early adopters:") >= 0)
                {

                    toreturn.earlyAdopters = new List<uint>();
                    for (int i = 2; i < pieces.Length; i++)
                    {
                        UInt32 curr;
                        if (uint.TryParse(pieces[i].Replace(",",""), out curr))
                            toreturn.earlyAdopters.Add(curr);

                    }

                }
                else if (line.IndexOf("Filename") >= 0)
                {
                    toreturn.graphFile = pieces[1].ToLower();
                    if (toreturn.graphFile == "cyclops_2009_ixp.txt" ||
                        toreturn.graphFile == "cyclops_20101209_ixp.txt" ||
                        toreturn.graphFile=="cyclopsixp20101209-big5-nochildren.txt")
                    {
                        toreturn.f = "0";
                    }
                    else
                    {
                        //filename looks like: cyclopsixp2009-big5-0.1.txt
                        if (toreturn.graphFile.IndexOf("ixpsmart") < 0)
                        {
                            pieces = toreturn.graphFile.Split("-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                            toreturn.f = pieces[2];
                        }
                        else
                            toreturn.f = "0.8";

                    }

                }
                else if (line.IndexOf("OutputDir") >= 0)
                {
                    //contains the directory tag. use this to derive
                    //the precursor for the standard filenames
                    toreturn.precursor = pieces[1].Substring(0, 20);

                }
                else if (line.IndexOf("percent") >= 0)
                {
                    //line setting the utility fraction
                    toreturn.u = pieces[1];
                }
                else if (line.IndexOf("K") >= 0)
                {
                    //line setting the K value
                    toreturn.k = pieces[1];
                }
                else if (line.IndexOf("Weighted Nodes:") >= 0)
                {
                    toreturn.weightedNodes = new List<uint>();
                    for (int i = 2; i < pieces.Length; i++)
                    {
                        UInt32 curr;
                        if (uint.TryParse(pieces[i].Replace(",",""), out curr))
                            toreturn.weightedNodes.Add(curr);

                    }

                }

            }

            input.Close();
            return toreturn;
        }
예제 #4
0
        private List<bool[]> postProcessState(List<bool[]> unprocessedState, resultObject Params)
        {
            List<UInt32> big5 = new List<uint>();
            big5.Add(22822);
            big5.Add(8075);
            big5.Add(15169);
            big5.Add(20940);
            big5.Add(32934);

            List<bool[]> processedState = new List<bool[]>();
            string graphFile = graphDirectory + Params.graphFile;
            if (!File.Exists(graphFile))
                Console.WriteLine("I could not find the graph file: " + graphFile);

            NetworkGraph g = new NetworkGraph();
            InputFileReader ifr = new InputFileReader(graphFile, g);
            ifr.ProcessFile();

            List<UInt32> stubs = g.getStubs();

            /*** Process and add the initial state of the simulation ***/
            bool[] initialState = SimulatorLibrary.initGlobalState(g, Params.earlyAdopters).S;

            //walk over stubs and re-evaluate their state.
            foreach (UInt32 AS in stubs)
            {
                if (!big5.Contains(AS))
                {
                    AsNode node = g.GetNode(AS);
                    initialState[AS] = false;//default to false for this stub.
                    var parents = node.GetNeighborsByType(RelationshipType.CustomerOf).ToList<AsNode>();
                    // parents.AddRange(node.GetNeighborsByType(RelationshipType.PeerOf)); //don't turn on for peers
                    foreach (AsNode parent in parents)
                    {
                        if (initialState[parent.NodeNum])
                        {//parent is true let it be true in the augmented state.
                            initialState[AS] = true;
                            break;
                        }

                    }
                }

            }
            foreach (var AS in Params.earlyAdopters)
                initialState[AS] = true;//make sure early adopters are "on"

            processedState.Add(initialState);

            for (int i = 0; i < unprocessedState.Count; i++)
            {

                bool[] currS = unprocessedState[i];
                //walk over stubs and re-evaluate their state.
                foreach (UInt32 AS in stubs)
                {
                    if (!big5.Contains(AS))
                    {
                        AsNode node = g.GetNode(AS);
                        currS[AS] = false;//default to false for this stub.
                        var parents = node.GetNeighborsByType(RelationshipType.CustomerOf).ToList<AsNode>();
                        // parents.AddRange(node.GetNeighborsByType(RelationshipType.PeerOf)); //don't turn on for peers
                        foreach (AsNode parent in parents)
                        {
                            if (currS[parent.NodeNum])
                            {//parent is true let it be true in the augmented state.
                                currS[AS] = true;
                                break;
                            }

                        }
                    }
                }

                foreach (var AS in Params.earlyAdopters)
                    currS[AS] = true;//make sure early adopters are "on"

                processedState.Add(currS);
            }

            return processedState;
        }