Example #1
0
 public static Func <IPacketRecord, string> GetFlowKeyFunc(FlowKey.Fields aggregation = Fields.None)
 {
     return(p =>
     {
         var fk = new FlowKey
         {
             IpSrc = aggregation.HasFlag(FlowKey.Fields.IpSrc) ? "0.0.0.0" : p.IpSrc,
             SrcPort = aggregation.HasFlag(FlowKey.Fields.SrcPort) ? 0 : p.SrcPort,
             IpDst = aggregation.HasFlag(FlowKey.Fields.IpDst) ? "0.0.0.0" : p.IpDst,
             DstPort = aggregation.HasFlag(FlowKey.Fields.DstPort) ? 0 : p.DstPort
         };
         return fk.ToString();
     });
 }
 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);
 }
Example #3
0
        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}].");
        }
Example #4
0
 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;
 }