public NetworkViewForm(string briteFilePath, Type deployType)
        {
            InitializeComponent();

            tb_file_name.Text = briteFilePath;

            m_topo = new NetworkTopology(0, 0);

            m_topo.SetupDrawingControl(draw_panel);

            tb_k.TextChanged += new EventHandler(checkValid);
            tb_n.TextChanged += new EventHandler(checkValid);

            tb_k.KeyPress += new KeyPressEventHandler(checkInputValue);
            tb_n.KeyPress += new KeyPressEventHandler(checkInputValue);

            btn_show.Click += (s, e) =>
            {
                m_topo.ReadBriteFile(tb_file_name.Text);

                int K = int.Parse(tb_k.Text);
                int N = int.Parse(tb_n.Text);

                Deployment deployment = Activator.CreateInstance(deployType, new object[] { 30, 20, 10, K, N }) as Deployment; //new KCutStartWithConsider2KConsiderCoefficient(10, 10, 10, K, N);
                deployment.Deploy(m_topo);

                draw_panel.Invalidate();
            };
        }
Пример #2
0
        public NetworkViewForm(string mapFileName, string dbFileName)
        {
            InitializeComponent();

            this.dbFileName = Path.Combine(Environment.CurrentDirectory, "Log", dbFileName);;

            comboBox1.Items.Add(typeof(NoneDeployment).Name);
            comboBox1.Items.Add(typeof(RandomDeployment).Name);
            comboBox1.Items.Add("KCutDeployV1");
            comboBox1.Items.Add("KCutDeployV2");
            //comboBox1.Items.Add(typeof(KCutStartWithCenterNode).Name);
            //comboBox1.Items.Add(typeof(KCutStartWithCenterNodeConsiderCoefficient).Name);
            //comboBox1.Items.Add(typeof(KCutStartWithComparableConsiderCoefficient).Name);
            //comboBox1.Items.Add(typeof(KCutStartWithConsider2KConsiderCoefficient).Name);
            //comboBox1.Items.Add(typeof(KCutStartWithSideNode).Name);
            //comboBox1.Items.Add(typeof(KCutStartWithSideNodeConsiderCoefficient).Name);

            comboBox1.SelectedValue = typeof(NoneDeployment).Name;
            networkTopology         = new NetworkTopology(0, 0);
            networkTopology.ReadBriteFile(mapFileName);

            networkTopology.SetupDrawingControl(panel1);
        }
