internal void Dump(FlowStats stats) { OpenLogfile(); writer.Write(new DateTime(stats.First).ToString("yyyy-MM-dd HH:mm:ss.fff")); writer.Write("\t"); TimeSpan duration = new TimeSpan(stats.Last - stats.First); writer.Write(duration.TotalMilliseconds.ToString("F0")); writer.Write("\t"); writer.Write(stats.Key.Source.Address); writer.Write("\t"); writer.Write(stats.Key.Source.Port); writer.Write("\t"); writer.Write(stats.Key.Destination.Address); writer.Write("\t"); writer.Write(stats.Key.Destination.Port); writer.Write("\t"); writer.Write((int)stats.Key.Protocol); writer.Write("\t"); writer.Write(stats.Packets); writer.Write("\t"); writer.Write(stats.Bytes); writer.WriteLine(); }
public FlowStats Resolve(Flow key, long packetTime) { FlowStats stats; if ((queue.Count > 0) && queue.Head.Key.Equals(key)) { stats = queue.Head; } else { stats = flows.ContainsKey(key) ? flows[key] : null; if (stats == null) { stats = new FlowStats(key); stats.First = packetTime; flows.Add(key, stats); } else if (queue.Count > 0) { queue.Remove(stats); } queue.Add(stats); } return(stats); }
public void Close() { pcap.Close(); #region Dump log while (tracker.Count > 0) { FlowStats stats = tracker.Tail; Dump(stats); tracker.Remove(stats); } #endregion writer.Close(); }
public void Add(FlowStats flow) { if (count == 0) { head = flow; tail = flow; flow.Next = null; flow.Prev = null; } else { flow.Next = head; head.Prev = flow; head = flow; } count++; }
public void Remove(FlowStats flow) { if (count == 0) { // Nothing to do ... //throw new InvalidOperationException("Remove from empty list"); return; } else if (count == 1) { if (flow != head) { // Nothing to do ... //throw new InvalidOperationException("Remove item not in list"); return; } else { head = null; tail = null; } } else { if (flow == head) { head = flow.Next; head.Prev = null; } else if (flow == tail) { tail = flow.Prev; tail.Next = null; } else { flow.Prev.Next = flow.Next; flow.Next.Prev = flow.Prev; } } flow.Next = null; flow.Prev = null; count--; }
public void Remove(FlowStats stats) { queue.Remove(stats); flows.Remove(stats.Key); }
public void Promote(FlowStats flow) { // TODO: Remove, then add Remove(flow); Add(flow); }
public FlowStats Resolve(Flow key, long packetTime) { FlowStats stats; if ((queue.Count > 0) && queue.Head.Key.Equals(key)) { stats = queue.Head; } else { stats = flows.ContainsKey(key) ? flows[key] : null; if (stats == null) { stats = new FlowStats(key); stats.First = packetTime; flows.Add(key, stats); } else if (queue.Count > 0) { queue.Remove(stats); } queue.Add(stats); } return stats; }