private void getpath(string[] pieces) { if (pieces.Length < 3) { return; } uint as1, as2; if (!uint.TryParse(pieces[1], out as1) || !uint.TryParse(pieces[2], out as2)) { return; } if (g.GetNode(as1) == null || g.GetNode(as2) == null) { return; } Destination as2_dst = new Destination(SimulatorLibrary.initMiniDestinationSP(g, as2, false)); bool[] dummyS = new bool[Constants._numASNs]; as2_dst.UpdatePaths(dummyS); Console.WriteLine("shortest path:"); Console.WriteLine(as2_dst.GetPath(as1, g)); Console.WriteLine("regular path:"); as2_dst = new Destination(SimulatorLibrary.initMiniDestination(g, as2, false)); as2_dst.UpdatePaths(dummyS); Console.WriteLine(as2_dst.GetPath(as1)); }
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++; } }
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); }
private static bool initDestination(ref NetworkGraph g, ref Destination d, string dest) { UInt32 destNum; if (!UInt32.TryParse(dest, out destNum)) { /* * Console.WriteLine("Invalid ASN!"); */ return(false); } if (g.GetNode(destNum) == null) { /* * Console.WriteLine("WARNING: Could not retrieve destination " + d + " from the graph."); */ return(false); } /* * Console.WriteLine("Initializing variables and running RTA"); */ MiniDestination miniDest = SimulatorLibrary.initMiniDestination(g, destNum, false); d = new Destination(miniDest); bool[] tempS = new bool[Constants._numASNs]; for (int i = 0; i < tempS.Length; i++) { tempS[i] = false; } d.UpdatePaths(tempS); /* * Console.WriteLine("Done initializing. Current active destination is: " + destNum); */ return(true); }
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 <UInt32> multihomedStubs = new List <UInt32>(); foreach (UInt32 stubNum in stubs) { AsNode stub = results.g.GetNode(stubNum); //if this stub is multihomed, init a destination. add it to the list. if (stub.GetNeighborsByType(RelationshipType.CustomerOf).ToArray().Length > 1) { multihomedStubs.Add(stubNum); } } Console.WriteLine(multihomedStubs.Count + " stubs out of " + stubs.Count + " are multihomed."); StreamWriter output = new StreamWriter("trafficThroughSecureProvider.txt"); /** Second, go through each iteration... **/ int iteration = 0; foreach (bool[] S in results.state) { DateTime IterationStart = DateTime.Now; Int32 numDone = 0; foreach (UInt32 multihomedStubNum in multihomedStubs) { /** for this multhomed stub, see how much traffic * goes through secure providers **/ AsNode multihomedStub = results.g.GetNode(multihomedStubNum); Destination multihomedStubDest = new Destination(SimulatorLibrary.initMiniDestination(results.g, multihomedStubNum, false)); //computer the paths and utilities. multihomedStubDest.UpdatePaths(S); multihomedStubDest.ComputeU(GS.W); //get the providers. var Providers = multihomedStub.GetNeighborsByType(RelationshipType.CustomerOf); //count traffic through secure providers (and number of secure providers). Int64 TotalU = 0; Int64 SecureProviderU = 0; Int32 TotalProviders = Providers.Count(); Int32 SecureProviders = 0; foreach (var Provider in Providers) { if (S[Provider.NodeNum]) { SecureProviderU += multihomedStubDest.U[Provider.NodeNum]; SecureProviders++; } TotalU += multihomedStubDest.U[Provider.NodeNum]; } /*write out summary of how much traffic went through secure providers. */ output.WriteLine(iteration + " :: " + multihomedStubNum + " " + SecureProviders + " " + TotalProviders + " " + SecureProviderU + " " + TotalU); numDone++; if ((numDone % 100) == 0) { Console.WriteLine("Done " + numDone + " at " + DateTime.Now); } } //some benchmarking. Console.WriteLine(DateTime.Now + " done iteration " + iteration + " it started at " + IterationStart); iteration++; } output.Close(); }
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); }