Пример #1
0
        static void Main(string[] args)
        {
            if (args.Length == 0) {
                    Console.WriteLine("USAGE:");
            Console.WriteLine("mono TestingApplication.exe -bulk <input file> <dest1> ... <dstN> -q <src1> <dst1> ... <srcN> <dstN>");
            Console.WriteLine("mono TestingApplication.exe -serverPORT <input file> <precomp file> <cache file>");
                    Console.WriteLine("mono TestingApplication.exe -cmd");
                    return;
            }

                if ("-cmd" == args[0]) {
                    TestingClass test = new TestingClass();
                    test.CLI(false);
                    return;
                }

            // Graph initialization
            //NetworkGraph g = new NetworkGraph();

            // E.g., input Cyclops_caida.txt
            if (File.Exists(args[1]))
                {
                    InputFileReader iFR = new InputFileReader(args[1], g);
                    iFR.ProcessFile();
                    Int32 p2pEdges = 0;
                    Int32 c2pEdges = 0;
                    foreach(var ASNode in g.GetAllNodes())
                    {
                        p2pEdges += ASNode.GetNeighborTypeCount(RelationshipType.PeerOf);
                        c2pEdges += ASNode.GetNeighborTypeCount(RelationshipType.CustomerOf);
                        c2pEdges += ASNode.GetNeighborTypeCount(RelationshipType.ProviderTo);
                    }

                    //Console.WriteLine("Read in the graph, it has " + g.NodeCount + " nodes and " + g.EdgeCount + " edges.");
                    //Console.WriteLine("P2P: " + p2pEdges + " C2P: " + c2pEdges);
            }
                else
                {
                    Console.WriteLine("The file " + args[1] +  " does not exist.");
                    return;
                }

                if ("-bulk" == args[0]) {
            // Setting destinations
            //HashSet<string> dests = new HashSet<string>();
                    //List<Destination> d = new List<Destination>();

            int i = 1;
            for (i = 1; i < args.Length; ++i) {
                if ("-q" == args[i]) break;
                        if (dests.Contains(args[i])) continue;
                        dests.Add(args[i]);

                        Destination newD = new Destination();
                        if (initDestination(ref g, ref newD, args[i]))
                {
                    d.Add(args[i], newD);
                Console.WriteLine("Initialized and added " + newD.destination);
                }
            }

                    Console.WriteLine("DESTS " + dests.Count);

            // Approaching queries
            for (i = i+1; i < args.Length; i += 2) {

                        //StringBuilder res = new StringBuilder();
                //int l = getPath(ref d, args[i], args[i+1]);
                //getAllPathsOfLength(ref d, l, args[i], args[i+1], ref res);

                        List<List<UInt32>> allPaths = new List<List<UInt32>>();

                        if (d.ContainsKey(args[i+1])) {
                            UInt32 src;
                            UInt32 dst;
                            if (UInt32.TryParse(args[i], out src) && UInt32.TryParse(args[i+1], out dst)) {
                                Console.WriteLine("ASes from " + src + " to " + dst);
                                d[args[i+1]].GetAllBestPaths(src, dst, ref allPaths);
                            }
                        }

                        foreach (List<UInt32> path in allPaths) {
                            for (int j = 0; j < path.Count; ++j) {
                                Console.WriteLine(path[j]);
                            }
                            Console.WriteLine("-");
                        }

                    }

                    return;
                }

                if (args[0].StartsWith("-server")) {

                    if (args.Length > 2) {
                        loadPrecomputation(args[2]);
                        cacheDestinations(args[3]);
                    }

                    String port = args[0].Replace("-server", "");
                    StartListening(port);
                }
        }
Пример #2
0
        private NetworkGraph input(string[] pieces)
        {
            if (pieces.Length < 2)
               {
               return null;
               }

               NetworkGraph g = new NetworkGraph();
               if (!File.Exists(pieces[1]))
               pieces[1] = "C:\\Users\\phillipa\\Desktop\\adoptTraffic\\AugmentedGraphs\\" + pieces[1];
               if (File.Exists(pieces[1]))
               {
               InputFileReader ifr = new InputFileReader(pieces[1], g);
               ifr.ProcessFile();
               Console.WriteLine("read graph: " + g.EdgeCount + " edges " + g.NodeCount + " nodes");
               return g;
               }
               return null;
        }
