private void CreateAnalysisData(CurrentCaptureFile file)
 {
     AnalysisEngine analysisEngine = new AnalysisEngine(AnalysisConfiguration.TrimSmallPackets, AnalysisConfiguration.HistogramBinSize, AnalysisConfiguration.HypothesisTestType, file);
     analysisEngine.CalculateSingleBatchStatistics();
     analysisEngine.CalculateCumulativeBatchStatistics();
     analysisEngine.CalculateSingleHistogramData();
     analysisEngine.CalculateCumulativeHistogramData();
     analysisEngine.CalculateCumulativeProbabilityDistribution(file.CaptureState);
     analysisEngine.CalculateHypothesisTestResults();
     analysisEngine = null;
 }
예제 #2
0
        private void ProcessCaptureDataButton_Click(object sender, EventArgs e)
        {
            // For testing - code to be moved to background worker thread
            // For production: use the OnFileReceived event handler to notify the BatchIntervalEngine that a new file has been received

            // For testing:
            BindingList<CurrentCaptureFile> _CurrentCaptureFiles = new BindingList<CurrentCaptureFile>();
            CurrentCaptureFile ccf = new CurrentCaptureFile("CaptureFile635674934252530702u.pcap", CaptureState.Unmarked);
            CurrentCaptureFile ccf1 = new CurrentCaptureFile("CaptureFile635674934452612146d.pcap", CaptureState.Marked);
            CurrentCaptureFile ccf2 = new CurrentCaptureFile("CaptureFile635674934652743658u.pcap", CaptureState.Unmarked);
            CurrentCaptureFile ccf3 = new CurrentCaptureFile("CaptureFile635674934852905142d.pcap", CaptureState.Marked);
            _CurrentCaptureFiles.Add(ccf);
            _CurrentCaptureFiles.Add(ccf1);
            _CurrentCaptureFiles.Add(ccf2);
            _CurrentCaptureFiles.Add(ccf3);

            if (_CurrentCaptureFiles.Count > 0)
            {
                foreach (CurrentCaptureFile file in _CurrentCaptureFiles)
                {
                    string captureFileName = file.FileName;

                    //BatchIntervalEngine biEngine = new BatchIntervalEngine(DbConnectionString, _ParsedFilesPath, _CurrentCaptureFileName, 5, InterarrivalInterval.GetIntervalMilliSeconds());
                    //string captureFileName = "CaptureFile635674934252530702u.pcap";
                    BatchIntervalEngine biEngine = new BatchIntervalEngine(DbConnectionString, _ParsedFilesPath, captureFileName, 5, InterarrivalInterval.GetIntervalMilliSeconds());
                    biEngine.ProcessNewBatchIntervals();

                    //AnalysisEngine analysisEngine = new AnalysisEngine(AnalysisConfiguration.TrimSmallPackets, AnalysisConfiguration.HistogramBinSize, AnalysisConfiguration.HypothesisTest, captureFileName, file.CaptureState);
                    AnalysisEngine analysisEngine = new AnalysisEngine(AnalysisConfiguration.TrimSmallPackets, AnalysisConfiguration.HistogramBinSize, AnalysisConfiguration.HypothesisTestType, file);
                    analysisEngine.CalculateSingleBatchStatistics();
                    analysisEngine.CalculateCumulativeBatchStatistics();
                    analysisEngine.CalculateSingleHistogramData();
                    analysisEngine.CalculateCumulativeHistogramData();
                    analysisEngine.CalculateCumulativeProbabilityDistribution(file.CaptureState);
                    analysisEngine.CalculateHypothesisTestResults();

                    biEngine = null;
                    analysisEngine = null;
                }
            }

            /******************************** Old code ********************************************/
            //DisplayStatisticsData bsd = new DisplayStatisticsData();
            //BindingList<DisplayStatistic> ds = new BindingList<DisplayStatistic>();
            //ds = bsd.GetSingleMarkedDisplayStatistics();

            //bool success = false;

            ////int intervalSizeMs = 30 ;
            //int intervalSizeMs = InterarrivalInterval.GetIntervalMilliSeconds();

            //// For testing:
            //BindingList<CurrentCaptureFile> _CurrentCaptureFiles = new BindingList<CurrentCaptureFile>();
            //CurrentCaptureFile ccf = new CurrentCaptureFile("CaptureFile635674934252530702u.pcap", CaptureState.Unmarked);
            //CurrentCaptureFile ccf1 = new CurrentCaptureFile("CaptureFile635674934452612146d.pcap", CaptureState.Marked);
            //CurrentCaptureFile ccf2 = new CurrentCaptureFile("CaptureFile635674934652743658u.pcap", CaptureState.Unmarked);
            //CurrentCaptureFile ccf3 = new CurrentCaptureFile("CaptureFile635674934852905142d.pcap", CaptureState.Marked);
            //_CurrentCaptureFiles.Add(ccf);
            //_CurrentCaptureFiles.Add(ccf1);
            //_CurrentCaptureFiles.Add(ccf2);
            //_CurrentCaptureFiles.Add(ccf3);

            //if (_CurrentCaptureFiles.Count > 0)
            //{
            //    foreach (CurrentCaptureFile file in _CurrentCaptureFiles)
            //    {
            //        BindingList<RawPacket> rawPackets = new BindingList<RawPacket>();
            //        BindingList<PacketInterval> intervalCounts = new BindingList<PacketInterval>();

            //        //int captureBatchId = 0;

            //        ProcessCapturePackets pcp = new ProcessCapturePackets();

            //        ClientStatusToolStripStatusLabel.Visible = true;
            //        ClientStatusToolStripProgressBar.Visible = true;
            //        ClientStatusToolStripStatusLabel.Text = "Loading capture packets into data store for file [" + file.FileName + "]...";

            //        try
            //        {
            //            rawPackets = pcp.LoadPackets(file.FileName);
            //            if (rawPackets.Count > 0) { success = true; }
            //        }
            //        catch (Exception ex)
            //        {
            //            MessageBox.Show("Error loading raw packet data for file [" + file.FileName + "]: " + ex.Message, "Process Capture Packets - Load Packets");
            //        }
            //        try
            //        {
            //            if (success)
            //            {
            //                intervalCounts = pcp.CalculateIntervalCounts(rawPackets, intervalSizeMs);
            //            }
            //        }
            //        catch (Exception ex)
            //        {
            //            success = false;
            //            MessageBox.Show("Error calculating interval counts for file [" + file.FileName + "]: " + ex.Message, "Process Capture Packets - Calculate Interval Counts");
            //        }

            //        // Load the batch intervals into the database
            //        if (success)
            //        {
            //            try
            //            {
            //                //success = pcp.SaveBatchIntervals(DbConnectionString, intervalCounts, file.FileName, captureBatchId, file.Marked);
            //                success = pcp.SaveBatchIntervals(DbConnectionString, intervalCounts);
            //            }
            //            catch (Exception ex)
            //            {
            //                success = false;
            //                MessageBox.Show("Error saving batch interval counts: " + ex.Message, "Save Batch Intervals");
            //            }
            //        }

            //        // Add batch to cumulative totals
            //        if(success)
            //        {
            //            try
            //            {
            //                //success = pcp.UpdateCumulativeIntervals(DbConnectionString, intervalCounts, file.Marked);
            //                success = pcp.UpdateCumulativeIntervals(DbConnectionString, intervalCounts);
            //            }
            //            catch (Exception ex)
            //            {
            //                success = false;
            //                MessageBox.Show("Error updating cumulative intervals for this file  [" + file.FileName + "]: " + ex.Message);
            //            }
            //        }

            //        BindingList<BatchIntervalMarked> markedIntervals = new BindingList<BatchIntervalMarked>();
            //        var captureBatchId = (from i in intervalCounts
            //                              select i.CaptureBatchId).FirstOrDefault();

            //        markedIntervals = pcp.GetMarkedBatchIntervals(captureBatchId);
            //        //AnalyzeData ad = new AnalyzeData(markedIntervals);

            //        CalculateHistogram h = new CalculateHistogram();
            //        Dictionary<int, int> histValues = new Dictionary<int, int>();
            //        //histValues = h.CalculateHistogramValues(markedIntervals);

            //        BindingList<CapturePacket> capturePackets = new BindingList<CapturePacket>();
            //        capturePackets = pcp.GetCapturePackets(file.FileName);
            //        histValues = h.CalculateHistogramValues(capturePackets);

            //        //Dictionary<int, decimal> probabilities = new CalculateProbability(histValues).GetProbabilityValues();
            //        //SortedDictionary<int, decimal> probabilities = new CalculateProbability(markedIntervals).GetProbabilityByPacketRange();

            //        // Display the batch in the graph:
            //        // - One batch each of marked and unmarked - alternate as a new batch becomes available
            //        // - One batch each of cumulative marked and unmarked - alternate as a new batch becomes available
            //        // - Add to cumulative distribution and display
            //    }
            //}
            //else
            //{
            //    MessageBox.Show("No capture files found to process!", "Process Capture Files");
            //}
        }
