static double ConditionHappened(HashSet<MODPhenomemon> observedPhenomemons, MODPhenomemonType type, int node, double starttime, double endtime, MODPhenomemon p1, List<MODPhenomemon> list, ComparePhenomemon comparer) { double likehood = global.SmallValue; foreach (MODPhenomemon p in observedPhenomemons) { if (p.nodeId == node && p.type == type && p.start >= starttime && p.end <= endtime && comparer(p1, p)) { list.Add(p); likehood = Math.Max(p.likehood, likehood); } } return likehood; }
static double ConditionHappened(HashSet<MODPhenomemon> observedPhenomemons, MODPhenomemonType type, int node, double starttime, double endtime, MODPhenomemon p1, ComparePhenomemon comparer) { foreach (MODPhenomemon p in observedPhenomemons) { if (p.nodeId == node && p.type == type && p.start >= starttime && p.end <= endtime && comparer(p1, p)) { return p.likehood; } } return global.SmallValue; }
public static MODEventTrustResult DeduceDropPacketMaliciouslyByPacket(int selfId, HashSet<MODPhenomemon> observedPhenomemons, double currentTime, MODPhenomemon p) { double a1, a2, a3, a4, a5, a6, a7, a19, a27; if (Global.getInstance().debug) Console.WriteLine("READER{0} Check DeduceDropPacketMaliciously", selfId); MODGlobal global = (MODGlobal)Global.getInstance(); MODReader selfNode = (MODReader)global.readers[selfId]; int node = p.nodeId; a1 = p.likehood; //likehood of receiving a packet at time p.start a2 = ConditionHappened(observedPhenomemons, MODPhenomemonType.SEND_PACKET, node, p.start, p.start + global.sendPacketTimeout, p.pkg); a3 = ConditionHappened(observedPhenomemons, MODPhenomemonType.NOT_SEND_PACKET, node, p.start, Scheduler.getInstance().currentTime, p.pkg); a4 = ConditionHappened(observedPhenomemons, MODPhenomemonType.BANDWIDTH_BUSY, selfId, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime); //如果对带宽占用没有知识,则正反都设置为未知。 a5 = 0.9 - a4; a6 = Utility.Average(new double[]{ ConditionHappened(observedPhenomemons, MODPhenomemonType.MOVE_FAST, node, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime), ConditionHappened(observedPhenomemons, MODPhenomemonType.MOVE_FAST, p.pkg.Prev, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime), ConditionHappened(observedPhenomemons, MODPhenomemonType.MOVE_FAST, selfId, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime) }); a7 = 0.9 - a6; //一个是观测节点和被观测节点的距离,看是否后者发送的消息能否被前者收到 //另一个是,看源节点发送的数据是否能被被观测节点收到 //a19 = Math.Max(FarDistanceLikehood(selfId, node, p.pkg.DstType==NodeType.OBJECT), // FarDistanceLikehood(selfId, p.pkg.Prev, p.pkg.PrevType == NodeType.OBJECT)); if (p.pkg.DstType == NodeType.OBJECT && selfNode.NearbyObjectCache.ContainsKey(p.pkg.Dst)) a19 = FarDistanceLikehood(selfId, node, true); else a19 = FarDistanceLikehood(selfId, node, false); a27 = 0.9 - a19; //A1 AND A2 AND A7 AND A11 -> B1 double b0 = DSClass.AND(a1, a2) * CF[(int)MODEventType.NotDropPacket]; //A1 AND A2 AND A7 AND A11 -> B1 double b1 = DSClass.AND(DSClass.AND(a1, a3), DSClass.OR(DSClass.OR(a4, a6), a19)) * CF[(int)MODEventType.NotDropPacketButNotReceivePacket]; //A1 AND A2 AND A7 AND A11 -> B1 double b2 = DSClass.AND(DSClass.AND(a1, a3), a4) * CF[(int)MODEventType.DropPacketDueToBandwith]; //A1 AND A2 AND A7 AND A11 -> B1 double b3 = DSClass.AND(DSClass.AND(DSClass.AND(DSClass.AND(a1, a3), a5), a7), a27) * CF[(int)MODEventType.DropPacketMaliciously]; /* if (global.debug) { Console.WriteLine("{0}->{1}:{2}", selfId, node, p.pkg.SrcSenderSeq); Console.WriteLine("a1:" + a1); Console.WriteLine("a2:" + a2); Console.WriteLine("a3:" + a3); Console.WriteLine("a4:" + a4); Console.WriteLine("a5:" + a5); Console.WriteLine("a6:" + a6); Console.WriteLine("a7:" + a7); Console.WriteLine("a19:" + a19); Console.WriteLine("a27:" + a27); Console.WriteLine("b0:" + b0); Console.WriteLine("b1:" + b1); Console.WriteLine("b2:" + b2); Console.WriteLine("b3:" + b3); }*/ DSClass ds = new DSClass(pow(MODDropPacketEventType.END)); ds.SetM(pow(MODDropPacketEventType.NotDropPacket), b0); ds.SetM(pow(MODDropPacketEventType.NotDropPacketButNotReceivePacket), b1); ds.SetM(pow(MODDropPacketEventType.DropPacketDueToBandwith), b2); ds.SetM(pow(MODDropPacketEventType.DropPacketMaliciously), b3); ds.SetM(pow(MODDropPacketEventType.END) - 1, 1 - b0 - b1 - b2 - b3); ds.Cal(); //ds.Output(); string pkgIdent = GetPacketIdent(p.pkg); MODEventTrustResult r = new MODEventTrustResult(node, global.readers[selfId], pkgIdent, MODEventCategoryType.DropPacket, ds); //此处,我们先过滤一些正常事件,否则事件太多了 if (ds.b[pow(MODEventType.NotDropPacket) + pow(MODEventType.NotDropPacketButNotReceivePacket)] < global.NormalBelief && ds.p[pow(MODEventType.NotDropPacket) + pow(MODEventType.NotDropPacketButNotReceivePacket)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值 { Console.WriteLine("{0:F4} reader{1} think reader{2} is not normal.", currentTime, selfId, p.nodeId); r.supportDroppingMalicious = 1; /* if (global.debug) r.ds.Output(); * */ } else r.supportDroppingMalicious = -1; return r; }
public static double SimiliarCommand(MODPhenomemon p, List<MODPhenomemon> list) { double likehood = 0; foreach (MODPhenomemon p1 in list) { likehood = Math.Max(likehood, 1 - global.SmallValue - Math.Abs(p1.pkg.SrcSenderSeq - p.pkg.SrcSenderSeq) / 100); } return likehood; }
public static bool ComparePhenomemonByExactTag(MODPhenomemon p1, MODPhenomemon p2) { if (p1.pkg == null || p1.pkg.Type != PacketType.COMMAND) return false; //使用PacketSeq判断两个数据包是否为同一个 return (p1.pkg.Command.tag == p2.pkg.Dst && p1.pkg.SrcSenderSeq == p2.pkg.SrcSenderSeq); }
public static bool ComparePhenomemonBySimiliarTag(MODPhenomemon p1, MODPhenomemon p2) { if (p1.pkg == null || p1.pkg.Type != PacketType.COMMAND) return false; //使用PacketSeq判断两个数据包是否为同一个 return (p1.pkg.Command.tag == p2.pkg.Dst); }
//将接收到的数据包添加到观察到的现象中 public void AddReceivePacketPhenomemon(Packet pkg) { MODPhenomemon p; this.totalReceivedPackets++; //忽略广播包(从实际来看,发送广播包的一般是节点本身的行为,不需要考虑其对数据包的恶意操作) if (pkg.Next == BroadcastNode.Node.Id) return; //如果不是我需要监控的节点,返回(在真实丢包的场景中,需要监控所有节点,否则只需要监控特定的节点即可) if (!global.monitoredNodes.Contains(pkg.Prev) && !global.monitoredNodes.Contains(pkg.Next) && global.DropData == false) return; if (!global.monitoredNodes.Contains(pkg.Next)) global.monitoredNodes.Add(pkg.Next); //记录发送现象 if (pkg.Next != BroadcastNode.Node.Id) { p = new MODPhenomemon(MODPhenomemonType.SEND_PACKET, pkg.Prev, scheduler.currentTime, pkg); p.likehood = global.sendLikehood; this.observedPhenomemons.Add(p); if (global.debug) Console.WriteLine("[Debug] reader{0} add a RECV phenomemon of reader{1}", Id, pkg.Next); } //记录接收现象 if (pkg.Next != pkg.Dst) { p = new MODPhenomemon(MODPhenomemonType.RECV_PACKET, pkg.Next, scheduler.currentTime, pkg); p.likehood = global.recvLikehood; this.observedPhenomemons.Add(p); //Console.WriteLine("[Debug] reader{0} add a SEND phenomemon of reader{1}", id, pkg.Prev); //延迟检查事件 Event.AddEvent(new Event(Scheduler.getInstance().currentTime + global.checkReceivedPacketTimeout, EventType.CHK_RECV_PKT, this, p)); } //数据包到达目的地,忽略 }
//在接收到DATA数据包后,检查是否发生了抛弃数据包的情况 public void CheckReceivedPacket(MODPhenomemon p) { int suspectedNodeId = p.nodeId; List<MODEventTrustResult> results = new List<MODEventTrustResult>(); string pkgIdent = MODEventTrust.GetPacketIdent(p.pkg); MODEventTrustResult realr = null; if (p == null)//没观察到接收数据包,则不确定 { string[] x = pkgIdent.Split(new char[] { '-', '>' }); int prevId = int.Parse(x[0]); Reader suspectedNode = global.readers[suspectedNodeId]; Reader prevNode = global.readers[prevId]; double[] speeds = new double[3]; if (this.Speed != null) speeds[0] = this.Speed[0]; if (suspectedNode.Speed != null) speeds[1] = suspectedNode.Speed[0]; if (prevNode.Speed != null) speeds[2] = prevNode.Speed[0]; bool[] isNeighbors = new bool[2] { this.Neighbors.ContainsKey(prevId), this.Neighbors.ContainsKey(suspectedNodeId) }; realr = MODEventTrust.NotObservedEventTrustResult(suspectedNodeId, this.Id, pkgIdent, MODEventCategoryType.DropPacket, speeds, isNeighbors); } else { realr = MODEventTrust.DeduceDropPacketMaliciouslyByPacket(this.Id, this.observedPhenomemons, scheduler.currentTime, p); } //正常节点或异常节点,如果正常事件,则不报告 if (!this.IsMalicious() && (realr.supportDroppingMalicious <= 0 || global.DropData == false))//normal return; //如果是恶意节点,事件也是恶意的,也不报告 if (this.IsMalicious() && (realr.supportDroppingMalicious > 0 || global.DropData == true))//malicious return; MODEventTrustResult myresult = null; if (global.debug) Console.Write("[Debug] node{0} CheckReceivedPacket of {1} of reader{2}\t", this.Id, MODEventTrust.GetPacketIdent(p.pkg), myresult.nodeId); if (pkgIdent != global.currentPkgIdent) { if (scheduler.currentTime - global.currentPkgIdentUpdate > 4) { global.currentPkgIdentUpdate = scheduler.currentTime; global.currentPkgIdent = pkgIdent; } else return; } if (!this.receivedEventReports.ContainsKey(pkgIdent)) this.receivedEventReports.Add(pkgIdent, new Dictionary<Node, MODEventTrustResult>()); if (this.receivedEventReports[pkgIdent].ContainsKey(this)) { myresult = this.receivedEventReports[pkgIdent][this]; } else { myresult = GetEventTrustResult(pkgIdent, p, results, suspectedNodeId, this.Id, realr); this.receivedEventReports[pkgIdent].Add(this, myresult); } //如果我是恶意节点,我推测和真实事件一致,也不报告 if (this.IsMalicious() && (myresult.supportDroppingMalicious == realr.supportDroppingMalicious))//malicious return; //报告恶意事件 //过一段时间转发事件报告 Console.WriteLine("Reader{0} inits an event report, suspected node is {1}", this.Id, myresult.nodeId); Event.AddEvent(new Event(scheduler.currentTime + 0.05f, EventType.FWD_EVENT_REPORT, this, pkgIdent)); //如果是正常的观测节点,过一段时间检查所有邻居对该事件的报告 if (!this.IsMalicious() && !this.toDeducedEventReports.Contains(pkgIdent)) { Event.AddEvent(new Event(scheduler.currentTime + global.checkPhenomemonTimeout, EventType.DEDUCE_EVENT, this, pkgIdent)); this.toDeducedEventReports.Add(pkgIdent); } }
private MODEventTrustResult GetEventTrustResult(string pkgIdent, MODPhenomemon p, List<MODEventTrustResult> results, int suspectedNodeId, int reportNodeId, MODEventTrustResult realr) { //0为正常行为,1为伪造异常报告,2为伪造正常报告 bool forgeReport = false; MODEventTrustResult result = null; if (!this.IsMalicious()) return realr; if (global.debug) Console.WriteLine("Reader{0} GetEventTrustResult", this.Id); bool isAccept = false; bool isSupportM = false; bool isCompositeReportSupport = false; //如果是恶意节点,则会考察检测节点可能的动作 if (this.IsMalicious()) { if (global.Step1DeduceMethod == DeduceMethod.Native)//原始的话,恶意节点与真实情况相反 { forgeReport = true; string sSupport = ""; if (global.DropData == false) { if (realr.supportDroppingMalicious < 0) sSupport = "supporting"; else sSupport = "nonsupporting"; } else// global.DropData == true { if (realr.supportDroppingMalicious > 0) sSupport = "nonsupporting"; else sSupport = "supporting"; } Console.WriteLine("{0:F4} [{1}] {2}{3} deduces {4} {5}{6} is {7} by {8}. [{9}:{10}]\t[{11}:{12}]\t[{13}:{14}]-${15}$:{16}", scheduler.currentTime, "DEDUCTION1-1", this.type, this.Id, sSupport, NodeType.READER, this.Id, "accept", this.Id, 0, 0, 1, 1, 1, 1, pkgIdent, "None"); } else if (global.Step1DeduceMethod == DeduceMethod.Game || global.Step1DeduceMethod == DeduceMethod.OrgGame || global.Step1DeduceMethod == DeduceMethod.CoOrgGame) { //如果是博弈论,则判断检测节点的观点 //此处仅以其周围邻居为参考,而非报告节点的邻居,这是由于ad-hoc的局限性所致的 Dictionary<Node, MODEventTrustResult> localcachedresults = new Dictionary<Node, MODEventTrustResult>(); foreach (MODEventTrustResult r in results) localcachedresults.Add(Reader.GetReader(r.reportNodeId), r); ReduceReports(localcachedresults); //初始化邻居的结构,且找到最久的邻居 int minNbId = GetLongestNormalNeighbor(); if (minNbId < 0)//没有正常节点 minNbId = GetOneNormalNodeFromReports(localcachedresults); if (minNbId < 0)//还是没有正常节点 forgeReport = true; else { Reader minNbNode = global.readers[minNbId]; MODEventTrustResult mr = null; if (this.IsMalicious() && realr.supportDroppingMalicious <= 0) { //如果事件是正常的,那么伪造恶意事件 mr = MODEventTrust.ForgeMaliciousEventTrustResult(suspectedNodeId, this.Id, pkgIdent, MODEventCategoryType.DropPacket); mr.supportDroppingMalicious = 1; } else if (this.IsMalicious() && realr.supportDroppingMalicious > 0) { //如果事件是恶意的,那么伪造正常事件 mr = MODEventTrust.ForgeNormalEventTrustResult(suspectedNodeId, this.Id, pkgIdent, MODEventCategoryType.DropPacket); mr.supportDroppingMalicious = -1; } else { mr = new MODEventTrustResult(suspectedNodeId, this.Id, pkgIdent, MODEventCategoryType.DropPacket, realr.ds); mr.supportDroppingMalicious = realr.supportDroppingMalicious; } localcachedresults.Add(this, mr); AddNeighborReports(minNbNode, realr, suspectedNodeId, pkgIdent, localcachedresults); Node[] reportNodes = localcachedresults.Keys.ToArray(); if (!this.pNBNormal.ContainsKey(minNbNode)) this.pNBNormal.Add(minNbNode, new Dictionary<Node, double>()); if (!this.NBNodeIteractions.ContainsKey(minNbNode)) this.NBNodeIteractions.Add(minNbNode, new List<IteratorType>()); if (!this.pNBNormal[minNbNode].ContainsKey(this)) this.pNBNormal[minNbNode].Add(this, global.pInitNormal); foreach (int nbId in this.Neighbors.Keys) { MODReader nbNode = (MODReader)global.readers[nbId]; if (!this.pNBNormal[minNbNode].ContainsKey(nbNode)) this.pNBNormal[minNbNode].Add(nbNode, global.pInitNormal); } //有一些节点不是我的邻居,暂且也用nbNode表示吧 foreach (Node nbNode in reportNodes) { if (!this.pNBNormal[minNbNode].ContainsKey(nbNode)) this.pNBNormal[minNbNode].Add(nbNode, global.pInitNormal); } if (!this.NBNodeTrustWeights.ContainsKey(minNbNode)) { this.NBNodeTrustWeights.Add(minNbNode, new Dictionary<Node, double>()); this.NBNodeTrustWeightsLastUpdate.Add(minNbNode, new Dictionary<Node, double>()); this.NBNodeSuspectCount.Add(minNbNode, new Dictionary<Node, List<double>>()); this.NBNodeHistoryMyVariance.Add(minNbNode, new Dictionary<Node, List<double>>()); this.NBNodeHistoryTotalVariance.Add(minNbNode, new Dictionary<Node, List<double>>()); } Dictionary<Node, double> pNormal = new Dictionary<Node, double>(); if (global.Step1DeduceMethod == DeduceMethod.OrgGame || global.Step1DeduceMethod == DeduceMethod.CoOrgGame) { List<DirectTrustEntity>[] orgDirectTrustWeight = new List<DirectTrustEntity>[global.orgNum]; for (int i = 0; i < global.orgNum; i++) { orgDirectTrustWeight[i] = new List<DirectTrustEntity>(); } Dictionary<Node, MODEventTrustResult> suspectedReportNodes = AdjustNodeTrust(this.NBNodeTrustWeights[minNbNode], this.NBNodeTrustWeightsLastUpdate[minNbNode], this.NBNodeSuspectCount[minNbNode], orgDirectTrustWeight, this.NBNodeHistoryMyVariance[minNbNode], this.NBNodeHistoryTotalVariance[minNbNode], localcachedresults, pkgIdent, minNbNode, suspectedNodeId); } //这个邻居节点对该节点邻居的印象 foreach (Node reportNode in reportNodes) { Organization org = global.orgs[((Reader)reportNode).OrgId]; if (this.NBNodeTrustWeights[minNbNode].ContainsKey(org)) pNormal.Add(reportNode, this.pNBNormal[minNbNode][reportNode] * this.NBNodeTrustWeights[minNbNode][org]); else pNormal.Add(reportNode, this.pNBNormal[minNbNode][reportNode]); } //计算报告节点的live时间,可估算在supportM的条件下,normal的概率 if (!this.NBNodeIteractions.ContainsKey(minNbNode)) this.NBNodeIteractions.Add(minNbNode, new List<IteratorType>()); double pDrop = global.pInitDrop; //SetDropBySupport(ref pDropBySupportM, ref pDropByNonsupportM, this.NBNodeIteractions[minNbNode]); if (global.debug) Console.WriteLine("deducing reports:{0}", reportNodes.Length); //然后模拟计算 Deduce2Result d2r = DeduceA2(reportNodes, false, suspectedNodeId, localcachedresults, minNbNode.Id, pDrop, pNormal, this.NBNodeTrustWeights[minNbNode], this.NBNodeTrustWeightsLastUpdate[minNbNode], this.NBNodeIteractions[minNbNode]); isAccept = d2r.IsAccept; isCompositeReportSupport = d2r.IsTotalReportSupport; //此时,真实事件是否正常已知,自己的性质,检测节点的最佳行为已知,但是由于整体报告的性质可能出现变化, //设有共有n个节点,m个正常节点,那么如果少于p-m/2个恶意节点改变自己的报告,则整体报告维持不变,否则整体报告改变。 isSupportM = DeduceA1(realr.supportDroppingMalicious <= 0, isCompositeReportSupport, isAccept); if (realr.supportDroppingMalicious > 0 && !isSupportM) forgeReport = true; else if (realr.supportDroppingMalicious <= 0 && isSupportM) forgeReport = true; else forgeReport = false; } } else { forgeReport = true; } } //恶意节点 if(forgeReport == false) { Console.WriteLine("READER{0} not forge a report", this.Id); return realr; } else if(forgeReport == true) { if (realr.supportDroppingMalicious > 0)//真实事件是恶意的 { Console.WriteLine("READER{0} forge a normal report", this.Id); result = MODEventTrust.ForgeNormalEventTrustResult(suspectedNodeId, this.Id, pkgIdent, MODEventCategoryType.DropPacket); } else//真实事件是正常的 { Console.WriteLine("READER{0} forge a malicious report", this.Id); result = MODEventTrust.ForgeMaliciousEventTrustResult(suspectedNodeId, this.Id, pkgIdent, MODEventCategoryType.DropPacket); } return result; } return null; }
private MODEventTrustResult GetEventTrustResult(string pkgIdent, MODPhenomemon p, List<MODEventTrustResult> results, int suspectedNodeId, int reportNodeId) { MODEventTrustResult realr = null; if (p == null)//没观察到接收数据包,则不确定 { string[] x = pkgIdent.Split(new char[]{'-','>'}); int prevId = int.Parse(x[0]); Reader suspectedNode = global.readers[suspectedNodeId]; Reader prevNode = global.readers[prevId]; double[] speeds = new double[3]; if (this.Speed != null) speeds[0] = this.Speed[0]; if (suspectedNode.Speed != null) speeds[1] = suspectedNode.Speed[0]; if (prevNode.Speed != null) speeds[2] = prevNode.Speed[0]; bool[] isNeighbors = new bool[2]{this.Neighbors.ContainsKey(prevId), this.Neighbors.ContainsKey(suspectedNodeId)}; realr = MODEventTrust.NotObservedEventTrustResult(suspectedNodeId, this.Id, pkgIdent, MODEventCategoryType.DropPacket, speeds, isNeighbors); } else { realr = MODEventTrust.DeduceDropPacketMaliciouslyByPacket(this.Id, this.observedPhenomemons, scheduler.currentTime, p); } return GetEventTrustResult(pkgIdent, p, results, suspectedNodeId, reportNodeId, realr); }
void CheckTimeoutPhenomemons() { double sendTimeout = global.sendPacketTimeout; List<MODPhenomemon> temp1 = new List<MODPhenomemon>(); List<MODPhenomemon> temp2 = new List<MODPhenomemon>(); foreach (MODPhenomemon p in this.observedPhenomemons) { if (p.type == MODPhenomemonType.RECV_PACKET && scheduler.currentTime - p.start > sendTimeout) { MODPhenomemon foundSend = null, foundNotSend = null; foreach (MODPhenomemon p1 in this.observedPhenomemons) { if (p1.pkg == null) continue; //找到该节点对该数据包的操作 if (Packet.IsSamePacket(p1.pkg, p.pkg) && p1.nodeId == p.nodeId) { if (p1.type == MODPhenomemonType.SEND_PACKET) { foundSend = p1; continue; } else if (p1.type == MODPhenomemonType.NOT_SEND_PACKET) { p1.end = scheduler.currentTime; foundNotSend = p1; continue; } else continue; } } if (foundSend != null && foundNotSend != null) { temp2.Add(foundNotSend); } else if (foundSend == null && foundNotSend == null) { MODPhenomemon p2 = new MODPhenomemon(MODPhenomemonType.NOT_SEND_PACKET, p.nodeId, p.start, scheduler.currentTime, p.pkg); p2.likehood = global.checkTimeoutPhenomemonLikehood; temp1.Add(p2); } } } foreach (MODPhenomemon p in temp1) { this.observedPhenomemons.Add(p); } foreach (MODPhenomemon p in temp2) { this.observedPhenomemons.Remove(p); } }
void CheckNodeSpeeds() { foreach (KeyValuePair<int, Neighbor> k in this.Neighbors) { int node = k.Key; Neighbor nb = k.Value; //节点无法测出邻居的距离,但是可以根据信号强弱估计出,为简化,此处直接给出两点距离。 double speed = global.readers[node].GetCurrentSpeed(); if (!this.neighborSpeedPhenomemons.ContainsKey(node)) { MODPhenomemon p = new MODPhenomemon(MODPhenomemonType.MOVE_FAST, node); p.start = 0; this.neighborSpeedPhenomemons.Add(node, p); this.observedPhenomemons.Add(p); } this.neighborSpeedPhenomemons[node].start = this.neighborSpeedPhenomemons[node].end; this.neighborSpeedPhenomemons[node].end = scheduler.currentTime; this.neighborSpeedPhenomemons[node].likehood = Math.Min(speed / global.nodeSpeedThreahold + global.SmallValue, 0.9); } this.neighborSpeedPhenomemons[Id].start = this.neighborSpeedPhenomemons[Id].end; this.neighborSpeedPhenomemons[Id].end = scheduler.currentTime; double s = GetCurrentSpeed(); this.neighborSpeedPhenomemons[Id].likehood = Math.Min(s / global.nodeSpeedThreahold + global.SmallValue, 0.9); }
public MODReader(int id, int org) : base(id, org) { this.global = (MODGlobal)Global.getInstance(); this.readerType = BehaviorType.NORMAL; this.observedPhenomemons = new HashSet<MODPhenomemon>(); this.neighborSpeedPhenomemons = new Dictionary<int, MODPhenomemon>(); this.receivedEventReports = new Dictionary<string, Dictionary<Node, MODEventTrustResult>>(); this.deducedEventReports = new HashSet<string>(); this.toDeducedEventReports = new HashSet<string>(); this.pNormal = new Dictionary<Node, double>(); //this.pSupportMByNormal = new Dictionary<Node, double>(); //this.pNonsupportMByMalicious = new Dictionary<Node, double>(); this.pNBNormal = new Dictionary<Node, Dictionary<Node, double>>(); //this.pNBSupportByNormal = new Dictionary<Node, Dictionary<Node, double>>(); //this.pNBNonsupportByMalicious = new Dictionary<Node, Dictionary<Node, double>>(); this.nodeSuspectCount = new Dictionary<Node, List<double>>() ; this.nodeTrustWeights = new Dictionary<Node, double>(); this.nodeTrustWeightsLastUpdate = new Dictionary<Node, double>(); this.orgDirectTrustWeights = new List<DirectTrustEntity>[global.orgNum]; for (int i = 0; i < this.orgDirectTrustWeights.Length;i++ ) this.orgDirectTrustWeights[i] = new List<DirectTrustEntity>(); this.NBNodeIteractions = new Dictionary<Node,List<IteratorType>>(); this.nodeIteractions = new List<IteratorType>(); this.nodeHistoryMyVariance = new Dictionary<Node, List<double>>(); this.nodeHistoryTotalVariance = new Dictionary<Node, List<double>>(); this.NBNodeSuspectCount = new Dictionary<Node, Dictionary<Node, List<double>>>(); this.NBNodeTrustWeights = new Dictionary<Node, Dictionary<Node, double>>(); this.NBNodeTrustWeightsLastUpdate = new Dictionary<Node, Dictionary<Node, double>>(); this.NBNodeHistoryMyVariance = new Dictionary<Node, Dictionary<Node, List<double>>>(); this.NBNodeHistoryTotalVariance = new Dictionary<Node, Dictionary<Node, List<double>>>(); MODPhenomemon p = new MODPhenomemon(MODPhenomemonType.MOVE_FAST, id); this.neighborSpeedPhenomemons.Add(id, p); this.observedPhenomemons.Add(p); CheckRoutine(); //Event.AddEvent(new Event( global.startTime + global.checkSWHubCandidateInterval, EventType.CHK_SW_NB, this, null)); }