Пример #3
0
        public resultObject loadSimulationNonInteractive(String directory)
        {
            if (!Directory.Exists(directory))
            {
                Console.WriteLine("error directory: " + directory + " does not exist");
                return new resultObject();
            }

            if (directory[directory.Length - 1] != '\\')
                directory = directory + "\\";

            if (!File.Exists(directory + "params.txt"))
            {
                Console.WriteLine("could not load params file for directory: " + directory);
                Console.WriteLine("params file did not exist");
                return new resultObject();
            }

            resultObject toreturn = readParamsFile(directory + "params.txt");
            toreturn.directory = directory;

            StreamReader input;
            if (!File.Exists(directory + toreturn.precursor + ".S200000.csv"))
            {
                Console.WriteLine("This directory has not been post-processed yet. I'm going to post process state before loading it, but before you use this data in R you will need to run the PostProcessing program.");
                List<bool[]> nonProcessedState = readStateFromFile(directory + toreturn.precursor + ".S000000.csv");
                toreturn.state = postProcessState(nonProcessedState, toreturn);
            }
            else
            {
                toreturn.state = readStateFromFile(directory + toreturn.precursor + ".S200000.csv");
            }

            toreturn.ubefore = readUTable(toreturn, "UBefore.csv");
            toreturn.uafter = readUTable(toreturn, "UAfter0.csv");

            toreturn.g = new NetworkGraph();
            if (File.Exists(graphDirectory + toreturn.graphFile))
            {
                InputFileReader ifr = new InputFileReader(graphDirectory + toreturn.graphFile, toreturn.g);
                ifr.ProcessFile();
                Console.WriteLine("loaded the graph: " + toreturn.graphFile + " it has " + toreturn.g.NodeCount + " nodes and " + toreturn.g.EdgeCount + " edges");

            }
            else
                Console.WriteLine("I was unable to load the graph " + toreturn.graphFile + " from directory " + graphDirectory + " please put the graph file in the directory or set the current graph directory with 'setgraphdir'");

            Console.WriteLine("********************************");
            Console.WriteLine("Loaded simulation with parameters: ");
            toreturn.printParams();
            Console.WriteLine("********************************");
            return toreturn;
        }
Пример #4
0
        private bool initGraph(ref NetworkGraph g,string command)
        {
            g = new NetworkGraph();
            string resp;

            if (command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > 1)
                resp = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1];
            else
            {
                Console.WriteLine("Please enter a file name or \"testgraph\" to use the graph from the routing tree algorithm figure in the Sigcomm 2010 paper");
                resp = Console.ReadLine().ToLower();
            }
            if (resp == "testgraph")
            {
                Console.WriteLine("loading test graph ...");
                g = getTestGraph();
                Console.WriteLine("done.");
                return true;
            }
            else
            {
                if (File.Exists(resp))
                {
                    InputFileReader iFR = new InputFileReader(resp, g);
                    iFR.ProcessFile();
                    Int32 p2pEdges = 0;
                    Int32 c2pEdges = 0;
                    foreach(var ASNode in g.GetAllNodes())
                    {
                        p2pEdges += ASNode.GetNeighborTypeCount(RelationshipType.PeerOf);
                        c2pEdges += ASNode.GetNeighborTypeCount(RelationshipType.CustomerOf);
                        c2pEdges += ASNode.GetNeighborTypeCount(RelationshipType.ProviderTo);
                    }
                    Console.WriteLine("read in the graph it has " + g.NodeCount + " nodes and " + g.EdgeCount + " edges");
                    Console.WriteLine("P2P: " + p2pEdges + " C2P: " + c2pEdges);
                    return true;
                }
                else
                {
                    Console.WriteLine("that file does not exist. Going back to main menu now.");
                    return false;
                }
            }
        }
Пример #5
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;
        }