コード例 #1
0
        public void testSPInterface()
        {
            SimulatorLibrary.setHash(true);
            SimulatorLibrary.setUtilityComputation(UtilityComputationType.outgoing);
            Console.WriteLine("Welcome to the short paths testing interface: ");
            bool exitNow = false;


            while (!exitNow)
            {
                Console.Write(">>");
                string   command = Console.ReadLine().ToLower();
                string[] pieces  = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (command.IndexOf("input") == 0)
                {
                    g = input(pieces);
                }
                else if (command.IndexOf("getpath") == 0)
                {
                    getpath(pieces);
                }
                else if (command.IndexOf("setstate") == 0)
                {
                    S = setstate(pieces);
                }
                else if (command.IndexOf("init") == 0)
                {
                    List <UInt32> ea = new List <uint>();
                    ea.Add(1239);
                    gs = SimulatorLibrary.initGlobalState(g, ea);
                }
                else if (command.IndexOf("iterate") == 0)
                {
                    List <MiniDestination> miniDs = new List <MiniDestination>();
                    foreach (var AS in g.GetAllNodes())
                    {
                        miniDs.Add(SimulatorLibrary.initMiniDestinationSP(g, AS.NodeNum, false));
                        Console.WriteLine("initialized AS " + AS.NodeNum);
                    }

                    List <Message> results = new List <Message>();
                    foreach (var mD in miniDs)
                    {
                        results.Add(SimulatorLibrary.ComputeOnDestination(mD, gs));
                        Console.WriteLine("computed on: " + mD.destination);
                    }
                    Console.WriteLine("updating global state.");
                    Int64[] Before = new Int64[Constants._numASNs];
                    Int64[] After  = new Int64[Constants._numASNs];


                    SimulatorLibrary.updateGlobalState(ref gs, results, (float)0, ref Before, ref After);
                    for (int i = 0; i < gs.S.Length; i++)
                    {
                        if (gs.S[i])
                        {
                            Console.WriteLine("AS " + i + " is on.");
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: valkiria88/Astoria
        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);
            }
        }
コード例 #3
0
ファイル: alwaysOff.cs プロジェクト: valkiria88/Astoria
        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");
        }