public override bool Allow (SimNode n1, SimNode n2) { if (n1.Nat == NatType.Symmetric && n2.Nat == NatType.Cone) { return false; } if (n2.Nat == NatType.Symmetric && n1.Nat == NatType.Cone) { return false; } if (n2.Nat == NatType.Symmetric && n2.Nat == NatType.Symmetric) { return false; } return true; }
public override bool Allow(SimNode n1, SimNode n2) { return !(_deny_matrix[n1.Idx, n2.Idx]); }
public static void Main(string []args) { Debug.Listeners.Add(new TextWriterTraceListener(Console.Out)); Debug.AutoFlush = true; Debug.WriteLineIf(true, "hello brother"); int network_size = Int32.Parse(args[0].Trim()); int m = Int32.Parse(args[1].Trim());//number of connections per node. // if (m < 2) { // //a node is not allowed to have less than 2 neighbor connections. // Console.WriteLine("atlest 2 neighbor connections required at each node"); // Environment.Exit(1); // } int index = 3; string mode = args[2].Trim(); if (mode.Equals("pair")) { int unique_bad_pairs = Int32.Parse(args[3].Trim()); index += 1; authorizer = new PairAuthorizer(network_size, unique_bad_pairs); } else if (mode.Equals("random")) { double loss_prob = double.Parse(args[3].Trim()); index += 1; authorizer = new RandomAuthorizer(network_size, loss_prob); } else if (mode.Equals("cluster")) { int cutoff = Int32.Parse(args[3].Trim()); double order = double.Parse(args[4].Trim()); index += 2; authorizer = new ClusterAuthorizer(network_size, cutoff, order); } else { Console.WriteLine("enter a valid mode"); Environment.Exit(1); } //Console.WriteLine(tunnel_mode); string routing_mode = string.Empty; if (args.Length > index) { routing_mode = args[index].Trim(); index++; } string operation_mode = string.Empty; if (args.Length > index) { operation_mode = args[index].Trim(); index++; } int node_idx = 0; for (int i = 0; i < network_size; i++) { AHAddress address = new AHAddress(new RNGCryptoServiceProvider()); SimNode node = new SimNode(address, NatType.Public, node_idx++); int idx = sorted_node_list.BinarySearch(address); if (idx < 0) { idx = ~idx; } else { Console.Error.WriteLine("Duplicate node"); } sorted_node_list.Insert(idx, address); address_to_node[address] = node; } Console.WriteLine("Nodes created: {0}.", network_size); if (routing_mode.Equals("inexact")) { //generate 10*network_size many keys key_list = new AHAddress[10*network_size]; for (int i = 0; i < key_list.Length; i++) { key_list[i] = new AHAddress(new RNGCryptoServiceProvider()); } Console.WriteLine("Keys generated: {0}.", 10*network_size); } if (operation_mode.Equals(string.Empty) || operation_mode.Equals("both")) { Console.WriteLine("Operation mode: no_tunnel"); CreateNetwork(m, false); if (routing_mode.Equals("exact")) { DoExactRouting(); } if (routing_mode.Equals("inexact")) { DoInexactRouting(); } } // // now redo the experiment in tunnel mode. // if (operation_mode.Equals("tunnel") || operation_mode.Equals("both")) { ResetNetwork(); Console.WriteLine("Operation mode: tunnel"); CreateNetwork(m, true); if (routing_mode.Equals("exact")) { DoExactRouting(); } if (routing_mode.Equals("inexact")) { DoInexactRouting(); } } }
protected void Trim(SimNode other, ConType t) { _con_table.Remove(other.LocalAddress, t); }
public void RemoveConnection(SimNode other, ConType t) { Trim(other, t); other.Trim(this, t); }
public bool AddConnection(SimNode other, ConType t) { if (other == this) { Console.WriteLine("Cannot add myself."); Environment.Exit(1); } if (_con_table.Add(other.LocalAddress, t)) { other.AddConnection(this, t); EstimateSize(); return true; } else { return false; } }
public override bool Allow(SimNode n1, SimNode n2) { return true; }
public abstract bool Allow(SimNode n1, SimNode n2);
public void TestConTable() { SortedList list = new SortedList(); for (int i = 0; i < 10; i++) { AHAddress address = new AHAddress(new RNGCryptoServiceProvider()); SimNode node = new SimNode(address, NatType.Public, 0); list[address] = node; } SimNode n0 = (SimNode) list.GetByIndex(0); for (int i = 1; i < 10; i++) { SimNode n = (SimNode) list.GetByIndex(i); n0.AddConnection(n, (i%2 == 0)?ConType.Near:ConType.Shortcut); } Assert.AreEqual(n0.ConnectionTable.GetConnections(ConType.Near).Count, 4); Assert.AreEqual(n0.ConnectionTable.GetConnections(ConType.Shortcut).Count, 5); Assert.AreEqual(n0.ConnectionTable.GetAllConnections().Count, 9); //make sure all connections are sorted in n0 table ArrayList n0_con = n0.ConnectionTable.GetAllConnections(); for (int i = 0; i < n0_con.Count; i++) { AHAddress target = (AHAddress) n0_con[i]; SimNode n = (SimNode) list.GetByIndex(i+1); Assert.AreEqual(target, n.LocalAddress); } //connection table is sorted (fine); SimNode n5 = (SimNode) list.GetByIndex(5); int idx = n0.ConnectionTable.IndexOf(n5.LocalAddress); Assert.IsTrue(idx > 0); Assert.AreEqual(idx, 4); idx = n0.ConnectionTable.IndexOf(n0.LocalAddress); Assert.IsTrue(idx < 0); idx = ~idx; Assert.IsTrue(idx == 0); for (int trials = 0; trials < 100; trials++) { AHAddress test_address = new AHAddress(new RNGCryptoServiceProvider()); SimNode test_node = new SimNode(test_address, NatType.Public, 0); list[test_address] = test_node; int test_idx = list.IndexOfKey(test_address); //address of this newly generated address idx = n0.ConnectionTable.IndexOf(test_address); Assert.IsTrue(idx < 0); idx = ~idx; if (test_idx == 0) { Assert.IsTrue(idx == 0); } else { Assert.IsTrue(idx == test_idx - 1); } list.Remove(test_address); } //do some unit tests for LeftInclusiveCount and RightInclusiveCount; for (int i = 1; i < 10; i++) { Assert.AreEqual(i-1, n0.ConnectionTable.LeftInclusiveCount(n0.LocalAddress, (AHAddress) list.GetKey(i))); //Console.WriteLine(n0.ConnectionTable.RightInclusiveCount(n0.LocalAddress, (AHAddress) list.GetKey(i))); Assert.AreEqual(list.Count - i - 1, n0.ConnectionTable.RightInclusiveCount(n0.LocalAddress, (AHAddress) list.GetKey(i))); } }
public override bool Allow(SimNode n1, SimNode n2) { return _node_to_cluster[n1.Idx] != _node_to_cluster[n2.Idx]; }