Пример #1
0
        private bool flipU(ref List<Destination> ds, ref NetworkGraph g, ref GlobalState globalState,string command)
        {
            Console.WriteLine("Flipping state:");

            string[] cpieces = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (cpieces.Length < 2)
            {
                Console.WriteLine("usage: flipu <d> <quiet?>");
                return false;
            }

            Destination d = new Destination();
            UInt32 destNum;
            if (!UInt32.TryParse(cpieces[1], out destNum))
            {
                Console.WriteLine("invalid destination number");
                return false;
            }
            foreach (Destination curr in ds)
            {
                if (curr.destination == destNum)
                    d = curr;
            }
            if (d.BucketTable == null)
            {
                Console.WriteLine("null bucket table!");
                return false;
            }

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            List<UInt32> toflip = new List<UInt32>();
            bool quiet = false;
            if (command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > 2)
            {
                quiet = true;
                Console.WriteLine("you have selected quiet mode");
            }

            List<UInt32> nonstubs = g.getNonStubs();
            foreach (UInt32 ASN in nonstubs)
            {
                if (d.Best[ASN] != null)//make sure this AS has a route to our destination
                {
                    Worker w = new Worker();
                    int notASN = w.ComputeUtility(d.BucketTable, d.Best, d.ChosenParent, d.SecP, globalState.S, ASN, d.L[ASN], d.BestRelation[ASN], globalState.W);
                    if (d.U[ASN] < notASN)
                    {
                        if (!quiet)
                            Console.WriteLine("AS: " + ASN + " from " + globalState.S[ASN] + " to " + !globalState.S[ASN]);
                        toflip.Add(ASN);//don't flip on the fly it messes up everyones calculations, do it at the end.
                    }
                }
            }

            foreach (int ASN in toflip)
            {
                if (globalState.S[ASN])
                    Console.WriteLine("AS: " + ASN + " is rolling back!!!");
                globalState.S[ASN] = !globalState.S[ASN];

            }
            stopwatch.Stop();
            Console.WriteLine("flip u took " + stopwatch.ElapsedMilliseconds + " ms");
            Console.WriteLine("it flipped " + toflip.Count + " ASes");
            return true;
        }
Пример #2
0
        private bool flipallU(ref List<Destination> ds, ref NetworkGraph g, ref GlobalState globalState, string command)
        {
            Console.WriteLine("Flipping state:");

            string[] cpieces = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (cpieces.Length < 1)
            {
                Console.WriteLine("usage: flipallu <quiet?>");
                return false;
            }

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            List<UInt32> toflip = new List<UInt32>();
            bool quiet = false;
            if (command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > 1)
            {
                quiet = true;
                Console.WriteLine("you have selected quiet mode");
            }
            List<UInt32> nonstubs = g.getNonStubs();
            Int64[] deltaU = new Int64[Constants._numASNs];
            for (int i = 0; i < deltaU.Length; i++)
                deltaU[i] = 0;

            foreach (Destination d in ds)
            {
                foreach (UInt32 ASN in nonstubs)
                {
                    if (d.Best[ASN] != null)//make sure this AS has a route to our destination
                    {
                        Worker w = new Worker();
                        int notASN = w.ComputeUtility(d.BucketTable, d.Best, d.ChosenParent, d.SecP, globalState.S, ASN, d.L[ASN], d.BestRelation[ASN], globalState.W);

                        deltaU[ASN] += (notASN - d.U[ASN]);

                    }
                }
            }
            int flipped = 0;
            for (int ASN = 0; ASN < deltaU.Length;ASN++ )
            {
                if (deltaU[ASN] > 0)//positive change in utility for this ASN
                {
                    flipped++;
                    if (globalState.S[ASN])
                        Console.WriteLine("AS: " + ASN + " is rolling back!!!");
                    globalState.S[ASN] = !globalState.S[ASN];
                    if (!quiet)
                    {
                        Console.WriteLine("AS: " + ASN + " had change in utility of " + deltaU[ASN]);
                    }
                }

            }
            stopwatch.Stop();
            Console.WriteLine("flip u took " + stopwatch.ElapsedMilliseconds + " ms");
            Console.WriteLine("it flipped " + flipped + " ASes");
            return true;
        }
Пример #3
0
        private bool printnonstubs(ref NetworkGraph g)
        {
            Console.WriteLine("printing non stubs:");
            List<UInt32> nonstubs = g.getNonStubs();
            for (int i = 0; i < nonstubs.Count; i++)
                Console.WriteLine(nonstubs[i]);

            return true;
        }
