static void Main(string[] args) { //bunch of stuff to point it at the canonical sim results directory on my computer. ResultsExplorer res = new ResultsExplorer(); string[] simulationDirectories = Directory.GetDirectories(ResultsExplorer.defaultResultsDirectory); //just set directory to point to the canonical sim results folder. string directory = simulationDirectories[33]; resultObject canonical = res.loadSimulationNonInteractive(directory); for (int i = 0; i < canonical.state.Count; i++) { double numOn = 0; bool[] currS = canonical.state[i]; StreamWriter output = new StreamWriter("canonical-ASesON-" + i + ".txt"); for (int AS = 0; AS < currS.Count(); AS++) { if (currS[AS]) { output.WriteLine(AS); numOn++; } } Console.WriteLine(numOn / currS.Count() + " of ASes are ON " + numOn + " " + currS.Count()); output.Close(); } // TrafficEngineering.trafficThroughSecureProviders(canonical); }
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"); }
private static List <UInt32> stubsThroughMeIncrease(List <UInt32> sourceNodes, UInt32 ASN, List <bool[]> state, NetworkGraph g, StreamWriter output) { var stubs = g.getStubs(); var ASNode = g.GetNode(ASN); //this node flipped,figure out which iteration. int flippedIter = -1; for (int i = 0; flippedIter < 0 && i < state.Count; i++) { if (state[i][ASN]) { flippedIter = i; } } if (flippedIter == 0) { Console.WriteLine("ASN: " + ASN + " was on to begin with."); return(new List <UInt32>()); } //one variable per source node counting how many stubs of mine //route through me from this source now. List <UInt32> newCustomerPathsPerSourceNode = new List <UInt32>(); for (int i = 0; i < sourceNodes.Count; i++) { newCustomerPathsPerSourceNode.Add(0); } foreach (var customer in ASNode.GetNeighborsByType(RelationshipType.ProviderTo)) { List <UInt32[]> pathsBefore = new List <uint[]>(); List <UInt32[]> pathsAfter = new List <uint[]>(); List <string> pathsBeforeStrings = new List <string>(); List <string> pathsAfterStrings = new List <string>(); Destination d = new Destination(SimulatorLibrary.initMiniDestination(g, customer.NodeNum, false)); //paths before the AS flipped (from early adopters to this stub.) d.UpdatePaths(state[flippedIter - 1]); foreach (var bigASN in sourceNodes) { if (bigASN != d.destination) { pathsBefore.Add(d.GetPathList(bigASN));//path from bigASN to the stub. pathsBeforeStrings.Add(d.GetPath(bigASN, state[flippedIter - 1])); } else {//dummy vals. this source is the destination. pathsBefore.Add(new UInt32[0]); pathsBeforeStrings.Add(""); } } //paths after AS flipped. d.UpdatePaths(state[flippedIter]); foreach (var bigASN in sourceNodes) { if (bigASN != d.destination) { pathsAfter.Add(d.GetPathList(bigASN)); pathsAfterStrings.Add(d.GetPath(bigASN, state[flippedIter])); } else { //dummy vals. this source is the destination. pathsAfter.Add(new UInt32[0]); pathsAfterStrings.Add(""); } } for (int i = 0; i < sourceNodes.Count; i++) { var bigASN = sourceNodes[i]; if (bigASN != d.destination) { var pathBefore = pathsBefore[i]; var pathAfter = pathsAfter[i]; bool pathChanged = false; for (int j = 0; j < pathBefore.Length; j++) { if (pathBefore[j] != pathAfter[j]) { pathChanged = true; } } if (pathChanged) { if (pathsBeforeStrings[i].IndexOf(ASN.ToString()) >= 0 || pathsAfterStrings[i].IndexOf(ASN.ToString()) >= 0) { //the path after must have been fully secure save for the guy who flipped. and the path before cannot contain the guy who flipped. if (ResultsExplorer.fullySecure(pathsAfter[i], ASNode.NodeNum, state[flippedIter - 1], stubs) && !pathsBefore[i].Contains(ASNode.NodeNum)) { /** Console.WriteLine("---"); * Console.WriteLine("Path from: " + bigASN + " to " + customer.NodeNum + " changed from: "); * Console.WriteLine(pathsBeforeStrings[i]); * Console.WriteLine("to: "); * Console.WriteLine(pathsAfterStrings[i]); * Console.WriteLine("---"); **///don't be verbose. newCustomerPathsPerSourceNode[i]++; } } } } } //put progress meter here } return(newCustomerPathsPerSourceNode); }