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 findSecureIslands(string[] commandPieces, resultObject Result) { if (commandPieces.Length < 2) { Console.WriteLine("usage: findsecureislands [iteration]"); return; } int iteration; if (!int.TryParse(commandPieces[1], out iteration)) { Console.WriteLine("malformed iteration value."); return; } StreamWriter output = new StreamWriter(Console.OpenStandardOutput()); bool[] iterationstate = Result.state[iteration]; List<List<UInt32>> allIslands = new List<List<UInt32>>(); List<UInt32> allVisited = new List<UInt32>(); Queue<UInt32> queue = new Queue<UInt32>(); UInt32 root = getFirstNotVisited(iterationstate, allVisited); do { List<UInt32> currentIsland = new List<UInt32>(); queue.Enqueue(root); allVisited.Add(root); currentIsland.Add(root); while (queue.Count > 0) { UInt32 curr = queue.Dequeue(); var currNeighbors = Result.g.GetNode(curr).GetAllNeighbors(); foreach (var neighbor in currNeighbors) { //haven't visited this guy before and he is on. if (!allVisited.Contains(neighbor.NodeNum) && iterationstate[neighbor.NodeNum]) { allVisited.Add(neighbor.NodeNum); queue.Enqueue(neighbor.NodeNum); currentIsland.Add(neighbor.NodeNum); } } } allIslands.Add(currentIsland); root = getFirstNotVisited(iterationstate, allVisited); } while (root != UInt32.MaxValue); foreach (var island in allIslands) { if (island.Count < 50) { printIsland(island, Result, output); } } output.Close(); }
public static void countDiamonds(string[] commandPieces,resultObject Result) { StreamWriter output = new StreamWriter(Console.OpenStandardOutput()); char sep='\t'; if (commandPieces.Length > 1) { sep=','; output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[1]); Console.WriteLine("outputting results to: " + ResultsExplorer.defaultOutputDirectory + commandPieces[1]); } foreach (UInt32 earlyAdopter in Result.earlyAdopters) { output.WriteLine(DateTime.Now + " :: Summarizing diamonds for: " + earlyAdopter); Hashtable diamonds = new Hashtable(); int customerDiamonds, peerDiamonds, providerDiamonds; getDiamonds(Result, earlyAdopter, _customerDiamonds, ref diamonds); customerDiamonds = diamonds.Count; diamonds = new Hashtable(); getDiamonds(Result, earlyAdopter, _peerDiamonds, ref diamonds); peerDiamonds = diamonds.Count; diamonds = new Hashtable(); getDiamonds(Result, earlyAdopter, _providerDiamonds, ref diamonds); providerDiamonds = diamonds.Count; output.WriteLine("{0}" + sep + "{1}" + sep + "{2}" + sep +"{3}", earlyAdopter, customerDiamonds, peerDiamonds ,providerDiamonds); } output.Close(); }
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<Destination> multihomedStubs = new List<Destination>(); foreach(UInt32 stubNum in stubs) { AsNode stub = results.g.GetNode(stubNum); if (stub.GetNeighborsByType(RelationshipType.CustomerOf).ToArray().Length > 1) multihomedStubs.Add(new Destination(SimulatorLibrary.initMiniDestination(results.g, stub.NodeNum, true))); } Console.WriteLine(multihomedStubs.Count + " stubs out of " + stubs.Count + " are multihomed."); /** Second, go through each iteration... **/ int iteration=0; foreach (bool[] S in results.state) { DateTime IterationStart = DateTime.Now; Int32 finishedDests = 0; foreach (Destination multihomedStub in multihomedStubs) { /** for this multhomed stub, see how much traffic * goes through secure providers **/ multihomedStub.UpdatePaths(S); multihomedStub.ComputeU(GS.W); var Providers = results.g.GetNode(multihomedStub.destination).GetNeighborsByType(RelationshipType.CustomerOf); Int64 TotalU = 0; Int64 SecureProviderU = 0; Int32 TotalProviders = Providers.Count(); Int32 SecureProviders = 0; foreach (var Provider in Providers) { if (S[Provider.NodeNum]) { SecureProviderU += multihomedStub.U[Provider.NodeNum]; SecureProviders++; } TotalU += multihomedStub.U[Provider.NodeNum]; } // Console.WriteLine(iteration + " :: " + multihomedStub.destination + " " + SecureProviders + " " + TotalProviders + " " + SecureProviderU + " " + TotalU); finishedDests++; if ((finishedDests % 1000) == 0) Console.WriteLine("Finished " + finishedDests + " at " + DateTime.Now + " iteration started at " + IterationStart); } Console.WriteLine(DateTime.Now + " done iteration " + iteration + " it started at " + IterationStart); iteration++; } }
/// <summary> /// write out ASNs for nodes that flipped but had no utility at beginning or end. /// </summary> /// <param name="commandPieces"></param> /// <param name="Result"></param> public static void getOnNonStubsWithNoUtility(string[] commandPieces,resultObject Result) { var nonStubs = Result.g.getNonStubs(); StreamWriter output = new StreamWriter(Console.OpenStandardOutput()); foreach (var nS in nonStubs) { if (Result.state[Result.state.Count - 1][nS] && Result.ubefore[0][nS] == 0 && Result.ubefore[Result.ubefore.Count - 1][nS] == 0) output.WriteLine(nS); } output.Close(); }
public static void edgeSummarize(string[] commandPieces, resultObject Result) { char sep = '\t'; StreamWriter output = new StreamWriter(Console.OpenStandardOutput()); if (commandPieces.Length > 1) { output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[1]); Console.WriteLine("outputting results to: " + ResultsExplorer.defaultOutputDirectory + commandPieces[1]); sep = ','; } output.WriteLine("iter" + sep + "total" + sep + "cust" + sep + "peer" + sep + "prov"+sep + "total-ns" + sep + "cust-ns" + sep + "peer-ns" + sep + "prov-ns"); for (int i = 1; i < Result.state.Count; i++) edgeIterationSummarize(Result, i, output, sep); output.Close(); }
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; }
public static void printGeoTotals(string[] commandPieces,resultObject Result) { try { List<UInt32> allASNs = new List<UInt32>(); foreach (var ASNode in Result.g.GetAllNodes()) { allASNs.Add(ASNode.NodeNum); } loadRIRASNs(allASNs); bool[] lastState = Result.state[Result.state.Count - 1]; int onARIN = howManyOn(lastState, arinASNs); int onRIPE = howManyOn(lastState, ripeASNs); int onLACNIC = howManyOn(lastState, lacnicASNs); int onAPNIC = howManyOn(lastState, apnicASNs); int onAFRINIC = howManyOn(lastState, afrinicASNs); int onALL = howManyOn(lastState,allASNs); double fracARIN = (double)onARIN / (double)arinASNs.Count; double fracRIPE = (double)onRIPE / (double)ripeASNs.Count; double fracLACNIC = (double)onLACNIC / (double)lacnicASNs.Count; double fracAPNIC = (double)onAPNIC / (double)apnicASNs.Count; double fracAFRINIC = (double)onAFRINIC / (double)afrinicASNs.Count; double fracALL = (double)onALL / (double)Result.g.NodeCount; Console.WriteLine("ALL {0}/{1} = {2:0.0000}", onALL, Result.g.NodeCount, fracALL); Console.WriteLine("ARIN {0}/{1} = {2:0.0000}", onARIN, arinASNs.Count, fracARIN); Console.WriteLine("RIPE {0}/{1} = {2:0.0000}", onRIPE, ripeASNs.Count, fracRIPE); Console.WriteLine("APNIC {0}/{1} = {2:0.0000}", onAPNIC, apnicASNs.Count, fracAPNIC); Console.WriteLine("LACNIC {0}/{1} = {2:0.0000}", onLACNIC, lacnicASNs.Count, fracLACNIC); Console.WriteLine("AFRINIC {0}/{1} = {2:0.0000}", onAFRINIC, afrinicASNs.Count, fracAFRINIC); /*** Debugging code, tells us how many ASNs had no RIR owner or multiple owners. Console.WriteLine("DEBUG total of RIRs is: " + (arinASNs.Count + ripeASNs.Count + lacnicASNs.Count + afrinicASNs.Count + apnicASNs.Count)); int[] ASNCounts = new int[6]; foreach (var ASN in allASNs) { int inASNs = 0; if (arinASNs.Contains(ASN)) inASNs++; if (ripeASNs.Contains(ASN)) inASNs++; if (lacnicASNs.Contains(ASN)) inASNs++; if (apnicASNs.Contains(ASN)) inASNs++; if (afrinicASNs.Contains(ASN)) inASNs++; ASNCounts[inASNs]++; } for (int i = 0; i < ASNCounts.Length; i++) Console.WriteLine("{0} ASNs had {1} RIR associated with them.", ASNCounts[i], i); * **/ } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\nAre the data files in " + RIRdata); return; } }
/// <summary> /// function that does all the things we want for AT&T /// pulls out ASes on at different points in simulation. /// computes different starting scenarios and writes them out. /// </summary> /// <param name="results"></param> public static void doATTThings(resultObject results) { printOnPerIteration(results); makeOutputScenarios(results); }
public static void getTieBreakSetSize(string[] commandPieces, resultObject Result) { if (commandPieces.Length < 2) { Console.WriteLine("usage: tiebreakset [AS+ASN | number to sample | b5t5 + number to sample ]"); return; } StreamWriter output = new StreamWriter(Console.OpenStandardOutput()); string bucketTableFile = "C:\\Users\\phillipa\\Desktop\\adoptTraffic\\Code\\AzureSecureSimulator\\MakeAllBucketTables\\bin\\Debug\\destinations2010\\"; if (commandPieces.Length > 2) { output.Close(); output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[2]); Console.WriteLine("outputting results to: " + ResultsExplorer.defaultOutputDirectory + commandPieces[2]); } string arg = commandPieces[1]; List<AsNode> sampleASes = new List<AsNode>(); if (arg.IndexOf("AS") == 0) { //sampling on single AS } else if (arg.IndexOf("all") < 0) { if (arg.IndexOf("b5t5") == 0) { sampleASes.Add(Result.g.GetNode(22822)); sampleASes.Add(Result.g.GetNode(15169)); sampleASes.Add(Result.g.GetNode(8075)); sampleASes.Add(Result.g.GetNode(20940)); sampleASes.Add(Result.g.GetNode(32934)); sampleASes.Add(Result.g.GetNode(7018)); sampleASes.Add(Result.g.GetNode(701)); sampleASes.Add(Result.g.GetNode(174)); sampleASes.Add(Result.g.GetNode(1239)); sampleASes.Add(Result.g.GetNode(3356)); } arg = arg.Replace("b5t5", ""); int numSamples = 0; if (int.TryParse(arg, out numSamples)) { numSamples += sampleASes.Count; while (sampleASes.Count < numSamples) { AsNode rand = Result.g.GetRandomNode(); if (!sampleASes.Contains(rand)) sampleASes.Add(rand); } } } else if (arg.IndexOf("all") == 0) sampleASes = Result.g.GetAllNodes().ToList(); Console.WriteLine("initiated sample set of size : " + sampleASes.Count); List<double> stubBestSizes = new List<double>(); List<double> nonStubBestSizes = new List<double>(); List<double> BestSizes = new List<double>(); var stubs = Result.g.getStubs(); var nonstubs = Result.g.getNonStubs(); var allASNs = new List<UInt32>(); foreach (var node in Result.g.GetAllNodes()) allASNs.Add(node.NodeNum); foreach (var sample in sampleASes) { Destination curr = ObjectToText.destinationFromText(bucketTableFile + sample.NodeNum + ".csv"); //SimulatorLibrary.initMiniDestination(Result.g, sample.NodeNum, false); var bestSizes = getAverageBestSizes(curr, stubs, nonstubs, allASNs, output); var avgBest = bestSizes.all; var sBest = bestSizes.stubs; var nsBest = bestSizes.nonstubs; Console.WriteLine("{0} {1:0.00} {2:0.00}(stubs) {3:0.00}(nonstubs)", sample.NodeNum, avgBest, sBest, nsBest); stubBestSizes.Add(sBest); nonStubBestSizes.Add(nsBest); BestSizes.Add(avgBest); } Console.WriteLine("-------ALL ASes--------"); Console.WriteLine("AVG: {0:0.000} SD: {1:0.000} MIN: {2:0.000} MAX: {3:0.000}", getMean(BestSizes), getSD(BestSizes, getMean(BestSizes)), getMin(BestSizes), getMax(BestSizes)); Console.WriteLine("-------STUB ASes--------"); Console.WriteLine("AVG: {0:0.000} SD: {1:0.000} MIN: {2:0.000} MAX: {3:0.000}", getMean(stubBestSizes), getSD(stubBestSizes, getMean(stubBestSizes)), getMin(stubBestSizes), getMax(stubBestSizes)); Console.WriteLine("-------NONSTUB ASes--------"); Console.WriteLine("AVG: {0:0.000} SD: {1:0.000} MIN: {2:0.000} MAX: {3:0.000}", getMean(nonStubBestSizes), getSD(nonStubBestSizes, getMean(nonStubBestSizes)), getMin(nonStubBestSizes), getMax(nonStubBestSizes)); output.Close(); }
private static void getDiamonds(resultObject Result, UInt32 pointASN, int diamondType,ref Hashtable diamonds) { var nonStubs = Result.g.getNonStubs(); var Stubs = Result.g.getStubs(); //neighbors depends on the type of diamond we want. IEnumerable<SecureSimulator.AsNode> neighborsOfPoint =null; switch (diamondType) { case _customerDiamonds: neighborsOfPoint = Result.g.GetNode(pointASN).GetNeighborsByType(SecureSimulator.RelationshipType.ProviderTo); break; case _peerDiamonds: neighborsOfPoint = Result.g.GetNode(pointASN).GetNeighborsByType(SecureSimulator.RelationshipType.PeerOf); break; case _providerDiamonds: neighborsOfPoint = Result.g.GetNode(pointASN).GetNeighborsByType(SecureSimulator.RelationshipType.CustomerOf); break; default: break; } var neighborASNs = new List<UInt32>(); foreach (var neighbor in Result.g.GetNode(pointASN).GetAllNeighbors()) neighborASNs.Add(neighbor.NodeNum); foreach (var neighbor in neighborsOfPoint) { //which neighbors our neighbors tell us about depends on the relationship type. IEnumerable<SecureSimulator.AsNode> grandchildren = null; switch (diamondType) { case _customerDiamonds: grandchildren = Result.g.GetNode(neighbor.NodeNum).GetNeighborsByType(SecureSimulator.RelationshipType.ProviderTo); break; case _peerDiamonds: grandchildren = Result.g.GetNode(neighbor.NodeNum).GetNeighborsByType(SecureSimulator.RelationshipType.ProviderTo); break; case _providerDiamonds: grandchildren = Result.g.GetNode(neighbor.NodeNum).GetAllNeighbors(); break; default: break; } foreach (var grandchild in grandchildren) { //this grandchild is a stub and is not directly connected to the point. if (Stubs.Contains(grandchild.NodeNum) && !neighborASNs.Contains(grandchild.NodeNum)) { if (diamonds.ContainsKey(grandchild.NodeNum)) ((List<UInt32>)diamonds[grandchild.NodeNum]).Add(neighbor.NodeNum); else { List<UInt32> toadd = new List<UInt32>(); toadd.Add(neighbor.NodeNum); diamonds.Add(grandchild.NodeNum, toadd); } } } } removeBadDiamonds(ref diamonds,pointASN,diamondType,Result); }
/// <summary> /// candidate to be deleted. /// </summary> /// <param name="Result"></param> /// <param name="pointASN"></param> /// <param name="output"></param> private static void countDiamonds(resultObject Result, UInt32 pointASN, StreamWriter output) { var nonStubs = Result.g.getNonStubs(); var Stubs = Result.g.getStubs(); var customersOfPoint = Result.g.GetNode(pointASN).GetNeighborsByType(SecureSimulator.RelationshipType.ProviderTo); var neighborASNs = new List<UInt32>(); foreach (var neighbor in Result.g.GetNode(pointASN).GetAllNeighbors()) neighborASNs.Add(neighbor.NodeNum); var customerDiamonds = new Hashtable(); foreach (var customer in customersOfPoint) { //my customers will only tell me about edges that pay them. foreach (var grandchild in customer.GetNeighborsByType(SecureSimulator.RelationshipType.ProviderTo))//customer edge will share all paths. { //this grandchild is a stub and is not directly connected to the point. if (Stubs.Contains(grandchild.NodeNum) && !neighborASNs.Contains(grandchild.NodeNum)) { if (customerDiamonds.ContainsKey(grandchild.NodeNum)) ((List<UInt32>)customerDiamonds[grandchild.NodeNum]).Add(customer.NodeNum); else { List<UInt32> toadd = new List<UInt32>(); toadd.Add(customer.NodeNum); customerDiamonds.Add(grandchild.NodeNum, toadd); } } } } var peersOfPoint = Result.g.GetNode(pointASN).GetNeighborsByType(SecureSimulator.RelationshipType.PeerOf); var peerDiamonds = new Hashtable(); foreach (var peer in peersOfPoint) { //this peer AS will only tell point about edges that pay it. foreach (var grandchild in peer.GetNeighborsByType(SecureSimulator.RelationshipType.ProviderTo)) { //this grandchild is a stub and is not directly connected to the point. if (Stubs.Contains(grandchild.NodeNum) && !neighborASNs.Contains(grandchild.NodeNum)) { if (peerDiamonds.ContainsKey(grandchild.NodeNum)) ((List<UInt32>)peerDiamonds[grandchild.NodeNum]).Add(peer.NodeNum); else { List<UInt32> toadd = new List<UInt32>(); toadd.Add(peer.NodeNum); peerDiamonds.Add(grandchild.NodeNum, toadd); } } } } var providersOfPoint = Result.g.GetNode(pointASN).GetNeighborsByType(SecureSimulator.RelationshipType.CustomerOf); var providerDiamonds = new Hashtable(); foreach (var provider in providersOfPoint) { //providers will tell us about all their edges. foreach (var grandchild in provider.GetAllNeighbors()) { //this grandchild is a stub and is not directly connected to the point. if (Stubs.Contains(grandchild.NodeNum) && !neighborASNs.Contains(grandchild.NodeNum)) { if (providerDiamonds.ContainsKey(grandchild.NodeNum)) ((List<UInt32>)providerDiamonds[grandchild.NodeNum]).Add(provider.NodeNum); else { List<UInt32> toadd = new List<UInt32>(); toadd.Add(provider.NodeNum); providerDiamonds.Add(grandchild.NodeNum, toadd); } } } } removeBadDiamonds(ref customerDiamonds, pointASN, _customerDiamonds, Result); removeBadDiamonds(ref peerDiamonds, pointASN, _peerDiamonds, Result); removeBadDiamonds(ref providerDiamonds, pointASN, _providerDiamonds, Result); output.WriteLine(pointASN + "," + customerDiamonds.Count + "," + peerDiamonds.Count + "," + providerDiamonds.Count); output.WriteLine(customerDiamonds.Count + " customer diamonds. " + summarizeDiamonds(customerDiamonds)); output.WriteLine(peerDiamonds.Count + " peer diamonds. " + summarizeDiamonds(peerDiamonds)); output.WriteLine(providerDiamonds.Count + " provider diamonds. " + summarizeDiamonds(providerDiamonds)); }
private static bool checkFlipOrder(Destination d, List<UInt32> diamond, UInt32 pointASN,resultObject Result) { UInt32 winningAS = d.Best[pointASN][0];//who the point routes through originally. int winnerFlip = -1; List<int> competitorFlips = new List<int>(); foreach (var competitor in diamond) { int i = 0; while (i < Result.state.Count && !Result.state[i][competitor]) i++; competitorFlips.Add(i); if (competitor == winningAS) winnerFlip = i; } int minFlip = int.MaxValue; for (int i = 0; i < competitorFlips.Count; i++) { if (competitorFlips[i] < minFlip) minFlip = competitorFlips[i]; } if (minFlip == winnerFlip && minFlip < Result.state.Count) return false;//winner flipped first. return true; }
public static void printDiamonds(string[] commandPieces, resultObject Result) { if (commandPieces.Length < 3) { Console.WriteLine("usage: printdiamonds [AS#] [customer/peer/provider] [outputfile?]"); return; } UInt32 ASN; if (!UInt32.TryParse(commandPieces[1], out ASN)) { Console.WriteLine("invalid ASN. "); return; } if (Result.g.GetNode(ASN) == null) { Console.WriteLine("ASN not in graph. "); return; } int diamondType = 0; switch (commandPieces[2]) { case "customer": diamondType = _customerDiamonds; break; case "peer": diamondType = _peerDiamonds; break; case "provider": diamondType = _providerDiamonds; break; default: diamondType=-1; //return; break; } StreamWriter output = new StreamWriter(Console.OpenStandardOutput()); if (commandPieces.Length > 3) { output.Close(); Console.WriteLine("outputting diamonds to : " + ResultsExplorer.defaultOutputDirectory + commandPieces[3]); output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[3]); } Hashtable diamonds = new Hashtable(); if (diamondType > 0) { getDiamonds(Result, ASN, diamondType, ref diamonds); int numPrinted = 0; foreach (var key in diamonds.Keys) { // if (((List<UInt32>)diamonds[key]).Count == degree) // { numPrinted++; output.WriteLine("------------ diamond " + numPrinted); printDiamond(ASN, (UInt32)key, ((List<UInt32>)diamonds[key]), Result.g, output); // } // if (numPrinted >= numDiamonds) // break; } output.Close(); } else { for (int Type = 1; Type < 4; Type++) { diamonds = new Hashtable(); getDiamonds(Result, ASN, Type, ref diamonds); int numPrinted = 0; foreach (var key in diamonds.Keys) { // if (((List<UInt32>)diamonds[key]).Count == degree) // { numPrinted++; output.WriteLine("------------ diamond " + numPrinted); printDiamond(ASN, (UInt32)key, ((List<UInt32>)diamonds[key]), Result.g, output); // } // if (numPrinted >= numDiamonds) // break; } } output.Close(); } }
public static bool isFirstIterationDiamond(UInt32 pointASN, UInt32 stub, List<UInt32> competitors, resultObject Result) { foreach (var competitor in competitors) { if (Result.state[0][competitor] == true)/* cannot be a L1 diamond with a * competitor who is an early adopter. */ return false; } /** now we know all competitors for this diamond were off at the start. **/ foreach (var competitor in competitors) { if (!Result.state[0][competitor] && Result.state[1][competitor]) { //now being a bit pickier. want 1 competitor flipping in round 1. all the others in //round 2. foreach (var othercompetitor in competitors) { if (othercompetitor != competitor) { if (!Result.state[2][othercompetitor]) return false;//a competitor was not on in round 2. } } return true; } } return false; }
public static void FindL2Diamonds(string[] commandPieces,resultObject Result) { if (commandPieces.Length < 2) { Console.WriteLine("usage: findl2diamonds [pointASN] [diamondsfile] [outputfile?]"); return; } UInt32 pointASN; if (!UInt32.TryParse(commandPieces[1], out pointASN)) { Console.WriteLine("invalid ASN"); return; } StreamWriter output; if (commandPieces.Length > 3) { output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[2]); Console.WriteLine("outputting to " + ResultsExplorer.defaultOutputDirectory + commandPieces[2]); } else output = new StreamWriter(Console.OpenStandardOutput()); Hashtable diamonds = readDiamonds(ResultsExplorer.defaultOutputDirectory + commandPieces[2]); foreach (var stub in diamonds.Keys) { } output.Close(); }
/// <summary> /// remove degree 1 diamonds and diamonds not used for traffic. /// </summary> /// <param name="diamonds"></param> private static void removeBadDiamonds(ref Hashtable diamonds, UInt32 point,int diamondType,resultObject Result) { NetworkGraph g = Result.g; //Remove level 1 diamonds. var keysToRemove = new List<UInt32>(); foreach (var key in diamonds.Keys) { if (((List<UInt32>)diamonds[key]).Count == 1) keysToRemove.Add((UInt32)key); } foreach (var key in keysToRemove) diamonds.Remove(key); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int keysProcessed = 0; keysToRemove = new List<uint>(); //for diamonds that arer peer nad provider make sure //the point doesn't have a better path // to the stub. foreach (var key in diamonds.Keys) { Destination k = ObjectToText.destinationFromText(bucketTableFile + key + ".csv"); if (diamondType == _peerDiamonds) { if (k.BestRelation[point] == Destination._CUSTOMERCOLUMN) keysToRemove.Add((UInt32)key); } else if (diamondType == _providerDiamonds) { if (k.BestRelation[point] == Destination._CUSTOMERCOLUMN) keysToRemove.Add((UInt32)key); else if (k.BestRelation[point] == Destination._PEERCOLUMN) keysToRemove.Add((UInt32)key); } if (!keysToRemove.Contains((UInt32)key) && !checkFlipOrder(k, (List<UInt32>)diamonds[key], point, Result)) keysToRemove.Add((UInt32)key); keysProcessed++; if (keysProcessed % 500 == 0) Console.WriteLine("processed " + keysProcessed + " out of " + diamonds.Count + " in " + stopwatch.ElapsedMilliseconds + " ms" + DateTime.Now); } stopwatch.Stop(); Console.WriteLine("processed " + diamonds.Count + " in " + stopwatch.ElapsedMilliseconds + " ms"); foreach (var key in keysToRemove) diamonds.Remove(key); }
public static void findFirstIterationDiamonds(string[] commandPieces, resultObject Result) { if (commandPieces.Length < 2) { Console.WriteLine("usage: firstiterationdiamonds [ASN]"); return; } UInt32 ASN; if (!UInt32.TryParse(commandPieces[1], out ASN)) { Console.WriteLine("invalid ASN. "); return; } if (Result.g.GetNode(ASN) == null) { Console.WriteLine("ASN not in graph. "); return; } Hashtable customerDiamonds = new Hashtable(); Hashtable providerDiamonds = new Hashtable(); Hashtable peerDiamonds = new Hashtable(); getDiamonds(Result, ASN, _customerDiamonds, ref customerDiamonds); getDiamonds(Result, ASN, _providerDiamonds, ref providerDiamonds); getDiamonds(Result, ASN, _peerDiamonds, ref peerDiamonds); StreamWriter output; if (commandPieces.Length > 2) { output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[2]); Console.WriteLine("outputting to " + ResultsExplorer.defaultOutputDirectory + commandPieces[2]); } else output = new StreamWriter(Console.OpenStandardOutput()); output.WriteLine("going through provider diamonds --------"); foreach (var stub in providerDiamonds.Keys) { if (isFirstIterationDiamond(ASN, (UInt32)stub, (List<UInt32>)providerDiamonds[stub], Result)) { output.WriteLine("---------------"); printDiamond(ASN, (UInt32)stub, (List<UInt32>)providerDiamonds[stub], Result.g, output); } } output.WriteLine("going through peer diamonds --------"); foreach (var stub in peerDiamonds.Keys) { if (isFirstIterationDiamond(ASN, (UInt32)stub, (List<UInt32>)peerDiamonds[stub], Result)) { output.WriteLine("---------------"); printDiamond(ASN, (UInt32)stub, (List<UInt32>)peerDiamonds[stub], Result.g, output); } } output.WriteLine("going through customer diamonds --------"); foreach (var stub in customerDiamonds.Keys) { if (isFirstIterationDiamond(ASN, (UInt32)stub, (List<UInt32>)customerDiamonds[stub], Result)) { output.WriteLine("---------------"); printDiamond(ASN, (UInt32)stub, (List<UInt32>)customerDiamonds[stub], Result.g, output); } } output.Close(); }
private static void edgeIterationSummarize(resultObject Result, int iteration, StreamWriter output, char sep) { if (iteration == 0) return; bool[] lastIteration = Result.state[iteration - 1]; bool[] currIteration = Result.state[iteration]; var ASNodes = Result.g.GetAllNodes(); int totalEdges = 0; int customerEdges = 0; int peerEdges = 0; int providerEdges = 0; int totalNonStubEdges = 0; int customerNonStubEdges = 0; int peerNonStubEdges = 0; int providerNonStubEdges = 0; var nonStubs = Result.g.getNonStubs(); foreach (var ASNode in ASNodes) { //this AS has flipped. if (currIteration[ASNode.NodeNum] != lastIteration[ASNode.NodeNum]) { var customers = ASNode.GetNeighborsByType(RelationshipType.ProviderTo); var peers = ASNode.GetNeighborsByType(RelationshipType.PeerOf); var providers = ASNode.GetNeighborsByType(RelationshipType.CustomerOf); foreach (var c in customers) { if (lastIteration[c.NodeNum]) { customerEdges++; totalEdges++; if (nonStubs.Contains(c.NodeNum)) { customerNonStubEdges++; totalNonStubEdges++; } } } foreach (var p in peers) { if (lastIteration[p.NodeNum]) { peerEdges++; totalEdges++; if (nonStubs.Contains(p.NodeNum)) { peerNonStubEdges++; totalNonStubEdges++; } } } foreach (var p in providers) { if (lastIteration[p.NodeNum]) { providerEdges++; totalEdges++; if (nonStubs.Contains(p.NodeNum)) { providerNonStubEdges++; totalNonStubEdges++; } } } } } output.WriteLine("{0}" + sep + "{1}" + sep + "{2}" + sep + "{3}" + sep + "{4}" + sep + "{5}" + sep + "{6}" + sep + "{7}" + sep + "{8}", iteration, totalEdges, customerEdges, peerEdges, providerEdges, totalNonStubEdges, customerNonStubEdges, peerNonStubEdges, providerNonStubEdges); }
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; }
private static void printIsland(List<UInt32> island, resultObject Result, StreamWriter output) { List<string> writtenEdges = new List<string>(); foreach (var AS in island) { var thisAS = Result.g.GetNode(AS); var neighbors = thisAS.GetAllNeighbors(); foreach (var neighbor in neighbors) { if (island.Contains(neighbor.NodeNum) && !writtenEdges.Contains(makeEdge(neighbor.NodeNum,AS))) { writtenEdges.Add(makeEdge(neighbor.NodeNum,AS)); output.WriteLine(AS + " " + thisAS.GetRelationshipTypeOfNeighbor(neighbor) + " " + neighbor.NodeNum); } } } }
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; }
public static void printOnPerIteration(resultObject results) { for (int i = 0; i < results.state.Count; i++) { int numPrinted = 0; bool[] currentIteration = results.state[i]; StreamWriter output = new StreamWriter(ATTdir + "simulation-" + i + ".txt"); for (int j = 0; j < currentIteration.Length; j++) { if (currentIteration[j]) { output.WriteLine(j); numPrinted++; } } Console.WriteLine("printed " + numPrinted + " for iteration " + i); output.Close(); } }
public void ResultsInterface() { results = new resultObject(); baseDirectory = ""; graphDirectory = ""; Console.WriteLine("*******************************"); Console.WriteLine("Welcome to the Results Explorer"); Console.WriteLine("*******************************"); Console.WriteLine("type 'help' to get the set of commands"); Console.Write(">"); Console.WriteLine("setting directories..."); setResultDir( "setresultdir default".Split(space,StringSplitOptions.RemoveEmptyEntries)); SimulatorLibrary.setHash(true); bool exitNow = false; StreamReader input = new StreamReader(Console.OpenStandardInput()); while (!exitNow) { Console.Write(">"); string command = input.ReadLine().ToLower(); string[] commandPieces = command.Split(space, StringSplitOptions.RemoveEmptyEntries); if (command.IndexOf("help") == 0) help(); else if (command.IndexOf("att") >= 0) ATT.doATTThings(results); else if (command.IndexOf("setresultdir") >= 0) setResultDir(commandPieces); else if (command.IndexOf("whoflippedforbig5") >= 0) whoFlippedForBig5(commandPieces); else if (command.IndexOf("setgraphdir") >= 0) setGraphDir(commandPieces); else if (command.IndexOf("loadsimulation") >= 0) results = loadSimulation(commandPieces); else if (command.IndexOf("printparams") >= 0) printParams(); else if (command.IndexOf("asninfo") >= 0) asnInfo(commandPieces); else if (command.IndexOf("getneighbortype") >= 0) getNeighborType(commandPieces); else if (command.IndexOf("getneighbors") >= 0) getneighbors(commandPieces); else if (command.IndexOf("whosepathchanged") >= 0) whosePathChanged(commandPieces); else if (command.IndexOf("getpath") >= 0) getPath(commandPieces); else if (command.IndexOf("summarize") >= 0 && command.IndexOf("geo") < 0 && command.IndexOf("edge") < 0) summarizeSimulationForNode(commandPieces); else if (command.IndexOf("whoflipped") >= 0) whoFlipped(commandPieces); else if (command.IndexOf("flipsummary") >= 0) flipSummary(commandPieces); else if (command.IndexOf("big5flipperson") >= 0) big5FlippersOn(commandPieces); else if (command.IndexOf("geosummarize") >= 0) getGeoTotals.printGeoTotalsPerIteration(commandPieces, results); else if (command.IndexOf("geototals") >= 0) getGeoTotals.printGeoTotals(commandPieces, results); else if (command.IndexOf("countdiamonds") >= 0) diamondFinder.countDiamonds(commandPieces, results); else if (command.IndexOf("printdiamonds") >= 0) diamondFinder.printDiamonds(commandPieces, results); else if (command.IndexOf("firstiterationdiamonds") >= 0) diamondFinder.findFirstIterationDiamonds(commandPieces, results); else if (command.IndexOf("edgesummarize") >= 0) edgeTypesPerIteration.edgeSummarize(commandPieces, results); else if (command.IndexOf("findisland") >= 0) secureIslands.findSecureIslands(commandPieces, results); else if (command.IndexOf("nonstubsnoutility") >= 0) noUtility.getOnNonStubsWithNoUtility(commandPieces, results); else if (command.IndexOf("neveron") >= 0) alwaysOff.neverOn(commandPieces); else if (command.IndexOf("computeutility") >= 0) noUtility.computeUtility(commandPieces, results); else if (command.IndexOf("averagedegree") >= 0) averageStubDegreeOfNeighbors(commandPieces); else if (command.IndexOf("findl2diamonds") >= 0) diamondFinder.FindL2Diamonds(commandPieces, results); else if (command.IndexOf("stubincrease") >= 0) firstRoundFlippers.normalizedStubIncrease(commandPieces, results); else if (command.IndexOf("tiebreakset") >= 0) TieBreakSetSize.getTieBreakSetSize(commandPieces, results); else if (command.IndexOf("exit") == 0) exitNow = true; } }
public static void makeOutputScenarios(resultObject results) { /* Scenario 1: - 1 file per large AS. File contains the AS and it's stub customers */ var stubs = results.g.getStubs(); UInt32[] highdegreeASes = { 701, 174, 3356, 7018, 1239, 209, 3549, 4323, 6939, 9002, 6461, 2828, 2914, 4589, 3856, 3561, 6762, 1299, 3320 }; UInt32[] CPs = { 15169, 8075, 22822, 32934, 20940 }; int numPrinted; foreach (UInt32 bigAS in highdegreeASes) { StreamWriter output = new StreamWriter(ATTdir + "AS" + bigAS + ".txt"); numPrinted = 1; List<UInt32> printedASes = new List<UInt32>(); output.WriteLine(bigAS); printedASes.Add(bigAS); AsNode curr = results.g.GetNode(bigAS); foreach (AsNode customer in curr.GetNeighborsByType(RelationshipType.ProviderTo)) { if (stubs.Contains(customer.NodeNum) && !printedASes.Contains(customer.NodeNum)) { printedASes.Add(customer.NodeNum); output.WriteLine(customer.NodeNum); numPrinted++; } } Console.WriteLine("printed " + numPrinted + " for AS " + bigAS); output.Close(); } /* Scenario 2: * - 1 file per CP. File contains the CP and it's peers. * */ foreach (UInt32 CP in CPs) { StreamWriter outputpeers = new StreamWriter(ATTdir + "CP-AS" + CP + "-peers.txt"); StreamWriter outputpeersandstubs = new StreamWriter(ATTdir + "CP-AS" + CP + "-peers-stubs.txt"); outputpeers.WriteLine(CP); outputpeersandstubs.WriteLine(CP); List<UInt32> printedASes1 = new List<UInt32>(); List<UInt32> printedASes2 = new List<UInt32>(); numPrinted = 1; AsNode curr = results.g.GetNode(CP); printedASes1.Add(CP); printedASes2.Add(CP); foreach (AsNode peer in curr.GetNeighborsByType(RelationshipType.PeerOf)) { if (!printedASes1.Contains(peer.NodeNum) && !printedASes2.Contains(peer.NodeNum)) { printedASes1.Add(peer.NodeNum); printedASes2.Add(peer.NodeNum); numPrinted++; outputpeers.WriteLine(peer.NodeNum); } foreach (AsNode peercustomer in peer.GetNeighborsByType(RelationshipType.ProviderTo)) { if (stubs.Contains(peercustomer.NodeNum) && !printedASes2.Contains(peercustomer.NodeNum)) { printedASes2.Add(peercustomer.NodeNum); outputpeersandstubs.WriteLine(peercustomer.NodeNum); } } } Console.WriteLine("printed " + printedASes1.Count + "peers for AS and "+ printedASes2.Count+ " peer/customers for " + CP); outputpeers.Close(); outputpeersandstubs.Close(); } }
public static void printGeoTotalsPerIteration(string[] commandPieces, resultObject Result) { try { List<UInt32> allASNs = new List<UInt32>(); foreach (var ASNode in Result.g.GetAllNodes()) { allASNs.Add(ASNode.NodeNum); } loadRIRASNs(allASNs); char sep = '\t'; StreamWriter output = new StreamWriter(Console.OpenStandardOutput()); if (commandPieces.Length > 1) { output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[1]); Console.WriteLine("outputting results to: " + ResultsExplorer.defaultOutputDirectory + commandPieces[1]); sep = ','; } output.WriteLine("iter"+sep+"ALL"+sep+"ARIN"+sep+"RIPE"+sep+"APNIC"+sep+"LACNIC"+sep+"AFRINIC"); int lastARIN = howManyOn(Result.state[0], arinASNs); int lastRIPE = howManyOn(Result.state[0], ripeASNs); int lastAPNIC = howManyOn(Result.state[0], apnicASNs); int lastLACNIC = howManyOn(Result.state[0], lacnicASNs); int lastAFRINIC = howManyOn(Result.state[0], afrinicASNs); int lastALL = howManyOn(Result.state[0], allASNs); for (int s = 1; s < Result.state.Count; s++) { bool[] currState = Result.state[s]; int onARIN = howManyOn(currState, arinASNs); int onRIPE = howManyOn(currState, ripeASNs); int onLACNIC = howManyOn(currState, lacnicASNs); int onAPNIC = howManyOn(currState, apnicASNs); int onAFRINIC = howManyOn(currState, afrinicASNs); int onALL = howManyOn(currState, allASNs); output.WriteLine("{0}"+sep+"{1}"+sep+"{2}"+sep+"{3}"+sep+"{4}"+sep+"{5}"+sep+"{6}", s, onALL-lastALL, onARIN-lastARIN, onRIPE-lastRIPE, onAPNIC-lastAPNIC, onLACNIC-lastLACNIC, onAFRINIC-lastAFRINIC); lastARIN = onARIN; lastRIPE = onRIPE; lastLACNIC = onLACNIC; lastAPNIC = onAPNIC; lastAFRINIC = onAFRINIC; lastALL = onALL; } output.Close(); } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\nAre the data files in " + RIRdata); return; } }