Exemple #1
0
 /// <summary>
 /// Constructs a ConnectionPair object
 /// </summary>
 /// <param name="srcIp"></param>
 /// <param name="srcPort"></param>
 /// <param name="destIp"></param>
 /// <param name="destPort"></param>
 public ConnectionPair2(IPAddress srcIp, int srcPort, IPAddress destIp, int destPort, Packet2.Protocol proto)
 {
     this.SrcEnd   = new IPEndPoint(srcIp, srcPort);
     this.DestEnd  = new IPEndPoint(destIp, destPort);
     this.Protocol = proto;
 }
Exemple #2
0
 public ConnectionPair2(IPEndPoint srcEnd, IPEndPoint destEnd, Packet2.Protocol proto)
 {
     this.SrcEnd   = srcEnd;
     this.DestEnd  = destEnd;
     this.Protocol = proto;
 }
        /// <summary>
        /// Generate flow features for the flow.The current flow is in a TimeWindow already.
        /// </summary>
        /// <returns></returns>
        public FlowFeature GenerateFeatuesInTimeWindow()
        {
            //

            //   System.Console.WriteLine(" inside GenerateFeatuesInTimeWindow ");
            if (_pktList.Count < 3)
            {
                return(null);
            }


            //collecting same length packet
            SortedList <uint, int> samePktLength = new SortedList <uint, int>();
            int    pktEx = 0;
            long   totalPayloadLength       = 0;
            long   totalTCPUDPPayloadLength = 0;
            int    pktExTCPUDP   = 0;
            int    noNullPacket  = 0;
            int    noSmallPacket = 0;
            double timeWindow    = new TimeSpan(0, 0, Properties.Settings.Default.TimeWindow).TotalSeconds;


            FlowFeature flowFeature = new FlowFeature();

            flowFeature.SrcIP   = this._conn.SrcEnd.Address.GetAddressBytes();
            flowFeature.SrcPort = this._conn.SrcEnd.Port;

            flowFeature.DestIP   = this._conn.DestEnd.Address.GetAddressBytes();
            flowFeature.DestPort = this._conn.DestEnd.Port;

            //getting the MAC address of the first packet for the flow
            //we assume that the MAC address is consistant per flow
            flowFeature.SrcMAC  = this._pktList[0].SrcMAC;
            flowFeature.DestMAC = this._pktList[0].DestMAC;

            flowFeature.Protocol  = (int)(this.Protocol);
            flowFeature.Reconnect = this.reconnect;

            flowFeature.FPS = (double)_pktList[0].PayloadLength; /// should be revised
            // flowFeature.tcpFlag = 0;

            flowFeature.DetectionTimeStamp = _pktList[0].ReceivingTime;



            DateTime[] interArrivalTime   = new DateTime[_pktList.Count];
            uint       noIncommingPackets = 0;
            uint       noOutgoingPackets  = 0;

            for (int i = 0; i < _pktList.Count; i++)
            {
                totalPayloadLength += _pktList[i].PayloadLength;
                pktEx++;

                interArrivalTime[i] = _pktList[i].ReceivingTime;

                if (_pktList[i].SrcEnd.Address == _conn.SrcEnd.Address)
                {
                    noIncommingPackets++;
                }
                else
                {
                    noOutgoingPackets++;
                }

                Packet2.Protocol temp = new Packet2.Protocol();
                if (temp != Packet2.Protocol.Mixed) //to capture TCP/UDP flows
                {                                   //either TCP/UDP
                    totalTCPUDPPayloadLength += _pktList[i].PayloadLength;
                    pktExTCPUDP++;
                }

                if (_pktList[i].PayloadLength == 0)
                {
                    noNullPacket += 1;
                }

                if (63 < _pktList[i].PayloadLength && _pktList[i].PayloadLength < 399) // counting th enumber of small packets
                {
                    noSmallPacket += 1;
                }

                if (samePktLength.ContainsKey(_pktList[i].PayloadLength))
                {
                    samePktLength[_pktList[i].PayloadLength] += 1;
                }
                else
                {
                    samePktLength.Add(_pktList[i].PayloadLength, 1);
                }
            }

            ////

            //////


            // flowFeature.Type = Flow2.GetLabelIndex(this._conn.SrcEnd.Address.GetAddressBytes());
            flowFeature.Type = Flow2.GetLabelIndex_ME(this._conn, flowFeature.SrcMAC, flowFeature.DestMAC);

//            if (flowFeature.Type == 3 || flowFeature.Type == 4 || flowFeature.Type == 5)
//                System.Diagnostics.Debug.WriteLine(flowFeature.ToString());
            flowFeature.PX  = (double)pktEx;
            flowFeature.APL = (double)(totalPayloadLength) / (double)pktEx;
            // flowFeature.PX = (double)pktEx;
            flowFeature.PV  = CalVariance(samePktLength, flowFeature.APL);
            flowFeature.DPL = (double)(samePktLength.Count) / pktEx;

            flowFeature.AB  = (double)totalTCPUDPPayloadLength / (double)pktExTCPUDP;
            flowFeature.TBT = totalPayloadLength;

            flowFeature.BS = (double)totalPayloadLength / (double)timeWindow;
            flowFeature.PS = (double)pktEx / (double)timeWindow;

            flowFeature.NNP = noNullPacket;
            flowFeature.NSP = noSmallPacket;
            flowFeature.PSP = ((double)noSmallPacket / (double)pktEx) * 100;

            flowFeature.Duration = (this.StopTime - this.StartTime).TotalSeconds;

            flowFeature.AIT = AverageIntervalTime(interArrivalTime);

            if (this.NoBackwardPackets != 0)
            {
                flowFeature.IOPR = (double)this.NbOfPkt / (double)this.NoBackwardPackets;
            }
            else
            {
                flowFeature.IOPR = -1;
            }
            //   flowFeature.SDNP = Variance(samePktLength, flowFeature.APL);

            flowFeature.PPS = pktEx < 2 ?
                              0.0
                    : (double)(pktEx) * 1000.0d
                              / (_pktList.Last().ReceivingTime - _pktList.First().ReceivingTime).TotalSeconds;

            if (Double.IsInfinity(flowFeature.PPS))
            {
                flowFeature.PPS = 0.0d;
            }


            // we do reseat all the calculation to be used by next flow because the function calling this is in a loop
            samePktLength.Clear();
            samePktLength = null;
            // _pktList.Clear();

            return(flowFeature);
        }