示例#1
0
        public void Run(int attackPacketPerSec, int normalPacketPerSec, int totalPacket, int percentageOfAttackPacket, double probibilityOfPacketTunneling, double probibilityOfPacketMarking, double startFiltering, int initialTimeOfAttackPacket, bool dynamicProbability, bool considerDistance)
        {
            Random     rd = new Random();
            int        victimID;
            int        attackerIndex = 0;
            List <int> path;

            List <PacketEvent>     packetEventList     = new List <PacketEvent>();
            List <PacketSentEvent> packetSentEventList = new List <PacketSentEvent>();
            List <TunnelingEvent>  tunnelingEventList  = new List <TunnelingEvent>();
            List <MarkingEvent>    markingEventList    = new List <MarkingEvent>();
            List <FilteringEvent>  filteringEventList  = new List <FilteringEvent>();

            foreach (NetworkTopology.Node node in topology.Nodes)
            {
                if (node.Tracer == NetworkTopology.TracerType.Tunneling)
                {
                    node.ProbabilityOfTunneling = probibilityOfPacketTunneling;
                    node.FilteringCount         = probibilityOfPacketTunneling * 10;
                    node.IsTunnelingActive      = true;
                }
            }

            for (int i = 0; i < totalPacket; i++)
            {
                int tunnelingNodeID = -1;

                bool isTunneling = false;
                bool isMarking   = false;
                bool isFiltering = false;

                bool shouldMarking   = false;
                bool shouldFiltering = false;

                NetworkTopology.Node SourceNode;
                victimID = topology.idOfVictims[rd.Next(topology.idOfVictims.Count)];

                do
                {
                    if (rd.NextDouble() < (double)percentageOfAttackPacket / 100)
                    {
                        SourceNode = attackNode[attackerIndex % attackNode.Count];
                        attackerIndex++;
                    }
                    else
                    {
                        SourceNode = topology.Nodes[rd.Next(topology.Nodes.Count)];
                    }
                } while (SourceNode.ID == victimID);


                path = topology.GetShortestPath(SourceNode.ID, victimID);

                PacketEvent packetEvent = new PacketEvent()
                {
                    PacketID    = i,
                    Source      = SourceNode.ID,
                    Destination = victimID,
                    Time        = SourceNode.Type == NetworkTopology.NodeType.Attacker ? initialTimeOfAttackPacket : 0,
                    Type        = SourceNode.Type
                };

                packetEventList.Add(packetEvent);

                for (int j = 0; j < path.Count; j++)
                {
                    packetEvent.Time = j == 0 ? packetEvent.Time : packetEvent.Time += topology.AdjacentMatrix[topology.NodeID2Index(path[j - 1]), topology.NodeID2Index(path[j])].Delay;

                    switch (topology.Nodes[topology.NodeID2Index(path[j])].Tracer)
                    {
                    case NetworkTopology.TracerType.Tunneling:
                        if (!isTunneling && !isMarking && rd.NextDouble() <= topology.Nodes.Find(node => node.ID == path[j]).ProbabilityOfTunneling&& topology.Nodes.Find(node => node.ID == path[j]).IsTunnelingActive)
                        {
                            TunnelingEvent tunnelingEvent = new TunnelingEvent(packetEvent);
                            tunnelingEvent.TunnelingSrc = path[j];

                            // Re-computing path.
                            //if (i < startFiltering * totalPacket / 100)
                            if (markingEventList.Count * 100 / totalPacket < startFiltering)
                            {
                                path          = ChooseTunnelingNode(path, j, NetworkTopology.TracerType.Marking, ref tunnelingEvent, considerDistance);
                                shouldMarking = true;
                            }
                            else
                            {
                                path            = ChooseTunnelingNode(path, j, NetworkTopology.TracerType.Filtering, ref tunnelingEvent, considerDistance);
                                shouldFiltering = true;
                            }

                            tunnelingNodeID = tunnelingEvent.TunnelingSrc;

                            tunnelingEventList.Add(tunnelingEvent);
                            isTunneling = true;
                        }
                        break;

                    case NetworkTopology.TracerType.Marking:
                        if ((!isMarking && rd.NextDouble() <= probibilityOfPacketMarking && markingEventList.Count * 100 / totalPacket < startFiltering && !shouldFiltering) || shouldMarking)
                        {
                            MarkingEvent markingEvent = new MarkingEvent(packetEvent);

                            if (shouldMarking && tunnelingNodeID != -1)
                            {
                                markingEvent.MarkingNodeID = tunnelingNodeID;
                            }
                            else
                            {
                                markingEvent.MarkingNodeID = path[j];
                            }

                            markingEventList.Add(markingEvent);
                            isMarking     = true;
                            shouldMarking = false;

                            if (markingEventList.Count * 100 / totalPacket >= startFiltering)
                            {
                                foreach (MarkingEvent e in markingEventList.Where(e => e.Type != NetworkTopology.NodeType.Attacker))
                                {
                                    NetworkTopology.Node n = topology.Nodes.Find(node => node.ID == e.MarkingNodeID);
                                    if (n.Tracer == NetworkTopology.TracerType.Tunneling)
                                    {
                                        n.IsTunnelingActive = false;
                                    }
                                }
                            }
                        }
                        break;

                    case NetworkTopology.TracerType.Filtering:
                        if (shouldFiltering || markingEventList.Count * 100 / totalPacket >= startFiltering)
                        {
                            if (packetEvent.Type == NetworkTopology.NodeType.Attacker)
                            {
                                FilteringEvent filteringEvent = new FilteringEvent(packetEvent);
                                filteringEvent.FilteringNodeID = path[j];
                                filteringEventList.Add(filteringEvent);
                                isFiltering = true;

                                // Adjust probability of Tunneling tracer which tunneling from...
                                if (dynamicProbability && tunnelingNodeID != -1)
                                {
                                    Network_Simulation.NetworkTopology.Node node = topology.Nodes.Find(n => n.ID == tunnelingNodeID);
                                    node.FilteringCount         = node.FilteringCount >= 10 ? 10 : node.FilteringCount + 1;
                                    node.ProbabilityOfTunneling = node.FilteringCount / 10;
                                }
                            }
                            else if (dynamicProbability && tunnelingNodeID != -1)
                            {
                                Network_Simulation.NetworkTopology.Node node = topology.Nodes.Find(n => n.ID == tunnelingNodeID);
                                node.FilteringCount         = node.FilteringCount <= 0 ? 0 : node.FilteringCount - 1;
                                node.ProbabilityOfTunneling = node.FilteringCount / 10;
                            }
                        }
                        break;
                    }

                    if (isFiltering)
                    {
                        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 : topology.AdjacentMatrix[topology.NodeID2Index(path[j]), topology.NodeID2Index(path[j + 1])].Length;

                    packetSentEventList.Add(packetSentEvent);
                }
                Report(i + 1, totalPacket);

                //DataUtility.Log("==============================");
                //foreach (NetworkTopology.Node node in topology.Nodes)
                //    DataUtility.Log(string.Format("Node%{0} FC:{1} Tp:{2}\n", node.ID, node.FilteringCount, node.ProbabilityOfTunneling));
            }

            List <PacketSentEvent> tracingList = new List <PacketSentEvent>();
            int        packetID = 0;
            List <int> FilteringAndMarkingTracerID = new List <int>();

            if (deployment.FilteringTracerID != null)
            {
                FilteringAndMarkingTracerID.AddRange(deployment.FilteringTracerID);
            }

            if (deployment.MarkingTracerID != null)
            {
                FilteringAndMarkingTracerID.AddRange(deployment.MarkingTracerID);
            }

            foreach (int victim in topology.idOfVictims)
            {
                foreach (int nodeID in FilteringAndMarkingTracerID)
                {
                    if (victim == nodeID)
                    {
                        continue;
                    }

                    path = topology.GetShortestPath(victim, nodeID);
                    for (int i = 0; i < path.Count - 1; i++)
                    {
                        tracingList.Add(new PacketSentEvent(packetID)
                        {
                            CurrentNodeID = path[i],
                            NextHopID     = path[i + 1],
                            Length        = topology.AdjacentMatrix[topology.NodeID2Index(path[i]), topology.NodeID2Index(path[i + 1])].Length
                        });
                    }
                    packetID++;
                }

                if (version == "Random" || version == "V2")
                {
                    foreach (int nodeID in deployment.TunnelingTracerID)
                    {
                        if (victim == nodeID)
                        {
                            continue;
                        }

                        path = topology.GetShortestPath(victim, nodeID);
                        for (int i = 0; i < path.Count - 1; i++)
                        {
                            tracingList.Add(new PacketSentEvent(packetID)
                            {
                                CurrentNodeID = path[i],
                                NextHopID     = path[i + 1],
                                Length        = topology.AdjacentMatrix[topology.NodeID2Index(path[i]), topology.NodeID2Index(path[i + 1])].Length
                            });
                        }
                        packetID++;
                    }
                }
            }

            if (version == "V1")
            {
                foreach (int nodeID in deployment.TunnelingTracerID)
                {
                    deployment.FilteringTracerID.Sort((x, y) => { return(topology.GetShortestPathCount(x, nodeID).CompareTo(topology.GetShortestPathCount(y, nodeID))); });
                    path = topology.GetShortestPath(deployment.FilteringTracerID.First(), nodeID);
                    for (int i = 0; i < path.Count - 1; i++)
                    {
                        tracingList.Add(new PacketSentEvent(packetID)
                        {
                            CurrentNodeID = path[i],
                            NextHopID     = path[i + 1],
                            Length        = topology.AdjacentMatrix[topology.NodeID2Index(path[i]), topology.NodeID2Index(path[i + 1])].Length
                        });
                    }
                    packetID++;
                }
            }

            sql.InsertTracingCost(tracingList);

            sql.InsertPacketEvent(packetEventList);
            sql.InsertPacketSentEvent(packetSentEventList);
            sql.InsertTunnelingEvent(tunnelingEventList);
            sql.InsertMarkingEvent(markingEventList);
            sql.InsertFilteringEvent(filteringEventList);

            sql.LogDeploymentResult(topology, deployment);
        }
        /// <summary>
        /// Starting run algorithm with specific source topology and K-diameter cut,
        /// and this round process will generate scope topology to scop_net_topo,
        /// and will add the deployment node to deployNodes structure.
        /// Finally, it will return the remain network topology with this process.
        /// </summary>
        /// <param name="src_net_topo">The source network topology</param>
        /// <param name="scope_net_topo">This round process that generte scope topology</param>
        /// <param name="nowDeployNodes">The result of the deployment node id</param>
        /// <returns>The remain network topology after process the algorithm.</returns>
        private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes)
        {
            List <int> neighbor      = new List <int>();
            int        max_hop_count = int.MinValue;
            int        selectNode    = scope_net_topo.Nodes[0].ID;

            while (max_hop_count < K)
            {
                neighbor.Remove(selectNode);
                neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.Distinct().ToList();

                selectNode = -1;

                int minD = int.MaxValue;

                foreach (int id in neighbor)
                {
                    int tmpD = src_net_topo.Nodes.Find(n => n.ID == id).Degree;

                    if (minD > tmpD)
                    {
                        minD       = tmpD;
                        selectNode = id;
                    }
                }

                if (scope_net_topo.Nodes.Count >= N)
                {
                    selectNode = -1;
                }

                // if nothing found, break the loop.
                if (selectNode == -1)
                {
                    break;
                }
                // adding the node to the scope set, and computing the max hop count.
                else
                {
                    scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                           e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                           e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                           ));

                    scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode));


                    foreach (var scopeNode in scope_net_topo.Nodes)
                    {
                        int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode);

                        if (max_hop_count < hop_count)
                        {
                            max_hop_count = hop_count;
                        }
                    }
                }
            }

            NetworkTopology remain_topo;

            // Handling the neighbor nodes of each node in the scope network topology.
            if (selectNode != -1)
            {
                neighbor.Remove(selectNode);
                neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.Distinct().ToList();
            }

            // During above process the tmp list will be deployment nodes, and add to deployNodes list.
            nowDeployNodes.AddRange(neighbor);

            // Adding deploy nodes to the scope network topology.
            foreach (int id in neighbor)
            {
                scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                       e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                       e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                       ));

                scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id));
            }

            // Computing the complement set between source and scope network topology.
            remain_topo = src_net_topo - scope_net_topo;

            // Removing deployment nodes and edges from scope network topology.
            foreach (int id in neighbor)
            {
                scope_net_topo.Nodes.RemoveAll(x => x.ID == id);
                scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id);
            }

            return(remain_topo);
        }
        /// <summary>
        /// Starting run algorithm with specific source topology and K-diameter cut,
        /// and this round process will generate scope topology to scop_net_topo,
        /// and will add the deployment node to deployNodes structure.
        /// Finally, it will return the remain network topology with this process.
        /// </summary>
        /// <param name="src_net_topo">The source network topology</param>
        /// <param name="scope_net_topo">This round process that generte scope topology</param>
        /// <param name="nowDeployNodes">The result of the deployment node id</param>
        /// <returns>The remain network topology after process the algorithm.</returns>
        private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes)
        {
            List <int> neighbor   = new List <int>();
            int        selectNode = scope_net_topo.Nodes[0].ID;

            while (true)
            {
                neighbor.Remove(selectNode);
                neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.Distinct().ToList();

                NetworkTopology concentrate_topo = new NetworkTopology(src_net_topo.Nodes);
                concentrate_topo.AdjacentMatrix = src_net_topo.AdjacentMatrix;

                concentrate_topo.Nodes.AddRange(src_net_topo.Nodes.Except(scope_net_topo.Nodes.Where(n => n.ID != scope_net_topo.Nodes[0].ID)));
                concentrate_topo.Edges.AddRange(src_net_topo.Edges.Where(e => !scope_net_topo.Nodes.Exists(n => n.ID == e.Node1 || n.ID == e.Node2)));
                foreach (int id in neighbor)
                {
                    concentrate_topo.Edges.Add(new NetworkTopology.Edge()
                    {
                        Node1 = id, Node2 = scope_net_topo.Nodes[0].ID
                    });
                }

                selectNode = -1;

                List <int> tmp = new List <int>(neighbor);

                //neighbor.Sort((x, y) => concentrate_topo.Degree(x).CompareTo(concentrate_topo.Degree(y)));

                for (int i = 0; i < neighbor.Count; i++)
                {
                    int max_hop_count = int.MinValue;
                    int minD          = int.MaxValue;

                    foreach (int id in tmp)
                    {
                        int tmpD = concentrate_topo.Degree(id);

                        if (minD > tmpD)
                        {
                            minD       = tmpD;
                            selectNode = id;
                        }
                    }
                    tmp.Remove(selectNode);

                    foreach (var scopeNode in scope_net_topo.Nodes)
                    {
                        int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1;

                        if (max_hop_count < hop_count)
                        {
                            max_hop_count = hop_count;
                        }
                    }

                    if (max_hop_count <= K - 1)
                    {
                        break;
                    }
                    else
                    {
                        selectNode = -1;
                    }
                }

                //int minD = int.MaxValue;

                //foreach (int id in neighbor)
                //{
                //    int tmpD = concentrate_topo.Degree(id);

                //    if (minD > tmpD)
                //    {
                //        minD = tmpD;
                //        selectNode = id;
                //    }
                //}

                //if (scope_net_topo.Nodes.Count >= N)
                //    selectNode = -1;

                // if nothing found, break the loop.
                if (selectNode == -1)
                {
                    break;
                }
                // Computing the max hop counts with adding the select node.
                else
                {
                    scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                           e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                           e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                           ));

                    scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode));

                    //foreach (var scopeNode in scope_net_topo.Nodes)
                    //{
                    //    int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode);

                    //    if (max_hop_count < hop_count)
                    //        max_hop_count = hop_count;
                    //}
                }
            }

            NetworkTopology remain_topo;

            // Handling the neighbor nodes of each node in the scope network topology.
            if (selectNode != -1)
            {
                neighbor.Remove(selectNode);
                neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.Distinct().ToList();
            }

            // During above process the tmp list will be deployment nodes, and add to deployNodes list.
            nowDeployNodes.AddRange(neighbor);

            // Adding deploy nodes to the scope network topology.
            foreach (int id in neighbor)
            {
                scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                       e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                       e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                       ));

                scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id));
            }

            // Computing the complement set between source and scope network topology.
            remain_topo = src_net_topo - scope_net_topo;

            // Removing deployment nodes and edges from scope network topology.
            foreach (int id in neighbor)
            {
                scope_net_topo.Nodes.RemoveAll(x => x.ID == id);
                scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id);
            }

            return(remain_topo);
        }
        /// <summary>
        /// Starting run algorithm with specific source topology and K-diameter cut,
        /// and this round process will generate scope topology to scop_net_topo,
        /// and will add the deployment node to deployNodes structure.
        /// Finally, it will return the remain network topology with this process.
        /// </summary>
        /// <param name="src_net_topo">The source network topology</param>
        /// <param name="scope_net_topo">This round process that generte scope topology</param>
        /// <param name="nowDeployNodes">The result of the deployment node id</param>
        /// <returns>The remain network topology after process the algorithm.</returns>
        private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes)
        {
            List <NeighborIDWithMaxHopCount> neighbor = new List <NeighborIDWithMaxHopCount>();
            int selectNode    = scope_net_topo.Nodes[0].ID;
            int now_hop_count = 0;

            while (true)
            {
                neighbor.RemoveAll(n => n.NodeID == selectNode);
                foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)))
                {
                    neighbor.Add(new NeighborIDWithMaxHopCount()
                    {
                        NodeID = id, HopCount = int.MinValue
                    });
                }
                //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList();

                NetworkTopology concentrate_topo = new NetworkTopology(src_net_topo.Nodes);
                concentrate_topo.AdjacentMatrix = src_net_topo.AdjacentMatrix;

                concentrate_topo.Nodes.AddRange(src_net_topo.Nodes.Except(scope_net_topo.Nodes.Where(n => n.ID != scope_net_topo.Nodes[0].ID)));
                concentrate_topo.Edges.AddRange(src_net_topo.Edges.Where(e => !scope_net_topo.Nodes.Exists(n => n.ID == e.Node1 || n.ID == e.Node2)));
                foreach (int id in neighbor.Select(n => n.NodeID))
                {
                    concentrate_topo.Edges.Add(new NetworkTopology.Edge()
                    {
                        Node1 = id, Node2 = scope_net_topo.Nodes[0].ID
                    });
                }

                selectNode = -1;

                //neighbor.Sort((x, y) => concentrate_topo.ClusteringCoefficient(x).CompareTo(concentrate_topo.ClusteringCoefficient(y)));

                if (now_hop_count < K / 2)
                {
                    Dictionary <int, double> tmp = new Dictionary <int, double>();

                    foreach (int id in neighbor.Where(n => n.HopCount == int.MinValue).Select(n => n.NodeID))
                    {
                        tmp.Add(id, concentrate_topo.ClusteringCoefficient(id));
                    }

                    for (int i = 0; i < tmp.Count;)
                    {
                        int max_hop_count = int.MinValue;

                        selectNode = tmp.Aggregate((kvp1, kvp2) => kvp1.Value >= kvp2.Value ? kvp1 : kvp2).Key;
                        tmp.Remove(selectNode);

                        NeighborIDWithMaxHopCount nowNode = neighbor.Find(n => n.NodeID == selectNode);

                        if (nowNode.HopCount == int.MinValue)
                        {
                            foreach (var scopeNode in scope_net_topo.Nodes)
                            {
                                int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1;

                                if (max_hop_count < hop_count)
                                {
                                    max_hop_count = hop_count;
                                }
                            }

                            nowNode.HopCount = max_hop_count;
                        }
                        else
                        {
                            max_hop_count = nowNode.HopCount;
                        }

                        now_hop_count = max_hop_count;

                        if (now_hop_count <= K - 1)
                        {
                            break;
                        }
                        else
                        {
                            selectNode = -1;
                        }
                    }
                }
                else
                {
                    Dictionary <int, int> tmp = new Dictionary <int, int>();

                    foreach (int id in neighbor.Where(n => n.HopCount == int.MinValue).Select(n => n.NodeID))
                    {
                        tmp.Add(id, src_net_topo.Degree(id));
                    }

                    for (int i = 0; i < tmp.Count;)
                    {
                        int max_hop_count = int.MinValue;

                        selectNode = tmp.Aggregate((kvp1, kvp2) => kvp1.Value <= kvp2.Value ? kvp1 : kvp2).Key;
                        tmp.Remove(selectNode);

                        NeighborIDWithMaxHopCount nowNode = neighbor.Find(n => n.NodeID == selectNode);

                        if (nowNode.HopCount == int.MinValue)
                        {
                            foreach (var scopeNode in scope_net_topo.Nodes)
                            {
                                int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1;

                                if (max_hop_count < hop_count)
                                {
                                    max_hop_count = hop_count;
                                }
                            }

                            nowNode.HopCount = max_hop_count;
                        }
                        else
                        {
                            max_hop_count = nowNode.HopCount;
                        }

                        now_hop_count = max_hop_count;

                        if (now_hop_count <= K - 1)
                        {
                            break;
                        }
                        else
                        {
                            selectNode = -1;
                        }
                    }
                }

                // if nothing found, break the loop.
                if (selectNode == -1)
                {
                    break;
                }
                // adding the node to the scope set, and computing the max hop count.
                else
                {
                    scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                           e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                           e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                           ));

                    scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode));
                }
            }

            NetworkTopology remain_topo;

            // Handling the neighbor nodes of each node in the scope network topology.
            if (selectNode != -1)
            {
                neighbor.RemoveAll(n => n.NodeID == selectNode);
                foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)))
                {
                    neighbor.Add(new NeighborIDWithMaxHopCount()
                    {
                        NodeID = id, HopCount = int.MinValue
                    });
                }
                //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList();
            }

            // During above process the tmp list will be deployment nodes, and add to deployNodes list.
            nowDeployNodes.AddRange(neighbor.Select(n => n.NodeID));

            // Adding deploy nodes to the scope network topology.
            foreach (int id in neighbor.Select(n => n.NodeID))
            {
                scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                       e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                       e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                       ));

                scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id));
            }

            // Computing the complement set between source and scope network topology.
            remain_topo = src_net_topo - scope_net_topo;

            // Removing deployment nodes and edges from scope network topology.
            foreach (int id in neighbor.Select(n => n.NodeID))
            {
                scope_net_topo.Nodes.RemoveAll(x => x.ID == id);
                scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id);
            }

            return(remain_topo);
        }
        /// <summary>
        /// Starting run algorithm with specific source topology and K-diameter cut,
        /// and this round process will generate scope topology to scop_net_topo,
        /// and will add the deployment node to deployNodes structure.
        /// Finally, it will return the remain network topology with this process.
        /// </summary>
        /// <param name="src_net_topo">The source network topology</param>
        /// <param name="scope_net_topo">This round process that generte scope topology</param>
        /// <param name="nowDeployNodes">The result of the deployment node id</param>
        /// <returns>The remain network topology after process the algorithm.</returns>
        private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes)
        {
            List <NeighborIDWithMaxHopCount> neighbor = new List <NeighborIDWithMaxHopCount>();
            int selectNode = scope_net_topo.Nodes[0].ID;

            while (true)
            {
                neighbor.RemoveAll(n => n.NodeID == selectNode);
                foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)))
                {
                    neighbor.Add(new NeighborIDWithMaxHopCount()
                    {
                        NodeID = id, HopCount = int.MinValue
                    });
                }
                //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList();

                selectNode = -1;

                Dictionary <int, int> tmp = new Dictionary <int, int>();

                foreach (int id in neighbor.Where(n => n.HopCount == int.MinValue).Select(n => n.NodeID))
                {
                    tmp.Add(id, src_net_topo.Degree(id));
                }

                for (int i = 0; i < tmp.Count;)
                {
                    int max_hop_count = int.MinValue;

                    selectNode = tmp.Aggregate((kvp1, kvp2) => kvp1.Value <= kvp2.Value ? kvp1 : kvp2).Key;
                    tmp.Remove(selectNode);

                    NeighborIDWithMaxHopCount nowNode = neighbor.Find(n => n.NodeID == selectNode);

                    if (nowNode.HopCount == int.MinValue)
                    {
                        foreach (var scopeNode in scope_net_topo.Nodes)
                        {
                            int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1;

                            if (max_hop_count < hop_count)
                            {
                                max_hop_count = hop_count;
                            }
                        }

                        nowNode.HopCount = max_hop_count;
                    }
                    else
                    {
                        max_hop_count = nowNode.HopCount;
                    }

                    if (max_hop_count <= K - 1)
                    {
                        break;
                    }
                    else
                    {
                        selectNode = -1;
                    }
                }

                //int minD = int.MaxValue;

                //foreach (int id in neighbor)
                //{
                //    int tmpD = src_net_topo.Degree(id);

                //    if (minD > tmpD)
                //    {
                //        minD = tmpD;
                //        selectNode = id;
                //    }
                //}

                //if (scope_net_topo.Nodes.Count >= N)
                //    selectNode = -1;

                // if nothing found, break the loop.
                if (selectNode == -1)
                {
                    break;
                }
                // Computing the max hop counts with adding the select node.
                else
                {
                    scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                           e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                           e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                           ));

                    scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode));

                    //foreach (var scopeNode in scope_net_topo.Nodes)
                    //{
                    //    int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode);

                    //    if (max_hop_count < hop_count)
                    //        max_hop_count = hop_count;
                    //}
                }
            }

            NetworkTopology remain_topo;

            // Handling the neighbor nodes of each node in the scope network topology.
            if (selectNode != -1)
            {
                neighbor.RemoveAll(n => n.NodeID == selectNode);
                foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)))
                {
                    neighbor.Add(new NeighborIDWithMaxHopCount()
                    {
                        NodeID = id, HopCount = int.MinValue
                    });
                }
                //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList();
            }

            // During above process the tmp list will be deployment nodes, and add to deployNodes list.
            nowDeployNodes.AddRange(neighbor.Select(n => n.NodeID));

            // Adding deploy nodes to the scope network topology.
            foreach (int id in neighbor.Select(n => n.NodeID))
            {
                scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                       e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                       e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                       ));

                scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id));
            }

            // Computing the complement set between source and scope network topology.
            remain_topo = src_net_topo - scope_net_topo;

            // Removing deployment nodes and edges from scope network topology.
            foreach (int id in neighbor.Select(n => n.NodeID))
            {
                scope_net_topo.Nodes.RemoveAll(x => x.ID == id);
                scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id);
            }

            return(remain_topo);
        }
