Exemplo n.º 1
0
    public void updateActionAreaForSelectedTraffic()
    {
        foreach (GameObject gObj in acticeNodeObjects)
        {
            GameObject.Destroy(gObj);
        }

        acticeNodeObjects.Clear();

        for (int i = 0; i < 4; i++)
        {
            nodeDetailsLists[i].Clear();
        }

        int totalCount = currentActiveNodes.Count + currActiveExteriorNodes.Count;

        if (totalCount < 2)
        {
            return;
        }

        string[] uniqueIpAddresses = new string[totalCount];

        int idx = 0;

        foreach (KeyValuePair <string, NodeStatus> kv in currentActiveNodes)
        {
            uniqueIpAddresses[idx++] = kv.Key;
        }

        foreach (KeyValuePair <long, string> kv in currActiveExteriorNodes)
        {
            uniqueIpAddresses[idx++] = kv.Value;
        }

        List <ipTimelineDetails> detTraffList = new List <ipTimelineDetails>();

        for (int i = 0; i < uniqueIpAddresses.Length; i++)
        {
            for (int j = i + 1; j < uniqueIpAddresses.Length; j++)
            {
                List <ipTimelineDetails> tmpList = dbConnClass.getDetailedNFTrafficBetweenNodes(uniqueIpAddresses[i], uniqueIpAddresses[j]);
                detTraffList.AddRange(tmpList);
            }
        }


        // iterate and get

        Dictionary <long, double> maxTimePerIp = new Dictionary <long, double>();

        double minTime = float.MaxValue;
        double maxTime = float.MinValue;

        double tTime;

        foreach (ipTimelineDetails details in detTraffList)
        {
            if (details.time < minTime)
            {
                minTime = details.time;
            }
            if (details.time > maxTime)
            {
                maxTime = details.time;
            }

            nodeDetailsLists[0].Add(details);

            if (maxTimePerIp.TryGetValue(details.srcIpNum, out tTime))
            {
                if (details.time > tTime)
                {
                    maxTimePerIp[details.srcIpNum] = details.time;
                }
            }
            else
            {
                maxTimePerIp.Add(details.srcIpNum, details.time);
            }

            if (maxTimePerIp.TryGetValue(details.dstIpNum, out tTime))
            {
                if (details.time > tTime)
                {
                    maxTimePerIp[details.dstIpNum] = details.time;
                }
            }
            else
            {
                maxTimePerIp.Add(details.dstIpNum, details.time);
            }
        }


        double timeDiff       = maxTime - minTime;
        float  minHeight      = 0.1f;
        float  maxHeight      = 1.0f;
        float  heightDiff     = maxHeight - minHeight;
        double heighTimeRatio = 0.0;

        if (Math.Abs(timeDiff) < 0.000001)
        {
            heighTimeRatio = 1.0;
            minHeight      = 0.5f;
        }
        else
        {
            heighTimeRatio = heightDiff / timeDiff;
        }

        long[]  tmpIpNums = new long[2];
        Vector3 offset    = Vector3.zero;
        Vector3 pos;

        List <timePosition> timePosList = new List <timePosition>();

        foreach (ipTimelineDetails det in nodeDetailsLists[0])
        {
            tmpIpNums[0] = det.srcIpNum;
            tmpIpNums[1] = det.dstIpNum;
            offset.y     = (float)((det.time - minTime) * heighTimeRatio + minHeight);

            timePosition tmpTp = new timePosition();
            tmpTp.time    = det.time;
            tmpTp.srcPort = det.firstSeenSrcPort;
            tmpTp.dstPort = det.firstSeenDstPort;

            for (int i = 0; i < 2; i++)
            {
                if (!subnetPointMaps.TryGetValue(tmpIpNums[i], out pos))
                {
                    if (numOuterPointsUnassigned < 1)
                    {
                        Debug.LogError("Reached maximum number of internet node points in active area");
                        continue;
                    }
                    int tmpIdx = (int)(UnityEngine.Random.value * (numOuterPointsUnassigned - 1));
                    pos = outerPlotPoints[tmpIdx];

                    subnetPointMaps.Add(tmpIpNums[i], outerPlotPoints[tmpIdx]);
                    outerPlotPoints[tmpIdx] = outerPlotPoints[numOuterPointsUnassigned - 1];
                    numOuterPointsUnassigned--;
                }

                GameObject ptObj = (GameObject)Instantiate(ptPrefab);
                ptObj.transform.SetParent(gameObject.transform);
                ptObj.transform.localPosition  = pos;
                ptObj.transform.localPosition += offset;

                if (i == 0)
                {
                    tmpTp.srcPosition = pos + offset;
                }
                else
                {
                    tmpTp.dstPosition = pos + offset;
                }

                acticeNodeObjects.Add(ptObj);

                timePosList.Add(tmpTp);
            }
        }


        Vector3[] tmpPts = new Vector3[2];

        foreach (KeyValuePair <long, double> kv in maxTimePerIp)
        {
            offset.y = (float)((kv.Value - minTime) * heighTimeRatio + minHeight);

            if (!subnetPointMaps.TryGetValue(kv.Key, out pos))
            {
                Debug.LogError("Cannot find the value for " + kv.Key);
                continue;
            }

            GameObject lineObj = (GameObject)Instantiate(linePrefab);
            lineObj.transform.SetParent(gameObject.transform);

            tmpPts[0] = gameObject.transform.TransformPoint(pos);
            tmpPts[1] = gameObject.transform.TransformPoint(pos + offset);

            LineRenderer lineRend = lineObj.GetComponent <LineRenderer>();
            lineRend.useWorldSpace = false;
            lineRend.SetPositions(tmpPts);
            lineRend.startWidth = 0.008f;
            lineRend.endWidth   = 0.008f;

            acticeNodeObjects.Add(lineObj);
        }


        if (drawTimeConnections)
        {
            Vector3[] tmpLinePts = new Vector3[2];

            foreach (timePosition tp in timePosList)
            {
                tmpLinePts[0] = gameObject.transform.TransformPoint(tp.srcPosition);
                tmpLinePts[1] = gameObject.transform.TransformPoint(tp.dstPosition);

                GameObject lineObj = (GameObject)Instantiate(linePrefab);
                lineObj.transform.SetParent(gameObject.transform);

                LineRenderer lineRend = lineObj.GetComponent <LineRenderer>();
                lineRend.useWorldSpace = false;
                lineRend.SetPositions(tmpLinePts);
                lineRend.startColor = getPortColor(tp.srcPort);
                lineRend.endColor   = getPortColor(tp.dstPort);

                acticeNodeObjects.Add(lineObj);
            }
        }
    }