예제 #3
0
        private void RecalculateData()
        {
            BatchIntervalEngine intervalEngine = new BatchIntervalEngine(DatabaseConnections.SqlConnection, AnalysisConfiguration.ProcessedCaptureFilesPath, "allFiles", 5, AnalysisConfiguration.IntervalSize);
            intervalEngine.RecalculateBatchIntervals();

            ProcessCapturePackets pcp = new ProcessCapturePackets();

            BindingList<CurrentCaptureFile> captureFiles = new BindingList<CurrentCaptureFile>();
            captureFiles = pcp.GetAllCaptureFiles();

            if (captureFiles.Count > 0)
            {
                foreach (CurrentCaptureFile file in captureFiles)
                {
                    AnalysisEngine analysisEngine = new AnalysisEngine(AnalysisConfiguration.TrimSmallPackets, AnalysisConfiguration.HistogramBinSize, AnalysisConfiguration.HypothesisTestType, file);
                    analysisEngine.CalculateSingleBatchStatistics();
                    analysisEngine.CalculateCumulativeBatchStatistics();
                    analysisEngine.CalculateSingleHistogramData();
                    analysisEngine.CalculateCumulativeHistogramData();
                    analysisEngine.CalculateCumulativeProbabilityDistribution(file.CaptureState);
                    analysisEngine.CalculateHypothesisTestResults();
                    analysisEngine = null;
                }
            }
        }