示例#6
0
        /// <summary>
        /// Starting run algorithm with specific source topology and K-diameter cut,
        /// and this round process will generate scope topology to scop_net_topo,
        /// and will add the deployment node to deployNodes structure.
        /// Finally, it will return the remain network topology with this process.
        /// </summary>
        /// <param name="src_net_topo">The source network topology</param>
        /// <param name="scope_net_topo">This round process that generte scope topology</param>
        /// <param name="nowDeployNodes">The result of the deployment node id</param>
        /// <returns>The remain network topology after process the algorithm.</returns>
        private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes)
        {
            List <NeighborIDWithMaxHopCount> neighbor = new List <NeighborIDWithMaxHopCount>();
            int selectNode = scope_net_topo.Nodes[0].ID;

            while (true)
            {
                neighbor.RemoveAll(n => n.NodeID == selectNode);
                foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)))
                {
                    neighbor.Add(new NeighborIDWithMaxHopCount()
                    {
                        NodeID = id, HopCount = int.MinValue
                    });
                }
                //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList();

                NetworkTopology concentrate_topo = new NetworkTopology(src_net_topo.Nodes);
                concentrate_topo.AdjacentMatrix = src_net_topo.AdjacentMatrix;

                concentrate_topo.Nodes.AddRange(src_net_topo.Nodes.Except(scope_net_topo.Nodes.Where(n => n.ID != scope_net_topo.Nodes[0].ID)));
                concentrate_topo.Edges.AddRange(src_net_topo.Edges.Where(e => !scope_net_topo.Nodes.Exists(n => n.ID == e.Node1 || n.ID == e.Node2)));
                foreach (int id in neighbor.Select(n => n.NodeID))
                {
                    concentrate_topo.Edges.Add(new NetworkTopology.Edge()
                    {
                        Node1 = id, Node2 = scope_net_topo.Nodes[0].ID
                    });
                }

                selectNode = -1;

                Dictionary <int, double> tmp = new Dictionary <int, double>();

                foreach (int id in neighbor.Where(n => n.HopCount == int.MinValue).Select(n => n.NodeID))
                {
                    tmp.Add(id, concentrate_topo.ClusteringCoefficient(id));
                }

                //neighbor.Sort((x, y) => concentrate_topo.ClusteringCoefficient(x).CompareTo(concentrate_topo.ClusteringCoefficient(y)));

                for (int i = 0; i < tmp.Count;)
                {
                    int max_hop_count = int.MinValue;

                    selectNode = tmp.Aggregate((kvp1, kvp2) => kvp1.Value >= kvp2.Value ? kvp1 : kvp2).Key;
                    tmp.Remove(selectNode);

                    NeighborIDWithMaxHopCount nowNode = neighbor.Find(n => n.NodeID == selectNode);

                    if (nowNode.HopCount == int.MinValue)
                    {
                        foreach (var scopeNode in scope_net_topo.Nodes)
                        {
                            int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1;

                            if (max_hop_count < hop_count)
                            {
                                max_hop_count = hop_count;
                            }
                        }

                        nowNode.HopCount = max_hop_count;
                    }
                    else
                    {
                        max_hop_count = nowNode.HopCount;
                    }

                    if (max_hop_count <= K - 1)
                    {
                        break;
                    }
                    else
                    {
                        selectNode = -1;
                    }
                }

                // if nothing found, break the loop.
                if (selectNode == -1)
                {
                    break;
                }
                // if K <= Diameter/2, checking the degree of selected node wether or not greater than threshold.
                else if (K <= Math.Ceiling(src_net_topo.Diameter / 2.0))
                {
                    List <NetworkTopology.Node> remain_nodes = src_net_topo.Nodes.Except(scope_net_topo.Nodes).ToList();
                    double avg       = remain_nodes.Average(n => src_net_topo.Degree(n.ID));
                    double std       = Math.Sqrt(remain_nodes.Sum(n => Math.Pow(src_net_topo.Degree(n.ID) - avg, 2)) / (double)remain_nodes.Count);
                    double ratio_k   = (double)K / (double)src_net_topo.Diameter;
                    int    threshold = Convert.ToInt32(Math.Round(avg + std * ratio_k, MidpointRounding.AwayFromZero));

                    //if (src_net_topo.Degree(selectNode) >= src_net_topo.Nodes.Except(scope_net_topo.Nodes).Average(n => src_net_topo.Degree(n.ID)) + K / 2)
                    if (src_net_topo.Degree(selectNode) > threshold)
                    {
                        selectNode = -1;
                        break;
                    }
                }

                // adding the node to the scope set, and computing the max hop count.
                scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                       e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                       e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                       ));

                scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode));
            }

            NetworkTopology remain_topo;

            // Handling the neighbor nodes of each node in the scope network topology.
            if (selectNode != -1)
            {
                neighbor.RemoveAll(n => n.NodeID == selectNode);
                foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)))
                {
                    neighbor.Add(new NeighborIDWithMaxHopCount()
                    {
                        NodeID = id, HopCount = int.MinValue
                    });
                }
                //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID)));
                neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList();
            }

            // During above process the tmp list will be deployment nodes, and add to deployNodes list.
            nowDeployNodes.AddRange(neighbor.Select(n => n.NodeID));

            // Adding deploy nodes to the scope network topology.
            foreach (int id in neighbor.Select(n => n.NodeID))
            {
                scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e =>
                                                                       e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) ||
                                                                       e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1)
                                                                       ));

                scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id));
            }

            // Computing the complement set between source and scope network topology.
            remain_topo = src_net_topo - scope_net_topo;

            // Removing deployment nodes and edges from scope network topology.
            foreach (int id in neighbor.Select(n => n.NodeID))
            {
                scope_net_topo.Nodes.RemoveAll(x => x.ID == id);
                scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id);
            }

            return(remain_topo);
        }
        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)
            });
        }