Пример #3
0
        void bg_DoWork(object sender, DoWorkEventArgs e)
        {
            //try
            //{
            foreach (string filename in filenames)
            {
                string dbName = string.Format("{0}_T{1}M{2}F{3}_A{4}V{5}_Pkt{6}_{7}", Path.GetFileNameWithoutExtension(filename),
                                              TunnelingTracer.Text,
                                              MarkingTracer.Text,
                                              FilteringTracer.Text,
                                              AttackNodes.Text,
                                              VictimNodes.Text,
                                              TotalPacket.Text,
                                              PercentageOfAttackPacket.Text);

                SQLiteUtility sql = new SQLiteUtility(ref dbName);
                postfixIndex = Convert.ToInt32(Path.GetFileNameWithoutExtension(dbName).Split('_').Last());

                // Read network topology and initialize the attackers, normal users and victim.
                NetworkTopology networkTopology = new NetworkTopology(Convert.ToDouble(AttackNodes.Text), Convert.ToInt32(VictimNodes.Text));
                networkTopology.ReadBriteFile(filename);

                //// Doesn't use any deployment method.
                NoneDeployment noneDeply = new NoneDeployment(0, 0, 0);
                sql.CreateTable(noneDeply.ToString());
                noneDeply.Deploy(networkTopology);
                Simulator noneSimulator = new Simulator(noneDeply, networkTopology, sql, "None");
                noneSimulator.onReportOccur += delegate(object obj, Simulator.ReportArgument ra)
                {
                    bg.ReportProgress(ra.CurrentPacket * 100 / ra.TotalPacket, new ProgressReportArg()
                    {
                        KEY = filename, ST = StatusType.NoneDeploymentStatus
                    });
                };
                noneSimulator.Run(Convert.ToInt32(AttackPacketPerSec.Text), Convert.ToInt32(NormalPacketPerSec.Text), Convert.ToInt32(TotalPacket.Text), Convert.ToInt32(PercentageOfAttackPacket.Text), Convert.ToDouble(ProbibilityOfPacketTunneling.Text), Convert.ToDouble(ProbibilityOfPacketMarking.Text), Convert.ToDouble(StartFiltering.Text), Convert.ToInt32(InitTimeOfAttackPacket.Text), DynamicProbability.Checked, ConsiderDistance.Checked);

                bg.ReportProgress((filenames.IndexOf(filename) * 4 + 1) * 100 / (filenames.Count * 4), new ProgressReportArg()
                {
                    ST = StatusType.TotalProgress
                });

                //// Using randomly depolyment method.
                RandomDeployment randomDeploy = new RandomDeployment(Convert.ToDouble(TunnelingTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100, Convert.ToDouble(MarkingTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100, Convert.ToDouble(FilteringTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100);
                sql.CreateTable(randomDeploy.ToString());
                randomDeploy.Deploy(networkTopology);
                Simulator randomSimulator = new Simulator(randomDeploy, networkTopology, sql, "Random");
                randomSimulator.onReportOccur += delegate(object obj, Simulator.ReportArgument ra)
                {
                    bg.ReportProgress(ra.CurrentPacket * 100 / ra.TotalPacket, new ProgressReportArg()
                    {
                        KEY = filename, ST = StatusType.RandomDeploymentStatus
                    });
                };
                randomSimulator.Run(Convert.ToInt32(AttackPacketPerSec.Text), Convert.ToInt32(NormalPacketPerSec.Text), Convert.ToInt32(TotalPacket.Text), Convert.ToInt32(PercentageOfAttackPacket.Text), Convert.ToDouble(ProbibilityOfPacketTunneling.Text), Convert.ToDouble(ProbibilityOfPacketMarking.Text), Convert.ToDouble(StartFiltering.Text), Convert.ToInt32(InitTimeOfAttackPacket.Text), DynamicProbability.Checked, ConsiderDistance.Checked);

                bg.ReportProgress((filenames.IndexOf(filename) * 4 + 2) * 100 / (filenames.Count * 4), new ProgressReportArg()
                {
                    ST = StatusType.TotalProgress
                });

                // Using KCut deployment method.
                KCutDeployment kCutDeploy = new KCutDeployment(Convert.ToDouble(TunnelingTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100, Convert.ToDouble(MarkingTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100, Convert.ToDouble(FilteringTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100, typeof(KCutStartWithSideNodeConsiderCoefficient));
                sql.CreateTable("KCutDeployV1");
                kCutDeploy.Deploy(networkTopology);
                Simulator kCutSimulator = new Simulator(kCutDeploy.Deployment, networkTopology, sql, "V1");
                kCutSimulator.onReportOccur += delegate(object obj, Simulator.ReportArgument ra)
                {
                    bg.ReportProgress(ra.CurrentPacket * 100 / ra.TotalPacket, new ProgressReportArg()
                    {
                        KEY = filename, ST = StatusType.KCutDeploymentStatus
                    });
                };
                kCutSimulator.Run(Convert.ToInt32(AttackPacketPerSec.Text), Convert.ToInt32(NormalPacketPerSec.Text), Convert.ToInt32(TotalPacket.Text), Convert.ToInt32(PercentageOfAttackPacket.Text), Convert.ToDouble(ProbibilityOfPacketTunneling.Text), Convert.ToDouble(ProbibilityOfPacketMarking.Text), Convert.ToDouble(StartFiltering.Text), Convert.ToInt32(InitTimeOfAttackPacket.Text), DynamicProbability.Checked, ConsiderDistance.Checked);

                bg.ReportProgress((filenames.IndexOf(filename) * 4 + 3) * 100 / (filenames.Count * 4), new ProgressReportArg()
                {
                    ST = StatusType.TotalProgress
                });

                // Using KCutV2 deployment method.
                KCutDeploymentV2 kCut2Deploy = new KCutDeploymentV2(Convert.ToDouble(TunnelingTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100, Convert.ToDouble(MarkingTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100, Convert.ToDouble(FilteringTracer.Text) * Convert.ToDouble(PercentageOfTracer.Text) / 100, typeof(KCutStartWithSideNodeConsiderCoefficient));
                sql.CreateTable("KCutDeployV2");
                kCut2Deploy.Deploy(networkTopology);
                Simulator kCut2Simulator = new Simulator(kCut2Deploy.Deployment, networkTopology, sql, "V2");
                kCut2Simulator.onReportOccur += delegate(object obj, Simulator.ReportArgument ra)
                {
                    bg.ReportProgress(ra.CurrentPacket * 100 / ra.TotalPacket, new ProgressReportArg()
                    {
                        KEY = filename, ST = StatusType.KCut2DeploymentStatus
                    });
                };
                kCut2Simulator.Run(Convert.ToInt32(AttackPacketPerSec.Text), Convert.ToInt32(NormalPacketPerSec.Text), Convert.ToInt32(TotalPacket.Text), Convert.ToInt32(PercentageOfAttackPacket.Text), Convert.ToDouble(ProbibilityOfPacketTunneling.Text), Convert.ToDouble(ProbibilityOfPacketMarking.Text), Convert.ToDouble(StartFiltering.Text), Convert.ToInt32(InitTimeOfAttackPacket.Text), DynamicProbability.Checked, ConsiderDistance.Checked);

                bg.ReportProgress((filenames.IndexOf(filename) * 4 + 4) * 100 / (filenames.Count * 4), new ProgressReportArg()
                {
                    ST = StatusType.TotalProgress
                });
            }

            File.WriteAllLines(Path.Combine(Environment.CurrentDirectory, "Log", "ARGS.txt"), new string[] {
                "Percentage of Attack node:" + AttackNodes.Text,
                "Number of Victim:" + VictimNodes.Text,
                "Percentage of Tracer:" + PercentageOfTracer.Text,
                "Percentage of Tunneling Tracer:" + TunnelingTracer.Text,
                "Percentage of Marking Tracer:" + MarkingTracer.Text,
                "Percentage of Filtering Tracer:" + FilteringTracer.Text,
                "Percentage of Marking receive, then begin filtering:" + StartFiltering.Text,
                "Attack packet per second:" + AttackPacketPerSec.Text,
                "Normal packet per second:" + NormalPacketPerSec.Text,
                "Total Packet:" + TotalPacket.Text,
                "Percentage of Attack Packet:" + PercentageOfAttackPacket.Text,
                "Initial Time of Attack Packet:" + InitTimeOfAttackPacket.Text,
                "Probability of Packet Tunneling:" + ProbibilityOfPacketTunneling.Text,
                "Probability of Packet Marking:" + ProbibilityOfPacketMarking.Text
            });
            //}
            //catch (Exception exception)
            //{
            //    Console.WriteLine(exception.Message);
            //    //MessageBox.Show(exception.Message);
            //}
        }
Пример #4
0
        static void Main(string[] args)
        {
            string filename                     = args[0];
            int    TunnelingTracer              = Convert.ToInt32(args[1]);
            int    MarkingTracer                = Convert.ToInt32(args[2]);
            int    FilteringTracer              = Convert.ToInt32(args[3]);
            double AttackNodes                  = Convert.ToDouble(args[4]);
            int    VictimNodes                  = Convert.ToInt32(args[5]);
            int    TotalPacket                  = Convert.ToInt32(args[6]);
            int    PercentageOfAttackPacket     = Convert.ToInt32(args[7]);
            int    AttackPacketPerSecond        = Convert.ToInt32(args[8]);
            int    NormalPacketPerSecond        = Convert.ToInt32(args[9]);
            double ProbabilityOfPacketTunneling = Convert.ToDouble(args[10]);
            double ProbabilityOfPackeMarking    = Convert.ToDouble(args[11]);
            double StartFiltering               = Convert.ToDouble(args[12]);
            int    InitTimeOfAttackPacket       = Convert.ToInt32(args[13]);
            bool   DynamicProbability           = Convert.ToBoolean(args[14]);
            bool   ConsiderDistance             = Convert.ToBoolean(args[15]);
            double PercentageOfTracer           = Convert.ToDouble(args[16]);
            string methodName                   = args[17];

            string dbName = string.Format("{0}_T{1}M{2}F{3}_A{4}V{5}_Pkt{6}_{7}", Path.GetFileNameWithoutExtension(filename),
                                          TunnelingTracer,
                                          MarkingTracer,
                                          FilteringTracer,
                                          AttackNodes,
                                          VictimNodes,
                                          TotalPacket,
                                          PercentageOfAttackPacket);


            filename = Path.Combine(Environment.CurrentDirectory, "maps", filename);

            SQLiteUtility   sql             = new SQLiteUtility(ref dbName);
            NetworkTopology networkTopology = new NetworkTopology(AttackNodes, VictimNodes);

            networkTopology.ReadBriteFile(filename);

            NoneDeployment noneDeploy = new NoneDeployment(0, 0, 0);

            if (sql.CreateTable(noneDeploy.ToString()))
            {
                noneDeploy.Deploy(networkTopology);
                Simulator noneSimulator = new Simulator(noneDeploy, networkTopology, sql, "None");
                noneSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
            }
            else
            {
                // Load Attackers and Victim.
                sql.LoadAttackersAndVictim(ref networkTopology);
            }

            RandomDeployment randomDeploy;
            KCutDeployment   kcutDeploy;
            KCutDeploymentV2 kcut2Deploy;

            switch (methodName)
            {
            case "RandomDeployment":
                randomDeploy = new RandomDeployment(TunnelingTracer * PercentageOfTracer / 100, MarkingTracer * PercentageOfTracer / 100, FilteringTracer * PercentageOfTracer / 100);
                if (sql.CreateTable(randomDeploy.ToString()))
                {
                    randomDeploy.Deploy(networkTopology);
                    if (MarkingTracer > 0)
                    {
                        MarkingAssistanceSimulator markSimulator = new MarkingAssistanceSimulator(randomDeploy, networkTopology, sql, "Random");
                        markSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                    else
                    {
                        Simulator randomSimulator = new Simulator(randomDeploy, networkTopology, sql, "Random");
                        randomSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                }
                break;

            case "KCutDeployment":
                kcutDeploy = new KCutDeployment(TunnelingTracer * PercentageOfTracer / 100, MarkingTracer * PercentageOfTracer / 100, FilteringTracer * PercentageOfTracer / 100, typeof(KCutStartWithSideNodeConsiderCoefficient));
                if (sql.CreateTable("KCutDeployV1"))
                {
                    kcutDeploy.Deploy(networkTopology);
                    if (MarkingTracer > 0)
                    {
                        MarkingAssistanceSimulator markSimulator = new MarkingAssistanceSimulator(kcutDeploy.Deployment, networkTopology, sql, "Random");
                        markSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                    else
                    {
                        Simulator kcutSimulator = new Simulator(kcutDeploy.Deployment, networkTopology, sql, "V1");
                        kcutSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                }
                break;

            case "KCutDeployment2":
                kcut2Deploy = new KCutDeploymentV2(TunnelingTracer * PercentageOfTracer / 100, MarkingTracer * PercentageOfTracer / 100, FilteringTracer * PercentageOfTracer / 100, typeof(KCutStartWithSideNodeConsiderCoefficient));
                if (sql.CreateTable("KCutDeployV2"))
                {
                    kcut2Deploy.Deploy(networkTopology);
                    if (MarkingTracer > 0)
                    {
                        MarkingAssistanceSimulator markSimulator = new MarkingAssistanceSimulator(kcut2Deploy.Deployment, networkTopology, sql, "Random");
                        markSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                    else
                    {
                        Simulator kcut2Simulator = new Simulator(kcut2Deploy.Deployment, networkTopology, sql, "V2");
                        kcut2Simulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                }
                break;

            case "OPTRandomDeployment":
                // Optimal Random
                randomDeploy = new RandomDeployment(TunnelingTracer * PercentageOfTracer / 100, MarkingTracer * PercentageOfTracer / 100, FilteringTracer * PercentageOfTracer / 100);
                if (sql.CreateTable("OPTRandomDeployment"))
                {
                    randomDeploy.Deploy(networkTopology);
                    if (MarkingTracer > 0)
                    {
                        OptMarkingAssistanceSimulator markSimulator = new OptMarkingAssistanceSimulator(randomDeploy, networkTopology, sql, "Random");
                        markSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                    else
                    {
                        OptSimulator optRandomSimulator = new OptSimulator(randomDeploy, networkTopology, sql, "Random");
                        optRandomSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                }
                break;

            case "OPTKCutDeployment":
                // Optimal KCutV1
                kcutDeploy = new KCutDeployment(TunnelingTracer * PercentageOfTracer / 100, MarkingTracer * PercentageOfTracer / 100, FilteringTracer * PercentageOfTracer / 100, typeof(KCutStartWithSideNodeConsiderCoefficient));
                if (sql.CreateTable("OPTKCutDeployV1"))
                {
                    kcutDeploy.Deploy(networkTopology);
                    if (MarkingTracer > 0)
                    {
                        OptMarkingAssistanceSimulator markSimulator = new OptMarkingAssistanceSimulator(kcutDeploy.Deployment, networkTopology, sql, "Random");
                        markSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                    else
                    {
                        OptSimulator optKCutSimulator = new OptSimulator(kcutDeploy.Deployment, networkTopology, sql, "V1");
                        optKCutSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                }
                break;

            case "OPTKCutDeploymentV2":
                // Optimal KCutV2
                kcut2Deploy = new KCutDeploymentV2(TunnelingTracer * PercentageOfTracer / 100, MarkingTracer * PercentageOfTracer / 100, FilteringTracer * PercentageOfTracer / 100, typeof(KCutStartWithSideNodeConsiderCoefficient));
                if (sql.CreateTable("OPTKCutDeployV2"))
                {
                    kcut2Deploy.Deploy(networkTopology);
                    if (MarkingTracer > 0)
                    {
                        OptMarkingAssistanceSimulator markSimulator = new OptMarkingAssistanceSimulator(kcut2Deploy.Deployment, networkTopology, sql, "Random");
                        markSimulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                    else
                    {
                        OptSimulator kcut2Simulator = new OptSimulator(kcut2Deploy.Deployment, networkTopology, sql, "V2");
                        kcut2Simulator.Run(AttackPacketPerSecond, NormalPacketPerSecond, TotalPacket, PercentageOfAttackPacket, ProbabilityOfPacketTunneling, ProbabilityOfPackeMarking, StartFiltering, InitTimeOfAttackPacket, DynamicProbability, ConsiderDistance);
                    }
                }
                break;
            }
        }
Пример #5
0
        private void eventRegist()
        {
            m_simulation_worker.DoWork += (s, e) =>
            {
                Deployment deployment = null;
                Simulator  sim = new Simulator(m_topo, m_now_deployment_method);
                string[]   files = tb_select_file.Text.Split(';');
                int        K, N = 0;

                for (int i = 0; i < files.Length; i++)
                {
                    m_simulation_worker.ReportProgress((int)(((double)(i) / (double)files.Count()) * 100.0),
                                                       new object[] { true, string.Format("Running {0}...", Path.GetFileNameWithoutExtension(files[i])) });

                    if (rdoBtn_specific.Checked)
                    {
                        K = int.Parse(tb_k.Text);
                        N = int.Parse(tb_n.Text);

                        m_simulation_worker.ReportProgress(0,
                                                           new object[] { false, "Preprocessing file...", true, files[i], K, N });

                        m_topo.ReadBriteFile(files[i]);

                        m_simulation_worker.ReportProgress(33,
                                                           new object[] { false, string.Format("Starting Deployment with K: {0}, N: {1}...", K, N), true, files[i], K, N });

                        // Using kcutwithclustering depolyment method.
                        deployment = Activator.CreateInstance(m_deploy_types.Find(t => t.Name == m_now_deployment_method), new object[] { 30, 20, 10, K, N }) as Deployment;// new KCutStartWithConsider2KConsiderWithCoefficient(30, 20, 10, K, N);
                        deployment.Deploy(m_topo);

                        m_simulation_worker.ReportProgress(100,
                                                           new object[] { false, string.Format("Completed for K: {0}, N: {1}.", K, N), true, files[i], K, N });
                    }
                    else
                    {
                        m_simulation_worker.ReportProgress(0,
                                                           new object[] { false, "Preprocessing file...", true, files[i], 0, 0 });

                        m_topo.ReadBriteFile(files[i]);

                        List <int> last_deploy_count;
                        int        satisfy_count;

                        for (K = 2; K <= m_topo.Diameter; K += 2)
                        {
                            N             = 0;
                            satisfy_count = 0;

                            if (m_now_deployment_method == typeof(KCutStartWithSideNodeConsiderCoefficientWithN).Name ||
                                m_now_deployment_method == typeof(KCutStartWithSideNodeConsiderCoefficientWithNRatio).Name ||
                                m_now_deployment_method == typeof(KCutStartWithSideNodeConsiderCoefficientStrictDegreeWithN).Name)
                            {
                                do
                                {
                                    if (N >= 50)
                                    {
                                        break;
                                    }

                                    //if (deployment != null)
                                    //    last_deploy_count = new List<int>(deployment.DeployNodes);
                                    //else
                                    //    last_deploy_count = new List<int>();

                                    using (deployment = Activator.CreateInstance(m_deploy_types.Find(t => t.Name == m_now_deployment_method), new object[] { 30, 20, 10, K, N += 10 }) as Deployment)
                                    {
                                        m_simulation_worker.ReportProgress((int)((double)K / (double)m_topo.Diameter * 100),
                                                                           new object[] { false, string.Format("Starting Deployment with K: {0}, N: {1}...", K, N), true, files[i], K, N });

                                        deployment.Deploy(m_topo);

                                        if (cb_run_sim.Checked && m_sim_run_n_range.Contains(N))
                                        {
                                            sim.Deployment = deployment;
                                            sim.Run();
                                        }

                                        m_simulation_worker.ReportProgress((int)((double)K / (double)m_topo.Diameter * 100),
                                                                           new object[] { false, string.Format("Completed for K: {0}, N: {1}.", K, N), true, files[i], K, N });

                                        //if (deployment.DeployNodes.Except(last_deploy_count).Count() == 0 && last_deploy_count.Except(deployment.DeployNodes).Count() == 0)
                                        //    satisfy_count++;
                                        //else
                                        //    satisfy_count = 0;
                                    }
                                } while (true);//satisfy_count < 2);
                            }
                            else
                            {
                                N = 1;
                                using (deployment = Activator.CreateInstance(m_deploy_types.Find(t => t.Name == m_now_deployment_method), new object[] { 30, 20, 10, K, N }) as Deployment)
                                {
                                    m_simulation_worker.ReportProgress((int)((double)K / (double)m_topo.Diameter * 100),
                                                                       new object[] { false, string.Format("Starting Deployment with K: {0}, N: {1}...", K, N), true, files[i], K, N });

                                    deployment.Deploy(m_topo);

                                    if (cb_run_sim.Checked)
                                    {
                                        sim.Deployment = deployment;
                                        sim.Run();
                                    }

                                    m_simulation_worker.ReportProgress((int)((double)K / (double)m_topo.Diameter * 100),
                                                                       new object[] { false, string.Format("Completed for K: {0}, N: {1}.", K, N), true, files[i], K, N });
                                }
                            }
                        }
                        m_simulation_worker.ReportProgress(100,
                                                           new object[] { false, string.Format("Completed for K: {0}, N: {1}.", K, N), true, files[i], K, N });
                    }

                    m_simulation_worker.ReportProgress((int)(((double)(i + 1) / (double)files.Count()) * 100.0),
                                                       new object[] { true, string.Format("Running {0}...", Path.GetFileNameWithoutExtension(files[i])) });
                }
            };

            m_simulation_worker.ProgressChanged += (s, e) =>
            {
                object[] obj = e.UserState as object[];

                if (obj != null)
                {
                    bool   isMainProgress = (bool)obj[0];
                    string status         = (string)obj[1];

                    if (isMainProgress)
                    {
                        progress_main.Value   = e.ProgressPercentage;
                        lb_main_progress.Text = string.Format("Main Progress: {0}", status);
                    }
                    else
                    {
                        bool isNeedRefreshList = (bool)obj[2];

                        progress_sub.Value   = e.ProgressPercentage;
                        lb_sub_progress.Text = string.Format("Sub Progress: {0}", status);

                        if (isNeedRefreshList)
                        {
                            string fileName = (string)obj[3];
                            int    k        = (int)obj[4];
                            int    n        = (int)obj[5];

                            lv_list.Items[fileName].SubItems[1].Text = k.ToString();
                            lv_list.Items[fileName].SubItems[2].Text = n.ToString();
                            lv_list.Items[fileName].SubItems[3].Text = status;

                            foreach (int index in lv_list.SelectedIndices)
                            {
                                lv_list.Items[index].Selected = false;
                            }

                            lv_list.Items[fileName].Selected = true;
                            lv_list.Items[fileName].Focused  = true;
                            //lv_list.TopItem = lv_list.Items[fileName];
                        }
                    }
                }
            };

            m_simulation_worker.RunWorkerCompleted += (s, e) =>
            {
                btn_run.Enabled       = true;
                groupBox2.Enabled     = true;
                cb_deployment.Enabled = true;

                if (rdoBtn_specific.Checked)
                {
                    tb_k.Enabled = true;
                    tb_n.Enabled = true;
                }

                tb_select_file.Enabled = true;

                lb_main_progress.Text = "Main Progress: Completed.";
                lb_sub_progress.Text  = "Sub Progress: Completed.";
            };

            m_data_worker.DoWork += (s, e) =>
            {
                object[] data = e.Argument as object[];

                if (data != null)
                {
                    bool       isQuery = (bool)data[0];
                    string     sqlCmd;
                    Deployment deployment = Activator.CreateInstance(m_deploy_types.Find(t => t.Name == m_now_deployment_method), new object[] { 30, 20, 10, 1, 1 }) as Deployment;// new Deployment.DeploySQLiteUtility("deploy_simulation");

                    if (isQuery)
                    {
                        sqlCmd = (string)data[1];

                        DataView dv = deployment.sqlite_utility.GetResult(sqlCmd, null);

                        e.Result = new object[] { true, dv };
                    }
                    else
                    {
                        string filePath = (string)data[1];
                        sqlCmd = "SELECT k,n,deploy_type,file_name,node_counts,level,edge_counts,diameter,job_id,deploy_name,node_id FROM (SELECT * FROM NetworkTopology AS N JOIN DeploySimulation AS D on N.n_id=D.n_id JOIN LevelRecord AS L on D.job_id=L.job_id ) AS Data";

                        DataView dv = deployment.sqlite_utility.GetResult(sqlCmd, null);

                        if (dv != null && dv.Count > 0)
                        {
                            DataUtility.ExcelExport(dv.Table, filePath, false);
                            e.Result = data;
                        }
                    }
                }
            };

            m_data_worker.RunWorkerCompleted += (s, e) =>
            {
                object[] data = e.Result as object[];

                if (data != null)
                {
                    bool isQuery = (bool)data[0];

                    if (isQuery)
                    {
                        DataView dv = data[1] as DataView;
                        if (dv != null && dv.Count > 0)
                        {
                            dataGridView1.DataSource = dv;
                        }
                        btn_query.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show(this, string.Format("The file: {0} has been exported.", Path.GetFileName((string)data[1])), "Export Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        btn_export.Enabled = true;
                    }
                    Cursor = Cursors.Arrow;
                }
            };

            lv_list.MouseDoubleClick += (s, e) =>
            {
                if (lv_list.SelectedIndices.Count > 0)
                {
                    ListViewItem item = lv_list.Items[lv_list.SelectedIndices[0]];

                    if (item.SubItems[3].Text.Contains("Completed"))
                    {
                        m_now_deployment_method = cb_deployment.SelectedItem.ToString();
                        NetworkViewForm view = new NetworkViewForm(item.Name, m_deploy_types.Find(t => t.Name == m_now_deployment_method));
                        view.Show(this);
                    }
                }
            };

            tb_select_file.Click += (s, e) =>
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect      = true;
                ofd.InitialDirectory = Environment.CurrentDirectory;
                ofd.Filter           = "Birte File|*.brite";
                ofd.Title            = "Select Brite Files";
                ofd.FileName         = "";

                if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    tb_select_file.Clear();

                    lv_list.BeginUpdate();
                    lv_list.Items.Clear();

                    foreach (string file in ofd.FileNames)
                    {
                        tb_select_file.Text += file + ";";

                        ListViewItem lvi = new ListViewItem(new string[] { Path.GetFileNameWithoutExtension(file), "0", "0", "Queued." });
                        lvi.Name = file;

                        lv_list.Items.Add(lvi);
                    }

                    tb_select_file.Text = tb_select_file.Text.TrimEnd(';');

                    lv_list.EndUpdate();
                }
            };

            btn_run.Click += (s, e) =>
            {
                m_now_deployment_method = cb_deployment.SelectedItem.ToString();
                m_simulation_worker.RunWorkerAsync();
                btn_run.Enabled       = false;
                groupBox2.Enabled     = false;
                cb_deployment.Enabled = false;

                if (rdoBtn_specific.Checked)
                {
                    tb_k.Enabled = false;
                    tb_n.Enabled = false;
                }

                tb_select_file.Enabled = false;
            };

            btn_query.Click += (s, e) =>
            {
                m_now_deployment_method = cb_deployment.SelectedItem.ToString();
                btn_query.Enabled       = false;
                Cursor = Cursors.WaitCursor;
                m_data_worker.RunWorkerAsync(new object[] { true, tb_sql_cmd.Text });
            };

            btn_export.Click += (s, e) =>
            {
                m_now_deployment_method = cb_deployment.SelectedItem.ToString();
                SaveFileDialog sfd = new SaveFileDialog();

                sfd.InitialDirectory = Environment.CurrentDirectory;
                sfd.OverwritePrompt  = true;
                sfd.Title            = "Export to";
                sfd.Filter           = "Excel Files|*.xls";
                sfd.FileName         = "";

                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    btn_export.Enabled = false;
                    Cursor             = Cursors.WaitCursor;
                    m_data_worker.RunWorkerAsync(new object[] { false, sfd.FileName });
                }
            };

            Load += (s, e) =>
            {
                btn_query.PerformClick();
            };

            tb_select_file.TextChanged += new EventHandler(checkValid);
            tb_k.TextChanged           += new EventHandler(checkValid);
            tb_n.TextChanged           += new EventHandler(checkValid);

            tb_k.KeyPress += new KeyPressEventHandler(checkInputValue);
            tb_n.KeyPress += new KeyPressEventHandler(checkInputValue);

            rdoBtn_specific.CheckedChanged += new EventHandler(rdoBtn_CheckedChanged);
            rdoBtn_all.CheckedChanged      += new EventHandler(rdoBtn_CheckedChanged);
        }