public static FlowProfile Create(ProtocolFactory protocolFactory, FlowKey.Fields flowAggregation, Enum modelKey, Type typ, string[] dimensions, double windowSize) { if (typ == typeof(CoapStatisticalModel)) { return(new FlowProfile(protocolFactory, dimensions, windowSize, flowAggregation, modelKey, new StatisticalModelFactory())); } if (typ == typeof(CoapMixtureModel)) { return(new FlowProfile(protocolFactory, dimensions, windowSize, flowAggregation, modelKey, new CoapMixtureModelFactory())); } if (typ == typeof(CoapStatisticalFingerprint)) { return(new FlowProfile(protocolFactory, dimensions, windowSize, flowAggregation, modelKey, new CoapStatisticalFingerprintFactory())); } return(null); }
private void LoadAndCompute(FlowProfile profile, string inputFile, IList <CoapPacketRecord> packets, double windowSize, LearningWindow learningWindows, ProtocolFactory protocolFactory, Enum modelKey, FlowKey.Fields flowAggregation = FlowKey.Fields.None) { var getFlowKeyFunc = FlowKey.GetFlowKeyFunc(flowAggregation); var getModelKeyFunc = protocolFactory.GetModelKeyFunc(modelKey); Console.WriteLine("┌ Load packets and compute profile:"); Console.WriteLine($"├─ input file: {inputFile}"); Console.WriteLine($"├─ packets count: {packets.Count}"); Console.WriteLine($"├─ window size: {windowSize} seconds"); Console.WriteLine($"├─ learning window: {learningWindows.Meassure}({learningWindows.Value})"); Console.WriteLine($"├─ protocol: {protocolFactory.Name}"); Console.WriteLine($"├─ model key: {modelKey}"); Console.WriteLine($"├─ flow aggregation: {flowAggregation}"); var sw = new Stopwatch(); sw.Start(); var startTime = packets.First().TimeEpoch; var packetBins = packets.GroupBy(p => (int)Math.Floor((p.TimeEpoch - startTime) / windowSize)).ToList(); var learningBins = learningWindows.Meassure == LearningWindow.ValueType.Absolute ? packetBins.Take((int)learningWindows.Value) : packetBins.Take((int)(packetBins.Count() * learningWindows.Value)); var pb1 = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new ProgressBar(packetBins.Count()) : null; foreach (var group in packetBins) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { pb1.Next($"├─ processing bin {group.Key}: {group.Count()} items"); } var flows = protocolFactory.CollectCoapFlows(group, getModelKeyFunc, getFlowKeyFunc); ComputeProfile(profile, flows); } var pb2 = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new ProgressBar(profile.Count) : null; profile.Commit(() => { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { pb2.Next($"├─ fitting models"); } }); Console.WriteLine($"└ done [{sw.Elapsed}]."); }
private void ProcessInput(string inputCsvFile, string inputCapFile, string outputFile, Settings settings) { var flowAggregation = settings.FlowAggregationFields; var protocolFactory = ProtocolFactory.Create(settings.Protocol); var modelKey = protocolFactory.GetModelKeyFields(settings.ModelKey); Console.WriteLine("IRONSTONE FLOW PROFILING: Learn Profile"); var profile = ProfileFactory.Create(protocolFactory, flowAggregation, modelKey, settings.ModelType, new string[] { "Packets", "Octets" }, settings.WindowSize); if (File.Exists(inputCsvFile)) { var packets = PacketLoader.LoadCoapPacketsFromCsv(inputCsvFile).ToList(); LoadAndCompute(profile, Path.GetFullPath(inputCsvFile), packets, settings.WindowSize, settings.WindowsCount, protocolFactory, modelKey, flowAggregation); } if (File.Exists(inputCapFile)) { var packets = PacketLoader.LoadCoapPacketsFromCap(inputCapFile).ToList(); LoadAndCompute(profile, Path.GetFullPath(inputCapFile), packets, settings.WindowSize, settings.WindowsCount, protocolFactory, modelKey, flowAggregation); } StoreProfile(profile, outputFile); }
public FlowProfile(ProtocolFactory protocolFactory, string[] dimensions, double windowSize, FlowKey.Fields flowAggregation, Enum modelKey, IFlowModelFactory builder) { ProtocolFactory = protocolFactory; Dimensions = dimensions; WindowSize = windowSize; FlowAggregation = flowAggregation; ModelKey = modelKey; ModelBuilder = builder; }