Ejemplo n.º 1
0
        /// <summary>
        /// Returns a list of flows
        /// </summary>
        /// <param name="packets"></param>
        /// <returns></returns>
        public static List <Flow2> GenerateFlows(IEnumerable <Packet2> packets)
        {
            // System.Console.WriteLine("flows2/GenerateFlows");
            SortedList <ConnectionPair2, Flow2> flows = new SortedList <ConnectionPair2, Flow2>();

            int id = 0;

            foreach (Packet2 pkt in packets)
            {
                ConnectionPair2 conn    = new ConnectionPair2(pkt);
                ConnectionPair2 revConn = conn.BackwardDirection; // the reverse direction of the flow

                if (!flows.ContainsKey(conn))
                {
                    if (!flows.ContainsKey(revConn))
                    {
                        flows.Add(conn, new Flow2(id++, conn));
                    }
                    else
                    {
                        conn = revConn;
                    }
                }

                flows[conn].AddPacket(pkt);
            }

            return(flows.Values.ToList());
        }
Ejemplo n.º 2
0
        public Flow2(int id, ConnectionPair2 connection)
        {
            this._id = id;

            this._pktList = new List <Packet2>();

            this._conn = connection;

            this.ProcessName = default(string);
        }
Ejemplo n.º 3
0
        public Flow2(int id, ConnectionPair2 connection, IEnumerable <Packet2> pktList)
        {
            this._id = id;

            this._conn = connection;

            this._pktList = new List <Packet2>();

            this._pktList.AddRange(pktList);

            this.ProcessName = default(string);
        }
Ejemplo n.º 4
0
        public int CompareTo(object obj)
        {
            if (obj is ConnectionPair2)
            {
                ConnectionPair2 cp = (ConnectionPair2)obj;

                if (this.Equals(cp))
                {
                    return(0);
                }
                else
                {
                    if (cp.Protocol == this.Protocol)
                    {
                        if (Protocol != Packet2.Protocol.UDP)
                        {
                            if (SrcEnd.Port > cp.SrcEnd.Port)
                            {
                                return(1);
                            }
                            else if (SrcEnd.Port == cp.SrcEnd.Port)
                            {
                                return(DestEnd.Port >= cp.DestEnd.Port ? 1 : -1);
                            }
                            else
                            {
                                return(-1);
                            }
                        }
                        else
                        {
                            return(SrcEnd.Port >= cp.SrcEnd.Port ? 1 : -1);
                        }
                    }
                    else
                    {
                        return(this.Protocol == Packet2.Protocol.TCP ? 1 : -1);
                    }
                }
            }
            else
            {
                return(-1);
            }
        }
Ejemplo n.º 5
0
        public override bool Equals(object obj)
        {
            if (!(obj is ConnectionPair2))
            {
                return(false);
            }

            ConnectionPair2 cpObj = (ConnectionPair2)obj;

            if (cpObj.SrcEnd.AddressFamily.Equals(this.SrcEnd.AddressFamily))
            {
                if (cpObj.SrcEnd.Address.Equals(this.SrcEnd.Address) &&
                    cpObj.DestEnd.Address.Equals(this.DestEnd.Address) &&
                    (cpObj.SrcEnd.Port == this.SrcEnd.Port) &&
                    (cpObj.DestEnd.Port == this.DestEnd.Port) &&
                    (cpObj.Protocol == this.Protocol))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        public static int GetLabelIndex_ME(ConnectionPair2 conn, byte [] srcMAc, byte [] dstMAC)
        {
            ///we first chech the value by IP

            byte[]        srcIP = conn.SrcEnd.Address.GetAddressBytes();
            byte[]        dstIP = conn.DestEnd.Address.GetAddressBytes();
            StringBuilder SRCip = new StringBuilder();
            StringBuilder DSTip = new StringBuilder();
            int           index = 0;

            //  int indexDST = 0;

            for (int i = 0; i < 3; i++)
            {
                SRCip.Append(srcIP[i].ToString());
                SRCip.Append(".");
            }

            SRCip.Append(srcIP[3].ToString());


            if (_labelIndex.TryGetValue(SRCip.ToString(), out index))
            {
                return(index);
            }

            else /// search by dest ip

            {
                for (int i = 0; i < 3; i++)
                {
                    DSTip.Append(dstIP[i].ToString());
                    DSTip.Append(".");
                }
            }

            DSTip.Append(dstIP[3].ToString());


            if (_labelIndex.TryGetValue(DSTip.ToString(), out index))
            {
                return(index);
            }

            // search by src mac

            /// then check by mac if it is not in IP labels
            StringBuilder SRCmac = new StringBuilder();
            StringBuilder DSTmac = new StringBuilder();

            for (int i = 0; i < 5; i++)
            {
                SRCmac.Append(srcMAc[i].ToString("X2"));
                SRCmac.Append(":");
            }

            SRCmac.Append(srcMAc[5].ToString("X2"));

            if (SRCmac.ToString().CompareTo(SRCmac.ToString().ToUpper()) != 0)
            {
                System.Diagnostics.Debug.WriteLine(SRCmac.ToString() + "<==>" + SRCmac.ToString().ToUpper());
            }


            if (_labelIndex.TryGetValue(SRCmac.ToString().ToUpper(), out index))
            {
                return(index);
            }

            ///search by dest mac
            for (int i = 0; i < 5; i++)
            {
                DSTmac.Append(srcMAc[i].ToString("X2"));
                DSTmac.Append(":");
            }

            DSTmac.Append(srcMAc[5].ToString("X2"));

            if (DSTmac.ToString().CompareTo(DSTmac.ToString().ToUpper()) != 0)
            {
                System.Diagnostics.Debug.WriteLine(DSTmac.ToString() + "<==>" + DSTmac.ToString().ToUpper());
            }


            if (_labelIndex.TryGetValue(DSTmac.ToString().ToUpper(), out index))
            {
                return(index);
            }

            else
            {
                return(0);
            }
        }
Ejemplo n.º 7
0
 public void Dispose()
 {
     this._conn = null;
     this._pktList.Clear();
     this._pktList = null;
 }