Пример #4
0
        private bool compareU(ref List<Destination> ds, ref GlobalState globalState,ref NetworkGraph g,string command)
        {
            string[] cpieces = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (cpieces.Length < 2)
            {
                Console.WriteLine("usage: compareu <d> <onlybenefit?>");
                return false;
            }
            /** first off try to parse out a specific destination (or all) **/

            UInt32 destNum;
            if (!UInt32.TryParse(cpieces[1], out destNum) && !cpieces[1].Equals("all"))
            {
                Console.WriteLine("invalid destination number");
                return false;
            }
            List<Destination> destinationsToCompare = new List<Destination>();
            if (cpieces[1].Equals("all"))
            {
                //want to run on all destinations.
                destinationsToCompare = ds;
            }
            else
            {
                foreach (Destination curr in ds)
                {
                    if (curr.destination == destNum)
                        destinationsToCompare.Add(curr);
                }
            }
            /** next see if we have been asked only for nodes that benefit **/
            bool onlybenefit = false;
            if (command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > 2)
            {
                Console.WriteLine("you've chosen to only display ASes that benefit");
                onlybenefit = true;
            }

            List<UInt32> nonstubs = g.getNonStubs();
            Worker w = new Worker();
            foreach (Destination d in destinationsToCompare)
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                Console.WriteLine("Destination : " + d.destination);
                Console.WriteLine("ASN :: U(before) : U(flipped)");
                runCompareU(nonstubs, d, ref w, onlybenefit,ref globalState);
                stopwatch.Stop();
                Console.WriteLine("compare u took " + stopwatch.ElapsedMilliseconds + " ms");
            }
            return true;
        }
