public void Deploy(NetworkTopology networkTopology) { numberOfTTracer = Convert.ToInt32(Math.Round(percentageOfTunnelingTracer * networkTopology.Nodes.Count / 100, 0, MidpointRounding.AwayFromZero)); numberOfMTracer = Convert.ToInt32(Math.Round(percentageOfMarkingTracer * networkTopology.Nodes.Count / 100, 0, MidpointRounding.AwayFromZero)); numberOfFTracer = Convert.ToInt32(Math.Round(percentageOfFilteringTracer * networkTopology.Nodes.Count / 100, 0, MidpointRounding.AwayFromZero)); List <int> last_deploy_count; int satisfy_count; Deployment try_deploy = null; List <Deployment> dList = new List <Deployment>(); for (int K = 1; K <= networkTopology.Diameter; K++) { int N = 0; satisfy_count = 0; do { if (try_deploy != null) { last_deploy_count = new List <int>(try_deploy.DeployNodes); } else { last_deploy_count = new List <int>(); } try_deploy = Activator.CreateInstance(m_deploy_type, new object[] { percentageOfTunnelingTracer, percentageOfMarkingTracer, percentageOfFilteringTracer, K, ++N }) as Deployment; try_deploy.Deploy(networkTopology); if (try_deploy.DeployNodes.Count <= numberOfTTracer) { DataUtility.Log(string.Format("K={0},N={1},|D|={2}\n", try_deploy.K, try_deploy.N, try_deploy.DeployNodes.Count)); dList.Add(try_deploy); } if (try_deploy.DeployNodes.Except(last_deploy_count).Count() == 0 && last_deploy_count.Except(try_deploy.DeployNodes).Count() == 0) { satisfy_count++; } else { satisfy_count = 0; } } while (satisfy_count < 2); } dList.Sort((x, y) => x.DeployNodes.Count.CompareTo(y.DeployNodes.Count)); m_deployment = dList.Last(); int c, e; List <NetworkTopology.Node> centerNode = new List <NetworkTopology.Node>(); foreach (var scope in m_deployment.AllRoundScopeList) { if (scope.FindCenterNodeID(out c, out e, true)) { DataUtility.Log(string.Format("center ID: {0}\n", c)); centerNode.Add(networkTopology.Nodes.Find(n => n.ID == c)); } else { DataUtility.Log(string.Format("center ID: {0}\n", scope.Nodes[0].ID)); centerNode.Add(networkTopology.Nodes.Find(n => n.ID == scope.Nodes[0].ID)); } } networkTopology.Reset(); // Clear the deployment method. foreach (NetworkTopology.Node node in networkTopology.Nodes) { node.Tracer = NetworkTopology.TracerType.None; } centerNode.Sort((x, y) => x.Eccentricity.CompareTo(y.Eccentricity)); m_deployment.FilteringTracerID = new List <int>(); m_deployment.MarkingTracerID = new List <int>(); m_deployment.TunnelingTracerID = new List <int>(); for (int i = 0; i < numberOfFTracer; i++) { NetworkTopology.Node node = centerNode.Find(n => n.Tracer == NetworkTopology.TracerType.None); if (node == null) { int j = i; do { NetworkTopology t = m_deployment.AllRoundScopeList.Find(s => s.Nodes.Exists(n => n == centerNode[j % centerNode.Count])); node = t.Nodes.Find(n => n.Tracer == NetworkTopology.TracerType.None); j++; } while (node == null); } node.Tracer = NetworkTopology.TracerType.Filtering; m_deployment.FilteringTracerID.Add(node.ID); } for (int i = 0; i < numberOfMTracer; i++) { NetworkTopology.Node node = centerNode.Find(n => n.Tracer == NetworkTopology.TracerType.None); if (node == null) { int j = i; do { NetworkTopology t = m_deployment.AllRoundScopeList.Find(s => s.Nodes.Exists(n => n == centerNode[j % centerNode.Count])); node = t.Nodes.Find(n => n.Tracer == NetworkTopology.TracerType.None); j++; } while (node == null); } node.Tracer = NetworkTopology.TracerType.Marking; m_deployment.MarkingTracerID.Add(node.ID); } foreach (int id in m_deployment.DeployNodes) { networkTopology.Nodes.Find(n => n.ID == id).Tracer = NetworkTopology.TracerType.Tunneling; m_deployment.TunnelingTracerID.Add(id); } if (m_deployment.DeployNodes.Count < numberOfTTracer) { for (int i = 0; i < numberOfTTracer - m_deployment.DeployNodes.Count; i++) { NetworkTopology.Node node; int j = i; do { NetworkTopology t = m_deployment.AllRoundScopeList.Find(s => s.Nodes.Exists(n => n == centerNode[j % centerNode.Count])); node = t.Nodes.Find(n => n.Tracer == NetworkTopology.TracerType.None); j++; } while (node == null); node.Tracer = NetworkTopology.TracerType.Tunneling; m_deployment.TunnelingTracerID.Add(node.ID); } } }
private void simSpecificDeployMethod() { int centerID, minE; List <int> path; List <MarkingEvent> markingEventList = new List <MarkingEvent>(); //List<PacketEvent> packetEventList = new List<PacketEvent>(); //List<PacketSentEvent> packetSentEventList = new List<PacketSentEvent>(); List <int> firstMeetTracerHopCountList = new List <int>(); List <int> srcToScopeCenterHopCountList = new List <int>(); List <int> attackerAreaCounts = new List <int>(); List <int> pathCountList = new List <int>(); Random rd = new Random(Guid.NewGuid().GetHashCode()); for (int i = 0; i < c_packetNumber; i++) { bool isMarking = false; NetworkTopology.Node srcNode = m_networkTopology.Nodes[rd.Next(m_networkTopology.Nodes.Count)]; NetworkTopology.Node desNode = null; while (desNode == null || desNode == srcNode) { desNode = m_networkTopology.Nodes[rd.Next(m_networkTopology.Nodes.Count)]; } NetworkTopology sourceScope = m_deployment.AllRoundScopeList.Find(scope => scope.Nodes.Exists(n => n.ID == srcNode.ID)); if (sourceScope != null) { if (sourceScope.FindCenterNodeID(out centerID, out minE) && srcNode.ID != centerID) { srcToScopeCenterHopCountList.Add(m_networkTopology.GetShortestPathCount(srcNode.ID, centerID) - 1); } else { srcToScopeCenterHopCountList.Add(0); } attackerAreaCounts.Add(sourceScope.Nodes.Count); } else { srcToScopeCenterHopCountList.Add(0); attackerAreaCounts.Add(0); } path = m_networkTopology.GetShortestPath(srcNode.ID, desNode.ID); PacketEvent packetEvent = new PacketEvent() { PacketID = i, Source = srcNode.ID, Destination = desNode.ID, Time = 0, Type = NetworkTopology.NodeType.Attacker }; //packetEventList.Add(packetEvent); for (int j = 0; j < path.Count; j++) { switch (m_networkTopology.Nodes[m_networkTopology.NodeID2Index(path[j])].Tracer) { case NetworkTopology.TracerType.None: break; case NetworkTopology.TracerType.Marking: if (!isMarking) { MarkingEvent markingEvent = new MarkingEvent(packetEvent); markingEvent.MarkingNodeID = path[j]; firstMeetTracerHopCountList.Add(j); isMarking = true; markingEventList.Add(markingEvent); } break; case NetworkTopology.TracerType.Tunneling: break; case NetworkTopology.TracerType.Filtering: break; default: break; } //PacketSentEvent packetSentEvent = new PacketSentEvent(packetEvent); //packetSentEvent.CurrentNodeID = path[j]; //packetSentEvent.NextHopID = j == path.Count - 1 ? -1 : path[j + 1]; //packetSentEvent.Length = j == path.Count - 1 ? 0 : m_networkTopology.AdjacentMatrix[m_networkTopology.NodeID2Index(path[j]), m_networkTopology.NodeID2Index(path[j + 1])].Length; //packetSentEventList.Add(packetSentEvent); } pathCountList.Add(path.Count - 1); if (!isMarking) { firstMeetTracerHopCountList.Add(path.Count - 1); } } m_networkTopology.Reset(); // Log into db double theoreticalUndetectedRatio = (double)m_deployment.AllRoundScopeList.Sum(s => s.Nodes.Count > 1 ? DataUtility.Combination(s.Nodes.Count, 2) : 0) / (double)DataUtility.Combination(m_networkTopology.Nodes.Count, 2); double upperboundUndetectedRatio = m_networkTopology.m_prob_hop.Sum(i => (m_networkTopology.m_prob_hop.ToList().IndexOf(i) >= 1 && m_networkTopology.m_prob_hop.ToList().IndexOf(i) <= m_deployment.K - 1) ? i : 0); double undetectedRatio = (double)(c_packetNumber - markingEventList.Count) / (double)c_packetNumber; double firstMeetTracerSearchingCost = (double)firstMeetTracerHopCountList.Sum() / (double)c_packetNumber; double srcToScopeCenterSearchingCost = (double)srcToScopeCenterHopCountList.Sum() / (double)c_packetNumber; double attackerScopeCountSearchingCost = attackerAreaCounts.Average(); double savingCost = 0; double survivalTrafficRatio = (double)firstMeetTracerHopCountList.Sum() / (double)pathCountList.Sum(); for (int i = 0; i < c_packetNumber; i++) { savingCost += pathCountList[i] - firstMeetTracerHopCountList[i]; } savingCost /= c_packetNumber; string cmd; // UndetectedRatio cmd = "INSERT INTO UndetectedRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "K-Cut Deployment"), new SQLiteParameter("@ratio", undetectedRatio) }); cmd = "INSERT INTO UndetectedRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "Theoretical Undetected Ratio"), new SQLiteParameter("@ratio", theoreticalUndetectedRatio) }); cmd = "INSERT INTO UndetectedRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "Theoretical Undetected Ratio Upper Bound"), new SQLiteParameter("@ratio", upperboundUndetectedRatio) }); // Searching Cost cmd = "INSERT INTO SearchingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "K-Cut Deployment - First Meet Tracer"), new SQLiteParameter("@ratio", firstMeetTracerSearchingCost) }); cmd = "INSERT INTO SearchingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", @"K-Cut Deployment - Attacker to Scope Center"), new SQLiteParameter("@ratio", srcToScopeCenterSearchingCost) }); cmd = "INSERT INTO SearchingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", @"K-Cut Deployment - The Number of Nodes in Attacker Area"), new SQLiteParameter("@ratio", attackerScopeCountSearchingCost) }); // Saving Cost cmd = "INSERT INTO SavingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "K-Cut Deployment"), new SQLiteParameter("@ratio", savingCost) }); // Survival Malicious Traffic Ratio cmd = "INSERT INTO SurvivalMaliciousTrafficRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "K-Cut Deployment"), new SQLiteParameter("@ratio", survivalTrafficRatio) }); }