예제 #4
0
        private void RefreshCumulativeBatchStatistics()
        {
            // Get the cumulative interval counts
            ProcessCapturePackets pcp = new ProcessCapturePackets();
            BindingList<CumulativeInterval> cumulativeIntervals = new BindingList<CumulativeInterval>();
            cumulativeIntervals = pcp.GetCumulativeIntervals();

            // Get the batch intervals
            BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>();
            BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>();

            foreach (CumulativeInterval ci in cumulativeIntervals)
            {
                if (ci.Marked)
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = 0;
                    bim.CaptureBatchId = 0;
                    bim.IntervalNumber = ci.CumulativeIntervalNumber;
                    bim.Marked = CaptureState.Marked;
                    bim.PacketCount = ci.PacketCount;
                    markedBatchIntervals.Add(bim);
                }
                else
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = 0;
                    bim.CaptureBatchId = 0;
                    bim.IntervalNumber = ci.CumulativeIntervalNumber;
                    bim.Marked = CaptureState.Unmarked;
                    bim.PacketCount = ci.PacketCount;
                    unmarkedBatchIntervals.Add(bim);
                }
            }

            BatchStatistics markedCumulativeStats = new BatchStatistics();
            BatchStatistics unmarkedCumulativeStats = new BatchStatistics();
            decimal markedMeanOfMeans = 0;
            decimal markedStdDevMeanOfMeans = 0;
            decimal unmarkedMeanOfMeans = 0;
            decimal unmarkedStdDevMeanOfMeans = 0;

            AnalysisEngine ae = new AnalysisEngine();

            if(markedBatchIntervals.Count > 0)
            {
                markedCumulativeStats = ae.CalculateBatchStatistics(markedBatchIntervals,CaptureState.Marked, BatchType.Cumulative);
                markedMeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Marked, TrimIntervals ? true : false);
                markedStdDevMeanOfMeans = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Marked, TrimIntervals ? true : false);

                // Load up the table
                // Cumulative marked column
                int row = 0;
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.IntervalCount;
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = TrimIntervals == true ? markedCumulativeStats.IntervalCountTrimmed.ToString() : "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.PacketCountMean);
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.PacketCountStandardDeviation);
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.PacketCountMinimum;
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.PacketCountMaximum;
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedMeanOfMeans);
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = "N/A";
            }

            if (unmarkedBatchIntervals.Count > 0)
            {
                unmarkedCumulativeStats = ae.CalculateBatchStatistics(unmarkedBatchIntervals, CaptureState.Marked, BatchType.Cumulative);
                unmarkedMeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Unmarked, TrimIntervals ? true : false);
                unmarkedStdDevMeanOfMeans = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Unmarked, TrimIntervals ? true : false);

                // Load up the table
                // Cumulative unmarked column
                int row = 0;
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.IntervalCount;
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = TrimIntervals == true ? unmarkedCumulativeStats.IntervalCountTrimmed.ToString() : "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.PacketCountMean);
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.PacketCountStandardDeviation);
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.PacketCountMinimum;
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.PacketCountMaximum;
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedMeanOfMeans);
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = "N/A";
            }

            if (markedBatchIntervals.Count > 0 && unmarkedBatchIntervals.Count > 0)
            {
                // Cumulative variance column
                int row = 0;
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.IntervalCount - markedCumulativeStats.IntervalCount;
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = TrimIntervals == true ? (unmarkedCumulativeStats.IntervalCountTrimmed - markedCumulativeStats.IntervalCountTrimmed).ToString() : "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.PacketCountMean - markedCumulativeStats.PacketCountMean));
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.PacketCountStandardDeviation - markedCumulativeStats.PacketCountStandardDeviation));
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.PacketCountMinimum - markedCumulativeStats.PacketCountMinimum;
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.PacketCountMaximum - markedCumulativeStats.PacketCountMaximum;
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedMeanOfMeans - markedMeanOfMeans));
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = "N/A";
            }

            // Update the K-S statistics object
            _KsStatistics.MarkedMean = markedMeanOfMeans;
            _KsStatistics.MarkedStdDev = markedStdDevMeanOfMeans;
            //_KsStatistics.MarkedMean = markedCumulativeStats.PacketCountMean;
            //_KsStatistics.MarkedStdDev = markedCumulativeStats.PacketCountStandardDeviation;
            _KsStatistics.MarkedIntervalCount = TrimIntervals == true ? markedCumulativeStats.IntervalCountTrimmed : markedCumulativeStats.IntervalCount;
            _KsStatistics.UnmarkedMean = unmarkedMeanOfMeans;
            _KsStatistics.UnmarkedStdDev = unmarkedStdDevMeanOfMeans;
            //_KsStatistics.UnmarkedMean = unmarkedCumulativeStats.PacketCountMean;
            //_KsStatistics.UnmarkedStdDev = unmarkedCumulativeStats.PacketCountStandardDeviation;
            _KsStatistics.UnmarkedIntervalCount = TrimIntervals == true ? unmarkedCumulativeStats.IntervalCountTrimmed : unmarkedCumulativeStats.IntervalCount;
        }