void getVals() { if (currTimeIdx >= timeSlices.Length - 2 || currTimeIdx < 0) { return; } for (int i = 0; i < subnetObjects.Length; i++) { nextNfIpsSeen[i] = new Dictionary <long, ipDataStruct>(); nextBbIpsSeen[i] = new Dictionary <long, bbDataStruct>(); nextIPSIpsSeen[i] = new Dictionary <long, ipsDataStruct>(); } outOfNetIpsSeen.Clear(); if (dataReader != null) { dataReader.Close(); dataReader = null; } if (dbcmd != null) { dbcmd.Dispose(); dbcmd = null; } string sql = ""; string tableName = "networkflow"; if (numMinutesPerSlice % 60 == 0) { tableName = "nfipcount_60"; } else if (numMinutesPerSlice % 30 == 0) { tableName = "nfipcount_30"; } else if (numMinutesPerSlice % 10 == 0) { tableName = "nfipcount_10"; } else if (numMinutesPerSlice % 5 == 0) { tableName = "nfipcount_5"; } else { tableName = "nfipcount_1"; } sql = "SELECT ipAddress, ipNum, numTimesSeen from " + tableName + " WHERE TimeSeconds>=" + timeSlices[currTimeIdx] + " AND TimeSeconds<" + timeSlices[currTimeIdx + 1] + ";" + "SELECT receivedfrom, recIpNum, statusNum from bigbrother WHERE currenttime>= " + timeSlices[currTimeIdx] + " AND currenttime< " + timeSlices[currTimeIdx + 1] + "; " + "SELECT SrcIp, srcIpNum, destIp, dstIpNum, priorityNum from ipsdata WHERE dateTimeNum>= " + timeSlices[currTimeIdx] + " AND dateTimeNum< " + timeSlices[currTimeIdx + 1] + "; "; dbcmd = dbconn.CreateCommand(); dbcmd.CommandText = sql; queryStartTime = DateTime.Now.TimeOfDay; dataReader = dbcmd.ExecuteReader(); queryActive = true; hasResultSets = true; currDbDataType = dbDataType.NETWORK_FLOW; }
// Update is called once per frame void Update() { if ((Input.GetKeyDown(KeyCode.Space) || inAnimation || currTimeIdx < 0) && !queryActive) { currTimeIdx++; currTimeIdx = Math.Max(0, Math.Min(timeSlices.Length - 2, currTimeIdx)); timelineScript.updateSliderPosition((float)currTimeIdx / (float)timeSlices.Length); getVals(); UpdateActiveTimeRange(); } if (Input.GetKeyDown(KeyCode.C)) { for (int i = 0; i < 3; i++) { Debug.Log("Subnet " + (i + 1) + ": " + currNfIpsSeen[i].Count); } } if (queryActive) { long ipNum; string ipAddress = ""; int numTimesSeen; int statusVal; long dstIpNum; string dstIpAddress; int priorityVal; int idx; // int numLoaded = 0; double currTime = DateTime.Now.TimeOfDay.TotalMilliseconds; double maxTime = currTime + iterTimeOffset; ipDataStruct tmpNfValue = new ipDataStruct(); bbDataStruct tmpBbValue = new bbDataStruct(); ipsDataStruct tmpIPSValue = new ipsDataStruct(); bool foundInSubnet = false; while (currTime < maxTime && hasResultSets) { if (currDbDataType == dbDataType.NETWORK_FLOW) { while (dataReader.Read()) { try { ipAddress = dataReader.GetString(0); ipNum = dataReader.GetInt64(1); numTimesSeen = dataReader.GetInt32(2); foundInSubnet = false; for (idx = 0; idx < 3; idx++) { if (ipNum <= maxSubnetIpNum[idx] && ipNum >= minSubnetIpNum[idx]) { //nextIpsSeen[idx]. if (!nextNfIpsSeen[idx].TryGetValue(ipNum, out tmpNfValue)) { tmpNfValue = new ipDataStruct(); tmpNfValue.ipAddress = ipAddress; tmpNfValue.numTimesSeen = numTimesSeen; nextNfIpsSeen[idx].Add(ipNum, tmpNfValue); } else { tmpNfValue.numTimesSeen += numTimesSeen; } foundInSubnet = true; break; } } if (!foundInSubnet) { tmpNfValue = new ipDataStruct(); tmpNfValue.ipAddress = ipAddress; outOfNetIpsSeen.Add(ipNum, tmpNfValue); } } catch (System.InvalidCastException e) { Debug.Log(e); } currTime = DateTime.Now.TimeOfDay.TotalMilliseconds; if (currTime >= maxTime) { break; } } } else if (currDbDataType == dbDataType.BIG_BROTHER) { while (dataReader.Read()) { try { ipAddress = dataReader.GetString(0); if (ipAddress == null || ipAddress.Length < 7) { continue; } ipNum = dataReader.GetInt64(1); statusVal = dataReader.GetInt32(2); for (idx = 0; idx < 3; idx++) { if (ipNum <= maxSubnetIpNum[idx] && ipNum >= minSubnetIpNum[idx]) { //nextIpsSeen[idx]. if (!nextBbIpsSeen[idx].TryGetValue(ipNum, out tmpBbValue)) { tmpBbValue = new bbDataStruct(); tmpBbValue.ipAddress = ipAddress; tmpBbValue.status = statusVal; nextBbIpsSeen[idx].Add(ipNum, tmpBbValue); } else { if (statusVal > tmpBbValue.status) { tmpBbValue.status = statusVal; } } break; } } } catch (System.InvalidCastException e) { Debug.Log(e.Message + " for ip/time: " + ipAddress + "/" + timeSlices[currTimeIdx]); } currTime = DateTime.Now.TimeOfDay.TotalMilliseconds; if (currTime >= maxTime) { break; } } } else if (currDbDataType == dbDataType.INTRUSION_PROTECTION) { while (dataReader.Read()) { try { ipAddress = dataReader.GetString(0); ipNum = dataReader.GetInt64(1); dstIpAddress = dataReader.GetString(2); dstIpNum = dataReader.GetInt64(3); priorityVal = dataReader.GetInt32(4); for (idx = 0; idx < 3; idx++) { if (ipNum <= maxSubnetIpNum[idx] && ipNum >= minSubnetIpNum[idx]) { if (!nextIPSIpsSeen[idx].TryGetValue(ipNum, out tmpIPSValue)) { tmpIPSValue = new ipsDataStruct(); tmpIPSValue.ipAddress = ipAddress; tmpIPSValue.priority = priorityVal; nextIPSIpsSeen[idx].Add(ipNum, tmpIPSValue); } else { if (priorityVal > tmpIPSValue.priority) { tmpIPSValue.priority = priorityVal; } } break; } } for (idx = 0; idx < 3; idx++) { if (dstIpNum <= maxSubnetIpNum[idx] && dstIpNum >= minSubnetIpNum[idx]) { if (!nextIPSIpsSeen[idx].TryGetValue(dstIpNum, out tmpIPSValue)) { tmpIPSValue = new ipsDataStruct(); tmpIPSValue.ipAddress = dstIpAddress; tmpIPSValue.priority = priorityVal; nextIPSIpsSeen[idx].Add(dstIpNum, tmpIPSValue); } else { if (priorityVal > tmpIPSValue.priority) { tmpIPSValue.priority = priorityVal; } } break; } } } catch (System.InvalidCastException e) { Debug.Log(e.Message); } currTime = DateTime.Now.TimeOfDay.TotalMilliseconds; if (currTime >= maxTime) { break; } } } if (currTime >= maxTime) { break; } else if (dataReader.NextResult()) { if (currDbDataType == dbDataType.NETWORK_FLOW) { currDbDataType = dbDataType.BIG_BROTHER; } else if (currDbDataType == dbDataType.BIG_BROTHER) { currDbDataType = dbDataType.INTRUSION_PROTECTION; } continue; } else { hasResultSets = false; } } if (!hasResultSets) { queryActive = false; queryEndTime = DateTime.Now.TimeOfDay; for (int i = 0; i < subnetObjects.Length; i++) { currNfIpsSeen[i].Clear(); currBbIpsSeen[i].Clear(); currIPSIpsSeen[i].Clear(); currNfIpsSeen[i] = nextNfIpsSeen[i]; currBbIpsSeen[i] = nextBbIpsSeen[i]; currIPSIpsSeen[i] = nextIPSIpsSeen[i]; subnetMappings[i].activateNodes(nextNfIpsSeen[i]); subnetMappings[i].activateBBNodes(nextBbIpsSeen[i]); subnetMappings[i].activateIPSNodes(nextIPSIpsSeen[i]); } } } }