Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void Close()
        {
            pcap.Close();

            #region Dump log
            while (tracker.Count > 0)
            {
                FlowStats stats = tracker.Tail;
                Dump(stats);
                tracker.Remove(stats);
            }
            #endregion

            writer.Close();
        }
Esempio n. 4
0
 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++;
 }
Esempio n. 5
0
 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--;
 }
Esempio n. 6
0
 public void Remove(FlowStats stats)
 {
     queue.Remove(stats);
     flows.Remove(stats.Key);
 }
Esempio n. 7
0
 public void Promote(FlowStats flow)
 {
     // TODO: Remove, then add
     Remove(flow);
     Add(flow);
 }
Esempio n. 8
0
        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;
        }
Esempio n. 9
0
 public void Remove(FlowStats stats)
 {
     queue.Remove(stats);
       flows.Remove(stats.Key);
 }
Esempio n. 10
0
 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--;
 }
Esempio n. 11
0
 public void Promote(FlowStats flow)
 {
     // TODO: Remove, then add
       Remove(flow);
       Add(flow);
 }
Esempio n. 12
0
 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++;
 }
Esempio n. 13
0
        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();
        }