Пример #5
0
        public void CLI(bool script)
        {
            bool debug = false;
            bool decoy_sim = false;

            string resp;
            List<Destination> d = new List<Destination>();
            NetworkGraph g = new NetworkGraph();
            Worker w = new Worker();
            bool[] S = new bool[Constants._numASNs];
            for (int i = 0; i < S.Length; i++)
                S[i] = false;
            GlobalState globalState = new GlobalState();
            globalState.S = S;
            StreamReader input = new StreamReader( Console.OpenStandardInput());
            if (script)
            {
                Console.WriteLine("You have selected to run a script, please enter the file name:");
                string scriptfile = Console.ReadLine();
                if (!File.Exists(scriptfile))
                    Console.WriteLine("script file: " + scriptfile + " did not exist, entering interactive mode");
                else
                    input = new StreamReader(scriptfile);
            }
            globalState.W = new UInt16[Constants._numASNs];
            for (int i = 0; i < globalState.W.Length; i++)
                globalState.W[i] = 1;

            Console.WriteLine("Welcome to the testing interface: (type help for help) Haseeb Mac");
            bool exitNow = false;

            //Automatcally load Cyclops_caida.txt
            if (decoy_sim)
            {
                String load = "inputfile decoy/Cyclops_poison.txt";
                initGraph(ref g, load);
                globalState.nonStubs = g.getNonStubs();
                Console.WriteLine("Cyclops_poison.txt Loaded!");
            } else {
                String load = "inputfile Cyclops_caida_new.txt";
                initGraph(ref g, load);
                globalState.nonStubs = g.getNonStubs();
                Console.WriteLine("Cyclops_caida_new.txt Loaded!");
            }

            //DEBUG
            if (debug) {
                String debugC = "analysepathfile test.txt";
                analysePathfile (ref g, debugC);
                exitNow = true;
            } else if (decoy_sim) {
                string dst;

                using (StreamReader reader = new StreamReader("decoy/helper.txt")) {
                    dst = reader.ReadLine();
                }
                String decoyC = "all_path_info " + dst;
                all_path_info(ref d, ref g, decoyC);
                exitNow = true;
            }

            while(!exitNow)
            {
                if (input.EndOfStream)
                {
                    input.Close();
                    input = new StreamReader(Console.OpenStandardInput());
                    Console.WriteLine("script has ended, now in interactive mode");
                }
                Console.Write(">>");
                string command = input.ReadLine().ToLower();

                if (command.IndexOf ("input") == 0) {
                    initGraph (ref g, command);
                    globalState.nonStubs = g.getNonStubs ();
                } else if (command.IndexOf ("destination") == 0) {

                    if (command.IndexOf ("all") < 0) {
                        Destination newD = new Destination ();
                        if (initDestination (ref g, ref newD, command)) {
                            d.Add (newD);
                            Console.WriteLine ("initialized and added " + newD.destination);
                        }
                    } else {
                        IEnumerable<AsNode> allASes = g.GetAllNodes ();
                        foreach (AsNode AS in allASes) {
                            Destination newD = new Destination ();
                            if (initDestination (ref g, ref newD, "destination " + AS.NodeNum)) {
                                d.Add (newD);
                                Console.WriteLine ("initialized and added " + newD.destination);
                            }
                        }
                    }

                } else if (command.IndexOf ("resultsexplorer") == 0) {
                    ResultsExplorer res = new ResultsExplorer ();
                    res.ResultsInterface ();
                } else if (command.IndexOf ("setstate") == 0)
                    initS (ref  globalState.S, command);
                else if (command.IndexOf ("addedges") == 0)
                    addEdges (command, ref g);
                else if (command.IndexOf ("getlink") == 0)
                    getLink (command, ref g);
                else if (command.IndexOf ("flipallu") == 0)
                    flipallU (ref d, ref g, ref globalState, command);
                else if (command.IndexOf ("printstate") == 0)
                    printState (ref  globalState.S, command);
                else if (command.IndexOf ("printsecp") == 0)
                    printSecP (ref d, command);
                else if (command.IndexOf ("getl") == 0)
                    getL (ref d, command);
                else if (command.IndexOf ("getw") == 0)
                    getW (ref globalState.W, command);
                else if (command.IndexOf ("printw") == 0)
                    printWeight (ref globalState.W, command);
                else if (command.IndexOf ("setw") == 0)
                    setW (ref globalState.W, command);
                else if (command.IndexOf ("getbestnew") == 0)
                    getBestNew (ref d, command);
                else if (command.IndexOf ("getbest") == 0)
                    getBest (ref d, command);
                else if (command.IndexOf ("all_path_info") == 0)
                    all_path_info (ref d, ref g, command);
                else if (command.IndexOf ("getpath") == 0)
                    getPath (ref d, ref g, command);
                else if (command.IndexOf ("analysepathfile") == 0)
                    analysePathfile (ref g, command);
                else if (command.IndexOf ("analysepath") == 0)
                    analysePath (ref g, command);
                else if (command.IndexOf ("serialise") == 0)
                    serialisePathArrays (ref g, command);
                else if (command.IndexOf ("getallpathsoflength") == 0)
                    getAllPathsoflength (ref d, ref g, command);
                else if (command.IndexOf ("getallpathsto") == 0)
                    getAllPathsTo (ref d, ref g, command);
                else if (command.IndexOf ("getallpaths") == 0)
                    getAllPaths (ref d, ref g, command);
                else if (command.IndexOf("getsecp") == 0)
                    getSecP(ref d, command);
                else if (command.IndexOf("getutility") == 0)
                    getUtility(ref d, command);
                else if (command.IndexOf("onlynonstubs") == 0)
                    SimulatorLibrary.setOnlyStubs(true);
                else if (command.IndexOf("notonlynonstubs") == 0)
                    SimulatorLibrary.setOnlyStubs(false);
                else if (command.IndexOf("iterateall") == 0)
                    iterateAll(ref d, ref g, ref globalState, command);
                else if (command.IndexOf("iterate") == 0)
                    iterate(ref d, ref  globalState, command);
                else if (command.IndexOf("not") == 0)
                    computeNotN(ref d, ref globalState, ref w, command);
                else if (command.IndexOf("wgetsecp") == 0)
                    getWorkerSecP(ref w, command);
                else if (command.IndexOf("checkpath") == 0)
                    checkPath(command);
                else if (command.IndexOf("initglobalstate") == 0)
                    initGlobalState(command, ref g, ref globalState);
                else if (command.IndexOf("wgetpath") == 0)
                    getWorkerPath(ref w, command);
                else if (command.IndexOf("wgetparent") == 0)
                    getWorkerParent(ref w, command);
                else if (command.IndexOf("printbuckettable") == 0)
                    printBucketTable(ref d, command);
                else if (command.IndexOf("compareu") == 0)
                    compareU(ref d, ref  globalState, ref g, command);
                else if (command.IndexOf("flipu") == 0)
                    flipU(ref d, ref g, ref globalState, command);
                else if (command.IndexOf("getnonstubs") == 0)
                    printnonstubs(ref g);
                else if (command.IndexOf("getstubs") == 0)
                    printstubs(ref g);
                else if (command.IndexOf("turnonstubs") == 0)
                    turnOnStubs(ref g, ref  globalState.S);
                else if (command.IndexOf("getcustomers") == 0)
                    getcustomers(ref g, command);
                else if (command.IndexOf("getpeers") == 0)
                    getpeers(ref g, command);
                else if (command.IndexOf("getproviders") == 0)
                    getproviders(ref g, command);
                else if (command.IndexOf("gets") == 0) //must be tested for after getsecp
                    getS(ref  globalState.S, command);
                else if (command.IndexOf("sets") == 0) //this must be tested for *after* the test for setstate
                    setS(ref  globalState.S, command);
                else if (command.IndexOf("computehash") == 0)
                    computeHash(command);
                else if (command.IndexOf("setutilitycomputation") == 0)
                    setUtilityComputation(command);
                else if (command.IndexOf("numberon") == 0)
                    numberOn(ref  globalState.S);
                else if (command.IndexOf("getaveragebest") == 0)
                    getAverageBest(command, ref d);
                else if (command.IndexOf("nodeswithnopath") == 0)
                    nodesWithNoPath(command, ref d, ref g);
                else if (command.IndexOf("traversedod") == 0)
                    DoDAnaly.traverseDoD(g);
                else if (command.IndexOf("clear") == 0)
                {
                    Console.WriteLine("clearing state of graph, destination, S and worker.");

                    g = new NetworkGraph();
                    for (int i = 0; i < S.Length; i++)
                        S[i] = false;
                    d = new List<Destination>();
                    w = new Worker();
                }
                else if (command.IndexOf("help") == 0)
                    help();
                else if (command.IndexOf("list") == 0)
                {
                    Console.WriteLine("printing current directory contents:");
                    string[] dirContents = Directory.GetFiles(".");
                    foreach (string s in dirContents)
                        Console.WriteLine(s);
                }
                else if (command.IndexOf("exit") == 0)
                    exitNow = true;

                Console.Write(">>");
            }

            input.Close();
        }