Exemplo n.º 2
0
 get => GUIToSeconds(timePosition - _visualsSettings.timelineOffset);
Exemplo n.º 3
0
    public void updateActiveNodeForAllTraffic()
    {
        //List<GameObject> acticeNodeObjects = new List<GameObject>();
        foreach (GameObject gObj in acticeNodeObjects)
        {
            GameObject.Destroy(gObj);
        }

        acticeNodeObjects.Clear();

        for (int i = 0; i < 4; i++)
        {
            nodeDetailsLists[i].Clear();
        }
        NodeStatus ns;
        long       currIpNum = 0;
        long       tgtIpNum;
        int        tgtIdx;
        int        numTotalPoints = 0;

        if (currentActiveNodes.TryGetValue(activeNodeIpAddress, out ns))
        {
            List <ipTimelineDetails> detTraffList = dbConnClass.getDetailedNFTrafficForNode(ns.currIpInfo.ipAddress);
            numTotalPoints = detTraffList.Count;
            currIpNum      = TestSQLiteConn.getIpNumFromString(ns.currIpInfo.ipAddress);

            foreach (ipTimelineDetails details in detTraffList)
            {
                if (details.srcIpNum == currIpNum)
                {
                    tgtIpNum = details.dstIpNum;
                }
                else
                {
                    tgtIpNum = details.srcIpNum;
                }

                tgtIdx = 3;

                for (int i = 0; i < 3; i++)
                {
                    if (tgtIpNum >= minSubnetIpNum[i] && tgtIpNum <= maxSubnetIpNum[i])
                    {
                        tgtIdx = i;
                        Debug.Log(details.srcIp + " connected with " + details.dstIp);
                        break;
                    }
                }

                nodeDetailsLists[tgtIdx].Add(details);
            }
        }



        double minTime = float.MaxValue;
        double maxTime = float.MinValue;

        ipTimelineDetails tmpDetails;
        bool isSrc;

        Dictionary <long, double> maxTimePerIp = new Dictionary <long, double>();
        double tTime;

        for (int i = 0; i < 4; i++)
        {
            Dictionary <long, ipTimelineDetails> uniqueNodes = new Dictionary <long, ipTimelineDetails>();

            foreach (ipTimelineDetails details in nodeDetailsLists[i])
            {
                if (details.time < minTime)
                {
                    minTime = details.time;
                }
                if (details.time > maxTime)
                {
                    maxTime = details.time;
                }

                if (details.srcIpNum == currIpNum)
                {
                    tgtIpNum = details.dstIpNum; isSrc = true;
                }
                else
                {
                    tgtIpNum = details.srcIpNum; isSrc = false;
                }

                if (!uniqueNodes.TryGetValue(tgtIpNum, out tmpDetails))
                {
                    uniqueNodes.Add(tgtIpNum, details);
                    uniqueNodes.TryGetValue(tgtIpNum, out tmpDetails);
                    tmpDetails.isSrc = isSrc;
                }



                if (maxTimePerIp.TryGetValue(details.srcIpNum, out tTime))
                {
                    if (details.time > tTime)
                    {
                        maxTimePerIp[details.srcIpNum] = details.time;
                    }
                }
                else
                {
                    maxTimePerIp.Add(details.srcIpNum, details.time);
                }

                if (maxTimePerIp.TryGetValue(details.dstIpNum, out tTime))
                {
                    if (details.time > tTime)
                    {
                        maxTimePerIp[details.dstIpNum] = details.time;
                    }
                }
                else
                {
                    maxTimePerIp.Add(details.dstIpNum, details.time);
                }
            }
        }

        double  timeDiff       = maxTime - minTime;
        float   minHeight      = 0.1f;
        float   maxHeight      = 1.0f;
        float   heightDiff     = maxHeight - minHeight;
        double  heighTimeRatio = heightDiff / timeDiff;
        Vector3 pos;

        Vector3[] tmpPts = new Vector3[2];
        Vector3   offset = Vector3.zero;

        timePosition[] tpArray = new timePosition[numTotalPoints];
        int            tpIdx   = 0;

        for (int i = 0; i < 4; i++)
        {
            foreach (ipTimelineDetails det in nodeDetailsLists[i])
            {
                tgtIpNum = det.isSrc ? det.srcIpNum : det.dstIpNum;
                offset.y = (float)((det.time - minTime) * heighTimeRatio + minHeight);
                if (!subnetPointMaps.TryGetValue(tgtIpNum, out pos))
                {
                    if (numOuterPointsUnassigned < 1)
                    {
                        Debug.LogError("Reached maximum number of internet node points in active area");
                        continue;
                    }
                    int tmpIdx = (int)(UnityEngine.Random.value * (numOuterPointsUnassigned - 1));
                    pos = outerPlotPoints[tmpIdx];

                    subnetPointMaps.Add(tgtIpNum, outerPlotPoints[tmpIdx]);
                    outerPlotPoints[tmpIdx] = outerPlotPoints[numOuterPointsUnassigned - 1];
                    numOuterPointsUnassigned--;
                }

                tpArray[tpIdx]         = new timePosition(det.time, gameObject.transform.TransformPoint(pos + offset));
                tpArray[tpIdx].srcPort = det.firstSeenSrcPort;
                tpArray[tpIdx].dstPort = det.firstSeenDstPort;
                tpIdx++;

                GameObject ptObj = (GameObject)Instantiate(ptPrefab);
                ptObj.transform.SetParent(gameObject.transform);
                ptObj.transform.localPosition = pos + offset;

                acticeNodeObjects.Add(ptObj);
            }
        }



        foreach (KeyValuePair <long, double> kv in maxTimePerIp)
        {
            offset.y = (float)((kv.Value - minTime) * heighTimeRatio + minHeight);

            if (!subnetPointMaps.TryGetValue(kv.Key, out pos))
            {
                Debug.LogError("Cannot find the value for " + kv.Key);
                continue;
            }

            GameObject lineObj = (GameObject)Instantiate(linePrefab);
            lineObj.transform.SetParent(gameObject.transform);

            tmpPts[0] = gameObject.transform.TransformPoint(pos);
            tmpPts[1] = gameObject.transform.TransformPoint(pos + offset);

            LineRenderer lineRend = lineObj.GetComponent <LineRenderer>();
            lineRend.useWorldSpace = false;
            lineRend.SetPositions(tmpPts);
            lineRend.startWidth = 0.1f;

            acticeNodeObjects.Add(lineObj);
        }

        if (drawTimeConnections)
        {
            Array.Sort <timePosition>(tpArray);
            Vector3[] tmpLinePts = new Vector3[tpArray.Length];

            for (int i = 0; i < tpArray.Length; i++)
            {
                tmpLinePts[i] = tpArray[i].srcPosition;
            }

            GameObject lineObj = (GameObject)Instantiate(linePrefab);
            lineObj.transform.SetParent(gameObject.transform);

            LineRenderer lineRend = lineObj.GetComponent <LineRenderer>();
            lineRend.useWorldSpace = false;
            lineRend.positionCount = tmpLinePts.Length;
            lineRend.SetPositions(tmpLinePts);
            lineRend.startColor = Color.white;
            lineRend.endColor   = Color.black;

            acticeNodeObjects.Add(lineObj);
        }
    }